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