Set up an MCP server
Connect Gemini CLI to your external databases and services. In this guide, youâll learn how to extend Gemini CLIâs capabilities by installing the GitHub MCP server and using it to manage your repositories.
Prerequisites
Section titled âPrerequisitesâ- Gemini CLI installed.
- Docker: Required for this specific example (many MCP servers run as Docker containers).
- GitHub token: A Personal Access Token (PAT) with repo permissions.
How to prepare your credentials
Section titled âHow to prepare your credentialsâMost MCP servers require authentication. For GitHub, you need a PAT.
- Create a fine-grained PAT.
- Grant it Read access to Metadata and Contents, and Read/Write access to Issues and Pull Requests.
- Store it in your environment:
macOS/Linux
export GITHUB_PERSONAL_ACCESS_TOKEN="github_pat_..."Windows (PowerShell)
$env:GITHUB_PERSONAL_ACCESS_TOKEN="github_pat_..."How to configure Gemini CLI
Section titled âHow to configure Gemini CLIâYou tell Gemini about new servers by editing your settings.json.
- Open
~/.gemini/settings.json(or the project-specific.gemini/settings.json). - Add the
mcpServersblock. This tells Gemini: âRun this docker container and talk to it.â
{ "mcpServers": { "github": { "command": "docker", "args": [ "run", "-i", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", "ghcr.io/modelcontextprotocol/servers/github:latest" ], "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PERSONAL_ACCESS_TOKEN}" } } }}Note: The
commandisdocker, and the rest are arguments passed to it. We map the local environment variable into the container so your secret isnât hardcoded in the config file.
How to verify the connection
Section titled âHow to verify the connectionâRestart Gemini CLI. It will automatically try to start the defined servers.
Command: /mcp list
You should see: â github: docker ... - Connected
If you see Disconnected or an error, check that Docker is running and your API
token is valid.
How to use the new tools
Section titled âHow to use the new toolsâNow that the server is running, the agent has new capabilities (âtoolsâ). You donât need to learn special commands; just ask in natural language.
Scenario: Listing pull requests
Section titled âScenario: Listing pull requestsâPrompt: List the open PRs in the google/gemini-cli repository.
The agent will:
- Recognize the request matches a GitHub tool.
- Call
github_list_pull_requests. - Present the data to you.
Scenario: Creating an issue
Section titled âScenario: Creating an issueâPrompt:
Create an issue in my repo titled "Bug: Login fails" with the description "See logs".
Troubleshooting
Section titled âTroubleshootingâ- Server wonât start? Try running the docker command manually in your terminal to see if it prints an error (e.g., âimage not foundâ).
- Tools not found? Run
/mcp reloadto force the CLI to re-query the server for its capabilities.
Next steps
Section titled âNext stepsâ- Explore the MCP servers reference to learn about SSE and HTTP transports for remote servers.
- Browse the official MCP server list to find connectors for Slack, Postgres, Google Drive, and more.