OpenSCAD MCP Server
# OpenSCAD MCP Server
[](https://opensource.org/licenses/MIT)
[](https://www.python.org/downloads/)
A Model Context Protocol (MCP) server that provides seamless integration between Large Language Models and OpenSCAD for collaborative 3D modeling and rapid prototyping.
## ๐ Features
- **Natural Language to 3D Models**: Describe your design in plain English and get working OpenSCAD code
- **Live Visual Feedback**: Real-time rendering with base64 PNG images optimized for vision models
- **Instant 3D Printing**: Direct STL export ready for your 3D printer
- **Persistent Workspace**: Scratchpad maintains your work across sessions
- **Multiple Camera Views**: Inspect your models from all angles (isometric, front, back, left, right, top, bottom)
- **Error Handling**: Comprehensive error reporting and logging for debugging
## ๐ฏ Use Cases
- **Rapid Prototyping**: Quickly iterate on mechanical parts and assemblies
- **Educational Tools**: Learn 3D modeling through conversational interfaces
- **Parametric Design**: Generate families of related objects with simple parameter changes
- **Accessibility**: 3D modeling for users who prefer text-based interfaces
- **Automation**: Integrate 3D model generation into larger workflows
## ๐ Requirements
- **Python 3.8+**
- **OpenSCAD** (installed and accessible via command line)
- **fastmcp** library
## ๐ ๏ธ Installation
### 1. Install OpenSCAD
**Windows:**
```bash
# Download from https://openscad.org/downloads.html
# Or via Chocolatey:
choco install openscad
```
**macOS:**
```bash
brew install openscad
```
**Linux (Ubuntu/Debian):**
```bash
sudo apt-get install openscad
```
### 2. Clone and Run
```bash
git clone https://github.com/jabberjabberjabber/openscad-mcp
cd openscad-mcp
uv run --with fastmcp fastmcp dev main.py
```
### 3. Install
**Add this to your client's MCP config:**
```json
"mcpServers": {
"openscad-mcp": {
"command": "uv",
"args": [
"run",
"--with",
"fastmcp",
"fastmcp",
"run",
"c:/path/to/openscad-mcp/main.py"
],
"env": {
"OPENSCAD_WORK_DIR": "c:/path/to/openscad-mcp/"
}
}
},
```
## ๐ฎ Usage
The server provides five main tools for 3D modeling workflows:
### Available Tools
| Tool | Purpose | Parameters |
|------|---------|------------|
| `show_openscad_script` | Display current script | None |
| `create_openscad_script` | Create/update script | `script_content: str` |
| `view_render` | Render PNG image | `view: str` (optional) |
| `export_model_to_stl` | Export for 3D printing | `filename: str` |
| `save_openscad_script` | Save script to file | `filename: str` |
### Example Workflow
```python
# 1. Create a model
create_openscad_script("""
// Simple cube with rounded corners
$fn = 32;
minkowski() {
cube([20, 20, 10], center=true);
sphere(r=2);
}
""")
# 2. View the result
view_render("isometric") # Returns base64 PNG
# 3. Export for printing
export_model_to_stl("rounded_cube")
# 4. Save the source
save_openscad_script("rounded_cube")
```
### Camera Views
- `isometric` (default) - 3D perspective view
- `front` - Front orthographic view
- `back` - Back orthographic view
- `left` - Left side view
- `right` - Right side view
- `top` - Top-down view
- `bottom` - Bottom-up view
## ๐๏ธ Architecture
```
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ LLM Client โโโโโถโ MCP Server โโโโโถโ OpenSCAD โ
โ โ โ โ โ Engine โ
โ Natural Languageโ โ โข Script Storage โ โ โข Rendering โ
โ Descriptions โ โ โข State Mgmt โ โ โข STL Export โ
โ โโโโโโ โข Error Handling โโโโโโ โข Validation โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
```
### Key Components
- **Persistent State**: JSON-based scratchpad for session continuity
- **OpenSCAD Integration**: Subprocess calls with timeout protection
- **Image Generation**: Base64 PNG encoding for vision model compatibility
- **File Management**: Organized output to configurable working directory
- **Error Handling**: Comprehensive logging and graceful failure modes
## ๐จ Example Projects
### Hollow Sphere (Vase Mode)
```openscad
$fn = 64;
difference() {
sphere(r=15); // 30mm diameter
sphere(r=12); // 3mm wall thickness
}
```
### Parametric Gear
```openscad
module gear(teeth=20, height=5) {
linear_extrude(height=height) {
for (i = [0:teeth-1]) {
rotate([0, 0, i*360/teeth]) {
translate([8, 0, 0]) circle(r=1);
}
}
circle(r=7);
}
}
gear(teeth=16, height=8);
```
### Customizable Bracket
```openscad
width = 30;
depth = 20;
height = 15;
thickness = 3;
difference() {
cube([width, depth, height]);
translate([thickness, thickness, thickness])
cube([width-2*thickness, depth-thickness, height]);
}
```
## โ๏ธ Configuration
### Environment Variables
- `OPENSCAD_WORK_DIR`: Working directory for files (default: server directory)
### Logging
Logs are written to `openscad_mcp.log` with detailed operation information:
- Script updates and validations
- Rendering operations and timing
- Export operations and file sizes
- Error conditions and recovery
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
TDQS
Scored across 5 tools
Most tools have clearly distinct purposes: read the scratchpad, update it, render a PNG, export STL, and save to file. The main friction is between create_openscad_script (updates scratchpad) and save_openscad_script (writes to file), which could be confused since both 'persist' the script, but descriptions clarify the target.
Three tools consistently use the verb_openscad_script pattern (show/create/save_openscad_script), which is predictable. view_render and export_model_to_stl deviate with different noun and suffix conventions, but remain readable and verb-first.
Five tools is well-scoped for a scratchpad-based script editing and rendering workflow, with each tool earning its place (read, write, preview, export, persist). No bloat and no obviously redundant operations.
The surface covers the core lifecycle: read, create/update, render preview, export STL, and save to file. Minor gaps exist, such as clearing/deleting the scratchpad or listing/returning saved file locations, but agents can work around these.