Skip to content

Commit a7f54ca

Browse files
committed
add fix for e2e
1 parent 3a4b2cc commit a7f54ca

File tree

3 files changed

+59
-8
lines changed

3 files changed

+59
-8
lines changed

cmd/github-mcp-server/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ var (
4545
return fmt.Errorf("failed to unmarshal toolsets: %w", err)
4646
}
4747

48+
// If no toolsets are specified, use the default ones
49+
if len(enabledToolsets) == 0 {
50+
enabledToolsets = github.DefaultTools()
51+
}
52+
4853
stdioServerConfig := ghmcp.StdioServerConfig{
4954
Version: version,
5055
Host: viper.GetString("host"),
@@ -69,7 +74,7 @@ func init() {
6974
rootCmd.SetVersionTemplate("{{.Short}}\n{{.Version}}\n")
7075

7176
// Add global flags that will be shared by all commands
72-
rootCmd.PersistentFlags().StringSlice("toolsets", github.DefaultTools(), "An optional comma separated list of groups of tools to allow")
77+
rootCmd.PersistentFlags().StringSlice("toolsets", nil, github.GenerateToolsetsHelp())
7378
rootCmd.PersistentFlags().Bool("dynamic-toolsets", false, "Enable dynamic toolsets")
7479
rootCmd.PersistentFlags().Bool("read-only", false, "Restrict the server to read-only operations")
7580
rootCmd.PersistentFlags().String("log-file", "", "Path to log file")

e2e/e2e_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"time"
1717

1818
"github.com/github/github-mcp-server/internal/ghmcp"
19-
"github.com/github/github-mcp-server/pkg/github"
2019
"github.com/github/github-mcp-server/pkg/translations"
2120
gogithub "github.com/google/go-github/v74/github"
2221
mcpClient "github.com/mark3labs/mcp-go/client"
@@ -141,17 +140,20 @@ func setupMCPClient(t *testing.T, options ...clientOption) *mcpClient.Client {
141140
}
142141

143142
// Add toolsets environment variable to the Docker arguments
144-
if len(opts.enabledToolsets) > 0 {
145-
args = append(args, "-e", "GITHUB_TOOLSETS")
143+
// Default to "all" if no specific toolsets are configured
144+
enabledToolsets := opts.enabledToolsets
145+
if len(enabledToolsets) == 0 {
146+
enabledToolsets = []string{"all"}
146147
}
148+
args = append(args, "-e", "GITHUB_TOOLSETS")
147149

148150
// Add the image name
149151
args = append(args, "github/e2e-github-mcp-server")
150152

151153
// Construct the env vars for the MCP Client to execute docker with
152154
dockerEnvVars := []string{
153155
fmt.Sprintf("GITHUB_PERSONAL_ACCESS_TOKEN=%s", token),
154-
fmt.Sprintf("GITHUB_TOOLSETS=%s", strings.Join(opts.enabledToolsets, ",")),
156+
fmt.Sprintf("GITHUB_TOOLSETS=%s", strings.Join(enabledToolsets, ",")),
155157
}
156158

157159
if host != "" {
@@ -168,8 +170,8 @@ func setupMCPClient(t *testing.T, options ...clientOption) *mcpClient.Client {
168170
// not in scope for using the MCP server directly. This probably indicates that we should refactor
169171
// so that there is a shared setup mechanism, but let's wait till we feel more friction.
170172
enabledToolsets := opts.enabledToolsets
171-
if enabledToolsets == nil {
172-
enabledToolsets = github.DefaultTools
173+
if len(enabledToolsets) == 0 {
174+
enabledToolsets = []string{"all"}
173175
}
174176

175177
ghServer, err := ghmcp.NewMCPServer(ghmcp.MCPServerConfig{
@@ -190,7 +192,7 @@ func setupMCPClient(t *testing.T, options ...clientOption) *mcpClient.Client {
190192
})
191193

192194
// Initialize the client
193-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
195+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
194196
defer cancel()
195197

196198
request := mcp.InitializeRequest{}

pkg/github/tools.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package github
22

33
import (
44
"context"
5+
"fmt"
6+
"strings"
57

68
"github.com/github/github-mcp-server/pkg/raw"
79
"github.com/github/github-mcp-server/pkg/toolsets"
@@ -79,6 +81,14 @@ func DefaultTools() []string {
7981
return tools
8082
}
8183

84+
func AvailableTools() []string {
85+
tools := make([]string, len(AvailableToolsets))
86+
for i, toolset := range AvailableToolsets {
87+
tools[i] = string(toolset)
88+
}
89+
return tools
90+
}
91+
8292
func DefaultToolsetGroup(readOnly bool, getClient GetClientFn, getGQLClient GetGQLClientFn, getRawClient raw.GetRawClientFn, t translations.TranslationHelperFunc, contentWindowSize int) *toolsets.ToolsetGroup {
8393
tsg := toolsets.NewToolsetGroup(readOnly)
8494

@@ -336,3 +346,37 @@ func ToStringPtr(s string) *string {
336346
}
337347
return &s
338348
}
349+
350+
// GenerateToolsetsHelp generates the help text for the toolsets flag
351+
func GenerateToolsetsHelp() string {
352+
// Format default tools
353+
defaultTools := strings.Join(DefaultTools(), ", ")
354+
355+
// Format available tools with line breaks for better readability
356+
allTools := AvailableTools()
357+
var availableToolsLines []string
358+
const maxLineLength = 70
359+
currentLine := ""
360+
361+
for i, tool := range allTools {
362+
if i == 0 {
363+
currentLine = tool
364+
} else if len(currentLine)+len(tool)+2 <= maxLineLength {
365+
currentLine += ", " + tool
366+
} else {
367+
availableToolsLines = append(availableToolsLines, currentLine)
368+
currentLine = tool
369+
}
370+
}
371+
if currentLine != "" {
372+
availableToolsLines = append(availableToolsLines, currentLine)
373+
}
374+
375+
availableTools := strings.Join(availableToolsLines, ",\n\t ")
376+
377+
toolsetsHelp := fmt.Sprintf("Comma-separated list of tool groups to enable (no spaces).\n"+
378+
"Default: %s\n"+
379+
"To enable all tools, use all\n"+
380+
"Available: %s", defaultTools, availableTools)
381+
return toolsetsHelp
382+
}

0 commit comments

Comments
 (0)