feat: Implement intelligent tool router pattern (Phase 1)

Adds tool discovery system to reduce AI context usage by up to 70% while
maintaining full access to all 59 tools. Organizes tools into 7 logical
categories with automatic discovery and execution.

## What's New

### Tool Router System
- 12 direct tools (always visible for high-frequency operations)
- 47 routed tools (organized into 7 discoverable categories)
- 4 router tools for discovery and execution:
  - list_tool_categories - Browse all categories
  - get_category_tools - View tools in a category
  - search_tools - Find tools by keyword
  - execute_tool - Execute any routed tool

### Tool Categories
1. board (9 tools) - Board configuration, layers, zones
2. component (8 tools) - Advanced component operations
3. export (8 tools) - Manufacturing file generation
4. drc (8 tools) - Design rule checking & validation
5. schematic (8 tools) - Schematic editor operations
6. library (4 tools) - Footprint library access
7. routing (2 tools) - Advanced routing (vias, copper pours)

## Implementation Details

### New Files
- src/tools/registry.ts - Tool categorization and lookup system
- src/tools/router.ts - Router tool implementations
- docs/ROUTER_ARCHITECTURE.md - Design specification
- docs/ROUTER_IMPLEMENTATION_STATUS.md - Implementation status
- docs/TOOL_INVENTORY.md - Complete tool catalog
- docs/ROUTER_QUICK_START.md - User guide
- docs/mcp-router-guide.md - Implementation guide
- test-router.js - Registry test suite

### Modified Files
- src/server.ts - Integrated router tool registration
- README.md - Updated with router documentation and user feedback section

## Benefits
- Reduces AI context by organizing tools into discoverable categories
- Maintains backwards compatibility (all tools still functional)
- Seamless user experience (discovery is automatic)
- Extensible architecture for adding new tools
- Comprehensive documentation

## Testing
 Build passes (npm run build)
 Registry tests pass (node test-router.js)
 Server starts successfully with router tools
 All 59 tools remain accessible

## Current State
Phase 1 Complete: Infrastructure implemented and tested
Phase 2 Pending: Optional token optimization (hide routed tools from context)

Token impact:
- Current: ~42K tokens (all tools still registered)
- Potential: ~12K tokens (70% reduction with Phase 2)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
KiCAD MCP Bot
2025-12-28 11:06:55 -05:00
parent c6e896c837
commit c65600049e
11 changed files with 2614 additions and 40 deletions

View File

@@ -20,6 +20,7 @@ import { registerExportTools } from './tools/export.js';
import { registerSchematicTools } from './tools/schematic.js';
import { registerLibraryTools } from './tools/library.js';
import { registerUITools } from './tools/ui.js';
import { registerRouterTools } from './tools/router.js';
// Import resource registration functions
import { registerProjectResources } from './resources/project.js';
@@ -123,7 +124,10 @@ export class KiCADMcpServer {
*/
private registerAll(): void {
logger.info('Registering KiCAD tools, resources, and prompts...');
// Register router tools FIRST (for tool discovery and execution)
registerRouterTools(this.server, this.callKicadScript.bind(this));
// Register all tools
registerProjectTools(this.server, this.callKicadScript.bind(this));
registerBoardTools(this.server, this.callKicadScript.bind(this));
@@ -134,19 +138,20 @@ export class KiCADMcpServer {
registerSchematicTools(this.server, this.callKicadScript.bind(this));
registerLibraryTools(this.server, this.callKicadScript.bind(this));
registerUITools(this.server, this.callKicadScript.bind(this));
// Register all resources
registerProjectResources(this.server, this.callKicadScript.bind(this));
registerBoardResources(this.server, this.callKicadScript.bind(this));
registerComponentResources(this.server, this.callKicadScript.bind(this));
registerLibraryResources(this.server, this.callKicadScript.bind(this));
// Register all prompts
registerComponentPrompts(this.server);
registerRoutingPrompts(this.server);
registerDesignPrompts(this.server);
logger.info('All KiCAD tools, resources, and prompts registered');
logger.info('Router pattern enabled: 4 router tools + direct tools for discovery');
}
/**