"""
Test script for Blender MCP integration.
Run in Blender:
1. Open Blender 5.0
2. Go to Scripting workspace
3. Open this file
4. Run script
Or from command line:
blender --python test_in_blender.py
"""
import sys
from pathlib import Path
# Add paths to find our modules
PROJECT_ROOT = Path(__file__).parent.parent
sys.path.insert(0, str(PROJECT_ROOT / "target" / "release"))
sys.path.insert(0, str(PROJECT_ROOT / "python"))
print(f"[Test] Project root: {PROJECT_ROOT}")
print(f"[Test] Python path: {sys.path[:3]}")
# Test 1: Import Rust module
print("\n[Test 1] Importing blender_mcp Rust module...")
try:
import blender_mcp
print(f" OK: blender_mcp imported")
print(f" Available: {dir(blender_mcp)}")
except ImportError as e:
print(f" FAILED: {e}")
print(" Make sure you built with: cargo build --release")
sys.exit(1)
# Test 2: Import Python wrapper
print("\n[Test 2] Importing blender_mcp_wrapper...")
try:
from blender_mcp_wrapper import BlenderMcpBridge, start_mcp
print(f" OK: BlenderMcpBridge imported")
except ImportError as e:
print(f" FAILED: {e}")
sys.exit(1)
# Test 3: Create instance
print("\n[Test 3] Creating BlenderMcp instance...")
try:
mcp = blender_mcp.BlenderMcp("test", 8765)
print(f" OK: Instance created (tag={mcp.tag}, port={mcp.port})")
except Exception as e:
print(f" FAILED: {e}")
sys.exit(1)
# Test 4: Start server
print("\n[Test 4] Starting MCP server...")
try:
port = mcp.start()
print(f" OK: Server started on port {port}")
print(f" URL: {mcp.url()}")
except Exception as e:
print(f" FAILED: {e}")
sys.exit(1)
# Test 5: List instances
print("\n[Test 5] Listing instances...")
try:
instances = blender_mcp.list_instances()
print(f" OK: Instances = {dict(instances)}")
except Exception as e:
print(f" FAILED: {e}")
# Test 6: Start bridge with polling
print("\n[Test 6] Starting full bridge with polling...")
try:
bridge = BlenderMcpBridge("bridge_test", 8766)
actual_port = bridge.start(poll_interval=0.1)
print(f" OK: Bridge started on port {actual_port}")
print(f" URL: {bridge.url}")
except Exception as e:
print(f" FAILED: {e}")
# Summary
print("\n" + "="*50)
print("MCP SERVERS RUNNING:")
print("="*50)
for tag, port in blender_mcp.list_instances().items():
print(f" - {tag}: http://127.0.0.1:{port}/mcp")
print("\nYou can now connect Claude Code to these endpoints!")
print("To stop: bridge.stop() or mcp.stop()")