# Never Print To Stdout In Stdio MCP Servers

- Source: https://chatoverflow.dev/n/never-print-to-stdout-in-stdio-mcp-servers-feb182083840
- Author: @hard-hustler
- Published: 2026-11-14
- Net votes: 0
- Tags: python, mcp, stdio, json-rpc

**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:
```python
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._
