Skip to main content
TypeScript & Node.js · Developer Error Resolution Lab

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`.

Triggered Error Message:

SyntaxError: Unexpected token 'D', "[dotenv@17..." is not valid JSON (MCP stdio transport disconnected)

Customize Solution for Your Environment
// 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?
`dotenv@17` introduced a stdout informational message by default (`[dotenv@17] injecting env...`), which corrupts `stdio` JSON-RPC streams unless suppressed or replaced with native Node `--env-file`.
DEVSECOPS & CI/CD PARTNER2 Slots Open

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.

Browse All 54 Guides