In this categoryGemini ยท 24
- How to Install the Gemini CLI and Run Your First PromptStart
- How to Get a Gemini API Key from Google AI Studio
- How to Call the Gemini API from Python
- How to Give Gemini CLI Project Context with a GEMINI.md File
- How to Choose the Right Gemini Model for Coding Tasks
- How to Fix a Bug in Your Codebase with the Gemini CLI
- How to Set Up Gemini Code Assist in VS Code
- How to Stream Gemini Responses in Node.js
- How to Feed a Long Document into Gemini's Long Context
- How to Run the Gemini CLI Non-Interactively in Scripts
- How to Analyze a Video File with the Gemini API
- How to Connect an MCP Server to the Gemini CLI
- How to Fix Common Gemini CLI Authentication Errors
- How to Cache Long Context in the Gemini API to Cut Costs
- How to Summarize a YouTube Video with Gemini
- How to Analyze PDFs and Docs in the Gemini Chat App
- How to Extract Data from Images and Screenshots with Gemini
- How to Generate a Short Video with Veo in Gemini
- How to Ground Gemini Answers in Your Own Documents
- How to Use Gemini Inside Google Docs to Draft Faster
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.
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.
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.
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "./data"]
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_TOKEN": "$GITHUB_TOKEN"
}
}
}
}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.
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.
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
16:12
3:58:44
12:00
09:00
15:21
14:27New guides in your inbox
Fresh step-by-step how-to guides as we publish them. One email a week, no more.