claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

MCP tool schemas loaded from permissions even when server is not configured or removed

Open pbohannon opened this issue 1 week ago • 0 comments

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

  1. User configured desktop-commander MCP server in Project A
  2. Used tools from that server, adding mcp__desktop-commander__* entries to permissions.allow
  3. Later removed the server configuration from .claude.json
  4. In a fresh session in a different project (Project B), Claude still had access to desktop-commander tool schemas
  5. /mcp command shows no desktop-commander server configured
  6. Yet the model's context included full tool definitions (~1-2k tokens)
  7. 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

  1. Add an MCP server (e.g., desktop-commander) to a project
  2. Use tools from it so they get added to permissions.allow in ~/.claude/settings.json
  3. Remove the server configuration from .claude.json
  4. Start a fresh Claude Code session (different project or same project)
  5. Run /mcp to confirm the server is not listed
  6. Ask the model: "Do you have tools for desktop-commander?"
  7. Observe that the model still believes it has access to the removed server's tools
  8. Manually remove mcp__desktop-commander__* entries from settings files
  9. Start fresh session - tools are now gone

Suggested Fix

  1. Schema loading gate: Before loading tool schemas, verify the corresponding MCP server is currently configured and connected
  2. Permission validation: Cross-reference permissions.allow entries with currently available MCP servers and skip loading schemas for non-existent tools
  3. Optional cleanup: Consider a command like claude mcp prune that removes orphaned permission entries

pbohannon avatar Dec 31 '25 16:12 pbohannon