-
-
Notifications
You must be signed in to change notification settings - Fork 194
feat: add tool discovery mode with automatic client capability fallback #86
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
fix: replace handler testing violations with logic function calls using dependency injection Replace 7 handler testing violations across 3 test files to follow the architectural principle: "NEVER test handlers directly - always test logic functions with dependency injection" VIOLATIONS FIXED: - src/mcp/tools/utilities/__tests__/clean_proj.test.ts: 2 violations * Replaced cleanProj.handler() calls with clean_projLogic() calls using mock executor * Changed parameter validation tests to successful execution tests - src/mcp/tools/ui-testing/__tests__/touch.test.ts: 3 violations * Replaced touchPlugin.handler() calls with touchLogic() calls using mock executor and axeHelpers * Changed parameter validation tests to business logic tests (axe dependency error, touch down/up) - src/mcp/tools/ui-testing/__tests__/type_text.test.ts: 2 violations * Replaced typeTextPlugin.handler() calls with type_textLogic() calls using mock executor and axeHelpers * Changed parameter validation tests to business logic tests (axe dependency error, successful typing) ARCHITECTURE COMPLIANCE: - All tests now use dependency injection pattern with createMockExecutor() - UI testing tools also use createMockAxeHelpers() for axe dependency simulation - Tests verify business logic rather than MCP SDK handler validation - Maintains comprehensive test coverage with literal response validation All affected tests pass (49/49) with proper dependency injection patterns. WIP
Only works with clients that support Sampling currently on VSCode.
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Important Review skippedMore than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review. 58 files out of 203 files are above the max files limit of 100. Please upgrade to Pro plan to get higher limits. You can disable this status message by setting the ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Claude finished @cameroncooke's task —— View job Code Review: Tool Discovery Mode ImplementationThis is an excellent PR that successfully introduces AI-powered tool discovery while addressing significant technical debt. The implementation demonstrates strong architectural discipline and comprehensive testing improvements. ✅ Major Strengths1. Exemplary Testing Refactor
2. Clean Architecture
3. Robust Error Handling
4. Performance Considerations
|
The TypeScript SDK fork now includes a prepare script that automatically builds the package when installed from GitHub, ensuring proper TypeScript declarations are available for CI/CD pipelines.
|
Claude finished @cameroncooke's task —— View job Code Review: Tool Discovery Mode ImplementationI've conducted a comprehensive review of this PR that introduces AI-powered tool discovery and addresses testing violations. Here's my detailed analysis: ✅ Major Strengths1. Exemplary Testing Refactor
Example from await list_devicesLogic({}, trackingExecutor, mockPathDeps, mockFsDeps);
expect(commandCalls[0].command).toEqual([
'xcrun', 'devicectl', 'list', 'devices', '--json-output', '/tmp/devicectl-123.json'
]);2. Clean Architecture Implementation
3. Robust Error Handling
4. Performance Optimizations
|
- Fix missing null check in discover_tools.ts for server.server access - Fix race condition in command.ts for detached processes by using resolved flag - Remove duplicate validation in UI testing tools (key_sequence, long_press) since createTypedTool already validates via Zod schemas - Clean up unused imports
|
Claude finished @cameroncooke's task —— View job Code Review: Tool Discovery Mode ImplementationI've conducted a comprehensive review of this PR that introduces AI-powered tool discovery and addresses testing violations. Here's my detailed analysis: ✅ Major Strengths1. Exemplary Testing Refactor
Example from await list_devicesLogic({}, trackingExecutor, mockPathDeps, mockFsDeps);
expect(commandCalls[0].command).toEqual([
'xcrun', 'devicectl', 'list', 'devices', '--json-output', '/tmp/devicectl-123.json'
]);2. Clean Architecture Implementation
3. Robust Error Handling
4. Performance Optimizations
|
- Add null checks for server.server access in discover_tools.ts - Fix race condition in command.ts for detached processes using resolved flag - Maintain validation in UI testing tools (user corrected: validation prevents invalid input) All quality checks passing: lint ✓, typecheck ✓, tests ✓ (1589 passed, 3 skipped)
|
Claude finished @cameroncooke's task —— View job Code Review: Tool Discovery Mode ImplementationI've conducted a comprehensive review of this PR that introduces AI-powered tool discovery and addresses testing violations. Here's my detailed analysis: Review Tasks:
✅ Major Strengths1. Exemplary Testing Refactor
Example from await list_devicesLogic({}, trackingExecutor, mockPathDeps, mockFsDeps);
expect(commandCalls[0].command).toEqual([
'xcrun', 'devicectl', 'list', 'devices', '--json-output', '/tmp/devicectl-123.json'
]);2. Clean Architecture Implementation
3. Robust Error Handling
4. Performance Optimizations
|
This commit eliminates redundant manual parameter validation that was duplicating Zod schema validation across 55 tool files in the MCP server. ## Changes Made ### Tool Files Modified (55 total): - Removed validateRequiredParam imports and calls - Preserved domain-specific validation (file existence checks, etc.) - All tools now rely solely on Zod schema validation via createTypedTool ### Test Files Updated: - Updated tests to expect Zod validation error messages - Changed tests to call handlers (with validation) instead of logic functions for parameter validation testing - Preserved all functional test coverage ### Key Improvements: - Eliminated 2,545 lines of redundant validation code - Consistent validation architecture using Zod schemas - Better error messages from Zod validation - Improved maintainability with single source of truth for parameter validation - Preserved all domain-specific business logic validation ### Quality Assurance: - All 1,557 tests passing - TypeScript compilation clean - ESLint validation passed - Build successful This refactoring addresses the critical Cursor Bot review comments from PR #86 by removing the duplicate validation layer while maintaining full functionality and type safety through the established createTypedTool pattern.
|
Claude finished @cameroncooke's task —— View job Code Review: Tool Discovery Mode ImplementationI've conducted a comprehensive review of this PR that introduces AI-powered tool discovery and addresses testing violations. Here's my detailed analysis: Review Tasks:
✅ Major Strengths1. Exemplary Testing Refactor
Example from await list_devicesLogic({}, trackingExecutor, mockPathDeps, mockFsDeps);
expect(commandCalls[0].command).toEqual([
'xcrun', 'devicectl', 'list', 'devices', '--json-output', '/tmp/devicectl-123.json'
]);2. Clean Architecture Implementation
3. Robust Error Handling
4. Performance Optimizations
|
|
cursor review |
- Add comprehensive input sanitization for LLM task descriptions - Remove control characters and normalize whitespace - Detect and filter potential prompt injection patterns - Enforce length limits (2000 chars) for safety - Validate non-empty strings after sanitization - Enhance null safety checks throughout response processing - Add comprehensive validation for sampling results - Improve error handling for malformed responses - Validate content structure before processing - Handle both array and object content formats safely - Make LLM parameters configurable via environment variables - XCODEBUILDMCP_LLM_MAX_TOKENS (default: 200) - XCODEBUILDMCP_LLM_TEMPERATURE (optional) - Replace hardcoded maxTokens with configurable values - Maintain backward compatibility with existing functionality - Add explicit ESLint disable for security-critical regex pattern - All changes validated through comprehensive manual testing Addresses remaining GitHub PR security review comments.
|
Claude finished @cameroncooke's task —— View job Code Review: Tool Discovery Mode ImplementationI've conducted a comprehensive review of this PR that introduces AI-powered tool discovery and addresses testing violations. Here's my detailed analysis: Review Tasks:
✅ Major Strengths1. Exemplary Testing Refactor
Example from await list_devicesLogic({}, trackingExecutor, mockPathDeps, mockFsDeps);
expect(commandCalls[0].command).toEqual([
'xcrun', 'devicectl', 'list', 'devices', '--json-output', '/tmp/devicectl-123.json'
]);2. Clean Architecture Implementation
3. Robust Error Handling
4. Performance Optimizations
|
- Add null checks for server.server access in discover_tools.ts - Fix race condition in command.ts for detached processes using resolved flag - Maintain validation in UI testing tools (user corrected: validation prevents invalid input) All quality checks passing: lint ✓, typecheck ✓, tests ✓ (1589 passed, 3 skipped)
This commit eliminates redundant manual parameter validation that was duplicating Zod schema validation across 55 tool files in the MCP server. ## Changes Made ### Tool Files Modified (55 total): - Removed validateRequiredParam imports and calls - Preserved domain-specific validation (file existence checks, etc.) - All tools now rely solely on Zod schema validation via createTypedTool ### Test Files Updated: - Updated tests to expect Zod validation error messages - Changed tests to call handlers (with validation) instead of logic functions for parameter validation testing - Preserved all functional test coverage ### Key Improvements: - Eliminated 2,545 lines of redundant validation code - Consistent validation architecture using Zod schemas - Better error messages from Zod validation - Improved maintainability with single source of truth for parameter validation - Preserved all domain-specific business logic validation ### Quality Assurance: - All 1,557 tests passing - TypeScript compilation clean - ESLint validation passed - Build successful This refactoring addresses the critical Cursor Bot review comments from PR #86 by removing the duplicate validation layer while maintaining full functionality and type safety through the established createTypedTool pattern.
Summary
This PR introduces a new Tool Discovery Mode for XcodeBuildMCP that enables AI-powered workflow selection based on natural language task descriptions, plus a comprehensive refactor addressing code quality and testing violations.
Background/Details
Major Refactor (WIP Commit)
The first commit contains a comprehensive refactor that addresses code quality and testing violations:
createMockExecutor()and dependency injection patterns instead of direct handler callsTool Discovery Mode (Main Feature)
The second commit introduces the core feature:
XCODEBUILDMCP_DYNAMIC_TOOLS=true, server starts with onlydiscover_toolsanddiscover_projsavailableSolution
Technical Implementation
XCODEBUILDMCP_DYNAMIC_TOOLS=trueto enable discovery modediscover_toolsanalyzes natural language task descriptions to select relevant workflowsArchitecture Changes
src/index.tsto support both static and dynamic modessrc/core/dynamic-tools.tswith bulk registration supportTesting
Reproduction Steps
XCODEBUILDMCP_DYNAMIC_TOOLS=trueand start with sampling-capable clientdiscover_toolswith task description → AI selects relevant workflowsValidation Method
discover_toolssuccessfully analyzes tasks and enables relevant workflowsEdge Cases
Notes
Client Compatibility
XCODEBUILDMCP_DYNAMIC_TOOLS=trueto enable discovery modePerformance Benefits
Dependencies
github:cameroncooke/typescript-sdk#mainThis implementation provides intelligent tool discovery for clients that support it, while maintaining full backward compatibility through explicit configuration.