Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ private List<McpServerFeatures.SyncToolSpecification> toSyncToolSpecifications(L

// De-duplicate tools by their name, keeping the first occurrence of each tool
// name
return tools.stream()
.collect(Collectors.toMap(tool -> tool.getToolDefinition().name(), // Key:
// tool
// name
tool -> tool, // Value: the tool itself
return tools.stream() // Key: tool name
.collect(Collectors.toMap(tool -> tool.getToolDefinition().name(), tool -> tool, // Value:
// the
// tool
// itself
(existing, replacement) -> existing)) // On duplicate key, keep the
// existing tool
.values()
Expand Down Expand Up @@ -185,47 +185,66 @@ public McpSyncServer mcpSyncServer(McpServerTransportProvider transportProvider,
// Create the server with both tool and resource capabilities
SyncSpecification serverBuilder = McpServer.sync(transportProvider).serverInfo(serverInfo);

List<SyncToolSpecification> toolSpecifications = new ArrayList<>(tools.stream().flatMap(List::stream).toList());
// Tools
if (serverProperties.getCapabilities().isTool()) {
logger.info("Enable tools capabilities, notification: " + serverProperties.isToolChangeNotification());
capabilitiesBuilder.tools(serverProperties.isToolChangeNotification());

List<ToolCallback> providerToolCallbacks = toolCallbackProvider.stream()
.map(pr -> List.of(pr.getToolCallbacks()))
.flatMap(List::stream)
.filter(fc -> fc instanceof ToolCallback)
.map(fc -> (ToolCallback) fc)
.toList();
List<SyncToolSpecification> toolSpecifications = new ArrayList<>(
tools.stream().flatMap(List::stream).toList());

toolSpecifications.addAll(this.toSyncToolSpecifications(providerToolCallbacks, serverProperties));
List<ToolCallback> providerToolCallbacks = toolCallbackProvider.stream()
.map(pr -> List.of(pr.getToolCallbacks()))
.flatMap(List::stream)
.filter(fc -> fc instanceof ToolCallback)
.map(fc -> (ToolCallback) fc)
.toList();

if (!CollectionUtils.isEmpty(toolSpecifications)) {
serverBuilder.tools(toolSpecifications);
capabilitiesBuilder.tools(serverProperties.isToolChangeNotification());
logger.info("Registered tools: " + toolSpecifications.size() + ", notification: "
+ serverProperties.isToolChangeNotification());
toolSpecifications.addAll(this.toSyncToolSpecifications(providerToolCallbacks, serverProperties));

if (!CollectionUtils.isEmpty(toolSpecifications)) {
serverBuilder.tools(toolSpecifications);
logger.info("Registered tools: " + toolSpecifications.size());
}
}

List<SyncResourceSpecification> resourceSpecifications = resources.stream().flatMap(List::stream).toList();
if (!CollectionUtils.isEmpty(resourceSpecifications)) {
serverBuilder.resources(resourceSpecifications);
// Resources
if (serverProperties.getCapabilities().isResource()) {
logger.info(
"Enable resources capabilities, notification: " + serverProperties.isResourceChangeNotification());
capabilitiesBuilder.resources(false, serverProperties.isResourceChangeNotification());
logger.info("Registered resources: " + resourceSpecifications.size() + ", notification: "
+ serverProperties.isResourceChangeNotification());

List<SyncResourceSpecification> resourceSpecifications = resources.stream().flatMap(List::stream).toList();
if (!CollectionUtils.isEmpty(resourceSpecifications)) {
serverBuilder.resources(resourceSpecifications);
logger.info("Registered resources: " + resourceSpecifications.size());
}
}

List<SyncPromptSpecification> promptSpecifications = prompts.stream().flatMap(List::stream).toList();
if (!CollectionUtils.isEmpty(promptSpecifications)) {
serverBuilder.prompts(promptSpecifications);
// Prompts
if (serverProperties.getCapabilities().isPrompt()) {
logger.info("Enable prompts capabilities, notification: " + serverProperties.isPromptChangeNotification());
capabilitiesBuilder.prompts(serverProperties.isPromptChangeNotification());
logger.info("Registered prompts: " + promptSpecifications.size() + ", notification: "
+ serverProperties.isPromptChangeNotification());

List<SyncPromptSpecification> promptSpecifications = prompts.stream().flatMap(List::stream).toList();
if (!CollectionUtils.isEmpty(promptSpecifications)) {
serverBuilder.prompts(promptSpecifications);
logger.info("Registered prompts: " + promptSpecifications.size());
}
}

List<SyncCompletionSpecification> completionSpecifications = completions.stream()
.flatMap(List::stream)
.toList();
if (!CollectionUtils.isEmpty(completionSpecifications)) {
serverBuilder.completions(completionSpecifications);
// Completions
if (serverProperties.getCapabilities().isCompletion()) {
logger.info("Enable completions capabilities");
capabilitiesBuilder.completions();
logger.info("Registered completions: " + completionSpecifications.size());

List<SyncCompletionSpecification> completionSpecifications = completions.stream()
.flatMap(List::stream)
.toList();
if (!CollectionUtils.isEmpty(completionSpecifications)) {
serverBuilder.completions(completionSpecifications);
logger.info("Registered completions: " + completionSpecifications.size());
}
}

rootsChangeConsumers.ifAvailable(consumer -> {
Expand Down Expand Up @@ -257,11 +276,11 @@ private List<McpServerFeatures.AsyncToolSpecification> toAsyncToolSpecification(
McpServerProperties serverProperties) {
// De-duplicate tools by their name, keeping the first occurrence of each tool
// name
return tools.stream()
.collect(Collectors.toMap(tool -> tool.getToolDefinition().name(), // Key:
// tool
// name
tool -> tool, // Value: the tool itself
return tools.stream() // Key: tool name
.collect(Collectors.toMap(tool -> tool.getToolDefinition().name(), tool -> tool, // Value:
// the
// tool
// itself
(existing, replacement) -> existing)) // On duplicate key, keep the
// existing tool
.values()
Expand Down Expand Up @@ -303,35 +322,51 @@ public McpAsyncServer mcpAsyncServer(McpServerTransportProvider transportProvide

toolSpecifications.addAll(this.toAsyncToolSpecification(providerToolCallbacks, serverProperties));

// Tools
if (serverProperties.getCapabilities().isTool()) {
logger.info("Enable tools capabilities, notification: " + serverProperties.isToolChangeNotification());
capabilitiesBuilder.tools(serverProperties.isToolChangeNotification());
}

if (!CollectionUtils.isEmpty(toolSpecifications)) {
serverBuilder.tools(toolSpecifications);
capabilitiesBuilder.tools(serverProperties.isToolChangeNotification());
logger.info("Registered tools: " + toolSpecifications.size() + ", notification: "
+ serverProperties.isToolChangeNotification());
logger.info("Registered tools: " + toolSpecifications.size());
}

// Resources
if (serverProperties.getCapabilities().isResource()) {
logger.info(
"Enable resources capabilities, notification: " + serverProperties.isResourceChangeNotification());
capabilitiesBuilder.resources(false, serverProperties.isResourceChangeNotification());
}

List<AsyncResourceSpecification> resourceSpecifications = resources.stream().flatMap(List::stream).toList();
if (!CollectionUtils.isEmpty(resourceSpecifications)) {
serverBuilder.resources(resourceSpecifications);
capabilitiesBuilder.resources(false, serverProperties.isResourceChangeNotification());
logger.info("Registered resources: " + resourceSpecifications.size() + ", notification: "
+ serverProperties.isResourceChangeNotification());
logger.info("Registered resources: " + resourceSpecifications.size());
}

// Prompts
if (serverProperties.getCapabilities().isPrompt()) {
logger.info("Enable prompts capabilities, notification: " + serverProperties.isPromptChangeNotification());
capabilitiesBuilder.prompts(serverProperties.isPromptChangeNotification());
}
List<AsyncPromptSpecification> promptSpecifications = prompts.stream().flatMap(List::stream).toList();
if (!CollectionUtils.isEmpty(promptSpecifications)) {
serverBuilder.prompts(promptSpecifications);
capabilitiesBuilder.prompts(serverProperties.isPromptChangeNotification());
logger.info("Registered prompts: " + promptSpecifications.size() + ", notification: "
+ serverProperties.isPromptChangeNotification());
logger.info("Registered prompts: " + promptSpecifications.size());
}

// Completions
if (serverProperties.getCapabilities().isCompletion()) {
logger.info("Enable completions capabilities");
capabilitiesBuilder.completions();
}
List<AsyncCompletionSpecification> completionSpecifications = completions.stream()
.flatMap(List::stream)
.toList();
if (!CollectionUtils.isEmpty(completionSpecifications)) {
serverBuilder.completions(completionSpecifications);
capabilitiesBuilder.completions();
logger.info("Registered completions: " + completionSpecifications.size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ public class McpServerProperties {
*/
private ServerType type = ServerType.SYNC;

private Capabilities capabilities = new Capabilities();

public Capabilities getCapabilities() {
return this.capabilities;
}

/**
* Server types supported by the MCP server.
*/
Expand Down Expand Up @@ -260,4 +266,48 @@ public Map<String, String> getToolResponseMimeType() {
return this.toolResponseMimeType;
}

public static class Capabilities {

private boolean resource = true;

private boolean tool = true;

private boolean prompt = true;

private boolean completion = true;

public boolean isResource() {
return this.resource;
}

public void setResource(boolean resource) {
this.resource = resource;
}

public boolean isTool() {
return this.tool;
}

public void setTool(boolean tool) {
this.tool = tool;
}

public boolean isPrompt() {
return this.prompt;
}

public void setPrompt(boolean prompt) {
this.prompt = prompt;
}

public boolean isCompletion() {
return this.completion;
}

public void setCompletion(boolean completion) {
this.completion = completion;
}

}

}
Loading