feat: add find_orphaned_wires schematic analysis tool

Detects wire segments with at least one dangling endpoint — an endpoint
not connected to a component pin, net label, or another wire.  These
cause ERC 'wire end unconnected' violations and are a common symptom of
incomplete routing or stray stub wires.

Algorithm uses exact KiCad IU (10 000 IU/mm) coordinate matching,
consistent with wire_connectivity.py:
  1. Build an endpoint-frequency map for all wires (IU precision)
  2. Collect anchored IU points: component pins (via PinLocator),
     net labels / global_labels, power symbol pins
     (via _parse_virtual_connections)
  3. An endpoint is dangling when it is touched by exactly one wire AND
     is not an anchored point; the containing wire is reported

Does not require the KiCad UI to be running.

Changes:
  python/commands/schematic_analysis.py — find_orphaned_wires() function
  python/kicad_interface.py             — handler + route registration
  python/schemas/tool_schemas.py        — MCP schema entry
  src/tools/schematic.ts                — TypeScript server.tool() call
  tests/test_schematic_analysis.py      — 7 integration tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Eugene Mikhantyev
2026-04-12 14:44:12 +01:00
parent 94b234a36e
commit 58bb08a252
5 changed files with 311 additions and 0 deletions

View File

@@ -1794,6 +1794,26 @@ SCHEMATIC_TOOLS = [
"required": ["schematicPath"],
},
},
{
"name": "find_orphaned_wires",
"title": "Find Orphaned Wires",
"description": (
"Find wire segments with at least one dangling endpoint — an endpoint not connected "
"to a component pin, net label, or another wire. "
"Orphaned wires cause ERC 'wire end unconnected' errors and indicate routing mistakes. "
"Does not require the KiCad UI to be running."
),
"inputSchema": {
"type": "object",
"properties": {
"schematicPath": {
"type": "string",
"description": "Path to the .kicad_sch schematic file",
}
},
"required": ["schematicPath"],
},
},
]
# =============================================================================