Fix MCP server startup: remove pre-run library init

Native library calls during startup interfered with FastMCP's
stdio transport initialization. Library is now loaded lazily on
first tool call instead.
This commit is contained in:
Ryan Malloy 2026-01-30 11:05:15 -07:00
parent a20689c463
commit ff12b9450f

View File

@ -265,26 +265,6 @@ 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 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)", file=sys.stderr)
except FileNotFoundError as e:
print(f" Library not found: {e}", file=sys.stderr)
except Exception as e:
print(f" Error initializing: {e}", file=sys.stderr)
mcp.run()