-
Notifications
You must be signed in to change notification settings - Fork 0
Add tool name filtering to getAgentTools()
#17
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
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughAdds an optional Changes
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Enables filtering tools by name in addition to server-level filtering. Supports both raw tool names (e.g., 'add') and server-prefixed names (e.g., 'time__get_current_time'). - Add tools parameter to AgentToolsOptions interface - Implement filtering logic with validation for prefixed format - Add TOOL_SEPARATOR constant to eliminate magic strings - Add comprehensive unit tests (9 test cases) - Update README with examples and progressive disclosure explanation
0cd5b92 to
f93935c
Compare
getAgentTools()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (4)
README.md(2 hunks)src/client.ts(2 hunks)src/types.ts(1 hunks)tests/unit/client.test.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/unit/client.test.ts (3)
examples/langchain/index.js (1)
tools(41-41)examples/vercel-ai/index.js (1)
tools(40-40)src/client.ts (1)
servers(615-626)
src/client.ts (4)
src/functionBuilder.ts (1)
AgentFunction(21-44)src/types.ts (1)
AgentToolsOptions(235-258)examples/langchain/index.js (2)
tools(41-41)tool(92-92)examples/vercel-ai/index.js (1)
tools(40-40)
🔇 Additional comments (9)
README.md (2)
362-368: LGTM! Clear rationale for the feature.The explanation effectively communicates the benefits of tool filtering for AI agent performance and the progressive disclosure pattern.
370-427: Excellent examples covering key usage patterns.The documentation provides clear examples for:
- Raw tool name filtering (cross-server)
- Prefixed tool name filtering (server-specific)
- Combined server and tool filtering
- Format compatibility
This comprehensive coverage will help users understand the feature quickly.
src/client.ts (3)
796-810: LGTM! Overload signatures updated consistently.The
tools?: string[]parameter is added consistently across all three overloads for different format options.
811-837: LGTM! Clean implementation with proper conditional filtering.The implementation correctly:
- Fetches all tools for requested servers
- Applies filtering only when the tools parameter is provided
- Handles empty arrays appropriately (returns empty result, as tested on lines 604-647)
- Converts to the requested format using the filtered results
53-58: No issues found with double underscore handling in tool names.The
matchesToolFilterfunction correctly handles tool names containing__by usingindexOf(TOOL_SEPARATOR)to locate only the first occurrence for server-tool boundary parsing. Additional__characters in the tool name itself are preserved in therightPart. Exact matching ontool.name(line 859) ensures names like "my__special__tool" and "test__my__special__tool" are correctly matched, as verified by the test cases at lines 705–720 and 747–762.src/types.ts (1)
241-249: LGTM! Clear documentation with examples.The
toolsproperty is well-documented with:
- Clear explanation of both filtering modes (raw and prefixed)
- Practical examples
- Appropriate optional typing
Note: Consider adding a remark about precedence when filter names are ambiguous (e.g., when a filter could match both a raw tool name and a prefixed format), aligning with the suggestion for
client.tslines 839-866.tests/unit/client.test.ts (3)
371-451: LGTM! Well-structured test setup.The test suite has:
- Comprehensive mock data covering multiple servers and tools
- Reusable helper function to reduce duplication
- Clear organisation for the test scenarios
453-502: LGTM! Comprehensive coverage of basic filtering scenarios.Tests validate:
- Single raw tool name filtering
- Multiple raw tool names
- Server-prefixed tool names
- Mixed raw and prefixed formats
All assertions check the appropriate properties to ensure correct matching behaviour.
504-647: LGTM! Thorough edge case coverage.Tests validate:
- Combined server and tool filtering working together
- Non-existent tool returning empty array (graceful handling)
- Empty tools list returning empty array (explicit filtering to nothing)
The assertions correctly use Set operations to verify the filtering logic.
- Remove unnecessary validation in #matchesToolFilter - Malformed filter strings naturally fail to match - Add test case for ambiguous filter names
Adds
toolsparameter togetAgentTools()for filtering by tool name.Supports two formats:
tools: ['add']- matches tool across all serverstools: ['time__get_current_time']- matches specific server+toolCan be combined with server filtering for progressive disclosure (operators filter servers, agents filter tools).
Introduces
TOOL_SEPARATORconstant and validation for prefixed format.Summary by CodeRabbit
New Features
API
Documentation
Tests