claude-code
claude-code copied to clipboard
MCP tool schemas loaded from permissions even when server is not configured or removed
Description
MCP tool permissions stored in ~/.claude/settings.json and ~/.claude/settings.local.json cause tool schemas to be loaded into the prompt context even when the corresponding MCP server is no longer configured or has been completely removed.
Environment
- OS: macOS
- Claude Code: Latest CLI version
Observed Behavior
- User configured
desktop-commanderMCP server in Project A - Used tools from that server, adding
mcp__desktop-commander__*entries topermissions.allow - Later removed the server configuration from
.claude.json - In a fresh session in a different project (Project B), Claude still had access to
desktop-commandertool schemas /mcpcommand shows nodesktop-commanderserver configured- Yet the model's context included full tool definitions (~1-2k tokens)
- After manually removing the orphaned
mcp__desktop-commander__*entries from settings files, the tools disappeared from the model's context
Expected Behavior
- Tool schemas should only load when the MCP server is actually configured and connected
- Permissions referencing non-existent MCP tools should be ignored during context building
- Disabled or removed servers should not have their tool schemas loaded into prompt
Impact
| Issue | Severity |
|---|---|
| Users pay token costs for unused tool definitions | Medium |
| Tools appear available but may fail when invoked | High |
/mcp command shows different state than actual model context |
Medium |
Reproduction Steps
- Add an MCP server (e.g.,
desktop-commander) to a project - Use tools from it so they get added to
permissions.allowin~/.claude/settings.json - Remove the server configuration from
.claude.json - Start a fresh Claude Code session (different project or same project)
- Run
/mcpto confirm the server is not listed - Ask the model: "Do you have tools for desktop-commander?"
- Observe that the model still believes it has access to the removed server's tools
- Manually remove
mcp__desktop-commander__*entries from settings files - Start fresh session - tools are now gone
Suggested Fix
- Schema loading gate: Before loading tool schemas, verify the corresponding MCP server is currently configured and connected
- Permission validation: Cross-reference
permissions.allowentries with currently available MCP servers and skip loading schemas for non-existent tools - Optional cleanup: Consider a command like
claude mcp prunethat removes orphaned permission entries