-
Notifications
You must be signed in to change notification settings - Fork 581
Add request options bag to high level requests and include Meta #970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
RequestOptionsclass to hold optional request parameters - Updated all client and server request method signatures to accept
RequestOptionsinstead of individual parameters - Created
PingRequestParamsprotocol 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 |
dc24e39 to
4ed55e6
Compare
| /// <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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
4ed55e6 to
0792a65
Compare
There was a problem hiding this 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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Co-authored-by: Stephen Toub <[email protected]>
stephentoub
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks close...
|
#970 (comment) still needs to be addressed. Also there are conflicts that need to be resolved. |
Motivation and Context
This PR adds the ability to set fields of the
_metaparameter 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
Checklist
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.