|
18 | 18 |
|
19 | 19 | import java.util.ArrayList; |
20 | 20 | import java.util.List; |
| 21 | +import java.util.Set; |
21 | 22 | import java.util.function.BiPredicate; |
| 23 | +import java.util.stream.Collectors; |
22 | 24 |
|
23 | 25 | import io.modelcontextprotocol.client.McpAsyncClient; |
24 | 26 | import io.modelcontextprotocol.spec.McpSchema.Tool; |
@@ -122,6 +124,34 @@ public AsyncMcpToolCallbackProvider(McpAsyncClient... mcpClients) { |
122 | 124 | this(List.of(mcpClients)); |
123 | 125 | } |
124 | 126 |
|
| 127 | + /** |
| 128 | + * Creates a new {@code AsyncMcpToolCallbackProvider} instance that includes only |
| 129 | + * clients from the specified allowed servers. |
| 130 | + * <p> |
| 131 | + * This constructor: |
| 132 | + * <ol> |
| 133 | + * <li>Filters the provided MCP clients to only those matching allowed server |
| 134 | + * names</li> |
| 135 | + * <li>Retains all tools from the selected clients (no additional tool filtering)</li> |
| 136 | + * <li>Ensures no null parameters are passed</li> |
| 137 | + * <li>Maintains full asynchronous operation capability</li> |
| 138 | + * </ol> |
| 139 | + * @param mcpClients complete list of available MCP async clients |
| 140 | + * @param allowedServerNames set of server names to include (case-sensitive) |
| 141 | + * @throws IllegalArgumentException if parameters are null or empty |
| 142 | + * @since 1.1.0 |
| 143 | + */ |
| 144 | + public AsyncMcpToolCallbackProvider(List<McpAsyncClient> mcpClients, Set<String> allowedServerNames) { |
| 145 | + Assert.notNull(mcpClients, "MCP clients list must not be null"); |
| 146 | + Assert.notNull(allowedServerNames, "Allowed server names set must not be null"); |
| 147 | + Assert.notEmpty(allowedServerNames, "Allowed server names set must not be empty"); |
| 148 | + |
| 149 | + this.mcpClients = mcpClients.stream() |
| 150 | + .filter(client -> allowedServerNames.contains(client.getServerInfo().name())) |
| 151 | + .collect(Collectors.toList()); |
| 152 | + this.toolFilter = (client, tool) -> true; |
| 153 | + } |
| 154 | + |
125 | 155 | /** |
126 | 156 | * Discovers and returns all available tools from the configured MCP servers. |
127 | 157 | * <p> |
|
0 commit comments