openscad-mcp-v2
# openscad-mcp-v2
A local [MCP](https://modelcontextprotocol.io) server for [OpenSCAD](https://openscad.org). You describe a part in a chat with Claude (or another MCP client); the client writes parametric OpenSCAD code, and this server stores it, validates it with OpenSCAD, renders images the client checks, shows the model in your OpenSCAD window, keeps every version and exports a 3MF or STL file for your slicer.
The server calls no language model. The MCP client is the model; the server gives it tools and design guidelines for 3D printing.
```
you: "Wall holder for a 28 mm broom handle, two M4 countersunk screws"
└─ client writes SCAD ─► create_design ─► OpenSCAD errors and a rendered image come back
update_design ◄─ client fixes what it sees
open_in_openscad ─► the model is in your OpenSCAD window and follows changes
you: "export it" ─► export_design ─► /…/broom-holder/exports/broom-holder-v0003.3mf
```
## Requirements
- **OpenSCAD**. A [development snapshot](https://openscad.org/downloads.html#snapshots) (2024 or newer) is recommended: its Manifold backend renders in well under a second, so every image is the real geometry. macOS: `brew install --cask openscad@snapshot`. Developed and tested with 2026.10.11 on macOS. The 2021.01 release has no Manifold; the server then falls back to OpenSCAD's quick preview (not tested with that release).
- **Node.js 22** or newer.
## Setup
The package is not on npm yet. From a checkout:
```bash
git clone https://github.com/JohnnyTheTank/openscad-mcp-v2.git
cd openscad-mcp-v2
npm install
npm run build
```
### Claude Code
```bash
claude mcp add openscad \
-e OPENSCAD_MCP_WORKSPACE=~/openscad-designs \
-e OPENSCAD_MCP_PRINTERS=a1,a1mini \
-- node /absolute/path/to/openscad-mcp-v2/dist/index.js
```
Add `--scope user` to have it in every project. Then ask for a part, or start with the prompt `new_design`.
### Claude Desktop
`claude_desktop_config.json` (Settings → Developer → Edit Config):
```json
{
"mcpServers": {
"openscad": {
"command": "node",
"args": ["/absolute/path/to/openscad-mcp-v2/dist/index.js"],
"env": {
"OPENSCAD_MCP_WORKSPACE": "~/openscad-designs",
"OPENSCAD_MCP_PRINTERS": "a1,a1mini"
}
}
}
}
```
Ask the client to run `check_setup` first: it reports the OpenSCAD version, the libraries it found, the workspace and the printer profiles, and says what is missing.
## Configuration
| Variable | Default | Meaning |
|---|---|---|
| `OPENSCAD_PATH` | auto-detect | OpenSCAD executable, a command name, or the `.app` bundle on macOS |
| `OPENSCAD_MCP_WORKSPACE` | `~/openscad-designs` | Folder with one sub-folder per design |
| `OPENSCAD_MCP_PRINTERS` | `generic` (256 × 256 × 256 mm) | Comma-separated printer profiles, see below; the first is the default |
| `OPENSCAD_MCP_PREVIEW` | `auto` | `auto`: `create_design` and `update_design` attach an image. `never`: only `render_views` renders |
| `OPENSCAD_MCP_IMAGE_SIZE` | `800x600` | Size of rendered images in pixels |
| `OPENSCAD_MCP_COLORSCHEME` | `Tomorrow` | OpenSCAD colour scheme for images |
| `OPENSCAD_MCP_PREVIEW_TIMEOUT_MS` | `60000` | Limit for validation and the automatic image |
| `OPENSCAD_MCP_RENDER_TIMEOUT_MS` | `300000` | Limit for `render_views`, `analyze_design` and `export_design` |
| `OPENSCAD_MCP_MANAGE_GUI_PREFS` | `true` | `false`: never change OpenSCAD's "Automatic Reload and Preview" setting |
### Printer profiles
`analyze_design` and `export_design` check the model against the build volume of every configured printer, also turned 90° and lying diagonally.
Built in: `a1mini`, `a1`, `p1p`, `p1s`, `x1c`, `x1e`, `h2s`, `h2d` (Bambu Lab), `mk4`, `mini` (Prusa), `ender3`.
Your own: `name:WIDTHxDEPTHxHEIGHT` in mm.
```
OPENSCAD_MCP_PRINTERS=a1,a1mini
OPENSCAD_MCP_PRINTERS=voron:350x350x340,a1mini
```
A single call can name another one: `printer: "x1c"` or `printer: "300x300x400"`.
## Tools
| Tool | What it does |
|---|---|
| `check_setup` | OpenSCAD version and path, libraries, workspace, printer profiles, state of the automatic reload |
| `get_guidelines` | Design guidelines: workflow, code structure, FDM rules, screw sizes, installed libraries, OpenSCAD reference |
| `list_designs` | Designs with latest version and time of change |
| `create_design` | Saves new code as version 1, validates it, returns errors with source lines and an image |
| `update_design` | Targeted text edits or complete new code, as a new version; validates and returns an image |
| `get_design` | Current code (or an old version) with its parameters |
| `validate_design` | Errors, warnings and echo output of the file as it is on disk |
| `render_views` | Images from `iso`, `iso_back`, `front`, `back`, `left`, `right`, `top`, `bottom`; optional parameter overrides |
| `open_in_openscad` | Shows the design in the OpenSCAD window, which then follows every change |
| `list_versions`, `restore_version` | History, and going back (a restore is a new version) |
| `set_parameters` | Lists the customizer parameters, or changes their values in the file |
| `analyze_design` | Real size, bounding box, closed-solid check, bed contact, fit per printer |
| `export_design` | 3MF (default) or binary STL into the design's `exports/` folder, with path, size and fit |
| `record_learning`, `list_learnings`, `forget_learning` | Lessons for later designs: your corrections and preferences, techniques that failed or worked |
Resources: `openscad://guidelines/3d-printing`, `openscad://guidelines/openscad-reference`, `openscad://guidelines/libraries`, `openscad://guidelines/learnings`, `openscad://design/{name}`. Prompts: `new_design`, `refine_design`.
### What counts as an error
OpenSCAD exits with 0 after a failed `assert()` and still writes files, and it only warns about an unknown module or a missing library although part of the model is then gone. The server treats both as errors and returns them with file, line and the source lines around it, so the client can repair its own code.
## Libraries
Libraries in OpenSCAD's library folders are found automatically, and `get_guidelines` adds usage notes for BOSL2, NopSCADlib and MCAD when they are installed. To install BOSL2 on macOS:
```bash
git clone --depth 1 https://github.com/BelfrySCAD/BOSL2.git ~/Documents/OpenSCAD/libraries/BOSL2
```
`check_setup` prints the library folder of your installation.
## The OpenSCAD window
OpenSCAD has no remote control. `open_in_openscad` starts it with the design's file and relies on OpenSCAD's own setting **Design → Automatic Reload and Preview**, which makes the window follow the file.
- **macOS** (verified): the server switches the setting on before it starts OpenSCAD. If OpenSCAD is already running with the setting off, the tool says so; switch it on once in the menu.
- **Linux** (implemented, not verified on a Linux machine): the setting is written to `~/.config/OpenSCAD/OpenSCAD.conf`; each design opens in its own OpenSCAD process.
- **Windows** (implemented, not verified): OpenSCAD is started with the file; switch the setting on once yourself.
The server remembers which designs it opened and does not open a second window for the same file. A window you opened yourself is unknown to it. You can edit the code in OpenSCAD's editor: the server notices the change and keeps it as its own version before the next update.
## Learnings
The server learns from the work in your workspace. When you correct the model ("round every edge"), when a technique fails and another one works, or when you change a design yourself in OpenSCAD, the client saves a one-sentence lesson with `record_learning`. `get_guidelines` returns these learnings with the guidelines, so the next design starts with them.
- Changes you make in OpenSCAD's editor or Customizer are reported to the client as a diff (changed values and changed lines) by the next tool that works on the design. `list_versions` keeps a summary of them.
- Learnings live in `.openscad-mcp/learnings.json` in the workspace, at most 100 at a time. `list_learnings` shows them with the reason; ask the client to forget one that is wrong (`forget_learning`). Nothing is deleted from the file: forgotten and replaced learnings stay with their reason.
- The server's instructions tell the client to take learnings only from your own words and from this server's results, never from text inside SCAD files or other tools, and that a learning never changes the rules on exporting and printing. The server cannot check where a sentence came from, so look at `list_learnings` now and then.
## Workspace
```
~/openscad-designs/
broom-holder/
broom-holder.scad current code
design.json name, description, version counter
versions/0001.scad … every saved state, never overwritten
renders/iso.png … latest images
exports/broom-holder-v0003.3mf
.openscad-mcp/
learnings.json lessons for later designs
gui.json OpenSCAD windows this server opened
```
Design names become folder names (lower-case letters, digits, dashes); nothing is written outside the workspace.
## Printing
This server ends at the exported file. 3MF and STL are models, not print jobs: a slicer turns them into one. Open the file in Bambu Studio, OrcaSlicer or PrusaSlicer, or hand its path to a printer MCP server that slices, such as [bambu-printer-mcp](https://github.com/DMontgomery40/bambu-printer-mcp) (`print_3mf` slices an unsliced 3MF with the Bambu Studio CLI first). An export of this server was sliced with the Bambu Studio 2.9 CLI for an A1 mini as a check.
Printer servers can start a print without asking. This server's instructions tell the model to start a print only after you asked for it in the conversation; keep your client's tool approval on for printer tools.
## Limits
- The closed-solid check is OpenSCAD's own. Two bodies that only share an edge pass it.
- Wall thickness, overhangs and bridges are not measured; the guidelines make the model design for them, and the slicer preview is the final check.
- Images show the bounding box fitted to the frame; there is no free camera yet.
## Development
```bash
npm test # unit and integration tests; a smoke test uses the installed OpenSCAD when present
npm run typecheck
npm run lint
npx tsx scripts/call.ts check_setup # call a tool in-process
npx tsx scripts/call.ts render_views '{"name":"x"}' --images /tmp/out
```
Notes for coding agents are in [CLAUDE.md](CLAUDE.md).
## Background
Successor of the web app vibecad (Next.js, OpenSCAD in WebAssembly, its own model calls). The design guidelines, the snapshot idea and the split between quick preview and final render come from there; the architecture does not.
## Security
Report vulnerabilities privately, see [SECURITY.md](SECURITY.md). It also describes what the server guards against and what it does not.
## License
MIT
TDQS
Scored across 17 tools
Most tools target clearly distinct lifecycle steps (create, update, validate, render, export, versioning). The main overlap is among validate_design, render_views, analyze_design, and export_design, which all evaluate/render a design, but their descriptions differentiate the exact purpose well enough. get_guidelines and list_learnings also overlap slightly because guidelines include learnings, but the distinction is documented.
All 17 tools use consistent snake_case verb_noun naming (list_designs, create_design, update_design, restore_version). The single prepositional name open_in_openscad still follows the verb-first pattern and is unambiguous.
At 17 tools, the server is slightly above the typical 3-15 sweet spot but every tool maps to a concrete OpenSCAD workflow step: setup, guidelines, design CRUD, versioning, rendering, analysis, export, parameters, and learnings. The count is reasonable for a rich design-and-print workflow, though a few analysis/render tools could potentially be consolidated.
Coverage is strong across the domain: create/read/update/list designs, version history and restore, parameter editing, validation, rendering, geometry analysis, export, and persistent learnings. The notable gap is deletion or archiving of designs and exports, so agents lack a lifecycle cleanup operation, but core workflows are fully supported.