Skip to content

fix(client): answer a server ping during the initialize handshake - #1366

Merged
gocamille merged 5 commits into
modelcontextprotocol:mainfrom
gocamille:fix/client-ping-during-initialize
Oct 16, 2026
Merged

gocamille merged 5 commits into
modelcontextprotocol:mainfrom
gocamille:fix/client-ping-during-initialize

Conversation

@gocamille

@gocamille gocamille commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1362

Motivation and Context

expect_response now answers a server ping with an empty result while the client waits for the initialize response, instead of logging and dropping it. The reply goes straight onto the transport and a send failure becomes a transport error, matching how the server answers an early client ping (#745).

expect_response also handles the server/discover wait, so it takes an answer_ping flag: true for initialize, false for discover. Discover keeps ignoring the ping since 2026-07-28 has no ping. Auto mode's fallback goes through the initialize path, so it answers there too.

How Has This Been Tested?

  • client_answers_server_ping_during_initialize (test_client_initialization.rs): both sides on 2025-11-25. The server pings after reading initialize and before sending the result, then checks the next message is the ping response and the one after is notifications/initialized. Fails on main.
  • discover_startup_ignores_server_ping (test_client_lifecycle_modes.rs): the server pings before the discover result, and the next message it reads must be the client's tools/list. This passes on main too; it's there so the flag can't leak into the discover path.

Validation:

  • cargo test -p rmcp --features client --test test_client_initialization --test test_client_lifecycle_modes: passed (20 tests).
  • cargo test -p rmcp --all-features: passed.
  • cargo clippy --all-targets --all-features -- -D warnings and cargo +nightly fmt --all -- --check: clean.

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

@github-actions github-actions Bot added T-test Testing related changes T-core Core library changes T-service Service layer changes labels Oct 15, 2026
@github-actions
github-actions Bot requested a review from bolinfest October 15, 2026 13:00
@github-actions

Copy link
Copy Markdown
Contributor

@bolinfest is on triage rotation this week and is the reviewer for this one.

Labels come from the PR labeler. Please review the change.

Automated triage. Labels are a first pass and the assigned maintainer has the final say.

@gocamille
gocamille marked this pull request as ready for review October 15, 2026 15:28
@gocamille
gocamille requested a review from a team as a code owner October 15, 2026 15:28
@gocamille gocamille self-assigned this Oct 15, 2026
Comment thread crates/rmcp/src/service/client.rs Outdated
Comment thread crates/rmcp/tests/test_client_initialization.rs
Comment thread crates/rmcp/tests/test_client_lifecycle_modes.rs Outdated
Comment thread crates/rmcp/src/service/client.rs Outdated
expect_response dropped a server ping while waiting for the initialize
response, so the ping never got a reply. Answer it with an empty result
during the initialize wait, the same way the server answers an early
client ping. The server/discover wait still leaves it unanswered.

Refs modelcontextprotocol#745
Fixes modelcontextprotocol#1362
@gocamille
gocamille force-pushed the fix/client-ping-during-initialize branch from 2746663 to 4b06f72 Compare October 16, 2026 17:55
@gocamille
gocamille requested a review from DaleSeo October 16, 2026 18:16
DaleSeo
DaleSeo previously approved these changes Oct 16, 2026

@DaleSeo DaleSeo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, @gocamille. Just one extra comment before merging.

Comment thread crates/rmcp/src/service/client.rs Outdated
The compiler now flags this spot if PreInitPing gains a variant, and
the PartialEq and Eq derives are no longer needed.
@gocamille
gocamille merged commit a156be8 into modelcontextprotocol:main Oct 16, 2026
24 checks passed
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 T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client never answers a server ping sent during the initialize handshake

2 participants