kicad-mcp-layer
CLAUDE.md2 starsChanged 3 months agoMITView on GitHub
An MCP server (official mcp 2.x SDK, Python 3.12) that drives KiCad 10 through kicad-cli, KiCad's IPC API (kicad-python) and direct file edits. * Never import the SWIG pcbnew module. tests/test_swig_guard.py fails the build if you do. * Never print to stdout. The server runs on stdio; log to stderr with logging. * Every path a tool accepts goes through kicad_layer.paths.resolve_in_workspace. * Anticipated failures are LayerError(code, message, hint=...). Codes are listed in errors.py and docs/tools.md. Never signal failure with a…
The file
We split this CLAUDE.md into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Never import the SWIG pcbnew module.
- Very specific: line 9
Never print to stdout. The server runs on stdio.
- Very specific: line 10
Every path a tool accepts goes through kicad_layer.paths.resolve_in_workspace.
- Very specific: line 49
Ask a built board through python -m kicad_layer.design.inspect <build> parts|part|net|pin|classes|drc|unrouted|bbox, not through a …
≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
kicad-mcp-layer: working notes for Claude Code
An MCP server (official mcp 2.x SDK, Python 3.12) that drives KiCad 10 through
kicad-cli, KiCad's IPC API (kicad-python) and direct file edits.
Ground rules
- Never import the SWIG
pcbnewmodule.tests/test_swig_guard.pyfails the build if you do. - Never print to stdout. The server runs on stdio; log to stderr with
logging. - Every path a tool accepts goes through
kicad_layer.paths.resolve_in_workspace. - Anticipated failures are
LayerError(code, message, hint=...). Codes are listed inerrors.pyanddocs/tools.md. Never signal failure with a{"success": false}dict. - A check that produced no report is
UNVERIFIED, neverPASS. - Design edits require
require_write_mode()and, for schematics, refuse while a~name.kicad_sch.lckfile exists. - Connectivity comes from
kicad-cli sch export netlist, never from wire tracing. - The KiCad file formats the writers emit live in
formats.pyonly. The layer is built against KiCad 10.0.6; a KiCad upgrade is deliberate: full suite after, doctor's advice read.kicad-pythonis theipcextra.
Layers
kicad_layer.designis the product: a board as data, the KiCad files as build outputs. It may import only the core (sexpr,ids,kicad_libs,libtables,paths,config,errors,models,cli/), the two writers androutes.tests/test_layers.pyenforces it.- The MCP server is the check-and-view layer.
KICAD_LAYER_TOOLSpicks the tier:core(default: checks, exports, renders, reviews, libraries, documents, board reads) orfull(plus design edits and the routers). kicad_layer.routersis frozen: fixes, not features, and onlytools.pyimports it. The intended loop routes by hand in KiCad and captures the copper as data (routes.py).
Layout
src/kicad_layer/tools.pydeclares every MCP tool, one registrar per group; implementation lives incli/,ipc/,routers/,project.py,doctor.py,capabilities.pyand is testable without MCP. The design package isdesign/; the copper data model isroutes.py.models.pyholds every output schema. Add fields; do not rename them.GROUPSintools.py(one registrar per group), the table indocs/tools.mdwith its tier column and thecoveredrows incapabilities.pymust agree;tests/test_registry.pychecks.
Context: what a session reads
Measured over the first two boards (shares of about 680k tokens of tool results): reading library source and project sheets 14%, scratch Python (board and schematic questions, PDFs, memory patches) 20%, images 14%, builds, tests and routing runs 15%, web search and fetch 8%, logs 4%, the MCP tools under 2%. Run the script after a board and compare. So:
- To write or change a sheet, a board or a project, read
docs/design-api.md(generated, about 7k tokens), never the source. Open a source file only to change the library.python -m kicad_layer.design.apiregenerates the sheet;tests/test_design_api.pyfails when it is stale. - Ask a built board through
python -m kicad_layer.design.inspect <build> parts|part|net|pin|classes|drc|unrouted|bbox, not through a one-liner. Add a question there when one recurs. Placing a part or adding copper is a question too:region(what is there),freeandspots(does or where does a part fit),clearandclear-via(does a candidate track or via keep every clearance, and what it hits if not). Never dump coordinates and do the arithmetic in the session. - Datasheets and reference designs: fetch once into the document library (
doc_fetch). Askdoc_factsfirst: a part's sheet inresearch/parts/answers pins, limits, values, circuit and package with pages at about a hundred tokens a section. No sheet yet: have a subagent write it (doc_sectionsfor the pages,doc_textwith those pages,doc_pageto check every table against the picture; the CLIpython -m kicad_layer.docsgives it the same without the server) and keep only the sheet. Never page through a PDF in the main session;doc_textwithfindreturns merged match windows only,pagesreads one page around a hit. - Renders and plots cost about a thousand tokens each; look once, at the crop you need.
Design package (src/kicad_layer/design)
- A project is data on it: sheets, placement, a
Project, aRoutingPlanforrouters.pipelineand the PCBWay package fromdesign/fab.py. A part added to a sheet needs no coordinates:Place(ref, at, rot, near=(REF, PAD))lets the build find the nearest place that fits (recorded inrouting/placed.json), andbuild.py --route-stubsroutes what the DRC leaves open on single-ended nets over the copper model, then builds again. Boards build on it; after a change runtests/test_design*.py, then a board'sbuild.py --sch-only --out <scratch>and compare with the previous build byte for byte. - Long patch scripts go through a file, not an inline heredoc (the shell drops commands over ~8 KB).
Tests
.venv\Scripts\python -m pytest # the fast loop: parallel, no slow, no live tests (about 30 s)
.venv\Scripts\python -m pytest -m "not gui" # plus the slow tests; run this before a commit
.venv\Scripts\python -m pytest -m "" # everything; needs KiCad open with the API onA test that takes more than ten seconds is marked slow. Keep the default run short.
tests/test_cli_live.py runs real kicad-cli on the fixture corpus in tests/fixtures/
(KiCad demo projects upgraded to the 10.0 formats) and self-skips without kicad-cli.
Fixtures must stay KiCad-authored; never hand-write one.
Decisions
The architecture decision record is ../research/notes/00-design-inputs.md in the author's workspace (not
published). Read it before changing how a channel works, when you have it.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

