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
23:41
1:42:18
28:14
41:09
9:47
8:23