[BUG] MCP Server Connection Race Condition - Connections closed immediately after establishment

Resolved 💬 3 comments Opened Nov 26, 2025 by softganz88 Closed Nov 29, 2025

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When I try to connect MCP servers on startup, Claude shows connection succeeding then
immediately closing within 1ms. The connection is established but tools fail to fetch
with error "MCP error -32000: Connection closed".

Log shows:

  • "Successfully connected to undefined server in 136ms"
  • "Connection closed after 0s (cleanly)" - just 1ms later!
  • "Failed to fetch tools: MCP error -32000: Connection closed"

What Should Happen?

MCP servers should connect reliably on startup without requiring manual intervention via /mcp reconnect.

Error Messages/Logs

{"debug": "Successfully connected to undefined server in 136ms", "timestamp":
"2025-11-26T07:43:16.263Z"}
{"debug": "UNKNOWN connection closed after 0s (cleanly)", "timestamp":
"2025-11-26T07:43:16.264Z"}
{"error": "Failed to fetch tools: MCP error -32000: Connection closed", "timestamp":
"2025-11-26T07:43:16.267Z"}

Steps to Reproduce

  1. Install project-health-auditor plugin from claude-code-plugins-plus marketplace
  2. Start Claude Code in any project directory
  3. Observe MCP server status - may show "failed"
  4. Check logs in ~/.cache/claude-cli-nodejs/<project-path>/mcp-logs-*/
  5. Use /mcp menu → Select server → "Reconnect" - should succeed (workaround works)

Claude Model

None

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.0.54

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Other

Additional Information

  • Node.js: v20.19.5
  • npm: 10.8.2
  • MCP SDK: @modelcontextprotocol/sdk ^0.7.0
  • Plugin: project-health-auditor from claude-code-plugins-plus
  • Manual reconnect via /mcp works reliably
  • Server name shows as "undefined" in logs despite being properly defined
  • Connection shows as "UNKNOWN" when closed, suggesting identity tracking issue
  • Issue is intermittent - sometimes works on first try

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗