local-only server
The server can only run on the client’s local machine because it depends on local resources.
Integrations
Enables interaction with FreeCAD CAD software through a standardized interface, offering tools for 3D model creation, manipulation, measurement, and export. Includes specialized smithery tools for blacksmithing designs, primitive shape generation, boolean operations, and model transformation capabilities.
🛠️ MCP-FreeCAD Integration
Note: This repository is under heavy development. Expect daily commits and potential breaking changes.
This project provides a robust integration between AI assistants and FreeCAD CAD software using the Model Context Protocol (MCP). It allows external applications to interact with FreeCAD through a standardized interface, offering multiple connection methods and specialized tools.
Quick Start (Recommended: AppImage + Launcher)
For the most reliable setup, follow these steps:
- Setup Environment (One-time): Run the setup script. This clones the repository to
~/.mcp-freecad
, creates a Python virtual environment, downloads the latest stable FreeCAD AppImage, extracts it, and configures the server to use it.Alternatively, clone the repo and runCopy./scripts/bin/setup_freecad_env.sh
manually. - Run the MCP Server: Use the installer script (which now just ensures the venv is active and runs the server) or the global command if installed.Copy
This starts the MCP server using the recommended launcher
method with the downloaded and extracted AppImage.
Docker Support
You can also run MCP-FreeCAD in a Docker container for easier deployment and isolation.
Running with Docker Compose
- Start the container:Copy
- Build from scratch (if you've made changes):Copy
The Docker container exposes the following ports:
- 8080: MCP server
- 12345: FreeCAD server
Docker Configuration
The Docker setup consists of:
Dockerfile
: Defines the container with Python 3.12, installs dependencies, and sets up the environmentdocker-compose.yml
: Configures the service, ports, volumes, and restart policies.dockerignore
: Excludes unnecessary files from the container
This approach is especially useful for CI/CD pipelines or when you need to isolate the MCP-FreeCAD environment from your system.
🔄 MCP Flow Chart
This flowchart shows the main components and how different connection methods selected by freecad_connection.py
lead to various ways of executing commands within FreeCAD. The launcher
method, often used with extracted AppImages via AppRun
, is the recommended approach for reliability.
For more detailed flowcharts, see FLOWCHART.md.
🔄 Core Components
1. FreeCAD MCP Server (freecad_mcp_server.py
)
- Description: The main server implementing the Model Context Protocol. It acts as the central hub for AI assistants or other clients to communicate with FreeCAD via MCP.
- Features:
- Handles standard MCP requests (
mcp/listTools
,mcp/executeTool
). - Utilizes
FreeCADConnection
to interact with FreeCAD using the configured method. - Exposes various toolsets (primitives, manipulation, export, etc.) based on configuration.
- Configurable via
config.json
.
- Handles standard MCP requests (
- Usage:Copy
2. FreeCAD Connection (freecad_connection.py
)
- Description: A unified Python interface encapsulating the logic for connecting to FreeCAD. Used internally by the MCP server and available for direct scripting.
- Features:
- Intelligently selects the best connection method based on configuration and availability.
- Methods:
- Launcher: (Recommended) Uses
freecad_launcher.py
andAppRun
. - Wrapper: Uses
freecad_wrapper.py
andfreecad_subprocess.py
. - Server: Connects to a running
freecad_server.py
via sockets. - Bridge: Uses the FreeCAD CLI via
freecad_bridge.py
. - Mock: Simulates FreeCAD for testing.
- Auto: Tries methods in recommended order (launcher > wrapper > server > bridge > mock).
- Launcher: (Recommended) Uses
- Usage (Direct Scripting Example):Copy
3. FreeCAD Launcher (freecad_launcher.py
)
- Description: Handles launching the FreeCAD environment, typically using
AppRun
from an extracted AppImage. It executesfreecad_script.py
within the launched environment. - Features:
- Manages the subprocess execution of FreeCAD/AppRun.
- Passes commands and parameters to the internal FreeCAD script.
- Parses JSON results from the script's output.
- Usage: Primarily used internally by
FreeCADConnection
when thelauncher
method is selected (configured inconfig.json
). Not typically run directly by the user.
4. FreeCAD Wrapper (freecad_wrapper.py
) & Subprocess (freecad_subprocess.py
)
- Description: The
freecad_wrapper.py
startsfreecad_subprocess.py
in a separate Python process.freecad_subprocess.py
imports FreeCAD modules and communicates with the wrapper via stdio pipes. - Features:
- Isolates FreeCAD module imports into a dedicated process.
- Provides an alternative connection method if direct module imports are feasible but AppRun/launcher is problematic.
- Usage: Used internally by
FreeCADConnection
when thewrapper
method is selected (configured inconfig.json
). Requires a Python environment where the subprocess can successfullyimport FreeCAD
.
5. FreeCAD Server (freecad_server.py
)
- Description: A standalone socket server designed to run inside a FreeCAD instance. Listens for connections from
FreeCADConnection
. - Features:
- Allows connection to a potentially persistent FreeCAD instance.
- Can interact with the GUI if run in
--connect
mode.
- Usage (Manual Start within FreeCAD):RequiresCopy
connection_method: server
inconfig.json
for the MCP Server to connect. (Seedocs/FREECAD_SERVER_SETUP.md
)
6. FreeCAD Bridge (freecad_bridge.py
)
- Description: Enables command-line interaction with the FreeCAD executable. Bypasses direct module import issues but can be slower.
- Features:
- Executes FreeCAD commands via subprocess calls to the
freecad
executable.
- Executes FreeCAD commands via subprocess calls to the
- Usage: Used internally by
FreeCADConnection
when thebridge
method is selected (configured inconfig.json
). Requiresfreecad
to be in the system PATH or thepath
correctly set in config.
7. FreeCAD Client (freecad_client.py
)
- Description: A command-line utility for interacting directly with the
FreeCADConnection
interface (for testing/debugging connection methods, not the MCP server). - Features:
- Allows testing specific
FreeCADConnection
commands (e.g., creating primitives, getting version) from the terminal. - Uses
config.json
to determine connection settings.
- Allows testing specific
- Usage Examples:Copy
🔄 Project Structure
The MCP-FreeCAD project is organized with the following directory structure:
For more details on scripts, see scripts/README.md.
⚙️ Installation & Setup Details
This section provides more details on the different installation and setup options.
Recommended Setup: AppImage + Launcher (Detailed Steps)
This involves two main scripts:
scripts/bin/setup_freecad_env.sh
: Prepares the environment.- Clones or updates the repository to
~/.mcp-freecad
. - Creates/updates a Python virtual environment (
.venv
) and installs requirements. - Runs
download_appimage.py
to fetch the latest stable FreeCAD Linux AppImage into~/.mcp-freecad
. - Runs
extract_appimage.py
which:- Extracts the downloaded AppImage to
~/.mcp-freecad/squashfs-root
. - Updates
~/.mcp-freecad/config.json
to useconnection_method: launcher
anduse_apprun: true
with correct absolute paths.
- Extracts the downloaded AppImage to
- How to run:
curl -sSL <URL>/setup_freecad_env.sh | bash
or./scripts/bin/setup_freecad_env.sh
- Clones or updates the repository to
scripts/bin/mcp-freecad-installer.sh
: Runs the server.- Note: Despite the name, this script no longer performs the full installation. It primarily ensures the repository is up-to-date, activates the virtual environment, and starts
freecad_mcp_server.py
. - It assumes the environment (AppImage download/extraction) has been prepared by
setup_freecad_env.sh
or manually. - How to run:
~/.mcp-freecad/scripts/bin/mcp-freecad-installer.sh
ormcp-freecad
(global command).
- Note: Despite the name, this script no longer performs the full installation. It primarily ensures the repository is up-to-date, activates the virtual environment, and starts
Other Installation Methods
Global Installation (install-global.sh
)
- Creates a symbolic link
mcp-freecad
in/usr/local/bin
pointing tomcp-freecad-installer.sh
in the repo. - Allows running
mcp-freecad
from anywhere. - Requires the environment to be set up first using
setup_freecad_env.sh
if you want to use the recommended launcher method.
Manual Installation
- Clone the repo.
- Create venv, install requirements.
- Manually download and extract AppImage: Run
python download_appimage.py
andpython extract_appimage.py /path/to/downloaded.AppImage
yourself. - Run the server:
python freecad_mcp_server.py
.
🚀 Using the MCP Server
This is the primary way to interact with FreeCAD using AI assistants like Claude.
Starting the MCP Server
The server will run and listen for connections from MCP clients.
Connecting an MCP Client
Use any MCP-compatible client. Example using the reference mcp client
:
Or using uv
if you have a client script like the one in the MCP docs:
Alternative: Starting FreeCAD with Integrated Server
You can also start FreeCAD with the integrated server using:
This will launch FreeCAD and automatically start the server inside it.
MCP Server Configuration (config.json
)
The config.json
file controls various aspects of the server. Here is an example reflecting the recommended launcher setup after running extract_appimage.py
:
Note: Replace example paths with your actual absolute paths.
See FREECAD_INTEGRATION.md for more details on integration options.
🛠️ Available MCP Tools
The MCP server exposes various tool groups. Here are all available tools:
📐 Basic FreeCAD Tools (freecad.*
)
freecad.create_document
: Create a new documentfreecad.export_stl
: Export the model or specific objects to STLfreecad.import_stl
: Import STL files into the current documentfreecad.save_document
: Save the current documentfreecad.load_document
: Load an existing document
🔧 Model Manipulation Tools (model_manipulation.*
)
model_manipulation.rotate
: Rotate objects around specified axesmodel_manipulation.translate
: Move objects in 3D spacemodel_manipulation.scale
: Scale objects uniformly or non-uniformlymodel_manipulation.mirror
: Mirror objects across specified planesmodel_manipulation.union
: Combine multiple objects using boolean unionmodel_manipulation.cut
: Cut objects using boolean differencemodel_manipulation.intersect
: Create intersection of multiple objects
📏 Measurement Tools (measurement.*
)
measurement.distance
: Measure distance between two pointsmeasurement.angle
: Measure angle between three pointsmeasurement.area
: Calculate surface area of objectsmeasurement.volume
: Calculate volume of solid objectsmeasurement.mass
: Calculate mass of objects (requires material properties)
📦 Primitives Tools (primitives.*
)
primitives.create_box
: Create a rectangular boxprimitives.create_cylinder
: Create a cylinderprimitives.create_sphere
: Create a sphereprimitives.create_cone
: Create a coneprimitives.create_torus
: Create a torusprimitives.create_polygon
: Create a regular polygonprimitives.create_ellipse
: Create an ellipse
🔄 Export/Import Tools (export_import.*
)
export_import.export_step
: Export to STEP formatexport_import.import_step
: Import from STEP formatexport_import.export_iges
: Export to IGES formatexport_import.import_iges
: Import from IGES formatexport_import.export_dxf
: Export to DXF formatexport_import.import_dxf
: Import from DXF format
💻 Code Generation Tools (code_generator.*
)
code_generator.generate_python
: Generate Python code for the current modelcode_generator.generate_openscad
: Generate OpenSCAD code for the current modelcode_generator.generate_gcode
: Generate G-code for CNC machiningcode_generator.generate_3d_print
: Generate optimized 3D printing settings
📝 Example MCP Interactions
Here are conceptual examples of using the MCP server with an AI assistant:
Creating and Exporting a Box
🔍 Troubleshooting
- MCP Server Connection Issues:
- Ensure
python src/mcp_freecad/server/freecad_mcp_server.py
can run without immediate errors. Check terminal output. - Check firewall settings if relevant (unlikely for
stdio
). - Verify
config.json
is valid JSON.
- Ensure
- FreeCAD Connection Issues (Especially with
launcher
method):- Run
extract_appimage.py
: Ensure the AppImage was extracted correctly andconfig.json
was updated. - Check
config.json
Paths: Verify all absolute paths in thefreecad
section are correct for your system. - Check Permissions: Ensure
squashfs-root/AppRun
has execute permissions (chmod +x
). - Check Logs: Examine
mcp_freecad.log
(created in the project root if logging starts),freecad_server_stdout.log
, andfreecad_server_stderr.log
for errors fromfreecad_launcher.py
,AppRun
, or the FreeCAD process itself. - Environment Variables: If
AppRun
fails to find libraries, ensureLD_LIBRARY_PATH
andPYTHONPATH
are correctly set, potentially within.cursor/mcp.json
if using Cursor, or exported manually if testing in the terminal. Theextract_appimage.py
script aims to make this less necessary, but it can be a factor. - Headless Issues: Sometimes FreeCAD has issues running completely headless (
QT_QPA_PLATFORM=offscreen
). Check logs for GUI-related errors.
- Run
server
method: Ensurefreecad_server.py
is running inside an active FreeCAD instance, listening on the correct host/port configured inconfig.json
.bridge
method: Verify FreeCAD is installed system-wide and thefreecad
command works in your terminal. Check thefreecad_path
inconfig.json
.- Missing MCP SDK: Install via
pip install modelcontextprotocol
. - Python Path Issues: If FreeCAD modules aren't found when not using the recommended AppImage setup, refer to PYTHON_INTERPRETER_SETUP.md.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🖥️ Cursor Integration
The MCP server is designed for integration with tools like Cursor IDE.
- Configure Cursor: Add the MCP server in Cursor's settings (Settings > Features > MCP Servers > Add New MCP Server). Configure it to run the Python script directly, setting the necessary environment variables and working directory. An example configuration in
.cursor/mcp.json
would look like this:ReplaceCopy/path/to/mcp-freecad
with the actual absolute path to your project. Ensure theLD_LIBRARY_PATH
andPYTHONPATH
match your AppImage structure if needed. - Restart Cursor: Fully restart Cursor for the configuration changes to take effect.
- Server Communication: The server uses
stdio
transport by default (configured inconfig.json
underserver.mcp.transport
), which is compatible with Cursor's communication protocol. Errors should be reported back to Cursor via MCP error responses.
Cursor-Specific Considerations
- The
freecad_mcp_server.py
script loadsconfig.json
by default. Ensure this file contains the correct settings, especially thefreecad
section updated byextract_appimage.py
. - The environment variables set in
.cursor/mcp.json
are crucial for allowing thelauncher
method to work correctly within the environment Cursor provides.
📋 Available Options and Use Cases
🔧 Connection Methods
- Launcher Connection (Recommended)
- Uses
AppRun
from an extracted AppImage. Most reliable. - Configured automatically by
extract_appimage.py
. - Configuration (
config.json
):
Copy - Uses
- Wrapper Connection
- Runs FreeCAD logic in a separate Python subprocess. Good alternative if AppImage/AppRun causes issues.
- Configuration (
config.json
):
Copy - Socket Server Connection
- Requires running
freecad_server.py
inside FreeCAD. - Use when running FreeCAD as a persistent background server.
- Configuration (
config.json
):
Copy - Requires running
- CLI Bridge Connection
- Uses the
freecad
command-line tool. Can be slower/less reliable. - Configuration (
config.json
):
Copy - Uses the
- Mock Connection
- For testing without FreeCAD.
- Configuration (
config.json
):
Copy - Auto Connection
- Automatically selects the best available method (launcher > wrapper > server > bridge > mock).
- Default if
connection_method
is missing or set to"auto"
.
🛠️ Tool Categories and Use Cases
- Basic FreeCAD Operations
- Essential document management
- Use cases:
- Creating new documents
- Saving and loading projects
- Exporting to various formats
- Managing document structure
- Model Manipulation
- Transforming and modifying objects
- Use cases:
- Rotating objects precisely
- Moving objects in 3D space
- Scaling models
- Creating mirrors and copies
- Boolean operations (union, cut, intersect)
- Measurement Tools
- Analysis and verification
- Use cases:
- Distance measurements
- Angle calculations
- Surface area analysis
- Volume calculations
- Mass properties
- Primitive Creation
- Basic shape generation
- Use cases:
- Creating boxes and cylinders
- Generating spheres
- Making cones and tori
- Creating regular polygons
- Drawing ellipses
- Export/Import Operations
- File format conversion
- Use cases:
- STEP file export/import
- IGES format handling
- DXF file processing
- STL export for 3D printing
- Code Generation
- Automated code creation
- Use cases:
- Python script generation
- OpenSCAD code export
- G-code generation for CNC
- 3D printer settings optimization
💻 Integration Scenarios
- Cursor IDE Integration
- Development environment integration
- Use cases:
- Direct model manipulation from IDE
- Real-time feedback
- Debug logging
- Error tracking
- AI Assistant Integration
- AI-powered design automation
- Use cases:
- Natural language model creation
- Automated design modifications
- Parameter optimization
- Design validation
- Command Line Usage
- Scripting and automation
- Use cases:
- Batch processing
- Automated testing
- CI/CD integration
- Command-line tools
🎯 Common Use Case Examples
- Rapid Prototyping
- Automated Processing
⚙️ Configuration Options
- Server Configuration
- Tool Enablement
- Debug Configuration
Features
- Connect AI assistants to FreeCAD through the MCP protocol
- Create and manipulate 3D models programmatically
- Support for primitive shapes (box, cylinder, sphere, cone)
- Boolean operations (union, intersection, cut)
- Object transformations (move, rotate)
- Export models to STL format
- Document and object management
Prerequisites
- Python 3.8 or newer
- MCP SDK (
pip install modelcontextprotocol
) - Recommended: A FreeCAD AppImage (downloaded and extracted using
extract_appimage.py
) for the reliablelauncher
connection method. - Alternatively: A system installation of FreeCAD 0.20+ (for
bridge
orserver
methods, potentially less reliable).
Available Tools
Document Management
- freecad.create_document - Create a new FreeCAD document
- freecad.list_documents - List all open documents
- freecad.list_objects - List all objects in a document
3D Primitives
- freecad.create_box - Create a box primitive
- freecad.create_cylinder - Create a cylinder primitive
- freecad.create_sphere - Create a sphere primitive
- freecad.create_cone - Create a cone primitive
Boolean Operations
- freecad.boolean_union - Create a union of two objects (add)
- freecad.boolean_cut - Cut the second object from the first (subtract)
- freecad.boolean_intersection - Create the intersection of two objects (common volume)
Transformations
- freecad.move_object - Move an object to a new position
- freecad.rotate_object - Rotate an object
Export
- freecad.export_stl - Export the model to an STL file
Testing
The project includes both unit tests and end-to-end (E2E) tests to ensure quality and reliability.
Unit Tests
To run the basic unit tests:
End-to-End Tests
End-to-end tests verify that the entire system works correctly from the client's perspective. They test real-world scenarios and interactions between different components.
To run all E2E tests:
The E2E tests are organized by functionality:
test_primitives.py
- Tests for basic shape creation and manipulationtest_smithery.py
- Tests for blacksmithing tool operations
Writing New E2E Tests
To add new E2E tests:
- Create a new test file in the
tests/e2e/
directory - Extend the appropriate base test class (
MCPClientTestBase
) - Add test methods that use the MCP client to interact with the tools
- Run your tests with the test runner
See existing test files for examples.
Documentation
The project includes several documentation files for different aspects:
- PYTHON_INTERPRETER_SETUP.md - How to configure the Python interpreter
- FREECAD_SERVER_SETUP.md - Server setup guide
- FREECAD_INTEGRATION.md - FreeCAD integration methods
- FLOWCHART.md - Detailed flow diagrams
- OPTIMIZATION_FEATURES.md - Performance optimization guide
- scripts/README.md - Scripts documentation
For AI assistants, please refer to the AI_ASSISTANT_GUIDE.md for detailed usage instructions and examples.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
- FreeCAD development team for the amazing CAD software
- Anthropic and Claude for the Model Context Protocol (MCP) SDK
This server cannot be installed
This project provides a robust integration between AI assistants and FreeCAD CAD software using the Model Context Protocol (MCP). It allows external applications to interact with FreeCAD through a standardized interface, offering multiple connection methods and specialized tools.
- Quick Start (Recommended: AppImage + Launcher)
- Docker Support
- 🔄 MCP Flow Chart
- 🔄 Core Components
- 1. FreeCAD MCP Server (freecad_mcp_server.py)
- 2. FreeCAD Connection (freecad_connection.py)
- 3. FreeCAD Launcher (freecad_launcher.py)
- 4. FreeCAD Wrapper (freecad_wrapper.py) & Subprocess (freecad_subprocess.py)
- 5. FreeCAD Server (freecad_server.py)
- 6. FreeCAD Bridge (freecad_bridge.py)
- 7. FreeCAD Client (freecad_client.py)
- 🔄 Project Structure
- ⚙️ Installation & Setup Details
- 🚀 Using the MCP Server
- 🛠️ Available MCP Tools
- 📝 Example MCP Interactions
- 🔍 Troubleshooting
- 📄 License
- 🖥️ Cursor Integration
- 📋 Available Options and Use Cases
- Features
- Prerequisites
- Available Tools
- Testing
- Documentation
- Contributing
- Acknowledgments