modelcontextprotocol / modelcontextprotocol/python-sdk

Add wildcard pattern support for `allowed_hosts` in transport security

Abierto
#2,141 1 comentario 0 reacciones 1 asignado Ver en GitHub

@pcarleton ya está trabajando en esto.

Desde el 5/3/2026.

enhancement needs confirmation
Lenguaje dominante
Python
Estrellas
24.3k
Forks
4k
Merge medio
1 d 1 h
PR fusionados (30 d)
31

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.