Fix McpClientPrompt/Resource types to use RequestOptions like McpClientTool does (#1370)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
This commit is contained in:
parent
1446cd738c
commit
8c46411f82
3 changed files with 115 additions and 12 deletions
|
|
@ -1,5 +1,4 @@
|
|||
using ModelContextProtocol.Protocol;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ModelContextProtocol.Client;
|
||||
|
||||
|
|
@ -74,7 +73,7 @@ public sealed class McpClientPrompt
|
|||
/// Gets this prompt's content by sending a request to the server with optional arguments.
|
||||
/// </summary>
|
||||
/// <param name="arguments">Optional arguments to pass to the prompt. Keys are parameter names, and values are the argument values.</param>
|
||||
/// <param name="serializerOptions">The serialization options governing argument serialization.</param>
|
||||
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
|
||||
/// <returns>A <see cref="ValueTask"/> containing the prompt's result with content and messages.</returns>
|
||||
/// <exception cref="McpException">The request failed or the server returned an error response.</exception>
|
||||
|
|
@ -91,13 +90,13 @@ public sealed class McpClientPrompt
|
|||
/// </remarks>
|
||||
public async ValueTask<GetPromptResult> GetAsync(
|
||||
IEnumerable<KeyValuePair<string, object?>>? arguments = null,
|
||||
JsonSerializerOptions? serializerOptions = null,
|
||||
RequestOptions? options = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
IReadOnlyDictionary<string, object?>? argDict =
|
||||
arguments as IReadOnlyDictionary<string, object?> ??
|
||||
arguments?.ToDictionary();
|
||||
|
||||
return await _client.GetPromptAsync(ProtocolPrompt.Name, argDict, new RequestOptions() { JsonSerializerOptions = serializerOptions }, cancellationToken).ConfigureAwait(false);
|
||||
return await _client.GetPromptAsync(ProtocolPrompt.Name, argDict, options, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ public sealed class McpClientResource
|
|||
/// <summary>
|
||||
/// Gets this resource's content by sending a request to the server.
|
||||
/// </summary>
|
||||
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
|
||||
/// <returns>A <see cref="ValueTask{ReadResourceResult}"/> containing the resource's result with content and messages.</returns>
|
||||
/// <exception cref="McpException">The request failed or the server returned an error response.</exception>
|
||||
|
|
@ -83,6 +84,7 @@ public sealed class McpClientResource
|
|||
/// </para>
|
||||
/// </remarks>
|
||||
public ValueTask<ReadResourceResult> ReadAsync(
|
||||
RequestOptions? options = null,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
_client.ReadResourceAsync(Uri, cancellationToken: cancellationToken);
|
||||
_client.ReadResourceAsync(Uri, options, cancellationToken);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,11 +78,13 @@ public sealed class McpClientResourceTemplate
|
|||
/// <param name="arguments">A dictionary of arguments to pass to the tool. Each key represents a parameter name,
|
||||
/// and its associated value represents the argument value.
|
||||
/// </param>
|
||||
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
|
||||
/// <returns>A <see cref="ValueTask{ReadResourceResult}"/> containing the resource template's result with content and messages.</returns>
|
||||
/// <exception cref="McpException">The request failed or the server returned an error response.</exception>
|
||||
public ValueTask<ReadResourceResult> ReadAsync(
|
||||
IReadOnlyDictionary<string, object?> arguments,
|
||||
RequestOptions? options = null,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
_client.ReadResourceAsync(UriTemplate, arguments, cancellationToken: cancellationToken);
|
||||
_client.ReadResourceAsync(UriTemplate, arguments, options, cancellationToken);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue