Skip to content

Commit 50e33a4

Browse files
committed
Move ForMCPRequest call to HTTP handler & explicitly set capabilities
1 parent 2871761 commit 50e33a4

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

pkg/github/server.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99
"time"
1010

11-
ghcontext "github.com/github/github-mcp-server/pkg/context"
1211
gherrors "github.com/github/github-mcp-server/pkg/errors"
1312
"github.com/github/github-mcp-server/pkg/inventory"
1413
"github.com/github/github-mcp-server/pkg/octicons"
@@ -107,21 +106,16 @@ func NewMCPServer(ctx context.Context, cfg *MCPServerConfig, deps ToolDependenci
107106
cfg.Logger.Warn("Warning: unrecognized toolsets ignored", "toolsets", strings.Join(unrecognized, ", "))
108107
}
109108

110-
invToUse := inv
111-
if methodInfo, ok := ghcontext.MCPMethod(ctx); ok && methodInfo != nil {
112-
invToUse = inv.ForMCPRequest(methodInfo.Method, methodInfo.ItemName)
113-
}
114-
115109
// Register GitHub tools/resources/prompts from the inventory.
116110
// In dynamic mode with no explicit toolsets, this is a no-op since enabledToolsets
117111
// is empty - users enable toolsets at runtime via the dynamic tools below (but can
118112
// enable toolsets or tools explicitly that do need registration).
119-
invToUse.RegisterAll(ctx, ghServer, deps)
113+
inv.RegisterAll(ctx, ghServer, deps)
120114

121115
// Register dynamic toolset management tools (enable/disable) - these are separate
122116
// meta-tools that control the inventory, not part of the inventory itself
123117
if cfg.DynamicToolsets {
124-
registerDynamicTools(ghServer, invToUse, deps, cfg.Translator)
118+
registerDynamicTools(ghServer, inv, deps, cfg.Translator)
125119
}
126120

127121
return ghServer, nil

pkg/http/handler.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,22 +169,38 @@ func withInsiders(next http.Handler) http.Handler {
169169
}
170170

171171
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
172-
inventory, err := h.inventoryFactoryFunc(r)
172+
inv, err := h.inventoryFactoryFunc(r)
173173
if err != nil {
174174
w.WriteHeader(http.StatusInternalServerError)
175175
return
176176
}
177177

178-
ghServer, err := h.githubMcpServerFactory(r, h.deps, inventory, &github.MCPServerConfig{
178+
invToUse := inv
179+
if methodInfo, ok := ghcontext.MCPMethod(r.Context()); ok && methodInfo != nil {
180+
invToUse = inv.ForMCPRequest(methodInfo.Method, methodInfo.ItemName)
181+
}
182+
183+
ghServer, err := h.githubMcpServerFactory(r, h.deps, invToUse, &github.MCPServerConfig{
179184
Version: h.config.Version,
180185
Translator: h.t,
181186
ContentWindowSize: h.config.ContentWindowSize,
182187
Logger: h.logger,
183188
RepoAccessTTL: h.config.RepoAccessCacheTTL,
189+
// Explicitly set empty capabilities. inv.ForMCPRequest currently returns nothing for Initialize.
190+
ServerOptions: []github.MCPServerOption{
191+
func(so *mcp.ServerOptions) {
192+
so.Capabilities = &mcp.ServerCapabilities{
193+
Tools: &mcp.ToolCapabilities{},
194+
Resources: &mcp.ResourceCapabilities{},
195+
Prompts: &mcp.PromptCapabilities{},
196+
}
197+
},
198+
},
184199
})
185200

186201
if err != nil {
187202
w.WriteHeader(http.StatusInternalServerError)
203+
return
188204
}
189205

190206
mcpHandler := mcp.NewStreamableHTTPHandler(func(_ *http.Request) *mcp.Server {

0 commit comments

Comments
 (0)