Class PromptsCapability
- Namespace
- ModelContextProtocol.Protocol
- Assembly
- ModelContextProtocol.Core.dll
Represents the server's capability to provide predefined prompt templates that clients can use.
public class PromptsCapability
- Inheritance
-
PromptsCapability
- Inherited Members
Remarks
The prompts capability allows a server to expose a collection of predefined prompt templates that clients can discover and use. These prompts can be static (defined in the PromptCollection) or dynamically generated through handlers.
See the schema for details.
Properties
GetPromptHandler
Gets or sets the handler for PromptsGet requests.
[JsonIgnore]
public Func<RequestContext<GetPromptRequestParams>, CancellationToken, ValueTask<GetPromptResult>>? GetPromptHandler { get; set; }
Property Value
Remarks
This handler is invoked when a client requests details for a specific prompt by name and provides arguments for the prompt if needed. The handler receives the request context containing the prompt name and any arguments, and should return a GetPromptResult with the prompt messages and other details.
This handler will be invoked if the requested prompt name is not found in the PromptCollection, allowing for dynamic prompt generation or retrieval from external sources.
ListChanged
Gets or sets whether this server supports notifications for changes to the prompt list.
[JsonPropertyName("listChanged")]
public bool? ListChanged { get; set; }
Property Value
- bool?
Remarks
When set to true, the server will send notifications using PromptListChangedNotification when prompts are added, removed, or modified. Clients can register handlers for these notifications to refresh their prompt cache. This capability enables clients to stay synchronized with server-side changes to available prompts.
ListPromptsHandler
Gets or sets the handler for PromptsList requests.
[JsonIgnore]
public Func<RequestContext<ListPromptsRequestParams>, CancellationToken, ValueTask<ListPromptsResult>>? ListPromptsHandler { get; set; }
Property Value
Remarks
This handler is invoked when a client requests a list of available prompts from the server via a PromptsList request. Results from this handler are returned along with any prompts defined in PromptCollection.
PromptCollection
Gets or sets a collection of prompts that will be served by the server.
[JsonIgnore]
public McpServerPrimitiveCollection<McpServerPrompt>? PromptCollection { get; set; }
Property Value
Remarks
The PromptCollection contains the predefined prompts that clients can request from the server. This collection works in conjunction with ListPromptsHandler and GetPromptHandler when those are provided:
- For PromptsList requests: The server returns all prompts from this collection plus any additional prompts provided by the ListPromptsHandler if it's set.
- For PromptsGet requests: The server first checks this collection for the requested prompt. If not found, it will invoke the GetPromptHandler as a fallback if one is set.