Skip to content

Fixes protocol compliance gap described in issue #1419#1440

Open
ChenyangLi4288 wants to merge 2 commits into
modelcontextprotocol:mainfrom
ChenyangLi4288:main
Open

Fixes protocol compliance gap described in issue #1419#1440
ChenyangLi4288 wants to merge 2 commits into
modelcontextprotocol:mainfrom
ChenyangLi4288:main

Conversation

@ChenyangLi4288
Copy link
Copy Markdown

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
@felixweinberger felixweinberger added needs more eyes auth Issues and PRs related to Authentication / OAuth labels Oct 8, 2025
@felixweinberger felixweinberger added needs maintainer Potentially serious issue - needs proactive fix and maintainer attention and removed needs more eyes auth Issues and PRs related to Authentication / OAuth labels Oct 13, 2025
@ChenyangLi4288
Copy link
Copy Markdown
Author

any chance of getting review? @felixweinberger

@BossChaos

This comment was marked as abuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs maintainer Potentially serious issue - needs proactive fix and maintainer attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants