xblaster/OpenSCAD-Vision-Bridge

★ 0Forks 0TypeScriptGitHub ↗Compare

README

OpenSCAD-Vision-Bridge

MCP (Model Context Protocol) server that bridges LLMs with OpenSCAD for parametric 3D CAD. Enables AI agents to generate, render, analyze, and export 3D models through a standardized protocol.

Features

Tool Description
render_openscad Render OpenSCAD code to PNG preview (Base64 multimodal response)
export_stl Export OpenSCAD code to STL for 3D printing
get_csg_tree Parse and return the CSG tree structure (JSON)
get_model_metrics Extract bounding box, dimensions, and vertex count

Prerequisites

  • Node.js >= 18
  • OpenSCAD installed and available in PATH (or configured via OPENSCAD_PATH)

Install OpenSCAD

# Ubuntu/Debian
sudo apt-get install openscad

# macOS
brew install openscad

# Or download from https://openscad.org/downloads.html

Installation

npm install
npm run build

Usage

With Claude Desktop

Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "openscad-vision-bridge": {
      "command": "node",
      "args": ["/absolute/path/to/dist/index.js"],
      "env": {
        "OPENSCAD_PATH": "/usr/bin/openscad"
      }
    }
  }
}

Standalone

npm start

Development

npm run dev    # Run with tsx (no build needed)
npm test       # Run tests
npm run build  # Compile TypeScript

Environment Variables

Variable Default Description
OPENSCAD_PATH openscad Path to the OpenSCAD binary
OPENSCAD_TIMEOUT 30000 Execution timeout in milliseconds
OPENSCAD_MAX_FILE_SIZE 52428800 Max output file size in bytes (50MB)

Architecture

src/
├── index.ts                    # Entry point, stdio transport
├── server.ts                   # MCP server setup & tool registration
├── services/
│   ├── openscad-executor.ts    # OpenSCAD binary execution with timeout
│   └── temp-file-manager.ts    # Ephemeral file lifecycle management
├── tools/
│   ├── render-openscad.ts      # PNG rendering tool
│   ├── export-stl.ts           # STL export tool
│   ├── get-csg-tree.ts         # CSG tree analysis tool
│   └── get-model-metrics.ts    # Dimensional metrics extraction tool
└── types/
    └── schemas.ts              # Zod validation schemas

Security

  • Execution timeouts: All OpenSCAD processes are killed after configurable timeout
  • File size limits: Output files are capped to prevent disk exhaustion
  • Input validation: All tool inputs validated via Zod schemas
  • Isolation: Each session uses a unique temporary directory, cleaned up on shutdown
  • No arbitrary code: Only OpenSCAD code is executed, no shell commands

License

MIT

Contributors

claude

Issues