Skip to content

Commit 7b7b45d

Browse files
committed
Merge branch 'http-routes' of https://github.com/github/github-mcp-server into http-routes
2 parents 1d7e656 + a92b77b commit 7b7b45d

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

pkg/context/request.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,19 @@ func GetToolsets(ctx context.Context) []string {
3333
}
3434
return nil
3535
}
36+
37+
// toolsCtxKey is a context key for tools
38+
type toolsCtxKey struct{}
39+
40+
// WithTools adds the tools to the context
41+
func WithTools(ctx context.Context, tools []string) context.Context {
42+
return context.WithValue(ctx, toolsCtxKey{}, tools)
43+
}
44+
45+
// GetTools retrieves the tools from the context
46+
func GetTools(ctx context.Context) []string {
47+
if tools, ok := ctx.Value(toolsCtxKey{}).([]string); ok {
48+
return tools
49+
}
50+
return nil
51+
}

pkg/http/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func InventoryFiltersForRequest(r *http.Request, builder *inventory.Builder) *in
177177
builder = builder.WithToolsets(toolsets)
178178
}
179179

180-
if tools := headers.ParseCommaSeparated(r.Header.Get(headers.MCPToolsHeader)); len(tools) > 0 {
180+
if tools := ghcontext.GetTools(ctx); len(tools) > 0 {
181181
if len(ghcontext.GetToolsets(ctx)) == 0 {
182182
builder = builder.WithToolsets([]string{})
183183
}

pkg/http/handler_test.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88

99
ghcontext "github.com/github/github-mcp-server/pkg/context"
10-
"github.com/github/github-mcp-server/pkg/http/headers"
1110
"github.com/github/github-mcp-server/pkg/inventory"
1211
"github.com/modelcontextprotocol/go-sdk/mcp"
1312
"github.com/stretchr/testify/assert"
@@ -38,7 +37,6 @@ func TestInventoryFiltersForRequest(t *testing.T) {
3837
tests := []struct {
3938
name string
4039
contextSetup func(context.Context) context.Context
41-
headers map[string]string
4240
expectedTools []string
4341
}{
4442
{
@@ -61,22 +59,18 @@ func TestInventoryFiltersForRequest(t *testing.T) {
6159
expectedTools: []string{"get_file_contents", "create_repository"},
6260
},
6361
{
64-
name: "context toolset takes precedence over header",
62+
name: "tools alone clears default toolsets",
6563
contextSetup: func(ctx context.Context) context.Context {
66-
return ghcontext.WithToolsets(ctx, []string{"repos"})
67-
},
68-
headers: map[string]string{
69-
headers.MCPToolsetsHeader: "issues",
64+
return ghcontext.WithTools(ctx, []string{"list_issues"})
7065
},
71-
expectedTools: []string{"get_file_contents", "create_repository"},
66+
expectedTools: []string{"list_issues"},
7267
},
7368
{
7469
name: "tools are additive with toolsets",
7570
contextSetup: func(ctx context.Context) context.Context {
76-
return ghcontext.WithToolsets(ctx, []string{"repos"})
77-
},
78-
headers: map[string]string{
79-
headers.MCPToolsHeader: "list_issues",
71+
ctx = ghcontext.WithToolsets(ctx, []string{"repos"})
72+
ctx = ghcontext.WithTools(ctx, []string{"list_issues"})
73+
return ctx
8074
},
8175
expectedTools: []string{"get_file_contents", "create_repository", "list_issues"},
8276
},
@@ -85,9 +79,6 @@ func TestInventoryFiltersForRequest(t *testing.T) {
8579
for _, tt := range tests {
8680
t.Run(tt.name, func(t *testing.T) {
8781
req := httptest.NewRequest(http.MethodGet, "/", nil)
88-
for k, v := range tt.headers {
89-
req.Header.Set(k, v)
90-
}
9182
req = req.WithContext(tt.contextSetup(req.Context()))
9283

9384
builder := inventory.NewBuilder().

pkg/http/middleware/request_config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ func WithRequestConfig(next http.Handler) http.Handler {
2222
ctx = ghcontext.WithToolsets(ctx, toolsets)
2323
}
2424

25+
if tools := headers.ParseCommaSeparated(r.Header.Get(headers.MCPToolsHeader)); len(tools) > 0 {
26+
ctx = ghcontext.WithTools(ctx, tools)
27+
}
28+
2529
next.ServeHTTP(w, r.WithContext(ctx))
2630
})
2731
}

0 commit comments

Comments
 (0)