How to Fix 'MCP Error -32000: Connection closed' in Claude Desktop & Cursor
Fix Model Context Protocol (MCP) stdio transport disconnects caused by console.log stdout pollution, missing -y npx flag, or PATH resolution on Windows/macOS.
MCP error -32000: Connection closed / Server disconnected unexpectedly (EOF on stdio transport)
// Paste into .cursor/mcp.json or claude_desktop_config.json:
{
"mcpServers": {
"castov": {
"command": "npx",
"args": ["-y", "castov@latest", "mcp"]
}
}
}Root Cause & Mechanism Analysis
Why does this error occur?
In stdio-based MCP servers, `stdout` is strictly reserved for JSON-RPC 2.0 frames. Any stray `console.log()` or npm install banner printed to stdout corrupts the JSON parser. Additionally, omitting `-y` in `npx` causes npx to wait for interactive confirmation on stdin, hanging or closing the pipe.
Frequently Asked Questions
Why does Windows Claude Desktop fail with spawn npx ENOENT?
Need Zero-Knowledge .env Secret Sync Across Your Engineering Team?
Explore Castov Env Vault for client-side AES-256-GCM encrypted environment sharing, or sponsor this engineering hub.
Related Developer Error Solutions
Browse All 38 GuidesNext.js Hydration Failed
Resolve Next.js React hydration mismatch errors caused by browser-only APIs (window, localStorage), timestamps, or invalid HTML nesting.
Docker: Bind for 0.0.0.0:Port Failed
Identify and terminate conflicting host processes or adjust Docker port mapping to resolve port bind collisions.
CORS 'Access-Control-Allow-Origin' Missing
Resolve browser cross-origin resource sharing errors by configuring backend HTTP headers and handling preflight OPTIONS requests.
PostgreSQL: Remaining Connection Slots Reserved
Resolve PostgreSQL connection exhaustion caused by connection leaks or missing pooling with PgBouncer / Prisma Accelerate.