using ModelContextProtocol.Protocol.Types;
using System.Text.Json;
namespace ModelContextProtocol.Client;
/// Provides an invocable prompt.
public sealed class McpClientPrompt
{
private readonly IMcpClient _client;
internal McpClientPrompt(IMcpClient client, Prompt prompt)
{
_client = client;
ProtocolPrompt = prompt;
}
/// Gets the protocol type for this instance.
public Prompt ProtocolPrompt { get; }
///
/// Retrieves a specific prompt with optional arguments.
///
/// Optional arguments for the prompt
/// The serialization options governing argument serialization.
/// The to monitor for cancellation requests. The default is .
/// A task containing the prompt's content and messages.
public async ValueTask GetAsync(
IEnumerable>? arguments = null,
JsonSerializerOptions? serializerOptions = null,
CancellationToken cancellationToken = default)
{
IReadOnlyDictionary? argDict =
arguments as IReadOnlyDictionary ??
arguments?.ToDictionary();
return await _client.GetPromptAsync(ProtocolPrompt.Name, argDict, serializerOptions, cancellationToken: cancellationToken).ConfigureAwait(false);
}
/// Gets the name of the prompt.
public string Name => ProtocolPrompt.Name;
/// Gets a description of the prompt.
public string? Description => ProtocolPrompt.Description;
}