feat: add get_schematic_view tool for rasterized schematic images

Exports schematic to SVG via kicad-cli, then converts to PNG using
cairosvg (same approach as get_board_2d_view). Falls back gracefully
to SVG if cairosvg is not installed. Supports configurable output
size and format (png/svg).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Eugene Mikhantyev
2026-03-12 23:57:39 +00:00
parent b2a547e624
commit 72e5320044
3 changed files with 128 additions and 0 deletions

View File

@@ -888,6 +888,61 @@ Note: operates on .kicad_sch files only. To modify a PCB footprint use edit_comp
},
);
// Get schematic view (rasterized image)
server.tool(
"get_schematic_view",
"Return a rasterized image of the schematic (PNG by default, or SVG). Uses kicad-cli to export SVG, then converts to PNG via cairosvg. Use this for visual feedback after placing or wiring components.",
{
schematicPath: z.string().describe("Path to the .kicad_sch file"),
format: z
.enum(["png", "svg"])
.optional()
.describe("Output format (default: png)"),
width: z.number().optional().describe("Image width in pixels (default: 1200)"),
height: z.number().optional().describe("Image height in pixels (default: 900)"),
},
async (args: {
schematicPath: string;
format?: "png" | "svg";
width?: number;
height?: number;
}) => {
const result = await callKicadScript("get_schematic_view", args);
if (result.success) {
if (result.format === "svg") {
return {
content: [
{
type: "text",
text: result.message
? `SVG data returned (${result.message})`
: `SVG schematic view (${result.imageData?.length || 0} chars)`,
},
],
};
}
// PNG — return as base64 image
return {
content: [
{
type: "image" as const,
data: result.imageData,
mimeType: "image/png",
},
],
};
}
return {
content: [
{
type: "text",
text: `Failed to get schematic view: ${result.message || "Unknown error"}`,
},
],
};
},
);
// Run Electrical Rules Check (ERC)
server.tool(
"run_erc",