fix: inject sys.argv to configure FastMCP run

This commit is contained in:
Clawdbot
2026-02-12 12:26:07 +11:00
parent 76aba3dcb1
commit 36bc6238dd

View File

@@ -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