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.
This commit is contained in:
parent
fc12d6a2d7
commit
a20689c463
@ -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()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user