feat: Add filtering(include/exclude params) for listing tools #1504
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.
Motivation and Context
Add
includeandexcludeparameters to thelist_toolsrequest to enable programmatic filtering of tools on the server side. This enhancement addresses a key limitation where MCP clients must retrieve all available tools from a server and then filter them client side, leading to unnecessary data transfer and larger context windows for LLMs.While MCP compliant UIs like Claude Desktop or Continue(VS Code) provide manual tool selection, programmatic use cases (such as LangChain integrations) would benefit from server side filtering capabilities. This is particularly important for LLM applications where reducing the number of tools in the context helps minimize token usage and improves model performance by avoiding overwhelming the LLM with non used tools.
For example, when using MCP servers with LangChain:
How Has This Been Tested?
ToolManagerincludeandexcludeparameter scenariosincludeandexcludeparameterslist_toolsimplementationsBreaking Changes
None. This is a backward compatible addition. Existing clients that don't use the new parameters will continue to work unchanged, receiving all available tools as before.
Types of changes
Checklist
Additional context
The implementation follows the existing MCP patterns:
PaginatedRequestParamsas the base forListToolsRequestto include the new filtering parametersincludeandexcludeto prevent ambiguous requests