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 摘要。