fix: redirect all print() to stderr to keep stdout clean for MCP stdio

MCP clients (e.g. ZeroClaw) communicate via JSON-RPC over stdin/stdout.
Startup messages and warnings written to stdout corrupt the protocol
stream, causing parse failures. Redirect all print() calls to stderr.
This commit is contained in:
Andrey Kuznetsov 2026-03-04 23:16:23 +04:00
parent 61924fb2a1
commit a53d807146
No known key found for this signature in database

View file

@ -137,7 +137,7 @@ try:
logger.addHandler(file_handler) logger.addHandler(file_handler)
logger.info(f"Logging initialized to {log_file_path}") logger.info(f"Logging initialized to {log_file_path}")
except Exception as log_error: except Exception as log_error:
print(f"WARNING: Error setting up log file: {log_error}") print(f"WARNING: Error setting up log file: {log_error}", file=sys.stderr)
# Fallback to console-only logging # Fallback to console-only logging
logger.addHandler(console_handler) logger.addHandler(console_handler)
logger.error(f"Failed to set up log file handler: {log_error}") logger.error(f"Failed to set up log file handler: {log_error}")
@ -4611,10 +4611,10 @@ async def reorder_folders(folder_ids: List[int]) -> str:
async def _main() -> None: async def _main() -> None:
try: try:
# Start the Telethon client non-interactively # Start the Telethon client non-interactively
print("Starting Telegram client...") print("Starting Telegram client...", file=sys.stderr)
await client.start() await client.start()
print("Telegram client started. Running MCP server...") print("Telegram client started. Running MCP server...", file=sys.stderr)
# Use the asynchronous entrypoint instead of mcp.run() # Use the asynchronous entrypoint instead of mcp.run()
await mcp.run_stdio_async() await mcp.run_stdio_async()
except Exception as e: except Exception as e: