Skip to content

Add McpClientOptions.InitializeMeta to set _meta on the initialize request#1599

Open
adityasingh2400 wants to merge 1 commit into
modelcontextprotocol:mainfrom
adityasingh2400:initialize-meta-option
Open

Add McpClientOptions.InitializeMeta to set _meta on the initialize request#1599
adityasingh2400 wants to merge 1 commit into
modelcontextprotocol:mainfrom
adityasingh2400:initialize-meta-option

Conversation

@adityasingh2400
Copy link
Copy Markdown

Fixes #1593.

Problem

InitializeRequestParams inherits Meta ([JsonPropertyName("_meta")]) from RequestParams, in line with the 2025-11-25 schema, but McpClientImpl.ConnectAsync constructs the params without reading from McpClientOptions. So the type supports _meta on initialize while the public client API offers no way to populate it. The current workaround is a custom IClientTransport that 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 InitializeMeta property to McpClientOptions and pass it as Meta when building the InitializeRequestParams. The protocol layer already models the field, so this is options-to-params plumbing only. When InitializeMeta is null, no _meta is sent, so existing behavior is unchanged.

Testing

Added two tests to McpClientMetaTests that use a server-side incoming message filter to capture the initialize request:

  • InitializeMeta_IsSentToServer_WhenSet asserts the value set on McpClientOptions arrives in the server's initialize _meta.
  • InitializeMeta_IsOmitted_WhenNotSet asserts no _meta is sent by default.

dotnet build of ModelContextProtocol.Core is clean (warnings-as-errors). The full McpClientMetaTests class passes (5/5) on net10.0.

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
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.

McpClientOptions has no way to inject _meta into the initialize request

1 participant