Skip to content
Nilay Kabariya

Entry No.032·Agents··3 min read

Fix: MCP error -32000 Connection closed / Failed to connect

An MCP server fails with Connection closed or Failed to connect and never says why. Where the real error is hiding, and the fixes, tested in Claude Code.

by Nilay#mcp#claude-code#nodeAGENTS

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
✓ Reproduced on Windows 11 Pro

Tested on

MCP TypeScript SDK
1.31.0
Claude Code
2.1.138
Node
24.14.0
OS
Windows 11 Pro
Contents
  1. The fix01
  2. The causes I reproduced02
  3. Two popular fixes that weren’t needed03
  4. How this was tested04

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 list

Each 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 set

3. 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" }
    }
  }
}

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

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.041

    Fix: Claude Code "Prompt is too long"

    Claude Code fails every message with Prompt is too long, or asks for usage credits. One oversized file did both in my tests, and Claude Code's guard missed it.

    > Prompt is too long

    AGENTS4 min
  2. No.038

    Fix: Claude Code "not compatible with the version of Windows"

    Windows says claude.exe won't run right after an npm install of Claude Code. Your Windows is fine. Reproduced on npm 12, with the reinstall that fixed it.

    > This version of C:\...\claude-code\bin\claude.exe is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.

    AGENTS3 min
  3. No.037

    Fix: Claude Code "Invalid API key" and "Please run /login"

    A bad key can freeze Claude Code for 3 minutes before it errors. Every auth message reproduced, the Windows quoting trap, and what auth status hides.

    > Invalid API key · Fix external API key

    AGENTS4 min

Post card · Newsletter

Get the next fix in your inbox.

One short email when a new entry is published. No spam, never shared, and you can leave any time.

— Nilay

or follow by RSSor on X

By subscribing you agree to the privacy note. One click to leave.

tip: paste the exact error text