forked from modelcontextprotocol/csharp-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPromptsCapability.cs
More file actions
82 lines (77 loc) · 3.9 KB
/
PromptsCapability.cs
File metadata and controls
82 lines (77 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using ModelContextProtocol.Server;
using System.Text.Json.Serialization;
namespace ModelContextProtocol.Protocol;
/// <summary>
/// Represents the server's capability to provide predefined prompt templates that clients can use.
/// </summary>
/// <remarks>
/// <para>
/// 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 <see cref="PromptCollection"/>) or
/// dynamically generated through handlers.
/// </para>
/// <para>
/// See the <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">schema</see> for details.
/// </para>
/// </remarks>
public class PromptsCapability
{
/// <summary>
/// Gets or sets whether this server supports notifications for changes to the prompt list.
/// </summary>
/// <remarks>
/// When set to <see langword="true"/>, the server will send notifications using
/// <see cref="NotificationMethods.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.
/// </remarks>
[JsonPropertyName("listChanged")]
public bool? ListChanged { get; set; }
/// <summary>
/// Gets or sets the handler for <see cref="RequestMethods.PromptsList"/> requests.
/// </summary>
/// <remarks>
/// This handler is invoked when a client requests a list of available prompts from the server
/// via a <see cref="RequestMethods.PromptsList"/> request. Results from this handler are returned
/// along with any prompts defined in <see cref="PromptCollection"/>.
/// </remarks>
[JsonIgnore]
public Func<RequestContext<ListPromptsRequestParams>, CancellationToken, ValueTask<ListPromptsResult>>? ListPromptsHandler { get; set; }
/// <summary>
/// Gets or sets the handler for <see cref="RequestMethods.PromptsGet"/> requests.
/// </summary>
/// <remarks>
/// <para>
/// 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 <see cref="GetPromptResult"/> with the prompt messages and other details.
/// </para>
/// <para>
/// This handler will be invoked if the requested prompt name is not found in the <see cref="PromptCollection"/>,
/// allowing for dynamic prompt generation or retrieval from external sources.
/// </para>
/// </remarks>
[JsonIgnore]
public Func<RequestContext<GetPromptRequestParams>, CancellationToken, ValueTask<GetPromptResult>>? GetPromptHandler { get; set; }
/// <summary>
/// Gets or sets a collection of prompts that will be served by the server.
/// </summary>
/// <remarks>
/// <para>
/// The <see cref="PromptCollection"/> contains the predefined prompts that clients can request from the server.
/// This collection works in conjunction with <see cref="ListPromptsHandler"/> and <see cref="GetPromptHandler"/>
/// when those are provided:
/// </para>
/// <para>
/// - For <see cref="RequestMethods.PromptsList"/> requests: The server returns all prompts from this collection
/// plus any additional prompts provided by the <see cref="ListPromptsHandler"/> if it's set.
/// </para>
/// <para>
/// - For <see cref="RequestMethods.PromptsGet"/> requests: The server first checks this collection for the requested prompt.
/// If not found, it will invoke the <see cref="GetPromptHandler"/> as a fallback if one is set.
/// </para>
/// </remarks>
[JsonIgnore]
public McpServerPrimitiveCollection<McpServerPrompt>? PromptCollection { get; set; }
}