modelcontextprotocol / modelcontextprotocol/python-sdk

resource_url_from_server_url preserves explicit default ports

Offen Anfängerfreundlich
#3,297 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

P3 v1 v2
Vorherrschende Sprache
Python
Sterne
24.3k
Forks
4k
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
31

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie bei resource_url_from_server_url() in mcp.shared.auth_utils und reproduzieren Sie das Beispiel mit expliziten Standard- und Nichtstandardports. Bestätigen Sie, dass HTTP 80 und HTTPS 443 entfernt werden, während Nichtstandardports erhalten bleiben, und überprüfen Sie, dass check_resource_allowed() gleichwertige kanonische Ressourcen-URLs akzeptiert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
authentication, security
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Ruhig
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
76/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.