使用说明
Fusion MCP(此处“Fusion MCP”可能是一个特定产品、技术或公司的名称,根据上下文无法确定具体含义,因此直接音译)
用于与Autodesk Fusion 360交互的模型上下文协议(MCP)服务器
使用自然语言驱动Fusion360 CAD建模
目录
系统架构
该项目采用双模式架构,支持在生产模式和仿真模式下实现全面功能,以满足开发和测试需求。
架构图
Plugin Mode Architecture (Recommended for Production)
┌─────────────────┐ TCP Socket ┌─────────────────┐ MCP ┌─────────────────┐
│ Fusion 360 │◄────:8765──────►│ MCP Server │◄──────────────►│ AI Client │
│ + Plugin │ │ (FastMCP) │ │ (Cursor/Claude) │
│ (Real API) │ │ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
↑ ↑ ↑
│ │ │
Fusion API Socket Bridge MCP Protocol
+ Tool Modules (JSON-RPC 2.0)
Simulation Mode Architecture (Development & Testing)
┌─────────────────┐ MCP ┌─────────────────┐
│ MCP Server │◄──────────────►│ AI Client │
│ (Mock Data) │ │ (Cursor/Claude) │
│ │ │ │
└─────────────────┘ └─────────────────┘
核心组件
| 组件 | 文件路径 | 描述 |
|---|---|---|
| MCP 服务器 | src/mcp_server.py FastMCP服务器,注册了44款CAD工具 |
|
| Socket Bridge(套接字桥接) | Fusion360SocketBridge 类 |
MCP服务器与Fusion360插件之间的TCP通信桥接 |
| Fusion360 插件 | src/fusion360/addin.py 在Fusion360内部运行的插件,提供真实的API访问权限 |
|
| 工具模块 | src/tools/ |
按功能组织的模块化工具实现 |
| 上下文管理器 | src/context/persistence.py 设计意图持久性管理 |
|
| 核心桥梁 | src/core/bridge.py API通信层,支持三模式切换 |
信息流(或沟通流程)
AI Command → MCP Client → stdio → MCP Server → TCP Socket → Fusion360 Plugin → Fusion360 API → CAD Operation
核心功能
主要能力
- 人工智能自然语言建模直接从自然语言描述中创建3D模型
- 双模式操作支持插件模式(完整功能)和模拟模式(开发/测试)
- 44种专业工具涵盖从草图绘制到建模、装配及分析的完整工作流程
- 设计意图持久性自动保存设计历史和参数
- 智能模式切换自动检测环境并选择最佳操作模式
- 异步架构基于FastMCP的高性能异步实现
- 强大的错误处理全面的异常处理和自动降级机制
技术规格
| 特性 | 描述 |
|---|---|
| MCP协议版本 | 模型上下文协议(官方规范) |
| Python 版本 3.8及以上版本 | |
| Fusion360 版本 | 版本1.1.0+ |
| 通信协议 | TCP Socket(本地主机:8765)+ 标准I/O(MCP) |
| 总工具 | 44款专业CAD工具 |
快速入门
先决条件
- Python 3.8或更高版本
- 已安装Autodesk Fusion 360
- MCP 客户端(Cursor/Claude 桌面版)
步骤1:克隆项目并安装依赖项
# Clone the repository
git clone https://github.com/zkbkb/fusion-mcp.git
cd fusion-mcp
# Install Python dependencies
pip install -r requirements.txt
步骤2:安装Fusion360插件
# Run plugin installation script
python install_addin.py
预期输出:
Using fixed manifest file
Fusion360 plugin installed to: /Users/.../Autodesk/Fusion 360/API/AddIns/FusionMCP
Plugin features:
- Fixed shebang issue
- Improved global variable initialization
- Simplified error handling
- runOnStartup: false (manual start)
- Full feature set included
步骤3:启动Fusion360插件
- 打开Fusion 360
- 访问插件管理器:
- 菜单:
Tools→Add-Ins and Scripts→Add-Ins
- 菜单:
- 启动插件:
- 找到
FusionMCP v1.1.0 - 点击
Run
- 找到
- 确认成功启动:
- 查看消息:“MCP通信服务器已在localhost:8765上启动”
步骤4:配置MCP客户端
示例:Claude 桌面版
编辑配置文件: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"fusion360": {
"command": "python",
"args": ["<PROJECT_PATH>/src/mcp_server.py"],
"env": {
"PYTHONPATH": "<PROJECT_PATH>/src"
}
}
}
}
注替换 <PROJECT_PATH> 使用项目实际的绝对路径。
步骤5:验证安装
重启AI客户端,然后测试连接:
# Run complete system test
python tests/integration/test_fusion360_integration.py
预期输出:
Starting Fusion360 MCP complete system test
Socket connection successful
Sketch created successfully
Circle drawn successfully
Rectangle drawn successfully
Test complete! You can now view the created geometry in Fusion 360
配置指南
环境变量
可选的环境变量配置:
# Custom Socket port (default: 8765)
export FUSION_MCP_PORT=8765
# Custom Socket host (default: localhost)
export FUSION_MCP_HOST=localhost
# Enable debug logging
export MCP_DEBUG=true
插件配置
插件配置文件: src/fusion360/FusionMCP.manifest
{
"autodeskProduct": "Fusion360",
"type": "addin",
"id": "com.autodesk.FusionMCP",
"version": "1.1.0",
"runOnStartup": false,
"supportedOS": ["windows", "mac"]
}
重要提示: runOnStartup: false 这意味着插件需要手动启动。
工具参考
该系统提供了44种专业的CAD工具,这些工具被归类为以下几类:
绘图工具(9种工具)
| 工具名称 | 功能 | 参数 |
|---|---|---|
create_sketch |
创建二维草图 | 平面,命名 |
draw_line |
绘制线条 | 起始点x坐标, 起始点y坐标, 终点x坐标, 终点y坐标, 草图名称 |
draw_circle |
画圆 | 半径, 中心x坐标, 中心y坐标, 草图名称 |
draw_rectangle |
绘制矩形 | 宽度,高度,中心_x,中心_y,草图名称 |
draw_arc |
绘制弧线 | 中心x坐标,中心y坐标,半径,起始角度,结束角度 |
draw_polygon |
绘制多边形 | 边数,半径,中心_x,中心_y,草图名称 |
add_geometric_constraint |
添加几何约束 | 约束类型, 实体, 草图名称 |
add_dimensional_constraint |
添加尺寸约束 | 尺寸类型,值,实体,草图名称 |
get_sketch_info |
获取草图信息 | 草图名称 |
建模工具(12种工具)
| 工具名称 | 功能 | 参数 |
|---|---|---|
create_extrude |
拉伸特征 | 草图名称,距离,操作 |
create_revolve |
旋转功能 | sketch_name(草图名称), axis(轴), angle(角度) |
create_sweep |
扫掠特征 | 轮廓,路径 |
create_loft |
阁楼特色 | 线条、轨道 |
create_fillet |
倒角特征 | 边缘,半径 |
create_chamfer |
倒角特征 | 边缘,距离 |
create_shell |
壳体特性 | 表面、厚度 |
boolean_operation |
布尔运算 | 运算, 目标体, 工具体 |
split_body |
分体式机体 | 机体,分体工具 |
create_pattern_rectangular |
矩形图案 | 特征,x轴数量,y轴数量,x轴间距,y轴间距 |
create_pattern_circular |
圆形图案 | 特征、轴、数量、角度 |
create_mirror |
镜像功能 | 功能,镜像平面 |
组装工具(9件工具)
| 工具名称 | 功能 | 参数 |
|---|---|---|
create_component |
创建组件 | 名称,描述 |
insert_component_from_file |
从文件插入组件 | 文件路径, 变换 |
get_assembly_info |
获取装配信息 | - |
create_mate_constraint |
创建配合约束 | 约束类型,实体1,实体2 |
create_joint |
创建关节 | 关节类型, 组件1, 组件2 |
create_motion_study |
动作研究 | 名称,研究类型,持续时间 |
check_interference |
干扰检查 | 组件 |
create_exploded_view |
分解图 | 名称,比例 |
animate_assembly |
组装动画 | 关节名称, 起始值, 结束值, 持续时间 |
分析工具(10个工具)
| 工具名称 | 功能 | 参数 |
|---|---|---|
measure_distance |
测量距离 | 实体1, 实体2 |
measure_angle |
测量角度 | 实体1,实体2,实体3 |
measure_area |
测量区域 | 面部 |
measure_volume |
测量体积 | 身体 |
calculate_mass_properties |
计算质量属性 | 物体,材料 |
create_section_analysis |
部件分析 | 平面,实体 |
perform_stress_analysis |
应力分析 | 研究名称、载荷、约束条件 |
perform_modal_analysis |
模态分析 | 研究名称, 模态数量 |
perform_thermal_analysis |
热分析 | 研究名称,热源,温度 |
generate_analysis_report |
生成分析报告 | study_name(研究名称), report_type(报告类型) |
通用工具(4件工具)
| 工具名称 | 功能 | 参数 |
|---|---|---|
connect_fusion360 |
连接到Fusion360环境 | - |
create_parameter |
创建参数化变量 | 名称,值,单位,注释 |
get_design_info |
获取设计基本信息 | - |
get_features_info |
获取功能列表信息 | - |
开发指南
开发环境设置
# Install development dependencies
pip install -r requirements.txt
# Install development tools
pip install black flake8 mypy pytest pytest-cov
项目结构
fusion-mcp/
├── src/ # Source code directory
│ ├── mcp_server.py # MCP server main entry (FastMCP)
│ ├── tools/ # Modular tool implementations
│ │ ├── sketch/ # Sketch tool modules
│ │ │ ├── basic.py # Basic drawing tools
│ │ │ ├── advanced.py # Advanced drawing tools
│ │ │ └── constraints.py # Constraint tools
│ │ ├── modeling/ # Modeling tool modules
│ │ │ ├── features.py # Feature tools
│ │ │ ├── patterns.py # Pattern tools
│ │ │ └── advanced.py # Advanced modeling tools
│ │ ├── assembly/ # Assembly tool modules
│ │ │ ├── components.py # Component management
│ │ │ ├── constraints.py # Assembly constraints
│ │ │ └── motion.py # Motion studies
│ │ ├── analysis/ # Analysis tool modules
│ │ │ ├── measurement.py # Measurement tools
│ │ │ ├── simulation.py # Simulation analysis
│ │ │ └── reporting.py # Report generation
│ │ └── utils.py # Shared utility functions
│ ├── core/ # Core components
│ │ ├── bridge.py # API communication bridge layer
│ │ ├── config.py # Configuration management
│ │ └── resources.py # Resource management
│ ├── context/ # Context management
│ │ ├── persistence.py # Design intent persistence
│ │ └── tools.py # Context tools
│ ├── fusion360/ # Fusion360 plugin source code
│ │ ├── addin.py # Plugin main file
│ │ └── FusionMCP.manifest # Plugin manifest
│ └── utils/ # Utility functions
│ ├── error_handler.py # Error handling
│ ├── helpers.py # Helper functions
│ ├── logging_config.py # Logging configuration
│ └── validators.py # Parameter validation
├── tests/ # Test suite
│ ├── unit/ # Unit tests
│ ├── integration/ # Integration tests
│ ├── performance/ # Performance tests
│ ├── platform/ # Platform compatibility tests
│ └── fixtures/ # Test fixtures
├── install_addin.py # Plugin installation script
├── mcp_config.json # MCP client configuration example
├── requirements.txt # Python dependencies
├── setup.py # Package installation configuration
├── LICENSE # License file
└── README.md # This file
添加新工具
步骤1:实现工具功能
在相应的工具模块中创建一个新函数:
# src/tools/sketch/basic.py
async def draw_ellipse(
center_x: float,
center_y: float,
major_radius: float,
minor_radius: float,
sketch_name: Optional[str] = None
) -> Dict[str, Any]:
"""
Draw an ellipse in a sketch
Args:
center_x: Ellipse center X coordinate
center_y: Ellipse center Y coordinate
major_radius: Major axis radius
minor_radius: Minor axis radius
sketch_name: Target sketch name
Returns:
Dictionary containing operation result
"""
# Implement ellipse drawing logic
pass
步骤2:导出工具功能
在模块中导出 __init__.py:
# src/tools/sketch/__init__.py
from .basic import (
draw_line,
draw_circle,
draw_rectangle,
draw_ellipse, # New addition
)
步骤3:在MCP服务器上注册
# src/mcp_server.py
@mcp.tool()
async def draw_ellipse(
center_x: float,
center_y: float,
major_radius: float,
minor_radius: float,
sketch_name: Optional[str] = None
) -> str:
"""Draw an ellipse in a sketch"""
parameters = {
"center_x": center_x,
"center_y": center_y,
"major_radius": major_radius,
"minor_radius": minor_radius,
"sketch_name": sketch_name
}
try:
result = fusion_bridge.send_command("draw_ellipse", parameters)
_log_tool_execution("draw_ellipse", parameters, result)
return json.dumps(result, ensure_ascii=False)
except Exception as e:
result = {"error": str(e)}
_log_tool_execution("draw_ellipse", parameters, result)
return json.dumps(result, ensure_ascii=False)
步骤4:添加单元测试
# tests/unit/test_sketch_tools.py
@pytest.mark.asyncio
async def test_draw_ellipse():
"""Test ellipse drawing functionality"""
result = await draw_ellipse(
center_x=0,
center_y=0,
major_radius=10,
minor_radius=5,
sketch_name="TestSketch"
)
assert "error" not in result
assert result["success"] == True
插件开发
插件文件位于 src/fusion360/addin.py,要点:
- 全局变量初始化所有全局变量(
app,ui,handlers,mcp_server) 在(某处)被初始化run()函数 - 套接字服务器使用守护线程运行监听8765端口的TCP服务器
- 错误处理所有API调用都用try-except块包裹起来
- 命令处理通过JSON协议接收并响应命令
修改插件后,重新安装它:
python install_addin.py
然后在Fusion 360中重新启动插件。
参考文档
在开发此项目时,以下资源将非常有用:
Fusion 360 API 文档
完整的Fusion 360 API参考文档,包括所有可用的类、方法和属性:
文档URL: Fusion 360 API 参考手册
主要内容:
adsk.core- 核心功能(应用程序、用户界面、几何图形)adsk.fusion- Fusion 360 特定功能(设计、建模、装配)adsk.cam- CAM功能(刀具路径,工具)- API对象模型和继承关系
- 代码示例和最佳实践
MCP Python SDK(MCP Python软件开发工具包)
官方模型上下文协议Python软件开发工具包,此项目基于FastMCP构建:
GitHub 仓库: 模型上下文协议/Python SDK
主要内容:
- MCP协议实现
- FastMCP快速开发框架
- 客户端和服务器示例
- 工具、资源和提示的注册方法
- 异步编程模式
MCP协议文档
模型上下文协议的官方文档和规范:
文档网址: MCP服务器开发指南
主要内容:
- MCP协议规范(JSON-RPC 2.0)
- 服务器构建指南(Python部分)
- 工具、资源、提示的设计模式
- 客户端集成方法(Cursor、Claude Desktop 等)
- 最佳实践和安全指南
代码风格
这个项目遵循以下代码标准:
# Code formatting
black src/ tests/
# Code linting
flake8 src/ tests/
# Type checking
mypy src/
# Import sorting
isort src/ tests/
推荐的编辑器设置(VS Code):
{
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"python.analysis.typeCheckingMode": "basic"
}
测试
运行测试
# Run all tests
pytest
# Run unit tests
pytest tests/unit/
# Run integration tests (requires Fusion360 plugin running)
pytest tests/integration/
# Run specific test file
pytest tests/unit/test_sketch_tools.py
# Run coverage tests
pytest --cov=src --cov-report=html
# Run performance tests
pytest tests/performance/
测试类别
| 测试类型 | 目录 | 依赖项 | 目的 |
|---|---|---|---|
| 单元测试 | tests/unit/ |
无 | 测试独立工具功能逻辑 |
| 集成测试 | tests/integration/ |
Fusion360 + 插件 | 测试完整工作流程 |
| 性能测试 | tests/performance/ |
无 | 测试响应时间和资源使用情况 |
| 平台测试 | tests/platform/ |
无 | 测试跨平台兼容性 |
测试覆盖率目标
- 单元测试覆盖率:> 80%
- 关键路径覆盖率:100%
- 集成测试:所有主要工作流程
故障排除
常见问题1:插件连接失败
症状:
Connection to Fusion 360 plugin failed: [Errno 61] Connection refused
Tool module initialization failed, using built-in implementation
解决方案:
-
确认Fusion 360正在运行
# Check Fusion 360 process ps aux | grep Fusion # macOS/Linux -
手动启动插件
- 在Fusion 360中:
Tools→Add-Ins and Scripts→Add-Ins - 查找
FusionMCP v1.1.0 - 点击
Run - 确认看到:“MCP通信服务器已在本地主机:8765上启动”
- 在Fusion 360中:
-
检查端口占用情况
# macOS/Linux lsof -i :8765 # Windows netstat -an | findstr :8765 -
重新安装插件
python install_addin.py
常见问题2:MCP客户端无法连接
症状: AI客户端(Cursor/Claude)无法看到Fusion 360工具
解决方案:
-
验证配置文件路径
- 确认
<PROJECT_PATH>已被实际路径替换 - 检查路径中是否包含特殊字符或空格
- 确认
-
验证JSON语法
# Use jq to verify JSON format cat mcp_config.json | jq . -
检查Python环境
# Confirm Python version python --version # Should be 3.8+ # Confirm dependencies are installed pip list | grep mcp pip list | grep pydantic -
重启AI客户端
- 完全退出 Cursor/Claude 桌面版
- 重启应用程序
-
查看MCP日志
# Cursor log location (example) tail -f ~/Library/Application\ Support/Cursor/logs/*.log
常见问题3:操作执行失败
症状:
{
"error": "No active design found",
"success": false
}
解决方案:
-
确保存在主动设计
- 在Fusion 360中创建或打开一个设计文档
-
检查参数格式
- 确认所有必需的参数均已提供
- 确认参数类型是否正确(数字、字符串等)
-
查看详细错误日志
# Enable DEBUG logging in mcp_server.py logging.basicConfig(level=logging.DEBUG) -
检查Fusion 360的状态
- 确认没有打开任何模态对话框
- 确认设计处于可编辑状态
常见问题4:插件无法启动
症状: 插件在Fusion 360插件列表中显示错误
解决方案:
-
检查清单文件
cat src/fusion360/FusionMCP.manifest # Confirm JSON format is correct -
检查Python路径
- 清单中的 Python 路径必须正确
- 默认使用系统自带的Python
-
查看 Fusion 360 日志
# macOS ~/Library/Application Support/Autodesk/Webdeploy/Production/[version]/logs/ # Windows %LOCALAPPDATA%\Autodesk\Webdeploy\Production\[version]\logs\ -
手动调试插件
# Directly run plugin script for testing cd src/fusion360 python addin.py
系统诊断
运行完整的诊断检查:
# Test MCP server
python -m src.mcp_server
# Test Socket connection
python test_mcp_connection.py
# Run platform compatibility tests
pytest tests/platform/test_compatibility.py -v
# Run complete system test
python tests/integration/test_fusion360_integration.py
寻求帮助
如果上述方法无法解决问题:
-
查看日志文件
logs/fusion360_mcp.log- MCP服务器日志logs/error.log- 错误日志logs/performance.log- 性能日志
-
提交问题
- 包含完整的错误信息
- 包含操作系统及版本信息
- 包含Fusion 360版本
- 包含复现步骤
-
社区支持
- GitHub 讨论区
- MCP社区论坛
版本历史
v1.1.0 - 当前版本
发行日期2024
主要更新:
- 集成了44套完整的CAD工具
- 修复了插件稳定性问题
- 简化安装和配置过程
- 全面的错误处理和回退机制
- 模块化架构重构
- 增加了设计意图持久性
- 优化了套接字通信性能
- 提高了测试覆盖率
工具统计:
- 草图工具:9
- 建模工具:12种
- 装配工具:9件
- 分析工具:10
- 通用工具:4
v1.0.0 - 初始版本
发布日期2023
初始特征:
- 基本的MCP服务器实现
- Fusion 360插件的基本功能
- 核心CAD工具的实现
- 套接字通信桥接
- 基本错误处理
做出贡献
我们欢迎各种形式的贡献!
贡献流程
-
为该项目创建分支(或:fork该项目)
git clone https://github.com/yourusername/fusion-mcp.git cd fusion-mcp -
创建功能分支
git checkout -b feature/amazing-new-feature -
做出改变
- 编写代码
- 添加测试
- 更新文档
-
提交更改
# Follow conventional commits specification git commit -m "feat(sketch): add ellipse drawing tool" -
推送分支
git push origin feature/amazing-new-feature -
创建拉取请求
- 描述变化
- 链接相关问题
- 等待代码审查
提交规范
这个项目接着 约定式提交(或传统提交规范) 规格:
<type>(<scope>): <description>
[optional body]
[optional footer]
类型:
feat新功能fix修复漏洞docs文档更新style代码格式调整refactor代码重构test与测试相关的chore构建工具或辅助工具的更换
示例:
feat(modeling): add boolean union operation
fix(sketch): resolve constraint calculation error
docs(readme): update installation instructions
代码审查标准
- 通过所有单元测试
- 代码覆盖率没有下降
- 遵循项目代码规范
- 包含适当的文档字符串
- 更新相关文档
许可证
这个项目采用以下许可协议 知识共享署名-非商业性使用 4.0 国际许可协议(CC BY-NC 4.0)
您可能:
- 分享 - 复制并重新分发此项目
- 适应 - 修改并创作衍生作品
- 非商业用途 - 用于个人学习和研究
你必须:
- 归属(或:署名) - 给予适当的署名,提供许可证链接,并指明是否进行了修改
- 非商业性 - 不得将此作品用于商业目的
详细信息
如需完整的许可证文本,请参阅 许可证 文件或访问: https://creativecommons.org/licenses/by-nc/4.0/ 翻译为中文是:https://creativecommons.org/licenses/by-nc/4.0/(注:该网址本身为英文,直接翻译无实际意义,但为符合问题要求,可表述为“该网址链接为‘知识共享署名-非商业性使用 4.0 国际许可协议’”)。不过,通常我们直接使用该网址的原英文表述,因为它是一个标准的许可协议标识,直接指向了具体的许可协议页面