hue_mcp

hue_mcp

A production-ready Model Context Protocol (MCP) server that enables Claude to control Philips Hue lights through natural language commands.

Category
访问服务器

README

Hue MCP Server

A production-ready Model Context Protocol (MCP) server that enables Claude to control Philips Hue lights through natural language commands. Built with FastMCP framework and designed for seamless integration with Claude Desktop.

Features

  • 🏠 Room-based Control: Control lights by room (kitchen, bedroom, office, basement, living_room)
  • 💡 Individual Light Control: Control specific lights by ID (1-17)
  • 🔍 Light Discovery: List all lights and get their current states
  • 🌉 Bridge Integration: Discover and test connectivity to Hue bridge
  • ⚡ High Performance: Async operations with connection pooling and rate limiting
  • 🛡️ Error Handling: Comprehensive error handling with retry logic
  • 📊 Production Ready: Full test coverage, logging, and monitoring

Available MCP Tools

Tool Description Parameters
hue_control_light Control individual light by ID light_id, action, brightness?, color_temp?
hue_control_room Control all lights in a room room, action, brightness?, color_temp?
hue_get_light_state Get current state of a light light_id
hue_list_lights List all lights and states None
hue_discover_bridge Test bridge connectivity None

Supported Rooms

  • kitchen - Controls lights: 10, 12, 13, 17 (stove_1, toaster_1, toaster_2, stove_2)
  • bedroom - Controls lights: 1, 4 (neals_lamp, bonnies_lamp)
  • office - Controls lights: 7 (office)
  • basement - Controls lights: 5, 6, 14, 15, 16 (basement_e, basement_w, stairway, batcave_color_1, batcave_color_2)
  • living_room - Controls lights: 3 (small_reading_lamp)
  • all - Controls all lights using group 0

Supported Actions

  • on - Turn lights on
  • off - Turn lights off
  • toggle - Toggle light state

Installation

Prerequisites

  • Python 3.8 or higher
  • Philips Hue Bridge on local network
  • Bridge username (already configured for IP 192.168.1.64)

Install Dependencies

# Install the package
pip install -e .

# Or install with development dependencies
pip install -e ".[dev]"

Environment Configuration

  1. Copy the environment template:

    cp .env.example .env
    
  2. Edit .env file if needed (default values work for the configured setup):

    HUE_BRIDGE_IP=192.168.1.64
    HUE_USERNAME=cJdzxhKlxr2h92jwDkTv-DvpOxglPxn147UEg1Gp
    LOG_LEVEL=INFO
    

Usage

Running the MCP Server

# Run directly
python -m hue_mcp

# Or using the console script
hue-mcp

Claude Desktop Integration

Add this configuration to your Claude Desktop MCP settings:

{
  "mcpServers": {
    "hue-control": {
      "command": "python",
      "args": ["-m", "hue_mcp"],
      "cwd": "/path/to/hue-mcp-server"
    }
  }
}

Natural Language Examples

Once integrated with Claude Desktop, you can use natural language commands:

  • "Turn on the kitchen lights" → Turns on lights 10, 12, 13, 17
  • "Set office light to 50% brightness" → Dims office light (ID 7) to ~127 brightness
  • "Turn off all lights" → Turns off all lights using group control
  • "What lights are currently on?" → Lists all lights with their current states
  • "Toggle the bedroom lights" → Toggles lights 1 and 4

Testing

Run Unit Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=src --cov-report=term-missing

# Run specific test file
pytest tests/test_hue_client.py -v

Test Bridge Connectivity

# Test basic connectivity
python -c "
import asyncio
from src.hue_mcp.hue_client import AsyncHueClient

async def test():
    async with AsyncHueClient() as client:
        success = await client.test_connection()
        print(f'Bridge connection: {\"SUCCESS\" if success else \"FAILED\"}')

asyncio.run(test())
"

Development

Code Quality

# Linting and formatting
ruff check src/ --fix
ruff format src/

# Type checking
mypy src/

# Run all quality checks
ruff check . --fix && mypy src/ && ruff format .

Project Structure

hue-mcp-server/
├── src/hue_mcp/
│   ├── __init__.py          # Package initialization
│   ├── __main__.py          # CLI entry point
│   ├── server.py            # Main MCP server
│   ├── hue_client.py        # Async HTTP client with rate limiting
│   ├── light_manager.py     # Business logic and room mappings
│   ├── config.py            # Configuration management
│   └── tools/               # MCP tool implementations
│       ├── light_control.py # Individual light control
│       ├── room_control.py  # Room-based control
│       └── discovery.py     # Light discovery and bridge testing
├── tests/                   # Comprehensive test suite
├── pyproject.toml           # Project configuration
├── README.md               # This file
└── .env.example            # Environment template

Performance

  • Light Operations: Under 1 second response time
  • Room Operations: Under 3 seconds for multiple lights
  • Rate Limiting: 10 light operations/second, 1 group operation/second
  • Connection Pooling: Optimized HTTP connections with keepalive
  • Concurrent Operations: Up to 5 concurrent light operations per room

Error Handling

The server includes comprehensive error handling for:

  • Network Issues: Connection timeouts, DNS failures
  • Bridge Errors: Invalid light IDs, bridge unavailable
  • Rate Limiting: Automatic retry with exponential backoff
  • Validation Errors: Invalid parameters, out-of-range values

Configuration

Environment Variables

Variable Default Description
HUE_BRIDGE_IP 192.168.1.64 IP address of Hue bridge
HUE_USERNAME (configured) Bridge authentication username
LOG_LEVEL INFO Logging level (DEBUG, INFO, WARNING, ERROR)
HUE_TIMEOUT_CONNECT 5.0 Connection timeout (seconds)
HUE_TIMEOUT_READ 10.0 Read timeout (seconds)
HUE_MAX_CONNECTIONS 10 Maximum HTTP connections
HUE_LIGHT_RATE_LIMIT 10 Light operations per second
HUE_GROUP_RATE_LIMIT 1.0 Group operations per second

Troubleshooting

Common Issues

Bridge Not Found

Error: Failed to connect to Hue bridge at 192.168.1.64
Solution: Verify bridge IP and network connectivity

Authentication Failed

Error: Invalid username/authentication
Solution: Verify HUE_USERNAME in .env file

Rate Limiting

Warning: Rate limited, retrying...
Solution: Normal behavior, requests will retry automatically

Debugging

Enable debug logging:

export LOG_LEVEL=DEBUG
python -m hue_mcp

Bridge Information

  • IP Address: 192.168.1.64
  • Username: cJdzxhKlxr2h92jwDkTv-DvpOxglPxn147UEg1Gp
  • Light Range: IDs 1-17
  • Configured Rooms: kitchen, bedroom, office, basement, living_room

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make changes with tests
  4. Run quality checks: ruff check . --fix && mypy src/ && pytest
  5. Submit a pull request

Built with ❤️ using FastMCP and designed for seamless Claude integration.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选