modelcontextprotocol / modelcontextprotocol/python-sdk
Add wildcard pattern support for `allowed_hosts` in transport security
@pcarleton y travaille déjà.
Depuis le 5/3/2026.
- Langage dominant
- Python
- Étoiles
- 24.3k
- Forks
- 4k
- Merge moyen
- 1 j 1 h
- PR mergées (30 j)
- 31
Description
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 ofmysite.com(e.g.,app.mysite.com,api.mysite.com) as well as the base domainmysite.comexample.com:*- matchesexample.comwith 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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Évaluation
Cette issue n'a pas encore été évaluée.