Skip to content

Commit e396227

Browse files
Merge branch 'main' into notifications-tooling
2 parents 6eaa8d3 + 495c0cb commit e396227

27 files changed

+1456
-569
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @juruen @sammorrowdrums @williammartin @toby
1+
* @github/github-mcp-server

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
.idea
22
cmd/github-mcp-server/github-mcp-server
3+
4+
# VSCode
5+
.vscode/mcp.json
6+
37
# Added by goreleaser init:
48
dist/
5-
__debug_bin*
9+
__debug_bin*
10+
11+
# Go
12+
vendor

README.md

Lines changed: 121 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ automation and interaction capabilities for developers and tools.
1919
3. Lastly you will need to [Create a GitHub Personal Access Token](https://github.com/settings/personal-access-tokens/new).
2020
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)).
2121

22-
23-
2422
## Installation
2523

2624
### Usage with VS Code
2725

28-
For quick installation, use one of the one-click install buttons at the top of this README.
26+
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.
2927

3028
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)`.
3129

@@ -91,14 +89,110 @@ More about using MCP server tools in VS Code's [agent mode documentation](https:
9189

9290
### Build from source
9391

94-
If you don't have Docker, you can use `go` to build the binary in the
95-
`cmd/github-mcp-server` directory, and use the `github-mcp-server stdio`
96-
command with the `GITHUB_PERSONAL_ACCESS_TOKEN` environment variable set to
97-
your token.
92+
If you don't have Docker, you can use `go build` to build the binary in the
93+
`cmd/github-mcp-server` directory, and use the `github-mcp-server stdio` command with the `GITHUB_PERSONAL_ACCESS_TOKEN` environment variable set to your token. To specify the output location of the build, use the `-o` flag. You should configure your server to use the built executable as its `command`. For example:
94+
95+
```JSON
96+
{
97+
"mcp": {
98+
"servers": {
99+
"github": {
100+
"command": "/path/to/github-mcp-server",
101+
"args": ["stdio"],
102+
"env": {
103+
"GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
104+
}
105+
}
106+
}
107+
}
108+
}
109+
```
110+
111+
## Tool Configuration
112+
113+
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.
114+
115+
### Available Toolsets
116+
117+
The following sets of tools are available (all are on by default):
118+
119+
| Toolset | Description |
120+
| ----------------------- | ------------------------------------------------------------- |
121+
| `repos` | Repository-related tools (file operations, branches, commits) |
122+
| `issues` | Issue-related tools (create, read, update, comment) |
123+
| `users` | Anything relating to GitHub Users |
124+
| `pull_requests` | Pull request operations (create, merge, review) |
125+
| `code_security` | Code scanning alerts and security features |
126+
| `experiments` | Experimental features (not considered stable) |
127+
128+
#### Specifying Toolsets
129+
130+
To specify toolsets you want available to the LLM, you can pass an allow-list in two ways:
131+
132+
1. **Using Command Line Argument**:
133+
134+
```bash
135+
github-mcp-server --toolsets repos,issues,pull_requests,code_security
136+
```
137+
138+
2. **Using Environment Variable**:
139+
```bash
140+
GITHUB_TOOLSETS="repos,issues,pull_requests,code_security" ./github-mcp-server
141+
```
142+
143+
The environment variable `GITHUB_TOOLSETS` takes precedence over the command line argument if both are provided.
144+
145+
### Using Toolsets With Docker
146+
147+
When using Docker, you can pass the toolsets as environment variables:
148+
149+
```bash
150+
docker run -i --rm \
151+
-e GITHUB_PERSONAL_ACCESS_TOKEN=<your-token> \
152+
-e GITHUB_TOOLSETS="repos,issues,pull_requests,code_security,experiments" \
153+
ghcr.io/github/github-mcp-server
154+
```
155+
156+
### The "all" Toolset
157+
158+
The special toolset `all` can be provided to enable all available toolsets regardless of any other configuration:
159+
160+
```bash
161+
./github-mcp-server --toolsets all
162+
```
163+
164+
Or using the environment variable:
165+
166+
```bash
167+
GITHUB_TOOLSETS="all" ./github-mcp-server
168+
```
169+
170+
## Dynamic Tool Discovery
171+
172+
**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.
173+
174+
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.
175+
176+
### Using Dynamic Tool Discovery
177+
178+
When using the binary, you can pass the `--dynamic-toolsets` flag.
179+
180+
```bash
181+
./github-mcp-server --dynamic-toolsets
182+
```
183+
184+
When using Docker, you can pass the toolsets as environment variables:
185+
186+
```bash
187+
docker run -i --rm \
188+
-e GITHUB_PERSONAL_ACCESS_TOKEN=<your-token> \
189+
-e GITHUB_DYNAMIC_TOOLSETS=1 \
190+
ghcr.io/github/github-mcp-server
191+
```
98192

99193
## GitHub Enterprise Server
100194

101-
The flag `--gh-host` and the environment variable `GH_HOST` can be used to set
195+
The flag `--gh-host` and the environment variable `GITHUB_HOST` can be used to set
102196
the GitHub Enterprise Server hostname.
103197

104198
## i18n / Overriding Descriptions
@@ -317,7 +411,6 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
317411
### Repositories
318412

319413
- **create_or_update_file** - Create or update a single file in a repository
320-
321414
- `owner`: Repository owner (string, required)
322415
- `repo`: Repository name (string, required)
323416
- `path`: File path (string, required)
@@ -327,50 +420,43 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
327420
- `sha`: File SHA if updating (string, optional)
328421

329422
- **list_branches** - List branches in a GitHub repository
330-
331423
- `owner`: Repository owner (string, required)
332424
- `repo`: Repository name (string, required)
333425
- `page`: Page number (number, optional)
334426
- `perPage`: Results per page (number, optional)
335427

336428
- **push_files** - Push multiple files in a single commit
337-
338429
- `owner`: Repository owner (string, required)
339430
- `repo`: Repository name (string, required)
340431
- `branch`: Branch to push to (string, required)
341432
- `files`: Files to push, each with path and content (array, required)
342433
- `message`: Commit message (string, required)
343434

344435
- **search_repositories** - Search for GitHub repositories
345-
346436
- `query`: Search query (string, required)
347437
- `sort`: Sort field (string, optional)
348438
- `order`: Sort order (string, optional)
349439
- `page`: Page number (number, optional)
350440
- `perPage`: Results per page (number, optional)
351441

352442
- **create_repository** - Create a new GitHub repository
353-
354443
- `name`: Repository name (string, required)
355444
- `description`: Repository description (string, optional)
356445
- `private`: Whether the repository is private (boolean, optional)
357446
- `autoInit`: Auto-initialize with README (boolean, optional)
358447

359448
- **get_file_contents** - Get contents of a file or directory
360-
361449
- `owner`: Repository owner (string, required)
362450
- `repo`: Repository name (string, required)
363451
- `path`: File path (string, required)
364452
- `ref`: Git reference (string, optional)
365453

366454
- **fork_repository** - Fork a repository
367-
368455
- `owner`: Repository owner (string, required)
369456
- `repo`: Repository name (string, required)
370457
- `organization`: Target organization name (string, optional)
371458

372459
- **create_branch** - Create a new branch
373-
374460
- `owner`: Repository owner (string, required)
375461
- `repo`: Repository name (string, required)
376462
- `branch`: New branch name (string, required)
@@ -391,16 +477,15 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
391477
- `page`: Page number, for files in the commit (number, optional)
392478
- `perPage`: Results per page, for files in the commit (number, optional)
393479

394-
### Search
395-
396-
- **search_code** - Search for code across GitHub repositories
397-
480+
- **search_code** - Search for code across GitHub repositories
398481
- `query`: Search query (string, required)
399482
- `sort`: Sort field (string, optional)
400483
- `order`: Sort order (string, optional)
401484
- `page`: Page number (number, optional)
402485
- `perPage`: Results per page (number, optional)
403486

487+
### Users
488+
404489
- **search_users** - Search for GitHub users
405490
- `query`: Search query (string, required)
406491
- `sort`: Sort field (string, optional)
@@ -422,6 +507,22 @@ export GITHUB_MCP_TOOL_ADD_ISSUE_COMMENT_DESCRIPTION="an alternative description
422507
- `ref`: Git reference (string, optional)
423508
- `state`: Alert state (string, optional)
424509
- `severity`: Alert severity (string, optional)
510+
- `tool_name`: The name of the tool used for code scanning (string, optional)
511+
512+
### Secret Scanning
513+
514+
- **get_secret_scanning_alert** - Get a secret scanning alert
515+
516+
- `owner`: Repository owner (string, required)
517+
- `repo`: Repository name (string, required)
518+
- `alertNumber`: Alert number (number, required)
519+
520+
- **list_secret_scanning_alerts** - List secret scanning alerts for a repository
521+
- `owner`: Repository owner (string, required)
522+
- `repo`: Repository name (string, required)
523+
- `state`: Alert state (string, optional)
524+
- `secret_type`: The secret types to be filtered for in a comma-separated list (string, optional)
525+
- `resolution`: The resolution status (string, optional)
425526

426527
## Resources
427528

cmd/github-mcp-server/main.go

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929
Use: "server",
3030
Short: "GitHub MCP Server",
3131
Long: `A GitHub MCP server that handles various tools and resources.`,
32-
Version: fmt.Sprintf("%s (%s) %s", version, commit, date),
32+
Version: fmt.Sprintf("Version: %s\nCommit: %s\nBuild Date: %s", version, commit, date),
3333
}
3434

3535
stdioCmd = &cobra.Command{
@@ -44,12 +44,16 @@ var (
4444
if err != nil {
4545
stdlog.Fatal("Failed to initialize logger:", err)
4646
}
47+
48+
enabledToolsets := viper.GetStringSlice("toolsets")
49+
4750
logCommands := viper.GetBool("enable-command-logging")
4851
cfg := runConfig{
4952
readOnly: readOnly,
5053
logger: logger,
5154
logCommands: logCommands,
5255
exportTranslations: exportTranslations,
56+
enabledToolsets: enabledToolsets,
5357
}
5458
if err := runStdioServer(cfg); err != nil {
5559
stdlog.Fatal("failed to run stdio server:", err)
@@ -61,27 +65,33 @@ var (
6165
func init() {
6266
cobra.OnInitialize(initConfig)
6367

68+
rootCmd.SetVersionTemplate("{{.Short}}\n{{.Version}}\n")
69+
6470
// Add global flags that will be shared by all commands
71+
rootCmd.PersistentFlags().StringSlice("toolsets", github.DefaultTools, "An optional comma separated list of groups of tools to allow, defaults to enabling all")
72+
rootCmd.PersistentFlags().Bool("dynamic-toolsets", false, "Enable dynamic toolsets")
6573
rootCmd.PersistentFlags().Bool("read-only", false, "Restrict the server to read-only operations")
6674
rootCmd.PersistentFlags().String("log-file", "", "Path to log file")
6775
rootCmd.PersistentFlags().Bool("enable-command-logging", false, "When enabled, the server will log all command requests and responses to the log file")
6876
rootCmd.PersistentFlags().Bool("export-translations", false, "Save translations to a JSON file")
6977
rootCmd.PersistentFlags().String("gh-host", "", "Specify the GitHub hostname (for GitHub Enterprise etc.)")
7078

7179
// Bind flag to viper
80+
_ = viper.BindPFlag("toolsets", rootCmd.PersistentFlags().Lookup("toolsets"))
81+
_ = viper.BindPFlag("dynamic_toolsets", rootCmd.PersistentFlags().Lookup("dynamic-toolsets"))
7282
_ = viper.BindPFlag("read-only", rootCmd.PersistentFlags().Lookup("read-only"))
7383
_ = viper.BindPFlag("log-file", rootCmd.PersistentFlags().Lookup("log-file"))
7484
_ = viper.BindPFlag("enable-command-logging", rootCmd.PersistentFlags().Lookup("enable-command-logging"))
7585
_ = viper.BindPFlag("export-translations", rootCmd.PersistentFlags().Lookup("export-translations"))
76-
_ = viper.BindPFlag("gh-host", rootCmd.PersistentFlags().Lookup("gh-host"))
86+
_ = viper.BindPFlag("host", rootCmd.PersistentFlags().Lookup("gh-host"))
7787

7888
// Add subcommands
7989
rootCmd.AddCommand(stdioCmd)
8090
}
8191

8292
func initConfig() {
8393
// Initialize Viper configuration
84-
viper.SetEnvPrefix("APP")
94+
viper.SetEnvPrefix("github")
8595
viper.AutomaticEnv()
8696
}
8797

@@ -107,6 +117,7 @@ type runConfig struct {
107117
logger *log.Logger
108118
logCommands bool
109119
exportTranslations bool
120+
enabledToolsets []string
110121
}
111122

112123
func runStdioServer(cfg runConfig) error {
@@ -115,18 +126,14 @@ func runStdioServer(cfg runConfig) error {
115126
defer stop()
116127

117128
// Create GH client
118-
token := os.Getenv("GITHUB_PERSONAL_ACCESS_TOKEN")
129+
token := viper.GetString("personal_access_token")
119130
if token == "" {
120131
cfg.logger.Fatal("GITHUB_PERSONAL_ACCESS_TOKEN not set")
121132
}
122133
ghClient := gogithub.NewClient(nil).WithAuthToken(token)
123134
ghClient.UserAgent = fmt.Sprintf("github-mcp-server/%s", version)
124135

125-
// Check GH_HOST env var first, then fall back to viper config
126-
host := os.Getenv("GH_HOST")
127-
if host == "" {
128-
host = viper.GetString("gh-host")
129-
}
136+
host := viper.GetString("host")
130137

131138
if host != "" {
132139
var err error
@@ -149,8 +156,40 @@ func runStdioServer(cfg runConfig) error {
149156
hooks := &server.Hooks{
150157
OnBeforeInitialize: []server.OnBeforeInitializeFunc{beforeInit},
151158
}
152-
// Create
153-
ghServer := github.NewServer(getClient, version, cfg.readOnly, t, server.WithHooks(hooks))
159+
// Create server
160+
ghServer := github.NewServer(version, server.WithHooks(hooks))
161+
162+
enabled := cfg.enabledToolsets
163+
dynamic := viper.GetBool("dynamic_toolsets")
164+
if dynamic {
165+
// filter "all" from the enabled toolsets
166+
enabled = make([]string, 0, len(cfg.enabledToolsets))
167+
for _, toolset := range cfg.enabledToolsets {
168+
if toolset != "all" {
169+
enabled = append(enabled, toolset)
170+
}
171+
}
172+
}
173+
174+
// Create default toolsets
175+
toolsets, err := github.InitToolsets(enabled, cfg.readOnly, getClient, t)
176+
context := github.InitContextToolset(getClient, t)
177+
178+
if err != nil {
179+
stdlog.Fatal("Failed to initialize toolsets:", err)
180+
}
181+
182+
// Register resources with the server
183+
github.RegisterResources(ghServer, getClient, t)
184+
// Register the tools with the server
185+
toolsets.RegisterTools(ghServer)
186+
context.RegisterTools(ghServer)
187+
188+
if dynamic {
189+
dynamic := github.InitDynamicToolset(ghServer, toolsets, t)
190+
dynamic.RegisterTools(ghServer)
191+
}
192+
154193
stdioServer := server.NewStdioServer(ghServer)
155194

156195
stdLogger := stdlog.New(cfg.logger.Writer(), "stdioserver", 0)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/docker/docker v28.0.4+incompatible
77
github.com/google/go-cmp v0.7.0
88
github.com/google/go-github/v69 v69.2.0
9-
github.com/mark3labs/mcp-go v0.18.0
9+
github.com/mark3labs/mcp-go v0.20.1
1010
github.com/migueleliasweb/go-github-mock v1.1.0
1111
github.com/sirupsen/logrus v1.9.3
1212
github.com/spf13/cobra v1.9.1

0 commit comments

Comments
 (0)