An MCP server with DNS rebinding protection checks every Host header against a list. If the name you use to reach it is not on the list, it answers 421 Misdirected Request – even though the server otherwise works fine.
Symptom
curl -s -w ' -> HTTP %{http_code}\n' http://worker1:8000/mcp "${KOPF[@]}" -H "Mcp-Method: server/discover" -H "Host: localhost:8000" --data @discover.json
Invalid Host header -> HTTP 421
In the course, the wrong name is set on purpose with -H "Host: localhost:8000". In practice it happens when you call the server via localhost, a new IP or an ingress name.
Diagnosis
Look in the server's configuration to see which hosts are allowed.
schutz = TransportSecuritySettings(
enable_dns_rebinding_protection=True,
allowed_hosts=["worker1:8000", "172.16.0.228:8000"],
allowed_origins=["http://cp1:8080"],
)
Causes
name missingHost name not in allowed_hosts
allowed_hosts lists every value that may appear in the Host header – each with port. localhost or a new DNS name are often missing.
port missingEntry without port
The Host header contains the port. An entry "worker1" does not match "worker1:8000"; "worker1:*" would allow any port.
gateway in frontName of the gateway or ingress
Behind a gateway, the public name arrives, for example leitwarte.labor. It must be allowed too.
Fix
uv run python fern.py
Don't: Turn off enable_dns_rebinding_protection. The protection stops a foreign web page from reaching your local MCP server through the browser.
MCPA hands-on, Day 8: Streamable HTTP with curl – headers, status codes, two eras on one endpoint and protection against DNS rebinding.
Go to day 8 →
FAQ
What is the difference to “Invalid Origin header” with 403?
421 concerns the Host header (which name the server is reached under), 403 the Origin header (which web page the request comes from).
Why does the SDK let curl through without Origin?
Requests without Origin do not come from a browser. The origin check only applies when the header is set.