"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
- Log to stderr instead
Node: useconsole.error. Python:print(..., file=sys.stderr)or theloggingmodule.// Node console.error("Server started"); # Python import sys print("Server started", file=sys.stderr) - Silence noisy dependencies
Libraries that print banners or progress bars to stdout must be silenced or redirected.
Related servers
Dev Tools● Maintained
Everything (test server)
This MCP server attempts to exercise all the features of the MCP protocol. It is not intended to be a useful server, but rather a test server for buil
★ 91.3k · updated 2026-10-10
Memory & Reasoning● Maintained
Sequential Thinking
An MCP server implementation that provides a tool for dynamic and reflective problem-solving through a structured thinking process.
★ 91.3k · updated 2026-10-10
Sources
- https://modelcontextprotocol.io/specification/2025-06-18/basic/transports
- https://modelcontextprotocol.io/docs/tools/debugging
- Unexpected token 'M', "MCP servic"... is not valid JSON (GitHub issue, 3 comments)
- Claude Desktop: MCP doc-forge: Unexpected token 'M', "MCP Doc Fo" '... is not valid JSON (GitHub issue, 3 comments)