Skip to content

Commit 95d6e3f

Browse files
committed
fix: preserve reconnect attempt counter on second stream disconnect
When the SSE stream ends a second time without a response, the reconnect attempt counter was incorrectly reset to 0, causing infinite reconnect loops instead of properly backing off. Pass `attempt + 1` so the counter advances correctly.
1 parent cbe489e commit 95d6e3f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/mcp/client/streamable_http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ async def _handle_reconnection(
421421
await event_source.response.aclose()
422422
return
423423

424-
# Stream ended again without response - reconnect again (reset attempt counter)
424+
# Stream ended again without response - reconnect again
425425
logger.info("SSE stream disconnected, reconnecting...")
426-
await self._handle_reconnection(ctx, reconnect_last_event_id, reconnect_retry_ms, 0)
426+
await self._handle_reconnection(ctx, reconnect_last_event_id, reconnect_retry_ms, attempt + 1)
427427
except Exception as e: # pragma: no cover
428428
logger.debug(f"Reconnection failed: {e}")
429429
# Try to reconnect again if we still have an event ID

0 commit comments

Comments
 (0)