fix(mcp): spawn bundled MCP servers on pull_request events#1261
Open
MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
Open
fix(mcp): spawn bundled MCP servers on pull_request events#1261MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
MukundaKatta wants to merge 1 commit intoanthropics:mainfrom
Conversation
The action prepends its bundled MCP servers (github_comment, github_ci,
github_inline_comment, github_file_ops, optional github) as a single
`--mcp-config '{...}'` flag inside claudeArgs. Earlier this stayed in
extraArgs["mcp-config"] for the SDK to forward to the spawned Claude
CLI subprocess. Multiple users have reported that the spawned CLI's
session init reports `mcp_servers: []` even though extraArgs is
correctly populated, so the bundled servers silently never register
and the action falls back to denying tools like
mcp__github_comment__update_claude_comment.
Lift inline JSON --mcp-config values onto sdkOptions.mcpServers — the
SDK's typed, in-process registration path used by Anthropic's own SDK
demos. File-path --mcp-config values stay in extraArgs so the CLI
loads and merges them alongside what the SDK already registered. User
inline JSON merges with action-prepended servers exactly like before,
with later flags winning on key conflict.
Closes anthropics#1245
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Closes #1245. On
pull_requestevents with the action's bundled MCP servers, the spawned Claude CLI's session init reportsmcp_servers: []andmcp__github_comment__update_claude_comment(and friends) are unavailable, so the tracking comment never updates. The action's tag-mode plumbing is correct: it builds the JSON viaprepareMcpConfig, escapes it into--mcp-config '{...}'insideclaudeArgs, andparseClaudeArgsToExtraArgskeeps it inextraArgs["mcp-config"]— but the spawned binary doesn't end up registering those servers. Same shape reported in #1191 for an external (Notion) MCP server passed inline.The cleanest fix is to bypass the brittle stringified-JSON CLI hop: route inline
--mcp-configJSON toOptions.mcpServers(the SDK's typed in-process registration path used by Anthropic's own SDK demos) and let only file-path values continue through the CLI flag.What
base-action/src/parse-sdk-options.ts:splitMcpConfigs()returns{ inlineServers, filePath }from accumulated--mcp-configvalues (replacesmergeMcpConfigs()).mcpServersontosdkOptions.mcpServers. DropextraArgs["mcp-config"]when the only values were inline JSON; keep it when the user also passed a file path.base-action/test/parse-sdk-options.test.ts: rewrites themcp-configblock to assert the new routing — inline JSON lands onsdkOptions.mcpServers, file paths stay inextraArgs["mcp-config"], mixed inputs split cleanly. Adds amcpServers === undefinedcase.No changes to
src/mcp/install-mcp-server.ts,src/modes/tag/index.ts, orsrc/modes/agent/index.ts— those keep building the same--mcp-config '{...}'string. The fix lives entirely in the parsing layer.Tested
bun test base-action/test/parse-sdk-options.test.ts— 28 pass, 0 fail. New 8-testmcp-config routingblock covers single inline, multi-inline merge, three-way merge, file-path-only, mixed inline+file, inline-with-other-flags, the bug-report scenario (action + user inline), and the no-mcp-config case.bun test— 665/666 pass. The single failure isvalidate-env > Direct Anthropic API > should fail when ANTHROPIC_API_KEY is missingin my local shell becauseCLAUDE_CODE_OAUTH_TOKENis set in env, unrelated to this change. CI will run with a clean env.Manual repro for the original bug is the workflow in #1245 (
pull_requestevent, default config,track_progress: true). With this change, the bundledgithub_comment/github_ci/github_file_opsservers appear inmcp_serverson session init and the tracking comment updates as expected.