klayout-draw-mcp
The klayout-draw-mcp server enables AI assistants to programmatically create, edit, inspect, and validate GDS/OASIS chip layouts using KLayout's Python API.
Layout Management
Create new layouts (
new_layout) with a named top cell and configurable database unitLoad existing GDS/OASIS files (
load_gds) for editing or inspectionSave layouts (
save_gds) to GDS/OASIS format with optional auto-open in KLayoutInspect layouts (
layout_info,inspect_gds) for per-layer shape counts, areas, bounding boxes, and cell lists
Drawing Primitives
Add rectangles (
add_box), polygons (add_polygon), paths (add_path), and text labels (add_label) on specified layers
Advanced Layout Construction
Create and manage cells (
create_cell,use_cell) and place instances or arrays (place_cell) with rotation/mirroringAdd vias (
add_via) — cut arrays with enclosing metal on both connected layersAdd Manhattan wires (
add_wire) — axis-aligned wires with automatic L-corner insertion
Design Rule Checking
Run DRC checks (
drc_check) for spacing, width, overlap, separation, and enclosure rules, reporting violations
GUI Integration
Open layouts in KLayout viewer (
open_layout) or editor mode (open_editor)
Scripting & Extensibility
Execute arbitrary Python code (
run_script) with full access toklayout.dbfor boolean geometry, custom DRC, cell hierarchies, and other advanced operations
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@klayout-draw-mcp draw a 10um square on layer 1 and save as out.gds"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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 |
Related MCP server: KiCad MCP Server
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.
Available Tools
18 toolsadd_boxC
Add a rectangle (micrometers) on GDS layer/datatype.
Inputs: x1 (required), x2 (required), y1 (required), y2 (required), +2 more. Returns: result
add_labelC
Add a text label at (x, y) micrometers.
Inputs: x (required), y (required), text (required), layer (required), +1 more. Returns: result
add_pathC
Add a path: centerline [x, y] points (micrometers) with the given width.
Inputs: layer (required), width (required), points (required), datatype. Returns: result
add_polygonC
Add a polygon from a list of [x, y] vertices (micrometers).
Inputs: layer (required), points (required), datatype. Returns: result
add_viaA
Add a via (cut array + enclosing metal on both layers) centred at (x, y).
Builds a rows*cols array of cuts (cut_size, spaced by cut_space) on cut_layer
and a metal landing on bottom_layer and top_layer extended by enclosure
around the cut array. All dimensions in micrometers.
Inputs: x (required), y (required), cut_layer (required), top_layer (required), +9 more. Returns: result
add_wireA
Add a Manhattan wire: routes through points inserting L-corners so every
segment is axis-aligned. horizontal_first chooses the corner direction at each
dog-leg. For layer changes, drop an add_via at the turn. Coordinates in um.
Inputs: layer (required), width (required), points (required), datatype, +1 more. Returns: result
create_cellA
Create (or select) a cell and make it the active drawing target.
Subsequent add_box / add_polygon / add_via / add_wire / place_cell calls go into
this cell. Use it to build a reusable library cell, then use_cell back to the
top and place_cell to instance it. Returns to the top cell with use_cell(top).
Inputs: name (required). Returns: result
drc_checkA
Run simple DRC rules against a layout and report violations.
Operates on path if given, else the current session. Each rule is a dict
(datatype defaults to 0, distances in micrometers):
{"type": "spacing", "layer": L, "datatype": D, "min": um} {"type": "width", "layer": L, "datatype": D, "min": um} {"type": "overlap", "layer": L, "datatype": D, "layer2": L2, "datatype2": D2} {"type": "separation", "layer": L, "datatype": D, "layer2": L2, "datatype2": D2, "min": um} {"type": "enclosure", "layer": L, "datatype": D, "layer2": L2, "datatype2": D2, "min": um}
"spacing" is min space within a layer; "width" is min feature width;
"overlap" flags any intersection between two layers (forbidden overlap);
"separation" is min space between two layers; "enclosure" requires layer2 to
surround layer by min. Up to max_report violation centres are listed per rule.
Inputs: rules (required), path, top_cell, max_report. Returns: result
inspect_gdsA
Inspect a layout: per-layer shape count, area and bbox, plus the cell list.
With path: inspect that file without touching the session. Without it:
inspect the current in-memory session. Areas use merged geometry (so
overlaps are not double-counted); coordinates are in micrometers.
Inputs: path, top_cell. Returns: result
layout_infoA
Report the current layout: top cell, dbu, layers, bbox, shape count.
Inputs: no named parameters. Returns: result
load_gdsA
Load an existing GDS/OASIS file into the active session for editing.
After loading, keep adding shapes (add_box / add_polygon / ...), inspect or
DRC-check it, then save_gds() to write it back. top_cell selects the cell
to edit (defaults to the first top cell). Replaces any current in-memory layout.
Inputs: path (required), top_cell. Returns: result
new_layoutA
Start a new in-memory layout to draw into.
top_cell: name of the top cell. dbu: database unit in micrometers (0.001 = 1 nm grid). Resets any previous in-memory layout.
Inputs: dbu, top_cell. Returns: result
open_editorA
Open KLayout in editor mode (-e). With a file: edit it. Without: a blank layout to draw.
Inputs: file_path. Returns: result
open_layoutB
Open an existing layout file in KLayout (viewer mode).
Inputs: file_path (required). Returns: result
place_cellB
Place an instance (or nx*ny array) of cell into the active cell.
orient: r0/r90/r180/r270 (rotation) or m0/m90/... (mirror + rotation). For an array, dx/dy are the column/row pitches in micrometers. Coordinates in um.
Inputs: x (required), y (required), cell (required), dx, +5 more. Returns: result
run_scriptA
Execute Python with klayout.db available (advanced).
Injected names: db (klayout.db), klayout, session (current
LayoutSession or None), LayoutSession. stdout is captured and returned.
A script may rebind session to a new LayoutSession to make it the active
layout. Runs locally in-process with full Python access.
Inputs: code (required). Returns: result
save_gdsA
Write the current layout to a file (.gds/.oas by extension). Optionally open it in the editor.
Inputs: path (required), open_after. Returns: result
use_cellB
Switch the active drawing cell to an existing cell (e.g. the top cell).
Inputs: name (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 18 tools
Each tool has a clearly distinct purpose: shape creation (box, label, path, polygon, via, wire), cell management (create_cell, use_cell, place_cell), layout I/O (load_gds, save_gds, new_layout, inspect_gds, layout_info), DRC checking, editor opening, and scripting. No ambiguity between tools.
All tool names follow a consistent verb_noun snake_case pattern (e.g., add_box, load_gds, inspect_gds). No mixed conventions or irregular naming.
18 tools are well-scoped for a GDS layout server, covering drawing, cell hierarchy, file operations, inspection, DRC, and scripting without being excessive or overly sparse.
The tool set covers the main layout workflow: creation, cell management, file operations, DRC, and scripting. Minor gaps like editing or deleting existing shapes are absent, but the core functionality is complete.
Maintenance
Related MCP Connectors
Design, route, check, review and export manufacturable PCBs from plain language; KiCad import.
EasyGerber brings AI printed circuit board (PCB) design, layout, and routing to MCP-compatible assistants. Describe a circuit or start from firmware pin assignments, search published electronic components, and build schematics using catalog parts with their footprints and available 3D models. Create and revise boards, generate layouts with automatic component placement and routing, inspect previews, and check saved layouts for blocking design issues. Export manufacturing ZIPs containing Gerber and drill files, a bill of materials, and component placement data, or download an editable EasyGerber (.egb) file. Start without signing up. Your agent uses one private board reference to create and continue a board, including catalog access, edits, layout, checks, previews, and exports, without a separate guest setup step or token to manage. To keep the board in your account or work with permitted saved personal or organization boards, complete EasyGerber sign-in and OAuth consent, then resume the same task. Account permissions, plan limits, and generation billing apply; support depends on your MCP client and installed integration.
Read, query, edit and render DWG drawings with AI. No AutoCAD required.
Autonomous 0-DRC PCB Routing, RF/DFM Pre-Flight & KiCad MCP Server (calligraphyeda.com).
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI tools to create, edit, and inspect KiCAD schematic files, including components, wires, labels, and sheets.MIT
- AlicenseCqualityDmaintenanceEnables LLMs to inspect, edit, analyze, and render PCB layouts in real-time using the KiCad IPC API, providing tools for board configuration, footprints, tracks, zones, nets, text, shapes, dimensions, exports, screenshots, and CLI automation.1001MIT
- AlicenseAqualityDmaintenanceEnables AI assistants to read and modify KiCAD PCB designs through the KiCAD IPC API, providing tools for board queries, footprint placement, track creation, DRC, and export.14MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with KiCAD for PCB design automation. Users can design PCBs using natural language, including component placement, routing, checks, and export.1MIT