feat: add wildcard tool filtering support with * patterns#2
Conversation
Implements glob-style wildcard filtering for tool names in both proxy mode and list-tools command. Tool patterns like 'get_*' now match any tool starting with 'get_' such as 'get_logs', 'get_metrics', etc. - Add matchesToolPattern function with proper regex escaping for safe wildcard matching - Update filtering logic in proxy-server.ts and cli.ts to use pattern matching - Maintain full backward compatibility with exact tool name matching - Add comprehensive test suite covering wildcard functionality - Enhance help text with wildcard usage examples - Update existing tests for additional test fixture tool 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Extract matchesToolPattern function to shared utils module - Add reusable test utilities and message builders - Refactor integration tests to use shared test helpers - Update ESLint config with formatting and unused vars rule 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull Request Overview
This PR adds wildcard pattern matching support for tool filtering using * patterns while maintaining full backward compatibility with exact tool name matching.
- Add
matchesToolPattern()function with proper regex escaping for wildcard pattern support - Extend
--enabled-toolsand--disabled-toolsto support glob-like patterns in both proxy and list-tools modes - Add comprehensive test coverage for wildcard filtering scenarios and edge cases
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils.ts | New utility function for wildcard pattern matching with regex escaping |
| src/proxy-server.ts | Updated tool filtering logic to use wildcard pattern matching |
| src/cli.ts | Enhanced list-tools mode and help text with wildcard pattern support |
| tests/wildcard-filtering.test.ts | Comprehensive test suite for wildcard filtering functionality |
| tests/test-utils.ts | New utility functions for test process management and JSON-RPC communication |
| tests/test-messages.ts | Centralized JSON-RPC message creation functions for tests |
| tests/fixtures/mcp-server.ts | Added subtract tool for more comprehensive testing |
| tests/list-tools.test.ts | Updated expectations to account for additional test tool |
| tests/integration.test.ts | Refactored to use shared test utilities and updated for new test tool |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if (args.length === 0) { | ||
| process.stderr.write('Usage: mcp-controller [--enabled-tools <tool1,tool2,...>] [--disabled-tools <tool1,tool2,...>] <command> [args...]\n'); | ||
| process.stderr.write(' mcp-controller list-tools [--enabled-tools <tool1,tool2,...>] [--disabled-tools <tool1,tool2,...>] <command> [args...]\n'); | ||
| process.stderr.write('Tool patterns support wildcards: use * to match any characters (e.g., get_* matches get_logs, get_metrics)\n'); |
There was a problem hiding this comment.
The indentation is inconsistent with the surrounding lines. This line should be indented to match the other process.stderr.write statements above and below it.
| process.stderr.write(' mcp-controller list-tools [--enabled-tools <tool1,tool2,...>] [--disabled-tools <tool1,tool2,...>] <command> [args...]\n'); | ||
| process.stderr.write('Tool patterns support wildcards: use * to match any characters (e.g., get_* matches get_logs, get_metrics)\n'); | ||
| process.stderr.write('Example: mcp-controller --enabled-tools add,subtract bun run server.ts\n'); | ||
| process.stderr.write('Example: mcp-controller --enabled-tools "get_*,list_*" bun run server.ts\n'); |
There was a problem hiding this comment.
The indentation is inconsistent with the surrounding lines. This line should be indented to match the other process.stderr.write statements above and below it.
| process.stderr.write('Example: mcp-controller --enabled-tools "get_*,list_*" bun run server.ts\n'); | |
| process.stderr.write('Example: mcp-controller --enabled-tools "get_*,list_*" bun run server.ts\n'); |
Summary
*character--enabled-toolsand--disabled-toolsto support glob-like patternsChanges
Core Functionality
Modified
src/cli.ts: AddedmatchesToolPattern()function with proper regex escaping to handle wildcard patterns*to regex.*with proper escaping of special charactersModified
src/proxy-server.ts: Extended proxy server tool filtering to support wildcard patternsmatchesToolPattern()function for consistent behaviorTest Coverage
Added
tests/wildcard-filtering.test.ts: Comprehensive test suite covering:*-argsandget-**pattern functionalityModified
tests/fixtures/mcp-server.ts: Addedsubtracttool to provide more tools for comprehensive wildcard testingUpdated existing tests: Modified
tests/integration.test.tsandtests/list-tools.test.tsto account for additional test fixture toolsUsage Examples
Implementation Details
Pattern Matching Logic
*use exact string comparison for performance*^pattern$to ensure full string matchingBackward Compatibility
*character usageTest Plan
get_*,*_args, and*work correctly🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com