Skip to content

feat!: add server discovery and negotiation (SEP-2575)#973

Merged
DaleSeo merged 3 commits into
mainfrom
feat/sep-2575-discovery-negotiation
Jul 16, 2026
Merged

feat!: add server discovery and negotiation (SEP-2575)#973
DaleSeo merged 3 commits into
mainfrom
feat/sep-2575-discovery-negotiation

Conversation

@DaleSeo

@DaleSeo DaleSeo commented Jul 10, 2026

Copy link
Copy Markdown
Member

Motivation and Context

This implements the discovery and negotiation portion of SEP-2575. It adds the server/discover RPC, per-request protocol version negotiation, and typed unsupported-version errors so clients can learn a server's versions and capabilities without initializing a session, while preserving the legacy initialization flow.

All six protocol union enums generated by ts_union! are now #[non_exhaustive]. This requires downstream exhaustive matches to add a wildcard arm once, but allows future protocol variants to be added without causing the same Rust API break.

How Has This Been Tested?

Added tests with conformance coverage

Breaking Changes

Yes. ClientRequest, ClientNotification, ClientResult, ServerRequest, ServerNotification, and ServerResult are now #[non_exhaustive], so downstream exhaustive matches must add a wildcard arm. DiscoverRequest and DiscoverResult also add variants to ClientRequest and ServerResult; subsequent variants can be added without another exhaustive-match break.

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

@DaleSeo DaleSeo self-assigned this Jul 10, 2026
@github-actions github-actions Bot added T-test Testing related changes T-config Configuration file changes T-core Core library changes T-handler Handler implementation changes T-model Model/data structure changes T-service Service layer changes T-transport Transport layer changes labels Jul 10, 2026
@DaleSeo DaleSeo linked an issue Jul 10, 2026 that may be closed by this pull request
6 tasks
@DaleSeo DaleSeo changed the title feat!: add server discovery and negotiation feat!: add server discovery and negotiation [SEP-2575] Jul 10, 2026
@DaleSeo DaleSeo changed the title feat!: add server discovery and negotiation [SEP-2575] feat!: add server discovery and negotiation (SEP-2575) Jul 10, 2026
@DaleSeo DaleSeo linked an issue Jul 10, 2026 that may be closed by this pull request
7 tasks
@DaleSeo
DaleSeo marked this pull request as ready for review July 10, 2026 22:08
@DaleSeo
DaleSeo requested a review from a team as a code owner July 10, 2026 22:08
@DaleSeo DaleSeo added this to the 2026-07-28 spec milestone Jul 13, 2026
@DaleSeo DaleSeo removed this from the 2026-07-28 spec milestone Jul 13, 2026
@DaleSeo
DaleSeo force-pushed the feat/sep-2575-discovery-negotiation branch 2 times, most recently from ce0b7a9 to 4071398 Compare July 14, 2026 15:21
Comment thread crates/rmcp/src/model.rs
/// The request used a protocol version the server does not support.
pub const UNSUPPORTED_PROTOCOL_VERSION: Self = Self(-32022);
/// Processing the request requires a client capability that was not declared.
pub const MISSING_REQUIRED_CLIENT_CAPABILITY: Self = Self(-32021);

@DaleSeo DaleSeo Jul 14, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I initially set them to -32004 and -32003 following the SEP, but it failed the conformance suite. Then, I noticed that the error codes in the SEP differ from the draft schema. I reported this issue in modelcontextprotocol/modelcontextprotocol/issues/3091

  • SEP
Image
  • Schema
Image


/// Select the first client-preferred protocol version supported by the server.
///
/// Returns `None` when no version is shared.

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.

What happens in this case? When a client only expresses a preference the server doesn't yet support?

Shouldn't it fall back to the newest one the server does support?

@DaleSeo DaleSeo Jul 15, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is wired up in the follow-up client lifecycle PR, #995. preferred_versions contains every version the client supports in preference order. When the server returns UnsupportedProtocolVersionError, the client selects the first mutually supported unattempted version and retries. If there is no overlap, it returns NoCompatibleProtocolVersion. It intentionally does not select a server version the client does not support. This should match the spec: https://modelcontextprotocol.io/specification/draft/basic/versioning#protocol-version-negotiation

@DaleSeo
DaleSeo force-pushed the feat/sep-2575-discovery-negotiation branch 2 times, most recently from 5f0b865 to 2815005 Compare July 15, 2026 15:25
@DaleSeo
DaleSeo requested a review from alexhancock July 15, 2026 17:33
@github-actions github-actions Bot added the T-CI Changes to CI/CD workflows and configuration label Jul 15, 2026
@DaleSeo
DaleSeo force-pushed the feat/sep-2575-discovery-negotiation branch from ca01b27 to b1bc9fd Compare July 15, 2026 18:13
alexhancock
alexhancock previously approved these changes Jul 16, 2026
@DaleSeo
DaleSeo force-pushed the feat/sep-2575-discovery-negotiation branch from b1bc9fd to 9b69a72 Compare July 16, 2026 17:39
@alexhancock
alexhancock self-requested a review July 16, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2026-07-28 T-CI Changes to CI/CD workflows and configuration T-config Configuration file changes T-core Core library changes T-handler Handler implementation changes T-model Model/data structure changes T-service Service layer changes T-test Testing related changes T-transport Transport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SEP-2575: Make MCP Stateless

2 participants