modelcontextprotocol / modelcontextprotocol/csharp-sdk
Add prior-knowledge connection path for modern protocol clients
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 814
- Avg merge
- 9d 19h
- Merged PRs (30d)
- 4
Description
Summary
Add a C# client API for 2026-07-28+ connections that lets callers skip the server/discover round trip when they already have trusted prior knowledge about the server. This should be distinct from McpClientOptions.ProtocolVersion, so exact version pinning can continue to mean "require this version / disable fallback" rather than "skip discovery."
Motivation
Today, setting McpClientOptions.ProtocolVersion = "2026-07-28" disables legacy fallback, but the client still sends server/discover before adopting the modern protocol. That is safe, but it leaves no zero-round-trip path for known modern servers or for clients that have cached a previous DiscoverResult.
A separate prior-knowledge API would improve startup latency and align C# with the stronger ergonomics in the other Tier 1 SDKs while preserving C#'s current safe defaults.
Current C# behavior
ProtocolVersion = null: default modern auto path; sendsserver/discoverand falls back to legacyinitializewhen appropriate.ProtocolVersion = "2026-07-28": sendsserver/discoverand requires a modern result; does not fall back to legacy.- Legacy exact versions such as
"2025-11-25": skipserver/discoverand use legacyinitialize. - No public API was found for providing a cached
DiscoverResultor directly adopting a known modern protocol version.
Relevant C# files:
src/ModelContextProtocol.Core/Client/McpClientOptions.cssrc/ModelContextProtocol.Core/Client/McpClientImpl.cssrc/ModelContextProtocol.Core/Protocol/DiscoverResult.cs
Tier 1 SDK references
TypeScript SDK
TypeScript exposes the strongest explicit prior-knowledge shape:
ConnectOptions.prior?: DiscoverResultlets callers provide a previously obtained discovery result._connectFromPrior(...)bypasses version negotiation andserver/discover, adopts capabilities/server info/instructions, and sets the negotiated protocol version.getDiscoverResult()returns a reusableDiscoverResult.
References:
- https://github.com/modelcontextprotocol/typescript-sdk/blob/main/packages/client/src/client/client.ts
- Look for
ConnectOptions.prior,_connectFromPrior, andgetDiscoverResult.
Python SDK
Python supports both an explicit cached-discovery path and a simple direct-modern mode:
Client(mode="auto")probes withserver/discoverand falls back.Client(mode="2026-07-28")adopts the modern protocol directly without sendingserver/discover.prior_discovercan provide a cachedDiscoverResult.ClientSession.adopt()installs anInitializeResultorDiscoverResultwithout wire traffic.ClientSession.discover_resultexposes the round-trippable discovery result for reuse.
References:
- https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/client/client.py
- https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/client/session.py
- Look for
ConnectMode,prior_discover,adopt, anddiscover_result.
Go SDK
Go has solid 2026-07-28 plumbing but does not appear to expose a public prior-knowledge client API:
Client.Connectdefaults to latest2026-07-28, sendsserver/discover, negotiates, and falls back to legacyinitializewhen needed.ClientSessionOptions.protocolVersionis unexported and documented as a testing override.- Server
discoveradvertises transport-filtered supported versions. - Go also implements modern per-request
_meta, standard HTTP headers,subscriptions/listen, multi-round-trip helpers, and TTL caches for modern list/read results.
References:
- https://github.com/modelcontextprotocol/go-sdk/blob/main/mcp/client.go
- https://github.com/modelcontextprotocol/go-sdk/blob/main/mcp/server.go
- https://github.com/modelcontextprotocol/go-sdk/blob/main/mcp/cache.go
- https://github.com/modelcontextprotocol/go-sdk/blob/main/docs/protocol.md
Proposed C# API direction
Add a distinct opt-in prior-knowledge path, for example:
McpClientOptions.KnownDiscoverResultorMcpClientOptions.PriorDiscoverResult: adopt a trusted discovery result and skipserver/discover.- Optionally, a direct-modern option such as
AssumeProtocolVersion = "2026-07-28"for callers that only know the protocol version but do not have server info/capabilities yet. - Keep
ProtocolVersionsemantics unchanged: exact modern version should still probe and require a compatible result unless the new prior-knowledge option is used.
Acceptance criteria
- A caller can connect to a known 2026-07-28+ server without sending
server/discover. - A caller can retrieve or construct the prior-knowledge payload needed for a later zero-round-trip connection.
- Existing default auto-negotiation and exact
ProtocolVersionbehavior remain backward compatible. - Per-request
_metaand HTTP headers continue to be populated correctly after prior-knowledge adoption. - Tests cover default auto, exact modern pin, cached prior discovery, and invalid/incompatible prior discovery.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading McpClientOptions.cs, McpClientImpl.cs, and DiscoverResult.cs to trace current modern discovery, exact-version, and legacy fallback behavior. Compare the referenced TypeScript and Python prior-knowledge paths, then add tests for default auto-negotiation, exact modern pinning, cached prior discovery, and invalid or incompatible prior discovery. Done means a trusted modern connection skips server/discover while existing behavior and per-request metadata remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100