Skip to content

Conversation

@mikekistler
Copy link
Contributor

Motivation and Context

This PR adds the ability to set fields of the _meta parameter in requests with the high-level request methods.

It also refactored these methods to move several parameters common in request methods -- JsonSerializerOptions, ProgressToken, and the new Meta field -- to an options bag to make these signatures more concise.

How Has This Been Tested?

All tests pass with the revised method signatures.

Breaking Changes

This will be breaking (as currently implemented) for users that specify any of these (uncommonly used) parameters.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Some new features in the 2025-11-25 version of the MCP spec require setting and reading fields of _meta, e.g. SEP-1686: Tasks. This change will make it easier for users to access these new features.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a RequestOptions class to consolidate common optional parameters (Meta, JsonSerializerOptions, and ProgressToken) across MCP client and server request methods. This refactoring reduces method signature complexity and enables setting the _meta field in requests, which is needed for new MCP spec features like SEP-1686 (Tasks).

Key Changes

  • Added new RequestOptions class to hold optional request parameters
  • Updated all client and server request method signatures to accept RequestOptions instead of individual parameters
  • Created PingRequestParams protocol class for structured ping requests
  • Updated tests to use the new method signatures with named parameters or null for options

Reviewed Changes

Copilot reviewed 32 out of 33 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/ModelContextProtocol.Core/RequestOptions.cs New options bag class with Meta, JsonSerializerOptions, and ProgressToken properties
src/ModelContextProtocol.Core/Protocol/PingRequestParams.cs New protocol parameter class for ping requests
src/ModelContextProtocol.Core/Client/McpClient.Methods.cs Updated all client methods to accept RequestOptions and properly set Meta in request params
src/ModelContextProtocol.Core/Server/McpServer.Methods.cs Updated SampleAsync and RequestRootsAsync to accept RequestOptions
src/ModelContextProtocol.Core/Client/McpClientExtensions.cs Updated extension methods to wrap individual parameters in RequestOptions
src/ModelContextProtocol.Core/Server/McpServerExtensions.cs Updated extension methods to forward calls with named parameters
src/ModelContextProtocol.Core/Client/McpClient*.cs Updated client wrapper classes to construct RequestOptions when calling client methods
src/ModelContextProtocol.Core/McpJsonUtilities.cs Added PingRequestParams to source generation context
tests/**/*.cs Updated all test call sites to use new signatures with null or named parameters
samples/**/*.cs Updated sample code to use named parameters for cancellationToken

@mikekistler mikekistler requested a review from halter73 November 17, 2025 22:01
/// <exception cref="InvalidOperationException">The client does not support sampling.</exception>
public async Task<ChatResponse> SampleAsync(
IEnumerable<ChatMessage> messages, ChatOptions? options = default, CancellationToken cancellationToken = default)
IEnumerable<ChatMessage> messages, ChatOptions? chatOptions = default, CancellationToken cancellationToken = default)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to rename this parameter to chatOptions to disambiguate with the RequestOptions option parameter that I've added on all the requests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not understanding, as there isn't a RequestOptions being passed in here. Are you saying that there are some overloads that accept both a ChatOptions and a RequestOptions?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 34 out of 35 changed files in this pull request and generated 8 comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

/// </summary>
public JsonObject? Meta
{
get
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getter should not be creating new objects on every access.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hasn't been addressed. If ProgressToken is not null, every access to Meta is creating and returning a new object.

This also looks broken for consumption patterns like:

RequestOptions options = new();
options.ProgressToken = token;
options.Meta["key"] = "value";

... am I reading it correctly that the changes to meta will be completely ignored?

I think this implementation needs to be restructured such that _meta is the source of truth for both Meta and ProgressToken.

Copy link
Contributor

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks close...

@stephentoub
Copy link
Contributor

#970 (comment) still needs to be addressed. Also there are conflicts that need to be resolved.

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.

7 participants