AAG2025: 建筑几何学进展 - 麻省理工学院 | 2025年11月16日-17日 | 研讨会页面
<div align="center"> <img src="img_1.jpg" width="30%" /> <img src="img_2.jpg" width="30%" /> <img src="img_3.jpg" width="30%" /> </div>一个模型上下文协议(MCP)服务器,提供超过30种工具,通过自然语言与Rhino 3D和Grasshopper进行交互。功能包括参数化几何生成、跨文件工作流、智能几何传输和自动化工作流建议。采用HTTP桥接架构来处理MCP(Python 3.10+)和Rhino的IronPython之间的Python版本兼容性。
┌─────────────────┐ ┌──────────────────┐ ┌─────────────┐
│ MCP 客户端 │ ◄─────► │ MCP 服务器 │ ◄─────► │ Rhino │
│ │ MCP │ (Python 3.10+) │ HTTP │ 桥接 │
└─────────────────┘ └──────────────────┘ └─────────────┘
▲
│
Rhino API
Grasshopper API
eml_ 前缀自动发现参数以支持跨文件工作流.env文件切换详细输出,在生产中节省60-80%的令牌MCP服务器和客户端集成:
main.py - 自动发现的MCP服务器bridge_client.py - 与Rhino通信的HTTP客户端config/ - 配置模板requirements.txt - Python 3.10+依赖项运行在Rhino内部的HTTP桥接服务器:
rhino_bridge_server.py - HTTP服务器(IronPython 2.7/3.9)start_rhino_bridge.py - 启动脚本基于装饰器自动发现的工具定义:
rhino_tools.py - Rhino 3D工具gh_tools.py - Grasshopper工具tool_registry.py - 自动发现系统Grasshopper 文件库/ - .gh文件存储cd MCP/
pip install -r requirements.txt
工具 > 脚本 > 编辑exec(open(r'C:\path\to\rhino_gh_mcp\Rhino\start_rhino_bridge.py').read())
http://localhost:8080/status添加到您的MCP客户端配置文件(可选:如果在虚拟环境中运行,可以指向该Python可执行文件):
{
"mcpServers": {
"rhino_gh": {
"command": "python",
"args": ["C:\\path\\to\\rhino_gh_mcp\\MCP\\main.py"]
}
}
}
重启您的MCP客户端以加载服务器。
控制工具响应的详细程度以优化令牌使用:
.env.example复制到项目根目录下的.envDEBUG_MODE=true用于开发或DEBUG_MODE=false用于生产优点:
DEBUG_MODE=false - 通过移除冗长的调试日志节省60-80%的令牌(推荐用于生产)DEBUG_MODE=true - 完整的诊断输出用于故障排除详情见Tools/README.md。
添加JSON元数据以描述Grasshopper文件并启用工作流建议:
Tools/Grasshopper 文件库/创建metadata.jsonsuggest_grasshopper_workflow工具获取智能文件顺序建议示例元数据结构见Tools/Grasshopper 文件库/metadata.json。
draw_line_rhino - 在3D空间中绘制线get_rhino_info - 获取会话信息typical_roof_truss_generator - 生成参数化桁架get_selected_rhino_objects - 获取选定对象的数据get_rhino_object_geometry - 提取几何list_gh_files - 列出可用的.gh文件open_gh_file - 打开文件(自动启动Grasshopper)open_all_gh_files - 一次性打开所有文件get_active_gh_files - 获取当前打开的文件close_gh_file - 关闭特定文件基于eml_前缀的自动化工作流工具:
list_eml_parameters - 发现带有eml_前缀的组件get_eml_parameter_value - 提取参数值set_eml_parameter_value - 设置参数值suggest_eml_connections - 建议数据流连接transfer_eml_geometry_between_files - 直接几何传输execute_eml_workflow - 多文件工作流编排list_grasshopper_sliders / set_grasshopper_sliderset_multiple_grasshopper_slidersanalyze_grasshopper_slidersanalyze_grasshopper_inputs_with_contextanalyze_grasshopper_outputs_with_contextget_grasshopper_overviewget_grasshopper_componentslist_grasshopper_valuelist_componentsset_grasshopper_valuelist_selectionlist_grasshopper_panels / set_grasshopper_panel_textget_grasshopper_panel_dataset_grasshopper_geometry_inputextract_grasshopper_geometry_outputdebug_grasshopper_statebake_grasshopper_geometry - 将几何烘焙到Rhino,带有图层控制execute_custom_grasshopper_script - 在GH上下文中运行Pythonsuggest_grasshopper_workflow - 根据元数据获取工作流建议set_active_gh_file - 切换活动文档predict_truss_tonnage - 基于多项式回归模型预测长跨度桁架吨位重要: 在使用MCP工具之前,请确保Grasshopper文件已正确配置:
只有在验证文件在Grasshopper中正常工作后,才能使用MCP工具进行自动化。
将验证过的.gh文件存储在Tools/Grasshopper 文件库/中,以便与文件管理工具一起使用。
eml_(外部ML)前缀使Grasshopper中的组件自动发现成为可能:
支持的组件:
| 类型 | 示例 | 目的 |
|---|---|---|
| 数字滑块 | eml_panel_count | 数值输入 |
| 面板 | eml_output_data | 文本显示 |
| 布尔开关 | eml_enable_feature | 开关 |
| 值列表 | eml_material_type | 下拉菜单 |
| 几何参数 | eml_input_curve | 几何输入/输出 |
工作流示例:
1. 打开带有`eml_output_curve`的generator.gh
2. 使用`list_eml_parameters`提取几何
3. 打开带有`eml_input_curve`的processor.gh
4. 使用`transfer_eml_geometry_between_files`传输
这使得跨文件自动化无需手动重新连线。
工具使用基于装饰器的自动发现。将两个装饰器添加到同一文件中:
# MCP工具(客户端侧)
@rhino_tool(name="create_circle", description="创建一个圆...")
async def create_circle(center_x: float, center_y: float, radius: float):
return call_bridge_api("/create_circle", {
"center_x": center_x,
"center_y": center_y,
"radius": radius
})
# 桥接处理器(服务器侧)
@bridge_handler("/create_circle")
def handle_create_circle(data):
import rhinoscriptsyntax as rs
center = [data['center_x'], data['center_y'], 0]
radius = data['radius']
circle_id = rs.AddCircle(center, radius)
return {"success": True, "circle_id": str(circle_id)}
重启两个服务器以激活新工具。
桥接服务器未响应:
http://localhost:8080/status进行验证工具未出现:
MCP/main.py路径是否使用绝对路径Grasshopper工具失败:
桥接中的类型错误:
curl http://localhost:8080/statuscurl http://localhost:8080/infoMIT许可证
Hossein Zargar (Seyed Hossein Zargar)