KLayout + Python + MCP

klink

An AI-native control plane for KLayout. It turns a running KLayout GUI into a layout kernel driven by external Python, MCP clients, and AI agents — geometry-first: mark intent on geometry, let algorithms complete the wiring, and decide "done" with structured geometry and LVS, not a screenshot that "looks right". It is an early-stage, experimental open-source project — try it and send feedback.

Package: klayout-klink Python 3.10+ KLayout 0.30.x tested Apache-2.0 open source Alpha · early stage

The control path

A thin plugin hugs KLayout; the heavy intelligence runs in external Python. The two sides talk only over RPC. Detail on Architecture.

control path
Agent (Claude Code / Codex)
  → MCP server   (python -m klink.mcp)
  → klink client (NDJSON over TCP)
  → KLayout plugin (in-process RPC)
       RPC:            127.0.0.1:8765+
       klive-compat:   127.0.0.1:8082

Sessions are ports, equal peers

Each KLayout window binds a port (8765, 8766…) as a session. No port has a privileged role — you always say which one.

Process purity

klink holds no process constants. Layers, sizes and devices are passed in from your pdk.py; a missing fact returns an instructive error with a next_action.

Capabilities, by domain

klink is a general geometry-first control plane. Below are some current capabilities grouped by domain, each backed by a runnable example script (all with no private GDS). The project is still early and experimental, so coverage will keep changing. Per-example measured detail on Examples.

EBL nanodevice

EBL nanodevices

Electron-beam-lithography device generation: EBL wraparound, Hall bar, with writefield planning, patches and geometry validation. Offline EBL measures 40 electrodes / 0 violations / 0 overlaps.

See EBL / Hall bar →
Neural electrode

Neural electrodes

Parametric neural-electrode probe: pad/via geometry → Ports → corridor anchors → tapered-hybrid routing, self-contained with no GDS. 4 rows: 48 ports / 24 nets / overlap 0.

See neural electrode →
New materials

Material flake detection

Detect material flakes from a microscope image (needs cv2+numpy), or read a precomputed traces.json, commit them as polygons and derive contact Ports. Built on KlayoutClaw priors.

See nanodevice tools →
Imaging

Cross-sections · 3D · SEM · Blender

One klink_visual_stack_v1 declaration plus your own .pyxs recipe yields process cross-sections and per-step films (with a z ruler), a 3D model with a self-contained offline web viewer, SEM-style top views, and paper-grade Blender renders. The starter is a four-transistor CMOS row and an eleven-step planar CMOS flow.

See the imaging tutorial →
Silicon photonics

Silicon photonics

Take an ordinary gdsfactory MZI script into klink in one call; after a GUI drag, one photonics.reroute re-routes optics (incl. sbend / all_angle / dubins) and metal together.

See the gdsfactory MZI →
Digital P&R

Custom-device digital P&R → LVS

Fit a device from synthetic exemplars, place, detailed-route, verify with live LVS. Measured routed 94/94, LVS match=True, 173 devices; the device-agnostic netlist flow is structdevice.*.

See the fit-device demo →
Region · intent

Regions & executable layout intent

Circle an area and tile any existing cell into it with a unique number label per copy: region.claim claims + intent.prepare previews + intent.apply commits + intent.regenerate atomically swaps. Measured region 14000 µm², placed 31 (4 rejected), regenerate relabels the whole array to S201..S231.

See the layout intent tutorial →

190+ tools, 15 domains

Plugin RPCs + MCP local tools, each with function, parameters and examples (exact counts on the MCP Tool Reference). The catalogue is generated from the live plugin's method registry — no hand-maintained list that can drift.