Skip to content

docs(mcp): add dynamic MCP client selection example #3751

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -65,7 +65,24 @@ For multiple clients:
List<McpSyncClient> clients = // obtain list of clients
List<ToolCallback> callbacks = SyncMcpToolCallbackProvider.syncToolCallbacks(clients);
----
+
For dynamic selection of a subset of clients
+
[source,java]
----
@Autowired
private List<McpSyncClient> mcpSyncClients;

public ToolCallbackProvider buildProvider(Set<String> allowedServerNames) {
// Filter by server.name().
List<McpSyncClient> selected = mcpSyncClients.stream()
.filter(c -> allowedServerNames.contains(c.getServerInfo().name()))
.toList();

return new SyncMcpToolCallbackProvider(selected);
}

----
Async::
+
[source,java]
Expand Down