Skip to main content
Glama

get_drc_history_tool

Retrieve Design Rule Check (DRC) history for a KiCad project by specifying the project file path. Access detailed DRC entries to analyze and improve PCB design integrity.

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
NameRequiredDescriptionDefault
project_pathYes

Implementation Reference

  • The primary handler function for the 'get_drc_history_tool' MCP tool. It is decorated with @mcp.tool() for registration and implements the core logic: validates project path, retrieves DRC history using helper function, computes improvement trend over time, and returns structured JSON response.
    @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 }
  • Top-level registration call in the MCP server setup that invokes register_drc_tools(mcp), which in turn defines and registers the get_drc_history_tool using FastMCP's @mcp.tool() decorator.
    register_drc_tools(mcp)
  • Key helper utility function that loads the project's DRC history from a JSON file (stored in user-specific directory), sorts entries by timestamp (newest first), and returns the list of history entries used 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 []
  • The register_drc_tools function that defines and registers both DRC tools (get_drc_history_tool and run_drc_check) using @mcp.tool() decorators when called from server.py.
    def register_drc_tools(mcp: FastMCP) -> None: """Register DRC tools with the MCP server. Args: mcp: The FastMCP server instance """ @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 }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lamaalrajih/kicad-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server