feat: Implement comprehensive MCP capabilities with tool schemas and resources

This major update brings the KiCAD MCP server to full MCP 2025-06-18 spec
compliance with proper tool schemas and resources capability.

## Dependencies Updated
- @modelcontextprotocol/sdk: 1.10.0 → 1.21.0 (critical update)
- dotenv: 16.0.3 → 17.0.0 (latest stable)
- typescript: 5.2.2 → 5.9.3
- zod: 3.22.2 → 3.25.0
- @types/node: 20.5.6 → 20.19.0
- @types/express: 5.0.1 → 5.0.5
- requests (Python): 2.31.0 → 2.32.5
- Added @cfworker/json-schema for MCP SDK compatibility

## Tool Schemas (52 tools)
Created comprehensive JSON Schema definitions for all tools organized by category:
- **Project Tools** (4): create_project, open_project, save_project, get_project_info
- **Board Tools** (9): set_board_size, add_board_outline, add_layer, etc.
- **Component Tools** (10): place_component, move_component, rotate_component, etc.
- **Routing Tools** (8): add_net, route_trace, add_via, route_differential_pair, etc.
- **Library Tools** (4): list_libraries, search_footprints, etc.
- **Design Rule Tools** (4): set_design_rules, run_drc, get_drc_violations, etc.
- **Export Tools** (5): export_gerber, export_pdf, export_svg, export_3d, export_bom
- **Schematic Tools** (6): create_schematic, add_schematic_component, etc.
- **UI Tools** (2): check_kicad_ui, launch_kicad_ui

Each tool now has:
- Detailed descriptions explaining purpose
- Complete JSON Schema for input validation
- Required/optional parameter specifications
- Type constraints and validation rules

## Resources Capability (8 resources)
Implemented MCP resources to expose project state:
- `kicad://project/current/info` - Project metadata
- `kicad://project/current/board` - Board properties
- `kicad://project/current/components` - Component list
- `kicad://project/current/nets` - Electrical nets
- `kicad://project/current/layers` - Layer stack
- `kicad://project/current/design-rules` - Design rules
- `kicad://project/current/drc-report` - DRC violations
- `kicad://board/preview.png` - Board preview image

## Protocol Compliance
- Updated initialize response with proper capabilities declaration
- Added `tools: { listChanged: true }`
- Added `resources: { subscribe: false, listChanged: true }`
- Enhanced serverInfo with title and version
- Added instructions field for user guidance
- Implemented resources/list method
- Implemented resources/read method with proper error handling
- All responses follow MCP 2025-06-18 spec exactly

## Benefits
✅ Claude/LLMs can now understand what each tool does
✅ Automatic parameter validation via JSON Schema
✅ Better error messages for invalid inputs
✅ Access to project state via resources (no need to call tools)
✅ Full MCP protocol compliance
✅ Better developer experience with latest SDK features

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

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
KiCAD MCP Bot
2025-11-05 21:50:33 -05:00
co-authored by Claude
parent 1ca3e1b5db
commit d23e90b847
8 changed files with 1771 additions and 51 deletions
+65 -12
View File
@@ -14,6 +14,10 @@ import logging
import os
from typing import Dict, Any, Optional
# Import tool schemas and resource definitions
from schemas.tool_schemas import TOOL_SCHEMAS
from resources.resource_definitions import RESOURCE_DEFINITIONS, handle_resource_read
# Configure logging
log_dir = os.path.join(os.path.expanduser('~'), '.kicad-mcp', 'logs')
os.makedirs(log_dir, exist_ok=True)
@@ -536,27 +540,44 @@ def main():
'result': {
'protocolVersion': '2025-06-18',
'capabilities': {
'tools': {}
'tools': {
'listChanged': True
},
'resources': {
'subscribe': False,
'listChanged': True
}
},
'serverInfo': {
'name': 'kicad-mcp-server',
'version': '0.1.0'
}
'title': 'KiCAD PCB Design Assistant',
'version': '2.1.0-alpha'
},
'instructions': 'AI-assisted PCB design with KiCAD. Use tools to create projects, design boards, place components, route traces, and export manufacturing files.'
}
}
elif method == 'tools/list':
logger.info("Handling MCP tools/list")
# Return list of available tools
# Return list of available tools with proper schemas
tools = []
for cmd_name in interface.command_routes.keys():
tools.append({
'name': cmd_name,
'description': f'KiCAD command: {cmd_name}',
'inputSchema': {
'type': 'object',
'properties': {}
}
})
# Get schema from TOOL_SCHEMAS if available
if cmd_name in TOOL_SCHEMAS:
tool_def = TOOL_SCHEMAS[cmd_name].copy()
tools.append(tool_def)
else:
# Fallback for tools without schemas
logger.warning(f"No schema defined for tool: {cmd_name}")
tools.append({
'name': cmd_name,
'description': f'KiCAD command: {cmd_name}',
'inputSchema': {
'type': 'object',
'properties': {}
}
})
logger.info(f"Returning {len(tools)} tools")
response = {
'jsonrpc': '2.0',
'id': request_id,
@@ -584,6 +605,38 @@ def main():
]
}
}
elif method == 'resources/list':
logger.info("Handling MCP resources/list")
# Return list of available resources
response = {
'jsonrpc': '2.0',
'id': request_id,
'result': {
'resources': RESOURCE_DEFINITIONS
}
}
elif method == 'resources/read':
logger.info("Handling MCP resources/read")
resource_uri = params.get('uri')
if not resource_uri:
response = {
'jsonrpc': '2.0',
'id': request_id,
'error': {
'code': -32602,
'message': 'Missing required parameter: uri'
}
}
else:
# Read the resource
resource_data = handle_resource_read(resource_uri, interface)
response = {
'jsonrpc': '2.0',
'id': request_id,
'result': resource_data
}
else:
logger.error(f"Unknown JSON-RPC method: {method}")
response = {