OpenSCAD MCP 服务器 标志

OpenSCAD MCP 服务器

社区
RobertCoop

A Model Context Protocol (MCP) server for OpenSCAD 3D modeling and rendering

发布者RobertCoop
代码仓库openscad-mcp
语言Python
复刻数
18
星标数
139
可用工具
0
传输类型stdio
分类
许可协议MIT
链接
  • 将工具接入 AI 工作流

    OpenSCAD MCP 服务器 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 139 个星标和 18 个复刻。

OpenSCAD MCP Server

PyPI CI Python MCP License

A Model Context Protocol (MCP) server that lets AI assistants design 3D-printable parts and assemblies in OpenSCAD: render with a stated scale, measure exact geometry, check assemblies for interference and clearance, extract holes and features, judge printability, and export. Built with FastMCP for Python; OpenSCAD 2021.01 is the supported floor and dev snapshots are used when present.

Prerequisites

  • OpenSCAD installed on your system
  • uv (recommended) or Python 3.10+

Installation

The server is published on PyPI as openscad-mcp, so uv runs it with no clone and no virtualenv: uvx openscad-mcp. uv keeps a cached copy; uv tool upgrade openscad-mcp (or uvx openscad-mcp@latest) pulls a new release, and uvx openscad-mcp@0.6.1 pins one.

Claude Code

Add the server with a single command:

bash
claude mcp add openscad --transport stdio -- uvx openscad-mcp

Or, if OpenSCAD is not on your PATH:

bash
claude mcp add openscad --transport stdio \
  --env OPENSCAD_PATH=/path/to/openscad -- uvx openscad-mcp

Use the --scope flag to control where the configuration is saved:

ScopeFlagEffect
Local (default)--scope localAvailable only to you in the current project
Project--scope projectShared with the team via .mcp.json
User--scope userAvailable to you across all projects

The repository is also a Claude Code plugin (skill plus server): /plugin marketplace add robertcoop/openscad-mcp then /plugin install openscad-mcp@openscad-mcp.

Claude Desktop

Add to your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
json
{
  "mcpServers": {
    "openscad": {
      "command": "uvx",
      "args": ["openscad-mcp"],
      "env": {
        "OPENSCAD_PATH": "/usr/bin/openscad"
      }
    }
  }
}

Then restart Claude Desktop.

Cursor / Windsurf / VS Code

Add a .mcp.json file to your project root:

json
{
  "mcpServers": {
    "openscad": {
      "command": "uvx",
      "args": ["openscad-mcp"]
    }
  }
}

Manual / Standalone

bash
# From PyPI (no install required)
uvx openscad-mcp

# The development version, straight from GitHub
uvx --from git+https://github.com/robertcoop/openscad-mcp.git openscad-mcp

# Or clone and run locally
git clone https://github.com/robertcoop/openscad-mcp.git
cd openscad-mcp
uv run openscad-mcp

# Run an assembly check file from a shell or a Makefile (exit code 0/1/2)
uvx openscad-mcp check checks.yaml --allow /path/to/project

Available Tools

Every tool response carries errors, warnings and hints parsed from OpenSCAD's output. Check them: OpenSCAD exits 0 on a failed assert() or an unknown module and draws a blank scene.

Rendering

ToolDescription
renderImages with a text digest before each one (camera, view direction, scale, bbox). mode=views (one image per view, or a custom camera), mode=section (exact cross-section with a scale bar), mode=parts (each part in its own colour, isolate ghosts the rest), mode=compare (before/after). grounded=true gives an orthographic view with a stated mm/px scale; annotate=true adds a scale bar, axis triad and bbox dimensions

Assemblies

ToolDescription
checkRelations between named parts, exported separately and never unioned: mode=interference (clear / contact / interference with penetration depth and a witness point), clearance (exact minimum distance with closest points), contact (area, normal, plane; `kind=static

Parts are given inline as parts=[{name, code, place?, frame?, ghost?, mass_g?, motion?}] or in a check file (frames, quality, parts, checks, model). Any number in a rule may be a SCAD expression string (point: "[BOLT_R, 0, BASE_H]") evaluated in the model's scope, so checks follow the parameters rather than a copy of them. openscad-mcp check <file.yaml> runs a check file from the shell with a meaningful exit code, so make check is one call.

Export & Model Management

ToolDescription
export_modelExport to STL, 3MF, AMF, OFF, NEF3, DXF, SVG, PDF or CSG. With parts=[...] every part is exported in its assembly position and bundled into one 3MF with named objects (or a directory of STLs)
model`action=create

Measurement & Validation

ToolDescription
measureExact numbers from the geometry: model (bbox, volume, area, components, watertight, mesh_health), parts, section (contours; the offset may be an expression in the model's scope), mass (grams; with parts= and about_axis= the assembly mass, centre of mass and inertia about an axis, with mass_g overrides for purchased parts), probe (solid/air and which part at points; ray crossings; line of sight along a polyline), features (holes from the CSG tree: axis, diameter, depth, through/blind, undersize at $fn, fit names), printability (overhang patches with unsupported reach, thickness distribution vs nozzle, islands, support estimate; facts only), orientation (candidate orientations, no winner chosen), anchors (BOSL2 anchor frames in the assembly frame). Accepts an existing STL/SVG via mesh
validatemode=syntax, geometry, predicates (with sweep={variable, values} reporting the crossing), includes (references resolved or not, plus the BOSL2 lint: a module from a used file placed by attach() is silently put at CENTER; autofix=true applies the rewrite when it is safe), printability (rules from the design-rule reference over measured facts)
scad_evalEvaluate expressions in a model's variable scope and get typed values (number, vector, string, bool, range, undef)
referenceSourced engineering data with confidence labels: fits (also bidirectional: diameter_mm=3.3 names the hole, shaft_mm+bore_mm names the fit), metric fasteners, heat-set inserts, bearings, magnets, joints, a purchased-parts catalog with BOSL2 modules and clearance masks, FDM design rules, materials, OpenSCAD cheatsheet, conventions
get_librariesDiscover installed OpenSCAD libraries
check_openscadVerify OpenSCAD installation, version and capabilities

Project Support

ToolDescription
get_project_filesList .scad files and their references; mode=trace follows a constant through the project (what depends on it, what it depends on)
clear_cacheClear the render cache

Usage Examples

Once connected, ask your AI assistant:

  • "Render a cube with rounded edges"
  • "Show me the front and top of this model with a scale bar"
  • "What is the volume and are there any cavities?"
  • "Cut a section through the lid at z = 12 and tell me the wall thickness"
  • "Colour the body and lid differently and ghost the body"
  • "What clearance should I use for an M3 screw and a press-fit 608 bearing?"
  • "Compare the model before and after changing the radius to 15"
  • "Export my gear model to STL"

The server also publishes MCP resources (openscad://conventions, openscad://cheatsheet, openscad://reference/{topic}) and server instructions with the coordinate and assembly conventions it expects. A Claude Code skill lives in skills/openscad-design/SKILL.md and the repo can be installed as a Claude Code plugin (.claude-plugin/).

Tool Parameters

API.md documents every tool and every parameter. Four parameters account for most of the questions:

  • parts — a list of {"name": ..., "code": ..., "place": ...} objects, accepted by render(mode="parts"), measure(mode="parts"), check and export_model. code is the statement that instantiates the part (lid();) and place is an optional OpenSCAD transform wrapped around it (translate([0,0,20])). Each part is exported on its own, so its identity survives; an assembly is never unioned. measure(mode="parts") measures each part in its placed position (the response says frame: "assembly"), the same grammar check, render and export_model use.
  • quality — draft, normal, high, or an integer $fn. It sets $fn/$fa/$fs for the run. It is a correctness knob, not only a speed one: check reports a distance smaller than the tessellation error bound as UNRESOLVED rather than guessing, and the fix is a higher quality.
  • variables — a dict injected as OpenSCAD variables. In the wrapped modes (section, parts, scad_eval) they are appended to the wrapped module body rather than passed with -D, and they are injected at file scope as well, so a constant derived inside an included file still sees them. This is how you set a $preview guard variable for an export.
  • include_paths — extra directories added to OPENSCADPATH. When MCP_ALLOWED_PATHS is set, every entry is validated against it, as is every file OpenSCAD actually reads.

Exactly one of scad_content or scad_file is required by every tool that takes source. All parameter parsers accept multiple input formats (JSON strings, lists, dicts, CSV) for AI assistant compatibility.

Each image costs roughly 640 vision tokens at 800x600, and image sizes are clamped to 1568 px on the long edge, above which vision models downscale anyway. Ask for the views that answer a question rather than all of them. Auto-fit renders (grounded=false) have no recoverable absolute scale, which the digest states.

Configuration

Environment Variables

VariableDescriptionDefault
OPENSCAD_PATHPath to OpenSCAD executableAuto-detected
MCP_TEMP_DIRTemporary file directory/tmp/openscad-mcp
MCP_TRANSPORTTransport type: stdio, http, ssestdio
MCP_HOSTHost for HTTP/SSE transportlocalhost
MCP_PORTPort for HTTP/SSE transport8000
MCP_MAX_CONCURRENT_RENDERSMax parallel renders5
MCP_RENDER_TIMEOUTRender timeout in seconds300
MCP_CACHE_ENABLEDEnable render cachingtrue
MCP_CACHE_SIZE_MBMax cache size in MB500
MCP_CACHE_TTL_HOURSCache TTL in hours24
MCP_LOG_LEVELLogging levelINFO
MCP_MAX_FILE_SIZE_MBMax SCAD file size10
MCP_ALLOWED_PATHSDirectories scripts may read from (os.pathsep-separated)unset = no validation
MCP_MAX_MEMORY_MBAddress-space limit per OpenSCAD process (POSIX), 0 disables4096
MCP_MAX_IMAGE_WIDTH / MCP_MAX_IMAGE_HEIGHTRender size clamp (aspect preserved)1568
MCP_HARD_WARNINGSPass --hardwarnings to OpenSCAD (see Security)false

YAML Configuration

Create a config.yaml for advanced configuration:

yaml
server:
  name: "OpenSCAD MCP Server"
  version: "0.1.0"
  transport: stdio

rendering:
  max_concurrent: 5
  timeout_seconds: 300
  default_color_scheme: Cornfield

cache:
  enabled: true
  max_size_mb: 500
  ttl_hours: 24

security:
  rate_limit: 60
  max_file_size_mb: 10
  allowed_paths:          # null = no path validation at all (a warning is logged)
    - /home/me/projects/parts
  max_memory_mb: 4096

Security

Threat model

The server runs OpenSCAD on source it is handed. OpenSCAD can read any file the process can read, through include <>, use <>, import() and surface(), and can return what it read as echo output or as geometry. The guarantees below hold only when allowed_paths is configured. Out of the box it is unset, no path validation is performed, and the server logs a warning at startup saying so.

What is enforced:

  • Path validation on arguments: scad_file, include_paths (in every tool) and export output_path must lie inside allowed_paths. Containment uses resolved paths, so symlinks and .. cannot escape.
  • Path validation on the dependency closure: every file OpenSCAD actually read is recorded with -d and checked after the run. If any lies outside allowed_paths, the standard library directories, or the server temp dir, the output (image, mesh, echo text) is withheld and the call fails. This closes the include <...>-as-data and surface(file=...) channels.
  • Memory ceiling: each OpenSCAD process runs under RLIMIT_AS (max_memory_mb, default 4 GB) on POSIX hosts. OpenSCAD has no ceiling of its own; a small minkowski() can otherwise consume all host memory.
  • Timeout: timeout_seconds, default 300 s; partial stderr is kept.
  • Echo channel bounds: echo_output is capped (200 lines, 2000 chars per line) and labelled as untrusted content from the rendered file.
  • File size limits, variable name validation (^\$?[a-zA-Z_][a-zA-Z0-9_]*$) and model name validation (no path traversal) as before.

What is not enforced: no OS-level sandbox (no network isolation, no filesystem namespace). For untrusted input run the server inside a container or under Landlock/bubblewrap with only the project directory mounted.

Why --hardwarnings is off

--hardwarnings stops OpenSCAD at the first warning but still exits 0, so it produced blank renders and silently truncated echo_output with no indication. Warnings now reach the assistant through the structured warnings, errors and hints fields on every tool response instead. Set MCP_HARD_WARNINGS=true to restore the flag.

Development

bash
# Clone the repo
git clone https://github.com/robertcoop/openscad-mcp.git
cd openscad-mcp

# Install dependencies (the dev extra; there is no dependency-groups table,
# so `uv sync --dev` would remove pytest, ruff, black and mypy)
uv sync --extra dev

# Run the server
uv run openscad-mcp

# Run the assembly checker on a check file
uv run openscad-mcp check examples/checks/turntable.yaml

# Run tests
uv run pytest

# Lint & format. The tree carries pre-existing findings, so expect noise;
# CI gates only on `ruff check --select F,E9,B src/openscad_mcp/`.
uv run ruff check src/ tests/
uv run black --check src/ tests/

# Type check (also not clean today)
uv run mypy src/

Project Structure

openscad-mcp/
├── src/openscad_mcp/
│   ├── server.py            # FastMCP server, the 12 tools, rendering, cache, CLI
│   ├── assembly.py          # Part/Frame/Assembly model and the check-file grammar
│   ├── checks.py            # RuleEngine: the rules a check file can ask for
│   ├── geom.py              # Mesh kernel: BVH, tri-tri distance, winding number, sweeps
│   ├── csgfeatures.py       # CSG-dump parser: holes, bosses, cross-part alignment
│   ├── massprops.py         # Mass, centre of mass, inertia by tetrahedra
│   ├── printability.py      # Overhangs, wall thickness, islands, orientation candidates
│   ├── analysis.py          # Static analysis: BOSL2 $var shadowing lint, constant tracing
│   ├── parts_catalog.py     # Purchased-parts catalog loader and self-check
│   ├── parts/*.scad         # One generated BOSL2 file per catalogued part
│   ├── threemf.py           # Multi-object 3MF writer
│   ├── wrappers.py          # Source-level wrappers: include hoisting, variable injection
│   ├── diagnostics.py       # stderr -> Diagnostics; -d deps parsing; repair hints
│   ├── camera.py            # Orthographic camera model, fit, annotation, spatial digest
│   ├── mesh.py              # Stdlib STL/SVG analysis: welding, components, volumes
│   ├── reference.py         # Sourced engineering data: fits, fasteners, inserts, DFM
│   ├── types.py             # Pydantic models and enums
│   └── utils/config.py      # Configuration with env/YAML/dotenv support
├── tests/                   # ~1,500 tests; 80% coverage floor
├── evals/                   # Deterministic geometry eval harness, 15 tasks
├── examples/checks/         # A worked check file and its model
├── skills/openscad-design/  # Claude Code skill: the design loop
└── .claude-plugin/          # Claude Code plugin manifest

Testing

bash
# Run all tests with coverage (about 1,500 tests, roughly a minute)
uv run pytest

# Run specific markers: unit, config, integration, slow, performance, edge, render
uv run pytest -m unit
uv run pytest -m performance
uv run pytest -m "not slow"

# Run a single file, without the coverage gate
uv run pytest tests/test_helpers.py -v --no-cov

Most tests mock the OpenSCAD subprocess, so no OpenSCAD installation is needed to run the suite. A mock that stands in for a render has to write both output files OpenSCAD would have written: the -o target and the -d dependency file that the cache manifest is built from. Tests that do need the real binary skip themselves when it is absent.

CI runs the suite on Python 3.10 and 3.12 with OpenSCAD 2021.01 and BOSL2 installed, under xvfb-run because PNG export on 2021.01 needs a display. It also builds the wheel, installs it in a clean environment, and asserts that a client sees exactly 12 tools. Coverage floor: 80%.

Troubleshooting

OpenSCAD Not Found

bash
# Check if OpenSCAD is installed
which openscad        # Linux/macOS
where openscad.exe    # Windows

# Set the path explicitly
export OPENSCAD_PATH=/path/to/openscad

Server Not Connecting

bash
# Verify the server starts correctly
uvx openscad-mcp

# In Claude Code, check MCP status
/mcp

Render Timeout

Increase the timeout:

bash
export MCP_RENDER_TIMEOUT=600

"Path not allowed" / "outside the allowed paths"

MCP_ALLOWED_PATHS is set and the file is not under one of its roots. The check covers arguments and, separately, every file OpenSCAD actually opened, so a model that lives inside an allowed root but does include <../shared/lib.scad> outside it is refused and the output is withheld. Add both roots:

bash
export MCP_ALLOWED_PATHS="$HOME/cad:$HOME/cad-shared"

Leaving the variable unset disables path validation entirely, which the server logs a warning about at startup. See Threat model.

An export or a measurement comes back empty

The usual cause is a $preview guard: a file that instantiates its geometry only inside if ($preview) renders in the GUI and exports nothing, because $preview is false for a render to a file. Pass the guard variable explicitly:

measure(scad_file="part.scad", variables={"$preview": true})

A difference() whose first child is smaller than what follows also yields nothing. validate(mode="syntax") will not catch either one; the exit code is 0 in both cases.

check rows say UNRESOLVED

The distance in question is smaller than the tessellation error of the mesh, so the answer would be an artefact of $fn rather than of the design. Re-run with quality="high" or an explicit integer $fn. Every row reports the quality.fn it was computed at.

A result looks stale

Renders are cached under ~/.cache/openscad-mcp/, keyed on every render parameter plus a manifest of every file OpenSCAD read. Editing an included file normally invalidates the entry, but if a response says cached: true and the number disagrees with the source, clear it:

clear_cache()

Renders fail on a headless machine

OpenSCAD 2021.01 needs a display to export PNG even in headless mode. Run the server under a virtual framebuffer:

bash
xvfb-run -a uv run openscad-mcp

Exports, measurements and checks produce meshes rather than images and do not need a display.

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-feature)
  3. Make your changes with tests
  4. Ensure tests pass (uv run pytest)
  5. Open a Pull Request

Commit style: feat:, fix:, docs:, refactor:, chore:

CONTRIBUTING.md covers the module map, how the tests mock OpenSCAD, the design rules that should not be undone, and how to add a parts-catalog entry or a check rule.

License

MIT — see LICENSE

Acknowledgments

  • OpenSCAD — Programmable CAD software. Everything here is a wrapper around its CLI.
  • FastMCP — Python MCP framework
  • Model Context Protocol — The MCP specification
  • BOSL2 — Used, not vendored, by the purchased-parts catalog and by the BOSL2 anchor probe. BSD-2-Clause; install it separately.
  • Dimensional data in reference and parts is cited entry by entry, with a confidence label on every number. See src/openscad_mcp/parts/README.md.

安装

TypingMind
前提条件:

Node.js 18+

{
  "mcpServers": {
    "quellant-openscad-mcp": {
      "command": "uvx",
      "args": [
        "openscad-mcp"
      ]
    }
  }
}

将 OpenSCAD MCP 服务器 MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 OpenSCAD MCP 服务器 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请勿关闭终端窗口或停止其中的连接器进程。
3

将 OpenSCAD MCP 服务器 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 OpenSCAD MCP 服务器 MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "quellant-openscad-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "openscad-mcp"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 OpenSCAD MCP 服务器 MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 OpenSCAD MCP 服务器 MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 OpenSCAD MCP 服务器 帮我完成这项任务吗?
OpenSCAD MCP 服务器
当然,我看过了。
以下是我使用 OpenSCAD MCP 服务器 得到的结果。

常见问题

OpenSCAD MCP 服务器 MCP 服务器有什么用途?

OpenSCAD MCP 服务器 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 OpenSCAD MCP 服务器 MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您无需为每个模型单独配置 MCP 服务器,就能在 Claude、ChatGPT、Gemini 或您在 TypingMind 中配置的其他 AI 模型中使用 OpenSCAD MCP 服务器。

为什么在 TypingMind 中使用 OpenSCAD MCP 服务器 MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是最出色的大语言模型聊天前端之一。连接 OpenSCAD MCP 服务器 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 OpenSCAD MCP 服务器 MCP 连接到 TypingMind?

OpenSCAD MCP 服务器 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

OpenSCAD MCP 服务器 MCP 在 TypingMind 中提供哪些工具?

OpenSCAD MCP 服务器 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 OpenSCAD MCP 服务器 MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行选择模型提供商,并自行管理 API 密钥、提示词和 MCP 配置。如果 OpenSCAD MCP 服务器 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇