Skip to content

Tool Reference

Every MCP tool the server exposes, generated from its source. All coordinates are in micrometers; the database grid defaults to dbu = 0.001 (1 nm).

Drawing

KLayout MCP server.

Two complementary ways to produce GDS layouts:

  1. High-level drawing tools (new_layout, add_box, add_polygon, ...) build an in-memory layout step by step using the standalone klayout.db module.
  2. run_script executes arbitrary Python with klayout.db available, for anything the high-level tools do not cover (cell hierarchy, arrays, boolean ops, DRC, ...).

Plus open_layout / open_editor to launch the installed KLayout application for viewing or manual drawing.

All coordinates in the high-level tools are in micrometers.

new_layout

new_layout(top_cell: str = 'TOP', dbu: float = 0.001) -> str

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.

add_box

add_box(layer: int, x1: float, y1: float, x2: float, y2: float, datatype: int = 0) -> str

Add a rectangle (micrometers) on GDS layer/datatype.

add_polygon

add_polygon(layer: int, points: list[list[float]], datatype: int = 0) -> str

Add a polygon from a list of [x, y] vertices (micrometers).

add_path

add_path(layer: int, points: list[list[float]], width: float, datatype: int = 0) -> str

Add a path: centerline [x, y] points (micrometers) with the given width.

add_label

add_label(layer: int, x: float, y: float, text: str, datatype: int = 0) -> str

Add a text label at (x, y) micrometers.

Cells, placement & routing

KLayout MCP server.

Two complementary ways to produce GDS layouts:

  1. High-level drawing tools (new_layout, add_box, add_polygon, ...) build an in-memory layout step by step using the standalone klayout.db module.
  2. run_script executes arbitrary Python with klayout.db available, for anything the high-level tools do not cover (cell hierarchy, arrays, boolean ops, DRC, ...).

Plus open_layout / open_editor to launch the installed KLayout application for viewing or manual drawing.

All coordinates in the high-level tools are in micrometers.

create_cell

create_cell(name: str) -> str

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).

use_cell

use_cell(name: str) -> str

Switch the active drawing cell to an existing cell (e.g. the top cell).

place_cell

place_cell(cell: str, x: float, y: float, orient: str = 'r0', mag: float = 1.0, nx: int = 1, ny: int = 1, dx: float = 0.0, dy: float = 0.0) -> str

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.

add_via

add_via(x: float, y: float, bottom_layer: int, top_layer: int, cut_layer: int, cut_size: float = 0.1, cut_space: float = 0.1, rows: int = 1, cols: int = 1, enclosure: float = 0.05, bottom_datatype: int = 0, top_datatype: int = 0, cut_datatype: int = 0) -> str

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.

add_wire

add_wire(layer: int, points: list[list[float]], width: float, datatype: int = 0, horizontal_first: bool = True) -> str

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.

Inspect & DRC

KLayout MCP server.

Two complementary ways to produce GDS layouts:

  1. High-level drawing tools (new_layout, add_box, add_polygon, ...) build an in-memory layout step by step using the standalone klayout.db module.
  2. run_script executes arbitrary Python with klayout.db available, for anything the high-level tools do not cover (cell hierarchy, arrays, boolean ops, DRC, ...).

Plus open_layout / open_editor to launch the installed KLayout application for viewing or manual drawing.

All coordinates in the high-level tools are in micrometers.

layout_info

layout_info() -> str

Report the current layout: top cell, dbu, layers, bbox, shape count.

load_gds

load_gds(path: str, top_cell: Optional[str] = None) -> str

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.

inspect_gds

inspect_gds(path: Optional[str] = None, top_cell: Optional[str] = None) -> str

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.

drc_check

drc_check(rules: list[dict], path: Optional[str] = None, top_cell: Optional[str] = None, max_report: int = 10) -> str

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}

"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.

Save & view

KLayout MCP server.

Two complementary ways to produce GDS layouts:

  1. High-level drawing tools (new_layout, add_box, add_polygon, ...) build an in-memory layout step by step using the standalone klayout.db module.
  2. run_script executes arbitrary Python with klayout.db available, for anything the high-level tools do not cover (cell hierarchy, arrays, boolean ops, DRC, ...).

Plus open_layout / open_editor to launch the installed KLayout application for viewing or manual drawing.

All coordinates in the high-level tools are in micrometers.

save_gds

save_gds(path: str, open_after: bool = False) -> str

Write the current layout to a file (.gds/.oas by extension). Optionally open it in the editor.

open_layout

open_layout(file_path: str) -> str

Open an existing layout file in KLayout (viewer mode).

open_editor

open_editor(file_path: Optional[str] = None) -> str

Open KLayout in editor mode (-e). With a file: edit it. Without: a blank layout to draw.

Scripting

KLayout MCP server.

Two complementary ways to produce GDS layouts:

  1. High-level drawing tools (new_layout, add_box, add_polygon, ...) build an in-memory layout step by step using the standalone klayout.db module.
  2. run_script executes arbitrary Python with klayout.db available, for anything the high-level tools do not cover (cell hierarchy, arrays, boolean ops, DRC, ...).

Plus open_layout / open_editor to launch the installed KLayout application for viewing or manual drawing.

All coordinates in the high-level tools are in micrometers.

run_script

run_script(code: str) -> str

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.