Smart House MCP Server
# π Smart House MCP Server

> One interface to rule them all. Natural language in, vendor-specific action out.
Smart House is an [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) server that gives any AI assistant full control over your smart home β regardless of what brands or protocols your devices use.
You say **"turn bedroom lights to warm white at 20%"**. The assistant figures out the intent, calls a standardized tool, and the server routes it to the right vendor SDK under the hood. You never think about WiZ vs Hue vs Tuya again.
```
you β assistant β MCP tool call β adapter β actual device
```
---
## π§ Why This Exists
Every smart home brand has its own API, its own SDK, its own protocol. Some use local UDP. Some use cloud REST. Some use MQTT. Some use a proprietary bridge. Some use jank you reverse-engineered at 2am.
This server sits in the middle. It exposes **one set of tools** that work across **all** of them. The adapter layer translates. Your assistant just calls `turn_on` and doesn't care what's behind it.
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MCP Server β
β β
β βββββββββββββββββ ββββββββββββββββββ ββββββββββββββββββ β
β β 11 Tools β β Device β β Scene β β
β β β β Registry β β Engine β β
β β list_devices β β β β β β
β β get_state β β 16+ devices β β 6 built-in β β
β β turn_on/off β β canonical β β + custom β β
β β set_brightnessβ β objects with β β scenes β β
β β set_color β β fuzzy resolve β β β β
β β set_color_tempβ β β β β β
β β control_deviceβ β β β β β
β β run_scene β β β β β β
β β list_scenes β β β β β β
β β create_scene β β β β β β
β βββββββββ¬ββββββββ βββββββββ¬βββββββββ ββββββββββββββββββ β
β β β β
β βββββββββΌββββββββββββββββββββΌββββββββββββββββββββββββββββββββ β
β β Adapter Manager β β
β β β β
β β ββββββββ ββββββββ ββββββββ ββββββββ βββββββββββββ β β
β β β Demo β β WiZ β β Hue β β Tuya β β MQTT β β β
β β β β β β β β β β β β β β
β β β sim β β UDP β β REST β βCloud β β Broker β β β
β β ββββββββ ββββββββ ββββββββ ββββββββ βββββββββββββ β β
β β β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β β
β β β Home Assistant (REST API) β β β
β β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
---
## β‘ Quick Start
### 1. Install
```bash
cd Smart_House
npm install
```
### 2. Test (no hardware needed)
```bash
npm test
```
This runs 38 integration tests against the built-in demo adapter β 16 simulated devices across 6 rooms.
```
βββ Smart House MCP β Tests βββ
Device Registry:
β has devices (16)
β can get by id
β findByRoom bedroom
β findByType bulb
β findByGroup bedroom lights
...
38 passed, 0 failed
```
### 3. Start the server
```bash
npm start
```
```
[smart-house] adapter loaded: demo
[demo] registered 16 simulated devices
[smart-house] 16 devices registered total
[smart-house] 6 scenes loaded
[smart-house] 11 tools registered
[smart-house] MCP server ready β waiting for connections
```
### 4. Connect to Claude Desktop
Add this to your `claude_desktop_config.json`:
```json
{
"mcpServers": {
"smart-house": {
"command": "node",
"args": ["F:/MK Solutions/MCPs/Smart_House/src/index.js"]
}
}
}
```
Restart Claude Desktop. Then just talk:
- *"Turn bedroom lights to warm white at 20%"*
- *"What's the temperature in the kitchen?"*
- *"Run movie night scene"*
- *"Turn off everything in the house"*
- *"Set living room to a nice sunset orange"*
- *"Open bedroom curtains halfway"*
- *"Create a scene called 'dinner party' that dims the kitchen and turns on the living room lights"*
---
## π§ MCP Tools Reference
### Device Control
| Tool | Description | Key Parameters |
|------|-------------|----------------|
| **`list_devices`** | List all registered devices | `room?`, `type?`, `group?`, `adapter?` |
| **`get_state`** | Get current state of device(s) | `target` |
| **`turn_on`** | Turn on with optional settings | `target`, `brightness?`, `color?`, `color_temp?` |
| **`turn_off`** | Turn off device(s) | `target` |
| **`set_brightness`** | Set brightness 1β100% | `target`, `brightness` |
| **`set_color`** | Set hex color | `target`, `color` (e.g. `"#ff0000"`) |
| **`set_color_temp`** | Set color temperature | `target`, `color_temp` (warm/soft/neutral/cool/daylight/bright) |
| **`control_device`** | Generic command for any device | `target`, `command`, `params?` |
### Scene Management
| Tool | Description | Key Parameters |
|------|-------------|----------------|
| **`run_scene`** | Execute a named scene | `scene` |
| **`list_scenes`** | List all available scenes | β |
| **`create_scene`** | Create a new scene | `name`, `description?`, `actions[]` |
### `control_device` Commands
For devices that go beyond on/off/brightness:
| Command | For | Parameters |
|---------|-----|-----------|
| `set_temperature` | AC/Thermostat | `{ temperature: 22 }` |
| `set_mode` | AC | `{ mode: "cool" }` |
| `set_fan_speed` | AC | `{ fan_speed: "auto" }` |
| `set_speed` | Fan | `{ speed: "medium" }` |
| `set_position` | Curtains | `{ position: 80 }` (0=closed, 100=open) |
| `set_volume` | TV | `{ volume: 30 }` |
| `set_channel` | TV | `{ channel: 5 }` |
| `set_source` | TV | `{ source: "hdmi1" }` |
---
## π― Target Resolution
Every tool that controls a device accepts a `target` string. The server resolves it using a layered fuzzy matcher:
| Priority | Method | Example |
|----------|--------|---------|
| 1 | **Exact ID** | `"demo-bed-bulb-1"` |
| 2 | **Exact name** | `"Bedroom Ceiling Light"` |
| 3 | **Group name** | `"bedroom lights"` β 2 bulbs |
| 4 | **Room + type** | `"bedroom bulbs"` β 2 bulbs, `"kitchen lights"` β 1 bulb |
| 5 | **Name substring** | `"ceiling"` β Bedroom Ceiling Light |
This means you can say `"bedroom lights"` and it resolves to every bulb in the bedroom. Or `"Kitchen Coffee Machine"` for a single device. The assistant doesn't need to know device IDs.
---
## π Adapters
### Demo β `src/adapters/demo.js`
**Status:** β
Works out of the box, no hardware needed.
Simulates 16 devices across 6 rooms with realistic state management. Every command updates in-memory state with a small random delay to simulate network latency.
**Enabled by default.**
---
### WiZ β `src/adapters/wiz.js`
**Protocol:** Local UDP, port 38899
**Supports:** Power, brightness, RGB color, color temperature
WiZ bulbs are controlled over your local network via JSON-over-UDP. The adapter can either auto-discover bulbs via broadcast or use an explicit device list.
```js
// src/config.js
wiz: {
enabled: true,
broadcast: "192.168.1.255", // for auto-discovery
timeout: 3000, // discovery timeout in ms
devices: [ // or list them explicitly
{
ip: "192.168.1.100",
name: "Bedroom WiZ Bulb",
room: "bedroom",
mac: "AA:BB:CC:DD:EE:FF", // optional
groups: ["bedroom lights"]
}
]
}
```
---
### Philips Hue β `src/adapters/hue.js`
**Protocol:** Local REST API via Hue Bridge
**Supports:** Power, brightness, CIE xy color, color temperature (mirek)
Connects to your Hue bridge on the local network. You need the bridge IP and an API username.
**Getting a Hue API username:**
1. Press the physical button on your Hue bridge
2. Within 30 seconds, run:
```bash
curl -X POST http://<bridge-ip>/api -d '{"devicetype":"smart-house-mcp"}'
```
3. Copy the `username` from the response
```js
// src/config.js
hue: {
enabled: true,
bridgeIp: "192.168.1.50",
username: "your-hue-api-username",
roomMap: { // optional: map Hue light IDs to rooms
"1": "bedroom",
"2": "living room"
},
groupMap: { // optional: map Hue light IDs to groups
"1": ["bedroom lights"],
"2": ["living room lights"]
}
}
```
---
### Tuya β `src/adapters/tuya.js`
**Protocol:** Tuya Open API v2.0 (cloud, HMAC-SHA256 auth)
**Supports:** Power, brightness, HSV color, color temperature
Controls Tuya/Smart Life devices through the cloud API. Requires a Tuya IoT Platform developer account.
**Getting Tuya credentials:**
1. Sign up at [iot.tuya.com](https://iot.tuya.com)
2. Create a Cloud Project
3. Link your Smart Life app account
4. Copy the Access ID (key) and Access Secret
```js
// src/config.js
tuya: {
enabled: true,
accessKey: "your-access-id",
secretKey: "your-access-secret",
region: "us", // us | eu | cn | in
devices: [
{
id: "eb0f...", // Tuya device ID
name: "Smart Plug Kitchen",
room: "kitchen",
type: "plug", // bulb | plug | ac | curtain | fan
groups: ["kitchen appliances"]
}
]
}
```
---
### MQTT β `src/adapters/mqtt.js`
**Protocol:** MQTT (any broker β Mosquitto, EMQX, HiveMQ, etc.)
**Supports:** Anything β fully configurable per device
**Requires:** `npm install mqtt`
The most flexible adapter. Works with any MQTT-based device. Supports both simple string payloads (`"ON"`/`"OFF"`) and structured JSON mode.
```js
// src/config.js
mqtt: {
enabled: true,
brokerUrl: "mqtt://192.168.1.10:1883",
username: "mqttuser", // optional
password: "mqttpass", // optional
devices: [
{
id: "mqtt-garage-light",
name: "Garage Light",
room: "garage",
type: "bulb",
capabilities: ["power", "brightness"],
commandTopic: "home/garage/light/set",
stateTopic: "home/garage/light/state",
jsonMode: false, // false = simple strings, true = JSON payloads
payloadMap: { // custom payload strings (simple mode only)
turn_on: "ON",
turn_off: "OFF"
}
},
{
id: "mqtt-zigbee-bulb",
name: "Zigbee Bulb",
room: "office",
type: "bulb",
capabilities: ["power", "brightness", "color_temp"],
commandTopic: "zigbee2mqtt/office_bulb/set",
stateTopic: "zigbee2mqtt/office_bulb",
jsonMode: true // sends { "state": "ON", "brightness": 80 }
}
]
}
```
---
### Home Assistant β `src/adapters/homeassistant.js`
**Protocol:** Home Assistant REST API
**Supports:** Lights, switches, fans, covers, climate, media players, sensors
The nuclear option. If HA already controls your devices, this adapter lets the MCP server talk through HA instead of directly to each brand. Supports auto-discovery of all entities or an explicit list.
**Getting a HA long-lived access token:**
1. Go to your HA instance β Profile β Security
2. Scroll to "Long-Lived Access Tokens"
3. Create one, copy it
```js
// src/config.js
homeassistant: {
enabled: true,
url: "http://homeassistant.local:8123",
token: "eyJhbGciOiJI...",
// Option A: auto-discover all entities (no entities array)
// Option B: explicit list for better naming/grouping
entities: [
{
entity_id: "light.bedroom_ceiling",
name: "Bedroom Ceiling Light",
room: "bedroom",
type: "bulb",
groups: ["bedroom lights"]
},
{
entity_id: "climate.bedroom_ac",
name: "Bedroom AC",
room: "bedroom",
type: "ac",
groups: []
}
]
}
```
---
## π¬ Built-in Scenes
| Scene | What Happens |
|-------|-------------|
| **`goodnight`** | All lights off, bedroom AC β 22Β°C, curtains closed, TV off |
| **`morning`** | Curtains open, kitchen light β daylight 100%, coffee machine on, AC off |
| **`movie night`** | Living room β 10% warm, TV on HDMI1, other rooms off |
| **`focus`** | Bedroom β daylight 100%, TV off |
| **`romantic`** | Bedroom + living room β 10-15% warm, floor lamp β orange, others off |
| **`all off`** | Every single device in the house β off |
### Creating Custom Scenes
Via the `create_scene` tool (the assistant can do this conversationally):
```json
{
"name": "dinner party",
"description": "Warm ambiance for hosting",
"actions": [
{ "target": "kitchen lights", "command": "set_brightness", "params": { "brightness": 70 } },
{ "target": "Kitchen Light", "command": "set_color_temp", "params": { "color_temp": "warm" } },
{ "target": "living room lights", "command": "set_brightness", "params": { "brightness": 40 } },
{ "target": "Living Room Main Light", "command": "set_color_temp", "params": { "color_temp": "soft" } },
{ "target": "Living Room TV", "command": "turn_off" }
]
}
```
---
## ποΈ Demo Devices
The demo adapter ships with a full simulated house:
| Room | Device | Type | Capabilities |
|------|--------|------|-------------|
| **Bedroom** | Ceiling Light | bulb | power, brightness, color, color_temp |
| | Nightstand Lamp | bulb | power, brightness, color_temp |
| | Charger Plug | plug | power |
| | AC | ac | power, temperature, mode, fan_speed |
| | Curtains | curtain | power, position |
| **Living Room** | Main Light | bulb | power, brightness, color, color_temp |
| | Floor Lamp | bulb | power, brightness, color |
| | TV | tv | power, volume, channel, source |
| | Fan Plug | plug | power |
| **Kitchen** | Light | bulb | power, brightness, color_temp |
| | Coffee Machine | plug | power |
| | Temperature Sensor | sensor | temperature, humidity |
| **Bathroom** | Light | bulb | power, brightness |
| | Exhaust Fan | fan | power, speed |
| **Hallway** | Motion Sensor | sensor | motion, luminance |
| **Garage** | Door Opener | plug | power |
---
## π§© Adding a Custom Adapter
Every adapter is a simple module with three functions:
```js
// src/adapters/myvendor.js
module.exports = {
name: "myvendor",
/**
* Called once at startup. Discover devices and register them.
*/
async initialize(registry, config) {
// Talk to your vendor's API, discover devices, then:
registry.register({
id: "myvendor-001",
name: "Office Desk Lamp",
room: "office",
type: "bulb",
adapter: "myvendor",
groups: ["office lights"],
capabilities: ["power", "brightness", "color"],
state: { power: false, brightness: 100, color: "#ffffff" },
meta: {
// anything adapter-specific: IP, API key, device token, etc.
ip: "192.168.1.200",
deviceToken: "abc123"
}
});
},
/**
* Called for every command. Route to real hardware.
*/
async execute(device, command, params) {
const ip = device.meta.ip;
switch (command) {
case "turn_on":
await myVendorApi.setPower(ip, true);
device.state.power = true;
return { power: true };
case "turn_off":
await myVendorApi.setPower(ip, false);
device.state.power = false;
return { power: false };
case "set_brightness":
await myVendorApi.setBrightness(ip, params.brightness);
device.state.brightness = params.brightness;
device.state.power = true;
return { brightness: params.brightness };
case "set_color":
await myVendorApi.setColor(ip, params.color);
device.state.color = params.color;
device.state.power = true;
return { color: params.color };
case "get_state":
return { ...device.state };
default:
throw new Error(`unsupported: ${command}`);
}
},
/**
* Optional cleanup on shutdown.
*/
async disconnect() {
// close connections, etc.
}
};
```
Then wire it in:
**1. Add to config (`src/config.js`):**
```js
myvendor: {
enabled: true,
// your config here
}
```
**2. Load in server (`src/index.js`):**
```js
const adapterModules = {
// ... existing adapters
myvendor: require("./adapters/myvendor"),
};
```
Done. The tool layer, scene engine, and target resolution all work automatically.
---
## π Project Structure
```
Smart_House/
β
βββ src/
β βββ index.js # MCP server entry point β wires everything together
β βββ config.js # Adapter configuration β enable/disable, set credentials
β β
β βββ core/
β β βββ device-registry.js # Central device store, queries, fuzzy target resolution
β β βββ adapter-manager.js # Loads adapters, routes commands to the right one
β β βββ scene-engine.js # Scene storage, batch execution
β β
β βββ adapters/
β β βββ demo.js # 16 simulated devices, 6 rooms (no hardware)
β β βββ wiz.js # WiZ bulbs β local UDP, port 38899
β β βββ hue.js # Philips Hue β local REST via bridge
β β βββ tuya.js # Tuya/Smart Life β cloud API v2.0
β β βββ mqtt.js # Generic MQTT β any broker, any device
β β βββ homeassistant.js # Home Assistant β REST API, auto-discovery
β β
β βββ tools/
β β βββ tools.js # 11 MCP tool definitions with Zod schemas
β β
β βββ devices/
β βββ default-scenes.js # 6 pre-built scenes
β
βββ tests/
β βββ run.js # 38 integration tests (runs against demo adapter)
β
βββ package.json
βββ README.md
```
---
## π§ͺ Running Tests
```bash
npm test
```
Tests exercise the full pipeline without MCP transport β registry, resolution, all 11 tools, scene execution, and error handling. No hardware or network required.
---
## π Color Temperature Reference
| Name | Kelvin | Vibe |
|------|--------|------|
| `warm` | 2700K | Cozy, candlelight |
| `soft` | 3000K | Relaxed, warm white |
| `neutral` | 3500K | Natural, balanced |
| `cool` | 4000K | Alert, clean |
| `daylight` | 5000K | Bright, productive |
| `bright` | 6500K | Blue-white, clinical |
---
## π Device Canonical Shape
Every device in the registry follows this shape, regardless of which adapter registered it:
```js
{
id: "demo-bed-bulb-1", // unique identifier
name: "Bedroom Ceiling Light", // human-friendly name
room: "bedroom", // room assignment
type: "bulb", // bulb|plug|ac|tv|curtain|sensor|fan|switch|thermostat
adapter: "demo", // which adapter owns this device
groups: ["bedroom lights"], // arbitrary grouping tags
capabilities: ["power","brightness","color","color_temp"], // what it can do
state: { // current known state
power: false,
brightness: 100,
color: "#ffffff",
color_temp: "daylight"
},
meta: { // adapter-specific data
simulated: true // (ip, mac, entity_id, topic, etc.)
}
}
```
---
## π License
ISC
TDQS
Scored across 11 tools
Each tool has a clear primary role: on/off, attribute setters, generic control, and scene management. The only real overlap is that control_device is a catch-all that could also do brightness/color, and turn_on accepts brightness/color params that duplicate set_brightness/set_color, but the descriptions steer toward the dedicated tools for common cases.
All 11 tools are lowercase snake_case with a verb-first pattern (turn_on, list_devices, get_state, set_color, run_scene, create_scene), and the paired turn_on/turn_off are symmetric. No mixed casing or stylistic drift anywhere in the set.
11 tools is squarely in the well-scoped range for a smart home controller. Convenience wrappers (set_brightness, set_color, set_color_temp) plus an escape hatch (control_device) plus scene management is a reasonable, non-bloated surface.
Core lifecycle is covered: discovery (list_devices), state inspection (get_state), actuation (on/off/attribute setters/generic control), and scene list/run/create. Scene management is asymmetric though β there is create_scene but no update_scene or delete_scene β and there is no tool for device/group configuration, which agents will have to work around.