- Namespace
- ModelContextProtocol.Server
- Assembly
- ModelContextProtocol.Core.dll
Represents an invocable prompt used by Model Context Protocol clients and servers.
public abstract class McpServerPrompt : IMcpServerPrimitive
- Inheritance
-
McpServerPrompt
- Implements
- Derived
- Inherited Members
Constructors
McpServerPrompt()
protected McpServerPrompt()
Properties
Metadata
Gets the metadata for this prompt instance.
public abstract IReadOnlyList<object> Metadata { get; }
Property Value
ProtocolPrompt
Gets the protocol Prompt type for this instance.
public abstract Prompt ProtocolPrompt { get; }
Property Value
Methods
Create(AIFunction, McpServerPromptCreateOptions?)
Creates an McpServerPrompt that wraps the specified Microsoft.Extensions.AI.AIFunction.
public static McpServerPrompt Create(AIFunction function, McpServerPromptCreateOptions? options = null)
Parameters
functionAIFunctionThe function to wrap.
optionsMcpServerPromptCreateOptionsOptional options used in the creation of the McpServerPrompt to control its behavior.
Returns
Exceptions
- ArgumentNullException
functionis null.
Create(Delegate, McpServerPromptCreateOptions?)
public static McpServerPrompt Create(Delegate method, McpServerPromptCreateOptions? options = null)
Parameters
methodDelegateThe method to be represented via the created McpServerPrompt.
optionsMcpServerPromptCreateOptionsOptional options used in the creation of the McpServerPrompt to control its behavior.
Returns
- McpServerPrompt
The created McpServerPrompt for invoking
method.
Exceptions
- ArgumentNullException
methodis null.
Create(MethodInfo, Func<RequestContext<GetPromptRequestParams>, object>, McpServerPromptCreateOptions?)
Creates an McpServerPrompt instance for a method, specified via a MethodInfo for an instance method, along with a Type representing the type of the target object to instantiate each time the method is invoked.
public static McpServerPrompt Create(MethodInfo method, Func<RequestContext<GetPromptRequestParams>, object> createTargetFunc, McpServerPromptCreateOptions? options = null)
Parameters
methodMethodInfoThe instance method to be represented via the created McpServerPrompt.
createTargetFuncFunc<RequestContext<GetPromptRequestParams>, object>Callback used on each function invocation to create an instance of the type on which the instance method
methodwill be invoked. If the returned instance is IAsyncDisposable or IDisposable, it will be disposed of after method completes its invocation.optionsMcpServerPromptCreateOptionsOptional options used in the creation of the McpServerPrompt to control its behavior.
Returns
- McpServerPrompt
The created McpServerPrompt for invoking
method.
Exceptions
- ArgumentNullException
methodorcreateTargetFuncis null.
Create(MethodInfo, object?, McpServerPromptCreateOptions?)
public static McpServerPrompt Create(MethodInfo method, object? target = null, McpServerPromptCreateOptions? options = null)
Parameters
methodMethodInfoThe method to be represented via the created McpServerPrompt.
targetobjectThe instance if
methodis an instance method; otherwise, null.optionsMcpServerPromptCreateOptionsOptional options used in the creation of the McpServerPrompt to control its behavior.
Returns
- McpServerPrompt
The created McpServerPrompt for invoking
method.
Exceptions
- ArgumentNullException
methodis null.- ArgumentException
methodis an instance method buttargetis null.
GetAsync(RequestContext<GetPromptRequestParams>, CancellationToken)
Gets the prompt, rendering it with the provided request parameters and returning the prompt result.
public abstract ValueTask<GetPromptResult> GetAsync(RequestContext<GetPromptRequestParams> request, CancellationToken cancellationToken = default)
Parameters
requestRequestContext<GetPromptRequestParams>The request context containing information about the prompt invocation, including any arguments passed to the prompt. This object provides access to both the request parameters and the server context.
cancellationTokenCancellationTokenThe CancellationToken to monitor for cancellation requests. The default is None.
Returns
- ValueTask<GetPromptResult>
A Task representing the asynchronous operation, containing a GetPromptResult with the prompt content and messages.
Exceptions
- ArgumentNullException
requestis null.- InvalidOperationException
The prompt implementation returns null or an unsupported result type.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.