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
Zapier MCP Server
Zapier MCP servers enable AI models to connect with 8,000+ apps and 30,000+ actions, providing powerful workflow automation and integration capabilities without complex API integrations.
Microsoft 365 MCP Server
Microsoft 365 MCP server provides unified access to Outlook mail, calendar, Teams, and files through the Microsoft Graph API for AI-powered productivity.
Unity MCP Server
Unity MCP servers enable AI models to interact with the Unity Editor, providing capabilities for scene manipulation, asset management, script editing, and game development automation.