fix: add compatibility handling for non-standard notifications #247
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses the issue where the Rust SDK fails to parse messages containing non-standard notifications (like
notifications/stderr
from @modelcontextprotocol/server-everything ), causing connection failures and preventing proper MCP communication.The solution implements graceful handling of non-standard notifications at the transport layer in
crates/rmcp/src/transport/async_rw.rs
:is_standard_notification
function to check for standard MCP notifications.try_parse_with_compatibility
function to handle parsing messages with compatibility for non-standard notifications.Motivation and Context
Problem: When connecting to MCP servers that send non-standard notifications (such as Claude Desktop's
notifications/stderr
), the Rust SDK fails to deserialize these messages, causing the entire connection to fail with parsing errors.Root Cause: The SDK's strict adherence to the MCP specification means any non-standard notification causes a deserialization failure, breaking the communication channel.
Why This Approach: Instead of hardcoding specific non-standard notification types into the core model (which would pollute the standard and require updates for each new non-standard notification), this solution:
How Has This Been Tested?
notifications/stderr
is_standard_notification
andtry_parse_with_compatibility
functionsBreaking Changes
None. This is a backward-compatible change that:
Types of changes
Checklist
Additional context
Design Philosophy: This solution follows the principle of "be liberal in what you accept, conservative in what you send." The SDK remains strict about outgoing messages (maintaining standard compliance) while being tolerant of incoming non-standard notifications.
Alternative Approaches Considered:
Implementation Notes:
is_standard_notification
function should be updated when new official notifications are added to the MCP specificationFuture Considerations: