Skip to content

Server is not responding to ping requests when long async handler is running #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jezekra1 opened this issue Feb 3, 2025 · 0 comments · Fixed by #206
Closed

Server is not responding to ping requests when long async handler is running #188

jezekra1 opened this issue Feb 3, 2025 · 0 comments · Fixed by #206
Labels
bug Something isn't working

Comments

@jezekra1
Copy link

jezekra1 commented Feb 3, 2025

Describe the bug
Due to the synchronous handling of messages in the order they come in (in lowlevel server.run method), if a single message takes longer, other requests are blocked.

This is also true for the PingRequest which should only serve as a healthcheck and be always handled immediately in my opinion.
This also prevents efficient use of asyncio - for example running multiple tool calls concurrently in a single client session.

async for message in session.incoming_messages:

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'mcp_simple_tool/server.py' example and add 20 seconds asyncio.sleep to the tool.
  2. Then call the tool using MCP client
  3. Send ping immediately afterwards - concurrently (i.e. using 2 asyncio tasks)

This could be easily solved by processing messages concurrently, naive code:

async for message in session.incoming_messages:
    async def handle_message():
        match message:
            case RequestResponder(request=types.ClientRequest(root=req):
               await self._handle_request( message, req, session, raise_exceptions)
            case types.ClientNotification(root=notify):
                await self._handle_notification(notify)
    tg.start_soon(handle_message)

I suppose there can still be legitimate reasons to process the messages synchronously "in order", but in that case would it be possible to extract at least the PingRequest to be handled immediately?

Thanks for all the amazing work! :)

@dsp-ant dsp-ant added the bug Something isn't working label Feb 6, 2025
@jerome3o-anthropic jerome3o-anthropic mentioned this issue Feb 13, 2025
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants