"MCP error -32000: Connection closed": Why Your MCP Server Won't Connect and How to Fix It
MCP error -32000 Connection closed means the client lost its MCP server, usually a stdio process that crashed or wrote junk to stdout. Find the cause and fix it.
"MCP error -32000: Connection closed" means your MCP client lost the connection to the server before it got an answer. With a local (stdio) server, that almost always means the server process exited, usually seconds after it started: a missing API key, a command that doesn't exist, a Node version the package doesn't support, or a crash in the server's own code. The error is generated by the client, so the real cause is in the server's stderr, which you need to go and read.
Checked against the JSON-RPC 2.0 specification, the MCP stdio transport spec, the MCP debugging guide and Inspector docs, the MCP TypeScript SDK source, and Claude Code's MCP, configuration debugging and CLI docs in November 2026.
You'll usually see it as a single line:
MCP error -32000: Connection closed
In Claude Code, claude mcp list shows the server as ✘ Failed to connect, and /mcp lists it as failed. In Claude Desktop the server simply doesn't appear among your connectors, and the reason is in its log files.
What -32000 actually means
JSON-RPC 2.0, the message format MCP uses, reserves codes -32000 to -32099 for "implementation-defined server-errors". The spec gives them no fixed meaning, so each implementation picks its own.
Version 1 of the official MCP TypeScript SDK, which many clients and servers are built on, defines two of them:
export enum ErrorCode {
// SDK error codes
ConnectionClosed = -32000,
RequestTimeout = -32001,
// ...
}
When the transport closes, the SDK rejects every request still waiting for an answer with McpError(ErrorCode.ConnectionClosed, 'Connection closed'), and McpError formats its message as MCP error ${code}: ${message}. So the server never sent -32000. The client produced it when the pipe went dead. Its sibling, MCP error -32001: Request timed out, means the server is alive but didn't answer in time.
Version 2 of the SDK reports the same situation as an SdkError with the string code CONNECTION_CLOSED, so clients built on it word the error differently. The causes are the same.
Why stdio connections close
With the stdio transport, the client starts the server as a child process and exchanges newline-delimited JSON-RPC messages over its stdin and stdout. The connection is the process. If the process exits, the connection closes, and anything waiting gets -32000. (Remote servers over Streamable HTTP fail differently; see MCP Transports: stdio vs Streamable HTTP.)
The causes, most common first:
- The server crashed on startup. A required environment variable such as an API token is missing, a config file isn't found, or the code throws before it starts listening.
- The command doesn't run. A typo in the package name, a relative path that resolves from the wrong directory, or an executable that isn't on the
PATHthe client sees. npxon native Windows.npxis a batch file (npx.cmd) there, and per the Node.js docs,.batand.cmdfiles "are not executable on their own without a terminal". Clients that spawn the command directly can't start it.- The wrong Node version. The server package needs a newer Node than the one the client found. The MCP TypeScript SDK v1 needs Node 18 or later, and the v2 server package needs Node 20 or later.
- Something else on stdout. The stdio spec says the server "MUST NOT write anything to its
stdoutthat is not a valid MCP message". A strayconsole.logor a startup banner corrupts the stream. Depending on the client, that shows up as parse errors or as a dropped connection.
Step 1: run the command yourself
Copy the exact command and args from your config and run them in a terminal:
GITHUB_TOKEN=xxx npx -y @example/mcp-server
A healthy stdio server prints nothing to stdout and sits there waiting for input on stdin (a startup line on stderr is fine). Press Ctrl+C to stop it. If it exits with a stack trace, command not found or Error: Missing required environment variable, you've found the problem without touching the client.
To check for stdout pollution, close stdin and throw stderr away, so anything left on screen came from stdout:
npx -y @example/mcp-server < /dev/null 2> /dev/null
The spec says servers should exit when stdin closes, and a correct server has nothing to say before it receives a request. Any text printed here is breaking the protocol.
Step 2: read the server's stderr
The server's stderr is where the crash message goes. Each client keeps it somewhere different.
Claude Code. Start with the status commands:
claude mcp list # health of every server, with failure detail
claude mcp get my-server # one server, with an Issue: line when it fails
Inside a session, /mcp shows each server's status and has a Reconnect option. For the server's own output, start Claude Code with MCP debug logging:
claude --debug=mcp
Per Claude Code's debugging docs, you then "read the server's stderr in the debug log at ~/.claude/debug/<session-id>.txt". Add --debug-file /tmp/claude-debug.log to choose the path yourself. Older guides mention a --mcp-debug flag; the current CLI reference documents --debug with a category filter instead.
Claude Desktop. Logs are in ~/Library/Logs/Claude on macOS, %APPDATA%\Claude\logs on Windows and ~/.config/Claude/logs on Linux. mcp.log covers connections and failures, and mcp-server-SERVERNAME.log holds that server's stderr:
tail -n 20 -f ~/Library/Logs/Claude/mcp*.log
MCP Inspector. The official Inspector connects to a server outside any AI client, which separates "the server is broken" from "the client config is wrong":
npx @modelcontextprotocol/inspector npx -y @example/mcp-server
It opens a browser UI where you can list and call tools and watch the JSON-RPC traffic. It needs a recent Node release; the Inspector docs list the minimum versions.
Fixes, safest first
Pass the environment variables explicitly. Don't rely on your shell's export. The TypeScript SDK's stdio client, when the config gives no env, passes on only HOME, LOGNAME, PATH, SHELL, TERM and USER (a different short list on Windows), so a token exported in your shell never reaches the server. Claude Code passes its own environment, minus some variables it strips, but its docs still recommend a per-server env block. In Claude Code's .mcp.json, ${VAR} references are expanded from your environment, and claude mcp list warns when one isn't set:
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@example/mcp-server"],
"env": { "GITHUB_TOKEN": "${GITHUB_TOKEN}" }
}
}
}
Claude Desktop's claude_desktop_config.json takes the same env block, but write the value itself there. Or add the server with the Claude Code CLI:
claude mcp add --env GITHUB_TOKEN=xxx --transport stdio github -- npx -y @example/mcp-server
The -- separates Claude Code's own flags from the server's command. Keep another option, such as --transport stdio, between --env and the server name, or the CLI reads the name as another KEY=value pair and rejects it.
Use absolute paths. Claude Code resolves relative paths in command or args against the directory you launched it from, and the MCP docs warn that Claude Desktop may start servers with an undefined working directory, such as / on macOS. Write /Users/you/servers/db/index.js, not ./index.js. If the client picks up the wrong Node, point command at the full path that which node or which npx prints.
Wrap npx in cmd /c on native Windows when your client can't start it:
{
"mcpServers": {
"example": {
"command": "cmd",
"args": ["/c", "npx", "-y", "@example/mcp-server"]
}
}
}
Claude Code removed its "Windows requires 'cmd /c' wrapper" warning in v2.1.119, calling it a false positive, so try your config without the wrapper there first. Under WSL, none of this applies. (Claude Code on Windows covers the native vs WSL choice.)
Move logging to stderr. In a Node server, replace console.log with console.error. In Python, print() goes to stdout, so use logging (its default handler writes to stderr) or print(..., file=sys.stderr). Check your dependencies too: a library that prints a banner on import breaks the stream just as surely. How to Build an MCP Server shows the server skeleton with this in place.
Upgrade Node if the package's engines field asks for a newer version than you have. node --version tells you; What Is nvm? covers switching versions.
Then reconnect. In Claude Code, pick Reconnect from the server's menu in /mcp, or run /mcp reconnect all (v2.1.284 or later). Claude Desktop needs a full quit and reopen; closing the window isn't enough.
When it happens mid-session
If a server connects, works for a while, then fails with -32000, it crashed while handling a tool call, and the stderr log will show the exception. In an interactive Claude Code session a stdio server that exits mid-session is marked as failed until you reconnect it; in a claude -p run, Claude Code starts it again the next time Claude calls one of its tools.
Quick checklist
- Run the configured command by hand and watch for errors.
- Read stderr:
claude --debug=mcpand~/.claude/debug/, or Claude Desktop'smcp-server-*.log. - Put required tokens in the server's
envblock. - Use absolute paths, and
cmd /c npxon native Windows if the client can't startnpx. - Make sure nothing except MCP messages goes to stdout.
- Test with the MCP Inspector, then reconnect from
/mcp.
On EasySpawn, Claude Code and its stdio MCP servers run on the same persistent Linux server, so the Windows npx problem doesn't come up and a server's env and paths are set once, not per laptop. A server that crashes on startup crashes there too, and you'll still need its stderr to find out why; the difference is that the logs, the config and the server are all on one machine Claude can inspect directly. See how it works or join the waitlist.
Related: Connecting MCP Servers to Claude Code: Setup, Scopes, and the Security Question · MCP Transports: stdio vs Streamable HTTP (and What the 2026 Spec Changed) · How to Build an MCP Server (TypeScript and Python) · What Is MCP? The Model Context Protocol for Beginners
Keep reading
Supabase Error 406 "Not Acceptable" (PGRST116): Why .single() Fails and How to Fix It
A Supabase 406 almost always means .single() got zero rows or several. Why row-level security often causes it, and when to use .maybeSingle() or fix a policy.
Postgres "ERROR: permission denied for table": Causes and Fixes
Postgres "permission denied for table" means your role lacks a privilege on it. How to check grants, fix future tables with default privileges, and sequences.