FreeCAD
STDIOFreeCAD MCP插件实现自动化建模执行
FreeCAD MCP插件实现自动化建模执行
The FreeCAD MCP plugin integrates the Model Control Protocol (MCP) into FreeCAD, enabling automation of model creation, macro execution, and view management through a server-client architecture. It provides a GUI control panel and a command-line client to streamline FreeCAD workflows, supporting tasks like creating/running macros, adjusting views, and integrating with external tools (e.g., Claude, Cursor, Trace, CodeBuddy).
The FreeCAD MCP plugin (v0.1.0) offers the following features:
FreeCADMCPPanel) and processes commands like create_macro, update_macro, run_macro, set_view, and get_report (implemented in freecad_mcp_server.py).stdio or TCP, manage .FCMacro files (create, update, run, validate), and control FreeCAD remotely (implemented in freecad_mcp_client.py).FreeCAD, FreeCADGui, Part, math) and post-execution steps (recompute, view adjustment) for macros.freecad_mcp_log.txt in the temporary directory (e.g., %TEMP%\freecad_mcp_log.txt) and a GUI report browser (100-line limit).FreeCADMCPWorkbench with toolbar and menu commands (implemented in InitGui.py).icon.svg), example models (gear.png, flange.png, boat.png, table.png), and demo animation (freecad.gif, freecad.mp4).Watch the demo animation:
Download the demo video: FreeCAD MCP Demo MP4
FreeCAD MCP workbench.FreeCAD_MCP_Show) and click "Start Server."python D:\FreeCAD\Mod\FreeCAD-MCP-main\src\freecad_mcp_client.py --run-macro gear.FCMacro --params '{"radius": 15}'
mcp-server>=1.2.0, httpx>=0.24.1 (specified in pyproject.toml).# Create and activate Anaconda environment conda create -n freecad_mcp python=3.8 conda activate freecad_mcp pip install mcp-server>=1.2.0 httpx>=0.24.1 # Or use system Python python -m pip install mcp-server>=1.2.0 httpx>=0.24.1
Ensurepip show mcp-server httpx
mcp-server version is >=1.2.0 and httpx version is >=0.24.1.Clone the Repository:
git clone https://github.com/ATOI-Ming/FreeCAD-MCP.git
Copy to FreeCAD Mod Directory:
Copy the FreeCAD-MCP folder to:
D:\FreeCAD\Mod\FreeCAD-MCP~/.local/share/FreeCAD/Mod/FreeCAD-MCP~/Library/Application Support/FreeCAD/Mod/FreeCAD-MCP# Windows example xcopy FreeCAD-MCP D:\FreeCAD\Mod\FreeCAD-MCP /E /H /C /I
Note: Adjust D:\FreeCAD\Mod based on your FreeCAD installation path.
Launch FreeCAD:
FreeCAD MCP workbench (icon: assets/icon.svg).FreeCAD-MCP is loaded in Edit > Preferences > Add-ons.Verify Installation:
FreeCAD_MCP_Show to open the control panel.%TEMP%\freecad_mcp_log.txt) for startup messages.Configure the MCP client to communicate with FreeCAD via stdio or TCP.
Create Configuration File:
Create mcp_config.json in D:\FreeCAD\Mod\FreeCAD-MCP-main\src\:
{ "mcpServers": { "freecad": { "disabled": false, "timeout": 60, "type": "stdio", "command": "D:\\Anaconda3\\python.exe", "args": ["D:\\FreeCAD\\Mod\\FreeCAD-MCP-main\\src\\freecad_mcp_client.py"] } } }
Note:
C:\Anaconda3\python.exe (Windows), /home/<user>/anaconda3/bin/python (Linux), /Users/<user>/anaconda3/bin/python (macOS).C:\Users\<YourUser>\AppData\Roaming\FreeCAD\Mod\FreeCAD-MCP (Windows), /home/<user>/.local/share/FreeCAD/Mod/FreeCAD-MCP (Linux), /Users/<user>/Library/Application Support/FreeCAD/Mod/FreeCAD-MCP (macOS)."type": "tcp", add "host": "localhost", and "port": 9876.Run the Server:
FreeCAD MCP workbench, click FreeCAD_MCP_Show and then "Start Server."conda activate freecad_mcp python D:\FreeCAD\Mod\FreeCAD-MCP-main\src\freecad_mcp_server.py
Verify Server:
%TEMP%\freecad_mcp_log.txt for a "Server started" message.python D:\FreeCAD\Mod\FreeCAD-MCP-main\src\freecad_mcp_client.py --get-report
FreeCAD MCP workbench (icon: assets/icon.svg).FreeCAD_MCP_Show to open the control panel (FreeCADMCPPanel).%TEMP%\freecad_mcp_log.txt.FreeCAD_MCP_RunMacro, select an .FCMacro file, and execute it with automatic normalization.conda activate freecad_mcp
Examples:python D:\FreeCAD\Mod\FreeCAD-MCP-main\src\freecad_mcp_client.py <command>
--create-macro my_macro --template-type part--run-macro my_macro.FCMacro --params '{"radius": 10}'--set-view '{"view_type": "7"}'--get-reportThe following tool functions are provided by freecad_mcp_client.py, sending commands via stdio or TCP (localhost:9876), processed by freecad_mcp_server.py.
| Function | Parameters | Description | 
|---|---|---|
create_macro | macro_name, template_type | Creates an .FCMacro file, validates name (letters, numbers, underscores, hyphens), supports templates (default, basic, part, sketch). | 
update_macro | macro_name, code | Updates macro content, auto-adds FreeCAD, FreeCADGui, Part, math imports. | 
run_macro | macro_path, params (optional) | Runs a macro, normalizes code, recomputes document, adjusts to axonometric view. | 
validate_macro_code | macro_name (optional), code (optional) | Validates macro code syntax, returns success or error (with traceback). | 
set_view | params (e.g., {"view_type": "7"}) | Sets view: 1 (front), 2 (top), 3 (right), 7 (axonometric). | 
get_report | None | Retrieves server logs (from %TEMP%\freecad_mcp_log.txt and report browser). | 
Create Macro:
python D:\FreeCAD\Mod\FreeCAD-MCP-main\src\freecad_mcp_client.py --create-macro gear --template-type part
Output: {"status": "success", "result": "Macro created"}
Update Macro:
python D:\FreeCAD\Mod\FreeCAD-MCP-main\src\freecad_mcp_client.py --update-macro gear --code "import FreeCAD, Part\nradius = 10\ngear = Part.makeCylinder(radius, 5)\nPart.show(gear)"
Output: {"status": "success", "result": "Macro updated"}
Run Macro:
python D:\FreeCAD\Mod\FreeCAD-MCP-main\src\freecad_mcp_client.py --run-macro gear.FCMacro --params '{"radius": 15}'
Output: {"status": "success", "result": {...}}
Validate Code:
python D:\FreeCAD\Mod\FreeCAD-MCP-main\src\freecad_mcp_client.py --validate-macro-code gear --code "import FreeCAD\nApp.newDocument()"
Output: {"status": "success"}
Set View:
python D:\FreeCAD\Mod\FreeCAD-MCP-main\src\freecad_mcp_client.py --set-view '{"view_type": "7"}'
Output: {"status": "success", "result": "view set to axonometric"}
Get Report:
python D:\FreeCAD\Mod\FreeCAD-MCP-main\src\freecad_mcp_client.py --get-report
Output: {"status": "success", "result": {...}}
Automated Gear Model Creation:
--create-macro gear --template-type part--update-macro gear --code "import FreeCAD, Part\nradius = 15\ngear = Part.makeCylinder(radius, 5)\nPart.show(gear)"--run-macro gear.FCMacro --params '{"radius": 15}'
Generating a Flange Model:
--run-macro flange.FCMacro
Text-Based Model Generation:
boat.FCMacro.--run-macro boat.FCMacro
CAD Drawing Recognition:
table.FCMacro.--run-macro table.FCMacro
Batch Processing Models:
for macro in gear.FCMacro flange.FCMacro; do python D:\FreeCAD\Mod\FreeCAD-MCP-main\src\freecad_mcp_client.py --run-macro $macro done
%TEMP%\freecad_mcp_log.txt.gear.png and flange.png.FreeCAD MCP supports integration with external tools to enhance model generation:
.FCMacro files from text descriptions.
Save asimport FreeCAD, Part radius = 10 gear = Part.makeCylinder(radius, 5) Part.show(gear)
gear.FCMacro, run: --run-macro gear.FCMacro..FCMacro files.
table.FCMacro, run: --run-macro table.FCMacro.flange.FCMacro in Cursor, update: --update-macro flange.FCMacro --code "<code>".The assets/ directory contains the following resources:
FreeCADMCPWorkbench, used in InitGui.py and package.xml.





netstat -ano | findstr 9876), change port, or terminate conflicting process.mcp_config.json.command and args paths, e.g., D:\Anaconda3\python.exe and D:\FreeCAD\Mod\FreeCAD-MCP-main\src\freecad_mcp_client.py.--validate-macro-code to check code, review traceback in %TEMP%\freecad_mcp_log.txt.%TEMP%\freecad_mcp_log.txt, or specify another path in freecad_mcp_server.py.Contributions are welcome! Follow these steps:
https://github.com/ATOI-Ming/FreeCAD-MCP.git checkout -b feature/your-feature.git commit -m "Add your feature".Please adhere to the Code of Conduct (to be added, see CODE_OF_CONDUCT.md).
This project is licensed under the MIT License. See LICENSE for details.