RhinoMCP——基于MCP的人工智能驱动Rhino 3D建模
使用AI代理控制Rhino 3D 模型上下文协议(MCP).
建筑
User (natural language)
│
▼
AI Agent (Claude, etc.)
│ MCP protocol
▼
RhinoMCP Server (this repo)
│ TCP socket (localhost:9876)
▼
Rhino Plugin (socket_server.py)
│
▼
rhinoscriptsyntax / RhinoCommon → Rhino 8
快速开始
1.安装MCP服务器
pip install -e ".[dev]"
2.安装Rhino插件
python scripts/install_rhino_plugin.py
按照打印的说明将插件加载到Rhino中。
3.在模拟模式下启动(不需要Rhino)
rhino-mcp --mock
4.从真正的Rhino开始
首先启动Rhino并加载插件(见步骤2),然后:
rhino-mcp
可用的MCP工具
几何图形创建
| 工具 | 说明 |
|---|
create_sphere | 创建球体 |
create_box | 创建长方体 |
create_cylinder | 创建圆柱体 |
create_cone | 创建圆锥体 |
create_torus | 创建圆环(甜甜圈) |
create_line | 创建直线曲线 |
create_circle | 创建一个圆 |
create_polyline | 创建折线 |
extrude_curve | 拉伸轮廓曲线 |
变换
| 工具 | 说明 |
|---|
move_object | 移动或复制对象 |
rotate_object | 绕轴旋转 |
scale_object | 均匀或非均匀缩放 |
mirror_object | 飞机对面的镜子 |
array_linear | 线性阵列 |
array_polar | 极性(旋转)阵列 |
布尔运算
| 工具 | 说明 |
|---|
boolean_difference | 减去固体(B-diff) |
boolean_union | 连接实体 |
boolean_intersection | 仅保留重叠 |
fillet_edges | 圆形边缘 |
曲面造型
| 工具 | 说明 |
|---|
loft | 横截面阁楼 |
sweep1 | 沿一条轨道扫过 |
sweep2 | 沿着两条铁轨扫过 |
revolve | 旋转配置文件 |
pipe | 沿曲线创建管道 |
offset_surface | 偏移曲面/实体 |
选择
| 工具 | 说明 |
|---|
select_by_layer | 在图层上获取对象 |
select_by_type | 按类型获取对象 |
select_closest_to_point | 查找最近的物体 |
get_all_objects | 列出所有对象 |
视口
| 工具 | 说明 |
|---|
capture_viewport | 视口截图 |
set_standard_view | 切换到标准视图 |
zoom_to_object | 缩放到对象 |
场景和图层
| 工具 | 说明 |
|---|
get_scene_state | 全场景快照 |
get_object_info | 对象详细信息 |
delete_objects | 删除对象 |
set_object_name | 命名一个对象 |
undo | 撤消操作 |
create_layer | 创建图层 |
set_object_layer | 移动到图层 |
get_all_layers | 列出所有图层 |
后备方案
| 工具 | 说明 |
|---|
execute_rhinoscript | 运行任意rhinoscript语法代码 |
health_check | 检查服务器/Rino状态 |
发展
运行测试(模拟模式——无需Rhino)
pytest tests/ -v
健康检查
python scripts/health_check.py
项目结构
rhino-mcp/
├── src/
│ ├── rhino_mcp/ # MCP Server
│ │ ├── server.py # Main entry point
│ │ ├── connection.py # TCP connection management
│ │ ├── protocol.py # JSON protocol definitions
│ │ ├── mock.py # Mock mode (no Rhino needed)
│ │ ├── logger.py # Structured JSON logging
│ │ └── tools/ # MCP tool implementations
│ │ ├── geometry.py # Primitives
│ │ ├── transform.py # Move/rotate/scale
│ │ ├── boolean.py # Boolean ops
│ │ ├── surface.py # Loft/sweep/revolve
│ │ ├── selection.py # Object selection
│ │ ├── viewport.py # Screenshots/views
│ │ ├── scene.py # Scene queries
│ │ ├── layers.py # Layer management
│ │ └── execute.py # Fallback executor
│ └── rhino_plugin/ # Rhino-side plugin
│ ├── socket_server.py # TCP server in Rhino
│ ├── executor.py # Code executor
│ ├── state.py # Scene state
│ └── viewport.py # Viewport control
├── tests/
├── scripts/
│ ├── health_check.py
│ └── install_rhino_plugin.py
└── pyproject.toml
通信协议
请求(MCP服务器→ 犀牛):
{
"id": "uuid",
"type": "execute_command",
"payload": {
"code": "import rhinoscriptsyntax as rs\nrs.AddSphere((0,0,0), 5)",
"timeout": 30
}
}
回应(Rhino→ MCP服务器):
{
"id": "uuid",
"status": "success",
"result": {
"created_objects": ["guid-xxx"],
"execution_time_ms": 120,
"scene_summary": {
"total_objects": 15,
"document_name": "Untitled"
}
},
"error": null
}
Claude桌面配置
{
"mcpServers": {
"rhino": {
"command": "rhino-mcp",
"args": [],
"env": {
"RHINO_HOST": "localhost",
"RHINO_PORT": "9876"
}
}
}
}
需求
- Python 3.10+
- Rhino 8(用于实际执行;不需要模拟/测试)
mcp, pydantic, anyio