diff --git a/python/kicad_interface.py b/python/kicad_interface.py index 1ee6bd0..340c721 100644 --- a/python/kicad_interface.py +++ b/python/kicad_interface.py @@ -591,6 +591,7 @@ class KiCADInterface: "export_drill": self._handle_export_drill, "export_ipc2581": self._handle_export_ipc2581, "export_odb": self._handle_export_odb, + "export_ipcd356": self._handle_export_ipcd356, "generate_netlist": self._handle_generate_netlist, "sync_schematic_to_board": self._handle_sync_schematic_to_board, "list_schematic_libraries": self._handle_list_schematic_libraries, @@ -4832,6 +4833,61 @@ class KiCADInterface: logger.error(f"Error exporting ODB++: {e}") return {"success": False, "message": str(e)} + def _handle_export_ipcd356(self, params: Dict[str, Any]) -> Dict[str, Any]: + """Generate an IPC-D-356 netlist file via kicad-cli (`pcb export ipcd356`). + + IPC-D-356 is a bare-board electrical-test netlist consumed by flying-probe + and bed-of-nails testers. Minimal option set (output + input only). Reads + the saved .kicad_pcb. + """ + import subprocess + + logger.info("Exporting IPC-D-356 netlist via kicad-cli") + try: + board_path = params.get("boardPath") or self._current_board_path() + output_path = params.get("outputPath") + + if not board_path: + return { + "success": False, + "message": "boardPath is required (no current board could be resolved)", + } + if not os.path.exists(board_path): + return {"success": False, "message": f"Board not found: {board_path}"} + if not output_path: + return {"success": False, "message": "outputPath is required"} + + kicad_cli = self._find_kicad_cli_static() + if not kicad_cli: + return {"success": False, "message": "kicad-cli not found in PATH"} + + output_path = os.path.abspath(os.path.expanduser(output_path)) + parent = os.path.dirname(output_path) + if parent: + os.makedirs(parent, exist_ok=True) + + cmd = [kicad_cli, "pcb", "export", "ipcd356", "--output", output_path] + cmd.append(board_path) + + logger.info(f"Running: {' '.join(cmd)}") + result = subprocess.run(cmd, capture_output=True, text=True, timeout=180) + + if result.returncode != 0: + return { + "success": False, + "message": f"kicad-cli failed (exit {result.returncode}): " + f"{result.stderr.strip()}", + } + return {"success": True, "outputPath": output_path} + + except FileNotFoundError: + return {"success": False, "message": "kicad-cli not found in PATH"} + except subprocess.TimeoutExpired: + return {"success": False, "message": "kicad-cli timed out after 180 seconds"} + except Exception as e: + logger.error(f"Error exporting IPC-D-356: {e}") + return {"success": False, "message": str(e)} + def _handle_generate_netlist(self, params: Dict[str, Any]) -> Dict[str, Any]: """Generate netlist from schematic and return structured JSON. diff --git a/src/tools/export.ts b/src/tools/export.ts index 8485e43..727beff 100644 --- a/src/tools/export.ts +++ b/src/tools/export.ts @@ -534,5 +534,29 @@ export function registerExportTools(server: McpServer, callKicadScript: CommandF }, ); + // ------------------------------------------------------ + // Export IPC-D-356 Netlist Tool (kicad-cli) + // ------------------------------------------------------ + server.tool( + "export_ipcd356", + "Generate an IPC-D-356 bare-board electrical-test netlist via kicad-cli. Consumed by flying-probe and bed-of-nails testers. Reads the last SAVED state of the .kicad_pcb.", + { + outputPath: z.string().describe("Output .ipc / netlist file path"), + boardPath: z.string().optional().describe("Path to the .kicad_pcb (default: current board)"), + }, + async (args) => { + logger.debug(`Exporting IPC-D-356 netlist to: ${args.outputPath}`); + const result = await callKicadScript("export_ipcd356", args); + return { + content: [ + { + type: "text", + text: JSON.stringify(result), + }, + ], + }; + }, + ); + logger.info("Export tools registered"); } diff --git a/src/tools/registry.ts b/src/tools/registry.ts index 1249961..8b1a6a5 100644 --- a/src/tools/registry.ts +++ b/src/tools/registry.ts @@ -62,6 +62,7 @@ export const toolCategories: ToolCategory[] = [ "export_drill", "export_ipc2581", "export_odb", + "export_ipcd356", "export_pdf", "export_svg", "export_3d",