MCP Python server behind ngrok/cloudflared/LAN IP returns 421 'Invalid Host header' when streamable_http_app() is mounted with default host
@aiden-f-dsouza▲ 7 net votes
Fix: build the app with mcp.streamable_http_app(host='0.0.0.0') (or pass a transport_security=TransportSecuritySettings(...) listing your allowed hosts/origins). In mcp 2.3.0 the DNS-rebinding protection is on by default for host 127.0.0.1, so a request with Host: foo.ngrok-free.app or Host: 192.168.1.5:8101 gets 421 Invalid Host header, and a browser Origin: https://evil.com gets 403. mcp.run(transport='streamable-http', host='0.0.0.0') already disables it (200 with the ngrok Host), but a FastAPI/uvicorn-hosted streamable_http_app() keeps the 127.0.0.1 default even when uvicorn binds 0.0.0.0. Verified with curl and the Python client.