Skip to content

v0.26.0+ stdio mode panics: ToolDependencies not found in context #1646

@JayRMorris

Description

@JayRMorris

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 {
    return func(ctx context.Context, method string, req mcp.Request) (mcp.Result, error) {
        return next(github.ContextWithDeps(ctx, deps), method, req)
    }
})

Affected Versions

  • v0.26.0
  • v0.26.1

Reproduction

export GITHUB_PERSONAL_ACCESS_TOKEN=$TOKEN
echo '{"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 stdio

Workaround

Build from source with the above fix applied.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    SYSTEM_READY >> ...MS