Provides a flexible interface for Home Assistant device management and automation through a REST API and WebSocket/SSE connections, enabling basic device control, state updates, and automation rule management.
Enables GPU-accelerated speech processing capabilities when using NVIDIA GPUs with CUDA support, improving performance for wake word detection and speech-to-text features.
Home Assistant Model Context Protocol (MCP)
A standardized protocol for AI assistants to interact with Home Assistant, providing a secure, typed, and extensible interface for controlling smart home devices.
Overview
The Model Context Protocol (MCP) server acts as a bridge between AI models (like Claude, GPT, etc.) and Home Assistant, enabling AI assistants to:
- Execute commands on Home Assistant devices
- Retrieve information about the smart home
- Stream responses for long-running operations
- Validate parameters and inputs
- Provide consistent error handling
Features
- Modular Architecture - Clean separation between transport, middleware, and tools
- Typed Interface - Fully TypeScript typed for better developer experience
- Multiple Transports:
- Standard I/O (stdin/stdout) for CLI integration
- HTTP/REST API with Server-Sent Events support for streaming
- Middleware System - Validation, logging, timeout, and error handling
- Built-in Tools:
- Light control (brightness, color, etc.)
- Climate control (thermostats, HVAC)
- More to come...
- Extensible Plugin System - Easily add new tools and capabilities
- Streaming Responses - Support for long-running operations
- Parameter Validation - Using Zod schemas
- Claude & Cursor Integration - Ready-made utilities for AI assistants
Getting Started
Prerequisites
- Node.js 16+
- Home Assistant instance (or you can use the mock implementations for testing)
Installation
Running the Server
Configuration
Configure the server using environment variables or a .env
file:
Architecture
The MCP server is built with a layered architecture:
- Transport Layer - Handles communication protocols (stdio, HTTP)
- Middleware Layer - Processes requests through a pipeline
- Tool Layer - Implements specific functionality
- Resource Layer - Manages stateful resources
Tools
Tools are the primary way to add functionality to the MCP server. Each tool:
- Has a unique name
- Accepts typed parameters
- Returns typed results
- Can stream partial results
- Validates inputs and outputs
Example tool registration:
API
When running with HTTP transport, the server provides a JSON-RPC 2.0 API:
POST /api/mcp/jsonrpc
- Execute a toolGET /api/mcp/stream
- Connect to SSE stream for real-time updatesGET /api/mcp/info
- Get server informationGET /health
- Health check endpoint
Integration with AI Models
Claude Integration
Cursor Integration
To use the Home Assistant MCP server with Cursor, add the following to your .cursor/config/config.json
file:
This configuration:
- Runs the MCP server with stdio transport
- Redirects all stderr output to /dev/null
- Uses grep to filter stdout for lines containing
{"jsonrpc":"2.0"
, ensuring clean JSON-RPC output
Troubleshooting Cursor Integration
If you encounter a "failed to create client" error when using the MCP server with Cursor:
- Make sure you're using the correct command and arguments in your Cursor configuration
- The bash script approach ensures only valid JSON-RPC messages reach Cursor
- Ensure the server is built by running
bun run build
before trying to connect
- Ensure the server is properly outputting JSON-RPC messages to stdout:Then examine json_only.txt to verify it contains only valid JSON-RPC messages.
- Make sure grep is installed on your system (it should be available by default on most systems)
- Try rebuilding the server with:
- Enable debug mode by setting
DEBUG_STDIO=true
in the environment variables
If the issue persists, you can try:
- Restarting Cursor
- Clearing Cursor's cache (Help > Developer > Clear Cache and Reload)
- Using a similar approach with Node.js:
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
MCP Server for Home Assistant ๐ ๐ค
Overview ๐
MCP (Model Context Protocol) Server is my lightweight integration tool for Home Assistant, providing a flexible interface for device management and automation. It's designed to be fast, secure, and easy to use. Built with Bun for maximum performance.
Core Features โจ
- ๐ Basic device control via REST API
- ๐ก WebSocket/Server-Sent Events (SSE) for state updates
- ๐ค Simple automation rule management
- ๐ JWT-based authentication
- ๐ Standard I/O (stdio) transport for integration with Claude and other AI assistants
Why Bun? ๐
I chose Bun as the runtime for several key benefits:
- โก Blazing Fast Performance
- Up to 4x faster than Node.js
- Built-in TypeScript support
- Optimized file system operations
- ๐ฏ All-in-One Solution
- Package manager (faster than npm/yarn)
- Bundler (no webpack needed)
- Test runner (built-in testing)
- TypeScript transpiler
- ๐ Built-in Features
- SQLite3 driver
- .env file loading
- WebSocket client/server
- File watcher
- Test runner
- ๐พ Resource Efficient
- Lower memory usage
- Faster cold starts
- Better CPU utilization
- ๐ Node.js Compatibility
- Runs most npm packages
- Compatible with Express/Fastify
- Native Node.js APIs
Prerequisites ๐
- ๐ Bun runtime (v1.0.26+)
- ๐ก Home Assistant instance
- ๐ณ Docker (optional, recommended for deployment)
- ๐ฅ๏ธ Node.js 18+ (optional, for speech features)
- ๐ฎ NVIDIA GPU with CUDA support (optional, for faster speech processing)
Quick Start ๐
- Clone my repository:
- Set up the environment:
- Configure your settings:
- Edit
.env
file with your Home Assistant details - Required: Add your
HASS_TOKEN
(long-lived access token)
- Build and launch with Docker:
Docker Build Options ๐ณ
My Docker build script (docker-build.sh
) supports different configurations:
1. Standard Build
- Basic MCP server functionality
- REST API and WebSocket support
- No speech features
2. Speech-Enabled Build
- Includes wake word detection
- Speech-to-text capabilities
- Pulls required images:
onerahmet/openai-whisper-asr-webservice
rhasspy/wyoming-openwakeword
3. GPU-Accelerated Build
- All speech features
- CUDA GPU acceleration
- Optimized for faster processing
- Float16 compute type for better performance
Build Features
- ๐ Automatic resource allocation
- ๐พ Memory-aware building
- ๐ CPU quota management
- ๐งน Automatic cleanup
- ๐ Detailed build logs
- ๐ Build summary and status
Environment Configuration ๐ง
I've implemented a hierarchical configuration system:
File Structure ๐
.env.example
- My template with all options.env
- Your configuration (copy from .env.example)- Environment overrides:
.env.dev
- Development settings.env.prod
- Production settings.env.test
- Test settings
Loading Priority โก
Files load in this order:
.env
(base config)- Environment-specific file:
NODE_ENV=development
โ.env.dev
NODE_ENV=production
โ.env.prod
NODE_ENV=test
โ.env.test
Later files override earlier ones.
Development ๐ป
Performance Comparison ๐
Operation | Bun | Node.js |
---|---|---|
Install Dependencies | ~2s | ~15s |
Cold Start | 300ms | 1000ms |
Build Time | 150ms | 4000ms |
Memory Usage | ~150MB | ~400MB |
Documentation ๐
Core Documentation
Advanced Features
- Natural Language Processing - AI-powered automation analysis and control
- Custom Prompts Guide - Create and customize AI behavior
- Extras & Tools - Additional utilities and advanced features
Client Integration ๐
Cursor Integration ๐ฑ๏ธ
Add to .cursor/config/config.json
:
Claude Desktop ๐ฌ
Add to your Claude config:
Command Line ๐ป
Windows users can use the provided script:
- Go to
scripts
directory - Run
start_mcp.cmd
Additional Features
Speech Features ๐ค
MCP Server optionally supports speech processing capabilities:
- ๐ฃ๏ธ Wake word detection ("hey jarvis", "ok google", "alexa")
- ๐ฏ Speech-to-text using fast-whisper
- ๐ Multiple language support
- ๐ GPU acceleration support
Speech Features Setup
Prerequisites
- ๐ณ Docker installed and running
- ๐ฎ NVIDIA GPU with CUDA (optional)
- ๐พ 4GB+ RAM (8GB+ recommended)
Configuration
- Enable speech in
.env
:
- Choose your STT engine:
Available Models ๐ค
Choose based on your needs:
tiny.en
: Fastest, basic accuracybase.en
: Good balance (recommended)small.en
: Better accuracy, slowermedium.en
: High accuracy, resource intensivelarge-v2
: Best accuracy, very resource intensive
Launch with Speech Features
Extra Tools ๐ ๏ธ
I've included several powerful tools in the extra/
directory to enhance your Home Assistant experience:
- Home Assistant Analyzer CLI (
ha-analyzer-cli.ts
)- Deep automation analysis using AI models
- Security vulnerability scanning
- Performance optimization suggestions
- System health metrics
- Speech-to-Text Example (
speech-to-text-example.ts
)- Wake word detection
- Speech-to-text transcription
- Multiple language support
- GPU acceleration support
- Claude Desktop Setup (
claude-desktop-macos-setup.sh
)- Automated Claude Desktop installation for macOS
- Environment configuration
- MCP integration setup
See Extras Documentation for detailed usage instructions and examples.
License ๐
MIT License. See LICENSE for details.
Author ๐จโ๐ป
Created by jango-blockchained
Running with Standard I/O Transport ๐
MCP Server supports a JSON-RPC 2.0 stdio transport mode for direct integration with AI assistants like Claude:
MCP Stdio Features
โ
JSON-RPC 2.0 Compatibility: Full support for the MCP protocol standard
โ
NPX Support: Run directly without installation using npx homeassistant-mcp
โ
Auto Configuration: Creates necessary directories and default configuration
โ
Cross-Platform: Works on macOS, Linux, and Windows
โ
Claude Desktop Integration: Ready to use with Claude Desktop
โ
Parameter Validation: Automatic validation of tool parameters
โ
Error Handling: Standardized error codes and handling
โ
Detailed Logging: Logs to files without polluting stdio
Option 1: Using NPX (Easiest)
Run the MCP server directly without installation using npx:
This will:
- Install the package temporarily
- Automatically run in stdio mode with JSON-RPC 2.0 transport
- Create a logs directory for logging
- Create a default .env file if not present
Perfect for integration with Claude Desktop or other MCP clients.
Integrating with Claude Desktop
To use MCP with Claude Desktop:
- Open Claude Desktop settings
- Go to the "Advanced" tab
- Under "MCP Server", select "Custom"
- Enter the command:
npx homeassistant-mcp
- Click "Save"
Claude will now use the MCP server for Home Assistant integration, allowing you to control your smart home directly through Claude.
Option 2: Local Installation
- Update your
.env
file to enable stdio transport: - Run the server using the stdio-start script:Available options:
When running in stdio mode:
- The server communicates via stdin/stdout using JSON-RPC 2.0 format
- No HTTP server is started
- Console logging is disabled to avoid polluting the stdio stream
- All logs are written to the log files in the
logs/
directory
JSON-RPC 2.0 Message Format
Request Format
Response Format
Error Response Format
Notification Format (Server to Client)
Supported Error Codes
Code | Description | Meaning |
---|---|---|
-32700 | Parse error | Invalid JSON was received |
-32600 | Invalid request | JSON is not a valid request object |
-32601 | Method not found | Method does not exist or is unavailable |
-32602 | Invalid params | Invalid method parameters |
-32603 | Internal error | Internal JSON-RPC error |
-32000 | Tool execution | Error executing the tool |
-32001 | Validation error | Parameter validation failed |
Integrating with Claude Desktop
To use this MCP server with Claude Desktop:
- Create or edit your Claude Desktop configuration:
- Add the MCP server configuration:
- Restart Claude Desktop.
- In Claude, you can now use the Home Assistant MCP tools.
JSON-RPC 2.0 Message Format
Usage
Using NPX (Easiest)
The simplest way to use the Home Assistant MCP server is through NPX:
This will automatically:
- Start the server in stdio mode
- Output JSON-RPC messages to stdout
- Send log messages to stderr
- Create a logs directory if it doesn't exist
You can redirect stderr to hide logs and only see the JSON-RPC output:
Manual Installation
If you prefer to install the package globally or locally:
Or install locally:
Advanced Usage
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Smart Device Control ๐ฎ ๐ก Lights: Brightness, color, RGB ๐ก๏ธ Climate: Temperature, HVAC, humidity ๐ช Covers: Position and tilt ๐ Switches: On/off ๐จ Sensors: State monitoring
Intelligent Organization ๐ Grouping with context awareness.
Robust Architecture ๐ ๏ธ Error handling, state validation ...
Related MCP Servers
- -securityAlicense-qualityAccess Home Assistant data and control devices (lights, switches, thermostats, etc).Last updated -6123TypeScriptApache 2.0
- AsecurityAlicenseAqualityEnables AI assistants to control SwitchBot devices, providing functionalities like device management, scene execution, and sensor information monitoring through the SwitchBot API.Last updated -3JavaScriptISC License
- -securityAlicense-qualityEnables users to control Govee LED devices using the Govee API, with features for turning devices on/off, setting colors, and adjusting brightness through a CLI or MCP clients.Last updated -3PythonMIT License
- AsecurityAlicenseAqualityA server that enables interaction with Home Assistant devices and automations through the Model Context Protocol, allowing users to monitor device states, control devices, trigger automations, and list entities.Last updated -429JavaScriptMIT License
Appeared in Searches
- An MCP for managing lifestyle, coordinating daily routines, exercise, and study tasks
- Searching for information about license types or information starting with 'f'
- Finding MCP Servers Providing Insights for a Conversational Voice Interface
- A server for finding information about guitars
- Software or solutions for managing a fleet of computers