Shipping an AI app or agent? Security review in 1 working day: $149 / ₹13,900. Request a review →
AI Review Ready
Home / Error fixes / MCP error -32000
Fix · MCP

MCP error -32000: Connection closed

The client lost its connection to the MCP server before a response arrived. For a local (stdio) server that almost always means the server process exited: it crashed on startup, couldn't be launched, or broke the protocol by printing to stdout.

Fix it

  1. Run the server command yourself, exactly as your config has it (same command, args and env), in a terminal. If it prints an error and exits, that is your cause: a missing dependency, wrong path, missing API key or unsupported runtime version.
  2. Move every log line to stderr. On stdio, stdout carries only protocol messages. Use console.error in Node, print(..., file=sys.stderr) in Python, and check dependencies that print banners.
  3. Use absolute paths in command and args. Relative paths resolve against the folder the client was started from, not the config file's folder.
  4. Put required variables in the server's env block rather than relying on your shell's environment.
  5. Read the client's log. In Claude Code: /mcp for status, claude mcp get <name> for the Issue: line, and claude --debug=mcp to write the server's stderr to ~/.claude/debug/<session-id>.txt.
  6. If the server is just slow to start, raise the client's startup timeout. In Claude Code: MCP_TIMEOUT=10000 claude (10 seconds).

What -32000 actually is

JSON-RPC 2.0 reserves codes -32000 to -32099 for implementation-defined server errors. The official MCP SDKs use -32000 for their own ConnectionClosed error: the TypeScript SDK (v1, ErrorCode.ConnectionClosed) and the Python SDK (CONNECTION_CLOSED = -32000, documented as "the connection closed before a response arrived; never emitted on the wire"). So the server didn't send this code. Your client raised it because the connection ended while it was waiting.

The TypeScript SDK v2 replaces the number with SdkErrorCode.ConnectionClosed, so code that checks error.code === -32000 silently stops matching after an upgrade.

Causes, and how to check

CauseHow to spot it
Server crashes at startupRunning the command by hand (step 1) prints a stack trace or exits at once
Something printed to stdoutThe client log shows SyntaxError: Unexpected token ... is not valid JSON; the quoted token is the first character of the stray line
Command not found / wrong pathWorks from one folder but not another; relative paths in the config
Missing environment variableServer exits complaining about a key; Claude Code warns about unset ${VAR} references in claude mcp list and /mcp
Startup slower than the client's timeoutRaising the startup timeout (step 6) makes it connect

The protocol rule behind the stdout problem

The MCP specification's stdio transport: the client launches the server as a subprocess; messages are newline-delimited JSON-RPC and must not contain embedded newlines; the server must not write anything to stdout that is not a valid MCP message, and may write UTF-8 logs to stderr. One stray console.log breaks the stream.

Test the server outside your editor

The official MCP Inspector connects to a server and shows every message, which separates server bugs from client configuration:

npx @modelcontextprotocol/inspector

Remote (HTTP) servers

  • 400 with JSON-RPC -32000 and Bad Request: Mcp-Session-Id header is required comes from the TypeScript SDK's HTTP server: the client didn't send the session ID it received at initialization. The spec requires clients to send MCP-Session-Id on every later request.
  • 404 on a request with a session ID means the server ended that session; the client must start a new one with a fresh initialize request.
  • Claude Code's MCP server "<name>" connection closed before the tool call was answered means the tool may have run. Check the target service before running it again.

Running Claude Code, Codex or Cursor on real repos, or shipping an AI agent? A Quick Review ($149 / ₹13,900, 1 working day) checks one repo, config or setup for leaked keys, risky agent permissions and MCP servers. Request a Quick Review

FAQ

What does MCP error -32000 mean?

In the official MCP SDKs, -32000 is the client-side ConnectionClosed error: the connection to the MCP server closed before a response arrived. The server did not send it.

Why does console.log break my MCP server?

On the stdio transport, stdout carries protocol messages, and the MCP spec says a server must not write anything else there. Log to stderr instead.

How do I see why an MCP server failed in Claude Code?

Run /mcp for its status, claude mcp get <name> for the Issue line, and claude --debug=mcp to capture the server's stderr in ~/.claude/debug/<session-id>.txt.

How do I increase the MCP startup timeout in Claude Code?

Set MCP_TIMEOUT in milliseconds when starting it, for example MCP_TIMEOUT=10000 claude.

Related errors

Sources

Read 29 Nov 2026. These tools change often: if a step no longer matches, the linked page wins.

Related free tools