How to Set Up MCP Servers in Gemini CLI (Step-by-Step)

Connect Gemini CLI to external tools with MCP servers. Complete Gemini CLI MCP setup guide with gemini.yaml MCP configuration, verification, and troubleshooting.

August 10, 2026
implementationguidesetupGemini CLIMCPgemini.yaml

Prerequisites

What is MCP?

MCP (Model Context Protocol) lets Gemini CLI's agent use external tools — filesystem, GitHub, databases, search — through a standard interface. Gemini CLI reads your MCP config at startup and exposes each server's tools to the agent.

Enabling MCP in Gemini CLI

MCP servers are configured in gemini.yaml, the CLI's main config file. Add an mcp block with a servers map:

mcp:
  servers:
    filesystem:
      command: npx
      args:
        - "-y"
        - "@modelcontextprotocol/server-filesystem"
        - "./"
    github:
      command: npx
      args:
        - "-y"
        - "@modelcontextprotocol/server-github"
      env:
        GITHUB_PERSONAL_ACCESS_TOKEN: "${GITHUB_TOKEN}"
    postgres:
      command: npx
      args:
        - "-y"
        - "@modelcontextprotocol/server-postgres"
        - "postgresql://localhost:5432/mydb"

Each server entry has three fields:

FieldPurpose
commandExecutable to launch (e.g. npx, docker, local binary)
argsArguments passed to the command
envEnvironment variables for the server, including API keys

Using "${VAR_NAME}" in env makes Gemini CLI resolve the value from your shell at launch — keep secrets out of the committed file.

Verifying Your Servers

  1. Start Gemini CLI in your project
  2. Ask the agent to use a tool from the server, e.g. "search the filesystem for README files" or "list my recent GitHub issues"
  3. If a server failed to connect, check the session log for the startup error

Using MCP Tools in Gemini CLI

Once connected, the agent calls the server's tools like any built-in tool:

You: "Use the postgres server to show the schema of the orders table."

Agent: [calls the postgres tool, returns the schema]

MCP tools are namespaced by server, so multiple servers can expose similarly named tools without conflict.

Security Considerations

  • Least privilege — give servers only the credentials they need
  • Keep secrets out of git — use ${VAR_NAME} interpolation so API keys resolve from your shell at launch
  • Review server tools — an MCP server executes arbitrary commands on your machine
  • Scoped servers — keep workspace-specific servers out of global config

Troubleshooting

Further Resources