modelcontextprotocol / modelcontextprotocol/python-sdk

resource_url_from_server_url preserves explicit default ports

未關閉 適合新手
#3,297 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

P3 v1 v2
主要語言
Python
星號
24.3k
分支
4k
平均合併
1 天 1 小時
30 天內合併 PR
31

描述

Initial checks
  • I tested the current main branch (6e30452).
  • I searched existing issues and pull requests for this behavior.
Description

resource_url_from_server_url() lowercases the scheme/authority and removes the fragment, but it preserves an explicitly specified default port. This makes an RFC 8707 resource URL such as https://example.com:443/mcp compare unequal to the equivalent https://example.com/mcp value used by Protected Resource Metadata.

RFC 3986 section 6.2.3 treats an explicit default port as equivalent to an omitted port. Pydantic also normalizes the metadata URL by dropping the default port. The SDK currently canonicalizes only one side, so check_resource_allowed() can reject an otherwise equivalent resource and abort OAuth resource validation.

Expected: HTTP port 80 and HTTPS port 443 are removed during canonicalization; non-default ports remain unchanged.

Example code
from mcp.shared.auth_utils import check_resource_allowed, resource_url_from_server_url

canonical = resource_url_from_server_url("https://example.com:443/mcp")
print(canonical)  # current: https://example.com:443/mcp
print(check_resource_allowed(canonical, "https://example.com/mcp"))  # current: False
Environment
  • Python 3.12
  • MCP Python SDK main at 6e30452

I used AI assistance while investigating this issue and reviewed and reproduced the behavior locally.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 mcp.shared.auth_utils 中的 resource_url_from_server_url() 開始,使用明確指定的預設連接埠和非預設連接埠重現該範例。確認 HTTP 80 和 HTTPS 443 會被移除,而非預設連接埠會保留,並驗證 check_resource_allowed() 接受等效的規範資源 URL。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
authentication, security
Issue 類型
缺陷
難度
2/5
預估耗時
1-3 小時
活躍度
冷清
描述清晰度
描述清楚
新手友好度
76/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。