modelcontextprotocol / modelcontextprotocol/python-sdk
Streamable HTTP clean EOF reconnects can exceed the request retry budget
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
Description
The streamable HTTP client can exceed its per-request SSE reconnection budget when each reconnect opens successfully, emits only an id-bearing priming event, and then reaches EOF without a JSON-RPC response.
In that case _handle_reconnection() currently recurses with attempt=0 after the clean EOF path. The exception path increments the counter, but the normal EOF-without-response path resets it, so a no-timeout request such as subscriptions/listen can keep reconnecting instead of resolving the waiter with CONNECTION_CLOSED after MAX_RECONNECTION_ATTEMPTS.
Reproduction
Drive StreamableHTTPTransport._handle_reconnection() with a mock HTTP transport that returns these per-request SSE responses:
- Reconnect 1:
id: evt-1with emptydata, then EOF. - Reconnect 2:
id: evt-2with emptydata, then EOF. - Reconnect 3: a JSON-RPC success response.
Starting from Last-Event-ID: evt-0 and retry_interval_ms=0, current main makes the third HTTP request and delivers the success response. I expected the client to stop after the two configured reconnect attempts, emit a JSONRPCError for the original request with CONNECTION_CLOSED, and only send Last-Event-ID: evt-0 and Last-Event-ID: evt-1.
Expected Behavior
Each per-request reconnect that reaches EOF without delivering a JSON-RPC response should consume the reconnect budget. That keeps request-scoped SSE drops consistent whether they end by transport exception or by clean EOF, and prevents no-timeout callers from staying parked forever when a server repeatedly closes resumable streams without producing the response.
Local Verification
I have a local regression test that fails on current main because the third reconnect response is accepted, then passes when the clean EOF path recurses with attempt + 1.
Commands run locally:
uv run --frozen pytest tests/client/test_streamable_http.py::test_empty_resumable_sse_reconnects_count_toward_the_request_budget -quv run --frozen pytest tests/client/test_streamable_http.py -quv run --frozen ruff check src/mcp/client/streamable_http.py tests/client/test_streamable_http.pyuv run --frozen ruff format --check src/mcp/client/streamable_http.py tests/client/test_streamable_http.pyuv run --frozen pyright src/mcp/client/streamable_http.py tests/client/test_streamable_http.pyUV_FROZEN=1 uv run --frozen strict-no-cover
Disclosure: I used AI assistance to help prepare this report and a local patch; I reviewed the reproduction, root cause, and test results.
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 con StreamableHTTPTransport._handle_reconnection() en src/mcp/client/streamable_http.py y después lee test_empty_resumable_sse_reconnects_count_toward_the_request_budget en tests/client/test_streamable_http.py. Ejecuta primero esa prueba de regresión y el archivo de pruebas completo de streamable HTTP. Se considera terminado cuando los EOF limpios sin una respuesta JSON-RPC consumen el presupuesto de reconexión de la solicitud y resuelven el waiter con CONNECTION_CLOSED.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- api, networking
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Activo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 88/100