feat!: add pagination to mcp_client list_tools_sync #436
+62
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds pagination support to the list_tools_sync method in the MCP client by introducing a new PaginatedList generic collection type. Previously, list_tools_sync returned a simple list without any pagination capabilities, which could be problematic when dealing with MCP servers that have large numbers of tools. FastMCP always returns all tools, so this is likely why customers have not encountered this before.
Key Changes:
This change is not technically backwards compatible as PaginatedList is not List[str]. But, the majority of users will not be
impacted as their existing code simply does does a spread or passes in the tools in the following manner
Agent(tools=[mcp_client.list_tools_sync()]) # still works
list_all was not added implicitly nor explicitly yet. As we proceed with #198 we will want to consider the mechanism to auto load tools on behalf of customers. But, as the approach now is manual, customers have the choice to paginate if they want to. What I would want to avoid, is forcing customers to paginate through hundreds or thousands of tools without a mechanism to halt early.
Related Issues
#198
Type of Change
New feature+Breaking change
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli
Checklist