"""Test MCP server start/stop through addon operators."""
import bpy
import time
import sys
print("[Test] Testing MCP server via addon...", flush=True)
# Enable addon
bpy.ops.preferences.addon_enable(module="mcp_server")
print("[Test] Addon enabled", flush=True)
# Start server
print("[Test] Starting MCP server...", flush=True)
try:
result = bpy.ops.mcp.start(port=8765)
print(f"[Test] Start result: {result}", flush=True)
except Exception as e:
print(f"[Test] Start failed: {e}", flush=True)
sys.exit(1)
# Wait a bit
time.sleep(1)
# Check status
print("[Test] Checking status...", flush=True)
try:
bpy.ops.mcp.status()
except Exception as e:
print(f"[Test] Status check: {e}", flush=True)
# Test HTTP endpoint
print("[Test] Testing HTTP endpoint...", flush=True)
try:
import urllib.request
with urllib.request.urlopen("http://127.0.0.1:8765/health", timeout=5) as response:
data = response.read().decode()
print(f"[Test] Health check: {data}", flush=True)
except Exception as e:
print(f"[Test] HTTP test failed: {e}", flush=True)
# Stop server
print("[Test] Stopping server...", flush=True)
try:
bpy.ops.mcp.stop()
print("[Test] Server stopped", flush=True)
except Exception as e:
print(f"[Test] Stop failed: {e}", flush=True)
print("[Test] ALL TESTS PASSED!", flush=True)