Add server "completions" capability (#232)

* Split apart Capabilities.cs

No code changes, just moving each type to its own file.

* Add server completions capability
This commit is contained in:
Stephen Toub 2025-04-07 16:59:37 -04:00 • committed by GitHub
commit 82510d5629
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -43,11 +43,11 @@ internal static class Program
Tools = ConfigureTools(),
Resources = ConfigureResources(),
Prompts = ConfigurePrompts(),
Logging = ConfigureLogging()
Logging = ConfigureLogging(),
Completions = ConfigureCompletions(),
},
ProtocolVersion = "2024-11-05",
ServerInstructions = "This is a test server with only stub functionality",
GetCompletionHandler = ConfigureCompletion(),
};
using var loggerFactory = CreateLoggerFactory();
@ -477,7 +477,7 @@ internal static class Program
};
}
private static Func<RequestContext<CompleteRequestParams>, CancellationToken, Task<CompleteResult>> ConfigureCompletion()
private static CompletionsCapability ConfigureCompletions()
{
List<string> sampleResourceIds = ["1", "2", "3", "4", "5"];
Dictionary<string, List<string>> exampleCompletions = new()
@ -486,7 +486,7 @@ internal static class Program
{"temperature", ["0", "0.5", "0.7", "1.0"]},
};
return (request, cancellationToken) =>
Func<RequestContext<CompleteRequestParams>, CancellationToken, Task<CompleteResult>> handler = (request, cancellationToken) =>
{
if (request.Params?.Ref?.Type == "ref/resource")
{
@ -512,6 +512,8 @@ internal static class Program
throw new McpException($"Unknown reference type: {request.Params?.Ref.Type}");
};
return new() { CompleteHandler = handler };
}
static CreateMessageRequestParams CreateRequestSamplingParams(string context, string uri, int maxTokens = 100)