|
| 1 | +# Install GitHub MCP Server in Google Gemini CLI |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | + |
| 5 | +1. Google Gemini CLI installed (see [official Gemini CLI documentation](https://github.com/google-gemini/gemini-cli)) |
| 6 | +2. [GitHub Personal Access Token](https://github.com/settings/personal-access-tokens/new) with appropriate scopes |
| 7 | +3. For local installation: [Docker](https://www.docker.com/) installed and running |
| 8 | + |
| 9 | +<details> |
| 10 | +<summary><b>Storing Your PAT Securely</b></summary> |
| 11 | +<br> |
| 12 | + |
| 13 | +For security, avoid hardcoding your token. Create or update `~/.gemini/.env` (where `~` is your home or project directory) with your PAT: |
| 14 | + |
| 15 | +```bash |
| 16 | +# ~/.gemini/.env |
| 17 | +GITHUB_PAT=your_token_here |
| 18 | +``` |
| 19 | + |
| 20 | +</details> |
| 21 | + |
| 22 | +## GitHub MCP Server Configuration |
| 23 | + |
| 24 | +MCP servers for Gemini CLI are configured in its settings JSON under an `mcpServers` key. |
| 25 | + |
| 26 | +- **Global configuration**: `~/.gemini/settings.json` where `~` is your home directory |
| 27 | +- **Project-specific**: `.gemini/settings.json` in your project directory |
| 28 | + |
| 29 | +After securely storing your PAT, you can add the GitHub MCP server configuration to your settings file using one of the methods below. You may need to restart the Gemini CLI for changes to take effect. |
| 30 | + |
| 31 | +> **Note:** For the most up-to-date configuration options, see the [main README.md](../../README.md). |
| 32 | +
|
| 33 | +### Method 1: Remote Server (Recommended) |
| 34 | + |
| 35 | +The simplest way is to use GitHub's hosted MCP server: |
| 36 | + |
| 37 | +```json |
| 38 | +// ~/.gemini/settings.json |
| 39 | +{ |
| 40 | + "mcpServers": { |
| 41 | + "github": { |
| 42 | + "httpUrl": "https://api.githubcopilot.com/mcp/", |
| 43 | + "trust": true, |
| 44 | + "headers": { |
| 45 | + "Authorization": "Bearer $GITHUB_PAT" |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +### Method 2: Local Docker |
| 53 | + |
| 54 | +With docker running, you can run the GitHub MCP server in a container: |
| 55 | + |
| 56 | +```json |
| 57 | +// ~/.gemini/settings.json |
| 58 | +{ |
| 59 | + "mcpServers": { |
| 60 | + "github": { |
| 61 | + "command": "docker", |
| 62 | + "args": [ |
| 63 | + "run", |
| 64 | + "-i", |
| 65 | + "--rm", |
| 66 | + "-e", |
| 67 | + "GITHUB_PERSONAL_ACCESS_TOKEN", |
| 68 | + "ghcr.io/github/github-mcp-server" |
| 69 | + ], |
| 70 | + "env": { |
| 71 | + "GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_PAT" |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +### Method 3: Binary |
| 79 | + |
| 80 | +You can download the latest binary release from the [GitHub releases page](https://github.com/github/github-mcp-server/releases) or build it from source by running `go build -o github-mcp-server ./cmd/github-mcp-server`. |
| 81 | + |
| 82 | +Then, replacing `/path/to/binary` with the actual path to your binary, configure Gemini CLI with: |
| 83 | + |
| 84 | +```json |
| 85 | +// ~/.gemini/settings.json |
| 86 | +{ |
| 87 | + "mcpServers": { |
| 88 | + "github": { |
| 89 | + "command": "/path/to/binary", |
| 90 | + "args": ["stdio"], |
| 91 | + "env": { |
| 92 | + "GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_PAT" |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +## Verification |
| 100 | + |
| 101 | +To verify that the GitHub MCP server has been configured, start Gemini CLI in your terminal with `gemini`, then: |
| 102 | + |
| 103 | +1. **Check MCP server status**: |
| 104 | + |
| 105 | + ``` |
| 106 | + /mcp list |
| 107 | + ``` |
| 108 | +
|
| 109 | + ``` |
| 110 | + ℹConfigured MCP servers: |
| 111 | +
|
| 112 | + 🟢 github - Ready (96 tools, 2 prompts) |
| 113 | + Tools: |
| 114 | + - github__add_comment_to_pending_review |
| 115 | + - github__add_issue_comment |
| 116 | + - github__add_sub_issue |
| 117 | + ... |
| 118 | + ``` |
| 119 | +
|
| 120 | +2. **Test with a prompt** |
| 121 | + ``` |
| 122 | + List my GitHub repositories |
| 123 | + ``` |
| 124 | +
|
| 125 | +## Troubleshooting |
| 126 | +
|
| 127 | +### Local Server Issues |
| 128 | +
|
| 129 | +- **Docker errors**: Ensure Docker Desktop is running |
| 130 | + ```bash |
| 131 | + docker --version |
| 132 | + ``` |
| 133 | +- **Image pull failures**: Try `docker logout ghcr.io` then retry |
| 134 | +- **Docker not found**: Install Docker Desktop and ensure it's running |
| 135 | +
|
| 136 | +### Authentication Issues |
| 137 | +
|
| 138 | +- **Invalid PAT**: Verify your GitHub PAT has correct scopes: |
| 139 | + - `repo` - Repository operations |
| 140 | + - `read:packages` - Docker image access (if using Docker) |
| 141 | +- **Token expired**: Generate a new GitHub PAT |
| 142 | +
|
| 143 | +### Configuration Issues |
| 144 | +
|
| 145 | +- **Invalid JSON**: Validate your configuration: |
| 146 | + ```bash |
| 147 | + cat ~/.gemini/settings.json | jq . |
| 148 | + ``` |
| 149 | +- **MCP connection issues**: Check logs for connection errors: |
| 150 | + ```bash |
| 151 | + gemini --debug "test command" |
| 152 | + ``` |
| 153 | +
|
| 154 | +## References |
| 155 | +
|
| 156 | +- Gemini CLI Docs > [MCP Configuration Structure](https://google-gemini.github.io/gemini-cli/docs/tools/mcp-server.html#configuration-structure) |
0 commit comments