feat: add Tool RAG for intelligent tool filtering with semantic search #139
+452
−4
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.
Summary
Adds Tool RAG (Retrieval-Augmented Generation) feature to intelligently filter tools using semantic search, dramatically improving performance for MCP clients with large tool sets (50+ tools).
Problem
When connecting to multiple MCP servers with 95+ tools, the client experiences severe performance degradation (3+ minutes per query) due to sending all tool schemas to the model.
Solution
Implements semantic search over tool schemas using sentence-transformers to send only relevant tools based on the user's query. Uses adaptive threshold-based filtering instead of fixed top_k for optimal results.
Performance Impact
Implementation Details
ToolRAGclass with embedding cache and semantic search--enable-tool-rag,--tool-rag-threshold, etc.Testing
bash
pytest tests/test_tool_rag.py -v
All 12 unit tests passing, including:
Dependencies
Adds
sentence-transformers(~80MB model download on first use)Breaking Changes
None - feature is opt-in via CLI flags