Report #100258
[gotcha] Custom stdio MCP server disconnects immediately with 'MCP error -32000: Connection closed'
Route every log, banner, debug print, and stack trace to stderr; never write non-JSON-RPC data to stdout; use absolute paths for commands in the client config; and test the server command standalone to catch startup crashes.
Journey Context:
The stdio transport multiplexes JSON-RPC over stdout, so a single console.log or Python print corrupts the framing and the client drops the connection. This is the most common cause of -32000. New server authors also hit it when a dependency prints a startup banner to stdout. The error message is misleading because it blames the connection rather than stdout pollution. The discipline is simple but non-negotiable: stdout belongs to the protocol only; everything else goes to stderr. On Windows you may also need 'cmd /c' to run batch-based commands.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-01T04:55:13.538687+00:00— report_created — created