development
location
documentation
public
home assistant
MCP
What is Model Context Protocol Server for Home Assistant enabling natural language control of smart home devices.?
The server uses the MCP protocol to share access to a local Home Assistant instance with an LLM application. 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.
Documentation
Model Context Protocol Server for Home Assistant
The server uses the MCP protocol to share access to a local Home Assistant instance with an LLM application.
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.
Features
๐ฎ Device Control: Control any Home Assistant device through natural language
๐ Real-time Updates: Get instant updates through Server-Sent Events (SSE)
๐ค Automation Management: Create, update, and manage automations
๐ State Monitoring: Track and query device states
๐ Secure: Token-based authentication and rate limiting
๐ฑ Mobile Ready: Works with any HTTP-capable client
Real-time Updates with SSE
The server includes a powerful Server-Sent Events (SSE) system that provides real-time updates from your Home Assistant instance. This allows you to:
๐ Get instant state changes for any device
๐ก Monitor automation triggers and executions
๐ฏ Subscribe to specific domains or entities
๐ Track service calls and script executions
Quick SSE Example
const eventSource = new EventSource(
'http://localhost:3000/subscribe_events?token=YOUR_TOKEN&domain=light'
);
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Update received:', data);
};
See SSE_API.md for complete documentation of the SSE system.
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)
The project includes Docker support for easy deployment and consistent environments across different platforms.
Clone the repository:
git clone https://github.com/jango-blockchained/homeassistant-mcp.git
cd homeassistant-mcp
Configure environment:
cp .env.example .env
Edit the .env file with your Home Assistant configuration:
# 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
DEBUG=false
Build and run with Docker Compose:
# Build and start the containers
docker compose up -d
# View logs
docker compose logs -f
# Stop the service
docker compose down
Verify the installation:
The server should now be running at http://localhost:3000. You can check the health endpoint at http://localhost:3000/health.
Update the application:
# Pull the latest changes
git pull
# Rebuild and restart the containers
docker compose up -d --build
Docker Configuration
The Docker setup includes:
Multi-stage build for optimal image size
Health checks for container monitoring
Volume mounting for environment configuration
Automatic container restart on failure
Exposed port 3000 for API access
Docker Compose Environment Variables
All environment variables can be configured in the .env file. The following variables are supported:
HASS_HOST: Your Home Assistant instance URL
HASS_TOKEN: Long-lived access token for Home Assistant
HASS_SOCKET_URL: WebSocket URL for Home Assistant
PORT: Server port (default: 3000)
NODE_ENV: Environment (production/development)
DEBUG: Enable debug mode (true/false)
Configuration# Environment Variables
HASS_HOST=http://homeassistant.local:8123 # Your Home Assistant instance URL
HASS_TOKEN=your_home_assistant_token # Long-lived access token
HASS_SOCKET_URL=ws://homeassistant.local:8123/api/websocket # WebSocket URL
# Server Configuration
PORT=3000 # Server port (default: 3000)
NODE_ENV=production # Environment (production/development)
DEBUG=false # Enable debug mode
# Test Configuration
TEST_HASS_HOST=http://localhost:8123 # Test instance URL
TEST_HASS_TOKEN=test_token # Test token
Configuration Files
Development: Copy .env.example to .env.development
Production: Copy .env.example to .env.production
Testing: Copy .env.example to .env.test
Adding to Claude Desktop (or other clients)
To use your new Home Assistant MCP server, you can add Claude Desktop as a client. Add the following to the configuration. Note this will run the MCP within claude and does not work with the Docker method.
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_HOST accessibility
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)