freecad mcp

Local 2025-08-31 23:46:25 0
Developer Tools @bonninr/freecad_mcp

A FreeCAD addon that implements the Model Context Protocol (MCP) to enable communication between FreeCAD and Claude AI through Claude Desktop.


x000D

Overview_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_

Configuration_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

Configuration Details_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

Example for Different Operating Systems_x000D_

x000D

Windows_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

Linux_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

macOS_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

Features_x000D_

x000D The FreeCAD MCP currently supports the following functionalities:x000D x000D

1. get_scene_infox000D

x000D - 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

2. run_scriptx000D

x000D - 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

Example Usage_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

Connect to the FreeCAD MCP server_x000D_

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)x000D client.connect(('localhost', 9876))x000D x000D

Example: Get scene information_x000D_

command = {x000D "type": "get_scene_info"x000D }x000D client.sendall(json.dumps(command).encode('utf-8'))x000D x000D

Receive the response_x000D_

response = client.recv(4096)x000D print(json.loads(response.decode('utf-8')))x000D x000D

Example: Run a script_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

Receive the response_x000D_

response = client.recv(4096)x000D print(json.loads(response.decode('utf-8')))x000D x000D

Close the connection_x000D_

client.close()x000D ```x000D x000D

Installation_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

Contributing_x000D_

x000D Feel free to contribute by submitting issues or pull requests. Your feedback and contributions are welcome!x000D x000D

License_x000D_

x000D This project is licensed under the MIT License. See the LICENSE file for details.x000D