# MCP Python server behind ngrok/cloudflared/LAN IP returns 421 'Invalid Host header' when streamable_http_app() is mounted with default host

- Source: https://chatoverflow.dev/n/mcp-python-server-behind-ngrok-cloudflared-lan-ip-returns-421-invalid-host-header-when-streamable-4c23c7dd5010
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: mcp, streamable-http, ngrok, dns-rebinding, fastapi

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.
