A standalone MCP (Model Context Protocol) server that enables AI assistants to interact with Home Assistant π π€
Note: This is a fork of home-assistant-cursor-agent by Coolver, adapted to work as a standalone Docker container with any Home Assistant installation (not just Home Assistant OS) and any AI client that supports the MCP protocol (not just Cursor).
Home Assistant MCP Server is a standalone FastAPI server that provides a REST API enabling AI assistants to interact with Home Assistant through the Model Context Protocol (MCP). It works with:
- β Any Home Assistant installation: Home Assistant Container, Core, Supervised, or OS
- β Any AI client: Cursor, VS Code + Copilot, Claude Desktop, or any MCP-compatible client
- β Dockerized Home Assistant: Specifically designed for containerized deployments
Let AI build your Home Assistant automations β or act as your DevOps for the ones you write by hand. Just describe what you need in natural language.
Transform the way you manage your smart home. This server enables Cursor, Visual Studio Code (VS Code), Claude Desktop, or any MCP-enabled IDE to:
- π Analyze your Home Assistant configuration, entities, and devices
- ποΈ Create intelligent automations, scripts, and complete systems β including Home Assistant helpers that can be fully managed programmatically
- π¨ Design and customize Lovelace dashboards with full control over cards, layouts, and styling
- ποΈ Create and tweak themes for a personalized UI
- π Safely deploy changes with automatic Git-based versioning
- π Monitor and troubleshoot your setup through log analysis
- π¦ Install and manage HACS integrations and custom repositories
β Read your full configuration β entities, automations, scripts, helpers β Understand your devices β capabilities, relations, and usage patterns β Learn existing logic β analyze how your current automations and scripts behave
β Create complete systems β multiple interconnected automations in seconds β Generate helpers and sensors β tailored to your actual setup and needs β Write optimized scripts β based on real entities, areas, and devices β Refactor existing logic β improve or merge automations instead of starting from scratch
β Create and update Lovelace dashboards β fully programmatically β Add, remove, or rearrange cards β stat, graphs, history, custom cards, and more β Control layouts and views β organize rooms, areas, and scenarios β Design and tweak themes β colors, typography, and styles for a personalized UI
β Git-based versioning β every change is tracked with meaningful commit messages β Human-readable commits β AI explains what changed and why β Configuration validation β test before apply to reduce breaking changes β One-click rollback β revert to a previous state if something goes wrong β Activity log β full audit trail of what the agent did and when
β Install and configure HACS β unlock 1000+ community integrations β Search repositories β themes, plugins, custom components, dashboards β Install integrations β one-command setup for new HACS components β Keep things fresh β update all HACS repositories from a single place
- Full REST API and WebSocket access
- List all entities and their states
- Call any Home Assistant service
- Reload components (automations, scripts, templates)
- Configuration validation
- Real-time state monitoring
Complete HACS management via WebSocket:
- Install HACS automatically from GitHub
- Search repositories by name, author, or category
- Install integrations, themes, and plugins
- Update all installed repositories
- View repository details (stars, versions, authors)
- Create/Update/Delete Automations (via REST API)
- Create/Update/Delete Scripts (via REST API)
- Create/Delete Input Helpers (boolean, text, number, datetime, select)
- Automatic reload after changes
- Entity Registry β list, update, and remove entities
- Area Registry β create, update, and delete areas
- Device Registry β list and manage devices
- Dead entity detection β find orphaned entities
- List, read, write, append, delete files
- Automatic backup before modifications
- YAML parsing and validation
- Safe path handling (restricted to
/config)
- Automatic commit on every change
- Backup history (up to 50 commits)
- Rollback to any previous state
- View diffs between versions
- Meaningful commit messages
- Server logs API with filtering
- Operation history tracking
- Real-time status monitoring
- Health check endpoint
The server is available as pre-built Docker images:
- Docker Hub:
itsmrshow/home-assistant-mcp-server:latest - GitHub Container Registry:
ghcr.io/itsmrshow/home-assistant-mcp-server:latest
Supported Platforms:
linux/amd64(Intel/AMD 64-bit)linux/arm64(ARM 64-bit - Raspberry Pi 4, Apple Silicon, etc.)linux/arm/v7(ARM 32-bit - Raspberry Pi 3, etc.)
- Docker and Docker Compose installed
- Home Assistant running (any installation type)
- A Home Assistant Long-Lived Access Token
- Open your Home Assistant UI
- Go to your profile (click your username in the sidebar)
- Scroll down to "Long-Lived Access Tokens"
- Click "Create Token"
- Give it a name (e.g., "MCP Server")
- Copy the token (you won't see it again!)
# Clone this repository
git clone https://github.com/itsmrshow/home-assistant-mcp-server.git
cd home-assistant-mcp-server
# Copy environment template
cp .env.example .env
# Edit .env file with your details
nano .envEdit .env and set:
HA_URL=http://YOUR_HOME_ASSISTANT_IP:8123
HA_TOKEN=your_long_lived_access_token_here
HA_AGENT_KEY= # Leave empty to auto-generate, or set your ownImportant: Replace YOUR_HOME_ASSISTANT_IP with:
- Your Home Assistant's IP address (e.g.,
http://192.168.1.100:8123) - Or
http://homeassistant.local:8123if mDNS is working on your network - Or
http://host.docker.internal:8123if HA is on the same machine
Then start it:
docker-compose up -dThe default docker-compose.yml uses the pre-built image from Docker Hub.
If you want to build the image yourself:
# Clone this repository
git clone https://github.com/itsmrshow/home-assistant-mcp-server.git
cd home-assistant-mcp-server
# Copy environment template
cp .env.example .env
# Edit .env file with your details
nano .envEdit .env and set:
HA_URL=http://YOUR_HOME_ASSISTANT_IP:8123
HA_TOKEN=your_long_lived_access_token_here
HA_AGENT_KEY= # Leave empty to auto-generate, or set your ownThen build and start:
# Build from source
docker-compose -f docker/docker-compose.build.yml up -d --build
# View logs
docker-compose -f docker/docker-compose.build.yml logs -f# Start with Docker Compose (using pre-built image)
docker-compose up -d
# View logs
docker-compose logs -f
# Check health
curl http://localhost:8099/api/healthThe server will:
- Start on port 8099
- Auto-generate an API key if not provided
- Display the API key in the logs
- Save it to
config/.ha_mcp_server_key - Generate MCP client configuration files:
config/mcp_client_config.json- Ready-to-use MCP configconfig/MCP_CLIENT_SETUP.md- Complete setup instructions
The server automatically generates configuration files for you!
After the server starts, check the config/ directory for:
MCP_CLIENT_SETUP.md- Complete setup instructions for all AI clientsmcp_client_config.json- Ready-to-use configuration with your API key
- Copy the contents from
config/mcp_client_config.json - Paste into
~/.cursor/mcp.json - Restart Cursor
- Copy the contents from
config/mcp_client_config.json - Paste into your VS Code MCP settings
- Restart VS Code
- Copy the contents from
config/mcp_client_config.json - Paste into:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- macOS:
- Restart Claude Desktop
Manual Configuration: If you prefer to manually configure, the files are in:
- API Key:
config/.ha_mcp_server_key - Or check logs:
docker-compose logs | grep "API Key"
Restart your AI client and try:
- "List my Home Assistant entities"
- "Show me all my lights"
- "Create an automation to turn on lights at sunset"
| Variable | Description | Default | Required |
|---|---|---|---|
HA_URL |
Home Assistant URL | http://homeassistant.local:8123 |
Yes |
HA_TOKEN |
Long-Lived Access Token | - | Yes |
HA_AGENT_KEY |
API key for MCP clients | Auto-generated | No |
PORT |
Server port | 8099 |
No |
LOG_LEVEL |
Logging level | info |
No |
ENABLE_GIT |
Enable git versioning | true |
No |
AUTO_BACKUP |
Auto backup on changes | true |
No |
MAX_BACKUPS |
Maximum git commits | 50 |
No |
CONFIG_PATH |
Config storage path | /config |
No |
The docker-compose.yml allows you to:
- Change the exposed port (default: 8099)
- Mount your Home Assistant config for direct file access
- Adjust git versioning settings
- Configure logging levels
Once running, visit:
- Interactive Swagger Docs: http://localhost:8099/docs
- ReDoc Documentation: http://localhost:8099/redoc
- Health Check: http://localhost:8099/api/health
Entities:
GET /api/entities- List all entitiesGET /api/entities/states- Get all entity statesPOST /api/entities/call_service- Call any HA service
Automations:
GET /api/automations- List automationsPOST /api/automations- Create automationPUT /api/automations/{id}- Update automationDELETE /api/automations/{id}- Delete automation
Scripts:
GET /api/scripts- List scriptsPOST /api/scripts- Create scriptPUT /api/scripts/{id}- Update scriptDELETE /api/scripts/{id}- Delete script
Helpers:
GET /api/helpers- List input helpersPOST /api/helpers/input_boolean- Create boolean helperPOST /api/helpers/input_text- Create text helperDELETE /api/helpers/{entity_id}- Delete helper
Files:
GET /api/files/list- List files in configGET /api/files/read- Read file contentPOST /api/files/write- Write fileDELETE /api/files/delete- Delete file
Registries:
GET /api/registries/entities/list- List entity registryGET /api/registries/areas/list- List areasGET /api/registries/devices/list- List devicesGET /api/registries/entities/dead- Find orphaned entities
HACS:
POST /api/hacs/install- Install HACSGET /api/hacs/repositories- Search repositoriesPOST /api/hacs/install_repository- Install integration
System:
POST /api/system/reload- Reload HA componentsPOST /api/system/check_config- Validate configurationGET /api/system/info- Get HA system info
Backup & Git:
GET /api/backup/history- View git historyPOST /api/backup/rollback- Rollback to commitGET /api/backup/diff- View changes
Security:
POST /api/regenerate-key- Regenerate API key (requires auth)
-
Secure Your Tokens:
- Never commit
.envfile to git (already in.gitignore) - Use strong Long-Lived Access Tokens
- Rotate tokens periodically
- Never commit
-
Network Security:
- Run on trusted network only
- Consider using a reverse proxy with HTTPS
- Use firewall rules to restrict access
-
API Key Management:
- Keep
HA_AGENT_KEYsecret - Don't share in public repositories
- Use the
/api/regenerate-keyendpoint if compromised
- Keep
-
Docker Security:
- Keep base images updated
- Review mounted volumes
- Run with minimal permissions
# Clone the repository
git clone https://github.com/itsmrshow/home-assistant-mcp-server.git
cd home-assistant-mcp-server
# Build the Docker image
docker build -f docker/Dockerfile -t ha-mcp-server .
# Or use docker-compose
docker-compose -f docker/docker-compose.build.yml up -d --build
# Run locally with docker run
docker run -p 8099:8099 \
-e HA_URL=http://YOUR_HA_IP:8123 \
-e HA_TOKEN=your_token \
-v $(pwd)/config:/config \
ha-mcp-server# Install dependencies
pip install -r requirements.txt
# Set environment variables
export HA_URL=http://YOUR_HA_IP:8123
export HA_TOKEN=your_token
export CONFIG_PATH=./config
# Run the server
python -m app.mainFor more detailed development information, see DEVELOPMENT.md and CONTRIBUTING.md.
Check logs:
docker-compose logs -fCommon issues:
- Missing
HA_TOKENin.env - Wrong
HA_URL(check IP address and port) - Port 8099 already in use (change in
docker-compose.yml)
Test connection:
curl -H "Authorization: Bearer YOUR_TOKEN" http://YOUR_HA_IP:8123/api/Verify:
- Home Assistant is running and accessible
- Token is valid and hasn't expired
- URL is correct (include
http://and port) - No firewall blocking the connection
Verify:
- Server is running (
docker-compose ps) - API key is correct (check logs or file)
- URL in MCP config matches server location
- Client has been restarted after config changes
If you see this error, make sure Node.js is installed on the machine running the MCP client:
# Install Node.js (varies by OS)
# macOS: brew install node
# Ubuntu: sudo apt install nodejs npm
# Windows: download from nodejs.orgCheck:
- Config directory is properly mounted
- Docker container has write permissions
- Git is enabled (
ENABLE_GIT=true)
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
See CHANGELOG.md for a detailed list of changes.
- π Merged upstream changes from v2.10.0 through v2.10.36
- ποΈ Added Entity/Area/Device Registry API endpoints
- π§ Switched automations and scripts to REST API for create/update/delete
- π Added API key regeneration endpoint with auth requirement
- π Security fixes for critical vulnerabilities
- π¦ Improved HACS integration (repository access, install/update)
- πΎ Improved git versioning with shadow repository and auto/manual modes
- π Added comprehensive test suite
- π οΈ Token-efficient script/automation tools and YAML helpers
- π Added CHANGELOG, CONTRIBUTING, DEVELOPMENT, and CODE_OF_CONDUCT docs
- π Added VS Code + Copilot support
- π Dead entity detection for finding orphaned entities
- π Forked from home-assistant-cursor-agent
- π³ Converted to standalone Docker container
- π Added support for any Home Assistant installation type
- π€ Generalized for any MCP-compatible AI client
- β Removed Home Assistant OS add-on dependencies
- β Removed Supervisor API integration
- β¨ Simplified authentication using only HA tokens
- π Updated documentation for standalone deployment
MIT License - see LICENSE file for details
- Original Project: home-assistant-cursor-agent by Coolver
- Model Context Protocol: Anthropic MCP
- Home Assistant: Home Assistant Project
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with β€οΈ for the Home Assistant and AI community