kicad-mcp/kicad_mcp/tools/project_tools.py
Ryan Malloy bc0f3db97c
Some checks are pending
CI / Lint and Format (push) Waiting to run
CI / Test Python 3.11 on macos-latest (push) Waiting to run
CI / Test Python 3.12 on macos-latest (push) Waiting to run
CI / Test Python 3.13 on macos-latest (push) Waiting to run
CI / Test Python 3.10 on ubuntu-latest (push) Waiting to run
CI / Test Python 3.11 on ubuntu-latest (push) Waiting to run
CI / Test Python 3.12 on ubuntu-latest (push) Waiting to run
CI / Test Python 3.13 on ubuntu-latest (push) Waiting to run
CI / Security Scan (push) Waiting to run
CI / Build Package (push) Blocked by required conditions
Implement comprehensive AI/LLM integration for KiCad MCP server
Add intelligent analysis and recommendation tools for KiCad designs:

## New AI Tools (kicad_mcp/tools/ai_tools.py)
- suggest_components_for_circuit: Smart component suggestions based on circuit analysis
- recommend_design_rules: Automated design rule recommendations for different technologies
- optimize_pcb_layout: PCB layout optimization for signal integrity, thermal, and cost
- analyze_design_completeness: Comprehensive design completeness analysis

## Enhanced Utilities
- component_utils.py: Add ComponentType enum and component classification functions
- pattern_recognition.py: Enhanced circuit pattern analysis and recommendations
- netlist_parser.py: Implement missing parse_netlist_file function for AI tools

## Key Features
- Circuit pattern recognition for power supplies, amplifiers, microcontrollers
- Technology-specific design rules (standard, HDI, RF, automotive)
- Layout optimization suggestions with implementation steps
- Component suggestion system with standard values and examples
- Design completeness scoring with actionable recommendations

## Server Integration
- Register AI tools in FastMCP server
- Integrate with existing KiCad utilities and file parsers
- Error handling and graceful fallbacks for missing data

Fixes ImportError that prevented server startup and enables advanced
AI-powered design assistance for KiCad projects.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 16:15:58 -06:00

63 lines
1.9 KiB
Python

"""
Project management tools for KiCad.
"""
import logging
import os
from typing import Any
from mcp.server.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)