110f2a308c2a88990cb31da44ebef61f612ca5a3
- Introduced WebSocket client for real-time Home Assistant event streaming - Created context management system for tracking resource relationships and state - Implemented performance monitoring and optimization utilities - Added security middleware with token validation, rate limiting, and input sanitization - Extended tool registry with enhanced tool registration and execution capabilities - Expanded test coverage for new modules and added comprehensive test scenarios - Improved type safety and added robust error handling across new modules
Model Context Protocol Server for Home Assistant
Forked from tevonsb/homeassistant-mcp
A powerful bridge between your Home Assistant instance and Language Learning Models (LLMs), enabling natural language control and monitoring of your smart home devices through the Model Context Protocol (MCP). This server provides a comprehensive API for managing your entire Home Assistant ecosystem, from device control to system administration.
Table of Contents
- Key Features
- Prerequisites
- Installation
- Configuration
- Development
- API Reference
- Natural Language Integration
- Troubleshooting
- Project Status
- Contributing
- Resources
- License
Key Features
Core Functionality 🎮
- Smart Device Control
- 💡 Lights: Brightness, color temperature, RGB color
- 🌡️ Climate: Temperature, HVAC modes, fan modes, humidity
- 🚪 Covers: Position and tilt control
- 🔌 Switches: On/off control
- 🚨 Sensors & Contacts: State monitoring
- 🎵 Media Players: Playback control, volume, source selection
- 🌪️ Fans: Speed, oscillation, direction
- 🔒 Locks: Lock/unlock control
- 🧹 Vacuums: Start, stop, return to base
- 📹 Cameras: Motion detection, snapshots
System Management 🛠️
-
Add-on Management
- Browse available add-ons
- Install/uninstall add-ons
- Start/stop/restart add-ons
- Version management
- Configuration access
-
Package Management (HACS)
- Integration with Home Assistant Community Store
- Multiple package types support:
- Custom integrations
- Frontend themes
- Python scripts
- AppDaemon apps
- NetDaemon apps
- Version control and updates
- Repository management
-
Automation Management
- Create and edit automations
- Advanced configuration options:
- Multiple trigger types
- Complex conditions
- Action sequences
- Execution modes
- Duplicate and modify existing automations
- Enable/disable automation rules
- Trigger automation manually
Architecture Features 🏗️
-
Intelligent Organization
- Area and floor-based device grouping
- State monitoring and querying
- Smart context awareness
- Historical data access
-
Robust Architecture
- Comprehensive error handling
- State validation
- Secure API integration
- TypeScript type safety
- Extensive test coverage
Prerequisites
- Node.js 20.10.0 or higher
- NPM package manager
- Docker Compose for containerization
- Running Home Assistant instance
- Home Assistant long-lived access token (How to get token)
- HACS installed for package management features
- Supervisor access for add-on management
Installation
Basic Setup
# Clone the repository
git clone https://github.com/jango-blockchained/homeassistant-mcp.git
cd homeassistant-mcp
# Install dependencies
npm install
# Build the project
npm run build
Docker Setup (Recommended)
-
Clone and prepare:
git clone -b docker https://github.com/jango-blockchained/homeassistant-mcp.git cd homeassistant-mcp cp .env.example .env -
Configure environment
.envfile:# Home Assistant Configuration HASS_HOST=http://homeassistant.local:8123 HASS_TOKEN=your_home_assistant_token HASS_SOCKET_URL=ws://homeassistant.local:8123/api/websocket # Server Configuration PORT=3000 NODE_ENV=production -
Launch with Docker Compose:
docker-compose up -d
API Reference
Device Control
Common Entity Controls
{
"tool": "control",
"command": "turn_on", // or "turn_off", "toggle"
"entity_id": "light.living_room"
}
Light Control
{
"tool": "control",
"command": "turn_on",
"entity_id": "light.living_room",
"brightness": 128,
"color_temp": 4000,
"rgb_color": [255, 0, 0]
}
Add-on Management
List Available Add-ons
{
"tool": "addon",
"action": "list"
}
Install Add-on
{
"tool": "addon",
"action": "install",
"slug": "core_configurator",
"version": "5.6.0"
}
Manage Add-on State
{
"tool": "addon",
"action": "start", // or "stop", "restart"
"slug": "core_configurator"
}
Package Management
List HACS Packages
{
"tool": "package",
"action": "list",
"category": "integration" // or "plugin", "theme", "python_script", "appdaemon", "netdaemon"
}
Install Package
{
"tool": "package",
"action": "install",
"category": "integration",
"repository": "hacs/integration",
"version": "1.32.0"
}
Automation Management
Create Automation
{
"tool": "automation_config",
"action": "create",
"config": {
"alias": "Motion Light",
"description": "Turn on light when motion detected",
"mode": "single",
"trigger": [
{
"platform": "state",
"entity_id": "binary_sensor.motion",
"to": "on"
}
],
"action": [
{
"service": "light.turn_on",
"target": {
"entity_id": "light.living_room"
}
}
]
}
}
Duplicate Automation
{
"tool": "automation_config",
"action": "duplicate",
"automation_id": "automation.motion_light"
}
Development
# Development mode with hot reload
npm run dev
# Build project
npm run build
# Production mode
npm run start
# Run tests
npx jest --config=jest.config.cjs
# Run tests with coverage
npx jest --coverage
# Lint code
npm run lint
# Format code
npm run format
Troubleshooting
Common Issues
-
Node.js Version (
toSorted is not a function)- Solution: Update to Node.js 20.10.0+
nvm install 20.10.0 nvm use 20.10.0 -
Connection Issues
- Verify Home Assistant is running
- Check
HASS_HOSTaccessibility - Validate token permissions
- Ensure WebSocket connection for real-time updates
-
Add-on Management Issues
- Verify Supervisor access
- Check add-on compatibility
- Validate system resources
-
HACS Integration Issues
- Verify HACS installation
- Check HACS integration status
- Validate repository access
-
Automation Issues
- Verify entity availability
- Check trigger conditions
- Validate service calls
- Monitor execution logs
Project Status
✅ Complete
- Entity, Floor, and Area access
- Device control (Lights, Climate, Covers, Switches, Contacts)
- Add-on management system
- Package management through HACS
- Advanced automation configuration
- Basic state management
- Error handling and validation
- Docker containerization
- Jest testing setup
- TypeScript integration
- Environment variable management
- Home Assistant API integration
- Project documentation
🚧 In Progress
- WebSocket implementation for real-time updates
- Enhanced security features
- Tool organization optimization
- Performance optimization
- Resource context integration
- API documentation generation
- Multi-platform desktop integration
- Advanced error recovery
- Custom prompt testing
- Enhanced macOS integration
- Type safety improvements
- Testing coverage expansion
Contributing
- Fork the repository
- Create a feature branch
- Implement your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
Resources
License
MIT License - See LICENSE file
Description
Languages
TypeScript
92.2%
Shell
3.4%
Python
2.3%
JavaScript
1.7%
Dockerfile
0.4%