Skip to content

Commit d7615e7

Browse files
Copilotstephentoub
andcommitted
Add RequestOptions parameter to McpClientPrompt.GetAsync, McpClientResource.ReadAsync, and McpClientResourceTemplate.ReadAsync
Co-authored-by: stephentoub <[email protected]>
1 parent 86d0c6d commit d7615e7

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/ModelContextProtocol.Core/Client/McpClientPrompt.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using ModelContextProtocol.Protocol;
2-
using System.Text.Json;
32

43
namespace ModelContextProtocol.Client;
54

@@ -74,7 +73,7 @@ public McpClientPrompt(McpClient client, Prompt prompt)
7473
/// Gets this prompt's content by sending a request to the server with optional arguments.
7574
/// </summary>
7675
/// <param name="arguments">Optional arguments to pass to the prompt. Keys are parameter names, and values are the argument values.</param>
77-
/// <param name="serializerOptions">The serialization options governing argument serialization.</param>
76+
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
7877
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
7978
/// <returns>A <see cref="ValueTask"/> containing the prompt's result with content and messages.</returns>
8079
/// <exception cref="McpException">The request failed or the server returned an error response.</exception>
@@ -91,13 +90,13 @@ public McpClientPrompt(McpClient client, Prompt prompt)
9190
/// </remarks>
9291
public async ValueTask<GetPromptResult> GetAsync(
9392
IEnumerable<KeyValuePair<string, object?>>? arguments = null,
94-
JsonSerializerOptions? serializerOptions = null,
93+
RequestOptions? options = null,
9594
CancellationToken cancellationToken = default)
9695
{
9796
IReadOnlyDictionary<string, object?>? argDict =
9897
arguments as IReadOnlyDictionary<string, object?> ??
9998
arguments?.ToDictionary();
10099

101-
return await _client.GetPromptAsync(ProtocolPrompt.Name, argDict, new RequestOptions() { JsonSerializerOptions = serializerOptions }, cancellationToken).ConfigureAwait(false);
100+
return await _client.GetPromptAsync(ProtocolPrompt.Name, argDict, options, cancellationToken).ConfigureAwait(false);
102101
}
103102
}

src/ModelContextProtocol.Core/Client/McpClientResource.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public McpClientResource(McpClient client, Resource resource)
7474
/// <summary>
7575
/// Gets this resource's content by sending a request to the server.
7676
/// </summary>
77+
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
7778
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
7879
/// <returns>A <see cref="ValueTask{ReadResourceResult}"/> containing the resource's result with content and messages.</returns>
7980
/// <exception cref="McpException">The request failed or the server returned an error response.</exception>
@@ -83,6 +84,7 @@ public McpClientResource(McpClient client, Resource resource)
8384
/// </para>
8485
/// </remarks>
8586
public ValueTask<ReadResourceResult> ReadAsync(
87+
RequestOptions? options = null,
8688
CancellationToken cancellationToken = default) =>
87-
_client.ReadResourceAsync(Uri, cancellationToken: cancellationToken);
89+
_client.ReadResourceAsync(Uri, options, cancellationToken);
8890
}

src/ModelContextProtocol.Core/Client/McpClientResourceTemplate.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ public McpClientResourceTemplate(McpClient client, ResourceTemplate resourceTemp
7878
/// <param name="arguments">A dictionary of arguments to pass to the tool. Each key represents a parameter name,
7979
/// and its associated value represents the argument value.
8080
/// </param>
81+
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
8182
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
8283
/// <returns>A <see cref="ValueTask{ReadResourceResult}"/> containing the resource template's result with content and messages.</returns>
8384
/// <exception cref="McpException">The request failed or the server returned an error response.</exception>
8485
public ValueTask<ReadResourceResult> ReadAsync(
8586
IReadOnlyDictionary<string, object?> arguments,
87+
RequestOptions? options = null,
8688
CancellationToken cancellationToken = default) =>
87-
_client.ReadResourceAsync(UriTemplate, arguments, cancellationToken: cancellationToken);
89+
_client.ReadResourceAsync(UriTemplate, arguments, options, cancellationToken);
8890
}

0 commit comments

Comments
 (0)