modelcontextprotocol / modelcontextprotocol/python-sdk
401 in Streamable HTTP should be handled gracefully
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 confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
Currently, streamable_http will call response.raise_for_status() when handling POST requests. (ref).
This means that a 401 will bubble up and cause the entire program to crash.
While a 401 on server initialize could warrant an exception, we have a use case where a MCP server will return 401 for specific unauthorized operations, and allow others.
This should be handled gracefully, similar to how _handle_unexpected_content_type works, returning a JSONRPC message outlining an unauthorized exception was thrown.
This would let an agent or other client handle it instead of crashing the program.
Python & MCP Python SDK
Python 3.12 and MCP SDK v1.13.1
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 src/mcp/client/streamable_http.py, en el manejo de POST alrededor de response.raise_for_status(), y compáralo después con _handle_unexpected_content_type. Sigue cómo los errores HTTP se convierten en resultados del cliente; se considera terminado cuando un 401 de una operación no autorizada produce un mensaje de error JSON-RPC unauthorized que el cliente puede manejar sin bloquearse.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- api
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Activo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 74/100