forked from mcp-use/mcp-use
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblender_use.py
More file actions
53 lines (39 loc) · 1.52 KB
/
blender_use.py
File metadata and controls
53 lines (39 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Blender MCP example for mcp_use.
This example demonstrates how to use the mcp_use library with MCPClient
to connect an LLM to Blender through MCP tools via WebSocket.
The example assumes you have installed the Blender MCP addon from:
https://github.com/ahujasid/blender-mcp
Make sure the addon is enabled in Blender preferences and the WebSocket
server is running before executing this script.
Special thanks to https://github.com/ahujasid/blender-mcp for the server.
"""
import asyncio
from dotenv import load_dotenv
from langchain_anthropic import ChatAnthropic
from mcp_use import MCPAgent, MCPClient
async def run_blender_example():
"""Run the Blender MCP example."""
# Load environment variables
load_dotenv()
# Create MCPClient with Blender MCP configuration
config = {"mcpServers": {"blender": {"command": "uvx", "args": ["blender-mcp"]}}}
client = MCPClient.from_dict(config)
# Create LLM
llm = ChatAnthropic(model="claude-sonnet-4-5")
# Create agent with the client
agent = MCPAgent(llm=llm, client=client, max_steps=30, pretty_print=True)
try:
# Run the query
result = await agent.run(
"Create an inflatable cube with soft material and a plane as ground.",
max_steps=30,
)
print(f"\nResult: {result}")
finally:
# Ensure we clean up resources properly
if client.sessions:
await client.close_all_sessions()
if __name__ == "__main__":
# Run the Blender example
asyncio.run(run_blender_example())