Fixes › Claude Desktop, Cursor, Claude Code

"Unexpected token … is not valid JSON" from a custom MCP server

Claude DesktopCursorClaude Code

The error

SyntaxError: Unexpected token 'S', "Server sta"... is not valid JSON

Why it happens

With the stdio transport, stdout is reserved for JSON-RPC messages. Any console.log / print() to stdout corrupts the stream.

How to fix it

  1. Log to stderr instead
    Node: use console.error. Python: print(..., file=sys.stderr) or the logging module.
    // Node
    console.error("Server started");
    
    # Python
    import sys
    print("Server started", file=sys.stderr)
  2. Silence noisy dependencies
    Libraries that print banners or progress bars to stdout must be silenced or redirected.

Related servers

Sources