Skip to main content
Glama
lamaalrajih

KiCad MCP Server

by lamaalrajih

analyze_schematic_connections

Analyze component connections in KiCad schematics to identify power nets, signal paths, and potential electrical issues.

Instructions

Analyze connections in a KiCad schematic.

This tool provides detailed analysis of component connections, including power nets, signal paths, and potential issues.

Args: schematic_path: Path to the KiCad schematic file (.kicad_sch) ctx: MCP context for progress reporting

Returns: Dictionary with connection analysis

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schematic_pathYes
ctxYes

Implementation Reference

  • Core handler implementation decorated with @mcp.tool(). Extracts netlist from schematic, categorizes components by type, identifies power and signal nets, detects potential issues like floating nets, and returns detailed analysis.
    @mcp.tool()
    async def analyze_schematic_connections(schematic_path: str, ctx: Context | None) -> Dict[str, Any]:
        """Analyze connections in a KiCad schematic.
        
        This tool provides detailed analysis of component connections,
        including power nets, signal paths, and potential issues.
        
        Args:
            schematic_path: Path to the KiCad schematic file (.kicad_sch)
            ctx: MCP context for progress reporting
            
        Returns:
            Dictionary with connection analysis
        """
        print(f"Analyzing connections in schematic: {schematic_path}")
        
        if not os.path.exists(schematic_path):
            print(f"Schematic file not found: {schematic_path}")
            if ctx:
                ctx.info(f"Schematic file not found: {schematic_path}")
            return {"success": False, "error": f"Schematic file not found: {schematic_path}"}
        
        # Report progress
        if ctx:
            await ctx.report_progress(10, 100)
            ctx.info(f"Extracting netlist from: {os.path.basename(schematic_path)}")
        
        # Extract netlist information
        try:
            netlist_data = extract_netlist(schematic_path)
            
            if "error" in netlist_data:
                print(f"Error extracting netlist: {netlist_data['error']}")
                if ctx:
                    ctx.info(f"Error extracting netlist: {netlist_data['error']}")
                return {"success": False, "error": netlist_data['error']}
            
            if ctx:
                await ctx.report_progress(40, 100)
            
            # Advanced connection analysis
            if ctx:
                ctx.info("Performing connection analysis...")
            
            analysis = {
                "component_count": netlist_data["component_count"],
                "net_count": netlist_data["net_count"],
                "component_types": {},
                "power_nets": [],
                "signal_nets": [],
                "potential_issues": []
            }
            
            # Analyze component types
            components = netlist_data.get("components", {})
            for ref, component in components.items():
                # Extract component type from reference (e.g., R1 -> R)
                import re
                comp_type_match = re.match(r'^([A-Za-z_]+)', ref)
                if comp_type_match:
                    comp_type = comp_type_match.group(1)
                    if comp_type not in analysis["component_types"]:
                        analysis["component_types"][comp_type] = 0
                    analysis["component_types"][comp_type] += 1
            
            if ctx:
                await ctx.report_progress(60, 100)
            
            # Identify power nets
            nets = netlist_data.get("nets", {})
            for net_name, pins in nets.items():
                if any(net_name.startswith(prefix) for prefix in ["VCC", "VDD", "GND", "+5V", "+3V3", "+12V"]):
                    analysis["power_nets"].append({
                        "name": net_name,
                        "pin_count": len(pins)
                    })
                else:
                    analysis["signal_nets"].append({
                        "name": net_name,
                        "pin_count": len(pins)
                    })
            
            if ctx:
                await ctx.report_progress(80, 100)
            
            # Check for potential issues
            # 1. Nets with only one connection (floating)
            for net_name, pins in nets.items():
                if len(pins) <= 1 and not any(net_name.startswith(prefix) for prefix in ["VCC", "VDD", "GND", "+5V", "+3V3", "+12V"]):
                    analysis["potential_issues"].append({
                        "type": "floating_net",
                        "net": net_name,
                        "description": f"Net '{net_name}' appears to be floating (only has {len(pins)} connection)"
                    })
            
            # 2. Power pins without connections
            # This would require more detailed parsing of the schematic
            
            if ctx:
                await ctx.report_progress(90, 100)
            
            # Build result
            result = {
                "success": True,
                "schematic_path": schematic_path,
                "analysis": analysis
            }
            
            # Complete progress
            if ctx:
                await ctx.report_progress(100, 100)
                ctx.info("Connection analysis complete")
            
            return result
            
        except Exception as e:
            print(f"Error analyzing connections: {str(e)}")
            if ctx:
                ctx.info(f"Error analyzing connections: {str(e)}")
            return {"success": False, "error": str(e)}
  • Invocation of register_netlist_tools(mcp) during server setup, which defines and registers the analyze_schematic_connections tool via @mcp.tool() decorator.
    register_netlist_tools(mcp)

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