Skip to main content
Glama
pedrof
by pedrof
test_connection.pyβ€’4.05 kB
#!/usr/bin/env python3 """ Test script to verify Hue Bridge connection and basic functionality. """ import asyncio import os import sys from dotenv import load_dotenv # Add src to path for imports sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) from hue_mcp_server.hue_client import HueClient async def test_connection(): """Test connection to Hue Bridge and basic operations.""" # Load environment variables load_dotenv() bridge_ip = os.getenv("HUE_BRIDGE_IP") api_key = os.getenv("HUE_API_KEY") print("=" * 60) print("Philips Hue MCP Server - Connection Test") print("=" * 60) print() # Verify credentials if not bridge_ip: print("❌ ERROR: HUE_BRIDGE_IP not set in .env file") return False if not api_key: print("❌ ERROR: HUE_API_KEY not set in .env file") return False print(f"πŸ“ Bridge IP: {bridge_ip}") print(f"πŸ”‘ API Key: {api_key[:10]}..." if len(api_key) > 10 else f"πŸ”‘ API Key: {api_key}") print() # Create client print("πŸ”Œ Connecting to Hue Bridge...") client = HueClient(bridge_ip, api_key) try: # Test connection await client.connect() print("βœ… Connected successfully!") print() # Test getting lights print("πŸ’‘ Fetching lights...") lights = await client.get_lights() print(f"βœ… Found {len(lights)} light(s)") print() if lights: print("Light Details:") print("-" * 60) for light_id, light_data in lights.items(): status = "ON" if light_data["on"] else "OFF" brightness = light_data.get("brightness") brightness_str = f" | Brightness: {brightness:.0f}%" if brightness else "" print(f" β€’ {light_data['name']}") print(f" ID: {light_id} | Status: {status}{brightness_str}") print() # Test getting groups print("🏠 Fetching groups/rooms...") groups = await client.get_groups() print(f"βœ… Found {len(groups)} group(s)") print() if groups: print("Group Details:") print("-" * 60) for group_id, group_data in groups.items(): light_count = len(group_data.get("lights", [])) print(f" β€’ {group_data['name']}") print(f" ID: {group_id} | Type: {group_data['type']} | Lights: {light_count}") print() # Test getting scenes print("🎨 Fetching scenes...") scenes = await client.get_scenes() print(f"βœ… Found {len(scenes)} scene(s)") print() if scenes: print("Scene Details (showing first 5):") print("-" * 60) for i, (scene_id, scene_data) in enumerate(list(scenes.items())[:5]): print(f" β€’ {scene_data['name']}") print(f" ID: {scene_id}") if len(scenes) > 5: print(f" ... and {len(scenes) - 5} more scenes") print() print("=" * 60) print("βœ… All tests passed! Your Hue Bridge is ready to use.") print("=" * 60) print() print("Next steps:") print(" 1. Run the MCP server: python -m hue_mcp_server.server") print(" 2. Or configure it with Claude Desktop (see README.md)") print() return True except Exception as e: print(f"❌ ERROR: {e}") print() print("Troubleshooting:") print(" 1. Verify your bridge IP is correct") print(" 2. Check that your API key is valid") print(" 3. Ensure you're on the same network as the bridge") print(" 4. Try pressing the bridge button and generating a new API key") return False finally: await client.disconnect() print("πŸ”Œ Disconnected from bridge") if __name__ == "__main__": success = asyncio.run(test_connection()) sys.exit(0 if success else 1)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pedrof/hue-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server