feat: add footprint + symbol creator tools
Footprint tools: - create_footprint: generates .kicad_mod via f-string (SMD/THT, courtyard, silkscreen, fab) - edit_footprint_pad: updates size/position/drill/shape in-place - list_footprint_libraries: scans .pretty directories - register_footprint_library: adds entry to fp-lib-table Symbol tools: - create_symbol: generates .kicad_sym with pins, rectangles, polylines - delete_symbol: removes symbol from library - list_symbols_in_library: lists all symbols in a .kicad_sym file - register_symbol_library: adds entry to sym-lib-table Also: - Fix footprint format version: 20250114 (schematic) -> 20241229 (footprint) - Two MCP prompts: create_footprint_guide + footprint_ipc_checklist Live tested: TMC2209 footprint (19 pads), R_0603_Test, edit_footprint_pad, TMC2209_Custom symbol with pins all confirmed in KiCAD 9
This commit is contained in:
137
src/prompts/footprint.ts
Normal file
137
src/prompts/footprint.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Footprint prompts for KiCAD MCP server
|
||||
*
|
||||
* Guides Claude in creating and editing KiCAD footprints (.kicad_mod)
|
||||
* using the create_footprint, edit_footprint_pad, and list_footprint_libraries tools.
|
||||
*/
|
||||
|
||||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||
import { z } from "zod";
|
||||
import { logger } from "../logger.js";
|
||||
|
||||
export function registerFootprintPrompts(server: McpServer): void {
|
||||
logger.info("Registering footprint prompts");
|
||||
|
||||
// ------------------------------------------------------
|
||||
// Create Footprint Prompt
|
||||
// ------------------------------------------------------
|
||||
server.prompt(
|
||||
"create_footprint_guide",
|
||||
{
|
||||
component: z
|
||||
.string()
|
||||
.describe(
|
||||
"Component description, e.g. 'SOT-23 NPN transistor' or '2-pin JST XH 2.5mm connector'",
|
||||
),
|
||||
libraryPath: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe("Target .pretty library path (optional)"),
|
||||
},
|
||||
() => ({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: {
|
||||
type: "text",
|
||||
text: `You are a KiCAD footprint expert. Create a correct KiCAD 9 footprint using the create_footprint tool.
|
||||
|
||||
## Component to footprint
|
||||
{{component}}
|
||||
|
||||
## Library path
|
||||
{{libraryPath}}
|
||||
|
||||
## Rules for correct footprints
|
||||
|
||||
### Coordinate system
|
||||
- Origin (0,0) is the footprint anchor, typically the centre of the pad pattern.
|
||||
- X increases to the right, Y increases downward (same as KiCAD screen).
|
||||
- All values in millimetres.
|
||||
|
||||
### SMD pads
|
||||
- type: "smd"
|
||||
- Default layers: ["F.Cu", "F.Paste", "F.Mask"]
|
||||
- No drill needed.
|
||||
- Common shapes: "rect" for square/rectangular, "roundrect" for ICs.
|
||||
|
||||
### THT pads
|
||||
- type: "thru_hole"
|
||||
- Default layers: ["*.Cu", "*.Mask"]
|
||||
- drill required (round = scalar, oval = {w, h}).
|
||||
- Pad 1 is typically square (rect), remaining pads are circle.
|
||||
|
||||
### Courtyard (F.CrtYd)
|
||||
- Add 0.25 mm clearance around the outermost extent of pads.
|
||||
- Line width: 0.05 mm.
|
||||
|
||||
### Silkscreen (F.SilkS)
|
||||
- Shows the component body outline, typically slightly inside the courtyard.
|
||||
- Line width: 0.12 mm.
|
||||
- Must not overlap pads.
|
||||
|
||||
### Fab layer (F.Fab)
|
||||
- Shows the realistic component outline with pin-1 marker.
|
||||
- Line width: 0.10 mm.
|
||||
|
||||
### Reference text
|
||||
- Place "REF**" above the courtyard (negative Y = above).
|
||||
- Value text below the courtyard (positive Y = below).
|
||||
|
||||
## Workflow
|
||||
1. Calculate pad positions from datasheet pitch and land pattern.
|
||||
2. Call create_footprint with pads[], courtyard, silkscreen, fabLayer.
|
||||
3. Verify with edit_footprint_pad if any correction is needed.
|
||||
|
||||
## Common packages quick reference
|
||||
| Package | Pitch | Pad size (SMD) | Notes |
|
||||
|-----------|--------|------------------|------------------------------|
|
||||
| 0402 | 1.0 mm | 0.6 × 0.7 mm | Very small, min 0.5 mm drill |
|
||||
| 0603 | 1.6 mm | 1.0 × 1.0 mm | Standard small passive |
|
||||
| 0805 | 2.0 mm | 1.4 × 1.2 mm | Easy to hand-solder |
|
||||
| SOT-23 | 0.95 mm| 1.0 × 1.3 mm | 3-pin, 2 on one side |
|
||||
| SOT-23-5 | 0.95 mm| 0.6 × 1.0 mm | 5-pin |
|
||||
| SOIC-8 | 1.27 mm| 1.6 × 0.6 mm | 4 pins each side |
|
||||
| DIP-8 | 2.54 mm| dia 1.6, drill 0.8| THT, 100 mil grid |
|
||||
|
||||
Now create the footprint for: {{component}}`,
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
// ------------------------------------------------------
|
||||
// Footprint IPC Checklist Prompt
|
||||
// ------------------------------------------------------
|
||||
server.prompt(
|
||||
"footprint_ipc_checklist",
|
||||
{
|
||||
footprintPath: z
|
||||
.string()
|
||||
.describe("Path to the .kicad_mod file to review"),
|
||||
},
|
||||
() => ({
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: {
|
||||
type: "text",
|
||||
text: `Review the footprint at {{footprintPath}} against IPC-7351 land pattern guidelines.
|
||||
|
||||
Check:
|
||||
1. **Pad size** – is the copper area sufficient for soldering (not undersized)?
|
||||
2. **Courtyard** – at least 0.25 mm clearance around all pads?
|
||||
3. **Silkscreen** – does it overlap pads? (it should NOT)
|
||||
4. **Pad 1 marker** – is pin 1 identifiable (square pad or triangle on silkscreen)?
|
||||
5. **Drill size** – for THT: drill ≥ lead diameter + 0.3 mm?
|
||||
6. **Layer assignments** – SMD pads: F.Cu/F.Paste/F.Mask; THT: *.Cu/*.Mask?
|
||||
7. **Anchor** – is the origin centred on the pad pattern?
|
||||
|
||||
Use edit_footprint_pad to fix any issues found.`,
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
/**
|
||||
* Prompts index for KiCAD MCP server
|
||||
*
|
||||
* Exports all prompt registration functions
|
||||
*/
|
||||
|
||||
export { registerComponentPrompts } from './component.js';
|
||||
export { registerRoutingPrompts } from './routing.js';
|
||||
export { registerDesignPrompts } from './design.js';
|
||||
/**
|
||||
* Prompts index for KiCAD MCP server
|
||||
*
|
||||
* Exports all prompt registration functions
|
||||
*/
|
||||
|
||||
export { registerComponentPrompts } from "./component.js";
|
||||
export { registerRoutingPrompts } from "./routing.js";
|
||||
export { registerDesignPrompts } from "./design.js";
|
||||
export { registerFootprintPrompts } from "./footprint.js";
|
||||
|
||||
Reference in New Issue
Block a user