Skip to content

Sync& mcp tool callback addmethod #3894

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 2 commits into
base: main
Choose a base branch
from

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);

Signed-off-by: Sizhe Fan <132420031+paoxiaomooo@users.noreply.github.com>
Signed-off-by: Sizhe Fan <132420031+paoxiaomooo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant