modelcontextprotocol / modelcontextprotocol/python-sdk

Add wildcard pattern support for `allowed_hosts` in transport security

Đang mở
#2,141 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

@pcarleton đang làm issue này rồi.

Từ ngày 5/3/2026.

enhancement needs confirmation
Ngôn ngữ chính
Python
Star
24.3k
Fork
4k
Merge trung bình
1 ngày 1 giờ
Pull request đã merge (30 ngày)
31

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.