fix: implement export_netlist handler and rewrite generate_netlist to use kicad-cli
export_netlist was returning "Unknown command" because no Python handler
existed. generate_netlist was timing out (30s) due to an O(nets × components
× pins) wire-graph algorithm with a new PinLocator instantiated per net.
Both handlers now delegate to `kicad-cli sch export netlist`:
- export_netlist: new handler; writes KiCad XML / Spice / Cadstar / OrcadPCB2
to the caller-supplied outputPath. Added schematicPath parameter to the TS
tool definition (was absent, making file export impossible).
- generate_netlist: replaces the slow wire-graph with kicad-cli + XML parse;
returns the same {components, nets} JSON the TS handler already expected.
Also adds _find_kicad_cli_static() so both handlers share CLI discovery
without depending on ExportCommands (which requires a loaded pcbnew board).
Cleaned up generate_netlist schema in tool_schemas.py (removed outputPath and
format fields the handler never used), updated MCP tool descriptions and
SCHEMATIC_TOOLS_REFERENCE.md to clearly distinguish the two tools.
26 unit tests added covering parameter validation, subprocess mocking,
format mapping, XML→JSON parsing, and error/timeout propagation.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1654,24 +1654,20 @@ SCHEMATIC_TOOLS = [
|
||||
},
|
||||
{
|
||||
"name": "generate_netlist",
|
||||
"title": "Generate Netlist",
|
||||
"description": "Generates a netlist from the schematic showing all components and their net connections.",
|
||||
"title": "Generate Netlist (JSON)",
|
||||
"description": (
|
||||
"Returns a structured JSON netlist from the schematic: component list "
|
||||
"(reference, value, footprint) and net list (net name + all connected "
|
||||
"component/pin pairs). Uses kicad-cli internally — requires a saved "
|
||||
".kicad_sch file. For writing to a file or exporting SPICE/Cadstar/OrcadPCB2 "
|
||||
"format, use export_netlist instead."
|
||||
),
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"schematicPath": {
|
||||
"type": "string",
|
||||
"description": "Path to schematic file",
|
||||
},
|
||||
"outputPath": {
|
||||
"type": "string",
|
||||
"description": "Optional path to save netlist file",
|
||||
},
|
||||
"format": {
|
||||
"type": "string",
|
||||
"enum": ["kicad", "json", "spice"],
|
||||
"description": "Netlist output format",
|
||||
"default": "json",
|
||||
"description": "Absolute path to the .kicad_sch schematic file",
|
||||
},
|
||||
},
|
||||
"required": ["schematicPath"],
|
||||
|
||||
Reference in New Issue
Block a user