The error, verbatim
Jump to the fix ↓MCP error -32000: Connection closed
# the same servers in `claude mcp list`:
crash: node .../crash.mjs - ✗ Failed to connect
needkey: node .../needkey.mjs - ✗ Failed to connect
badcmd: nonexistent-command-xyz - ✗ Failed to connect
Tested on
- MCP TypeScript SDK
- 1.31.0
- Claude Code
- 2.1.138
- Node
- 24.14.0
- OS
- Windows 11 Pro
Contents
Connection closed means the MCP server process ended before it finished talking to the client. The client only sees that the pipe closed, so the message never says why. The reason is almost always printed by the server itself, somewhere you aren’t looking.
The fix
1. Find which server fails. In Claude Code:
claude mcp listEach server gets a line ending in ✓ Connected or ✗ Failed to connect.
2. Run that server’s command yourself, exactly as it’s written in your MCP config, in a normal terminal. Whatever made it exit gets printed there:
> node crash.mjs
Error: config file not found
> node needkey.mjs
DEMO_API_KEY is not set3. Fix that cause. The three I reproduced are in the next section, with the fix for each.
The causes I reproduced
Each of these gave the same -32000: Connection closed from the official MCP TypeScript SDK client, and ✗ Failed to connect in Claude Code:
| The server… | What running it by hand shows | Fix |
|---|---|---|
| crashes on start (bad import, missing file, bad config) | the exception, e.g. Error: config file not found |
fix the crash; it’s the server’s bug or setup |
| needs an API key that isn’t set | its own message, e.g. DEMO_API_KEY is not set |
put the key in the server’s env in your MCP config |
| has a command that doesn’t exist | 'nonexistent-command-xyz' is not recognized as an internal or external command (Windows) |
fix the command, or install the tool it names |
The missing key is the one people trip on most, because the key is usually set in their own terminal but not passed to the server. MCP hosts start servers themselves, so set it in the config:
{
"mcpServers": {
"my-server": {
"command": "node",
"args": ["C:/path/to/server.mjs"],
"env": { "DEMO_API_KEY": "your-key-here" }
}
}
}
Two popular fixes that weren’t needed
How this was tested
Small MCP servers built with the official TypeScript SDK 1.31.0, each broken one way on purpose: one that throws on start, one that exits without its API key, one with a command that doesn’t exist, and one that logs to stdout. Each was connected from the SDK’s own stdio client and listed with claude mcp list in Claude Code 2.1.138, using a project .mcp.json, on Windows 11 with Node 24.14.0. The Windows npx check used the official @modelcontextprotocol/server-everything package. Every message above is copied from those runs.
— N.K., end of entry No.032