karolkaczmarek1/openscad-mcp-server
If you are the rightful owner of openscad-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The OpenSCAD MCP Server is a specialized server designed to facilitate interaction with OpenSCAD through Model Context Protocol (MCP), enabling LLMs to perform tasks like writing SCAD code, rendering previews, and exporting 3D models.
OpenSCAD MCP Server
OpenSCAD Agent for LLMs
A Model Context Protocol (MCP) server that provides tools for interacting with OpenSCAD. This allows LLMs (like Gemini) to write SCAD code, render previews, export 3D models, and securely inspect installed libraries.
Features
- Write SCAD Files:
write_scad_scriptallows creating/editing scripts in the current directory. - Multimodal Previews:
render_preview: Returns a rendered PNG image of the model. Supports optionalrotation_x,rotation_y,rotation_zanddistanceparameters.- Auto-Centering & Auto-Zoom: The tool automatically analyzes the model geometry (via temporary STL export) to center the camera and calculate an optimal distance, ensuring the object is always visible.
render_views_matrix: Generates a composite image containing 14 standard views (6 orthogonal: Top, Bottom, Front, Back, Left, Right; and 8 isometric from every corner), clearly labeled and framed. This provides a comprehensive visual summary of the object.
- Export STL:
export_stlfor geometry validation (manifold checks) and export. - Library Inspection:
list_libraries: Lists all available library roots.list_scad_library_directoryandread_scad_library_fileallow the LLM to learn from installed libraries (e.g.BOSL2/threading.scad).- Smart Path Resolution: Supports searching by relative paths (e.g., just
BOSL2). - Access is strictly limited to configured library paths.
- Configuration: Customizable via
.envfile.
Prerequisites
- Python 3.10+
- OpenSCAD: Must be installed.
- Windows: Checks
C:\Program Files\OpenSCAD\openscad.exeby default. - Linux: Checks
PATH. Requiresxvfb(e.g.,apt install xvfb) for headless rendering support, which is automatically handled.
- Windows: Checks
- Python Dependencies:
mcppython-dotenvPillow(for image processing)numpy&numpy-stl(for geometry analysis and auto-centering)
Installation
- Clone this repository.
- Install dependencies:
pip install -r requirements.txt - (Optional) Configure paths in
.env:- Copy
.env.exampleto.env. - Edit
.envto set yourOPENSCAD_PATHorOPENSCAD_LIBRARIES_PATHif they differ from defaults.
- Copy
Usage
Running the Server
Run the server using Python:
python src/server.py
Integration with Gemini CLI
To use this with the Gemini CLI (or any MCP client), configure the client to launch this server.
Example configuration:
{
"mcpServers": {
"openscad": {
"command": "python",
"args": ["<path_to_repo>/src/server.py"]
}
}
}
Windows Notes
- If OpenSCAD is not detected, set
OPENSCAD_PATHin.env. - To allow the LLM to read your installed libraries (e.g., in
Documents/OpenSCAD/libraries), ensure that path is either standard or added toOPENSCAD_LIBRARIES_PATHin.env.
Troubleshooting for LLMs
If the model tries to use generic tools like write_file or edit_file:
- The server is designed with aggressive prompts in tool descriptions to force the use of
write_scad_script. - Ensure your client is actually using the tools provided by this server.
Acknowledgements
- LLMto3D: This work is inspired by the research paper LLMto3D - Generation of parametric 3D printable objects using large language models by Bat El Hizmi et al.
- OpenSCAD: The programmers' solid 3D CAD modeller.
- BOSL2: The Belfry OpenScad Library v2, an essential library for parametric design.
- Gemini CLI: An open-source AI agent that brings the power of Gemini directly into your terminal.