Skip to main content
Glama
bonninr
by bonninr

FreeCAD MCP(模型控制协议)

概述

FreeCAD MCP(模型控制协议)提供了一个简化的接口,用于通过服务器-客户端架构与 FreeCAD 进行交互。这允许用户执行命令并检索有关当前 FreeCAD 文档和场景的信息。

https://github.com/user-attachments/assets/5acafa17-4b5b-4fef-9f6c-617e85357d44

Related MCP server: freecad mcp

配置

要配置 MCP 服务器,您可以使用 JSON 格式指定服务器设置。以下是示例配置:

{
    "mcpServers": {
        "freecad": {
            "command": "C:\\ProgramData\\anaconda3\\python.exe",
            "args": [
                "C:\\Users\\USER\\AppData\\Roaming\\FreeCAD\\Mod\\freecad_mcp\\src\\freecad_bridge.py"
            ]
        }
    }
}

配置详细信息

  • command :运行 FreeCAD MCP 服务器的 Python 可执行文件的路径。这可能会因操作系统而异:

    • Windows :通常,它可能看起来像C:\\ProgramData\\anaconda3\\python.exeC:\\Python39\\python.exe

    • Linux :它可以是/usr/bin/python3或 Python 安装的路径。

    • macOS :通常,它是/usr/local/bin/python3或 Python 安装的路径。

  • args :传递给 Python 命令的参数数组。第一个参数应为freecad_bridge.py脚本的路径,该脚本负责处理 MCP 服务器逻辑。请务必根据您的安装情况调整路径。

不同操作系统的示例

视窗

{
    "mcpServers": {
        "freecad": {
            "command": "C:\\ProgramData\\anaconda3\\python.exe",
            "args": [
                "C:\\Users\\USER\\AppData\\Roaming\\FreeCAD\\Mod\\freecad_mcp\\src\\freecad_bridge.py"
            ]
        }
    }
}

Linux

{
    "mcpServers": {
        "freecad": {
            "command": "/usr/bin/python3",
            "args": [
                "/home/USER/.FreeCAD/Mod/freecad_mcp/src/freecad_bridge.py"
            ]
        }
    }
}

macOS

{
    "mcpServers": {
        "freecad": {
            "command": "/usr/local/bin/python3",
            "args": [
                "/Users/USER/Library/Preferences/FreeCAD/Mod/freecad_mcp/src/freecad_bridge.py"
            ]
        }
    }
}

特征

FreeCAD MCP 目前支持以下功能:

1. get_scene_info

  • 描述:检索有关当前 FreeCAD 文档的综合信息,包括:

    • 文档属性(名称、标签、文件名、对象数量)

    • 详细的对象信息(类型、位置、旋转、形状属性)

    • 草图数据(几何形状、约束)

    • 查看信息(摄像机位置、方向等)

2. run_script

  • 描述:在 FreeCAD 环境中执行任意 Python 代码。这允许用户使用 FreeCAD 的 Python API 执行复杂的操作、创建新对象、修改现有对象以及自动执行任务。

示例用法

要使用 FreeCAD MCP,您可以连接到服务器并发送以下命令:

import socket
import json

# Connect to the FreeCAD MCP server
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('localhost', 9876))

# Example: Get scene information
command = {
    "type": "get_scene_info"
}
client.sendall(json.dumps(command).encode('utf-8'))

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

# Example: Run a script
script = """
import FreeCAD
doc = FreeCAD.ActiveDocument
box = doc.addObject("Part::Box", "MyBox")
box.Length = 20
box.Width = 20
box.Height = 20
doc.recompute()
"""
command = {
    "type": "run_script",
    "params": {
        "script": script
    }
}
client.sendall(json.dumps(command).encode('utf-8'))

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

# Close the connection
client.close()

安装

  1. 克隆存储库或下载文件。

  2. freecad_mcp目录放在您的 FreeCAD 模块目录中:

    • Windows: %APPDATA%/FreeCAD/Mod/

    • Linux: ~/.FreeCAD/Mod/

    • macOS: ~/Library/Preferences/FreeCAD/Mod/

  3. 重新启动 FreeCAD 并从工作台选择器中选择“FreeCAD MCP”工作台。

贡献

欢迎通过提交问题或拉取请求来贡献代码。欢迎您的反馈和贡献!

执照

本项目遵循 MIT 许可证。详情请参阅 LICENSE 文件。

-
security - not tested
A
license - permissive license
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bonninr/freecad_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server