Skip to main content

Observer-first MCP server for KLayout layout inspection.

Project description

klayout-mcp

CI Docs

Read-only MCP server for KLayout. It opens GDS/OAS layouts, inspects geometry and hierarchy, renders deterministic PNGs, and runs batch DRC with structured JSON output.

Install

Fastest one-off run:

uvx klayout-mcp@latest

Install once:

uv tool install klayout-mcp

Traditional Python install:

python -m pip install klayout-mcp

For batch DRC, the klayout executable must be on PATH or exposed through KLAYOUT_BIN.

export KLAYOUT_BIN=/Applications/klayout.app/Contents/MacOS/klayout

Quick Start

klayout-mcp is a stdio MCP server. The default launch shape is:

command: uvx
args:    klayout-mcp@latest

If your client cannot use uvx, install the tool once and launch klayout-mcp directly.

Typical workflow:

  1. open_layout
  2. list_layers
  3. list_cells or describe_cell
  4. query_region
  5. measure_geometry
  6. analyze_waveguide
  7. render_view
  8. run_drc_script
  9. extract_markers
  10. close_session

Client Setup

More copy-paste examples live in examples/mcp/README.md.

Codex

[mcp_servers.klayout]
command = "uvx"
args = ["klayout-mcp@latest"]

[mcp_servers.klayout.env]
KLAYOUT_BIN = "/Applications/klayout.app/Contents/MacOS/klayout"

Or add it with the CLI:

codex mcp add klayout \
  --env KLAYOUT_BIN=/Applications/klayout.app/Contents/MacOS/klayout \
  -- uvx klayout-mcp@latest

Claude Code

{
  "mcpServers": {
    "klayout": {
      "command": "uvx",
      "args": ["klayout-mcp@latest"],
      "env": {
        "KLAYOUT_BIN": "/Applications/klayout.app/Contents/MacOS/klayout"
      }
    }
  }
}

Or add it with the CLI:

claude mcp add --transport stdio klayout \
  --scope project \
  --env KLAYOUT_BIN=/Applications/klayout.app/Contents/MacOS/klayout \
  -- uvx klayout-mcp@latest

Cursor

Cursor is file-config based:

{
  "mcpServers": {
    "klayout": {
      "command": "uvx",
      "args": ["klayout-mcp@latest"],
      "env": {
        "KLAYOUT_BIN": "/Applications/klayout.app/Contents/MacOS/klayout"
      }
    }
  }
}

OpenCode

OpenCode is file-config based:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "klayout": {
      "type": "local",
      "command": ["uvx", "klayout-mcp@latest"],
      "enabled": true,
      "environment": {
        "KLAYOUT_BIN": "/Applications/klayout.app/Contents/MacOS/klayout"
      }
    }
  }
}

Other MCP Hosts

Use:

  • command: uvx
  • args: ["klayout-mcp@latest"]
  • env: KLAYOUT_BIN when needed

Tools

  • Session: open_layout, close_session
  • Structure: list_layers, list_cells, describe_cell
  • Geometry: query_region, measure_geometry, analyze_waveguide
  • View: set_view, render_view
  • DRC: run_drc_script, extract_markers

Configuration

Variable Purpose Default
KLAYOUT_MCP_ARTIFACT_ROOT Root directory for runtime artifacts <repo>/.artifacts
KLAYOUT_MCP_SESSION_TTL_SECONDS Session inactivity timeout 3600
KLAYOUT_BIN KLayout batch executable for DRC klayout

Behavior:

  • any absolute local path can be used for layouts and DRC scripts
  • artifact paths returned by tools are absolute
  • sessions expire lazily after inactivity
  • close_session removes the session artifact directory

Artifacts And Errors

Artifacts are stored under .artifacts/sessions/<session_id>/ and include renders, DRC reports, marker crops, and logs.

Tool failures return structured JSON such as:

{
  "code": "FILE_NOT_FOUND",
  "message": "Layout file does not exist",
  "details": {
    "path": "/abs/path/to/missing.gds"
  }
}

Common codes: FILE_NOT_FOUND, SESSION_NOT_FOUND, INVALID_BOX, INVALID_LAYER, INVALID_TARGET, DRC_RUN_FAILED.

Development

For a source checkout:

uv sync --extra dev
uv run klayout-mcp

If an MCP client needs to launch the checkout directly:

command: uv
args:    --directory /abs/path/to/klayout-mcp run klayout-mcp

Contributor workflow is in CONTRIBUTING.md. Release notes are in CHANGELOG.md.

Releases

Normal releases are automated with release-please.

  • merge Conventional Commits to main
  • release-please opens or updates a release PR
  • merging that release PR updates pyproject.toml, CHANGELOG.md, creates the tag and GitHub release, and publishes to PyPI

To let the release PR run normal CI under branch protection, configure a repository secret named RELEASE_PLEASE_TOKEN with a GitHub token that can open pull requests. Without it, release-please falls back to github.token, which may not trigger PR workflows.

The manual release.yml workflow remains available for TestPyPI validation and recovery publishing.

Reference

Documentation Site

The repository is configured for Read the Docs with MkDocs.

Build the docs locally:

uv run --extra docs mkdocs build --strict

Serve the docs locally:

uv run --extra docs mkdocs serve

After importing the GitHub repository into Read the Docs, it can build directly from the default branch using .readthedocs.yaml.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

klayout_mcp-0.2.1.tar.gz (31.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

klayout_mcp-0.2.1-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file klayout_mcp-0.2.1.tar.gz.

File metadata

  • Download URL: klayout_mcp-0.2.1.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for klayout_mcp-0.2.1.tar.gz
Algorithm Hash digest
SHA256 92e7a439bc33ee8b3385103edcf2f67db95edc054b6f24c4cf6c1e9d97d2e952
MD5 05c0b48c048365d5f90999794a31309f
BLAKE2b-256 1d0a86fc045e7f7c41de16a02473bda066e76bfadf81598167d1352b400e377a

See more details on using hashes here.

Provenance

The following attestation bundles were made for klayout_mcp-0.2.1.tar.gz:

Publisher: release.yml on aycandv/klayout-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file klayout_mcp-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: klayout_mcp-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 30.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for klayout_mcp-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0922d4ff45cfd31a7e117efefbca6ea4bb14072fdf423feefdc6c53051cb8218
MD5 ef09506660767bf1fec40a1ba08879ee
BLAKE2b-256 ce99320737c8094c47e965b9e15acd8957f0c59af5c1bcc317664294bc97f69f

See more details on using hashes here.

Provenance

The following attestation bundles were made for klayout_mcp-0.2.1-py3-none-any.whl:

Publisher: release.yml on aycandv/klayout-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page