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