freecad mcp
A FreeCAD addon that implements the Model Context Protocol (MCP) to enable communication between FreeCAD and Claude AI through Claude Desktop.
A FreeCAD addon that implements the Model Context Protocol (MCP) to enable communication between FreeCAD and Claude AI through Claude Desktop.
x000D
x000D The FreeCAD MCP (Model Control Protocol) provides a simplified interface for interacting with FreeCAD through a server-client architecture. This allows users to execute commands and retrieve information about the current FreeCAD document and scene.x000D x000D https://github.com/user-attachments/assets/5acafa17-4b5b-4fef-9f6c-617e85357d44_x000D_
x000D
To configure the MCP server, you can use a JSON format to specify the server settings. Below is an example configuration:x000D
x000D
json_x000D_
{_x000D_
"mcpServers": {_x000D_
"freecad": {_x000D_
"command": "C:ProgramDataanaconda3python.exe",_x000D_
"args": [_x000D_
"C:UsersUSERAppDataRoamingFreeCADModfreecad_mcpsrcfreecad_bridge.py"_x000D_
]_x000D_
}_x000D_
}_x000D_
}_x000D_
x000D
x000D
x000D
- command: The path to the Python executable that will run the FreeCAD MCP server. This can vary based on your operating system:x000D
- Windows: Typically, it might look like C:ProgramDataanaconda3python.exe
or C:Python39python.exe
.x000D
- Linux: It could be /usr/bin/python3
or the path to your Python installation.x000D
- macOS: Usually, it would be /usr/local/bin/python3
or the path to your Python installation.x000D
x000D
- args: An array of arguments to pass to the Python command. The first argument should be the path to the freecad_bridge.py
script, which is responsible for handling the MCP server logic. Make sure to adjust the path according to your installation.x000D
x000D
x000D
json_x000D_
{_x000D_
"mcpServers": {_x000D_
"freecad": {_x000D_
"command": "C:ProgramDataanaconda3python.exe",_x000D_
"args": [_x000D_
"C:UsersUSERAppDataRoamingFreeCADModfreecad_mcpsrcfreecad_bridge.py"_x000D_
]_x000D_
}_x000D_
}_x000D_
}_x000D_
x000D
x000D
json_x000D_
{_x000D_
"mcpServers": {_x000D_
"freecad": {_x000D_
"command": "/usr/bin/python3",_x000D_
"args": [_x000D_
"/home/USER/.FreeCAD/Mod/freecad_mcp/src/freecad_bridge.py"_x000D_
]_x000D_
}_x000D_
}_x000D_
}_x000D_
x000D
x000D
json_x000D_
{_x000D_
"mcpServers": {_x000D_
"freecad": {_x000D_
"command": "/usr/local/bin/python3",_x000D_
"args": [_x000D_
"/Users/USER/Library/Preferences/FreeCAD/Mod/freecad_mcp/src/freecad_bridge.py"_x000D_
]_x000D_
}_x000D_
}_x000D_
}_x000D_
x000D
x000D
x000D The FreeCAD MCP currently supports the following functionalities:x000D x000D
get_scene_info
x000Dx000D - Description: Retrieves comprehensive information about the current FreeCAD document, including:x000D - Document properties (name, label, filename, object count)x000D - Detailed object information (type, position, rotation, shape properties)x000D - Sketch data (geometry, constraints)x000D - View information (camera position, direction, etc.)x000D x000D
run_script
x000Dx000D - Description: Executes arbitrary Python code within the FreeCAD context. This allows users to perform complex operations, create new objects, modify existing ones, and automate tasks using FreeCAD's Python API.x000D x000D
x000D To use the FreeCAD MCP, you can connect to the server and send commands as follows:x000D x000D ```python_x000D_ import socket_x000D_ import json_x000D_ x000D
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)x000D client.connect(('localhost', 9876))x000D x000D
command = {x000D "type": "get_scene_info"x000D }x000D client.sendall(json.dumps(command).encode('utf-8'))x000D x000D
response = client.recv(4096)x000D print(json.loads(response.decode('utf-8')))x000D x000D
script = """x000D import FreeCAD_x000D_ doc = FreeCAD.ActiveDocument_x000D_ box = doc.addObject("Part::Box", "MyBox")x000D box.Length = 20_x000D_ box.Width = 20_x000D_ box.Height = 20_x000D_ doc.recompute()x000D """x000D command = {x000D "type": "run_script",x000D "params": {x000D "script": script_x000D_ }x000D }x000D client.sendall(json.dumps(command).encode('utf-8'))x000D x000D
response = client.recv(4096)x000D print(json.loads(response.decode('utf-8')))x000D x000D
client.close()x000D ```x000D x000D
x000D
1. Clone the repository or download the files.x000D
2. Place the freecad_mcp
directory in your FreeCAD modules directory:x000D
- Windows: %APPDATA%/FreeCAD/Mod/
x000D
- Linux: ~/.FreeCAD/Mod/
x000D
- macOS: ~/Library/Preferences/FreeCAD/Mod/
x000D
3. Restart FreeCAD and select the "FreeCAD MCP" workbench from the workbench selector.x000D
x000D
x000D Feel free to contribute by submitting issues or pull requests. Your feedback and contributions are welcome!x000D x000D
x000D This project is licensed under the MIT License. See the LICENSE file for details.x000D