Unexpected token … is not valid JSON
- Spec
2026-07-28- Evidence
- E2Reproducedarm64
- TypeScript SDK v1
@modelcontextprotocol/sdk@1.32.2- Verified
What it means
Section titled “What it means”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 JSONThe 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.
Your code logs to stdout
Section titled “Your code logs to stdout”console.log in Node.js and print() in Python write to stdout. Write logs to stderr instead:
console.error('Server starting...');import sysprint("Server starting...", file=sys.stderr)Most clients copy the server’s stderr into their own log, so nothing is lost.
A dependency or launcher prints to stdout
Section titled “A dependency or launcher prints to stdout”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
echobefore starting the server. - Package runners: a first-run
npxinstall prompt waits for input on the same stream. Usenpx -yso it never asks.
Run the exact command from the client config in a terminal. Before you type anything, stdout must stay empty.
Related
Section titled “Related”MCPDev is community documentation. It is not affiliated with the Model Context Protocol project or with the vendors of the clients it covers.