klayout-draw-mcp
klayout-draw-mcp
An MCP server for drawing GDS layouts with KLayout — generate, edit, and view layouts from an AI assistant such as Claude Code or Claude Desktop.
Layout geometry is built in-process with the standalone klayout Python module (no GUI needed). The installed KLayout application is launched only for viewing or manual editing.
Tools
Tool | Purpose |
| Start a new in-memory layout (coordinates in micrometers) |
| Add a rectangle |
| Add a polygon from |
| Add a path with width |
| Add a text label |
| Create/select the active drawing cell |
| Place an instance or array of a cell |
| Via: cut array + enclosing metal |
| Manhattan wire (auto L-corners) |
| Inspect current layout (layers, bbox, shape count) |
| Load an existing GDS/OASIS into the session for editing |
| Per-layer shape count, area and bbox of a file or the session |
| Simple DRC: spacing / width / overlap / separation / enclosure |
| Write GDS/OASIS; optionally open in the editor |
| Open a file in KLayout (viewer) |
| Open KLayout in editor mode, or a blank layout |
| Run arbitrary Python with |
Requirements
Python ≥ 3.10
The
klayoutandmcpPython packages (installed via the steps below)The KLayout application — only needed for
open_layout/open_editor
Install
uv syncRegister with Claude Code
claude mcp add klayout -s user -- "<repo>/.venv/Scripts/python.exe" -m klayout_draw_mcp.serverOn macOS/Linux use .venv/bin/python.
Usage
"Draw a 5×5 µm box on layer 1 and a 2 µm-wide path, then save to out.gds and open it."
Claude calls new_layout → add_box / add_path → save_gds(open_after=True).
You can also open and check an existing layout:
"Load chip.gds, check that M1 spacing ≥ 0.15 µm and that OD never overlaps POLY, and report violations."
Claude calls load_gds → inspect_gds → drc_check([...]), then edits and save_gds.
See Editing & DRC.
For anything beyond the basic shapes, run_script exposes the full klayout.db API.
Examples
Self-contained scripts in examples/. Each builds a layout with the
standalone klayout.db module and writes a GDS:
uv run python examples/cis_aps_pixel.py out.gdsYou can also paste the body of a script's build() function into the run_script
tool. The scripts share one layer map (OD 3/0, POLY 6/0, NPLUS 4/0, METAL1 9/0, ...).
Example | What it draws |
| The four primitives: box, path, polygon, label |
| A single NMOS (active, poly gate, n+, contacts, M1 S/G/D) |
| A CMOS inverter: PMOS over NMOS, shared gate, Vdd/Vss rails |
| A 1 µm 4T CMOS image-sensor pixel, tiled as a 2×2 array |
Place & route skill
skills/klayout-pnr/ packages place-and-route recipes — row placement, power rails, and
an obstacle-aware maze (Lee) router — plus a SKILL.md workflow guide for assistants.
Copy it to your skills directory to have it auto-discovered:
cp -r skills/klayout-pnr ~/.claude/skills/Documentation
Full docs (Getting Started walkthrough, examples, editing/DRC, place & route) are at https://geniuskey.github.io/klayout-draw-mcp/.
Note
run_script executes arbitrary Python locally, in-process. Only run scripts you trust.