From 36bc6238dd4d2385bfa40d7835086ecb81d0106b Mon Sep 17 00:00:00 2001 From: Clawdbot Date: Thu, 12 Feb 2026 12:26:07 +1100 Subject: [PATCH] fix: inject sys.argv to configure FastMCP run --- server.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/server.py b/server.py index bdbd367..1f86579 100644 --- a/server.py +++ b/server.py @@ -211,8 +211,26 @@ def query_notebook(notebook: str, query: str, limit: int = 5) -> str: if __name__ == "__main__": try: - logging.info("Starting knowledge-mcp server (transport=sse, host=0.0.0.0, port=8000)...") - mcp.run(transport="sse", host="0.0.0.0", port=8000) + logging.info("Starting knowledge-mcp server (transport=sse)...") + # NOTE: FastMCP.run() uses Typer/Click to parse CLI args. + # It does NOT accept host/port as direct kwargs in .run(). + # However, it allows command-line flags. + # To bypass CLI parsing and force settings, we must set sys.argv + # or use internal methods, but for now we will rely on CLI args + # passed by the Docker CMD, or defaults. + # + # If we really want to force it in code without CLI args, we'd use: + # mcp._run_sse(host="0.0.0.0", port=8000) (if accessing private API) + # OR just rely on the fact that `mcp` SDK handles this differently. + # + # For FastMCP 0.2+, run() is a CLI entrypoint. + # We will remove the kwargs and let the Docker CMD handle the flags. + import sys + # Inject args if they are missing (hack to force 0.0.0.0:8000 inside container) + if len(sys.argv) == 1: + sys.argv.extend(["sse", "--host", "0.0.0.0", "--port", "8000"]) + + mcp.run() except BaseException as e: logging.critical(f"Server crashed: {e}", exc_info=True) raise