Skip to content

Commit 80d1386

Browse files
fix(client): propagate HTTP transport exceptions to caller
ROOT CAUSE: In SSE and StreamableHTTP transports, when HTTP errors occur or other exceptions are raised in post_writer, exceptions are caught and logged but never sent to read_stream_writer, causing the caller to hang indefinitely waiting for a response that will never arrive. CHANGES: - sse.py: Send exceptions from post_writer to read_stream_writer - streamable_http.py: Send exceptions from post_writer to read_stream_writer IMPACT: This prevents callers from hanging when HTTP errors occur in the transport layer, ensuring exceptions are properly propagated to the caller for handling. FILES MODIFIED: - src/mcp/client/sse.py - src/mcp/client/streamable_http.py Reported-by: gspeter Github-Issue: #2110
1 parent 0fe16dd commit 80d1386

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/mcp/client/sse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ async def post_writer(endpoint_url: str):
144144
)
145145
response.raise_for_status()
146146
logger.debug(f"Client message sent successfully: {response.status_code}")
147-
except Exception: # pragma: lax no cover
147+
except Exception as exc: # pragma: lax no cover
148148
logger.exception("Error in post_writer")
149+
await read_stream_writer.send(exc)
149150
finally:
150151
await write_stream.aclose()
151152

src/mcp/client/streamable_http.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,9 @@ async def handle_request_async():
478478
else:
479479
await handle_request_async()
480480

481-
except Exception: # pragma: lax no cover
481+
except Exception as exc: # pragma: lax no cover
482482
logger.exception("Error in post_writer")
483+
await read_stream_writer.send(exc)
483484
finally:
484485
await read_stream_writer.aclose()
485486
await write_stream.aclose()

0 commit comments

Comments
 (0)