Skip to content

Commit 82510d5

Browse files
authored
Add server "completions" capability (#232)
* Split apart Capabilities.cs No code changes, just moving each type to its own file. * Add server completions capability
1 parent ac0bc3a commit 82510d5

21 files changed

+321
-272
lines changed

samples/EverythingServer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ await ctx.Server.RequestSamplingAsync([
115115
}
116116
return Task.FromResult(new EmptyResult());
117117
})
118-
.WithGetCompletionHandler((ctx, ct) =>
118+
.WithCompleteHandler((ctx, ct) =>
119119
{
120120
var exampleCompletions = new Dictionary<string, IEnumerable<string>>
121121
{

src/ModelContextProtocol/Client/McpClientExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public static Task<ReadResourceResult> ReadResourceAsync(
386386
/// <param name="argumentName">Name of argument. Must be non-null and non-empty.</param>
387387
/// <param name="argumentValue">Value of argument. Must be non-null.</param>
388388
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
389-
public static Task<CompleteResult> GetCompletionAsync(this IMcpClient client, Reference reference, string argumentName, string argumentValue, CancellationToken cancellationToken = default)
389+
public static Task<CompleteResult> CompleteAsync(this IMcpClient client, Reference reference, string argumentName, string argumentValue, CancellationToken cancellationToken = default)
390390
{
391391
Throw.IfNull(client);
392392
Throw.IfNull(reference);

src/ModelContextProtocol/Configuration/McpServerBuilderExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,15 @@ public static IMcpServerBuilder WithReadResourceHandler(this IMcpServerBuilder b
288288
}
289289

290290
/// <summary>
291-
/// Sets the handler for get completion requests.
291+
/// Sets the handler for completion complete requests.
292292
/// </summary>
293293
/// <param name="builder">The builder instance.</param>
294294
/// <param name="handler">The handler.</param>
295-
public static IMcpServerBuilder WithGetCompletionHandler(this IMcpServerBuilder builder, Func<RequestContext<CompleteRequestParams>, CancellationToken, Task<CompleteResult>> handler)
295+
public static IMcpServerBuilder WithCompleteHandler(this IMcpServerBuilder builder, Func<RequestContext<CompleteRequestParams>, CancellationToken, Task<CompleteResult>> handler)
296296
{
297297
Throw.IfNull(builder);
298298

299-
builder.Services.Configure<McpServerHandlers>(s => s.GetCompletionHandler = handler);
299+
builder.Services.Configure<McpServerHandlers>(s => s.CompleteHandler = handler);
300300
return builder;
301301
}
302302

src/ModelContextProtocol/Protocol/Types/Capabilities.cs

Lines changed: 0 additions & 207 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using ModelContextProtocol.Protocol.Messages;
2+
using ModelContextProtocol.Server;
3+
using System.Text.Json.Serialization;
4+
5+
namespace ModelContextProtocol.Protocol.Types;
6+
7+
/// <summary>
8+
/// Represents the capabilities that a client may support.
9+
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">See the schema for details</see>
10+
/// </summary>
11+
public class ClientCapabilities
12+
{
13+
/// <summary>
14+
/// Experimental, non-standard capabilities that the client supports.
15+
/// </summary>
16+
[JsonPropertyName("experimental")]
17+
public Dictionary<string, object>? Experimental { get; set; }
18+
19+
/// <summary>
20+
/// Present if the client supports listing roots.
21+
/// </summary>
22+
[JsonPropertyName("roots")]
23+
public RootsCapability? Roots { get; set; }
24+
25+
/// <summary>
26+
/// Present if the client supports sampling from an LLM.
27+
/// </summary>
28+
[JsonPropertyName("sampling")]
29+
public SamplingCapability? Sampling { get; set; }
30+
31+
/// <summary>Gets or sets notification handlers to register with the client.</summary>
32+
/// <remarks>
33+
/// When constructed, the client will enumerate these handlers, which may contain multiple handlers per key.
34+
/// The client will not re-enumerate the sequence.
35+
/// </remarks>
36+
[JsonIgnore]
37+
public IEnumerable<KeyValuePair<string, Func<JsonRpcNotification, CancellationToken, Task>>>? NotificationHandlers { get; set; }
38+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using ModelContextProtocol.Server;
2+
using System.Text.Json.Serialization;
3+
4+
namespace ModelContextProtocol.Protocol.Types;
5+
6+
/// <summary>
7+
/// Represents the completions capability configuration.
8+
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">See the schema for details</see>
9+
/// </summary>
10+
public class CompletionsCapability
11+
{
12+
// Currently empty in the spec, but may be extended in the future.
13+
14+
/// <summary>
15+
/// Gets or sets the handler for get completion requests.
16+
/// </summary>
17+
[JsonIgnore]
18+
public Func<RequestContext<CompleteRequestParams>, CancellationToken, Task<CompleteResult>>? CompleteHandler { get; set; }
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using ModelContextProtocol.Protocol.Messages;
2+
using ModelContextProtocol.Server;
3+
using System.Text.Json.Serialization;
4+
5+
namespace ModelContextProtocol.Protocol.Types;
6+
7+
/// <summary>
8+
/// Represents the logging capability configuration.
9+
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">See the schema for details</see>
10+
/// </summary>
11+
public class LoggingCapability
12+
{
13+
// Currently empty in the spec, but may be extended in the future
14+
15+
16+
/// <summary>
17+
/// Gets or sets the handler for set logging level requests.
18+
/// </summary>
19+
[JsonIgnore]
20+
public Func<RequestContext<SetLevelRequestParams>, CancellationToken, Task<EmptyResult>>? SetLoggingLevelHandler { get; set; }
21+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using ModelContextProtocol.Protocol.Messages;
2+
using ModelContextProtocol.Server;
3+
using System.Text.Json.Serialization;
4+
5+
namespace ModelContextProtocol.Protocol.Types;
6+
7+
/// <summary>
8+
/// Represents the prompts capability configuration.
9+
/// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/">See the schema for details</see>
10+
/// </summary>
11+
public class PromptsCapability
12+
{
13+
/// <summary>
14+
/// Whether this server supports notifications for changes to the prompt list.
15+
/// </summary>
16+
[JsonPropertyName("listChanged")]
17+
public bool? ListChanged { get; set; }
18+
19+
/// <summary>
20+
/// Gets or sets the handler for list prompts requests.
21+
/// </summary>
22+
[JsonIgnore]
23+
public Func<RequestContext<ListPromptsRequestParams>, CancellationToken, Task<ListPromptsResult>>? ListPromptsHandler { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets the handler for get prompt requests.
27+
/// </summary>
28+
[JsonIgnore]
29+
public Func<RequestContext<GetPromptRequestParams>, CancellationToken, Task<GetPromptResult>>? GetPromptHandler { get; set; }
30+
31+
/// <summary>Gets or sets a collection of prompts served by the server.</summary>
32+
/// <remarks>
33+
/// Prompts will specified via <see cref="PromptCollection"/> augment the <see cref="ListPromptsHandler"/> and
34+
/// <see cref="GetPromptHandler"/>, if provided. ListPrompts requests will output information about every prompt
35+
/// in <see cref="PromptCollection"/> and then also any tools output by <see cref="ListPromptsHandler"/>, if it's
36+
/// non-<see langword="null"/>. GetPrompt requests will first check <see cref="PromptCollection"/> for the prompt
37+
/// being requested, and if the tool is not found in the <see cref="PromptCollection"/>, any specified <see cref="GetPromptHandler"/>
38+
/// will be invoked as a fallback.
39+
/// </remarks>
40+
[JsonIgnore]
41+
public McpServerPrimitiveCollection<McpServerPrompt>? PromptCollection { get; set; }
42+
}

0 commit comments

Comments
 (0)