get_drc_history_tool
Retrieve Design Rule Check history for a KiCad project to track PCB design compliance and identify recurring issues.
Instructions
Get the DRC check history for a KiCad project.
Args: project_path: Path to the KiCad project file (.kicad_pro)
Returns: Dictionary with DRC history entries
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_path | Yes |
Implementation Reference
- kicad_mcp/tools/drc_tools.py:22-63 (handler)The handler function for the get_drc_history_tool MCP tool. It fetches the DRC history using the helper function and computes a trend analysis.@mcp.tool() def get_drc_history_tool(project_path: str) -> Dict[str, Any]: """Get the DRC check history for a KiCad project. Args: project_path: Path to the KiCad project file (.kicad_pro) Returns: Dictionary with DRC history entries """ print(f"Getting DRC history for project: {project_path}") if not os.path.exists(project_path): print(f"Project not found: {project_path}") return {"success": False, "error": f"Project not found: {project_path}"} # Get history entries history_entries = get_drc_history(project_path) # Calculate trend information trend = None if len(history_entries) >= 2: first = history_entries[-1] # Oldest entry last = history_entries[0] # Newest entry first_violations = first.get("total_violations", 0) last_violations = last.get("total_violations", 0) if first_violations > last_violations: trend = "improving" elif first_violations < last_violations: trend = "degrading" else: trend = "stable" return { "success": True, "project_path": project_path, "history_entries": history_entries, "entry_count": len(history_entries), "trend": trend }
- kicad_mcp/server.py:152-152 (registration)The registration call that invokes register_drc_tools to add the get_drc_history_tool to the MCP server.register_drc_tools(mcp)
- Helper function get_drc_history that loads the JSON history file for a project and returns sorted list of entries. Directly called by the tool handler.def get_drc_history(project_path: str) -> List[Dict[str, Any]]: """Get the DRC history for a project. Args: project_path: Path to the KiCad project file Returns: List of DRC history entries, sorted by timestamp (newest first) """ history_path = get_project_history_path(project_path) if not os.path.exists(history_path): print(f"No DRC history found for {project_path}") return [] try: with open(history_path, 'r') as f: history = json.load(f) # Sort entries by timestamp (newest first) entries = sorted( history.get("entries", []), key=lambda x: x.get("timestamp", 0), reverse=True ) return entries except (json.JSONDecodeError, IOError) as e: print(f"Error reading DRC history: {str(e)}") return []
- kicad_mcp/server.py:25-25 (registration)Import statement for the register_drc_tools function.from kicad_mcp.tools.drc_tools import register_drc_tools