Skip to content

Commit 3ddc84d

Browse files
authored
initialize description depending on the host
1 parent 96369b1 commit 3ddc84d

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

pkg/http/server.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ func RunHTTPServer(cfg ServerConfig) error {
129129
if err != nil {
130130
return fmt.Errorf("failed to parse API host: %w", err)
131131
}
132+
hostType, err := utils.ParseHostType(cfg.Host)
133+
if err != nil {
134+
return fmt.Errorf("failed to classify API host: %w", err)
135+
}
132136

133137
repoAccessOpts := []lockdown.RepoAccessOption{
134138
lockdown.WithLogger(logger.With("component", "lockdown")),
@@ -156,7 +160,7 @@ func RunHTTPServer(cfg ServerConfig) error {
156160
)
157161

158162
// Initialize the global tool scope map
159-
err = initGlobalToolScopeMap(t)
163+
err = initGlobalToolScopeMap(t, hostType)
160164
if err != nil {
161165
return fmt.Errorf("failed to initialize tool scope map: %w", err)
162166
}
@@ -239,10 +243,10 @@ func resolveListenAddress(host string, port int) string {
239243
return net.JoinHostPort(host, strconv.Itoa(port))
240244
}
241245

242-
func initGlobalToolScopeMap(t translations.TranslationHelperFunc) error {
246+
func initGlobalToolScopeMap(t translations.TranslationHelperFunc, hostType utils.HostType) error {
243247
// Build inventory with all tools to extract scope information
244248
inv, err := inventory.NewBuilder().
245-
SetTools(github.AllTools(t)).
249+
SetTools(github.AllTools(t, github.WithHost(hostType))).
246250
Build()
247251

248252
if err != nil {

pkg/http/server_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,48 @@ import (
66

77
ghcontext "github.com/github/github-mcp-server/pkg/context"
88
"github.com/github/github-mcp-server/pkg/github"
9+
"github.com/github/github-mcp-server/pkg/utils"
910
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
1112
)
1213

14+
func TestInitGlobalToolScopeMapUsesHost(t *testing.T) {
15+
tests := []struct {
16+
name string
17+
hostType utils.HostType
18+
want string
19+
}{
20+
{
21+
name: "dotcom uses semantic search",
22+
hostType: utils.HostTypeDotcom,
23+
want: "Search issues using natural-language semantic matching. Best for conceptual or paraphrased queries (e.g. \"login fails after password reset\"). Already scoped to is:issue.",
24+
},
25+
{
26+
name: "GHES uses lexical search",
27+
hostType: utils.HostTypeGHES,
28+
want: "Search for issues in GitHub repositories using issues search syntax already scoped to is:issue",
29+
},
30+
}
31+
32+
for _, tt := range tests {
33+
t.Run(tt.name, func(t *testing.T) {
34+
translations := make(map[string]string)
35+
translator := func(key, defaultValue string) string {
36+
if value, ok := translations[key]; ok {
37+
return value
38+
}
39+
translations[key] = defaultValue
40+
return defaultValue
41+
}
42+
43+
require.NoError(t, initGlobalToolScopeMap(translator, tt.hostType))
44+
45+
tool := github.SearchIssues(translator, github.WithHost(tt.hostType))
46+
assert.Equal(t, tt.want, tool.Tool.Description)
47+
})
48+
}
49+
}
50+
1351
func TestCreateHTTPFeatureChecker(t *testing.T) {
1452
tests := []struct {
1553
name string

0 commit comments

Comments
 (0)