Add McpClientOptions.InitializeMeta to set _meta on the initialize request#1599
Open
adityasingh2400 wants to merge 1 commit into
Open
Add McpClientOptions.InitializeMeta to set _meta on the initialize request#1599adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
InitializeRequestParams already inherits Meta (_meta) from RequestParams, but McpClientImpl.ConnectAsync built the params without reading from McpClientOptions, so callers had no way to populate it. Add an InitializeMeta property on McpClientOptions and thread it through the handshake. Fixes modelcontextprotocol#1593
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.
Fixes #1593.
Problem
InitializeRequestParamsinheritsMeta([JsonPropertyName("_meta")]) fromRequestParams, in line with the 2025-11-25 schema, butMcpClientImpl.ConnectAsyncconstructs the params without reading fromMcpClientOptions. So the type supports_metaoninitializewhile the public client API offers no way to populate it. The current workaround is a customIClientTransportthat writes out-of-band data before the handshake, which couples the mechanism to the transport layer the SDK is meant to abstract.Fix
Add an
InitializeMetaproperty toMcpClientOptionsand pass it asMetawhen building theInitializeRequestParams. The protocol layer already models the field, so this is options-to-params plumbing only. WhenInitializeMetais null, no_metais sent, so existing behavior is unchanged.Testing
Added two tests to
McpClientMetaTeststhat use a server-side incoming message filter to capture theinitializerequest:InitializeMeta_IsSentToServer_WhenSetasserts the value set onMcpClientOptionsarrives in the server'sinitialize_meta.InitializeMeta_IsOmitted_WhenNotSetasserts no_metais sent by default.dotnet buildofModelContextProtocol.Coreis clean (warnings-as-errors). The fullMcpClientMetaTestsclass passes (5/5) on net10.0.