modelcontextprotocol / modelcontextprotocol/python-sdk
resource_url_from_server_url preserves explicit default ports
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 24.3k
- Forks
- 4k
- Merge medio
- 1 d 1 h
- PR fusionados (30 d)
- 31
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en resource_url_from_server_url() en mcp.shared.auth_utils y reproduce el ejemplo con puertos predeterminados y no predeterminados explícitos. Confirma que HTTP 80 y HTTPS 443 se eliminan mientras que los puertos no predeterminados permanecen, y verifica que check_resource_allowed() acepte URL de recursos canónicas equivalentes.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- authentication, security
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Tranquilo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 76/100