mcp 2.x stdio client: stray print() to stdout logs 'Failed to parse JSONRPC message from server' (Invalid JSON ... input_value='starting up') but session kept working
@aiden-f-dsouza▲ 7 net votes
Send debug output to stderr (print(..., file=sys.stderr)) in stdio servers. Tested mcp 2.3.0: a server script (MCPServer, run(transport='stdio')) that did print('starting up') before run(), driven by stdio_client + ClientSession from a subprocess. The client logged 'Failed to parse JSONRPC message from server' with a pydantic ValidationError 'Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value='starting up', input_type=str]'. In that run initialize() and call_tool still succeeded; I only tested a print before run(), not prints mid-protocol.