Skip to main content

Observer-first MCP server for KLayout layout inspection.

Project description

klayout-mcp

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

Install In 60 Seconds

Fastest one-off run:

uvx klayout-mcp

Install once and keep the command on your machine:

uv tool install klayout-mcp
klayout-mcp

Traditional Python install:

python -m pip install klayout-mcp

klayout-mcp depends on the klayout Python package. For batch DRC, you also need the klayout executable on PATH or KLAYOUT_BIN set explicitly.

Common macOS app path:

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

Quick Start

Set KLAYOUT_BIN if the klayout executable is not already on PATH:

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

The server speaks MCP over stdio. The most common launcher is:

command: uvx
args:    klayout-mcp

If your host cannot use uvx, install once with uv tool install klayout-mcp and point the client at the installed klayout-mcp binary instead.

Choose Your Client

Ready-to-copy config files live in examples/mcp/README.md.

Codex

Codex supports user-scoped ~/.codex/config.toml and project-scoped .codex/config.toml.

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

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

Codex CLI also supports adding stdio servers directly:

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

Claude Code

Claude Code supports project-scoped .mcp.json and user-scoped MCP configuration.

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

CLI form:

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

Cursor

Cursor reads MCP servers from .cursor/mcp.json for a project or ~/.cursor/mcp.json globally.

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

OpenCode

OpenCode reads MCP servers from opencode.json under the mcp key.

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

Other MCP Hosts And Agents

Use this stdio shape:

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

This server works well with agents because it is read-only with respect to layout content, but it still writes artifacts for renders, reports, and marker crops.

Typical Workflow

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

Available Tools

Session

  • open_layout
  • close_session

Structure

  • list_layers
  • list_cells
  • describe_cell

Geometry

  • query_region
  • measure_geometry

View

  • set_view
  • render_view

DRC

  • run_drc_script
  • extract_markers

Configuration

Supported environment variables:

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

Important 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

Runtime artifacts are stored under:

.artifacts/
  sessions/
    <session_id>/
      session.json
      renders/
      drc/

Typical outputs include:

  • rendered PNGs
  • DRC reports (.lyrdb)
  • markers.json
  • stdout.txt and stderr.txt
  • crop images for extracted markers

Error Model

Tool failures return structured JSON objects:

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

Common codes include:

  • FILE_NOT_FOUND
  • SESSION_NOT_FOUND
  • INVALID_BOX
  • INVALID_LAYER
  • INVALID_TARGET
  • DRC_RUN_FAILED

Security Notes

  • This server is read-only with respect to layout content
  • any absolute local layout path or DRC script path may be used
  • tool parameters are treated as data, not shell fragments

Source Checkout

For local development or unreleased builds:

uv sync --extra dev
uv run klayout-mcp

If an MCP client needs to launch a source checkout directly:

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

Contributor workflow, branch policy, and release expectations are documented in CONTRIBUTING.md.

CI And Releases

GitHub Actions workflows included in this repo:

  • .github/workflows/ci.yml
  • .github/workflows/release.yml
  • .github/workflows/github-release.yml

Human-readable release notes live in CHANGELOG.md.

Release flow:

  1. Update version in pyproject.toml
  2. Move Unreleased notes into a new version section in CHANGELOG.md
  3. Merge to main
  4. Run the Release workflow for testpypi
  5. Verify the package from TestPyPI
  6. Run the Release workflow for pypi
  7. Push the matching tag, for example v0.1.0

Reference Docs

If those documents disagree, follow the contract.

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.1.1.tar.gz (25.4 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.1.1-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: klayout_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 25.4 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.1.1.tar.gz
Algorithm Hash digest
SHA256 17325f743f6ff185bf0a94f473b2b5ddb95e3c4828d470ef5b417b9936699ddc
MD5 b04b70176162f4ce3f2cebcb98761733
BLAKE2b-256 c113e889a90eb098dcff62c3624f21638f4aa0a7a112506b994e9d3a863a2c0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for klayout_mcp-0.1.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.1.1-py3-none-any.whl.

File metadata

  • Download URL: klayout_mcp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 24.7 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f2d89f2972b05227dc6d056849e558a22692f9ec13eb0c6b7a2598022bf0a79
MD5 804983cc58fe824a5d65e25f20418b28
BLAKE2b-256 6e57bac3db05afc33a028a4931d18af8ff68d9ab4bd095c8ba22b56aa023e78c

See more details on using hashes here.

Provenance

The following attestation bundles were made for klayout_mcp-0.1.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