Skip to content

Conversation

@peteski22
Copy link
Contributor

@peteski22 peteski22 commented Nov 18, 2025

Adds tools parameter to getAgentTools() for filtering by tool name.

Supports two formats:

  • Raw: tools: ['add'] - matches tool across all servers
  • Prefixed: tools: ['time__get_current_time'] - matches specific server+tool

Can be combined with server filtering for progressive disclosure (operators filter servers, agents filter tools).

Introduces TOOL_SEPARATOR constant and validation for prefixed format.

Summary by CodeRabbit

  • New Features

    • Added client-side tool-name filtering when retrieving agent tools; accepts raw names or server-prefixed identifiers and can be combined with server and format options.
  • API

    • Public API updated to accept an optional tools?: string[] option alongside servers? and format?.
  • Documentation

    • README updated with cross-server, server-qualified and mixed-filter examples and notes on output formats (default: array).
  • Tests

    • New unit tests covering varied filtering scenarios and all output formats.

@coderabbitai
Copy link

coderabbitai bot commented Nov 18, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds an optional tools?: string[] option to getAgentTools, updates types and implementation to filter tools by raw or server‑prefixed names, updates README examples, and adds extensive unit tests (including a duplicated test suite) covering array/object/map outputs and combined server/tool filtering.

Changes

Cohort / File(s) Change Summary
Documentation
README.md
Documents new tools?: string[] option for getAgentTools, adds usage examples for raw names, server‑prefixed names, combined server/tool filtering, and array/object/map output formats.
Public types
src/types.ts
Adds tools?: string[] to AgentToolsOptions interface (accepts raw tool names and server__tool‑style prefixed names).
Implementation
src/client.ts
Extends getAgentTools overloads and implementation to accept tools?: string[]; introduces TOOL_SEPARATOR and a private matcher to support raw and server‑prefixed filtering; applies filtering before formatting results.
Tests
tests/unit/client.test.ts
Adds a suite of tests for tool filtering (raw, multiple, prefixed, mixed, combined server/tool, non‑existent/empty lists, and array/object/map formats); suite appears duplicated within the file.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding tool name filtering capability to the getAgentTools() method.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f93935c and 8a603ae.

📒 Files selected for processing (2)
  • src/client.ts (2 hunks)
  • tests/unit/client.test.ts (1 hunks)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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
@peteski22 peteski22 force-pushed the peteski22/get-agent-tools-tool-filtering branch from 0cd5b92 to f93935c Compare November 18, 2025 17:32
@peteski22 peteski22 changed the title Add tool name filtering to getAgentTools() Add tool name filtering to getAgentTools() Nov 18, 2025
Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1d6b889 and f93935c.

📒 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 matchesToolFilter function correctly handles tool names containing __ by using indexOf(TOOL_SEPARATOR) to locate only the first occurrence for server-tool boundary parsing. Additional __ characters in the tool name itself are preserved in the rightPart. Exact matching on tool.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 tools property 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.ts lines 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
@peteski22 peteski22 merged commit 3a07f34 into main Nov 19, 2025
2 of 3 checks passed
@peteski22 peteski22 deleted the peteski22/get-agent-tools-tool-filtering branch November 19, 2025 09:03
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.

3 participants