modelcontextprotocol / modelcontextprotocol/python-sdk

resource_url_from_server_url preserves explicit default ports

Aperta Adatta ai principianti
#3,297 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

P3 v1 v2
Lingua principale
Python
Stelle
24.3k
Fork
4k
Merge medio
1g 1h
PR unite (30g)
31

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da resource_url_from_server_url() in mcp.shared.auth_utils e riproduci l'esempio con porte predefinite e non predefinite esplicite. Conferma che HTTP 80 e HTTPS 443 vengano rimossi mentre le porte non predefinite rimangano, e verifica che check_resource_allowed() accetti URL di risorse canonici equivalenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
authentication, security
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
76/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.