What this thread does
Do first: pass transport_security=TransportSecuritySettings(...) with explicit allowed_hosts and browser allowed_origins to streamable_http_app().
Symptom
421 Misdirected Request / Invalid Host Header is the error described by Junyi-99 for proxy, gateway and custom-domain deployments. The server response text in the v2 deployment guide is Invalid Host header. The linked duplicate report by longz30 supplies another affected deployment.
Cause
DNS rebinding protection checks the request Host against an allowlist before MCP handling. Without explicit transport security, the embedded app assumes localhost. A server can start and route correctly while rejecting the hostname used by its proxy.
Fix
| Setting | Value | Applies to | Source |
|---|---|---|---|
allowed_hosts | ["mcp.example.com", "mcp.example.com:*"] | Replace the example with the hostname actually served; list bare and port forms | v2 guide |
allowed_origins | ["https://app.example.com"] | Browser clients; replace the example origin | PR documentation |
transport_security | The configured TransportSecuritySettings object | Argument to streamable_http_app() | v2 guide |
If you cannot upgrade: the issue itself shows configuring TransportSecuritySettings on FastMCP, including enable_dns_rebinding_protection=True and explicit allowlists. Its reverse-proxy note also requires the proxy to pass the correct Host header.
Fixed in
The closing maintainer points to the released v2 line and documentation PR #3044, merged 2026-07-01. This is configuration guidance, not removal of Host validation. The first release containing that documentation is v2.0.0b2 (released 2026-07-14), an opt-in beta; v2.0.0 (released 2026-07-28) is the stable release containing it. The PR merge is absent from b1 and present in b2 and the stable tag.
If it still fails
- Passing a non-localhost
host=does not add that hostname to the allowlist. The deployment guide says it prevents the localhost default protection from being armed; usetransport_security=to state the policy explicitly. - An Origin rejected with
403 Forbiddenis a separate allowlist check. Host configuration alone does not repair it. - The documented alternative
enable_dns_rebinding_protection=Falseis conditional on local development or another layer enforcing the policy.
Not for: a lost HTTP session after initialization; see mcp-python-lost-http-session-reconnect-without-call-replay.
Sources
- Guide: Resolving "421 Invalid Host Header" (DNS Rebinding Protection), Junyi-99, opened 2025-12-17; closed as completed on 2026-07-29: "You can wildcard the ports using
*." - 1.24.0出现报错, longz30, opened 2025-12-17; closed as duplicate on 2025-12-17.
- docs: restructure into topical sections and add the four most-asked-for pages, maxisbey, merged 2026-07-01; state: merged.
- v2.0.0b2, published 2026-07-14; pre-release.
- v2.0.0, published 2026-07-28.
- Deploy & scale at v2.0.0.
- PR merge compared with b1; behind.
- PR merge compared with b2; ahead, no commits behind.
Checked
2026-11-24; read both issue API records, primary issue comments, PR and changed documentation API records, versioned deployment guide, release records, release list and merge-to-tag comparisons; no command was run.
Started from a post by @Junyi-99, packaged by the editor. Original post