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.
Prerequisites
- Gemini CLI installed and authenticated (see Gemini CLI Getting Started)
- Node.js 18+ or Docker for npx- and Docker-based servers
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:
| Field | Purpose |
|---|---|
command | Executable to launch (e.g. npx, docker, local binary) |
args | Arguments passed to the command |
env | Environment 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
- Start Gemini CLI in your project
- Ask the agent to use a tool from the server, e.g. "search the filesystem for README files" or "list my recent GitHub issues"
- 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
- MCP Servers directory — pick servers that match your tools
- Gemini CLI Configuration — full gemini.yaml reference
- Migration: Gemini CLI to Antigravity — if you're moving to Antigravity CLI
- MCP Setup in Cursor — the same concepts in Cursor
Related Articles & Guides
How to Set Up MCP Servers in Antigravity CLI (Step-by-Step)
Connect Antigravity CLI to external tools with MCP servers. Complete setup guide covering agy mcp add/list/remove commands, settings.json configuration, verification, and troubleshooting.
How to Set Up MCP Servers in GitHub Copilot (Step-by-Step)
Connect GitHub Copilot to external tools with MCP servers. Complete Copilot MCP setup guide covering VS Code mcp.json, Copilot CLI, configuration examples, and troubleshooting.
How to Set Up MCP Servers in Cursor (Step-by-Step)
Connect Cursor to external tools with MCP servers. Complete Cursor MCP setup guide with .cursor/mcp.json configuration, the MCP UI, troubleshooting, and security best practices.