GeminiAdvanced

How to Connect an MCP Server to the Gemini CLI

Register a Model Context Protocol server in your Gemini CLI settings to give the agent new tools.

9 minAdvanced

The Gemini CLI supports the Model Context Protocol, the open standard for plugging external tools into an agent. By adding an MCP server you give Gemini abilities it does not have out of the box, like querying a database or hitting an internal API. This guide registers a server and confirms its tools are live.

What you need

  • The Gemini CLI installed and authenticated
  • An MCP server you can launch, for example a published npm package
  • Comfort editing a JSON settings file
  • About 8 minutes

Step 1: Open the settings file

The CLI reads MCP servers from a settings.json file. Use the project-local .gemini/settings.json to scope a server to one repo, or ~/.gemini/settings.json to make it available everywhere. Create the file if it does not exist.

zsh - locate settings
$mkdir -p .gemini
$code .gemini/settings.json
Project-scoped settings for the Gemini CLI
$

Step 2: Add an mcpServers entry

Add an mcpServers object. Each key is a name you choose; the value tells the CLI how to launch the server. For a stdio server you give a command and its args. Environment variables go in an env block so secrets stay out of the args.

.gemini/settings.json
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "./data"]
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "$GITHUB_TOKEN"
      }
    }
  }
}
Only add servers you trust
An MCP server can run code and read data on your behalf. Install servers from sources you trust, and never paste a token directly into args where it could be logged. Reference an environment variable instead.

Step 3: Verify the tools loaded

Restart the CLI and run /mcp. It lists each configured server, its connection status, and the tools it exposes. A server in connected state with tools listed means Gemini can call them.

gemini - mcp
> /mcp
filesystem connected 3 tools
read_file, write_file, list_directory
github connected 5 tools
search_repos, get_issue, create_issue ...
Output of /mcp showing connected servers and tools.

Step 4: Use a tool in a prompt

Now ask something that requires the new capability. The agent decides when to call a tool and asks for approval before actions that write or modify, so you stay in control of side effects.

gemini - tool call
You
List the open issues in this repo labeled bug.
Agent
Calling github.search_issues with label:bug state:open... Found 4 open bugs. The oldest is #112, a crash on empty input from 9 days ago.
Gemini invoking an MCP tool to answer.

Result

Your Gemini CLI now reaches beyond its built-in tools. The /mcp command confirms what is connected, and the agent pulls in the right tool when a prompt needs it. Add more servers to the same mcpServers block as your workflow grows.

Watch related tutorials

Tags
#gemini-cli#mcp#tools#config#integration