Skip to content

Commit f9427ab

Browse files
committed
Ensure toolsets are configurable via env var
1 parent 4a39c03 commit f9427ab

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

cmd/github-mcp-server/main.go

Lines changed: 9 additions & 1 deletion
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{

e2e/e2e_test.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/json"
88
"os"
99
"os/exec"
10+
"slices"
1011
"sync"
1112
"testing"
1213
"time"
@@ -115,6 +116,9 @@ func setupMCPClient(t *testing.T, options ...ClientOption) *mcpClient.Client {
115116
t.Log("Starting Stdio MCP client...")
116117
client, err := mcpClient.NewStdioMCPClient(args[0], []string{}, args[1:]...)
117118
require.NoError(t, err, "expected to create client successfully")
119+
t.Cleanup(func() {
120+
require.NoError(t, client.Close(), "expected to close client successfully")
121+
})
118122

119123
// Initialize the client
120124
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
@@ -166,5 +170,33 @@ func TestGetMe(t *testing.T) {
166170
require.NoError(t, err, "expected to get user successfully")
167171
require.Equal(t, trimmedContent.Login, *user.Login, "expected login to match")
168172

169-
require.NoError(t, mcpClient.Close(), "expected to close client successfully")
173+
}
174+
175+
func TestToolsets(t *testing.T) {
176+
mcpClient := setupMCPClient(
177+
t,
178+
WithEnvVars(map[string]string{
179+
"GITHUB_TOOLSETS": "repos,issues",
180+
}),
181+
)
182+
183+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
184+
defer cancel()
185+
186+
request := mcp.ListToolsRequest{}
187+
response, err := mcpClient.ListTools(ctx, request)
188+
require.NoError(t, err, "expected to list tools successfully")
189+
190+
// We could enumerate the tools here, but we'll need to expose that information
191+
// declaratively in the MCP server, so for the moment let's just check the existence
192+
// of an issue and repo tool, and the non-existence of a pull_request tool.
193+
var toolsContains = func(expectedName string) bool {
194+
return slices.ContainsFunc(response.Tools, func(tool mcp.Tool) bool {
195+
return tool.Name == expectedName
196+
})
197+
}
198+
199+
require.True(t, toolsContains("get_issue"), "expected to find 'get_issue' tool")
200+
require.True(t, toolsContains("list_branches"), "expected to find 'list_branches' tool")
201+
require.False(t, toolsContains("get_pull_request"), "expected not to find 'get_pull_request' tool")
170202
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy