Add prior discovery client connections#1697
Open
halter73 wants to merge 1 commit into
Open
Conversation
Adds an opt-in PriorDiscoverResult client option for trusted modern discovery snapshots, exposes McpClient.GetDiscoverResult(), and reuses the discovery adoption path so clients can skip server/discover when reconnecting with prior knowledge. Adds tests for zero-probe prior discovery, pinned-version validation, invalid legacy combinations, reusable snapshots, and 2026-07-28 per-request metadata emission. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in “prior knowledge” connection path for modern (2026-07-28+) MCP clients, allowing callers to skip the server/discover probe when they already have a trusted discovery snapshot, while preserving existing protocol pinning and fallback semantics.
Changes:
- Introduces
McpClientOptions.PriorDiscoverResultto adopt a trustedDiscoverResultand bypassserver/discover. - Adds
McpClient.GetDiscoverResult()(and an override inMcpClientImpl) to provide reusable discovery snapshots including cache hints. - Updates stateless protocol documentation and adds tests for the new connection + required
_metaemission behavior.
Show a summary per file
| File | Description |
|---|---|
| tests/ModelContextProtocol.Tests/Client/July2026ProtocolListMetaEmissionTests.cs | Adds coverage to ensure required _meta is emitted when connecting via prior discovery. |
| tests/ModelContextProtocol.Tests/Client/July2026ProtocolConnectionTests.cs | Adds prior-discovery connection tests (skip discover, pin semantics, invalid prior cases, snapshot cloning). |
| src/ModelContextProtocol.Core/Client/McpClientOptions.cs | Adds PriorDiscoverResult option with XML docs describing behavior and constraints. |
| src/ModelContextProtocol.Core/Client/McpClientImpl.cs | Implements adopting prior discovery, cloning/storing discover results, and overriding GetDiscoverResult(). |
| src/ModelContextProtocol.Core/Client/McpClient.cs | Adds public virtual GetDiscoverResult() API and documentation. |
| docs/concepts/stateless/stateless.md | Documents the prior-knowledge reconnect path and example usage. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 1
- Review effort level: Low
Comment on lines
+72
to
+74
| /// The default implementation returns a minimal discovery result containing only the negotiated | ||
| /// protocol version. Concrete clients may override this to preserve the full <c>server/discover</c> | ||
| /// response, including every server-supported version and caching hints. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
McpClientOptions.PriorDiscoverResultso trusted modern discovery snapshots can skip theserver/discoverprobe.McpClient.GetDiscoverResult()for reusable discovery snapshots, including cache hints.Closes #1696