Skip to content

fix(client): allow missing server info in discovery - #1903

Open
Coding-Professional wants to merge 1 commit into
modelcontextprotocol:mainfrom
Coding-Professional:fix/1901-optional-server-info
Open

Coding-Professional wants to merge 1 commit into
modelcontextprotocol:mainfrom
Coding-Professional:fix/1901-optional-server-info

Conversation

@Coding-Professional

Copy link
Copy Markdown

Problem and change

Under the 2026-07-28 protocol, a server may omit io.modelcontextprotocol/serverInfo from its server/discover response. Today, reading McpClient.ServerInfo after that valid handshake throws InvalidOperationException. This makes a connected server with no identity metadata look like a disconnected client.

This change makes McpClient.ServerInfo nullable. It returns null when a connected server omits the optional metadata, continues to return the advertised identity when present, and still throws InvalidOperationException when the client is not connected. Explicitly malformed metadata still fails during connection with JsonException.

For example, a consumer can now use client.ServerInfo?.Name after connecting to a server that omits identity metadata.

The getter keeps the same CLR return type/signature, but the nullable annotation can introduce compiler warnings for downstream C# code that dereferences ServerInfo without a null check. I chose this because it makes the existing API safe for the valid protocol response. If maintainers prefer an additive TryGetServerInfo-style API for compatibility, I'm happy to revise the PR.

Validation

  • dotnet build -v quiet — passed with 0 warnings and 0 errors.
  • Core client and July 2026 protocol tests (net10.0) — 43 passed.
  • ASP.NET SSE and Streamable HTTP tests (net10.0) — 75 passed, 9 skipped.
  • The full core test suite was started but did not complete locally; the test host stopped making progress and the run was interrupted. No full-suite pass is claimed.

Fixes #1901

Copilot AI balanced review requested due to automatic review settings October 2, 2026 13:45

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK 2.2.0 - McpClient.ServerInfo throws when optional 2026-07-28 serverInfo metadata is absent

2 participants