"MCP error -32000: Connection closed" or "server transport closed unexpectedly" means the server process started and then exited before completing the MCP handshake. The client did not break — the server crashed. Here is how to find out why.
What the error really means
MCP stdio servers talk over standard input/output. If the process writes to stdout something that is not a valid MCP message, or exits on startup, the client sees the pipe close and reports "connection closed." So the fix is almost always: find why the server process is dying.
1. Run the command by hand
Copy the exact command + args from your config and run them in a terminal. You will see the real crash — a stack trace, "module not found", a missing env var, or an auth error. This single step solves most cases.
2. Check for a bad or missing argument
A wrong path, missing --dsn, or an unsupported flag makes many servers exit immediately. Compare your args against the server's README.
3. Verify the runtime
Most servers need Node 18+ (npx) or Python 3.10+ with uv/uvx. An old or missing runtime kills the process instantly. Check node --version / uvx --version.
4. Stop the server printing to stdout
If you wrote the server, anything you console.log to stdout corrupts the MCP stream and closes the connection. Log to stderr instead. This is the classic bug in custom servers.
5. Fix spawn ENOENT
A variant: the client cannot even find npx/node (PATH issue on macOS GUI apps). Use absolute paths in command. See Cursor MCP not working.
6. Check tokens and network
If the server authenticates on startup (database, API), a bad token or unreachable host makes it exit. Confirm credentials and connectivity.
Still failing?
Run the command standalone (#1) and read the actual error — it is almost never generic. Client-specific guides: Claude Desktop MCP not loading, Windsurf MCP not connecting. Building your own server? Start from build your first MCP server.