feat(server): synthesize host:* siblings for bare allowed_hosts#537
Merged
Conversation
When an adopter passes ``allowed_hosts=['acme.localhost']`` to ``create_mcp_server`` / ``serve``, the ``host:*`` sibling (``acme.localhost:*``) is now auto-added so requests on either bare or port-suffixed Host headers pass FastMCP's transport-security check. Mirrors the port-stripping ``InMemorySubdomainTenantRouter`` does at lookup time — registering once now covers both surfaces. Salesagent adopter feedback flagged the asymmetry: their dev setup needed both ``acme.localhost`` (router) and ``acme.localhost:*`` (allowlist) per host, while the spec'd surface should accept a single declaration. Hosts that already include ``:`` (explicit port or wildcard) pass through unchanged — adopter signaled they're managing the form themselves. Idempotent: both forms in the input produce no duplicates. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Per review on #537 — flag that bracketed and raw IPv6 literals contain colons and pass through without synthesis (correctly), and point adopters at the explicit `[::1]:*` form for custom v6 hosts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #518.
Summary
When
allowed_hosts=['acme.localhost']is passed tocreate_mcp_server(orserve),acme.localhost:*is now automatically added as a sibling so the FastMCP transport-security check accepts requests on either bare or port-suffixedHostheaders.Why
Salesagent adopter feedback (issue #518): registering
acme.localhostonce inInMemorySubdomainTenantRoutercovers bothacme.localhostandacme.localhost:3001at lookup time (per_normalize_hostport-stripping). But the FastMCPallowed_hostsallowlist required both forms registered explicitly — asymmetric.This change makes the two surfaces symmetric. Single host registration in adopter code now covers both router lookup and transport allowlist.
Behavior
"acme.localhost") → both"acme.localhost"and"acme.localhost:*"registered."acme.localhost:*","acme.localhost:3001") → passes through unchanged. Adopter signaled they're managing the form themselves; we don't second-guess.Test plan
tests/test_serve_transport_security.py::*sibling:*form passes through (no bare-host auto-add)ruff,mypy, all pre-commit hooks pass🤖 Generated with Claude Code