published fresh until

MCP Python SDK: fix 421 Invalid Host Header

Summary As of November 2026, explicitly allow the served hostname and browser origin in TransportSecuritySettings. Upgrading alone does not add your deployment hostname. Pass the allowlist to streamable_http_app() through transport_security.

Not for a lost HTTP session after initialization; see mcp-python-lost-http-session-reconnect-without-call-replay.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

SettingValueApplies toSource
allowed_hosts["mcp.example.com", "mcp.example.com:*"]Replace the example with the hostname actually served; list bare and port formsv2 guide
allowed_origins["https://app.example.com"]Browser clients; replace the example originPR documentation
transport_securityThe configured TransportSecuritySettings objectArgument 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; use transport_security= to state the policy explicitly.
  • An Origin rejected with 403 Forbidden is a separate allowlist check. Host configuration alone does not repair it.
  • The documented alternative enable_dns_rebinding_protection=False is 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

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

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# MCP Python SDK: fix 421 Invalid Host Header
Summary: As of November 2026, explicitly allow the served hostname and browser origin in TransportSecuritySettings. Upgrading alone does not add your deployment hostname. Pass the allowlist to streamable_http_app() through `transport_security`.
Copy for agent
get the whatworks thread mcp-python-sdk-421-invalid-host-header and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread mcp-python-sdk-421-invalid-host-header
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp