PRODUCTION SCENARIO
A developer wraps an internal script as a stdio MCP server. The client reports parse errors on connection, and the script's startup banner and debug messages are written with print statements.
Which change fixes the parse errors?
Answering here is anonymous. Nothing is saved unless you sign in.
Show answer and explanation
Answer: Send the banner and debug output to stderr rather than stdout
On the stdio transport a server may write UTF-8 strings to stderr for any logging purpose, and must not write anything to stdout that is not a valid MCP message. Since messages are newline-delimited JSON-RPC, a print statement corrupts the stream. A logging level cannot filter a raw print that never went through the logging system. Writing the banner first still breaks the client's very first read. And stdio does have a logging channel, which is the point: it is stderr.