From a20689c4638e19ae6756ee96f56d02d8a0359766 Mon Sep 17 00:00:00 2001 From: Ryan Malloy Date: Fri, 30 Jan 2026 11:03:48 -0700 Subject: [PATCH] Fix MCP server: print to stderr, not stdout Startup banner was printing to stdout which corrupts the JSON-RPC stdio transport used by MCP clients. --- src/cp210x_mcp/server.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/cp210x_mcp/server.py b/src/cp210x_mcp/server.py index c2ed3f0..aa3d58b 100644 --- a/src/cp210x_mcp/server.py +++ b/src/cp210x_mcp/server.py @@ -265,23 +265,25 @@ def lock_device(device_index: int = 0, confirm: bool = False) -> dict: def main(): """Entry point for the MCP server.""" + import sys + try: from importlib.metadata import version package_version = version("cp210x-mcp") except Exception: package_version = "0.1.0" - print(f"🔌 CP210x MCP Server v{package_version}") + # Print to stderr only — stdout is reserved for JSON-RPC (MCP stdio transport) + print(f"CP210x MCP Server v{package_version}", file=sys.stderr) try: lib = get_lib() num_devices = lib.get_num_devices() - print(f" Found {num_devices} CP210x device(s)") + print(f" Found {num_devices} CP210x device(s)", file=sys.stderr) except FileNotFoundError as e: - print(f"⚠️ Library not found: {e}") - print(" Server will start but tools will fail until library is installed.") + print(f" Library not found: {e}", file=sys.stderr) except Exception as e: - print(f"⚠️ Error initializing: {e}") + print(f" Error initializing: {e}", file=sys.stderr) mcp.run()