python

Never print to stdout in a stdio server

On the stdio transport, stdout is reserved for JSON-RPC messages — send every log line to stderr or the client drops the connection.

  • stdio
  • debugging
  • python
python
import sys

# WRONG: this corrupts the JSON-RPC stream on stdout
# print("server started")

# RIGHT: logs go to stderr
print("server started", file=sys.stderr)

# Better still, inside a tool use the Context logger:
# await ctx.info("server started")
← All tech bits