Skip to content

Commit 66c844a

Browse files
committed
http error gets pushed through
1 parent eaf7cf4 commit 66c844a

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/mcp/client/streamable_http.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,17 +400,22 @@ async def post_writer(
400400
sse_read_timeout=self.sse_read_timeout,
401401
)
402402

403-
async def handle_request_async():
404-
if is_resumption:
405-
await self._handle_resumption_request(ctx)
406-
else:
407-
await self._handle_post_request(ctx)
403+
async def handle_request_async(ctx: RequestContext, is_resumption: bool) -> None:
404+
try:
405+
if is_resumption:
406+
await self._handle_resumption_request(ctx)
407+
else:
408+
await self._handle_post_request(ctx)
409+
except Exception as e:
410+
# Send error to read stream so client knows request failed
411+
logger.error("Request handler error: %s", e)
412+
await ctx.read_stream_writer.send(e)
408413

409414
# If this is a request, start a new task to handle it
410415
if isinstance(message.root, JSONRPCRequest):
411-
tg.start_soon(handle_request_async)
416+
tg.start_soon(handle_request_async, ctx, is_resumption)
412417
else:
413-
await handle_request_async()
418+
await handle_request_async(ctx, is_resumption)
414419

415420
except Exception:
416421
logger.exception("Error in post_writer")

0 commit comments

Comments
 (0)