@orellbuehler/homeassistant-mcp 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +142 -39
  2. package/bin/homeassistant-mcp.js +51 -0
  3. package/binaries/darwin-arm64/homeassistant-mcp +0 -0
  4. package/binaries/darwin-x64/homeassistant-mcp +0 -0
  5. package/binaries/linux-arm64/homeassistant-mcp +0 -0
  6. package/binaries/linux-x64/homeassistant-mcp +0 -0
  7. package/binaries/win32-x64/homeassistant-mcp.exe +0 -0
  8. package/package.json +5 -38
  9. package/dist/config.js +0 -26
  10. package/dist/hass/format.js +0 -38
  11. package/dist/hass/rest.js +0 -50
  12. package/dist/hass/ws.js +0 -80
  13. package/dist/index.js +0 -17
  14. package/dist/server.js +0 -9
  15. package/dist/tools/auth.js +0 -191
  16. package/dist/tools/automations.js +0 -62
  17. package/dist/tools/backup.js +0 -375
  18. package/dist/tools/control.js +0 -133
  19. package/dist/tools/dashboards.js +0 -206
  20. package/dist/tools/diagnostics.js +0 -537
  21. package/dist/tools/energy.js +0 -235
  22. package/dist/tools/entities.js +0 -57
  23. package/dist/tools/hacs.js +0 -52
  24. package/dist/tools/helpers.js +0 -98
  25. package/dist/tools/history.js +0 -57
  26. package/dist/tools/integrations.js +0 -538
  27. package/dist/tools/lists.js +0 -216
  28. package/dist/tools/organization.js +0 -548
  29. package/dist/tools/raw.js +0 -41
  30. package/dist/tools/registry.js +0 -195
  31. package/dist/tools/reload.js +0 -40
  32. package/dist/tools/resources.js +0 -56
  33. package/dist/tools/scripts.js +0 -206
  34. package/dist/tools/services.js +0 -33
  35. package/dist/tools/statistics.js +0 -363
  36. package/dist/tools/system.js +0 -57
  37. package/dist/tools/templates.js +0 -21
  38. package/dist/tools/trace.js +0 -74
  39. package/dist/tools/zha.js +0 -121
  40. package/dist/toolsets.js +0 -356
@@ -1,133 +0,0 @@
1
- import { z } from "zod";
2
- import { ok, err } from "../hass/format.js";
3
- const json = (body) => ({ method: "POST", body: JSON.stringify(body) });
4
- export function registerControlTools(server, client, ws) {
5
- server.tool("call_service", "Call a Home Assistant service/action (POST /api/services/{domain}/{service}) — this CONTROLS DEVICES and runs for real (lights switch, covers move, notifications send). Put the target (entity_id / device_id / area_id / label_id) and the service fields together in 'data'. Returns the states that changed during the call; set return_response for services that return data (e.g. weather.get_forecasts, calendar.get_events), which then returns { changed_states, service_response }. Use list_services to discover services and their fields.", {
6
- domain: z.string().describe("Service domain, e.g. 'light'"),
7
- service: z.string().describe("Service name, e.g. 'turn_on'"),
8
- data: z
9
- .record(z.unknown())
10
- .optional()
11
- .describe("Service data including the target, e.g. { entity_id: 'light.kitchen' }"),
12
- return_response: z
13
- .boolean()
14
- .optional()
15
- .describe("Request the service response; required for response-only services"),
16
- }, async ({ domain, service, data, return_response }) => {
17
- try {
18
- const path = `/api/services/${encodeURIComponent(domain)}/${encodeURIComponent(service)}`;
19
- return ok(await client.fetch(`${path}${return_response ? "?return_response" : ""}`, json(data ?? {})));
20
- }
21
- catch (e) {
22
- return err(e);
23
- }
24
- });
25
- server.tool("set_state", "Set or create an entity's state in the state machine (POST /api/states/{entity_id}). This only overwrites Home Assistant's representation — it does NOT talk to the device, and an integration-backed entity overwrites it again on its next update. Useful for testing automations against a state or for virtual entities. Attributes are replaced, not merged. Returns the stored state.", {
26
- entity_id: z.string().describe("Entity to set, e.g. 'sensor.test_temperature'"),
27
- state: z.string().describe("New state value"),
28
- attributes: z.record(z.unknown()).optional().describe("Full attribute set to store"),
29
- force_update: z
30
- .boolean()
31
- .optional()
32
- .describe("Fire state_changed even if the state and attributes are unchanged"),
33
- }, async ({ entity_id, state, attributes, force_update }) => {
34
- try {
35
- const body = { state };
36
- if (attributes !== undefined)
37
- body.attributes = attributes;
38
- if (force_update !== undefined)
39
- body.force_update = force_update;
40
- return ok(await client.fetch(`/api/states/${encodeURIComponent(entity_id)}`, json(body)));
41
- }
42
- catch (e) {
43
- return err(e);
44
- }
45
- });
46
- server.tool("delete_state", "Remove an entity's state from the state machine (DELETE /api/states/{entity_id}). This does not delete the entity from the registry or its integration — an integration-backed entity reappears on its next update. Meant for cleaning up states created with set_state.", {
47
- entity_id: z.string().describe("Entity whose state to remove"),
48
- }, async ({ entity_id }) => {
49
- try {
50
- return ok(await client.fetch(`/api/states/${encodeURIComponent(entity_id)}`, { method: "DELETE" }));
51
- }
52
- catch (e) {
53
- return err(e);
54
- }
55
- });
56
- server.tool("fire_event", "Fire an event on the Home Assistant event bus (POST /api/events/{event_type}). Any automation or integration listening for that event type reacts for real. Useful for testing event-triggered automations.", {
57
- event_type: z.string().describe("Event type to fire, e.g. 'my_custom_event'"),
58
- event_data: z.record(z.unknown()).optional().describe("Event data object"),
59
- }, async ({ event_type, event_data }) => {
60
- try {
61
- return ok(await client.fetch(`/api/events/${encodeURIComponent(event_type)}`, json(event_data ?? {})));
62
- }
63
- catch (e) {
64
- return err(e);
65
- }
66
- });
67
- server.tool("handle_intent", "Handle an intent (POST /api/intent/handle), e.g. HassTurnOn with slot data — this can control devices. Requires the 'intent' integration. Returns the intent response.", {
68
- name: z.string().describe("Intent name, e.g. 'HassTurnOn'"),
69
- data: z
70
- .record(z.unknown())
71
- .optional()
72
- .describe("Slot values, e.g. { name: 'Kitchen light' }"),
73
- language: z.string().optional().describe("Language code, e.g. 'en'"),
74
- assistant: z.string().nullable().optional().describe("Assistant id, e.g. 'conversation'"),
75
- device_id: z.string().nullable().optional().describe("Device the intent originates from"),
76
- }, async ({ name, data, language, assistant, device_id }) => {
77
- try {
78
- const body = { name };
79
- if (data !== undefined)
80
- body.data = data;
81
- if (language !== undefined)
82
- body.language = language;
83
- if (assistant !== undefined)
84
- body.assistant = assistant;
85
- if (device_id !== undefined)
86
- body.device_id = device_id;
87
- return ok(await client.fetch("/api/intent/handle", json(body)));
88
- }
89
- catch (e) {
90
- return err(e);
91
- }
92
- });
93
- server.tool("execute_script", "Run an ad-hoc action sequence via the WebSocket API (execute_script) — the same syntax as an automation's 'actions' list, executed immediately and for real. Use it to test a sequence before saving it in an automation or script. Returns the script's response variable, if any. Sequences that run longer than the WebSocket timeout report a timeout although they keep running.", {
94
- sequence: z
95
- .array(z.record(z.unknown()))
96
- .min(1)
97
- .describe("Action list, e.g. [{ action: 'light.turn_on', target: { entity_id: 'light.x' } }]"),
98
- variables: z.record(z.unknown()).optional().describe("Variables available to the sequence"),
99
- }, async ({ sequence, variables }) => {
100
- try {
101
- const payload = { sequence };
102
- if (variables !== undefined)
103
- payload.variables = variables;
104
- return ok(await ws.command("execute_script", payload));
105
- }
106
- catch (e) {
107
- return err(e);
108
- }
109
- });
110
- server.tool("process_conversation", "Send a sentence to a conversation agent via the WebSocket API (conversation/process), as if spoken to Assist — the agent may control devices. Returns the agent's response and the conversation_id to continue the dialogue.", {
111
- text: z.string().describe("Sentence to process, e.g. 'turn on the kitchen light'"),
112
- conversation_id: z.string().nullable().optional().describe("Continue this conversation"),
113
- language: z.string().optional().describe("Language code, e.g. 'en'"),
114
- agent_id: z
115
- .string()
116
- .optional()
117
- .describe("Conversation agent entity_id; defaults to the built-in agent"),
118
- }, async ({ text, conversation_id, language, agent_id }) => {
119
- try {
120
- const payload = { text };
121
- if (conversation_id !== undefined)
122
- payload.conversation_id = conversation_id;
123
- if (language !== undefined)
124
- payload.language = language;
125
- if (agent_id !== undefined)
126
- payload.agent_id = agent_id;
127
- return ok(await ws.command("conversation/process", payload));
128
- }
129
- catch (e) {
130
- return err(e);
131
- }
132
- });
133
- }
@@ -1,206 +0,0 @@
1
- import { z } from "zod";
2
- import { ok, err } from "../hass/format.js";
3
- const urlPath = z
4
- .string()
5
- .optional()
6
- .describe("Dashboard url_path as shown in its URL (/<url_path>) and in list_dashboards, e.g. 'energy-overview'. Omit for the default dashboard.");
7
- const dashboardId = z
8
- .string()
9
- .describe("The 'id' field from list_dashboards — the slugified url_path with underscores (url_path 'my-dash' has id 'my_dash'), NOT the url_path itself.");
10
- export function registerDashboardTools(server, ws) {
11
- server.tool("list_dashboards", "List the Lovelace dashboards (lovelace/dashboards/list) that have a config entry: UI-managed 'storage' dashboards (id, url_path, title, icon, show_in_sidebar, require_admin, mode 'storage') and dashboards defined in configuration.yaml (mode 'yaml', filename). Use the url_path with get_dashboard_config/save_dashboard_config/delete_dashboard_config and the id with update_dashboard/delete_dashboard. The built-in default dashboard is addressed by omitting url_path.", {}, async () => {
12
- try {
13
- return ok(await ws.command("lovelace/dashboards/list"));
14
- }
15
- catch (e) {
16
- return err(e);
17
- }
18
- });
19
- server.tool("create_dashboard", "Create a new UI-managed (storage mode) dashboard entry via lovelace/dashboards/create. Requires an admin token. This only registers the dashboard and its sidebar entry — it has no content until you call save_dashboard_config with its url_path. url_path must be unique, must not collide with an existing panel, and must contain a hyphen unless allow_single_word is true. Config authoring only. Returns the created dashboard including its generated id (needed for update_dashboard/delete_dashboard).", {
20
- url_path: z
21
- .string()
22
- .describe("URL slug for the dashboard, e.g. 'energy-overview' (needs a hyphen by default)"),
23
- title: z.string().describe("Title shown in the sidebar and as the dashboard name"),
24
- icon: z
25
- .string()
26
- .optional()
27
- .describe("Sidebar icon in 'prefix:name' form, e.g. 'mdi:view-dashboard'"),
28
- require_admin: z
29
- .boolean()
30
- .optional()
31
- .describe("Only admin users can open the dashboard (default false)"),
32
- show_in_sidebar: z.boolean().optional().describe("Show it in the sidebar (default true)"),
33
- allow_single_word: z
34
- .boolean()
35
- .optional()
36
- .describe("Allow a url_path without a hyphen, e.g. 'map'"),
37
- }, async ({ url_path, title, icon, require_admin, show_in_sidebar, allow_single_word }) => {
38
- try {
39
- const payload = { url_path, title };
40
- if (icon !== undefined)
41
- payload.icon = icon;
42
- if (require_admin !== undefined)
43
- payload.require_admin = require_admin;
44
- if (show_in_sidebar !== undefined)
45
- payload.show_in_sidebar = show_in_sidebar;
46
- if (allow_single_word !== undefined)
47
- payload.allow_single_word = allow_single_word;
48
- return ok(await ws.command("lovelace/dashboards/create", payload));
49
- }
50
- catch (e) {
51
- return err(e);
52
- }
53
- });
54
- server.tool("update_dashboard", "Update a UI-managed dashboard's sidebar metadata (lovelace/dashboards/update): title, icon, require_admin and/or show_in_sidebar. Requires an admin token; only storage-mode dashboards can be updated, and url_path cannot be changed. This does not touch the dashboard's cards/views (use save_dashboard_config). At least one field besides dashboard_id is required. Returns the updated dashboard.", {
55
- dashboard_id: dashboardId,
56
- title: z.string().optional().describe("New title"),
57
- icon: z
58
- .string()
59
- .nullable()
60
- .optional()
61
- .describe("New icon in 'prefix:name' form, e.g. 'mdi:home'; null removes the icon"),
62
- require_admin: z.boolean().optional().describe("Only admin users can open the dashboard"),
63
- show_in_sidebar: z.boolean().optional().describe("Show it in the sidebar"),
64
- }, async ({ dashboard_id, title, icon, require_admin, show_in_sidebar }) => {
65
- try {
66
- if (title === undefined &&
67
- icon === undefined &&
68
- require_admin === undefined &&
69
- show_in_sidebar === undefined) {
70
- throw new Error("Provide at least one of 'title', 'icon', 'require_admin' or 'show_in_sidebar' to update the dashboard");
71
- }
72
- const payload = { dashboard_id };
73
- if (title !== undefined)
74
- payload.title = title;
75
- if (icon !== undefined)
76
- payload.icon = icon;
77
- if (require_admin !== undefined)
78
- payload.require_admin = require_admin;
79
- if (show_in_sidebar !== undefined)
80
- payload.show_in_sidebar = show_in_sidebar;
81
- return ok(await ws.command("lovelace/dashboards/update", payload));
82
- }
83
- catch (e) {
84
- return err(e);
85
- }
86
- });
87
- server.tool("delete_dashboard", "Delete a UI-managed dashboard (lovelace/dashboards/delete) — removes its sidebar entry AND its stored cards/views config permanently. Requires an admin token; only storage-mode dashboards can be deleted (YAML dashboards are removed from configuration.yaml). Get the dashboard_id from list_dashboards.", {
88
- dashboard_id: dashboardId,
89
- }, async ({ dashboard_id }) => {
90
- try {
91
- await ws.command("lovelace/dashboards/delete", { dashboard_id });
92
- return ok({ dashboard_id, deleted: true });
93
- }
94
- catch (e) {
95
- return err(e);
96
- }
97
- });
98
- server.tool("get_dashboard_config", "Get a dashboard's full Lovelace config (title, views, cards, or a strategy) via lovelace/config. Omit url_path for the default dashboard. Fails with config_not_found when the dashboard has no saved config yet (it is auto-generated or newly created) — see list_dashboards for the available url_paths. Call this before save_dashboard_config to edit: the save replaces the whole config.", {
99
- url_path: urlPath,
100
- force: z
101
- .boolean()
102
- .optional()
103
- .describe("Only matters for YAML-mode dashboards: re-read the file instead of using the cache (default false)"),
104
- }, async ({ url_path, force }) => {
105
- try {
106
- const payload = {};
107
- if (url_path !== undefined)
108
- payload.url_path = url_path;
109
- if (force !== undefined)
110
- payload.force = force;
111
- return ok(await ws.command("lovelace/config", payload));
112
- }
113
- catch (e) {
114
- return err(e);
115
- }
116
- });
117
- server.tool("save_dashboard_config", "Save a dashboard's Lovelace config via lovelace/config/save. Requires an admin token and a storage-mode dashboard (YAML dashboards are read-only: edit the file instead). The config REPLACES the stored one entirely, so to edit call get_dashboard_config first and send back the modified object. Home Assistant does not validate card contents — a bad card config only shows an error in the UI. Config authoring only: it changes what dashboards display, not any device.", {
118
- config: z
119
- .record(z.unknown())
120
- .describe("Full dashboard config object, e.g. { title, views: [{ title, path, cards: [...] }] } or a strategy dashboard such as { strategy: { type: 'map' } }"),
121
- url_path: urlPath,
122
- }, async ({ config, url_path }) => {
123
- try {
124
- const payload = { config };
125
- if (url_path !== undefined)
126
- payload.url_path = url_path;
127
- await ws.command("lovelace/config/save", payload);
128
- return ok({ url_path: url_path ?? null, saved: true });
129
- }
130
- catch (e) {
131
- return err(e);
132
- }
133
- });
134
- server.tool("delete_dashboard_config", "Delete a dashboard's stored cards/views config (lovelace/config/delete) while keeping the dashboard entry itself — afterwards it has no stored config (get_dashboard_config fails with config_not_found until you save one again). Requires an admin token; YAML dashboards cannot be deleted this way. Irreversible: call get_dashboard_config first if you may want it back. To remove the dashboard entirely use delete_dashboard.", {
135
- url_path: urlPath,
136
- }, async ({ url_path }) => {
137
- try {
138
- const payload = {};
139
- if (url_path !== undefined)
140
- payload.url_path = url_path;
141
- await ws.command("lovelace/config/delete", payload);
142
- return ok({ url_path: url_path ?? null, deleted: true });
143
- }
144
- catch (e) {
145
- return err(e);
146
- }
147
- });
148
- server.tool("get_lovelace_info", "Get Lovelace info (lovelace/info). Returns { resource_mode: 'storage' | 'yaml' } — how the Lovelace resource registry is managed. The *_lovelace_resource tools only work in 'storage' mode.", {}, async () => {
149
- try {
150
- return ok(await ws.command("lovelace/info"));
151
- }
152
- catch (e) {
153
- return err(e);
154
- }
155
- });
156
- server.tool("list_frontend_panels", "List the frontend panels (sidebar entries and dashboards) registered in Home Assistant via the get_panels WebSocket command, keyed by url_path. Each has component_name, title, icon, url_path, require_admin, show_in_sidebar, default_visible, config and config_panel_domain. Panels that require admin are omitted when the token's user is not an admin. Includes custom/UI dashboards, so it is a quick way to see what url_paths exist.", {}, async () => {
157
- try {
158
- return ok(await ws.command("get_panels"));
159
- }
160
- catch (e) {
161
- return err(e);
162
- }
163
- });
164
- server.tool("get_frontend_themes", "Get the installed frontend themes (frontend/get_themes): { themes, default_theme, default_dark_theme }. 'themes' maps each theme name to its CSS variables, with optional 'modes' { light, dark } overrides (themes come from the frontend: themes: section of configuration.yaml). 'default_dark_theme' may be null. Useful when styling cards. Returns an empty theme set in safe mode or recovery mode.", {}, async () => {
165
- try {
166
- return ok(await ws.command("frontend/get_themes"));
167
- }
168
- catch (e) {
169
- return err(e);
170
- }
171
- });
172
- server.tool("get_frontend_translations", "Get backend translation strings for a language and category (frontend/get_translations): { resources: { '<component.domain.category.key>': 'text' } }. Useful for finding the exact UI wording of entity states, service names or config flow steps. The result can be very large when no integration filter is given (it then covers every loaded integration) — pass 'integration' to limit it.", {
173
- language: z.string().describe("Language code, e.g. 'en' or 'de'"),
174
- category: z
175
- .string()
176
- .describe("Translation category, i.e. a top-level key of an integration's translations: e.g. 'entity', 'entity_component', 'config', 'options', 'services', 'selector', 'exceptions', 'issues', 'title'"),
177
- integration: z
178
- .array(z.string())
179
- .optional()
180
- .describe("Only these integration domains, e.g. ['hue', 'light']"),
181
- config_flow: z
182
- .boolean()
183
- .optional()
184
- .describe("When no integration is given, also include integrations that are not yet set up but have a config flow"),
185
- }, async ({ language, category, integration, config_flow }) => {
186
- try {
187
- const payload = { language, category };
188
- if (integration !== undefined)
189
- payload.integration = integration;
190
- if (config_flow !== undefined)
191
- payload.config_flow = config_flow;
192
- return ok(await ws.command("frontend/get_translations", payload));
193
- }
194
- catch (e) {
195
- return err(e);
196
- }
197
- });
198
- server.tool("list_persistent_notifications", "List the active persistent notifications (the bell icon in the UI) via persistent_notification/get. Each has notification_id, title (may be null), message and created_at. Often where integrations report setup problems, discovered devices or failed automations. Read-only: dismissing them is a service (persistent_notification.dismiss).", {}, async () => {
199
- try {
200
- return ok(await ws.command("persistent_notification/get"));
201
- }
202
- catch (e) {
203
- return err(e);
204
- }
205
- });
206
- }