Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,12 @@ Alternatively, to manually configure VS Code, choose the appropriate JSON block

### Configuration

#### Default toolset configuration

The default configuration is:
- context
- repos
- issues
- pull_requests
- users
#### Toolset configuration

See [Remote Server Documentation](docs/remote-server.md) for full details on remote server configuration, toolsets, headers, and advanced usage. This file provides comprehensive instructions and examples for connecting, customizing, and installing the remote GitHub MCP Server in VS Code and other MCP hosts.

When no toolsets are specified, [default toolsets](#default-toolset) are used.

#### Enterprise Cloud with data residency (ghe.com)

GitHub Enterprise Cloud can also make use of the remote server.
Expand Down Expand Up @@ -329,7 +324,7 @@ The GitHub MCP Server supports enabling or disabling specific groups of function

_Toolsets are not limited to Tools. Relevant MCP Resources and Prompts are also included where applicable._

The Local GitHub MCP Server follows the same [default toolset configuration](#default-toolset-configuration) as the remote version.
When no toolsets are specified, [default toolsets](#default-toolset) are used.

#### Specifying Toolsets

Expand Down Expand Up @@ -359,7 +354,9 @@ docker run -i --rm \
ghcr.io/github/github-mcp-server
```

### The "all" Toolset
### Special toolsets

#### "all" toolset

The special toolset `all` can be provided to enable all available toolsets regardless of any other configuration:

Expand All @@ -373,6 +370,22 @@ Or using the environment variable:
GITHUB_TOOLSETS="all" ./github-mcp-server
```

#### "default" toolset
The default toolset `default` is the configuration that gets passed to the server if no toolsets are specified.

The default configuration is:
- context
- repos
- issues
- pull_requests
- users

To keep the default configuration and add additional toolsets:

```bash
GITHUB_TOOLSETS="default,stargazers" ./github-mcp-server
```

### Available Toolsets

The following sets of tools are available (all are on by default):
Expand Down
3 changes: 2 additions & 1 deletion cmd/github-mcp-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ var (
return fmt.Errorf("failed to unmarshal toolsets: %w", err)
}

// No passed toolsets configuration means we enable the default toolset
if len(enabledToolsets) == 0 {
enabledToolsets = github.GetDefaultToolsetIDs()
enabledToolsets = []string{github.ToolsetMetadataDefault.ID}
}

stdioServerConfig := ghmcp.StdioServerConfig{
Expand Down
35 changes: 34 additions & 1 deletion internal/ghmcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,14 @@ func NewMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) {
// filter "all" from the enabled toolsets
enabledToolsets = make([]string, 0, len(cfg.EnabledToolsets))
for _, toolset := range cfg.EnabledToolsets {
if toolset != "all" {
if toolset != github.ToolsetMetadataAll.ID {
enabledToolsets = append(enabledToolsets, toolset)
}
}
}

enabledToolsets = transformDefault(enabledToolsets)

// Generate instructions based on enabled toolsets
instructions := github.GenerateInstructions(enabledToolsets)

Expand Down Expand Up @@ -470,3 +472,34 @@ func (t *bearerAuthTransport) RoundTrip(req *http.Request) (*http.Response, erro
req.Header.Set("Authorization", "Bearer "+t.token)
return t.transport.RoundTrip(req)
}

// transformDefault replaces "default" in the enabled toolsets with the actual default toolset IDs.
// If "default" is present, it removes it and adds the default toolset IDs from GetDefaultToolsetIDs().
// Duplicates are removed from the final result.
func transformDefault(enabledToolsets []string) []string {
hasDefault := false
result := make([]string, 0, len(enabledToolsets))
seen := make(map[string]bool)

// First pass: check if "default" exists and collect non-default toolsets
for _, toolset := range enabledToolsets {
if toolset == github.ToolsetMetadataDefault.ID {
hasDefault = true
} else if !seen[toolset] {
result = append(result, toolset)
seen[toolset] = true
}
}

// If "default" was found, add the default toolset IDs
if hasDefault {
for _, defaultToolset := range github.GetDefaultToolsetIDs() {
if !seen[defaultToolset] {
result = append(result, defaultToolset)
seen[defaultToolset] = true
}
}
}

return result
}
156 changes: 156 additions & 0 deletions internal/ghmcp/server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package ghmcp

import (
"testing"

"github.com/github/github-mcp-server/pkg/github"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestTransformDefault(t *testing.T) {
tests := []struct {
name string
input []string
expected []string
}{
{
name: "empty slice",
input: []string{},
expected: []string{},
},
{
name: "default only",
input: []string{"default"},
expected: []string{
"context",
"repos",
"issues",
"pull_requests",
"users",
},
},
{
name: "default with additional toolsets",
input: []string{"default", "actions", "gists"},
expected: []string{
"actions",
"gists",
"context",
"repos",
"issues",
"pull_requests",
"users",
},
},
{
name: "default with overlapping toolsets",
input: []string{"default", "issues", "actions"},
expected: []string{
"issues",
"actions",
"context",
"repos",
"pull_requests",
"users",
},
},
{
name: "no default present",
input: []string{"actions", "gists", "notifications"},
expected: []string{"actions", "gists", "notifications"},
},
{
name: "duplicate toolsets without default",
input: []string{"actions", "gists", "actions"},
expected: []string{"actions", "gists"},
},
{
name: "duplicate toolsets with default",
input: []string{"actions", "default", "actions", "issues"},
expected: []string{
"actions",
"issues",
"context",
"repos",
"pull_requests",
"users",
},
},
{
name: "multiple defaults (edge case)",
input: []string{"default", "actions", "default"},
expected: []string{
"actions",
"context",
"repos",
"issues",
"pull_requests",
"users",
},
},
{
name: "all default toolsets already present with default",
input: []string{"context", "repos", "issues", "pull_requests", "users", "default"},
expected: []string{
"context",
"repos",
"issues",
"pull_requests",
"users",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := transformDefault(tt.input)

// Check that the result has the correct length
require.Len(t, result, len(tt.expected), "result length should match expected length")

// Create a map for easier comparison since order might vary
resultMap := make(map[string]bool)
for _, toolset := range result {
resultMap[toolset] = true
}

expectedMap := make(map[string]bool)
for _, toolset := range tt.expected {
expectedMap[toolset] = true
}

// Check that both maps contain the same toolsets
assert.Equal(t, expectedMap, resultMap, "result should contain all expected toolsets without duplicates")

// Verify no duplicates in result
assert.Len(t, resultMap, len(result), "result should not contain duplicates")

// Verify "default" is not in the result
assert.False(t, resultMap["default"], "result should not contain 'default'")
})
}
}

func TestTransformDefaultWithActualDefaults(t *testing.T) {
// This test verifies that the function uses the actual default toolsets from GetDefaultToolsetIDs()
input := []string{"default"}
result := transformDefault(input)

defaultToolsets := github.GetDefaultToolsetIDs()

// Check that result contains all default toolsets
require.Len(t, result, len(defaultToolsets), "result should contain all default toolsets")

resultMap := make(map[string]bool)
for _, toolset := range result {
resultMap[toolset] = true
}

for _, defaultToolset := range defaultToolsets {
assert.True(t, resultMap[defaultToolset], "result should contain default toolset: %s", defaultToolset)
}

// Verify "default" is not in the result
assert.False(t, resultMap["default"], "result should not contain 'default'")
}
8 changes: 8 additions & 0 deletions pkg/github/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ type ToolsetMetadata struct {
}

var (
ToolsetMetadataAll = ToolsetMetadata{
ID: "all",
Description: "Special toolset that enables all available toolsets",
}
ToolsetMetadataDefault = ToolsetMetadata{
ID: "default",
Description: "Special toolset that enables the default toolset configuration. When no toolsets are specified, this is the set that is enabled",
}
ToolsetMetadataContext = ToolsetMetadata{
ID: "context",
Description: "Tools that provide context about the current user and GitHub context you are operating in",
Expand Down
Loading