Skip to content

Commit 80ed2c3

Browse files
committed
Address PR review comments
1 parent 63a4749 commit 80ed2c3

File tree

5 files changed

+29
-35
lines changed

5 files changed

+29
-35
lines changed

src/ModelContextProtocol.Core/Client/McpClientPrompt.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public sealed class McpClientPrompt
3030
/// <remarks>
3131
/// <para>
3232
/// This constructor enables reusing cached prompt definitions across different <see cref="McpClient"/> instances
33-
/// without needing to call <see cref="McpClient.ListPromptsAsync"/> on every reconnect. This is particularly useful
33+
/// without needing to call <see cref="McpClient.ListPromptsAsync"/> on every reconnect. This is particularly useful
3434
/// in scenarios where prompt definitions are stable and network round-trips should be minimized.
3535
/// </para>
3636
/// <para>
37-
/// The provided <paramref name="prompt"/> must represent a prompt that is actually available on the server
38-
/// associated with the <paramref name="client"/>. Attempting to invoke a prompt that doesn't exist on the
37+
/// The provided <paramref name="prompt"/> must represent a prompt that is actually available on the server
38+
/// associated with the <paramref name="client"/>. Attempting to invoke a prompt that doesn't exist on the
3939
/// server will result in an <see cref="McpException"/>.
4040
/// </para>
4141
/// </remarks>
@@ -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, new RequestOptions(null, serializerOptions), cancellationToken).ConfigureAwait(false);
101+
return await _client.GetPromptAsync(ProtocolPrompt.Name, argDict, new RequestOptions(){Meta = null, JsonSerializerOptions = serializerOptions}, cancellationToken).ConfigureAwait(false);
102102
}
103103
}

src/ModelContextProtocol.Core/Client/McpClientTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public ValueTask<CallToolResult> CallAsync(
198198
ProtocolTool.Name,
199199
arguments,
200200
progress,
201-
new RequestOptions
201+
serializerOptions is null ? null : new RequestOptions
202202
{
203203
JsonSerializerOptions = serializerOptions
204204
},

src/ModelContextProtocol.Core/Protocol/RequestParams.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,24 @@ private protected RequestParams()
2323
/// Implementations must not make assumptions about its contents.
2424
/// </remarks>
2525
[JsonPropertyName("_meta")]
26-
public JsonObject? Meta { get; set; }
26+
public JsonObject? Meta {
27+
get;
28+
set
29+
{
30+
// If progressToken is already set in Meta and not present in the new value, preserve it.
31+
if (field?["progressToken"] is JsonValue existingProgressToken &&
32+
(value is null || !value.ContainsKey("progressToken")))
33+
{
34+
// Create a copy to avoid modifying the input parameter
35+
field = value is null ? [] : new JsonObject(value);
36+
field["progressToken"] = existingProgressToken;
37+
}
38+
else
39+
{
40+
field = value;
41+
}
42+
}
43+
}
2744

2845
/// <summary>
2946
/// Gets or sets an opaque token that will be attached to any subsequent progress notifications.

src/ModelContextProtocol.Core/RequestOptions.cs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,10 @@ public sealed class RequestOptions
2424
/// </summary>
2525
public ProgressToken? ProgressToken { get; set; }
2626

27-
/// <summary>
28-
/// Gets a default instance with all properties set to null.
29-
/// </summary>
30-
public static RequestOptions Default { get; } = new();
31-
3227
/// <summary>
3328
/// Initializes a new instance of the <see cref="RequestOptions"/> class.
3429
/// </summary>
3530
public RequestOptions()
3631
{
3732
}
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-
}
6033
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public ValueTask<CreateMessageResult> SampleAsync(
6262

6363
if (options?.Meta is not null)
6464
{
65-
request.Meta = options.Meta;
65+
request.Meta = request.Meta is not null ?
66+
new JsonObject(request.Meta.Union(options.Meta))
67+
: options.Meta;
6668
}
6769

6870
return SendRequestAsync(
@@ -234,7 +236,9 @@ public ValueTask<ListRootsResult> RequestRootsAsync(
234236

235237
if (options?.Meta is not null)
236238
{
237-
request.Meta = options.Meta;
239+
request.Meta = request.Meta is not null ?
240+
new JsonObject(request.Meta.Union(options.Meta))
241+
: options.Meta;
238242
}
239243

240244
return SendRequestAsync(

0 commit comments

Comments
 (0)