#!/usr/bin/env python3
"""
Test script to check connection to Open Brush API
"""
import httpx
import sys
API_BASE_URL = "http://localhost:40074/api/v1"
def test_connection():
"""Test connection to Open Brush API"""
print("π Testing connection to Open Brush API...")
print(f"π‘ URL: {API_BASE_URL}")
print()
try:
# Test 1: Check that API responds
print("1οΈβ£ Connectivity test...")
response = httpx.get(API_BASE_URL, params={"help": ""}, timeout=5.0)
response.raise_for_status()
print(" β
API accessible!")
print()
# Test 2: Test a simple command
print("2οΈβ£ Testing simple command (undo)...")
response = httpx.get(API_BASE_URL, params={"undo": ""}, timeout=5.0)
response.raise_for_status()
print(" β
Command executed successfully!")
print(f" π Response: {response.text[:100]}...")
print()
# Test 3: Get help
print("3οΈβ£ Retrieving help...")
response = httpx.get(API_BASE_URL, params={"help": ""}, timeout=5.0)
if response.status_code == 200:
print(" β
Help page available!")
print(f" π Response size: {len(response.text)} characters")
print()
print("=" * 60)
print("β¨ All tests passed!")
print("=" * 60)
print()
print("The MCP server should work correctly.")
print("You can now:")
print(" 1. Configure Claude Desktop with this server")
print(" 2. Run: python openbrush_mcp_server.py")
return True
except httpx.ConnectError:
print(" β Cannot connect to API")
print()
print("Check that:")
print(" β’ Open Brush is running")
print(" β’ HTTP API is enabled in settings")
print(" β’ Port 40074 is being used")
return False
except httpx.HTTPError as e:
print(f" β HTTP Error: {e}")
return False
except Exception as e:
print(f" β Unexpected error: {e}")
return False
if __name__ == "__main__":
success = test_connection()
sys.exit(0 if success else 1)