Skip to content

Commit 0c0ce8f

Browse files
authored
Merge branch 'main' into issue-350
2 parents 2e797d8 + 4e26dce commit 0c0ce8f

24 files changed

+1086
-615
lines changed

.github/CODEOWNERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @juruen @sammorrowdrums @williammartin @toby
1+
* @github/github-mcp-server

.gitignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
.idea
22
cmd/github-mcp-server/github-mcp-server
3+
4+
# VSCode
5+
.vscode/*
6+
!.vscode/launch.json
7+
38
# Added by goreleaser init:
49
dist/
5-
__debug_bin*
10+
__debug_bin*
11+
12+
# Go
13+
vendor

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG VERSION="dev"
22

3-
FROM golang:1.23.7 AS build
3+
FROM golang:1.24.2 AS build
44
# allow this step access to build arg
55
ARG VERSION
66
# Set the working directory

README.md

+152-17
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ automation and interaction capabilities for developers and tools.
1515
## Prerequisites
1616

1717
1. To run the server in a container, you will need to have [Docker](https://www.docker.com/) installed.
18-
2. [Create a GitHub Personal Access Token](https://github.com/settings/personal-access-tokens/new).
19-
Each tool requires specific permissions to function. See the [Required Token Permissions](#required-token-permissions) section below for details.
2018

2119
## Required Token Permissions
2220

@@ -77,18 +75,18 @@ Each tool requires specific GitHub Personal Access Token permissions to function
7775

7876
Note: For organization repositories, additional organization-specific permissions may be required.
7977

78+
2. Once Docker is installed, you will also need to ensure Docker is running. The image is public; if you get errors on pull, you may have an expired token and need to `docker logout ghcr.io`.
79+
3. Lastly you will need to [Create a GitHub Personal Access Token](https://github.com/settings/personal-access-tokens/new).
80+
The MCP server can use many of the GitHub APIs, so enable the permissions that you feel comfortable granting your AI tools (to learn more about access tokens, please check out the [documentation](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)).
81+
8082
## Installation
8183

8284
### Usage with VS Code
8385

84-
For quick installation, use one of the one-click install buttons at the top of this README.
86+
For quick installation, use one of the one-click install buttons at the top of this README. Once you complete that flow, toggle Agent mode (located by the Copilot Chat text input) and the server will start.
8587

8688
For manual installation, add the following JSON block to your User Settings (JSON) file in VS Code. You can do this by pressing `Ctrl + Shift + P` and typing `Preferences: Open User Settings (JSON)`.
8789

88-
Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace. This will allow you to share the configuration with others.
89-
90-
> Note that the `mcp` key is not needed in the `.vscode/mcp.json` file.
91-
9290
```json
9391
{
9492
"mcp": {
@@ -120,6 +118,39 @@ Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace
120118
}
121119
```
122120

121+
Optionally, you can add a similar example (i.e. without the mcp key) to a file called `.vscode/mcp.json` in your workspace. This will allow you to share the configuration with others.
122+
123+
124+
```json
125+
{
126+
"inputs": [
127+
{
128+
"type": "promptString",
129+
"id": "github_token",
130+
"description": "GitHub Personal Access Token",
131+
"password": true
132+
}
133+
],
134+
"servers": {
135+
"github": {
136+
"command": "docker",
137+
"args": [
138+
"run",
139+
"-i",
140+
"--rm",
141+
"-e",
142+
"GITHUB_PERSONAL_ACCESS_TOKEN",
143+
"ghcr.io/github/github-mcp-server"
144+
],
145+
"env": {
146+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github_token}"
147+
}
148+
}
149+
}
150+
}
151+
152+
```
153+
123154
More about using MCP server tools in VS Code's [agent mode documentation](https://code.visualstudio.com/docs/copilot/chat/mcp-servers).
124155

125156
### Usage with Claude Desktop
@@ -166,9 +197,91 @@ If you don't have Docker, you can use `go build` to build the binary in the
166197
}
167198
```
168199

200+
## Tool Configuration
201+
202+
The GitHub MCP Server supports enabling or disabling specific groups of functionalities via the `--toolsets` flag. This allows you to control which GitHub API capabilities are available to your AI tools. Enabling only the toolsets that you need can help the LLM with tool choice and reduce the context size.
203+
204+
### Available Toolsets
205+
206+
The following sets of tools are available (all are on by default):
207+
208+
| Toolset | Description |
209+
| ----------------------- | ------------------------------------------------------------- |
210+
| `repos` | Repository-related tools (file operations, branches, commits) |
211+
| `issues` | Issue-related tools (create, read, update, comment) |
212+
| `users` | Anything relating to GitHub Users |
213+
| `pull_requests` | Pull request operations (create, merge, review) |
214+
| `code_security` | Code scanning alerts and security features |
215+
| `experiments` | Experimental features (not considered stable) |
216+
217+
#### Specifying Toolsets
218+
219+
To specify toolsets you want available to the LLM, you can pass an allow-list in two ways:
220+
221+
1. **Using Command Line Argument**:
222+
223+
```bash
224+
github-mcp-server --toolsets repos,issues,pull_requests,code_security
225+
```
226+
227+
2. **Using Environment Variable**:
228+
```bash
229+
GITHUB_TOOLSETS="repos,issues,pull_requests,code_security" ./github-mcp-server
230+
```
231+
232+
The environment variable `GITHUB_TOOLSETS` takes precedence over the command line argument if both are provided.
233+
234+
### Using Toolsets With Docker
235+
236+
When using Docker, you can pass the toolsets as environment variables:
237+
238+
```bash
239+
docker run -i --rm \
240+
-e GITHUB_PERSONAL_ACCESS_TOKEN=<your-token> \
241+
-e GITHUB_TOOLSETS="repos,issues,pull_requests,code_security,experiments" \
242+
ghcr.io/github/github-mcp-server
243+
```
244+
245+
### The "all" Toolset
246+
247+
The special toolset `all` can be provided to enable all available toolsets regardless of any other configuration:
248+
249+
```bash
250+
./github-mcp-server --toolsets all
251+
```
252+
253+
Or using the environment variable:
254+
255+
```bash
256+
GITHUB_TOOLSETS="all" ./github-mcp-server
257+
```
258+
259+
## Dynamic Tool Discovery
260+
261+
**Note**: This feature is currently in beta and may not be available in all environments. Please test it out and let us know if you encounter any issues.
262+
263+
Instead of starting with all tools enabled, you can turn on dynamic toolset discovery. Dynamic toolsets allow the MCP host to list and enable toolsets in response to a user prompt. This should help to avoid situations where the model gets confused by the shear number of tools available.
264+
265+
### Using Dynamic Tool Discovery
266+
267+
When using the binary, you can pass the `--dynamic-toolsets` flag.
268+
269+
```bash
270+
./github-mcp-server --dynamic-toolsets
271+
```
272+
273+
When using Docker, you can pass the toolsets as environment variables:
274+
275+
```bash
276+
docker run -i --rm \
277+
-e GITHUB_PERSONAL_ACCESS_TOKEN=<your-token> \
278+
-e GITHUB_DYNAMIC_TOOLSETS=1 \
279+
ghcr.io/github/github-mcp-server
280+
```
281+
169282
## GitHub Enterprise Server
170283

171-
The flag `--gh-host` and the environment variable `GH_HOST` can be used to set
284+
The flag `--gh-host` and the environment variable `GITHUB_HOST` can be used to set
172285
the GitHub Enterprise Server hostname.
173286

174287
## i18n / Overriding Descriptions
@@ -387,7 +500,6 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
387500
### Repositories
388501

389502
- **create_or_update_file** - Create or update a single file in a repository
390-
391503
- `owner`: Repository owner (string, required)
392504
- `repo`: Repository name (string, required)
393505
- `path`: File path (string, required)
@@ -396,44 +508,44 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
396508
- `branch`: Branch name (string, optional)
397509
- `sha`: File SHA if updating (string, optional)
398510

399-
- **push_files** - Push multiple files in a single commit
511+
- **list_branches** - List branches in a GitHub repository
512+
- `owner`: Repository owner (string, required)
513+
- `repo`: Repository name (string, required)
514+
- `page`: Page number (number, optional)
515+
- `perPage`: Results per page (number, optional)
400516

517+
- **push_files** - Push multiple files in a single commit
401518
- `owner`: Repository owner (string, required)
402519
- `repo`: Repository name (string, required)
403520
- `branch`: Branch to push to (string, required)
404521
- `files`: Files to push, each with path and content (array, required)
405522
- `message`: Commit message (string, required)
406523

407524
- **search_repositories** - Search for GitHub repositories
408-
409525
- `query`: Search query (string, required)
410526
- `sort`: Sort field (string, optional)
411527
- `order`: Sort order (string, optional)
412528
- `page`: Page number (number, optional)
413529
- `perPage`: Results per page (number, optional)
414530

415531
- **create_repository** - Create a new GitHub repository
416-
417532
- `name`: Repository name (string, required)
418533
- `description`: Repository description (string, optional)
419534
- `private`: Whether the repository is private (boolean, optional)
420535
- `autoInit`: Auto-initialize with README (boolean, optional)
421536

422537
- **get_file_contents** - Get contents of a file or directory
423-
424538
- `owner`: Repository owner (string, required)
425539
- `repo`: Repository name (string, required)
426540
- `path`: File path (string, required)
427541
- `ref`: Git reference (string, optional)
428542

429543
- **fork_repository** - Fork a repository
430-
431544
- `owner`: Repository owner (string, required)
432545
- `repo`: Repository name (string, required)
433546
- `organization`: Target organization name (string, optional)
434547

435548
- **create_branch** - Create a new branch
436-
437549
- `owner`: Repository owner (string, required)
438550
- `repo`: Repository name (string, required)
439551
- `branch`: New branch name (string, required)
@@ -449,16 +561,24 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
449561

450562
### Search
451563

452-
- **search_code** - Search for code across GitHub repositories
564+
- **get_commit** - Get details for a commit from a repository
565+
- `owner`: Repository owner (string, required)
566+
- `repo`: Repository name (string, required)
567+
- `sha`: Commit SHA, branch name, or tag name (string, required)
568+
- `page`: Page number, for files in the commit (number, optional)
569+
- `perPage`: Results per page, for files in the commit (number, optional)
453570

571+
- **search_code** - Search for code across GitHub repositories
454572
- `query`: Search query (string, required)
455573
- `sort`: Sort field (string, optional)
456574
- `order`: Sort order (string, optional)
457575
- `page`: Page number (number, optional)
458576
- `perPage`: Results per page (number, optional)
459577

578+
### Users
579+
460580
- **search_users** - Search for GitHub users
461-
- `query`: Search query (string, required)
581+
- `q`: Search query (string, required)
462582
- `sort`: Sort field (string, optional)
463583
- `order`: Sort order (string, optional)
464584
- `page`: Page number (number, optional)
@@ -480,6 +600,21 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
480600
- `severity`: Alert severity (string, optional)
481601
- `tool_name`: The name of the tool used for code scanning (string, optional)
482602

603+
### Secret Scanning
604+
605+
- **get_secret_scanning_alert** - Get a secret scanning alert
606+
607+
- `owner`: Repository owner (string, required)
608+
- `repo`: Repository name (string, required)
609+
- `alertNumber`: Alert number (number, required)
610+
611+
- **list_secret_scanning_alerts** - List secret scanning alerts for a repository
612+
- `owner`: Repository owner (string, required)
613+
- `repo`: Repository name (string, required)
614+
- `state`: Alert state (string, optional)
615+
- `secret_type`: The secret types to be filtered for in a comma-separated list (string, optional)
616+
- `resolution`: The resolution status (string, optional)
617+
483618
## Resources
484619

485620
### Repository Content

cmd/github-mcp-server/main.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ var (
4545
stdlog.Fatal("Failed to initialize logger:", err)
4646
}
4747

48-
enabledToolsets := viper.GetStringSlice("toolsets")
48+
// If you're wondering why we're not using viper.GetStringSlice("toolsets"),
49+
// it's because viper doesn't handle comma-separated values correctly for env
50+
// vars when using GetStringSlice.
51+
// https://github.com/spf13/viper/issues/380
52+
var enabledToolsets []string
53+
err = viper.UnmarshalKey("toolsets", &enabledToolsets)
54+
if err != nil {
55+
stdlog.Fatal("Failed to unmarshal toolsets:", err)
56+
}
4957

5058
logCommands := viper.GetBool("enable-command-logging")
5159
cfg := runConfig{

0 commit comments

Comments
 (0)