Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix stdio mode panic: inject ToolDependencies into request context#1647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
SamMorrowDrums merged 2 commits intomainfromcopilot/fix-stdio-mode-panics
Dec 18, 2025

Conversation

Copy link
Contributor

CopilotAI commentedDec 18, 2025
edited
Loading

Summary

Stdio server panics with "ToolDependencies not found in context" on tool calls. After deps were refactored to context-based injection, middleware to inject them was missing.

Why

Tool handlers callMustDepsFromContext(ctx) but no middleware injects deps into the request context.

What changed

  • Added middleware inNewMCPServer() that wraps requests withgithub.ContextWithDeps(ctx, deps)
  • Added tests for server creation and toolset resolution logic
// Inject dependencies into context for all tool handlersghServer.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)    }})

MCP impact

  • No tool or API changes — Fixes runtime panic, no API surface changes

Prompts tested (tool changes only)

  • N/A

Security / limits

  • No security or limits impact — Middleware only propagates existing deps

Lint & tests

  • Linted locally with./script/lint
  • Tested locally with./script/test

Docs

  • Not needed — Internal fix, no user-facing changes
Original prompt

This section details on the original issue you should resolve

<issue_title>v0.26.0+ stdio mode panics: ToolDependencies not found in context</issue_title>
<issue_description>## 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

Ininternal/ghmcp/server.go,NewMCPServer() creates deps at line ~196-204 and passes them toinventory.RegisterAll(), but the new context-based tool handlers created byNewServerToolWithContextHandler expect 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):

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

  • v0.26.0
  • v0.26.1

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 stdio

Workaround

Build from source with the above fix applied.</issue_description>

Comments on the Issue (you are@copilot in this section)


✨ Let Copilot coding agentset things up for you — coding agent works faster and does higher quality work when set up for your repo.

The issue was that after PR#1640 switched from closure-based deps to context-based deps,the stdio server was missing middleware to inject ToolDependencies into the request context.This caused tools to panic with "ToolDependencies not found in context" when called.Added middleware in NewMCPServer() that wraps all requests with github.ContextWithDeps(),ensuring deps are available to tool handlers via MustDepsFromContext().Also added tests to verify server creation and toolset resolution logic.Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
CopilotAI changed the title[WIP] Fix stdio mode panics for tool dependenciesFix stdio mode panic: inject ToolDependencies into request contextDec 18, 2025
@SamMorrowDrumsSamMorrowDrums marked this pull request as ready for reviewDecember 18, 2025 20:50
@SamMorrowDrumsSamMorrowDrums requested a review froma team as acode ownerDecember 18, 2025 20:50
CopilotAI review requested due to automatic review settingsDecember 18, 2025 20:50
@SamMorrowDrumsSamMorrowDrums merged commit311d581 intomainDec 18, 2025
19 checks passed
@SamMorrowDrumsSamMorrowDrums deleted the copilot/fix-stdio-mode-panics branchDecember 18, 2025 20:50
Copy link
Contributor

CopilotAI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Pull request overview

This PR fixes a critical panic in stdio mode that occurs when any tool is called. The panic was introduced after refactoring to context-based dependency injection, where middleware to inject dependencies into the request context was inadvertently omitted.

Key changes:

  • Added middleware inNewMCPServer() to injectToolDependencies into the request context for all tool handlers
  • Added comprehensive tests for server creation and toolset resolution logic

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

FileDescription
internal/ghmcp/server.goAdds middleware after line 205 to inject deps into context viagithub.ContextWithDeps(ctx, deps) for all tool handlers
internal/ghmcp/server_test.goAdds new test file with tests for server creation (verifying middleware is configured) and toolset resolution logic

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

+1 more reviewer

@SamMorrowDrumsSamMorrowDrumsSamMorrowDrums approved these changes

Reviewers whose approvals may not affect merge requirements

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

2 participants

@SamMorrowDrums

[8]ページ先頭

©2009-2025 Movatter.jp