feat: add connected_pin_count to list_schematic_nets and list_floating_labels tool

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Eugene Mikhantyev
2026-04-12 15:46:32 +01:00
parent e826cf3d32
commit 4895bf169c
5 changed files with 786 additions and 1 deletions

View File

@@ -660,7 +660,9 @@ Note: operates on .kicad_sch files only. To modify a PCB footprint use edit_comp
}
const lines = nets.map((n: any) => {
const conns = (n.connections || []).map((c: any) => `${c.component}/${c.pin}`).join(", ");
return ` ${n.name}: ${conns || "(no connections)"}`;
const pinCount =
n.connected_pin_count !== undefined ? ` [${n.connected_pin_count} pin(s)]` : "";
return ` ${n.name}${pinCount}: ${conns || "(no connections)"}`;
});
return {
content: [
@@ -1361,6 +1363,38 @@ Note: operates on .kicad_sch files only. To modify a PCB footprint use edit_comp
},
);
// List floating net labels
server.tool(
"list_floating_labels",
"Returns all net labels in the schematic that are not connected to any component pin. " +
"A label is 'floating' when no component pin falls on the wire-network reachable from the " +
"label's position. Floating labels indicate misplaced or off-grid labels that cause ERC errors. " +
"Does not require the KiCAD UI to be running.",
{
schematicPath: z.string().describe("Path to the .kicad_sch schematic file"),
},
async (args: { schematicPath: string }) => {
const result = await callKicadScript("list_floating_labels", args);
if (result.success) {
const labels: any[] = result.floating_labels || [];
if (labels.length === 0) {
return { content: [{ type: "text", text: "No floating labels found." }] };
}
const lines: string[] = [`Found ${labels.length} floating label(s):\n`];
labels.slice(0, 50).forEach((lbl: any) => {
lines.push(` "${lbl.name}" (${lbl.type}) at (${lbl.x}, ${lbl.y})`);
});
if (labels.length > 50) {
lines.push(` ... and ${labels.length - 50} more`);
}
return { content: [{ type: "text", text: lines.join("\n") }] };
}
return {
content: [{ type: "text", text: `Failed: ${result.message || "Unknown error"}` }],
};
},
);
// Find orphaned wires
server.tool(
"find_orphaned_wires",