Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/mcp/client/streamable_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading