Skip to content

Conversation

@loocor
Copy link
Contributor

@loocor loocor commented Sep 3, 2025

  • Gracefully ignore non-MCP notifications (like window/logMessage) for compatibility
  • Add proper MCP method validation based on 2025-06-18 specification
  • Fix connection failures with servers like 21Magic that send IDE integration messages

Resolves connection closed errors during initialization with mixed-protocol servers.

Motivation and Context

Certain MCP servers (like 21Magic) send LSP (Language Server Protocol) notifications such as window/logMessage for IDE integration purposes. These messages, while valid JSON-RPC 2.0, are not part of the MCP specification and cause the Rust SDK to fail parsing, resulting in connection termination.

This change implements graceful handling of non-MCP notifications while maintaining strict parsing for actual MCP messages, ensuring compatibility with servers that send mixed protocol messages for enhanced IDE integration.

How Has This Been Tested?

  • Tested with 21Magic server - successfully connects and operates with 4 tools synced
  • Verified backward compatibility with existing MCP servers
  • Confirmed LSP messages are gracefully ignored with appropriate trace logging
  • Validated that standard MCP message parsing remains unaffected
  • Compilation and linting checks pass

Breaking Changes

None. This is a backward-compatible fix that only affects error handling paths. All existing MCP servers continue to work without any changes required.

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

Implementation Details:

  • Added is_standard_method() function based on MCP specification 2025-06-18
  • Added should_ignore_notification() helper for compatibility checks
  • Enhanced try_parse_with_compatibility() to handle mixed-protocol scenarios
  • Uses trace level logging for ignored messages to avoid log pollution

Design Decisions:

  • Only notifications (messages without id field) are subject to lenient parsing
  • Request/response messages maintain strict MCP compliance
  • Follows existing code patterns using matches! macro for consistency
  • Minimal performance impact - compatibility checks only occur on parse failures

This fix enables broader MCP ecosystem compatibility, particularly with servers that integrate with IDEs through LSP messages while maintaining full protocol compliance for standard MCP operations.

- Gracefully ignore non-MCP notifications (like window/logMessage) for compatibility
- Add proper MCP method validation based on 2025-06-18 specification
- Fix connection failures with servers like 21Magic that send IDE integration messages

Resolves connection closed errors during initialization with mixed-protocol servers.
@github-actions github-actions bot added T-core Core library changes T-transport Transport layer changes labels Sep 3, 2025
Copy link
Collaborator

@4t145 4t145 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@4t145 4t145 merged commit b514bc4 into modelcontextprotocol:main Sep 4, 2025
11 checks passed
@github-actions github-actions bot mentioned this pull request Sep 3, 2025
takumi-earth pushed a commit to earthlings-dev/rmcp that referenced this pull request Jan 27, 2026
…ons (modelcontextprotocol#413)

- Gracefully ignore non-MCP notifications (like window/logMessage) for compatibility
- Add proper MCP method validation based on 2025-06-18 specification
- Fix connection failures with servers like 21Magic that send IDE integration messages

Resolves connection closed errors during initialization with mixed-protocol servers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-transport Transport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants