fix: add MCP migration helper and subagent connectivity pre-check#1
fix: add MCP migration helper and subagent connectivity pre-check#1Tibsfox wants to merge 3 commits intodev-bugfixfrom
Conversation
Add /gsd:migrate-mcp slash command that reads project .mcp.json, displays configured servers, and offers to merge them into ~/.claude/mcp.json (global scope). This provides the primary workaround for Claude Code bug #13898 where project-scoped MCP servers don't propagate to custom subagents. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add <mcp_check> block to every agent that instructs them to verify MCP tool availability before use, report clearly when unavailable instead of hallucinating results, and reference /gsd:migrate-mcp as the fix. Placed after </project_context> or </role> depending on agent structure. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
b1225d8 to
f32bfa1
Compare
Code Logic Verification of PR #1PR: feat: add MCP migration helper and subagent connectivity pre-check 1. The Before State (Bug Path)Claude Code bug #13898 prevents project-scoped MCP servers (
Affected agents: Primarily 2. The After State (Fix Path)The PR applies a belt-and-suspenders approach: fix the root cause (migration command) + add runtime resilience (pre-check blocks). Component A — New user-facing command
Edge cases handled: missing Component B — Identical block inserted in all 11
Block placement verified via MD5 checksum — all 11 are byte-identical. Architecturally correct: fires after identity/context, before workflow execution. 3. Key Correctness Checks
4. VerdictPASS — The PR addresses a real platform bug (#13898) with a sound two-component architecture: a user-facing migration command that fixes the root cause, plus runtime pre-check blocks that provide graceful degradation. Code trace confirms clean implementation: 12 files, 249 insertions, 0 deletions, consistent block placement, correct architectural ordering. Noted concerns (non-blocking, suitable for follow-up):
These are improvements, not blockers. The current implementation is safe and functional. Upstream: gsd-build/get-shit-done#814 — open and mergeable. Verification performed using parallel adversarial review, security analysis, and code trace teams. - Tibsfox ^.^ |
… agents Five improvements to the MCP migration helper and agent mcp_check blocks: 1. Add AskUserQuestion to migrate-mcp allowed-tools (needed for conflict resolution prompts) 2. Remove Bash from allowed-tools; reword 3 steps to use Read tool instead of cat commands 3. Add backup step: write ~/.claude/mcp.json.pre-migrate before overwriting existing config 4. Fix mcp_check wording: "check tool listings to confirm accessibility" instead of "attempt to list or call the expected MCP tool" — agents should not invoke MCP tools just to test them 5. Remove mcp_check from 7 agents that never use MCP tools (plan-checker, integration-checker, research-synthesizer, verifier, roadmapper, debugger, codebase-mapper); keep in the 4 that do (planner, executor, phase-researcher, project-researcher) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
/gsd:migrate-mcpcommand that guides users through migrating project-scoped MCP servers (.mcp.json) to global scope (~/.claude/mcp.json) — the proven workaround for Claude Code bug #13898<mcp_check>connectivity pre-check block to all 11 GSD agent definitions, preventing subagents from silently hallucinating MCP results when project-scoped servers are inaccessibledocs/MCP-FRONTMATTER-FINDINGS.mdRoot Cause
Claude Code bug #13898 prevents custom subagents (agents defined in
.claude/agents/or~/.claude/*/agents/) from accessing project-scoped MCP servers configured in.mcp.json. When a subagent attempts to use an MCP tool (e.g.,mcp__context7__*,mcp__slack__*), the call silently fails and the agent hallucinate results rather than reporting an error. Global MCP servers (~/.claude/mcp.json) propagate correctly to all agent types.The
mcpServers:frontmatter field was investigated as an alternative solution (seedocs/MCP-FRONTMATTER-FINDINGS.md). While it works for project-specific agents in.claude/agents/, it cannot solve GSD's problem because GSD agents are generic templates installed globally — we cannot hardcode user-specific MCP server configurations into them.Fix
Two complementary, defense-in-depth changes:
1.
/gsd:migrate-mcpcommand (commands/gsd/migrate-mcp.md, +117 lines)A guided 5-step interactive command that:
.mcp.jsonand displays discovered servers~/.claude/mcp.json(if it exists)Handles edge cases: missing
.mcp.json, empty configs, conflicting server names with interactive resolution, and idempotent re-runs.2. MCP connectivity pre-check in all 11 agents (+12 lines each, +132 lines total)
Adds a
<mcp_check>block after each agent's<role>or<project_context>section with four directives:/gsd:migrate-mcp)Agents modified:
gsd-codebase-mapper,gsd-debugger,gsd-executor,gsd-integration-checker,gsd-phase-researcher,gsd-plan-checker,gsd-planner,gsd-project-researcher,gsd-research-synthesizer,gsd-roadmapper,gsd-verifierRelationship to Other PRs
This is PR-1 of 6 from the
dev-bugfixbranch. It is the only PR that targetsdev-bugfix(the others targetmain):dev-bugfixmainmainmainmainmainMerge order recommendation: Merge PR #5 to
mainfirst (addsmcpServers:frontmatter to agents), then mergedev-bugfixtomain, then this PR todev-bugfix. The<mcp_check>blocks added here do not conflict with PR #5's frontmatter additions — they modify different sections of the agent files.Relationship to PR #5: PR #5 adds YAML frontmatter (including
mcpServers:field support) and anti-heredoc instructions to agent files. This PR adds<mcp_check>blocks in the agent body. Both modify the same 11 agent files but in non-overlapping sections — frontmatter vs. body content.Testing
/gsd:migrate-mcpis a prompt-based command (markdown instruction file), not executable code. It cannot be unit-tested. The test plan is manual:Manual Test Plan
/gsd:migrate-mcpin a project with.mcp.jsoncontaining 2+ servers — verify it reads config, displays server table, presents merge plan, and writes to~/.claude/mcp.json/gsd:migrate-mcpin a project without.mcp.json— verify graceful "no servers found" message with guidance/gsd:migrate-mcpwhen~/.claude/mcp.jsonalready has some servers — verify correct ADD/SKIP/CONFLICT classification/gsd:migrate-mcpwhen project and global configs have identical servers — verify SKIP (idempotent)/gsd:migrate-mcpwhen project and global configs have conflicting servers (same name, different config) — verify CONFLICT resolution prompt<mcp_check>block is present in all 11 agent.mdfilesgsd-executor) in a project with only project-scoped MCP — verify the pre-check catches itRegression Test Suite
Full test suite passes with no regressions:
Test suites include agent frontmatter validation (47 tests), anti-heredoc verification, spawn consistency checks, and command structure validation — all passing.
Impact
/gsd:migrate-mcp) resolves the issue.<mcp_check>block is a no-op when MCP tools are available. The command is opt-in.Future Considerations
/gsd:migrate-mcpbecomes optional (nice-to-have convenience rather than required workaround). The<mcp_check>blocks remain useful as defense-in-depth regardless.mcpServers:frontmatter for project agents: Users with project-specific custom agents (.claude/agents/) can addmcpServers:directly to their frontmatter today. This doesn't help GSD's globally-installed templates but is a valid approach for per-project agents./gsd:health --mcp-check: A future health command could auto-detect whether #13898 is fixed by testing MCP propagation to a subagent, eliminating the need for users to know about the bug at all.Addresses: BUG-5 (Global MCP Migration Helper), MCP Connectivity Pre-Check
Upstream: Claude Code #13898