Skip to content

server: skip duplicate response on CancelledError #1153

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

lukacf
Copy link

@lukacf lukacf commented Jul 16, 2025

When clients cancel long-running tool calls, the server crashes with an assertion error and becomes unresponsive. This PR fixes the issue by preventing duplicate responses.

Problem

  • RequestResponder.cancel() sends an error response when cancelled
  • _handle_request tries to send another error response
  • This causes "Request already responded to" assertion
  • Server becomes completely unresponsive

Solution

Catch CancelledError in _handle_request and return early without sending a second response.

Testing

Added test that cancels a tool call and verifies the server remains responsive.

Fixes #1152
Related: jlowin/fastmcp#508, jlowin/fastmcp#823

lukacf added 6 commits July 16, 2025 12:31
When a tool call is cancelled, RequestResponder.cancel() sends an error
response. Previously, _handle_request would try to send another error
response, causing "Request already responded to" assertion.

This fix catches CancelledError and returns early, preventing the
duplicate response.

Fixes modelcontextprotocol#1152
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CancelledError causes duplicate response and server crash
1 participant