An MCP (Model Context Protocol) server that integrates FreeCAD with AI models (Claude, GPT-4o, Gemini), providing natural language CAD control, Docker-containerized headless execution, Vision AI analysis, and AI-powered 3D generation.
- Natural Language CAD Control: 57 MCP tools for comprehensive CAD operations
- Docker-Containerized FreeCAD: Headless execution with optional VNC GUI access
- AI 3D Generation: TRELLIS.2 for image-to-3D, ComfyUI for text-to-image generation
- Gradio Web Interface: Debug interface with request tracking and image gallery
- Cloudflare Quick Tunnels: Public URL access without port forwarding
- Vision AI Integration: Cosmos VLM for model analysis, SAM3 for segmentation
- Docker Service Management: Start/stop/monitor all services from MCP tools
- Dual GPU Support: Optimized for dual 24GB 3090 setup with automatic quantization
┌─────────────────┐
│ AI Model │ (Claude/GPT-4o/Gemini)
└────────┬────────┘
│ MCP Protocol (JSON-RPC 2.0)
┌────────▼────────┐
│ MCP Server │ ← 57 tools
│ + Gradio UI │ ← Web interface + tunnel
└────────┬────────┘
│
┌────┴────┬─────────────┬─────────────┐
│ │ │ │
▼ ▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│ FreeCAD │ │ TRELLIS │ │ ComfyUI │ │Inference│
│ :9875 │ │ :8000 │ │ :8188 │ │ :5555 │
│ XML-RPC │ │ HTTP │ │ HTTP │ │ ZMQ │
└─────────┘ └─────────┘ └─────────┘ └─────────┘
Headless Image→3D Text→Image VLM+SAM
- Docker Engine: Install from docs.docker.com/engine/install
- Docker Compose: Included with Docker Desktop, or install separately for Linux
- NVIDIA Container Toolkit (for GPU services): Install from docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html
- Python 3.10+
# Verify Docker installation
docker --version
docker compose version
# Verify NVIDIA Container Toolkit (optional, for GPU services)
docker run --rm --gpus all nvidia/cuda:12.1-base nvidia-smi# Start FreeCAD only
docker compose up freecad -d
# Or start with GUI (VNC access on port 3000)
ENABLE_GUI=true docker compose up freecad -d# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -e .# For Claude Desktop integration
python -m src.mcp_server
# Or run debug interface standalone
python -m src.debug_interface --port 7860There are two ways to configure the MCP server with your AI client:
Create a .mcp.json file in the project root (copy from example):
cp .mcp.json.example .mcp.jsonEdit .mcp.json and update the cwd path to your installation directory:
{
"mcpServers": {
"freecad": {
"command": "python",
"args": ["-m", "src.mcp_server"],
"cwd": "/absolute/path/to/freecad_mcp",
"env": {
"FREECAD_HOST": "localhost",
"FREECAD_PORT": "9875",
"TRELLIS_HOST": "localhost",
"TRELLIS_PORT": "8000",
"DIFFUSION_HOST": "localhost",
"DIFFUSION_PORT": "8188"
}
}
}
}MCP clients like Claude Code will automatically detect and use this configuration when working in the project directory.
Add to ~/.config/claude-desktop/config.json (Linux) or ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):
{
"mcpServers": {
"freecad": {
"command": "python",
"args": ["-m", "src.mcp_server"],
"cwd": "/absolute/path/to/freecad_mcp"
}
}
}Note: The cwd path must be absolute (e.g., /home/user/freecad_mcp, not ~/freecad_mcp).
create_document- Create new FreeCAD documentopen_document- Open existing .FCStd filesave_document- Save document to fileclose_document- Close documentlist_documents- List all open documents
create_primitive- Create Box, Cylinder, Sphere, Cone, Torusboolean_operation- Union, Cut, Intersect operationstransform_object- Move, rotate, scale objectsfillet_chamfer- Add fillets or chamfers to edges
create_body- Create PartDesign Body containercreate_sketch- Create parametric sketch on plane/faceadd_sketch_geometry- Add lines, circles, arcs, rectanglesadd_sketch_constraint- Add dimensional and geometric constraintspad_sketch- Extrude sketch into solidpocket_sketch- Cut pocket from sketch
draft_line- Create 2D linedraft_rectangle- Create 2D rectangledraft_circle- Create 2D circle
get_objects- List all objectsget_object_info- Detailed object introspectionedit_object- Modify object propertiesdelete_object- Remove objectexecute_code- Run arbitrary Python (with security checks)export_model- Export to STEP, STL, OBJ, IGESimport_model- Import from various formats
get_view- Capture viewport screenshotset_view- Set camera anglescreenshot_webpage- Take screenshot of web interfacerender_spinning_video- Render spinning video of 3D model
measure_distance- Distance between objectsget_bounding_box- Object bounding box
generate_3d_from_text- Text description → 3D mesh (via image generation)generate_3d_from_image- Image → 3D meshget_trellis_status- Check TRELLIS.2 model statusload_trellis_model/unload_trellis_model- GPU memory managementimport_mesh- Import GLB/OBJ/STL into FreeCAD
start_docker_service- Start container (freecad, trellis, diffusion, inference)stop_docker_service- Stop containerget_docker_status- Check container statuslist_docker_services- List available servicesget_docker_logs- View container logsget_gpu_status- GPU memory usageget_full_status- Comprehensive system status
create_tunnel- Create public URL for local portstop_tunnel- Stop tunnellist_tunnels- List active tunnels
Start TRELLIS.2 and ComfyUI for AI-powered 3D model generation:
# Start TRELLIS.2 (image-to-3D)
docker compose --profile trellis up -d
# Start ComfyUI (text-to-image)
docker compose --profile diffusion up -d
# Or start both
docker compose --profile full up -d- ComfyUI generates image from text prompt (Z-Image Turbo)
- TRELLIS.2 converts image to 3D mesh (GLB)
- Optionally imports into FreeCAD
generate_3d_from_text(
prompt="a wooden dining chair",
import_to_freecad=True
)Start the inference container for VLM and SAM capabilities:
docker compose --profile vision up -d- Analyze CAD models with natural language
- Validate designs against requirements
- Get improvement suggestions
- Analyze spinning videos of 3D models
- Segment features by clicking points
- Measure feature areas
- Highlight specific features
segment_and_analyze- Colorize regions with SAM, then have VLM describe eachsegment_grid- Auto-detect regions using grid samplingsegment_points- Segment specific points with labelsidentify_and_segment- Two-pass: VLM identifies features, SAM segments, VLM analyzes- Automatic container and model lifecycle management
| Variable | Default | Description |
|---|---|---|
FREECAD_HOST |
localhost | FreeCAD container hostname |
FREECAD_PORT |
9875 | XML-RPC port |
INFERENCE_HOST |
localhost | Inference container hostname |
INFERENCE_PORT |
5555 | ZMQ port |
ENABLE_TUNNEL |
true | Enable Cloudflare Quick Tunnel |
VLM_QUANTIZATION |
4bit | VLM quantization (4bit, 8bit, none) |
The system auto-detects GPU configuration:
- Single 48GB+ GPU: Full precision models
- Dual 24GB GPUs: VLM on GPU 0 (4-bit), SAM on GPU 1
GPU Memory Usage:
| Service | VRAM | Default GPU |
|---|---|---|
| TRELLIS.2 | ~20-24GB | cuda:1 (auto-selects) |
| ComfyUI | ~8GB | cuda:0 |
| VLM (4-bit) | ~5GB | cuda:0 |
| SAM | ~2.5GB | cuda:1 |
Use get_gpu_status() to check memory before starting services.
freecad_mcp/
├── src/
│ ├── mcp_server.py # Main MCP server (57 tools)
│ ├── cache_manager.py # Session-based file caching
│ ├── freecad_client.py # FreeCAD XML-RPC client
│ ├── docker_client.py # Docker service management
│ ├── tunnel_client.py # Cloudflare tunnel management
│ ├── segmentation_pipeline.py # SAM + VLM combined analysis
│ ├── trellis_client.py # TRELLIS.2 HTTP client
│ ├── diffusion_client.py # ComfyUI HTTP client
│ ├── inference_client.py # Vision AI ZMQ client
│ ├── debug_interface.py # Gradio web interface
│ └── code_security.py # Code execution safety
├── docker/
│ ├── freecad/
│ │ ├── Dockerfile
│ │ ├── rpc_server.py # FreeCAD XML-RPC server
│ │ └── render_video.py # Headless video rendering
│ ├── inference/
│ │ ├── Dockerfile
│ │ └── server.py # Vision AI ZMQ server
│ ├── trellis/
│ │ ├── Dockerfile
│ │ └── server.py # TRELLIS.2 HTTP server
│ └── diffusion/
│ └── Dockerfile # ComfyUI + workflows
├── cache/ # Output files (auto-managed, 1GB limit)
│ └── session_YYYYMMDD_HHMMSS/
├── data/
│ └── trellis/outputs/ # Generated 3D meshes
├── tests/
├── docker-compose.yml
└── pyproject.toml
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Type checking
mypy src/
# Linting
ruff check src/The execute_code tool has security checks to prevent:
- Dangerous module imports (os, subprocess, etc.)
- File system operations
- Network access
- FreeCAD session termination
For advanced operations, review the code security policy in src/code_security.py.
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests (
pytest) - Run linting (
ruff check src/) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Clone the repository
git clone https://github.com/YOUR_USERNAME/freecad-mcp.git
cd freecad-mcp
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install with dev dependencies
pip install -e ".[dev]"
# Configure MCP server
cp .mcp.json.example .mcp.json
# Edit .mcp.json and set "cwd" to your absolute path (e.g., /home/user/freecad-mcp)
# Start FreeCAD container
docker compose up freecad -d
# Run tests
pytestThis project is licensed under the MIT License - see the LICENSE file for details.