using Microsoft.Extensions.AI;
using ModelContextProtocol.Protocol.Types;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
namespace ModelContextProtocol.Server;
/// Represents an invocable prompt used by Model Context Protocol servers.
public abstract class McpServerPrompt : IMcpServerPrimitive
{
/// Initializes a new instance of the class.
protected McpServerPrompt()
{
}
/// Gets the protocol type for this instance.
public abstract Prompt ProtocolPrompt { get; }
/// Invokes the .
/// The request information resulting in the invocation of this tool.
/// The to monitor for cancellation requests. The default is .
/// The call response from invoking the tool.
/// is .
public abstract Task GetAsync(
RequestContext request,
CancellationToken cancellationToken = default);
///
/// Creates an instance for a method, specified via a instance.
///
/// The method to be represented via the created .
/// Optional options used in the creation of the to control its behavior.
/// The created for invoking .
/// is .
public static McpServerPrompt Create(
Delegate method,
McpServerPromptCreateOptions? options = null) =>
AIFunctionMcpServerPrompt.Create(method, options);
///
/// Creates an instance for a method, specified via a instance.
///
/// The method to be represented via the created .
/// The instance if is an instance method; otherwise, .
/// Optional options used in the creation of the to control its behavior.
/// The created for invoking .
/// is .
/// is an instance method but is .
public static McpServerPrompt Create(
MethodInfo method,
object? target = null,
McpServerPromptCreateOptions? options = null) =>
AIFunctionMcpServerPrompt.Create(method, target, options);
///
/// Creates an instance for a method, specified via an for
/// and instance method, along with a representing the type of the target object to
/// instantiate each time the method is invoked.
///
/// The instance method to be represented via the created .
///
/// The to construct an instance of on which to invoke when
/// the resulting is invoked. If services are provided,
/// ActivatorUtilities.CreateInstance will be used to construct the instance using those services; otherwise,
/// is used, utilizing the type's public parameterless constructor.
/// If an instance can't be constructed, an exception is thrown during the function's invocation.
///
/// Optional options used in the creation of the to control its behavior.
/// The created for invoking .
/// is .
public static McpServerPrompt Create(
MethodInfo method,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type targetType,
McpServerPromptCreateOptions? options = null) =>
AIFunctionMcpServerPrompt.Create(method, targetType, options);
/// Creates an that wraps the specified .
/// The function to wrap.
/// Optional options used in the creation of the to control its behavior.
/// is .
///
/// Unlike the other overloads of Create, the created by
/// does not provide all of the special parameter handling for MCP-specific concepts, like .
///
public static McpServerPrompt Create(
AIFunction function,
McpServerPromptCreateOptions? options = null) =>
AIFunctionMcpServerPrompt.Create(function, options);
///
public override string ToString() => ProtocolPrompt.Name;
///
string IMcpServerPrimitive.Name => ProtocolPrompt.Name;
}