Skip to main content
Glama
klayout-draw-mcp

klayout-draw-mcp

by geniuskey

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

new_layout(top_cell, dbu)

Start a new in-memory layout (coordinates in micrometers)

add_box(layer, x1, y1, x2, y2, datatype)

Add a rectangle

add_polygon(layer, points, datatype)

Add a polygon from [x, y] vertices

add_path(layer, points, width, datatype)

Add a path with width

add_label(layer, x, y, text, datatype)

Add a text label

create_cell(name) / use_cell(name)

Create/select the active drawing cell

place_cell(cell, x, y, orient, nx, ny, dx, dy)

Place an instance or array of a cell

add_via(x, y, bottom_layer, top_layer, cut_layer, …)

Via: cut array + enclosing metal

add_wire(layer, points, width)

Manhattan wire (auto L-corners)

layout_info()

Inspect current layout (layers, bbox, shape count)

load_gds(path, top_cell?)

Load an existing GDS/OASIS into the session for editing

inspect_gds(path?)

Per-layer shape count, area and bbox of a file or the session

drc_check(rules, path?)

Simple DRC: spacing / width / overlap / separation / enclosure

save_gds(path, open_after)

Write GDS/OASIS; optionally open in the editor

open_layout(file_path)

Open a file in KLayout (viewer)

open_editor(file_path?)

Open KLayout in editor mode, or a blank layout

run_script(code)

Run arbitrary Python with klayout.db (cell hierarchy, arrays, booleans, DRC, ...)

Related MCP server: KiCad MCP Server

Requirements

  • Python ≥ 3.10

  • The klayout and mcp Python packages (installed via the steps below)

  • The KLayout application — only needed for open_layout / open_editor

Install

uv sync

Register with Claude Code

claude mcp add klayout -s user -- "<repo>/.venv/Scripts/python.exe" -m klayout_draw_mcp.server

On 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 &amp; 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.gds

You 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

basic_shapes.py

The four primitives: box, path, polygon, label

nmos_transistor.py

A single NMOS (active, poly gate, n+, contacts, M1 S/G/D)

cmos_inverter.py

A CMOS inverter: PMOS over NMOS, shared gate, Vdd/Vss rails

cis_aps_pixel.py

A 1 µm 4T CMOS image-sensor pixel, tiled as a 2×2 array

Place &amp; 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 &amp; 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 tools
add_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

    A3.7/5.0

    Scored across 18 tools

    Disambiguation5/5

    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.

    Naming Consistency5/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      C
      quality
      D
      maintenance
      Enables 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.
      100
      1
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables 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.
      14
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to interact with KiCAD for PCB design automation. Users can design PCBs using natural language, including component placement, routing, checks, and export.
      1
      MIT