Skip to content

Conversation

ChenyangLi4288
Copy link

Brief summary of changes

  • Add RequestResponder.mark_cancelled_without_response() to support silent cancellation.
  • Use silent cancellation in BaseSession._receive_loop() when handling CancelledNotification.
  • When emitting a CancelledNotification, proactively cancel the local pending request so send_request() unblocks with McpError("Request cancelled").

Motivation and Context

  • Aligns with MCP spec guidance: receivers of cancellation notifications SHOULD not send a response.
  • Fixes protocol compliance gap described in issue #1419 (link).

How Has This Been Tested?

  • Ran tests/shared/test_session.py::test_request_cancellation to confirm the client’s in-flight request is cancelled promptly without waiting for a peer response.
  • Sanity-checked other session paths to ensure no regressions; linter clean.

Breaking Changes

  • None. Behavior change only affects cancellation-notification flows and makes them spec-compliant.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

  • Implements silent cancellation per spec and avoids emitting JSON-RPC error responses upon receiving CancelledNotification, improving interoperability and reducing unnecessary traffic.

…l pending requester when emitting CancelledNotification (spec SHOULD-not response)
…ncellation for CancelledNotification + local requester cancellation
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.

1 participant