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():
|
def main():
|
||||||
"""Entry point for the MCP server."""
|
"""Entry point for the MCP server."""
|
||||||
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from importlib.metadata import version
|
from importlib.metadata import version
|
||||||
package_version = version("cp210x-mcp")
|
package_version = version("cp210x-mcp")
|
||||||
except Exception:
|
except Exception:
|
||||||
package_version = "0.1.0"
|
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:
|
try:
|
||||||
lib = get_lib()
|
lib = get_lib()
|
||||||
num_devices = lib.get_num_devices()
|
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:
|
except FileNotFoundError as e:
|
||||||
print(f"⚠️ Library not found: {e}")
|
print(f" Library not found: {e}", file=sys.stderr)
|
||||||
print(" Server will start but tools will fail until library is installed.")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ Error initializing: {e}")
|
print(f" Error initializing: {e}", file=sys.stderr)
|
||||||
|
|
||||||
mcp.run()
|
mcp.run()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user