返回市场
融合360-MCP服务器

融合360-MCP服务器

作者:ArchimedesCrypto47 星标更新:2025-04-11

项目介绍

Fusion 360 MCP Server

这是一个介于Cline和Autodesk Fusion 360之间的模型上下文协议(MCP)服务器。该服务器将Fusion 360工具栏级别的命令暴露为可以直接映射到Fusion API的可调用工具。

🧠 概述

此项目允许Cline:

  • 解析自然语言提示(例如,“创建一个带有圆角的盒子”)
  • 将其解析为Fusion工具操作(例如,CreateSketch → DrawRectangle → Extrude → Fillet)
  • 通过这个MCP服务器调用这些工具
  • 返回可以在Fusion 360中执行的Python脚本

🛠️ 安装

先决条件

  • Python 3.9或更高版本
  • Autodesk Fusion 360

设置

  1. 克隆此仓库:

    git clone https://github.com/yourusername/fusion360-mcp-server.git
    cd fusion360-mcp-server
    
  2. 安装依赖项:

    pip install -r requirements.txt
    

🚀 使用方法

运行HTTP服务器

cd src
python main.py

这将在http://127.0.0.1:8000启动FastAPI服务器。

作为MCP服务器运行

cd src
python main.py --mcp

这将以MCP模式启动服务器,从标准输入读取并写入标准输出。

API端点

  • GET /: 检查服务器是否正在运行
  • GET /tools: 列出所有可用工具
  • POST /call_tool: 调用单个工具并生成脚本
  • POST /call_tools: 依次调用多个工具并生成脚本

示例API调用

列出工具

curl -X GET http://127.0.0.1:8000/tools

调用单个工具

curl -X POST http://127.0.0.1:8000/call_tool \
  -H "Content-Type: application/json" \
  -d '{
    "tool_name": "CreateSketch",
    "parameters": {
      "plane": "xy"
    }
  }'

调用多个工具

curl -X POST http://127.0.0.1:8000/call_tools \
  -H "Content-Type: application/json" \
  -d '{
    "tool_calls": [
      {
        "tool_name": "CreateSketch",
        "parameters": {
          "plane": "xy"
        }
      },
      {
        "tool_name": "DrawRectangle",
        "parameters": {
          "width": 10,
          "depth": 10
        }
      },
      {
        "tool_name": "Extrude",
        "parameters": {
          "height": 5
        }
      }
    ]
  }'

📦 可用工具

服务器当前支持以下Fusion 360工具:

创建

  • CreateSketch: 在指定平面上创建新的草图
  • DrawRectangle: 在活动草图中绘制矩形
  • DrawCircle: 在活动草图中绘制圆形
  • Extrude: 将轮廓拉伸成三维实体
  • Revolve: 将轮廓绕轴旋转

修改

  • Fillet: 向选定边缘添加倒圆角
  • Chamfer: 向选定边缘添加倒斜角
  • Shell: 以指定壁厚掏空实体
  • Combine: 使用布尔运算合并两个实体

导出

  • ExportBody: 将实体导出到文件

🔌 MCP集成

要使用此服务器与Cline一起工作,请将其添加到您的MCP设置配置文件中:

{
  "mcpServers": {
    "fusion360": {
      "command": "python",
      "args": ["/path/to/fusion360-mcp-server/src/main.py", "--mcp"],
      "env": {},
      "disabled": false,
      "autoApprove": []
    }
  }
}

🧩 工具注册表

工具定义在src/tool_registry.json中。每个工具都有:

  • name: 工具名称
  • description: 工具的功能描述
  • parameters: 工具接受的参数
  • docs: 相关Fusion API文档链接

示例工具定义:

{
  "name": "Extrude",
  "description": "将轮廓拉伸成三维实体。",
  "parameters": {
    "profile_index": {
      "type": "integer",
      "description": "要拉伸的轮廓索引。",
      "default": 0
    },
    "height": {
      "type": "number",
      "description": "拉伸的高度,单位为毫米。"
    },
    "operation": {
      "type": "string",
      "description": "操作类型(例如,'new', 'join', 'cut', 'intersect')。",
      "default": "new"
    }
  },
  "docs": "https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-6D381FCD-22AB-4F08-B4BB-5D3A130189AC"
}

📝 脚本生成

服务器基于工具调用生成Fusion 360 Python脚本。这些脚本可以在Fusion 360的脚本编辑器中执行。

示例生成的脚本:

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        design = app.activeProduct
        
        # 获取设计中的活动组件
        component = design.rootComponent
        
        # 在xy平面上创建新的草图
        sketches = component.sketches
        xyPlane = component.xYConstructionPlane
        sketch = sketches.add(xyPlane)
        
        # 绘制矩形
        rectangle = sketch.sketchCurves.sketchLines.addTwoPointRectangle(
            adsk.core.Point3D.create(0, 0, 0),
            adsk.core.Point3D.create(10, 10, 0)
        )
        
        # 拉伸轮廓
        prof = sketch.profiles.item(0)
        extrudes = component.features.extrudeFeatures
        extInput = extrudes.createInput(prof, adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        distance = adsk.core.ValueInput.createByReal(5)
        extInput.setDistanceExtent(False, distance)
        extrude = extrudes.add(extInput)
        
        ui.messageBox('操作成功完成')
    except:
        if ui:
            ui.messageBox('失败:\n{}'.format(traceback.format_exc()))

🧪 扩展服务器

添加新工具

  1. src/tool_registry.json中添加新的工具定义
  2. src/script_generator.pySCRIPT_TEMPLATES中添加脚本模板
  3. src/script_generator.py_process_parameters中添加参数处理逻辑

📚 文档链接

🔄 未来改进

  • 会话状态跟踪以实现上下文感知操作
  • 动态工具注册
  • 通过套接字或文件轮询实现自动化
  • 更多Fusion命令

📄 许可证

本项目采用MIT许可证 - 详情见LICENSE文件。