tirth8205/code-review-graph · error · ValueError

streamable-http transport requires host and port

Error message

streamable-http transport requires host and port

What it means

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.

Source

Thrown at code_review_graph/main.py:1241

            asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
            # Pre-warm sentence-transformers on the main thread before fastmcp's
            # event loop starts. Lazy-loading ``torch`` + tokenizers inside an
            # executor worker thread deadlocks ``semantic_search_nodes_tool`` on
            # Windows stdio MCP (DLL init / OpenMP thread-pool registration grabs
            # locks the loop needs). #385 added ``asyncio.to_thread`` to peer
            # tools but cannot fix this case — the dangerous initialization has
            # to happen on the main thread before any worker thread is spawned.
            from .embeddings import prewarm_local_embeddings

            prewarm_local_embeddings()

        if transport == "stdio":
            # Stdio MCP must keep stdout strictly JSON-RPC. FastMCP's banner/update
            # notices corrupt the handshake stream on clients like Codex CLI.
            mcp.run(transport="stdio", show_banner=False)
        elif transport == "streamable-http":
            if host is None or port is None:
                raise ValueError("streamable-http transport requires host and port")
            # Validate Host/Origin on the loopback HTTP endpoint. Without it a web
            # page the user visits can point a hostname it controls at 127.0.0.1
            # (DNS rebinding) and drive the tools, which read the user's code.
            # Non-browser MCP clients send no Origin and are unaffected; see
            # code_review_graph.http_origin_guard.
            from .http_origin_guard import build_http_middleware

            mcp.run(
                transport="streamable-http",
                host=host,
                port=port,
                middleware=build_http_middleware(host, port),
            )
        else:
            raise ValueError(f"unsupported transport: {transport!r}")
    finally:
        if watch_store is not None:
            watch_store.close()

View on GitHub (pinned to b58668751a)

Solutions

  1. Pass both --host and --port, e.g. --transport streamable-http --host 127.0.0.1 --port 8080.
  2. If embedding via API, supply host= and port= keywords — never rely on defaults for this transport.
  3. Use transport stdio when no HTTP endpoint is intended.

Example fix

# before
mcp --transport streamable-http
# after
mcp --transport streamable-http --host 127.0.0.1 --port 8080
Defensive patterns

Strategy: validation

Validate before calling

if transport == "streamable-http" and (host is None or port is None):
    host = host or "127.0.0.1"
    port = port or 8080  # or fail fast with a clear message

Try / catch

try:
    main()
except ValueError as exc:
    if "requires host and port" in str(exc):
        print(exc); sys.exit(2)

Prevention

When it happens

Trigger: Calling the CLI/MCP entrypoint with --transport streamable-http (or the equivalent API call) while omitting --host or --port, or passing them as None.

Common situations: 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.

Related errors


AI-assisted analysis of tirth8205/code-review-graph@b58668751a (2026-08-28). Data as JSON: /api/errors/a53025984adcc755. Report an issue: GitHub.