Bug Description
After PR #1640 (inject deps via context instead of closures), the stdio server panics on any tool call:
panic: ToolDependencies not found in context; use ContextWithDeps to inject
Root Cause
In internal/ghmcp/server.go, NewMCPServer() creates deps at line ~196-204 and passes them to inventory.RegisterAll(), but the new context-based tool handlers created by NewServerToolWithContextHandler expect deps to be in context via MustDepsFromContext(ctx).
No middleware injects deps into context before tool handlers execute.
Fix
Add middleware after deps creation (~line 205):
ghServer.AddReceivingMiddleware(func(next mcp.MethodHandler) mcp.MethodHandler {
returnfunc(ctx context.Context, methodstring, req mcp.Request) (mcp.Result, error) {
returnnext(github.ContextWithDeps(ctx, deps), method, req)
}
})Affected Versions
Reproduction
export GITHUB_PERSONAL_ACCESS_TOKEN=$TOKENecho'{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"0.1.0","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_me","arguments":{}}}'| ./github-mcp-server stdioWorkaround
Build from source with the above fix applied.
Bug Description
After PR #1640 (inject deps via context instead of closures), the stdio server panics on any tool call:
Root Cause
In
internal/ghmcp/server.go,NewMCPServer()creates deps at line ~196-204 and passes them toinventory.RegisterAll(), but the new context-based tool handlers created byNewServerToolWithContextHandlerexpect deps to be in context viaMustDepsFromContext(ctx).No middleware injects deps into context before tool handlers execute.
Fix
Add middleware after deps creation (~line 205):
Affected Versions
Reproduction
Workaround
Build from source with the above fix applied.