Skip to content

Paoxiaomooo sync mcp tool callback addmethod #3891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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 @@ -18,6 +18,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.BiPredicate;

import io.modelcontextprotocol.client.McpAsyncClient;
Expand Down Expand Up @@ -90,7 +91,33 @@ public AsyncMcpToolCallbackProvider(BiPredicate<McpAsyncClient, Tool> toolFilter
this.mcpClients = mcpClients;
this.toolFilter = toolFilter;
}

/**
* Creates a new {@code AsyncMcpToolCallbackProvider} instance that includes only clients
* from the specified allowed servers.
* <p>
* This constructor:
* <ol>
* <li>Filters the provided MCP clients to only those matching allowed server names</li>
* <li>Retains all tools from the selected clients (no additional tool filtering)</li>
* <li>Ensures no null parameters are passed</li>
* <li>Maintains full asynchronous operation capability</li>
* </ol>
*
* @param mcpClients complete list of available MCP async clients
* @param allowedServerNames set of server names to include (case-sensitive)
* @throws IllegalArgumentException if parameters are null or empty
* @since 1.1.0
*/
public AsyncMcpToolCallbackProvider(List<McpAsyncClient> mcpClients, Set<String> allowedServerNames) {
Assert.notNull(mcpClients, "MCP clients list must not be null");
Assert.notNull(allowedServerNames, "Allowed server names set must not be null");
Assert.notEmpty(allowedServerNames, "Allowed server names set must not be empty");

this.mcpClients = mcpClients.stream()
.filter(client -> allowedServerNames.contains(client.getServerInfo().name()))
.collect(Collectors.toList());
this.toolFilter = (client, tool) -> true;
}
/**
* Creates a new {@code AsyncMcpToolCallbackProvider} instance with a list of MCP
* clients.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.ai.mcp;

import java.util.List;
import java.util.Set;
import java.util.function.BiPredicate;

import io.modelcontextprotocol.client.McpSyncClient;
Expand Down Expand Up @@ -86,7 +87,32 @@ public SyncMcpToolCallbackProvider(BiPredicate<McpSyncClient, Tool> toolFilter,
this.mcpClients = mcpClients;
this.toolFilter = toolFilter;
}

/**
* Creates a new {@code SyncMcpToolCallbackProvider} instance that includes only clients
* from the specified allowed servers.
* <p>
* This constructor:
* <ol>
* <li>Filters the provided MCP clients to only those matching allowed server names</li>
* <li>Retains all tools from the selected clients (no additional tool filtering)</li>
* <li>Ensures no null parameters are passed</li>
* </ol>
*
* @param mcpClients complete list of available MCP clients
* @param allowedServerNames set of server names to include (case-sensitive)
* @throws IllegalArgumentException if parameters are null or empty
* @since 1.1.0
*/
public SyncMcpToolCallbackProvider(List<McpSyncClient> mcpClients, Set<String> allowedServerNames) {
Assert.notNull(mcpClients, "MCP clients list must not be null");
Assert.notNull(allowedServerNames, "Allowed server names set must not be null");
Assert.notEmpty(allowedServerNames, "Allowed server names set must not be empty");

this.mcpClients = mcpClients.stream()
.filter(client -> allowedServerNames.contains(client.getServerInfo().name()))
.toList();
this.toolFilter = (client, tool) -> true; // No additional filtering
}
/**
* Creates a new {@code SyncMcpToolCallbackProvider} instance with a list of MCP
* clients.
Expand Down
Loading