Skip to content

Unexpected token … is not valid JSON

Spec
2026-07-28
Evidence
E2Reproducedarm64
TypeScript SDK v1
@modelcontextprotocol/sdk@1.32.2
Verified

On stdio, stdout is reserved for protocol messages: one JSON-RPC object per line. Anything else on stdout reaches the client’s JSON parser. We added console.log('Server starting...') to a working server and connected with the TypeScript SDK v1 client, which is what many desktop clients use. Its error handler received:

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

The quoted part is the start of the offending line, which is the fastest way to find where it comes from.

What happens next depends on the client. In our test the v1 client logged the error and carried on, and the TypeScript v2 client ignored the line silently. Clients that treat a parse error as fatal show the server as failed, and a server whose replies are interleaved with stray output can end in Request timed out.

console.log in Node.js and print() in Python write to stdout. Write logs to stderr instead:

console.error('Server starting...');
import sys
print("Server starting...", file=sys.stderr)

Most clients copy the server’s stderr into their own log, so nothing is lost.

If your own code is clean, look at what else runs in the process:

  • Libraries that print banners or deprecation notices on import.
  • Wrapper scripts that echo before starting the server.
  • Package runners: a first-run npx install prompt waits for input on the same stream. Use npx -y so it never asks.

Run the exact command from the client config in a terminal. Before you type anything, stdout must stay empty.

MCPDev is community documentation. It is not affiliated with the Model Context Protocol project or with the vendors of the clients it covers.