Stale deferred tool in session causes permanent 400 error after MCP server disconnect
Description
When an MCP server disconnects mid-session, its tools are removed from the active deferred-tools list — but some tools (specifically DesignSync in my case) are not cleaned up. The tool name remains in the deferred-tools system prompt injection for all subsequent turns, and the API rejects every request with a 400 because the tool is referenced but not in the actual tools array. The session becomes permanently broken with no way to recover it.
Steps to Reproduce
- Start a long-running session with MCP servers that provide deferred tools (e.g. a claude.ai MCP server providing
DesignSync) - During the session, run
/mcpor otherwise cause some MCP servers to disconnect - Observe that most of the disconnected server's tools are removed from the deferred-tools list via a
deferred_tools_deltawithremovedNames - Note that
DesignSync(and possibly others) are not added toremovedNamesdespite the server being gone - Submit any prompt — every subsequent turn errors immediately
Error
API Error: 400 Tool reference 'DesignSync' not found in available tools
Expected Behavior
When an MCP server disconnects, all of its tools should be removed from the deferred-tools list. If any tool can't be cleanly removed, the session should degrade gracefully rather than becoming permanently broken.
Actual Behavior
The stale tool name persists in the deferred-tools injection for the lifetime of the session. Every API call fails with a 400. The session cannot be recovered — a new session must be started.
Environment
- Claude Code version: 2.1.220
- Platform: Windows 11 Enterprise
- Session had been running for an extended period (~27 hours based on timestamps)
- The
DesignSynctool was initially added via adeferred_tools_deltaattachment, then not removed when its MCP server disconnected
Suggested Fix
When processing MCP server disconnects, ensure all tools from that server are included in removedNames in the deferred_tools_delta. Additionally, consider making the deferred-tools validation in the API request more resilient so a single missing tool doesn't hard-break the entire session.