Skip to main content
Glama

Smart Home MCP Server

by vmm
PROJECT_PLAN.md•8.78 kB
# Smart Home MCP Server - Project Plan ## šŸ“‹ Project Summary Build an MCP (Model Context Protocol) server to control smart home devices (TP-Link Kasa, Tuya, and other WiFi devices) through LLM integration, bypassing Google Home API limitations. The system will enable N8N automation workflows and provide human-friendly APIs for device control. ## šŸ  Your Environment Details ### Network Configuration - **Main Network**: `192.168.86.x` (MacBook development, future Raspberry Pi) - **Guest Network**: `192.168.87.x` (Smart devices isolated) - **Router**: Google WiFi Pro 6 mesh system - **Challenge**: Cross-network communication between main and guest networks ### Smart Devices - **Count**: 5-10 devices total - **Types**: RGB light bulbs, smart plugs - **Brands**: TP-Link Kasa, Tuya-based devices, generic Amazon WiFi devices - **Current Control**: Google Home app only ### Development Setup - **Initial Development**: MacBook (current machine) - **Production Deployment**: Raspberry Pi (future) - **Automation Platform**: N8N on VPS (Hostinger) - **External Access**: Will use Cloudflare Tunnel ## šŸŽÆ Project Goals 1. **Learn MCP Server Development** - Build production-quality MCP tools 2. **LLM Home Control** - Control lights via natural language through Claude/other LLMs 3. **N8N Integration** - Create automation workflows (build status indicators, alerts) 4. **Network Discovery** - Solve device discovery across network boundaries 5. **Human-Friendly APIs** - Create intuitive, well-documented interfaces ## šŸ—ļø System Architecture ```mermaid graph TB subgraph "External Services" N8N[N8N on VPS] Claude[Claude Desktop] GitHub[GitHub Webhooks] end subgraph "MacBook/Pi - Main Network 192.168.86.x" MCP[MCP Server :3000] API[Smart Home API :3001] Registry[Device Registry] Discovery[Discovery Service] end subgraph "Guest Network 192.168.87.x" Kasa[Kasa Devices] Tuya[Tuya Devices] Other[Other WiFi Devices] end N8N --> |Cloudflare Tunnel| MCP Claude --> |MCP Protocol| MCP GitHub --> |Webhooks| N8N MCP --> API API --> Registry API --> Discovery Discovery -.->|Network Scan| Kasa Discovery -.->|Cross-Network| Tuya Discovery -.->|Discovery| Other API -->|HTTP/TCP| Kasa API -->|Tuya Protocol| Tuya API -->|Various| Other ``` ## šŸ”§ Technical Components ### 1. Device Registry System - Manual MAC address → Device name mapping - Persistent storage (JSON initially, DB later) - Device capabilities metadata - Room/location grouping ### 2. Network Discovery - ARP table scanning for MAC addresses - Cross-network device detection - Fallback to manual IP configuration - Device online/offline status tracking ### 3. Device Control Protocols - **TP-Link Kasa**: Direct HTTP API (port 9999) - **Tuya**: Local API with device keys - **Generic WiFi**: Protocol detection/fallback ### 4. MCP Server Tools - `turnOnLight(deviceName, brightness?, color?)` - `turnOffLight(deviceName)` - `setScene(sceneName)` - Predefined lighting scenes - `flashAlert(color, duration)` - Visual notifications - `getBuildStatus()` / `setBuildStatus(status)` - `listDevices()` - Show available devices - `getDeviceStatus(deviceName)` - Current state ### 5. REST API Endpoints - `GET /api/devices` - List all devices with status - `GET /api/devices/:name` - Get specific device info - `POST /api/devices/:name/control` - Control device - `GET /api/scenes` - List available scenes - `POST /api/scenes/:name/activate` - Activate scene - `GET /api/discovery/scan` - Trigger network scan - `POST /api/registry/device` - Add/update device mapping ## 🚧 Known Challenges & Solutions ### Challenge 1: Cross-Network Communication **Problem**: Devices on guest network (192.168.87.x) isolated from main network **Solutions**: - Configure firewall rules to allow specific ports - Use mDNS/Bonjour for discovery - Manual IP:Port mapping as fallback - Consider running discovery service on guest network ### Challenge 2: Device Name Mapping **Problem**: Google Home has friendly names, network shows only MACs **Solution**: Build semi-automated mapping tool: 1. List all devices by MAC 2. Toggle devices on/off in Google Home 3. Match MAC to friendly name 4. Store in persistent registry ### Challenge 3: Unknown Device Protocols **Problem**: Generic Amazon devices may use various protocols **Solution**: Protocol detection strategy: 1. Try common protocols (Tuya, Smart Life) 2. Packet sniffing for unknown protocols 3. Fallback to IR/RF bridge if needed ## šŸ“ Project Structure ``` home-automation/ ā”œā”€ā”€ packages/ │ ā”œā”€ā”€ mcp-server/ # MCP Server implementation │ │ ā”œā”€ā”€ src/ │ │ │ ā”œā”€ā”€ index.ts # MCP server entry │ │ │ ā”œā”€ā”€ tools/ # MCP tool definitions │ │ │ └── config.ts # Server configuration │ │ └── package.json │ │ │ ā”œā”€ā”€ smart-home-api/ # REST API & device control │ │ ā”œā”€ā”€ src/ │ │ │ ā”œā”€ā”€ app.ts # Express server │ │ │ ā”œā”€ā”€ controllers/ # API endpoints │ │ │ ā”œā”€ā”€ services/ # Business logic │ │ │ │ ā”œā”€ā”€ discovery.ts │ │ │ │ ā”œā”€ā”€ registry.ts │ │ │ │ └── device-resolver.ts │ │ │ └── devices/ # Protocol implementations │ │ │ ā”œā”€ā”€ kasa.ts │ │ │ ā”œā”€ā”€ tuya.ts │ │ │ └── generic.ts │ │ └── package.json │ │ │ └── shared/ # Shared types & utilities │ ā”œā”€ā”€ src/ │ │ ā”œā”€ā”€ types.ts │ │ └── utils.ts │ └── package.json │ ā”œā”€ā”€ data/ │ └── device-registry.json # Device mappings │ ā”œā”€ā”€ scripts/ │ ā”œā”€ā”€ discover-devices.ts # Network scanning tool │ ā”œā”€ā”€ test-device.ts # Device control tester │ └── build-registry.ts # Registry builder wizard │ ā”œā”€ā”€ docker/ │ ā”œā”€ā”€ Dockerfile.mcp │ ā”œā”€ā”€ Dockerfile.api │ └── docker-compose.yml │ ā”œā”€ā”€ docs/ │ ā”œā”€ā”€ MCP_INTEGRATION.md │ ā”œā”€ā”€ DEVICE_SETUP.md │ ā”œā”€ā”€ NETWORK_CONFIG.md │ └── API_REFERENCE.md │ └── examples/ ā”œā”€ā”€ n8n-workflows/ ā”œā”€ā”€ claude-config/ └── test-scripts/ ``` ## šŸ” Security Considerations 1. **Authentication**: Bearer token for external access 2. **Network Isolation**: Minimize cross-network exposure 3. **Encryption**: Use HTTPS for Cloudflare Tunnel 4. **Secrets Management**: Environment variables for keys 5. **Rate Limiting**: Prevent device flooding 6. **Audit Logging**: Track all device control actions ## šŸ“Š Success Metrics 1. **Phase 1**: Control one device via HTTP API 2. **Phase 2**: MCP server responds to Claude commands 3. **Phase 3**: N8N workflow changes lights on GitHub events 4. **Phase 4**: Full device discovery across networks 5. **Final**: Natural language control of all devices ## šŸ”— Integration Points ### N8N Workflows - GitHub webhook → Build status lights - Calendar events → Scene activation - Weather changes → Lighting adjustments - Security alerts → Flash notifications ### Claude/LLM Integration - "Turn on the living room lights" - "Set work mode lighting" - "Flash red alert for failed build" - "Dim all lights for movie time" ## šŸ“š Learning Objectives 1. **MCP Protocol**: Deep understanding of tool creation 2. **Network Programming**: Cross-subnet communication 3. **IoT Protocols**: Kasa, Tuya, generic WiFi devices 4. **API Design**: RESTful and RPC patterns 5. **Docker Deployment**: Multi-container orchestration 6. **Security**: Network isolation and authentication ## šŸŽÆ MVP Definition **Minimum Viable Product includes:** - Control 2-3 devices (1 Kasa, 1 Tuya) - Basic MCP server with on/off/color tools - Simple device registry (hardcoded initially) - Local network operation only - Basic documentation **Not required for MVP:** - Full network discovery - Web dashboard - Complex scenes - Docker deployment - Cloudflare tunnel --- ## šŸ“… Timeline Estimate **Week 1**: Research & Setup (8-10 hours) - Network analysis and device identification - Basic Kasa/Tuya control working - Device registry design **Week 2**: Core Development (10-12 hours) - REST API implementation - MCP server creation - Basic integration testing **Week 3**: Integration & Polish (8-10 hours) - N8N workflow setup - Cloudflare tunnel configuration - Documentation and testing **Total estimate**: 26-32 hours over 3 weeks

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/vmm/homer-mcp'

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