-
Notifications
You must be signed in to change notification settings - Fork 570
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?
Changes from all commits
35f48e0
826a615
e19ad6a
f6887ea
5ac3f93
073f110
65b3a9b
dc24e39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| namespace ModelContextProtocol.Protocol; | ||
|
|
||
| /// <summary> | ||
| /// Represents the parameters used with a <see cref="RequestMethods.Ping"/> request to verify | ||
| /// server connectivity. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// The server responds with a <see cref="PingResult"/>. | ||
| /// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details. | ||
| /// </remarks> | ||
| public sealed class PingRequestParams : RequestParams; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| using System.Text.Json; | ||
| using System.Text.Json.Nodes; | ||
| using ModelContextProtocol.Protocol; | ||
|
|
||
| namespace ModelContextProtocol; | ||
|
|
||
| /// <summary> | ||
| /// Contains optional parameters for MCP requests. | ||
| /// </summary> | ||
| public sealed class RequestOptions | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets optional metadata to include in the request. | ||
| /// </summary> | ||
| public JsonObject? Meta { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the JSON serializer options to use for serialization and deserialization. | ||
| /// </summary> | ||
| public JsonSerializerOptions? JsonSerializerOptions { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the progress token for tracking long-running operations. | ||
| /// </summary> | ||
| public ProgressToken? ProgressToken { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets a default instance with all properties set to null. | ||
| /// </summary> | ||
| public static RequestOptions Default { get; } = new(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any code in the process could do: RequestOptions.Default.Meta = new();or the like with any of the properties, such that the properties would no longer be null. This property should be removed. (Alternatively, you could modify the other properties to all throw if |
||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="RequestOptions"/> class. | ||
| /// </summary> | ||
| public RequestOptions() | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="RequestOptions"/> class with the specified metadata. | ||
| /// </summary> | ||
| /// <param name="meta">Optional metadata to include in the request.</param> | ||
| public RequestOptions(JsonObject? meta) | ||
| { | ||
| Meta = meta; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="RequestOptions"/> class with the specified options. | ||
| /// </summary> | ||
| /// <param name="meta">Optional metadata to include in the request.</param> | ||
| /// <param name="jsonSerializerOptions">The JSON serializer options to use.</param> | ||
| /// <param name="progressToken">The progress token for tracking operations.</param> | ||
| public RequestOptions(JsonObject? meta = null, JsonSerializerOptions? jsonSerializerOptions = null, ProgressToken? progressToken = null) | ||
| { | ||
| Meta = meta; | ||
| JsonSerializerOptions = jsonSerializerOptions; | ||
| ProgressToken = progressToken; | ||
| } | ||
|
Comment on lines
+39
to
+59
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these constructors necessary? |
||
| } | ||
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.
It'd be nice to avoid allocating the RequestOptions when serializerOptions is null (which is expected to be the common case)