python-sdk
python-sdk copied to clipboard
Fixes protocol compliance gap described in issue #1419
Brief summary of changes
- Add
RequestResponder.mark_cancelled_without_response()to support silent cancellation. - Use silent cancellation in
BaseSession._receive_loop()when handlingCancelledNotification. - When emitting a
CancelledNotification, proactively cancel the local pending request sosend_request()unblocks withMcpError("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_cancellationto 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.
any chance of getting review? @felixweinberger