modelcontextprotocol / modelcontextprotocol/python-sdk

Add wildcard pattern support for `allowed_hosts` in transport security

Offen
#2,141 1 Kommentar 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@pcarleton arbeitet bereits daran.

Seit 05.3.2026.

enhancement needs confirmation
Vorherrschende Sprache
Python
Sterne
24.3k
Forks
4k
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
31

Beschreibung

Description

Problem

Currently, the allowed_hosts configuration in TransportSecuritySettings only supports exact string matching link. This is too restrictive for real-world scenarios where you need to allow multiple subdomains under the same parent domain.

For example, if you want to allow app.mysite.com, api.mysite.com, admin.mysite.com, etc., you currently need to list each subdomain explicitly:

allowed_hosts=["app.mysite.com", "api.mysite.com", "admin.mysite.com", ...]

This becomes impractical when you have many subdomains or dynamic subdomain generation.

Proposed Solution

Add wildcard pattern support similar to Starlette's TrustedHostMiddleware or Django's ALLOWED_HOSTS , allowing patterns like:

  • *.mysite.com - matches any subdomain of mysite.com (e.g., app.mysite.com, api.mysite.com) as well as the base domain mysite.com
  • example.com:* - matches example.com with any port (already supported)

Example Usage

from mcp.server.transport_security import TransportSecuritySettings

settings = TransportSecuritySettings(
    enable_dns_rebinding_protection=True,
    allowed_hosts=["*.mysite.com", "localhost:*"],
)

I'd be happy to follow up and create a PR.

References

No response

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.