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

Bug: disabledMcpServers setting not enforced at session startup

Open bitr8 opened this issue 2 months ago • 3 comments

Bug: disabledMcpServers setting not enforced at session startup

Environment

  • Claude Code version: 2.0.61
  • OS: Fedora 43 (Linux 6.17.9)
  • Shell: bash

Description

MCP servers listed in disabledMcpServers are not actually disabled when starting a new Claude Code session. The setting is persisted correctly in ~/.claude.json and the /mcp command shows them as disabled, but Claude can still connect to and use all the servers.

Steps to Reproduce

  1. Configure MCP servers globally in ~/.claude.json:
{
  "mcpServers": {
    "pixellab": { ... },
    "leonardo-ai": { ... },
    "gemini-cli": { ... },
    "chrome-devtools": { ... },
    "codex-cli": { ... }
  }
}
  1. Add all servers to disabledMcpServers for a project (either via /mcp toggle or programmatically):
{
  "projects": {
    "/home/rob/Projects/ziggurat": {
      "disabledMcpServers": [
        "leonardo-ai",
        "pixellab",
        "gemini-cli",
        "chrome-devtools",
        "codex-cli"
      ]
    }
  }
}
  1. Start a new Claude Code session in that project directory

  2. Run /mcp - shows all servers as disabled (correct)

  3. Ask Claude to check MCP server status with claude mcp list

Expected Behavior

  • Disabled MCP servers should not be connected
  • Claude should not have access to tools from disabled servers
  • claude mcp list should show disabled servers as disconnected or not listed

Actual Behavior

  • All 5 servers show as "✓ Connected" when running claude mcp list
  • Claude can see and invoke tools from all MCP servers
  • The disabledMcpServers setting is completely ignored at runtime

Evidence

Config in ~/.claude.json:

{
  "projects": {
    "/home/rob/Projects/ziggurat": {
      "disabledMcpServers": [
        "leonardo-ai",
        "pixellab",
        "gemini-cli",
        "chrome-devtools",
        "codex-cli"
      ]
    }
  }
}

Output of claude mcp list:

Checking MCP server health...

pixellab: https://api.pixellab.ai/mcp (HTTP) - ✓ Connected
leonardo-ai: https://mcp.leonardo.ai/v1/mcp (HTTP) - ✓ Connected
gemini-cli: npx -y gemini-mcp-tool - ✓ Connected
codex-cli: npx -y codex-mcp-server - ✓ Connected
chrome-devtools: npx chrome-devtools-mcp@latest - ✓ Connected

Related Issues

  • #12025 - Feature request to disable MCP servers globally and enable per-project
  • #4879 - Feature request for MCP Server Enable/Disable Toggle
  • #7068 - Feature request for enable/disable in /mcp command

Impact

Users cannot disable MCP servers per-project. This affects:

  • Projects that don't need certain MCP tools (unnecessary tool clutter)
  • Security/privacy (servers connect even when not wanted)
  • Token usage (disabled tools may still be included in context)

bitr8 avatar Dec 07 '25 16:12 bitr8

Found 1 possible duplicate issue:

  1. https://github.com/anthropics/claude-code/issues/9996

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Dec 07 '25 16:12 github-actions[bot]

Additional Testing Results (2025-12-08)

Finding 1: UI toggle doesn't persist either

Initially suspected only programmatic edits were ignored. Further testing confirms:

  1. Used /mcp UI to toggle all 5 servers OFF
  2. Verified disabledMcpServers array was updated in ~/.claude.json
  3. Started fresh Claude Code session
  4. Result: All 5 servers still show "✓ Connected" in claude mcp list

The /mcp UI toggle is also not respected - the bug affects both programmatic and UI-based disabling.

Finding 2: No config inheritance issue

Checked for parent path overrides:

  • Project path has all 5 servers in disabledMcpServers
  • No parent directory entry overriding the setting ✓
  • No disabledMcpServers in ~/.claude/settings.json

The config is correct - it's simply not being read/enforced at startup.

Finding 3: Token cost impact

"Connected" servers likely still:

  1. Spawn the MCP server process (npx runs on startup)
  2. Fetch tool schemas from each server
  3. Inject tool definitions into the system prompt

This means disabled servers are costing tokens on every request - tool definitions consume input tokens even when you never intend to use them. The bug isn't just about unwanted tool availability; it's actively wasting context window and increasing costs.


Re: Duplicate Detection

This is not a duplicate of #9996 - that issue is about plugin marketplace UI, not MCP server disabledMcpServers setting.

bitr8 avatar Dec 07 '25 16:12 bitr8