|
1 | 1 | # Install GitHub MCP Server in Google Gemini CLI
|
2 | 2 |
|
3 | 3 | ## Prerequisites
|
| 4 | + |
4 | 5 | 1. Google Gemini CLI installed (see [official Gemini CLI documentation](https://github.com/google-gemini/gemini-cli))
|
5 | 6 | 2. [GitHub Personal Access Token](https://github.com/settings/personal-access-tokens/new) with appropriate scopes
|
6 |
| -3. For local installation: [Docker](https://www.docker.com/) or [Podman](https://podman.io) installed and running |
7 |
| - |
8 |
| -## GitHub MCP Server Configuration |
| 7 | +3. For local installation: [Docker](https://www.docker.com/) installed and running |
9 | 8 |
|
10 |
| -### Method 1: Remote Server (Recommended) |
| 9 | +<details> |
| 10 | +<summary><b>Storing Your PAT Securely</b></summary> |
| 11 | +<br> |
11 | 12 |
|
12 |
| -The simplest way is to use GitHub's hosted MCP server: |
| 13 | +For security, avoid hardcoding your token. Create or update `~/.gemini/.env` (where `~` is your home or project directory) with your PAT: |
13 | 14 |
|
14 |
| -```json |
15 |
| -{ |
16 |
| - "mcpServers": { |
17 |
| - "github": { |
18 |
| - "httpUrl": "https://api.githubcopilot.com/mcp/", |
19 |
| - "trust": true, |
20 |
| - "headers": { |
21 |
| - "Authorization": "Bearer YOUR_GITHUB_PAT" |
22 |
| - } |
23 |
| - } |
24 |
| - } |
25 |
| -} |
26 |
| -``` |
27 |
| - |
28 |
| -Create or update `~/.gemini/.env` with your environment variables: |
29 | 15 | ```bash
|
30 | 16 | # ~/.gemini/.env
|
31 |
| -GITHUB_PAT=ghp_sample_sample_sample |
32 |
| -GOOGLE_CLOUD_PROJECT=my-gcp-project |
33 |
| -GEMINI_API_KEY=AIzSamplelBQGwHw-62R598eI-HFOWd4Ol847g |
34 |
| -``` |
35 |
| - |
36 |
| -### Method 2: Local Docker Setup (Alternative) |
37 |
| - |
38 |
| -### Docker Configuration |
39 |
| - |
40 |
| -```json |
41 |
| -{ |
42 |
| - "mcpServers": { |
43 |
| - "github": { |
44 |
| - "command": "docker", |
45 |
| - "args": [ |
46 |
| - "run", |
47 |
| - "-i", |
48 |
| - "--rm", |
49 |
| - "-e", |
50 |
| - "GITHUB_PERSONAL_ACCESS_TOKEN", |
51 |
| - "ghcr.io/github/github-mcp-server" |
52 |
| - ], |
53 |
| - "env": { |
54 |
| - "GITHUB_PERSONAL_ACCESS_TOKEN": "YOUR_GITHUB_PAT" |
55 |
| - } |
56 |
| - } |
57 |
| - } |
58 |
| -} |
59 |
| -``` |
60 |
| - |
61 |
| -### Binary Configuration (Alternative) |
62 |
| - |
63 |
| -If you prefer not to use Docker, you can build from source: |
64 |
| - |
65 |
| -```bash |
66 |
| -# Clone and build the server |
67 |
| -git clone https://github.com/github/github-mcp-server.git |
68 |
| -cd github-mcp-server |
69 |
| -go build -o github-mcp-server ./cmd/github-mcp-server |
70 |
| -``` |
71 |
| - |
72 |
| -Then configure: |
73 |
| - |
74 |
| -```json |
75 |
| -{ |
76 |
| - "mcpServers": { |
77 |
| - "github": { |
78 |
| - "command": "/path/to/github-mcp-server", |
79 |
| - "args": ["stdio"], |
80 |
| - "env": { |
81 |
| - "GITHUB_PERSONAL_ACCESS_TOKEN": "YOUR_GITHUB_PAT" |
82 |
| - } |
83 |
| - } |
84 |
| - } |
85 |
| -} |
| 17 | +GITHUB_PAT=your_token_here |
86 | 18 | ```
|
87 | 19 |
|
88 |
| -## Installation Steps |
| 20 | +</details> |
89 | 21 |
|
90 |
| -### Configuration File Location |
| 22 | +## GitHub MCP Server Configuration |
91 | 23 |
|
92 |
| -Gemini CLI uses a settings JSON file to configure MCP servers: |
| 24 | +MCP servers for Gemini CLI are configured in its settings JSON under an `mcpServers` key. |
93 | 25 |
|
94 |
| -- **Global configuration**: `~/.gemini/settings.json` |
| 26 | +- **Global configuration**: `~/.gemini/settings.json` where `~` is your home directory |
95 | 27 | - **Project-specific**: `.gemini/settings.json` in your project directory
|
96 | 28 |
|
97 |
| -### Setup Steps |
| 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. |
98 | 30 |
|
99 |
| -1. Create or edit your settings file with your chosen configuration from above |
100 |
| -2. Replace `YOUR_GITHUB_PAT` with your actual [GitHub Personal Access Token](https://github.com/settings/tokens) |
101 |
| -3. Save the file |
102 |
| -4. Restart Gemini CLI if it was running |
103 |
| - |
104 |
| -### Using Environment Variables (Recommended) |
| 31 | +### Method 1: Remote Server (Recommended) |
105 | 32 |
|
106 |
| -For better security, use environment variables: |
| 33 | +The simplest way is to use GitHub's hosted MCP server: |
107 | 34 |
|
108 | 35 | ```json
|
| 36 | +// ~/.gemini/settings.json |
109 | 37 | {
|
110 |
| - "mcpServers": { |
111 |
| - "github": { |
112 |
| - "command": "docker", |
113 |
| - "args": [ |
114 |
| - "run", |
115 |
| - "-i", |
116 |
| - "--rm", |
117 |
| - "-e", |
118 |
| - "GITHUB_PERSONAL_ACCESS_TOKEN", |
119 |
| - "ghcr.io/github/github-mcp-server" |
120 |
| - ], |
121 |
| - "env": { |
122 |
| - "GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_PAT" |
123 |
| - } |
| 38 | + "mcpServers": { |
| 39 | + "github": { |
| 40 | + "httpUrl": "https://api.githubcopilot.com/mcp/", |
| 41 | + "trust": true, |
| 42 | + "headers": { |
| 43 | + "Authorization": "Bearer $GITHUB_PAT" |
| 44 | + } |
| 45 | + } |
124 | 46 | }
|
125 |
| - } |
126 | 47 | }
|
127 | 48 | ```
|
128 | 49 |
|
129 |
| -Then add the environment variable to `~/.gemini/.env`: |
130 |
| -```bash |
131 |
| -GITHUB_PAT=your_github_pat |
132 |
| -``` |
133 |
| - |
134 |
| -## Configuration Options |
| 50 | +### Method 2: Local Docker |
135 | 51 |
|
136 |
| -### Toolset Configuration |
137 |
| - |
138 |
| -Enable specific GitHub API capabilities: |
| 52 | +With docker running, you can run the GitHub MCP server in a container: |
139 | 53 |
|
140 | 54 | ```json
|
| 55 | +// ~/.gemini/settings.json |
141 | 56 | {
|
142 |
| - "mcpServers": { |
143 |
| - "github": { |
144 |
| - "command": "docker", |
145 |
| - "args": [ |
146 |
| - "run", |
147 |
| - "-i", |
148 |
| - "--rm", |
149 |
| - "-e", |
150 |
| - "GITHUB_PERSONAL_ACCESS_TOKEN", |
151 |
| - "-e", |
152 |
| - "GITHUB_TOOLSETS", |
153 |
| - "ghcr.io/github/github-mcp-server" |
154 |
| - ], |
155 |
| - "env": { |
156 |
| - "GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_PAT", |
157 |
| - "GITHUB_TOOLSETS": "repos,issues,pull_requests,actions" |
158 |
| - } |
| 57 | + "mcpServers": { |
| 58 | + "github": { |
| 59 | + "command": "docker", |
| 60 | + "args": [ |
| 61 | + "run", |
| 62 | + "-i", |
| 63 | + "--rm", |
| 64 | + "-e", |
| 65 | + "GITHUB_PERSONAL_ACCESS_TOKEN", |
| 66 | + "ghcr.io/github/github-mcp-server" |
| 67 | + ], |
| 68 | + "env": { |
| 69 | + "GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_PAT" |
| 70 | + } |
| 71 | + } |
159 | 72 | }
|
160 |
| - } |
161 | 73 | }
|
162 | 74 | ```
|
163 | 75 |
|
164 |
| -### Read-Only Mode |
165 |
| - |
166 |
| -For security, run the server in read-only mode: |
167 |
| - |
168 |
| -```json |
169 |
| -{ |
170 |
| - "mcpServers": { |
171 |
| - "github": { |
172 |
| - "command": "docker", |
173 |
| - "args": [ |
174 |
| - "run", |
175 |
| - "-i", |
176 |
| - "--rm", |
177 |
| - "-e", |
178 |
| - "GITHUB_PERSONAL_ACCESS_TOKEN", |
179 |
| - "-e", |
180 |
| - "GITHUB_READ_ONLY", |
181 |
| - "ghcr.io/github/github-mcp-server" |
182 |
| - ], |
183 |
| - "env": { |
184 |
| - "GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_PAT", |
185 |
| - "GITHUB_READ_ONLY": "1" |
186 |
| - } |
187 |
| - } |
188 |
| - } |
189 |
| -} |
190 |
| -``` |
| 76 | +### Method 3: Binary |
191 | 77 |
|
192 |
| -### GitHub Enterprise Support |
| 78 | +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`. |
193 | 79 |
|
194 |
| -For GitHub Enterprise Server or Enterprise Cloud with data residency: |
| 80 | +Then, replacing `/path/to/binary` with the actual path to your binary, configure Gemini CLI with: |
195 | 81 |
|
196 | 82 | ```json
|
| 83 | +// ~/.gemini/settings.json |
197 | 84 | {
|
198 |
| - "mcpServers": { |
199 |
| - "github": { |
200 |
| - "command": "docker", |
201 |
| - "args": [ |
202 |
| - "run", |
203 |
| - "-i", |
204 |
| - "--rm", |
205 |
| - "-e", |
206 |
| - "GITHUB_PERSONAL_ACCESS_TOKEN", |
207 |
| - "-e", |
208 |
| - "GITHUB_HOST", |
209 |
| - "ghcr.io/github/github-mcp-server" |
210 |
| - ], |
211 |
| - "env": { |
212 |
| - "GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_PAT", |
213 |
| - "GITHUB_HOST": "https://your-github-enterprise.com" |
214 |
| - } |
| 85 | + "mcpServers": { |
| 86 | + "github": { |
| 87 | + "command": "/path/to/binary", |
| 88 | + "args": ["stdio"], |
| 89 | + "env": { |
| 90 | + "GITHUB_PERSONAL_ACCESS_TOKEN": "$GITHUB_PAT" |
| 91 | + } |
| 92 | + } |
215 | 93 | }
|
216 |
| - } |
217 | 94 | }
|
218 | 95 | ```
|
219 | 96 |
|
220 | 97 | ## Verification
|
221 | 98 |
|
222 |
| -After configuration, verify the installation: |
| 99 | +To verify that the GitHub MCP server has been configured, start Gemini CLI in your terminal with `gemini`, then: |
223 | 100 |
|
224 | 101 | 1. **Check MCP server status**:
|
225 |
| - ```bash |
226 |
| - gemini --prompt "/mcp list" |
227 |
| - ``` |
228 |
| - |
229 |
| -2. **List available tools**: |
230 |
| - ```bash |
231 |
| - gemini --prompt "/tools" |
232 |
| - ``` |
233 |
| - |
234 |
| -3. **Test with a simple command**: |
235 |
| - ```bash |
236 |
| - gemini "List my GitHub repositories" |
237 |
| - ``` |
238 |
| - |
239 |
| -## Usage Examples |
240 | 102 |
|
241 |
| -Once configured, use natural language commands: |
| 103 | + ``` |
| 104 | + /mcp list |
| 105 | + ``` |
242 | 106 |
|
243 |
| -```bash |
244 |
| -# Repository operations |
245 |
| -gemini "Show me the latest commits in microsoft/vscode" |
246 |
| - |
247 |
| -# Issue management |
248 |
| -gemini "Create an issue titled 'Bug report' in my-org/my-repo" |
| 107 | + ``` |
| 108 | + ℹConfigured MCP servers: |
249 | 109 |
|
250 |
| -# Pull request operations |
251 |
| -gemini "Review the latest pull request in my repository" |
| 110 | + 🟢 github - Ready (96 tools, 2 prompts) |
| 111 | + Tools: |
| 112 | + - github__add_comment_to_pending_review |
| 113 | + - github__add_issue_comment |
| 114 | + - github__add_sub_issue |
| 115 | + ... |
| 116 | + ``` |
252 | 117 |
|
253 |
| -# Code analysis |
254 |
| -gemini "Analyze the security alerts in my repositories" |
255 |
| -``` |
| 118 | +2. **Test with a prompt** |
| 119 | + ``` |
| 120 | + List my GitHub repositories |
| 121 | + ``` |
256 | 122 |
|
257 | 123 | ## Troubleshooting
|
258 | 124 |
|
259 | 125 | ### Local Server Issues
|
| 126 | +
|
260 | 127 | - **Docker errors**: Ensure Docker Desktop is running
|
261 |
| - ```bash |
262 |
| - docker --version |
263 |
| - ``` |
| 128 | + ```bash |
| 129 | + docker --version |
| 130 | + ``` |
264 | 131 | - **Image pull failures**: Try `docker logout ghcr.io` then retry
|
265 | 132 | - **Docker not found**: Install Docker Desktop and ensure it's running
|
266 | 133 |
|
267 |
| -### Authentication Issues |
| 134 | +### Authentication Issues |
| 135 | +
|
268 | 136 | - **Invalid PAT**: Verify your GitHub PAT has correct scopes:
|
269 |
| - - `repo` - Repository operations |
270 |
| - - `read:packages` - Docker image access (if using Docker) |
| 137 | + - `repo` - Repository operations |
| 138 | + - `read:packages` - Docker image access (if using Docker) |
271 | 139 | - **Token expired**: Generate a new GitHub PAT
|
272 | 140 |
|
273 | 141 | ### Configuration Issues
|
| 142 | +
|
274 | 143 | - **Invalid JSON**: Validate your configuration:
|
275 |
| - ```bash |
276 |
| - cat ~/.gemini/settings.json | jq . |
277 |
| - ``` |
| 144 | + ```bash |
| 145 | + cat ~/.gemini/settings.json | jq . |
| 146 | + ``` |
278 | 147 | - **MCP connection issues**: Check logs for connection errors:
|
279 |
| - ```bash |
280 |
| - gemini --debug "test command" |
281 |
| - ``` |
282 |
| - |
283 |
| -### Debug Mode |
284 |
| - |
285 |
| -Enable debug mode for detailed logging: |
286 |
| - |
287 |
| -```bash |
288 |
| -gemini --debug "Your command here" |
289 |
| -``` |
| 148 | + ```bash |
| 149 | + gemini --debug "test command" |
| 150 | + ``` |
290 | 151 |
|
291 | 152 | ## Important Notes
|
292 | 153 |
|
293 | 154 | - **Official repository**: [github/github-mcp-server](https://github.com/github/github-mcp-server)
|
294 | 155 | - **Docker image**: `ghcr.io/github/github-mcp-server` (official and supported)
|
295 | 156 | - **Gemini CLI specifics**: Uses `mcpServers` key, supports both global and project configurations
|
296 |
| -- **Remote server method**: Preferred approach using GitHub's hosted MCP server at `https://api.githubcopilot.com/mcp/` |
| 157 | +- **Remote server method**: Preferred approach using GitHub's hosted MCP server at `https://api.githubcopilot.com/mcp/` |
0 commit comments