[BUG] MCP server connection fails with error -32000: Connection closed (race condition)
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?
MCP servers fail to connect with MCP error -32000: Connection closed. The server starts correctly and responds to MCP protocol when tested manually, but Claude Code's connection drops before completing the handshake.
This is a re-filing of previously auto-closed issues that were never actually fixed:
- #3071 (auto-closed due to inactivity)
- #3184 (auto-closed, was assigned to @ashwin-ant)
- #3634 (auto-closed due to inactivity)
- #12449 (closed as duplicate of #3071)
Evidence This Is a Race Condition (Not Server Issue)
- SSH tunnel verified working -
lsof -i :5522confirms tunnel is active - Direct mysql2 connection works:
``javascript``
const conn = await mysql.createConnection({host: '127.0.0.1', port: 5522, ...});
// Result: Connected successfully! Query result: [ { test: 1 } ]
- MCP server starts correctly when tested manually:
````
[mcp-mysql] Starting with config: { host: '127.0.0.1', port: 5522, ... }
[mcp-mysql] Server connected and ready
- MCP protocol handshake works when tested directly:
``bash``
echo '{"jsonrpc":"2.0","id":1,"method":"initialize",...}' | node index.js
# Returns valid response with tools
- Multiple packages all fail identically:
@benborla29/mcp-server-mysql@2.0.7❌@benborla29/mcp-server-mysql@1.0.21❌@sajithrw/mcp-mysql@1.0.0❌@liangshanli/mcp-server-mysql@3.0.0❌- Custom local server with no stdout pollution ❌
Debug Log Evidence
2026-01-25T00:28:17.650Z [DEBUG] MCP server "mysql": Starting connection with timeout of 30000ms
2026-01-25T00:28:24.193Z [DEBUG] MCP server "mysql": Connection failed after 6544ms: MCP error -32000: Connection closed
The server process starts but Claude Code closes the connection before the MCP handshake completes.
What Should Happen?
MCP server should connect successfully when the server is running and responding correctly to the MCP protocol.
Error Messages/Logs
MCP error -32000: Connection closed
Steps to Reproduce
- Configure any MCP server in
.mcp.json - Ensure the server works when tested manually (stdin/stdout JSON-RPC)
- Run
/mcpin Claude Code - Observe: "Failed to reconnect to mysql" with error -32000 in debug logs
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.19
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
Environment:
- Node.js: v25.2.1
- macOS Darwin 25.3.0
Workarounds attempted (all failed):
- Clearing npx cache
- Using different MCP server packages
- Creating custom local MCP server with no stdout pollution
- Adding explicit PATH and cwd to mcp.json
- Renaming mcp.json to .mcp.json
Related external resources:
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗