Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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 19 src/mcp/client/streamable_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,17 +558,22 @@ async def post_writer(
read_stream_writer=read_stream_writer,
)

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too broad of an error, we should be more specific about the type of Exception we handle here.

We should at least limit to HTTPStatusError if your problem is with HTTP errors specifically.

# 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") # pragma: no cover
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.