kicad-mcp/kicad_mcp/tools/project_tools.py
Ryan Malloy eda114db90 Implement revolutionary KiCad MCP server with FreeRouting integration
This major update transforms the KiCad MCP server from file-based analysis to
a complete EDA automation platform with real-time KiCad integration and
automated routing capabilities.

🎯 Key Features Implemented:
- Complete FreeRouting integration engine for automated PCB routing
- Real-time KiCad IPC API integration for live board analysis
- Comprehensive routing tools (automated, interactive, quality analysis)
- Advanced project automation pipeline (concept to manufacturing)
- AI-enhanced design analysis and optimization
- 3D model analysis and mechanical constraint checking
- Advanced DRC rule management and validation
- Symbol library analysis and organization tools
- Layer stackup analysis and impedance calculations

🛠️ Technical Implementation:
- Enhanced MCP tools: 35+ new routing and automation functions
- FreeRouting engine with DSN/SES workflow automation
- Real-time component placement optimization via IPC API
- Complete project automation from schematic to manufacturing files
- Comprehensive integration testing framework

🔧 Infrastructure:
- Fixed all FastMCP import statements across codebase
- Added comprehensive integration test suite
- Enhanced server registration for all new tool categories
- Robust error handling and fallback mechanisms

 Testing Results:
- Server startup and tool registration: ✓ PASS
- Project validation with thermal camera project: ✓ PASS
- Routing prerequisites detection: ✓ PASS
- KiCad CLI integration (v9.0.3): ✓ PASS
- Ready for KiCad IPC API enablement and FreeRouting installation

🚀 Impact:
This represents the ultimate KiCad integration for Claude Code, enabling
complete EDA workflow automation from concept to production-ready files.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-13 00:07:04 -06:00

63 lines
1.8 KiB
Python

"""
Project management tools for KiCad.
"""
import logging
import os
from typing import Any
from fastmcp import FastMCP
from kicad_mcp.utils.file_utils import get_project_files, load_project_json
from kicad_mcp.utils.kicad_utils import find_kicad_projects, open_kicad_project
# Get PID for logging
# _PID = os.getpid()
def register_project_tools(mcp: FastMCP) -> None:
"""Register project management tools with the MCP server.
Args:
mcp: The FastMCP server instance
"""
@mcp.tool()
def list_projects() -> list[dict[str, Any]]:
"""Find and list all KiCad projects on this system."""
logging.info("Executing list_projects tool...")
projects = find_kicad_projects()
logging.info(f"list_projects tool returning {len(projects)} projects.")
return projects
@mcp.tool()
def get_project_structure(project_path: str) -> dict[str, Any]:
"""Get the structure and files of a KiCad project."""
if not os.path.exists(project_path):
return {"error": f"Project not found: {project_path}"}
project_dir = os.path.dirname(project_path)
project_name = os.path.basename(project_path)[:-10] # Remove .kicad_pro extension
# Get related files
files = get_project_files(project_path)
# Get project metadata
metadata = {}
project_data = load_project_json(project_path)
if project_data and "metadata" in project_data:
metadata = project_data["metadata"]
return {
"name": project_name,
"path": project_path,
"directory": project_dir,
"files": files,
"metadata": metadata,
}
@mcp.tool()
def open_project(project_path: str) -> dict[str, Any]:
"""Open a KiCad project in KiCad."""
return open_kicad_project(project_path)