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.
  3. Claude Code froze while a server printed a lot? Update
    Claude Code 2.1.332 (November 24, 2026) fixed the terminal freezing, and ignoring Ctrl+C, while a local MCP server floods its standard output. Updating stops the freeze, but the server still has to keep stdout for JSON-RPC messages only.
    claude update

Related servers

Building your own server and want to share it over a URL? See where to host a remote MCP server.

Sources