From a53d80714693fec278b8c0229bf19ae6757b8e87 Mon Sep 17 00:00:00 2001 From: Andrey Kuznetsov Date: Wed, 4 Mar 2026 23:16:23 +0400 Subject: [PATCH] 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. --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 5dd1d6c..1cb01c3 100644 --- a/main.py +++ b/main.py @@ -137,7 +137,7 @@ try: logger.addHandler(file_handler) logger.info(f"Logging initialized to {log_file_path}") 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 logger.addHandler(console_handler) 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: try: # Start the Telethon client non-interactively - print("Starting Telegram client...") + print("Starting Telegram client...", file=sys.stderr) 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() await mcp.run_stdio_async() except Exception as e: