modelcontextprotocol / modelcontextprotocol/python-sdk
resource_url_from_server_url preserves explicit default ports
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 24.3k
- フォーク
- 4k
- 平均マージ
- 1日 1時間
- マージ済み PR(30日)
- 31
説明
Initial checks
- I tested the current
mainbranch (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
mainat6e30452
I used AI assistance while investigating this issue and reviewed and reproduced the behavior locally.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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