hass-mcp

czechbol/hass-mcp Checked 58 minutes ago

HACS custom integration that mounts an MCP server inside Home Assistant with generic meta-tools covering the full admin surface.

Home Assistant integration that mounts a Model Context Protocol (MCP) server inside HA, exposing a small set of generic meta-tools that cover the full HA admin surface — not the narrow LLM-API subset that the core mcp_server integration provides. Install it from the built-in Marketplace (Home Assistant 2026.11+, formerly HACS). 1. Add this repository as a custom repository, then install Native MCP for Home Assistant: - Home Assistant 2026.11+ — Settings → Marketplace, the ⋮ menu → Custom repositories (or Add from link), add this repo's URL as an Integration, then Install.

Summary extracted from the README.

Native MCP for Home Assistant

Home Assistant integration that mounts a Model Context Protocol (MCP) server inside HA, exposing a small set of generic meta-tools that cover the full HA admin surface — not the narrow LLM-API subset that the core mcp_server integration provides. Install it from the built-in Marketplace (Home Assistant 2026.11+, formerly HACS).

  • Mounted on HA's HTTP at POST /api/hass_mcp (Streamable HTTP, stateless, JSON-RPC body).
  • Authentication: reuses HA bearer tokens (long-lived access tokens work).
  • Transport: POST request → JSON response or 202 Accepted for notifications. No SSE, no separate port.
  • Coexists with HA's built-in mcp_server (which lives at /api/mcp).

Documentation

Install

  1. Add this repository as a custom repository, then install Native MCP for Home Assistant:

    • Home Assistant 2026.11+ — Settings → Marketplace, the ⋮ menu → Custom repositories (or Add from link), add this repo's URL as an Integration, then Install. No restart needed for the download.
    • Home Assistant 2026.10 and older — in HACS, add this repo as a custom repository (Integration), Download, then Restart Home Assistant.
  2. Restart HA if prompted (Marketplace surfaces a repair; HACS requires it).

  3. Settings → Devices & Services → Add Integration → Native MCP for Home Assistant. Toggle which tool classes are allowed: writes, destructive ops, firing arbitrary events.

  4. Create a long-lived access token in your HA profile.

  5. Point an MCP client at the endpoint:

    POST https://<your-ha>:8123/api/hass_mcp
    Authorization: Bearer <token>
    Content-Type: application/json
    

Smoke test

curl -sS -X POST https://your-ha:8123/api/hass_mcp \
  -H "Authorization: Bearer $HA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | jq .

Claude Code / Claude Desktop

Add to your MCP client config:

{
  "mcpServers": {
    "homeassistant": {
      "type": "http",
      "url": "https://your-ha:8123/api/hass_mcp",
      "headers": {
        "Authorization": "Bearer YOUR_LONG_LIVED_TOKEN"
      }
    }
  }
}

For clients that only speak stdio, wrap with mcp-remote:

{
  "homeassistant": {
    "command": "npx",
    "args": [
      "-y",
      "mcp-remote",
      "https://your-ha:8123/api/hass_mcp",
      "--header",
      "Authorization: Bearer YOUR_LONG_LIVED_TOKEN"
    ]
  }
}

Tool reference

All tools live under the ha_ prefix. List with tools/list; call with tools/call. JSON Schema for every input is included in the listing.

Tool Purpose
ha_list_states Filter+list entity states (domain / area / device / label / glob). Attributes omitted by default; include_attributes=true for full
ha_get_state Single entity state and attributes
ha_describe_entity Rich introspection: state + attributes + decoded supported_features + registry/device/area join + available services
ha_set_state Write to the state machine without invoking a device
ha_delete_state Remove entity from the state machine
ha_call_service Call any HA service. return_response auto-detected from supports_response
ha_list_services Service catalog with field schemas, selectors, descriptions, targets — same data as HA UI. Filter to one service for by-id detail
ha_search Fuzzy search across entities / devices / areas / labels
ha_render_template Render an HA Jinja template
ha_validate_config Validate trigger / condition / action blocks
ha_yaml_config CRUD for automations.yaml / scripts.yaml / scenes.yaml + auto-reload
ha_blueprint List / get / import (url or yaml) / delete / substitute blueprints
ha_recorder Info, purge, purge_entities
ha_energy Energy dashboard prefs: get / save / validate
ha_trace Read automation/script execution traces (list/get/contexts)
ha_diagnostics Per-integration / per-device diagnostics dump
ha_helper CRUD for input_boolean / input_number / input_select / input_text / input_datetime / counter / timer / schedule
ha_backup Backup integration: info/details/generate/delete/restore + agents/config
ha_lovelace Dashboards / configs / resources — read + CRUD (save/delete configs, create/update/delete dashboards & resources)
ha_auth Refresh + long-lived token mgmt (list/create/revoke)
ha_webhook List registered webhooks (op=list, admin-only — URLs are secrets)
ha_list_events Event types + listener counts
ha_fire_event Fire an event on the bus (gated)
ha_system System introspection + core-config: op=get_config / set_config / check_config / get_health / read_error_log / read_system_log / clear_system_log
ha_registry Entity / device / area / label / floor / category / issue CRUD
ha_config_entries Manage installed integrations: list / reload / unload / setup / remove / update_options
ha_config_flow Add new integrations via the same flow the UI uses
ha_hacs HACS: list/get/install/update repositories (legacy HACS WebSocket API, HA ≤2026.10; not yet ported to the 2026.11+ Marketplace)
ha_history Recorder timeline: kind=state_changes (significant state history) or kind=logbook (logbook events) between two timestamps
ha_statistics Long-term statistics: list_ids / period / metadata / clear
ha_assist Invoke Assist: op=converse (conversation pipeline) or op=handle_intent (named intent like HassTurnOn)
ha_camera_snapshot Capture a camera frame as base64

Adding a new integration via MCP

The ha_config_flow tool drives the same multi-step flow the UI uses:

ha_config_flow op=list_handlers          # discover available domains
ha_config_flow op=init domain=hue        # start a flow → returns flow_id
ha_config_flow op=configure flow_id=...  # submit user_input

Limitations:

  • Adds integrations whose code is already on disk. It does not download packages — use the Marketplace (HACS on HA ≤2026.10) / pip for that.
  • YAML-only integrations have no config flow.
  • OAuth / external-step flows will surface the auth URL; you (the human) need to open it.

Permissions model

Two independent layers guard every mutating call:

1. Server policy — three integration options gate tool classes. For meta-tools the gate is applied per op (e.g. ha_registry op=delete is destructive while op=get is a read):

Option Default Enables
allow_write ✅ on write ops — ha_call_service, ha_set_state, create/update/reload across ha_registry / ha_config_entries / ha_helper / ha_yaml_config / ha_blueprint / ha_energy, ha_config_flow, ha_assist, ha_hacs
allow_destructive ❌ off destructive ops — ha_delete_state, and delete/remove/purge/revoke/restore/clear across ha_registry, ha_config_entries, ha_helper, ha_backup, ha_yaml_config, ha_blueprint, ha_statistics, ha_recorder, ha_auth, ha_lovelace, ha_system (clear_system_log)
allow_fire_event ❌ off ha_fire_event

Tool classes that are disabled are omitted from tools/list entirely.

2. Effective user — every tool call executes as the Home Assistant user who owns the bearer token, and HA's own permission machinery enforces that user's rights. Mutating calls fail closed if the request carries no authenticated user. Operations that HA treats as admin-only and that this integration performs via direct APIs — mutations on ha_registry, ha_config_entries, ha_config_flow, ha_energy, ha_statistics, ha_set_state, ha_delete_state — additionally require the token's user to be an administrator (their read ops do not, except ha_trace and ha_yaml_config list/get, which return full automation/script logic, and ha_webhook, whose URLs are bearer-equivalent secrets — all admin-only in full). Reads honor the token owner's per-entity read policy: a restricted non-admin token only sees entities its HA policy allows (via ha_list_states, ha_get_state, ha_describe_entity, ha_search, ha_camera_snapshot, ha_history, ha_statistics); ha_render_template requires unrestricted read access.

Security notes

  • A token grants exactly its owner's permissions. An admin token has admin-level control; to limit a client, mint its token under an appropriately-privileged (e.g. non-admin) HA user. Rotate tokens when revoking access.
  • A write-enabled token can call any Home Assistant service via ha_call_service — this matches HA's own behavior (non-admins can call services). Operations HA treats as admin-only (registry/config-entry/flow mutations, state writes, energy/statistics, and sensitive reads such as logs, diagnostics, and core config) additionally require an admin token.
  • Only expose /api/hass_mcp over HTTPS in production.
  • If you front HA with a reverse proxy, ensure the Authorization header is forwarded.

Development

# Symlink into a dev HA config dir:
ln -s "$PWD/custom_components/hass_mcp" /path/to/ha-config/custom_components/hass_mcp
# Restart HA. Watch home-assistant.log for `hass_mcp: MCP endpoint registered`.

Quick interactive test with the MCP Inspector:

npx @modelcontextprotocol/inspector \
  --url https://your-ha:8123/api/hass_mcp \
  --header "Authorization: Bearer $HA_TOKEN"

Supported Home Assistant versions

The automated test suite runs against Home Assistant 2026.11 and newer — that's the floor of Home Assistant's official pytest-homeassistant harness, so it's the range we verify in CI. Older releases are not tested but may well still work; the integration imposes no hard minimum, so you're welcome to run it on an earlier version at your own risk.

License

MIT