feat(mcp): add support for completion specifications in MCP server
Add support for completion specifications in both sync and async MCP servers by: - Adding parameters for SyncCompletionSpecification and AsyncCompletionSpecification - Implementing registration of completion specifications in server builders - Updating capabilities builders to include completions - Upgrading MCP SDK version to 0.10.0-SNAPSHOT Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
This commit is contained in:
@@ -28,9 +28,11 @@ import io.modelcontextprotocol.server.McpServer;
|
||||
import io.modelcontextprotocol.server.McpServer.AsyncSpecification;
|
||||
import io.modelcontextprotocol.server.McpServer.SyncSpecification;
|
||||
import io.modelcontextprotocol.server.McpServerFeatures;
|
||||
import io.modelcontextprotocol.server.McpServerFeatures.AsyncCompletionSpecification;
|
||||
import io.modelcontextprotocol.server.McpServerFeatures.AsyncPromptSpecification;
|
||||
import io.modelcontextprotocol.server.McpServerFeatures.AsyncResourceSpecification;
|
||||
import io.modelcontextprotocol.server.McpServerFeatures.AsyncToolSpecification;
|
||||
import io.modelcontextprotocol.server.McpServerFeatures.SyncCompletionSpecification;
|
||||
import io.modelcontextprotocol.server.McpServerFeatures.SyncPromptSpecification;
|
||||
import io.modelcontextprotocol.server.McpServerFeatures.SyncResourceSpecification;
|
||||
import io.modelcontextprotocol.server.McpServerFeatures.SyncToolSpecification;
|
||||
@@ -173,6 +175,7 @@ public class McpServerAutoConfiguration {
|
||||
ObjectProvider<List<SyncToolSpecification>> tools,
|
||||
ObjectProvider<List<SyncResourceSpecification>> resources,
|
||||
ObjectProvider<List<SyncPromptSpecification>> prompts,
|
||||
ObjectProvider<List<SyncCompletionSpecification>> completions,
|
||||
ObjectProvider<BiConsumer<McpSyncServerExchange, List<McpSchema.Root>>> rootsChangeConsumers,
|
||||
List<ToolCallbackProvider> toolCallbackProvider) {
|
||||
|
||||
@@ -216,6 +219,15 @@ public class McpServerAutoConfiguration {
|
||||
+ serverProperties.isPromptChangeNotification());
|
||||
}
|
||||
|
||||
List<SyncCompletionSpecification> completionSpecifications = completions.stream()
|
||||
.flatMap(List::stream)
|
||||
.toList();
|
||||
if (!CollectionUtils.isEmpty(completionSpecifications)) {
|
||||
serverBuilder.completions(completionSpecifications);
|
||||
capabilitiesBuilder.completions();
|
||||
logger.info("Registered completions: " + completionSpecifications.size());
|
||||
}
|
||||
|
||||
rootsChangeConsumers.ifAvailable(consumer -> {
|
||||
serverBuilder.rootsChangeHandler((exchange, roots) -> consumer.accept(exchange, roots));
|
||||
logger.info("Registered roots change consumer");
|
||||
@@ -270,6 +282,7 @@ public class McpServerAutoConfiguration {
|
||||
ObjectProvider<List<AsyncToolSpecification>> tools,
|
||||
ObjectProvider<List<AsyncResourceSpecification>> resources,
|
||||
ObjectProvider<List<AsyncPromptSpecification>> prompts,
|
||||
ObjectProvider<List<AsyncCompletionSpecification>> completions,
|
||||
ObjectProvider<BiConsumer<McpAsyncServerExchange, List<McpSchema.Root>>> rootsChangeConsumer,
|
||||
List<ToolCallbackProvider> toolCallbackProvider) {
|
||||
|
||||
@@ -313,6 +326,15 @@ public class McpServerAutoConfiguration {
|
||||
+ serverProperties.isPromptChangeNotification());
|
||||
}
|
||||
|
||||
List<AsyncCompletionSpecification> completionSpecifications = completions.stream()
|
||||
.flatMap(List::stream)
|
||||
.toList();
|
||||
if (!CollectionUtils.isEmpty(completionSpecifications)) {
|
||||
serverBuilder.completions(completionSpecifications);
|
||||
capabilitiesBuilder.completions();
|
||||
logger.info("Registered completions: " + completionSpecifications.size());
|
||||
}
|
||||
|
||||
rootsChangeConsumer.ifAvailable(consumer -> {
|
||||
BiFunction<McpAsyncServerExchange, List<McpSchema.Root>, Mono<Void>> asyncConsumer = (exchange, roots) -> {
|
||||
consumer.accept(exchange, roots);
|
||||
|
||||
Reference in New Issue
Block a user