{"record":{"id":"a53025984adcc755","repo":"tirth8205/code-review-graph","slug":"streamable-http-transport-requires-host-and-port","errorCode":null,"errorMessage":"streamable-http transport requires host and port","messagePattern":"streamable-http transport requires host and port","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"code_review_graph/main.py","lineNumber":1241,"sourceCode":"            asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())\n            # Pre-warm sentence-transformers on the main thread before fastmcp's\n            # event loop starts. Lazy-loading ``torch`` + tokenizers inside an\n            # executor worker thread deadlocks ``semantic_search_nodes_tool`` on\n            # Windows stdio MCP (DLL init / OpenMP thread-pool registration grabs\n            # locks the loop needs). #385 added ``asyncio.to_thread`` to peer\n            # tools but cannot fix this case — the dangerous initialization has\n            # to happen on the main thread before any worker thread is spawned.\n            from .embeddings import prewarm_local_embeddings\n\n            prewarm_local_embeddings()\n\n        if transport == \"stdio\":\n            # Stdio MCP must keep stdout strictly JSON-RPC. FastMCP's banner/update\n            # notices corrupt the handshake stream on clients like Codex CLI.\n            mcp.run(transport=\"stdio\", show_banner=False)\n        elif transport == \"streamable-http\":\n            if host is None or port is None:\n                raise ValueError(\"streamable-http transport requires host and port\")\n            # Validate Host/Origin on the loopback HTTP endpoint. Without it a web\n            # page the user visits can point a hostname it controls at 127.0.0.1\n            # (DNS rebinding) and drive the tools, which read the user's code.\n            # Non-browser MCP clients send no Origin and are unaffected; see\n            # code_review_graph.http_origin_guard.\n            from .http_origin_guard import build_http_middleware\n\n            mcp.run(\n                transport=\"streamable-http\",\n                host=host,\n                port=port,\n                middleware=build_http_middleware(host, port),\n            )\n        else:\n            raise ValueError(f\"unsupported transport: {transport!r}\")\n    finally:\n        if watch_store is not None:\n            watch_store.close()","sourceCodeStart":1223,"sourceCodeEnd":1259,"githubUrl":"https://github.com/tirth8205/code-review-graph/blob/b58668751ab0c7670c078cf7cbd4d1f5b8e54f81/code_review_graph/main.py#L1223-L1259","documentation":"Raised by main() when the MCP server is launched with transport='streamable-http' but no host and/or port was supplied. The HTTP transport has no default endpoint, so both values are mandatory before the server can bind and apply its DNS-rebinding Origin guard.","triggerScenarios":"Calling the CLI/MCP entrypoint with --transport streamable-http (or the equivalent API call) while omitting --host or --port, or passing them as None.","commonSituations":"Porting a stdio-based MCP config to HTTP and forgetting the endpoint flags; scripts that default host/port to None; config files that omit the http section.","solutions":["Pass both --host and --port, e.g. --transport streamable-http --host 127.0.0.1 --port 8080.","If embedding via API, supply host= and port= keywords — never rely on defaults for this transport.","Use transport stdio when no HTTP endpoint is intended."],"exampleFix":"# before\nmcp --transport streamable-http\n# after\nmcp --transport streamable-http --host 127.0.0.1 --port 8080","handlingStrategy":"validation","validationCode":"if transport == \"streamable-http\" and (host is None or port is None):\n    host = host or \"127.0.0.1\"\n    port = port or 8080  # or fail fast with a clear message","typeGuard":null,"tryCatchPattern":"try:\n    main()\nexcept ValueError as exc:\n    if \"requires host and port\" in str(exc):\n        print(exc); sys.exit(2)","preventionTips":["Centralize transport config parsing so host/port defaults are applied once.","Fail fast at config-load time rather than at server startup.","Prefer loopback host 127.0.0.1 unless remote access is required."],"tags":["mcp","transport","http","config"],"backgroundTag":"missing-required-config-option","analyzedSha":"b58668751ab0c7670c078cf7cbd4d1f5b8e54f81","analyzedAt":"2026-08-28T13:19:08.966Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}