@orellbuehler/homeassistant-mcp 0.9.0 → 1.0.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.
- package/README.md +161 -43
- package/dist/index.js +5 -1
- package/dist/server.js +6 -28
- package/dist/tools/auth.js +191 -0
- package/dist/tools/backup.js +375 -0
- package/dist/tools/control.js +133 -0
- package/dist/tools/dashboards.js +206 -0
- package/dist/tools/diagnostics.js +537 -0
- package/dist/tools/helpers.js +98 -0
- package/dist/tools/integrations.js +538 -0
- package/dist/tools/lists.js +216 -0
- package/dist/tools/organization.js +548 -0
- package/dist/tools/raw.js +41 -0
- package/dist/tools/registry.js +2 -1
- package/dist/tools/resources.js +1 -1
- package/dist/tools/scripts.js +206 -0
- package/dist/tools/statistics.js +363 -0
- package/dist/tools/system.js +17 -0
- package/dist/toolsets.js +356 -0
- package/package.json +6 -2
|
@@ -0,0 +1,206 @@
|
|
|
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
|
+
}
|