python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

Fixes protocol compliance gap described in issue #1419

Open ChenyangLi4288 opened this issue 4 months ago • 1 comments

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

  • [x] 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

  • [x] I have read the MCP Documentation
  • [x] My code follows the repository's style guidelines
  • [x] New and existing tests pass locally
  • [x] 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.

ChenyangLi4288 avatar Oct 07 '25 15:10 ChenyangLi4288

any chance of getting review? @felixweinberger

ChenyangLi4288 avatar Nov 25 '25 00:11 ChenyangLi4288