Skip to content

Skip notification in initialization handshake#421

Merged
4t145 merged 2 commits intomodelcontextprotocol:mainfrom
quangIO:main
Sep 8, 2025
Merged

Skip notification in initialization handshake#421
4t145 merged 2 commits intomodelcontextprotocol:mainfrom
quangIO:main

Conversation

@quangIO
Copy link
Copy Markdown
Contributor

@quangIO quangIO commented Sep 5, 2025

This allows supporting nonconforming MCP servers by skipping notification in initialization handshake.

Fix #412

Motivation and Context

How Has This Been Tested?

Tested with DesktopCommanderMCP. All standard MCP servers continue to work normally.

Breaking Changes

None

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

@github-actions github-actions bot added T-core Core library changes T-service Service layer changes labels Sep 5, 2025
@4t145
Copy link
Copy Markdown
Contributor

4t145 commented Sep 5, 2025

@vorporeal Could you help review this pr?

}
ServerJsonRpcMessage::Notification(notification) => {
let notification = serde_json::to_string(&notification).unwrap_or_default();
tracing::debug!(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we use handler's implementation to handle notifications?

Copy link
Copy Markdown
Contributor Author

@quangIO quangIO Sep 5, 2025

Choose a reason for hiding this comment

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

Could you point out how should we do that?

Sorry I am not familiar with the code base enough so I try to keep it simple in this PR. Moreover, the type of MCP doing this doesn't follow the specs (EDIT: specs' recommendations). The connection is not consider established so we only debug log for courtesy. The handler assumes the connection is established right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The connection is not consider established so we only debug log for courtesy.

The spec allow both server and client send log and ping notification before initialization. But I am not sure about that should the peer side handle those notifications. I assume that some one may use a customized logger in handler's on_log_notification method, and that person would miss the log before initialization.

Could you point out how should we do that?

We can pass the handler into this function and let the handler handle ping and log notifications. (If all of us think it's reasonable).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done! Please review them again.

We handle the initialization process more robustly.
- Allow logging and ping
- For other messages, we simply ignore it instead of rejecting right away
@quangIO quangIO requested a review from 4t145 September 5, 2025 11:46
@4t145 4t145 merged commit a2fc90a into modelcontextprotocol:main Sep 8, 2025
11 checks passed
@github-actions github-actions bot mentioned this pull request Sep 8, 2025
takumi-earth pushed a commit to earthlings-dev/rmcp that referenced this pull request Jan 27, 2026
* fix: handle logging and ping in handshake

We handle the initialization process more robustly.
- Allow logging and ping
- For other messages, we simply ignore it instead of rejecting right away

* fix: inject context to notification handler
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-service Service layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client implementation is not robust to ill-conforming servers during initialization handshake

2 participants