使用说明
Blender MCP服务器
用于管理和执行Blender脚本的模型上下文协议(MCP)服务器。
特性
- 添加、编辑、执行和删除Blender Python脚本
- 在无头Blender环境中执行脚本
- 查看执行结果和错误
- 跟踪脚本元数据(创建日期、上次修改时间、执行次数)
需求
- Python 3.7+
- 搅拌机已安装且可访问
- MCP库(
pip install mcp)
用法
-
启动服务器:
python server.py -
使用MCP客户端(如Claude Desktop)连接到服务器
-
使用提供的工具管理脚本:
add_script(name, content)-添加新脚本edit_script(name, content)-编辑现有脚本execute_script(name, blend_file=None)-在Blender中执行脚本,可选择指定.blend文件remove_script(name)-删除脚本
-
访问资源以获取信息:
scripts://list-获取可用脚本列表script://{name}-获取特定脚本的内容result://{name}-获取脚本的执行结果
例子
基础示例
# Add a simple script
add_script("hello_cube", '''
import bpy
# Clear existing objects
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
# Create a cube
bpy.ops.mesh.primitive_cube_add(size=2, location=(0, 0, 0))
print("Cube created!")
''')
# Execute the script
execute_script("hello_cube")
# Get the result
# Access using: result://hello_cube
使用混合文件
# Add a script that works with a blend file
add_script("analyze_scene", '''
import bpy
# Print information about the current scene
print(f"Current Blender version: {bpy.app.version_string}")
print(f"Current file: {bpy.data.filepath}")
# List all objects in the scene
print("\\nObjects in the scene:")
for obj in bpy.data.objects:
print(f" - {obj.name} ({obj.type})")
''')
# Execute with a specific blend file
execute_script("analyze_scene", blend_file="/path/to/your/project.blend")
# Get the result
# Access using: result://analyze_scene
运作原理
- 添加脚本时,它会存储在
script_files/scripts目录 - 执行时,脚本在无头Blender实例中运行
- 如果指定了混合文件,Blender将在运行脚本之前打开该文件
- 否则,将使用默认的空Blender场景
- 输出和错误被捕获并存储在
script_files/results目录 - 在中跟踪有关脚本的元数据
script_files/metadata.json
安装
- 克隆此存储库
- 安装MCP库:
pip install mcp - 确保Blender已安装并可从PATH访问
许可证
麻省理工学院