MCP error -32000: Connection closed" — server works standalone, dies under Claude Code

custom mcp server connects totally fine when i run it manually pipe an initialize request at it, get a clean response back, full tool list, zero issues. the second i put it in claude code’s config and start a session i get MCP error -32000: Connection closed. claude mcp list even shows it as “connected” right up until it tries to actually grab the tools,

then it just dies. no stack trace, nothing useful in the logs at all. it’s stdio, launched with npx.

so you’re not just guessing run the server standalone but using the exact command from your config, copy paste it, don’t retype it from memory. sometimes the version you run manually and the version in the config differ by one flag you forgot was even there, and that’s the whole gap.

also, if this was working before and just broke mid-session, check if it happened right after claude code auto-compacted. compaction can leave a server showing as “connected” in the UI but the tool bindings are quietly gone. running /mcp forces a reconnect and fixes that specific case without touching your actual server config at all.

-32000: Connection closed basically means the process claude code spawned died before the handshake finished — it’s not a timeout or a refused connection, the thing actually exited. since it works fine when you run it yourself, this is almost certainly a race condition specific to how claude code spawns the process. two things to check:

you’re probably relying on npx resolving off your shell PATH, and claude code’s spawn environment doesn’t always inherit your full PATH. point the config at the absolute binary path instead (which npx to find it).
if you’re on an odd-numbered node version (21, 23, etc), there’s a known timing issue with how the event loop exits under async stdio — worth pinning to an even LTS like 20 or 22.

try the absolute path first, it’s the quicker one to test.

1 Like

yeah, it was the path thing…. npx wasn’t resolving the same way under claude code’s spawn env. absolute path fixed it right away. that exact-command check is just part of my process now honestly, good catch salman bro.. :+1: :+1: :+1:

1 Like