Repository avatar
Other Tools
v0.1.0a1
active

kicad-placement-mcp

io.github.cvaldess/kicad-placement-mcp

Places and orients the passives of a KiCad board around your anchors, then applies it in KiCad.

Documentation

kicad-placement-mcp

Component placement for KiCad boards, as an MCP server for Claude (or any MCP client) and as a command-line tool.

You and the assistant decide the structure of the board: zones, anchors (connectors, ICs, anything you place by hand) and the design intent that the netlist does not show. The tool does the tedious, error-prone part deterministically:

  • measure a placement: overlaps, copper too close to the edge, pads on vias or tracks of other nets, parts in keepout areas, decoupling capacitors whose own pad blocks the route to their pin, IC power pins without a decoupling capacitor, isolation barriers, your constraints, and wire length (HPWL);
  • place the 2-pad passives (R, C, L, D, LED, ferrite beads, fuses) around the anchors, or, in conservative mode, fix only what is wrong in a placement done by hand;
  • orient the passives (90° steps) so that their pads face their nets and do not block the routes;
  • apply the proposal to the board open in KiCad, through the official IPC API, in one undoable commit.

It never edits a .kicad_pcb file: it reads it with its own parser and writes only through KiCad.

Status: alpha (0.1.0a1). It has been used on about ten real boards, two of them public (in tests/data). Expect wrong placements: please report them. Read the limitations before trusting a proposal, and always review the result and run DRC before routing.

Install

Python 3.12 or newer.

pip install --pre kicad-placement-mcp

This installs both the MCP server (kicad-placement-mcp) and the command-line tool (kicad-placement). With uv you can skip the install and register uvx kicad-placement-mcp instead.

Register the MCP server

Claude Code:

claude mcp add -s user kicad-placement -- kicad-placement-mcp

Claude Desktop or other clients (claude_desktop_config.json or equivalent):

{
  "mcpServers": {
    "kicad-placement": { "command": "kicad-placement-mcp" }
  }
}

If kicad-placement-mcp is not on the client's PATH, give the full path of the script, or run the module with the Python of your environment: "command": "C:\\path\\to\\.venv\\Scripts\\python.exe", "args": ["-m", "kicad_placement.mcp_server"].

apply changes the board open in KiCad. It is marked as destructive, so clients ask before running it; in Claude Code you can make sure with "permissions": {"ask": ["mcp__kicad-placement__apply"]} in ~/.claude/settings.json.

Docker (MCP Toolkit)

The server is also published as an image. Mount the folder with your boards; the tools see it as /boards:

docker run -i --rm -v /path/to/boards:/boards ghcr.io/cvaldess/kicad-placement-mcp:latest

In Docker Desktop's MCP Toolkit you can add it to a catalog of your own with docker mcp catalog create <your-catalog> --server docker://ghcr.io/cvaldess/kicad-placement-mcp:latest. It is also listed in the MCP Registry as io.github.cvaldess/kicad-placement-mcp.

From a container, apply cannot reach KiCad's IPC socket on Windows or macOS: use the container for measure, place and orient, and a local install (above) to apply.

Enable the KiCad IPC API (only for apply)

KiCad 9 or newer. In KiCad: Preferences → Plugins → Enable KiCad API, then open the board in the PCB editor (the project manager alone does not serve it). apply connects to the default socket; pass --socket (CLI) if yours is different.

How to use it

Ask the assistant in plain words, for example "measure my board", "place the passives around U3 and U5", "fix what is wrong in my placement without moving the rest" (conservative), "apply it". The tools:

ToolWhat it doesTouches the board?
measuremetrics and problems of the current placementno
placeproposes positions for the movable passives (movable, or all 2-pad passives that are not anchors); conservative keeps what already compliesno
orientproposes rotations onlyno
applytakes the last proposal to the board open in KiCad, in one commit (one Ctrl+Z); does not saveyes

Every call writes its result next to the board, in placement/: <board>.measure.json, <board>.place.json, <board>.orient.json and a .png view of each (overwritten each time). The JSON of place says, for each part, where it was, where it goes, how far it moves and why ("decoupling of U3:16", "next to the control pin Q2:1", "stays: already complies where it is"…), plus a before/after summary.

Before applying, apply checks that the open board matches the file that was measured, part by part; afterwards it reads the pads back and checks that every footprint is unchanged except for its position. If anything differs it says so and reports ok: false. Parts with tracks connected are refused unless you force it (the routing would be left behind).

Command line

The same actions, without an assistant:

kicad-placement measure board.kicad_pcb --png view.png --json measure.json [--rules rules.json]
kicad-placement place   board.kicad_pcb --json place.json [--movable C1,C2,R5] [--conservative] [--rules rules.json]
kicad-placement orient  board.kicad_pcb --json orient.json [--only C8,C10]
kicad-placement apply   board.kicad_pcb place.json        # to the board open in KiCad

On Windows, run Python with -X utf8 if the console shows mangled characters.

Rules

The design intent goes in placement/<board>.rules.json, next to the board (or --rules). Everything is optional. Distances are in mm, edge to edge (courtyard ∪ pads); in constraints and exemptions, references accept * and ? wildcards; "U2:31" means pad 31 of U2.

{
  "anchors": ["C1", "R5"],
  "movable": ["TP3"],
  "decoupling": {"C8": "U3:16"},
  "decoupling_exempt": ["U10:5"],
  "overlap_exempt": ["J7", "J2–J3"],
  "edge_exempt": ["J1"],
  "edge_mm": 0.5,
  "constraints": [
    {"type": "near", "a": "C19", "b": "D3", "max": 1.5, "source": "input protection next to the connector"},
    {"type": "separate", "a": ["J7:1", "J7:2"], "b": ["*"], "min": 2.0},
    {"type": "outside", "footprint": "J7", "margin": 0.5, "except": ["J1"]},
    {"type": "outside", "rect": [10, 20, 40, 35], "refs": ["C*", "R*"]},
    {"type": "zone", "refs": ["R1?"], "rect": [50, 10, 70, 30]},
    {"type": "edge", "ref": "J1", "edge": "left", "max": 1.0},
    {"type": "side", "ref": "U4", "side": "F"},
    {"type": "barrier", "dru": "barrera_tc", "min": 3.6, "nets": ["/GND_TC", "/+3V3_TC"], "footprints": ["U2"]}
  ]
}
KeyMeaning
anchors2-pad passives that must not move (exact references). Parts locked in KiCad and everything that is not a 2-pad passive are anchors already
movableextra parts that may move (exact references: test points, net ties…)
decouplingties a capacitor to a pin; overrides the automatic assignment (also valid on signal nets: RC filters)
decoupling_exemptpower pins that do not need a capacitor next to them (the datasheet says so: e.g. an eFuse output)
overlap_exemptparts, or pairs "A–B" / ["A", "B"], whose overlaps are intended
edge_exempt, edge_mmparts allowed past the edge clearance, and the clearance (0.5 mm)
neara within max of b
separatecopper of a at least min from copper of b
outsidenothing (or refs, minus except) inside a rectangle [x0, y0, x1, y1] or a footprint's courtyard, plus margin
zonerefs inside the rectangle
edgeref within max of the board edge top/bottom/left/right
sideref on side F or B
barrierisolation between two domains: the nets, footprints and net classes of one side keep min from the rest; dru names the .kicad_dru rule it comes from

source (or _note) is free text for you. If the .kicad_dru has an isolation clearance that no barrier covers, measure warns and place refuses (unless forced): the proposal would not respect it.

Keepout areas drawn in KiCad, vias, tracks and copper zones are read from the board; they need no rules.

Limitations

  • One side: only parts on their current side are placed; parts are not flipped.
  • Anchors are not placed: connectors, ICs, crystals and anything not a 2-pad passive stay where you put them.
  • Test points need a rule to move.
  • Rotations in 90° steps only.
  • Notes that depend on routing (keep away from a trace, Kelvin connections, differential pairs) are not modelled.
  • Decoupling capacitors are assigned by geometry and pin types; bulk capacitors also by the schematic. Ambiguous cases are reported and need a decoupling rule.
  • No RF awareness.
  • A full placement of a 150-part board takes a few minutes.

See DESIGN.md for how it works and why.

Reporting a failure

Any placement you consider wrong is a failure of the tool or of the rules, and the most useful contribution you can make. Please open an issue with the Placement failure form and include:

  • what you asked (tool and options, or the assistant's call) and the version (pip show kicad-placement-mcp);
  • the part(s) and what is wrong, and where you would put them and why (a datasheet note, a layout rule of thumb);
  • the placement/<board>.<action>.json and .png, and your rules.json;
  • the board files if you can share them (.kicad_pcb, .kicad_pro, .kicad_dru, .kicad_sch). A failure that comes with its board becomes a regression test; if the board is private, a minimal board that shows the same failure works just as well.

Crashes and wrong measurements go in a Bug report. If you use the assistant, ask it to draft the issue: it has the JSON at hand.

Development

git clone https://github.com/cvaldess/kicad-placement-mcp
cd kicad-placement-mcp
python -m venv .venv
.venv/bin/pip install -e ".[test]"       # Windows: .venv\Scripts\pip
.venv/bin/python -m pytest -q

The tests do not need KiCad, except tests/test_apply.py, which runs KiCad 11 nightly in Docker and is skipped if the image is missing:

docker build -t kicad-placement-kicad:nightly-YYYYMMDD -f docker/kicad-nightly.Dockerfile docker
docker build -t kicad-placement-test:nightly-YYYYMMDD -f docker/test.Dockerfile docker

(Set IMAGE in tests/test_apply.py to your tag.) Read CONTRIBUTING.md before a pull request: every change of criterion comes with a test on a real board.

License

GPL-3.0-or-later, like KiCad. The test boards in tests/data are CERN-OHL-S-2.0 (NOTICE).

This project is not affiliated with or endorsed by the KiCad project.

PYPI
kicad-placement-mcp
Install Command
pip install kicad-placement-mcp
OCI
ghcr.io/cvaldess/kicad-placement-mcp:0.1.0a1
Install Command
docker pull ghcr.io/cvaldess/kicad-placement-mcp:0.1.0a1:undefined