Skip to content

Commit c4e95fc

Browse files
fix exception propagation
1 parent ef4e167 commit c4e95fc

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/mcp/client/streamable_http.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,17 @@ async def post_writer(
399399
)
400400

401401
async def handle_request_async():
402-
if is_resumption:
403-
await self._handle_resumption_request(ctx)
404-
else:
405-
await self._handle_post_request(ctx)
402+
try:
403+
if is_resumption:
404+
await self._handle_resumption_request(ctx)
405+
else:
406+
await self._handle_post_request(ctx)
407+
except Exception as e:
408+
# Send exception to main session for proper error handling
409+
try:
410+
await ctx.read_stream_writer.send(e)
411+
except Exception as e:
412+
logger.exception(f"Failed to send exception to read stream: {e}")
406413

407414
# If this is a request, start a new task to handle it
408415
if isinstance(message.root, JSONRPCRequest):

0 commit comments

Comments
 (0)