蚱蜢MCP工作流程
Grasshopper MCP工作流是一个桥接服务器,使用模型上下文协议(MCP)标准连接Grasshopper和Cursor。
文件:https://www.autodesignlab.org/zh/blog/lecture-2025-rhino-mcp/
Language Selection /语言选择: 英语 | 繁体中文
特性
- MCP协议集成:通过模型上下文协议(MCP)标准连接Grasshopper和Cursor
- 组件管理:用于创建、管理和连接Grasshopper组件的直观工具功能
- 意图识别:支持高级意图识别,从简单描述自动创建复杂的组件模式
- 组件知识库:包括一个全面的知识库,了解常见组件的参数和连接规则
- 工作流程自动化:提供从JSON和MMD文件执行复杂Grasshopper工作流的工具
- CLI工具:用于批处理操作和自动化的命令行界面
- 参数管理:高级参数设置和管理功能
- 组管理:使用自定义颜色和名称将组件组织成组
系统架构
该系统由以下部分组成:
- 蚱蜢MCP组件(GH_MCP.gha):安装在Grasshopper中的C#插件,提供TCP服务器来接收命令
- Python MCP网桥服务器 (
grasshopper_mcp):连接Cursor和Grasshopper MCP组件的网桥服务器 - 蚱蜢工具 (
grasshopper_tools):一个用于管理Grasshopper组件、连接、参数和工作流的全面Python库 - 组件知识库:包含组件信息、模式和意图的JSON文件
- 工作流程技能 (
grasshopper-workflow):Cursor提供高级工作流自动化功能的专业技能
安装说明
先决条件
- Rhino 7或更高
- 蚱蜢
- Python 3.8或更高版本
- 光标
安装步骤
- 安装Grasshopper MCP组件
方法1:下载预编译的GH_MCP.gha文件(推荐)
下载 GH_MCP.gha 直接从GitHub存储库中下载文件并将其复制到Grasshopper组件文件夹:
%APPDATA%\Grasshopper\Libraries\方法2:从源代码构建
如果您更喜欢从源代码构建,请克隆存储库并使用Visual Studio构建C#项目。
- 安装Python MCP网桥服务器
方法1:从PyPI安装(推荐)
最简单的方法是使用pip直接从PyPI安装:
pip install grasshopper-mcp方法2:从GitHub安装
您还可以从GitHub安装最新版本:
pip install git+https://github.com/alfredatnycu/grasshopper-mcp.git方法3:从源代码安装
如果需要修改代码或开发新功能,可以克隆存储库并安装:
git clone https://github.com/alfredatnycu/grasshopper-mcp.git
cd grasshopper-mcp
pip install -e .用法
- 开始犀牛和蚱蜢
启动Rhino并打开Grasshopper。
- 将GH_MCP组件添加到画布
在Grasshopper组件面板中找到GH_MCP组件并将其添加到画布中。
- 启动Python MCP网桥服务器
打开终端并运行:
python -m grasshopper_mcp.bridge> 备注:命令 grasshopper-mcp 由于Python脚本路径问题,可能无法直接工作。使用 python -m grasshopper_mcp.bridge 是推荐的更可靠的方法。
- 配置光标MCP连接
在Cursor中配置MCP服务器连接,以启用Cursor和Grasshopper MCP网桥服务器之间的通信。
配置步骤:
1. 找到Cursor的MCP配置文件 mcp.json,通常位于:
- 窗户: %APPDATA%\Cursor\User\mcp.json 或 ~\.cursor\mcp.json - macOS: ~/Library/Application Support/Cursor/User/mcp.json 或 ~/.cursor/mcp.json
1. 将以下配置添加到 mcp.json 文件:
{
"mcpServers": {
"grasshopper": {
"command": "python",
"args": ["-m", "grasshopper_mcp.bridge"]
}
}
}1. 使用虚拟环境或特定的Python路径:
如果您使用的是虚拟环境或conda环境,请指定Python可执行文件的完整路径:
{
"mcpServers": {
"grasshopper": {
"command": "C:\\Users\\YourUsername\\.conda\\envs\\grasshopper-mcp\\python.exe",
"args": ["-m", "grasshopper_mcp.bridge"]
}
}
}> 小贴士:在Windows上,路径中的反斜杠需要用双反斜杠转义 \\ 或使用正斜杠 /.
1. 验证Python路径:
您可以使用以下命令找到Python可执行文件的完整路径:
- 窗户: where python 或 where python3 - macOS/Linux: which python 或 which python3
如果使用conda环境,可以运行:
conda activate grasshopper-mcp
where python # Windows
which python # macOS/Linux1. 保存配置文件后,重新启动Cursor以使更改生效。
> 备注:在配置MCP之前,请确保已完成步骤2(将GH_MCP组件添加到Grasshopper画布)和步骤3(启动Python MCP网桥服务器)。在Cursor可以连接之前,MCP网桥服务器需要运行。
- 开始使用带有光标的Grasshopper
现在,您可以使用Cursor通过自然语言命令控制Grasshopper。
示例命令
以下是一些可以与Cursor一起使用的示例命令:
- 在点(0,0,0)处创建半径为5的圆
- “将圆连接到高度为10的拉伸组件”
- “创建一个5行5列的点网格”
- “对所有选定对象应用随机旋转”
- “创建一个矩形组件并将其宽度设置为10”
- “将所有选定的组件分组,并将其命名为“几何图形组””
使用蚱蜢工具
该项目包括一个全面的 grasshopper_tools Grasshopper程序控制库:
Python API用法
from grasshopper_tools import (
GrasshopperClient,
ComponentManager,
ConnectionManager,
ParameterSetter,
GroupManager
)
# Create client connection
client = GrasshopperClient(host="localhost", port=8080)
# Create component manager
comp_mgr = ComponentManager(client)
# Add a component
component_id = comp_mgr.add_component(
guid="e2bb9b8d-0d80-44e7-aa2d-2e446f5c61da", # Number Slider GUID
x=100,
y=200,
component_id="SLIDER_WIDTH"
)
# Set component parameters
param_setter = ParameterSetter(client)
param_setter.set_slider_properties(
component_id=component_id,
value="10",
min_value=0,
max_value=100
)CLI使用情况
# Execute a placement workflow from JSON
python -m grasshopper_tools.cli execute-placement GH_WIP/placement_info.json
# Parse MMD files
python -m grasshopper_tools.cli parse-mmd GH_WIP/component_info.mmd --action sliders
# View help
python -m grasshopper_tools.cli --help有关更详细的文档,请参阅 grasshopper_tools文档.
故障排除
如果遇到问题,请检查以下内容:
- GH_MCP组件未加载
- 确保.gha文件位于正确的位置: %APPDATA%\Grasshopper\Libraries\ - 在Grasshopper中,转到“文件”>“首选项”>“库”,然后单击“取消阻止”以取消阻止新组件 - 重启Rhino和Grasshopper - 检查您是否正确。NET运行时已安装(net48或net7.0)
- 网桥服务器无法启动
- 如果 grasshopper-mcp 命令不起作用,请使用 python -m grasshopper_mcp.bridge 相反 - 确保安装了所有必需的Python依赖项: pip install -r requirements.txt - 检查端口8080是否已被其他应用程序使用 - 验证Python版本是否为3.8或更高版本: python --version
- 游标无法连接
- 确保网桥服务器正在运行 - 验证您使用的连接设置是否正确(localhost:8080) - 检查网桥服务器的控制台输出是否有任何错误消息 - 确保GH_MCP组件已添加到Grasshopper画布中 - 检查Cursor的MCP配置是否正确
- 命令未执行
- 验证GH_MCP组件是否在Grasshopper画布上 - 检查网桥服务器控制台是否有错误消息 - 确保Cursor已正确连接到网桥服务器 - 使用时验证组件GUID是否正确 grasshopper_tools
- 蚱蜢工具问题
- 确保您使用了正确的主机和端口(默认值:localhost:8080) - 在使用这些工具之前,请检查MCP网桥服务器是否正在运行 - 使用CLI命令时验证文件路径 - 看 grasshopper_tools文档 详细故障排除
发展
项目结构
grasshopper-mcp/
├── grasshopper_mcp/ # Python MCP bridge server
│ ├── __init__.py
│ └── bridge.py # Main bridge server implementation
├── grasshopper_tools/ # Python tools library
│ ├── client.py # MCP client implementation
│ ├── component_manager.py # Component management
│ ├── connection_manager.py # Connection management
│ ├── parameter_setter.py # Parameter setting utilities
│ ├── group_manager.py # Group management
│ ├── placement_executor.py # Workflow execution
│ ├── parser_utils.py # MMD/JSON parsing
│ ├── cli.py # Command-line interface
│ └── docs/ # Documentation
├── GH_MCP/ # Grasshopper component (C#)
│ └── GH_MCP/
│ ├── Commands/ # Command handlers
│ ├── Models/ # Data models
│ ├── Utils/ # Utilities
│ └── Resources/ # Component knowledge base
├── grasshopper-workflow/ # Workflow skill for Cursor
│ ├── references/ # API references
│ ├── scripts/ # Workflow scripts
│ └── SKILL.md # Skill documentation
├── GH_WIP/ # Work in progress files
│ ├── component_info.mmd # Component information
│ ├── part_info.mmd # Part information
│ └── placement_info.json # Placement workflow
├── scripts/ # Utility scripts
├── prompt/ # Prompt templates
├── docs/ # Project documentation
├── releases/ # Pre-compiled binaries
│ └── GH_MCP.gha # Compiled Grasshopper component
├── setup.py # Python package setup
├── requirements.txt # Python dependencies
└── README.md # This file其他资源
- 蚱蜢工具文档:参见 grasshopper_工具/文档/ 获取详细的API文档和使用指南
- 工作流程技能:The
grasshopper-workflow技能为Cursor提供高级工作流自动化功能 - 示例脚本:检查
scripts/目录,例如使用脚本 - 提示模板:The
prompt/目录包含各种工作流步骤的提示模板
贡献
欢迎投稿!请随时提交拉取请求。
贡献时:
- 遵循现有的代码样式和结构
- 为新功能添加文档
- 尽可能包括测试
- 如果添加新功能或更改安装步骤,请更新此README
更新日志
版本0.1.0
发布日期: 2024-12-19
- Grasshopper MCP Bridge首次发布
- 支持MCP协议与Cursor的集成
- 组件管理和连接工具
- 自动创建组件模式的意图识别
- 全面的组件知识库
- JSON和MMD文件的工作流自动化
- 用于批处理操作的CLI工具
- 参数和组管理功能
许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
致谢
- 感谢Rhino和Grasshopper社区提供的出色工具
- 感谢Cursor和MCP协议支持
联系
如有疑问或支持,请在GitHub存储库上打开问题。
