Skip to content

Commit 72f56c3

Browse files
committed
Clean build
1 parent 72b640d commit 72f56c3

26 files changed

Lines changed: 237 additions & 177 deletions

samples/EverythingServer/Tools/SampleLlmTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static async Task<string> SampleLLM(
1515
CancellationToken cancellationToken)
1616
{
1717
var samplingParams = CreateRequestSamplingParams(prompt ?? string.Empty, "sampleLLM", maxTokens);
18-
var sampleResult = await server.SampleAsync(samplingParams, meta: null, cancellationToken);
18+
var sampleResult = await server.SampleAsync(samplingParams, options: null, cancellationToken);
1919

2020
return $"LLM sampling result: {sampleResult.Content.OfType<TextContentBlock>().FirstOrDefault()?.Text}";
2121
}

samples/TestServerWithHosting/Tools/SampleLlmTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static async Task<string> SampleLLM(
1818
CancellationToken cancellationToken)
1919
{
2020
var samplingParams = CreateRequestSamplingParams(prompt ?? string.Empty, "sampleLLM", maxTokens);
21-
var sampleResult = await thisServer.SampleAsync(samplingParams, meta: null, cancellationToken);
21+
var sampleResult = await thisServer.SampleAsync(samplingParams, options: null, cancellationToken);
2222

2323
return $"LLM sampling result: {sampleResult.Content.OfType<TextContentBlock>().FirstOrDefault()?.Text}";
2424
}

src/ModelContextProtocol.Core/Client/McpClient.Methods.cs

Lines changed: 65 additions & 73 deletions
Large diffs are not rendered by default.

src/ModelContextProtocol.Core/Client/McpClientPrompt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,6 @@ public async ValueTask<GetPromptResult> GetAsync(
9898
arguments as IReadOnlyDictionary<string, object?> ??
9999
arguments?.ToDictionary();
100100

101-
return await _client.GetPromptAsync(ProtocolPrompt.Name, argDict, null, serializerOptions, cancellationToken: cancellationToken).ConfigureAwait(false);
101+
return await _client.GetPromptAsync(ProtocolPrompt.Name, argDict, new RequestOptions(null, serializerOptions), cancellationToken).ConfigureAwait(false);
102102
}
103103
}

src/ModelContextProtocol.Core/Client/McpClientResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public McpClientResource(McpClient client, Resource resource)
8080
/// <returns>A <see cref="ValueTask{ReadResourceResult}"/> containing the resource's result with content and messages.</returns>
8181
/// <remarks>
8282
/// <para>
83-
/// This is a convenience method that internally calls <see cref="McpClient.ReadResourceAsync(string, System.Text.Json.Nodes.JsonObject, CancellationToken)"/>.
83+
/// This is a convenience method that internally calls <see cref="McpClient.ReadResourceAsync(string, RequestOptions, CancellationToken)"/>.
8484
/// </para>
8585
/// </remarks>
8686
public ValueTask<ReadResourceResult> ReadAsync(

src/ModelContextProtocol.Core/Client/McpClientTool.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,15 @@ public ValueTask<CallToolResult> CallAsync(
194194
IProgress<ProgressNotificationValue>? progress = null,
195195
JsonSerializerOptions? serializerOptions = null,
196196
CancellationToken cancellationToken = default) =>
197-
_client.CallToolAsync(ProtocolTool.Name, arguments, progress, null, serializerOptions, cancellationToken);
197+
_client.CallToolAsync(
198+
ProtocolTool.Name,
199+
arguments,
200+
progress,
201+
new RequestOptions
202+
{
203+
JsonSerializerOptions = serializerOptions
204+
},
205+
cancellationToken);
198206

199207
/// <summary>
200208
/// Creates a new instance of the tool but modified to return the specified name from its <see cref="Name"/> property.

src/ModelContextProtocol.Core/McpSession.Methods.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ internal Task SendNotificationAsync<TParameters>(
152152
/// </summary>
153153
/// <param name="progressToken">The <see cref="ProgressToken"/> identifying the operation for which progress is being reported.</param>
154154
/// <param name="progress">The progress update to send, containing information such as percentage complete or status message.</param>
155-
/// <param name="meta">Optional metadata to include in the notification.</param>
155+
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
156156
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
157157
/// <returns>A task representing the completion of the notification operation (not the operation being tracked).</returns>
158158
/// <exception cref="ArgumentNullException">The current session instance is <see langword="null"/>.</exception>
@@ -169,7 +169,7 @@ internal Task SendNotificationAsync<TParameters>(
169169
public Task NotifyProgressAsync(
170170
ProgressToken progressToken,
171171
ProgressNotificationValue progress,
172-
JsonObject? meta = null,
172+
RequestOptions? options = null,
173173
CancellationToken cancellationToken = default)
174174
{
175175
return SendNotificationAsync(
@@ -178,7 +178,7 @@ public Task NotifyProgressAsync(
178178
{
179179
ProgressToken = progressToken,
180180
Progress = progress,
181-
Meta = meta,
181+
Meta = options?.Meta,
182182
},
183183
McpJsonUtilities.JsonContext.Default.ProgressNotificationParams,
184184
cancellationToken);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Nodes;
3+
using ModelContextProtocol.Protocol;
4+
5+
namespace ModelContextProtocol;
6+
7+
/// <summary>
8+
/// Contains optional parameters for MCP requests.
9+
/// </summary>
10+
public sealed class RequestOptions
11+
{
12+
/// <summary>
13+
/// Gets or sets optional metadata to include in the request.
14+
/// </summary>
15+
public JsonObject? Meta { get; set; }
16+
17+
/// <summary>
18+
/// Gets or sets the JSON serializer options to use for serialization and deserialization.
19+
/// </summary>
20+
public JsonSerializerOptions? JsonSerializerOptions { get; set; }
21+
22+
/// <summary>
23+
/// Gets or sets the progress token for tracking long-running operations.
24+
/// </summary>
25+
public ProgressToken? ProgressToken { get; set; }
26+
27+
/// <summary>
28+
/// Gets a default instance with all properties set to null.
29+
/// </summary>
30+
public static RequestOptions Default { get; } = new();
31+
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="RequestOptions"/> class.
34+
/// </summary>
35+
public RequestOptions()
36+
{
37+
}
38+
39+
/// <summary>
40+
/// Initializes a new instance of the <see cref="RequestOptions"/> class with the specified metadata.
41+
/// </summary>
42+
/// <param name="meta">Optional metadata to include in the request.</param>
43+
public RequestOptions(JsonObject? meta)
44+
{
45+
Meta = meta;
46+
}
47+
48+
/// <summary>
49+
/// Initializes a new instance of the <see cref="RequestOptions"/> class with the specified options.
50+
/// </summary>
51+
/// <param name="meta">Optional metadata to include in the request.</param>
52+
/// <param name="jsonSerializerOptions">The JSON serializer options to use.</param>
53+
/// <param name="progressToken">The progress token for tracking operations.</param>
54+
public RequestOptions(JsonObject? meta = null, JsonSerializerOptions? jsonSerializerOptions = null, ProgressToken? progressToken = null)
55+
{
56+
Meta = meta;
57+
JsonSerializerOptions = jsonSerializerOptions;
58+
ProgressToken = progressToken;
59+
}
60+
}

src/ModelContextProtocol.Core/Server/McpServer.Methods.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,18 @@ public static McpServer Create(
5151
/// Requests to sample an LLM via the client using the specified request parameters.
5252
/// </summary>
5353
/// <param name="request">The parameters for the sampling request.</param>
54-
/// <param name="meta">Optional metadata to include in the request.</param>
54+
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
5555
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests.</param>
5656
/// <returns>A task containing the sampling result from the client.</returns>
5757
/// <exception cref="InvalidOperationException">The client does not support sampling.</exception>
5858
public ValueTask<CreateMessageResult> SampleAsync(
59-
CreateMessageRequestParams request, JsonObject? meta = null, CancellationToken cancellationToken = default)
59+
CreateMessageRequestParams request, RequestOptions? options = null, CancellationToken cancellationToken = default)
6060
{
6161
ThrowIfSamplingUnsupported();
6262

63-
if (meta is not null)
63+
if (options?.Meta is not null)
6464
{
65-
request.Meta = meta;
65+
request.Meta = options.Meta;
6666
}
6767

6868
return SendRequestAsync(
@@ -223,18 +223,18 @@ public ILoggerProvider AsClientLoggerProvider()
223223
/// Requests the client to list the roots it exposes.
224224
/// </summary>
225225
/// <param name="request">The parameters for the list roots request.</param>
226-
/// <param name="meta">Optional metadata to include in the request.</param>
226+
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
227227
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests.</param>
228228
/// <returns>A task containing the list of roots exposed by the client.</returns>
229229
/// <exception cref="InvalidOperationException">The client does not support roots.</exception>
230230
public ValueTask<ListRootsResult> RequestRootsAsync(
231-
ListRootsRequestParams request, JsonObject? meta = null, CancellationToken cancellationToken = default)
231+
ListRootsRequestParams request, RequestOptions? options = null, CancellationToken cancellationToken = default)
232232
{
233233
ThrowIfRootsUnsupported();
234234

235-
if (meta is not null)
235+
if (options?.Meta is not null)
236236
{
237-
request.Meta = meta;
237+
request.Meta = options.Meta;
238238
}
239239

240240
return SendRequestAsync(
@@ -488,7 +488,7 @@ private sealed class SamplingChatClient(McpServer server) : IChatClient
488488

489489
/// <inheritdoc/>
490490
public Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default) =>
491-
_server.SampleAsync(messages, options, meta: null, cancellationToken);
491+
_server.SampleAsync(messages, options, requestOptions: null, cancellationToken);
492492

493493
/// <inheritdoc/>
494494
async IAsyncEnumerable<ChatResponseUpdate> IChatClient.GetStreamingResponseAsync(

src/ModelContextProtocol.Core/Server/McpServerOptions.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public sealed class McpServerOptions
2121
/// </summary>
2222
/// <remarks>
2323
/// These determine which features will be available when a client connects.
24-
/// Capabilities can include "tools", "prompts", "resources", "logging", and other
24+
/// Capabilities can include "tools", "prompts", "resources", "logging", and other
2525
/// protocol-specific functionality.
2626
/// </remarks>
2727
public ServerCapabilities? Capabilities { get; set; }
@@ -84,21 +84,21 @@ public sealed class McpServerOptions
8484
/// Gets the filter collections for MCP server handlers.
8585
/// </summary>
8686
/// <remarks>
87-
/// This property provides access to filter collections that can be used to modify the behavior
88-
/// of various MCP server handlers. Filters are applied in reverse order, so the last filter
87+
/// This property provides access to filter collections that can be used to modify the behavior
88+
/// of various MCP server handlers. Filters are applied in reverse order, so the last filter
8989
/// added will be the outermost (first to execute).
9090
/// </remarks>
9191
public McpServerFilters Filters { get; } = new();
9292

9393
/// <summary>
9494
/// Gets or sets the container of handlers used by the server for processing protocol messages.
9595
/// </summary>
96-
public McpServerHandlers Handlers
97-
{
96+
public McpServerHandlers Handlers
97+
{
9898
get => field ??= new();
9999
set
100-
{
101-
Throw.IfNull(value);
100+
{
101+
Throw.IfNull(value);
102102
field = value;
103103
}
104104
}
@@ -143,7 +143,7 @@ public McpServerHandlers Handlers
143143
/// when those are provided:
144144
/// </para>
145145
/// <para>
146-
/// - For <see cref="RequestMethods.PromptsList"/> requests: The server returns all prompts from this collection
146+
/// - For <see cref="RequestMethods.PromptsList"/> requests: The server returns all prompts from this collection
147147
/// plus any additional prompts provided by the <see cref="McpServerHandlers.ListPromptsHandler"/> if it's set.
148148
/// </para>
149149
/// <para>
@@ -158,7 +158,7 @@ public McpServerHandlers Handlers
158158
/// </summary>
159159
/// <remarks>
160160
/// <para>
161-
/// This value is used in <see cref="McpServer.SampleAsync(IEnumerable{Microsoft.Extensions.AI.ChatMessage}, Microsoft.Extensions.AI.ChatOptions?, System.Text.Json.Nodes.JsonObject?, CancellationToken)"/>
161+
/// This value is used in <see cref="McpServer.SampleAsync(IEnumerable{Microsoft.Extensions.AI.ChatMessage}, Microsoft.Extensions.AI.ChatOptions?, RequestOptions?, CancellationToken)"/>
162162
/// when <see cref="Microsoft.Extensions.AI.ChatOptions.MaxOutputTokens"/> is not set in the request options.
163163
/// </para>
164164
/// <para>

0 commit comments

Comments
 (0)