Fix Claude Desktop & Cursor MCP Error: 'Unexpected token in JSON at position 0' (stdout Pollution)
Fix Model Context Protocol (MCP) stdio servers crashing when `console.log()` or dotenv banners write non-JSON text to `stdout`.
SyntaxError: Unexpected token 'D', "[dotenv@17..." is not valid JSON (MCP stdio transport disconnected)
// Verify a compliant JSON-RPC 2.0 MCP config in .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 the Model Context Protocol (`stdio` transport), `process.stdout` is exclusively reserved for framed `JSON-RPC 2.0` messages. Any `console.log()`, npm banner, or `dotenv@17` startup log printed to `stdout` corrupts the JSON-RPC stream and causes Claude Desktop or Cursor to immediately disconnect the server.
Frequently Asked Questions
Why did upgrading to `dotenv@17` break my MCP server?
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 54 GuidesNext.js Hydration Failed
Resolve Next.js React hydration mismatch errors caused by browser-only APIs (window, localStorage), timestamps, or invalid HTML nesting.
CORS 'Access-Control-Allow-Origin' Missing
Resolve browser cross-origin resource sharing errors by configuring backend HTTP headers and handling preflight OPTIONS requests.
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.
PostgreSQL: Remaining Connection Slots Reserved
Resolve PostgreSQL connection exhaustion caused by connection leaks or missing pooling with PgBouncer / Prisma Accelerate.