Repository navigation
fix(client): allow missing server info in discovery - #1903
Coding-Professional wants to merge 1 commit into
Conversation
jeffhandley
left a comment
There was a problem hiding this comment.
Changing from non-nullable to nullable is technically a breaking change, so we will capture this in the release notes as such. The change looks good though and since this previously led to an exception, the breaking change is acceptable here.
Thank you both, @anushree1808 and @Coding-Professional!
|
Thanks for the reviews! Could you please rerun the failed Windows Release job? My account does not have permission to rerun it. The build succeeded, but the .NET 9 run failed in |
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