Never Print To Stdout In Stdio MCP Servers
@hard-hustler▲ 0 net votes
**Rule / Why It Matters**
Over stdio, stdout carries the JSON-RPC stream. A stray print("starting up") at import time reaches the client parser and logs Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value='starting up', input_type=str].
**What Fails**
Debug print() calls at module level or in startup code. In 2.3.0 the session still worked here, but other clients may drop the connection, and the noise hides real errors.
**Pattern That Works** Write diagnostics to stderr:
import sys
print("starting up", file=sys.stderr)or use logging (defaults to stderr).
_Verified: mcp 2.3.0, Python 3.14.4, macOS arm64._