Class McpClientPrompt
- Namespace
- ModelContextProtocol.Client
- Assembly
- ModelContextProtocol.dll
Represents a named prompt that can be retrieved from an MCP server and invoked with arguments.
public sealed class McpClientPrompt
- Inheritance
-
McpClientPrompt
- Inherited Members
Remarks
This class provides a client-side wrapper around a prompt defined on an MCP server. It allows retrieving the prompt's content by sending a request to the server with optional arguments. Instances of this class are typically obtained by calling ListPromptsAsync(IMcpClient, CancellationToken) or EnumeratePromptsAsync(IMcpClient, CancellationToken).
Each prompt has a name and optionally a description, and it can be invoked with arguments to produce customized prompt content from the server.
Properties
Description
Gets a description of the prompt.
public string? Description { get; }
Property Value
Name
Gets the name of the prompt.
public string Name { get; }
Property Value
ProtocolPrompt
Gets the underlying protocol Prompt type for this instance.
public Prompt ProtocolPrompt { get; }
Property Value
Remarks
This property provides direct access to the underlying protocol representation of the prompt, which can be useful for advanced scenarios or when implementing custom MCP client extensions.
For most common use cases, you can use the more convenient Name and Description properties instead of accessing the ProtocolPrompt directly.
Methods
GetAsync(IEnumerable<KeyValuePair<string, object?>>?, JsonSerializerOptions?, CancellationToken)
Gets this prompt's content by sending a request to the server with optional arguments.
public ValueTask<GetPromptResult> GetAsync(IEnumerable<KeyValuePair<string, object?>>? arguments = null, JsonSerializerOptions? serializerOptions = null, CancellationToken cancellationToken = default)
Parameters
arguments
IEnumerable<KeyValuePair<string, object>>Optional arguments to pass to the prompt. Keys are parameter names, and values are the argument values.
serializerOptions
JsonSerializerOptionsThe serialization options governing argument serialization.
cancellationToken
CancellationTokenThe CancellationToken to monitor for cancellation requests. The default is None.
Returns
- ValueTask<GetPromptResult>
A ValueTask containing the prompt's result with content and messages.
Remarks
This method sends a request to the MCP server to execute this prompt with the provided arguments. The server will process the request and return a result containing messages or other content.
This is a convenience method that internally calls GetPromptAsync(IMcpClient, string, IReadOnlyDictionary<string, object?>?, JsonSerializerOptions?, CancellationToken) with this prompt's name and arguments.