modelcontextprotocol / modelcontextprotocol/csharp-sdk

Add prior-knowledge connection path for modern protocol clients

Open
#1,696 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement needs confirmation P2
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; sends server/discover and falls back to legacy initialize when appropriate.
  • ProtocolVersion = "2026-07-28": sends server/discover and requires a modern result; does not fall back to legacy.
  • Legacy exact versions such as "2025-11-25": skip server/discover and use legacy initialize.
  • No public API was found for providing a cached DiscoverResult or directly adopting a known modern protocol version.

Relevant C# files:

  • src/ModelContextProtocol.Core/Client/McpClientOptions.cs
  • src/ModelContextProtocol.Core/Client/McpClientImpl.cs
  • src/ModelContextProtocol.Core/Protocol/DiscoverResult.cs

Tier 1 SDK references

TypeScript SDK

TypeScript exposes the strongest explicit prior-knowledge shape:

  • ConnectOptions.prior?: DiscoverResult lets callers provide a previously obtained discovery result.
  • _connectFromPrior(...) bypasses version negotiation and server/discover, adopts capabilities/server info/instructions, and sets the negotiated protocol version.
  • getDiscoverResult() returns a reusable DiscoverResult.

References:

Python SDK

Python supports both an explicit cached-discovery path and a simple direct-modern mode:

  • Client(mode="auto") probes with server/discover and falls back.
  • Client(mode="2026-07-28") adopts the modern protocol directly without sending server/discover.
  • prior_discover can provide a cached DiscoverResult.
  • ClientSession.adopt() installs an InitializeResult or DiscoverResult without wire traffic.
  • ClientSession.discover_result exposes the round-trippable discovery result for reuse.

References:

Go SDK

Go has solid 2026-07-28 plumbing but does not appear to expose a public prior-knowledge client API:

  • Client.Connect defaults to latest 2026-07-28, sends server/discover, negotiates, and falls back to legacy initialize when needed.
  • ClientSessionOptions.protocolVersion is unexported and documented as a testing override.
  • Server discover advertises 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:

Proposed C# API direction

Add a distinct opt-in prior-knowledge path, for example:

  • McpClientOptions.KnownDiscoverResult or McpClientOptions.PriorDiscoverResult: adopt a trusted discovery result and skip server/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 ProtocolVersion semantics 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 ProtocolVersion behavior remain backward compatible.
  • Per-request _meta and 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.