From 66c844a8dc636cd5c796dabf241e29f09b64fdb5 Mon Sep 17 00:00:00 2001 From: lorenss-m Date: Wed, 13 Aug 2025 04:19:06 -0700 Subject: [PATCH] http error gets pushed through --- src/mcp/client/streamable_http.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/mcp/client/streamable_http.py b/src/mcp/client/streamable_http.py index b1ab2c079..ec1ad99ea 100644 --- a/src/mcp/client/streamable_http.py +++ b/src/mcp/client/streamable_http.py @@ -400,17 +400,22 @@ async def post_writer( sse_read_timeout=self.sse_read_timeout, ) - async def handle_request_async(): - if is_resumption: - await self._handle_resumption_request(ctx) - else: - await self._handle_post_request(ctx) + async def handle_request_async(ctx: RequestContext, is_resumption: bool) -> None: + try: + if is_resumption: + await self._handle_resumption_request(ctx) + else: + await self._handle_post_request(ctx) + except Exception as e: + # Send error to read stream so client knows request failed + logger.error("Request handler error: %s", e) + await ctx.read_stream_writer.send(e) # If this is a request, start a new task to handle it if isinstance(message.root, JSONRPCRequest): - tg.start_soon(handle_request_async) + tg.start_soon(handle_request_async, ctx, is_resumption) else: - await handle_request_async() + await handle_request_async(ctx, is_resumption) except Exception: logger.exception("Error in post_writer")