fix(client): allow missing server info in discovery - #1903
Open
Coding-Professional wants to merge 1 commit into
Open
Coding-Professional wants to merge 1 commit into
Coding-Professional wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Problem and change
Under the 2026-07-28 protocol, a server may omit
io.modelcontextprotocol/serverInfofrom itsserver/discoverresponse. Today, readingMcpClient.ServerInfoafter that valid handshake throwsInvalidOperationException. This makes a connected server with no identity metadata look like a disconnected client.This change makes
McpClient.ServerInfonullable. It returnsnullwhen a connected server omits the optional metadata, continues to return the advertised identity when present, and still throwsInvalidOperationExceptionwhen the client is not connected. Explicitly malformed metadata still fails during connection withJsonException.For example, a consumer can now use
client.ServerInfo?.Nameafter 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
ServerInfowithout a null check. I chose this because it makes the existing API safe for the valid protocol response. If maintainers prefer an additiveTryGetServerInfo-style API for compatibility, I'm happy to revise the PR.Validation
dotnet build -v quiet— passed with 0 warnings and 0 errors.net10.0) — 43 passed.net10.0) — 75 passed, 9 skipped.Fixes #1901