Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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:
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
53 changes: 43 additions & 10 deletions internal/ghmcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,7 @@ func NewMCPServer(cfg MCPServerConfig) (*server.MCPServer, error) {
},
}

enabledToolsets := cfg.EnabledToolsets
if cfg.DynamicToolsets {
// filter "all" from the enabled toolsets
enabledToolsets = make([]string, 0, len(cfg.EnabledToolsets))
for _, toolset := range cfg.EnabledToolsets {
if toolset != "all" {
enabledToolsets = append(enabledToolsets, toolset)
}
}
}
enabledToolsets := cleanToolsets(cfg.EnabledToolsets, cfg.DynamicToolsets)

// Generate instructions based on enabled toolsets
instructions := github.GenerateInstructions(enabledToolsets)
Expand Down Expand Up @@ -470,3 +461,45 @@ func (t *bearerAuthTransport) RoundTrip(req *http.Request) (*http.Response, erro
req.Header.Set("Authorization", "Bearer "+t.token)
return t.transport.RoundTrip(req)
}

// cleanToolsets handles special toolset keywords in the enabled toolsets list:
// - Duplicates are removed from the result.
// - Removes whitespace
// - "all": Returns ["all"] immediately, ignoring all other toolsets (unless dynamicToolsets is true)
// - "default": Replaces with the actual default toolset IDs from GetDefaultToolsetIDs()
// When dynamicToolsets is true, filters out "all" from the enabled toolsets.
func cleanToolsets(enabledToolsets []string, dynamicToolsets bool) []string {
seen := make(map[string]bool)
result := make([]string, 0, len(enabledToolsets))

// Add non-default toolsets, removing duplicates and trimming whitespace
for _, toolset := range enabledToolsets {
trimmed := strings.TrimSpace(toolset)
if !seen[trimmed] {
seen[trimmed] = true
if trimmed != github.ToolsetMetadataDefault.ID && trimmed != github.ToolsetMetadataAll.ID {
result = append(result, trimmed)
}
}
}

hasDefault := seen[github.ToolsetMetadataDefault.ID]
hasAll := seen[github.ToolsetMetadataAll.ID]

// Handle "all" keyword - return early if not in dynamic mode
if hasAll && !dynamicToolsets {
return []string{github.ToolsetMetadataAll.ID}
}

// Expand "default" keyword to actual default toolsets
if hasDefault {
for _, defaultToolset := range github.GetDefaultToolsetIDs() {
if !seen[defaultToolset] {
result = append(result, defaultToolset)
seen[defaultToolset] = true
}
}
}

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

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCleanToolsets(t *testing.T) {
tests := []struct {
name string
input []string
dynamicToolsets bool
expected []string
}{
{
name: "empty slice",
input: []string{},
dynamicToolsets: false,
expected: []string{},
},
{
name: "nil input slice",
input: nil,
dynamicToolsets: false,
expected: []string{},
},
// all test cases
{
name: "all only",
input: []string{"all"},
dynamicToolsets: false,
expected: []string{"all"},
},
{
name: "all appears multiple times",
input: []string{"all", "actions", "all"},
dynamicToolsets: false,
expected: []string{"all"},
},
{
name: "all with other toolsets",
input: []string{"all", "actions", "gists"},
dynamicToolsets: false,
expected: []string{"all"},
},
{
name: "all with default",
input: []string{"default", "all", "actions"},
dynamicToolsets: false,
expected: []string{"all"},
},
// default test cases
{
name: "default only",
input: []string{"default"},
dynamicToolsets: false,
expected: []string{
"context",
"repos",
"issues",
"pull_requests",
"users",
},
},
{
name: "default with additional toolsets",
input: []string{"default", "actions", "gists"},
dynamicToolsets: false,
expected: []string{
"actions",
"gists",
"context",
"repos",
"issues",
"pull_requests",
"users",
},
},
{
name: "no default present",
input: []string{"actions", "gists", "notifications"},
dynamicToolsets: false,
expected: []string{"actions", "gists", "notifications"},
},
{
name: "duplicate toolsets without default",
input: []string{"actions", "gists", "actions"},
dynamicToolsets: false,
expected: []string{"actions", "gists"},
},
{
name: "duplicate toolsets with default",
input: []string{"context", "repos", "issues", "pull_requests", "users", "default"},
dynamicToolsets: false,
expected: []string{
"context",
"repos",
"issues",
"pull_requests",
"users",
},
},
{
name: "default appears multiple times with different toolsets in between",
input: []string{"default", "actions", "default", "gists", "default"},
dynamicToolsets: false,
expected: []string{
"actions",
"gists",
"context",
"repos",
"issues",
"pull_requests",
"users",
},
},
// Dynamic toolsets test cases
{
name: "dynamic toolsets - all only should be filtered",
input: []string{"all"},
dynamicToolsets: true,
expected: []string{},
},
{
name: "dynamic toolsets - all with other toolsets",
input: []string{"all", "actions", "gists"},
dynamicToolsets: true,
expected: []string{"actions", "gists"},
},
{
name: "dynamic toolsets - all with default",
input: []string{"all", "default", "actions"},
dynamicToolsets: true,
expected: []string{
"actions",
"context",
"repos",
"issues",
"pull_requests",
"users",
},
},
{
name: "dynamic toolsets - no all present",
input: []string{"actions", "gists"},
dynamicToolsets: true,
expected: []string{"actions", "gists"},
},
{
name: "dynamic toolsets - default only",
input: []string{"default"},
dynamicToolsets: true,
expected: []string{
"context",
"repos",
"issues",
"pull_requests",
"users",
},
},
{
name: "only special keywords with dynamic mode",
input: []string{"all", "default"},
dynamicToolsets: true,
expected: []string{
"context",
"repos",
"issues",
"pull_requests",
"users",
},
},
{
name: "all with default and overlapping default toolsets in dynamic mode",
input: []string{"all", "default", "issues", "repos"},
dynamicToolsets: true,
expected: []string{
"issues",
"repos",
"context",
"pull_requests",
"users",
},
},
// Whitespace test cases
{
name: "whitespace check - leading and trailing whitespace on regular toolsets",
input: []string{" actions ", " gists ", "notifications"},
dynamicToolsets: false,
expected: []string{"actions", "gists", "notifications"},
},
{
name: "whitespace check - default toolset",
input: []string{" actions ", " default ", "notifications"},
dynamicToolsets: false,
expected: []string{
"actions",
"notifications",
"context",
"repos",
"issues",
"pull_requests",
"users",
},
},
{
name: "whitespace check - all toolset",
input: []string{" actions ", " gists ", "notifications", " all "},
dynamicToolsets: false,
expected: []string{"all"},
},
}

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

// 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'")
})
}
}
Loading
Loading