Skip to content

Conversation

@paoxiaomooo
Copy link
Contributor

Add filtered constructors for MCP Tool Callback Providers

This PR introduces new constructors for both SyncMcpToolCallbackProvider and AsyncMcpToolCallbackProvider to allow initialization with a filtered subset of MCP clients based on allowed server names.

Changes

  • Added a constructor to SyncMcpToolCallbackProvider that:

    • Accepts a full list of McpSyncClient instances and a set of allowed server names
    • Filters clients to only include those with names in the allowed list
    • Applies no additional tool-level filtering
  • Added a similar constructor to AsyncMcpToolCallbackProvider for McpAsyncClient

  • Ensured that both constructors validate non-null and non-empty input parameters

Motivation

When building large-scale AI workflows, users may want to initialize tool callback providers with only a subset of trusted or registered MCP servers. These new constructors provide a convenient way to restrict tool resolution to specific servers without affecting existing usage.

Compatibility

These additions are non-breaking and fully backward-compatible. Default constructors remain unchanged.

Why Add Server Filtering?

  1. Selective Tool Discovery – Only fetch tools from specified servers, reducing overhead and improving performance.
  2. Consistent API – Matches the sync version’s functionality, avoiding surprises.
  3. Reactive Efficiency – Built-in non-blocking filtering for cleaner, optimized async flows.
  4. Operational Control – Enables precise server management in multi-server environments.

Before: Manual filtering + duplicate checks.
After: Single-line reactive filtering with validation.
// Cleaner, safer usage
Flux tools = asyncToolCallbacksByServer(clients, allowedServers);

@ilayaperumalg ilayaperumalg self-assigned this Sep 24, 2025
@ilayaperumalg
Copy link
Member

@paoxiaomooo Thank you for the PR.

In 1.1.0-M1, we have added the tool filtering mechanism which can be customised and injected into both Sync/Async MCP ToolCallbackProviders. Please check this detailed documentation around the tool filtering option in Spring AI MCP Client Boot Starters.

With this support, we are closing this PR without merging. We sincerely appreciate your contribution and looking forward to working with you in other topics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants