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

Tool Duplication in MCP SSE Server Connections Across Projects

Open joemocha opened this issue 7 months ago • 6 comments

Bug Report: MCP SSE Server Tool Duplication in Claude Code

Summary

Claude Code exhibits tool duplication when the same MCP SSE server is configured across multiple projects. Tools from the MCP server accumulate rather than being properly isolated per project, resulting in duplicate tool listings.

Environment

  • Claude Code Version: Current (as of 2025-06-14)
  • OS: Linux 6.8.0-60-generic
  • MCP Server Type: SSE (Server-Sent Events)

Steps to Reproduce

  1. Configure an MCP SSE server in Project A (e.g., /home/foo/docker)

    "mcpServers": {
      "context7": {
        "type": "sse",
        "url": "http://mcp.foo.dev/context7/sse"
      }
    }
    
  2. Configure the same MCP SSE server in Project B (e.g., /home/foo/workbook/a2a-platform)

    "mcpServers": {
      "context7": {
        "type": "sse",
        "url": "http://mcp.foo.dev/context7/sse"
      }
    }
    
  3. Open Claude Code in Project A - observe correct tool count (e.g., 2 tools)

  4. Switch to Project B - observe duplicated tools (e.g., 4 tools instead of 2)

Expected Behavior

Each project should maintain isolated MCP connections. When switching projects, tools from the previous project's MCP servers should be cleared, and only the current project's MCP tools should be available.

Actual Behavior

Tools from MCP SSE servers persist across project sessions, causing duplicate tool registrations. The same server that correctly reports 2 tools shows 4 tools (2x duplication) in projects where the session state has accumulated.

Root Cause Analysis

The issue appears to be a session state management bug where:

  1. SSE connections or their tool registrations persist when switching between projects
  2. Tool registry is not properly cleared when changing project contexts
  3. Session data in ~/.claude/projects/[encoded-path]/*.jsonl retains duplicate tool information

Workaround

Clearing the session files resolves the issue temporarily:

rm ~/.claude/projects/[encoded-project-path]/*.jsonl

Technical Details

  • Configuration files (~/.claude.json) show correct, non-duplicated MCP server entries
  • The MCP server itself correctly reports the proper number of tools
  • The duplication occurs client-side in Claude Code's session management
  • Issue persists even after closing and reopening Claude Code sessions
  • Only affects SSE-type MCP servers (not confirmed for stdio-type)

Impact

This bug causes confusion as users see duplicate tools in the MCP tool list, potentially leading to:

  • Incorrect tool counts in the UI
  • Possible performance implications with duplicate SSE connections
  • User confusion about which tools are actually available

Suggested Fix

  1. Ensure SSE connections are properly terminated when switching project contexts
  2. Clear tool registry when loading a new project's MCP configuration
  3. Prevent accumulation of tool definitions in session state files
  4. Add proper isolation between project MCP connections

joemocha avatar Jun 14 '25 23:06 joemocha

On my installation, every tool is duplicated. It happens on context7 and deepwiki. Even with a fresh install.

jijijaco avatar Jun 15 '25 21:06 jijijaco

can confirm on my installation all are duplicated though its only in the IDE connector not in the normal terminal

mattbrandman avatar Jun 20 '25 21:06 mattbrandman

this is not isolated to SSE connections in my case and happens with locally defined tools as well.

On VS Code, on MacOs.

Bug Description Local tool definitions appear twice on Claude Code and not on other MCP clients. Can be seen on /mcp -> mcp-server -> tools. My local server has 5 tools, and only displays the 5 on Claude Desktop and other MCP clients like Cline, but will list them twice on Claude Code.

Environment Info

  • Platform: darwin
  • Terminal: vscode
  • Version: 1.0.31
  • Feedback ID: 69921681-da52-424e-b08d-1574951f2152

rodosaborio avatar Jun 21 '25 16:06 rodosaborio

I think this might happen when you add the MCP to the Claude Desktop app and the CLI with the same name (case-insensitive). I had the same issue but after adding the the server thorugh the CLI with a slightly different name it did not happen again.

SC-CTS avatar Jun 23 '25 14:06 SC-CTS

Me too, but I'm using the global configuration and have the same issue.

Image

/root/.claude.json

  "mcpServers": {
    "deepwiki": {
      "type": "http",
      "url": "https://mcp.deepwiki.com/mcp"
    },
    "zen": {
      "type": "stdio",
      "command": "/home/xx/work/zen-mcp-server/.zen_venv/bin/python",
      "args": [
        "/home/xx/work/zen-mcp-server/server.py"
      ],
      "env": {}
    }
  }

isCopyman avatar Jun 27 '25 10:06 isCopyman

can confirm on my installation all are duplicated though its only in the IDE connector not in the normal terminal

Yes, I noticed that after canceling/disconnecting the IDE, the number of tools returned to normal.

isCopyman avatar Jun 27 '25 10:06 isCopyman

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Oct 10 '25 10:10 github-actions[bot]