Control Xiaomi smart home devices through AI assistants via MCP (Model Context Protocol). QR code login, zero config.
Overview
Control your Xiaomi smart home devices through AI assistants via the Model Context Protocol (MCP). Works with Claude Code, Claude Desktop, Cursor, and any MCP-compatible client. - — Automatically find all devices in your Xiaomi account - — Read power state, brightness, temperature, humidity, battery, lock status - — Turn on/off, adjust brightness, color temperature, target temperature - — Play/pause music, TTS, volume control, voice commands - — Scan with Mi Home app, no password needed - — Just two Python files, no pip install required - Python 3.10+ - uv (recommended) or pip - Mi Home app on your phone (for QR code login) A QR code will open in your browser. Scan it with the Mi Home app (Profile → Scan icon in top-right corner). Tokens are saved to ~/.xiaomi-mcp/tokens.json with 600 permissions. That's it! Now you can talk to your devices: "Turn on the lamp" "What's the room temperature?" "Is the door locked?" "Set brightness to 50%" "Play some music"
README
Xiaomi Home MCP Server
Control your Xiaomi smart home devices through AI assistants via the Model Context Protocol (MCP).
Works with Claude Code, Claude Desktop, Cursor, and any MCP-compatible client.
Features
- Device Discovery — Automatically find all devices in your Xiaomi account
- Status Monitoring — Read power state, brightness, temperature, humidity, battery, lock status
- Device Control — Turn on/off, adjust brightness, color temperature, target temperature
- XiaoAi Speaker — Play/pause music, TTS, volume control, voice commands
- QR Code Login — Scan with Mi Home app, no password needed
- Zero Dependencies Setup — Just two Python files, no pip install required
Quick Start
Prerequisites
- Python 3.10+
- uv (recommended) or pip
- Mi Home app on your phone (for QR code login)
1. Login
uv run --script login.py
A QR code will open in your browser. Scan it with the Mi Home app (Profile → Scan icon in top-right corner).
Tokens are saved to ~/.xiaomi-mcp/tokens.json with 600 permissions.
2. Connect to Claude Code
claude mcp add xiaomi-home -- uv run --script /path/to/mcp_server.py
That’s it! Now you can talk to your devices:
“Turn on the lamp” “What’s the room temperature?” “Is the door locked?” “Set brightness to 50%” “Play some music”
2a. Connect to Claude Desktop
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"xiaomi-home": {
"command": "uv",
"args": ["run", "--script", "/path/to/mcp_server.py"]
}
}
}
Available Tools
| Tool | Description |
|---|---|
get_devices() |
List all devices and online status |
get_device_status(name?) |
Query detailed status (power, brightness, temperature, battery, etc.) |
control_device(name, action) |
Control device: on/off, brightness, color_temp, target_temp |
play_music(keyword?) |
Play music on XiaoAi speaker |
pause_music() |
Pause playback |
resume_music() |
Resume playback |
set_volume(volume) |
Set speaker volume (0-100) |
tts(text) |
Text-to-speech on speaker |
xiaoai_command(command) |
Send voice command to XiaoAi |
get_speaker_status() |
Get playback status |
Supported Devices
The server auto-detects device types by model prefix:
| Type | Models | Status Query | Control |
|---|---|---|---|
| Light | philips.light.*, yeelink.light.* |
Power, Brightness | On/Off, Brightness, Color Temp |
| AC Partner | lumi.acpartner.* |
Power | On/Off |
| Heater | xiaomi.heater.* |
Power, Target Temp | On/Off, Target Temp |
| Fan | xiaomi.fan.* |
Power, Speed, Oscillate | On/Off |
| Lock | loock.lock.* |
Lock State, Battery | — |
| Sensor | miaomiaoce.sensor_ht.* |
Temperature, Humidity, Battery | — |
| Speaker | xiaomi.wifispeaker.* |
Playback Status | Play, Pause, Volume, TTS |
| Kettle | yunmi.kettle.* |
BLE only (not supported) | — |
Note: MIoT spec properties (siid/piid) vary by model. The built-in mappings cover common models. If your device returns incorrect values, you may need to look up the correct spec at miot-spec.com and adjust the
MIOT_PROPSdict inmcp_server.py.
Token Management
# Check if token is still valid
uv run --script login.py --check
# Clear cached token
uv run --script login.py --logout
# Re-login
uv run --script login.py
Tokens are long-lived but may expire after weeks/months. If the MCP server starts failing, re-run login.py.
Alternative: Environment Variables
If you prefer not to use the login tool, you can pass credentials directly:
claude mcp add xiaomi-home \
-e XIAOMI_PASS_TOKEN="your_pass_token" \
-e XIAOMI_USER_ID="your_user_id" \
-e XIAOMI_DEVICE_ID="your_device_id" \
-- uv run --script /path/to/mcp_server.py
To get these values, log in to account.xiaomi.com in your browser and extract passToken, userId, and deviceId from cookies.
How It Works
Mi Home App (scan QR) → login.py → ~/.xiaomi-mcp/tokens.json
↓
Claude / Cursor ←→ MCP Protocol ←→ mcp_server.py ←→ Xiaomi Cloud API
(api.io.mi.com)
- Authentication: passToken → serviceToken exchange (auto-refreshed)
- Device Control: MIoT spec protocol (siid/piid) + legacy miio RPC
- Speaker: Dual channel — IoT (control/TTS) + MiNA (volume/status)
License
MIT
Install
This server does not publish a one-line install command.
Open the repository installation guideConfiguration
{
"mcpServers": {
"xiaomi-home": {
"command": "uv",
"args": ["run", "--script", "/path/to/mcp_server.py"]
}
}
}