zigbee2mqtt-mcp 0.7.0 → 0.8.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 +76 -6
- package/dist/client.js +56 -12
- package/dist/config.js +50 -1
- package/dist/http.js +120 -0
- package/dist/index.js +3 -98
- package/dist/redact.js +11 -4
- package/dist/server.js +64 -0
- package/dist/start.js +88 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/zigbee2mqtt-mcp)
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
[](https://glama.ai/mcp/servers/alexpfau/zigbee2mqtt-mcp)
|
|
7
|
+
[](https://mcprush.com/to/zigbee2mqtt-mcp?ref=badge)
|
|
7
8
|
|
|
8
9
|
A [Model Context Protocol](https://modelcontextprotocol.io) server for **administering** a Zigbee2MQTT estate.
|
|
9
10
|
|
|
@@ -18,7 +19,7 @@ If you already run Home Assistant, your Zigbee devices are exposed there and an
|
|
|
18
19
|
## Design
|
|
19
20
|
|
|
20
21
|
- **No database.** Zigbee2MQTT publishes its bridge topics as retained messages, so a fresh subscription yields a complete picture in a few hundred milliseconds. The server keeps only the latest payload per topic in memory.
|
|
21
|
-
- **No daemon.**
|
|
22
|
+
- **No daemon by default.** Over stdio it starts and dies with the MCP session. The optional [HTTP transport](#http-transport) runs it as a long-lived server instead.
|
|
22
23
|
- **Correlated requests.** Every `bridge/request/*` carries a `transaction` id and is matched to its `bridge/response/*`, so concurrent calls cannot cross wires.
|
|
23
24
|
- **Tiered writes.** Destructive operations are gated behind a write mode *and* an explicit `confirm` argument.
|
|
24
25
|
|
|
@@ -30,6 +31,14 @@ Requires Node.js 22 or newer and network access to the MQTT broker that Zigbee2M
|
|
|
30
31
|
npx zigbee2mqtt-mcp
|
|
31
32
|
```
|
|
32
33
|
|
|
34
|
+
### Home Assistant app
|
|
35
|
+
|
|
36
|
+
On Home Assistant OS or Supervised, run it as an app instead:
|
|
37
|
+
|
|
38
|
+
[](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Falexpfau%2Fzigbee2mqtt-mcp)
|
|
39
|
+
|
|
40
|
+
It takes the broker from the Mosquitto broker app without configuration, and Home Assistant 2026.10 and newer discover it, so Assist's AI agents can use its tools. Other MCP clients on your network, or behind your own reverse proxy or tunnel, connect to the URL in its log. See the [app documentation](homeassistant-app/DOCS.md).
|
|
41
|
+
|
|
33
42
|
### VS Code / GitHub Copilot
|
|
34
43
|
|
|
35
44
|
Add to your MCP configuration:
|
|
@@ -88,6 +97,51 @@ Add to your MCP configuration:
|
|
|
88
97
|
| `Z2M_REQUEST_TIMEOUT_MS` | `15000` | Default bridge request timeout |
|
|
89
98
|
| `Z2M_MQTT_REJECT_UNAUTHORIZED` | `true` | Set `false` for self-signed TLS |
|
|
90
99
|
| `Z2M_MQTT_CA` / `_CERT` / `_KEY` | – | Paths to TLS material |
|
|
100
|
+
| `Z2M_TRANSPORT` | `stdio` | `stdio` or `http` |
|
|
101
|
+
| `Z2M_HTTP_HOST` | `127.0.0.1` | Address the HTTP transport binds to |
|
|
102
|
+
| `Z2M_HTTP_PORT` | `3000` | Port the HTTP transport listens on |
|
|
103
|
+
| `Z2M_HTTP_PATH` | `/mcp` | The one URL path the HTTP transport serves MCP at |
|
|
104
|
+
| `Z2M_HTTP_AUTH_TOKEN` | – | When set, HTTP requests must send `Authorization: Bearer <token>` |
|
|
105
|
+
| `Z2M_HTTP_ALLOWED_HOSTS` | – | Comma-separated `Host` names the HTTP transport accepts |
|
|
106
|
+
|
|
107
|
+
## HTTP transport
|
|
108
|
+
|
|
109
|
+
Set `Z2M_TRANSPORT=http` to serve MCP over Streamable HTTP at `/mcp` (or `Z2M_HTTP_PATH`) instead of stdio, for clients that connect to a URL rather than start a process:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
Z2M_TRANSPORT=http \
|
|
113
|
+
Z2M_HTTP_AUTH_TOKEN="$(openssl rand -hex 32)" \
|
|
114
|
+
Z2M_MQTT_URL=mqtt://192.168.1.10:1883 \
|
|
115
|
+
npx zigbee2mqtt-mcp
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"mcpServers": {
|
|
121
|
+
"zigbee2mqtt": {
|
|
122
|
+
"type": "http",
|
|
123
|
+
"url": "http://127.0.0.1:3000/mcp",
|
|
124
|
+
"headers": { "Authorization": "Bearer <token>" }
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
- **Stateless.** Every request stands alone, so there are no sessions to expire and any number of clients can use the one process. They share a single MQTT connection, which stays open between requests.
|
|
131
|
+
- **Local by default.** It binds to `127.0.0.1` and refuses requests whose `Host` header is not a loopback name, which stops DNS rebinding from a web page. To reach it from other machines or containers, set `Z2M_HTTP_HOST=0.0.0.0` and a token.
|
|
132
|
+
- **Bearer token.** With `Z2M_HTTP_AUTH_TOKEN` set, a request without that token gets `401`. Without it, anyone who can reach the port can use every tool in the active write mode; the server warns at startup when that port is not loopback-only.
|
|
133
|
+
- **Secret path.** `Z2M_HTTP_PATH` moves the endpoint, for example to `/private_$(openssl rand -hex 16)`. Every other path gets `404` before any token check, and the match is exact, case included. For clients that can only take a URL, an unguessable path is the credential, so the startup warning about a missing token is not shown once a custom path is set. Pick one nobody can guess, or set a token as well.
|
|
134
|
+
- **Host names.** `Z2M_HTTP_ALLOWED_HOSTS` replaces the accepted `Host` names, for example `z2m.internal,localhost` behind a reverse proxy or a container hostname.
|
|
135
|
+
- **No TLS.** The token travels in clear text, so put a reverse proxy or tunnel that terminates HTTPS in front of anything beyond loopback.
|
|
136
|
+
|
|
137
|
+
In a container, publish the port and bind to every interface:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
docker run --rm -p 127.0.0.1:3000:3000 \
|
|
141
|
+
-e Z2M_TRANSPORT=http -e Z2M_HTTP_HOST=0.0.0.0 \
|
|
142
|
+
-e Z2M_HTTP_AUTH_TOKEN=... -e Z2M_MQTT_URL=mqtt://192.168.1.10:1883 \
|
|
143
|
+
zigbee2mqtt-mcp
|
|
144
|
+
```
|
|
91
145
|
|
|
92
146
|
## Write modes
|
|
93
147
|
|
|
@@ -157,6 +211,7 @@ Some fields depend on your Zigbee2MQTT configuration. The server detects what is
|
|
|
157
211
|
|
|
158
212
|
- The broker URL may carry credentials (`mqtt://user:pass@host`). They are redacted everywhere the URL is echoed back to a model or written to a log, and error text from the MQTT client is scrubbed before it leaves the process. Zigbee2MQTT logs its own broker URL at startup, so lines relayed by `z2m_get_logs` are scrubbed too.
|
|
159
213
|
- `safe` mode can actuate anything on the mesh via `z2m_set_state`, including locks, valves and sirens. Use `off` if that matters.
|
|
214
|
+
- The HTTP transport has no TLS of its own and no authentication unless `Z2M_HTTP_AUTH_TOKEN` is set. See [HTTP transport](#http-transport) before binding it beyond loopback.
|
|
160
215
|
- `z2m_permit_join` opens the network to any nearby Zigbee device for the duration of the window. It is in `safe` because it is routine and reversible, but it is a security boundary.
|
|
161
216
|
|
|
162
217
|
## Example prompts
|
|
@@ -187,6 +242,18 @@ Z2M_MQTT_URL=mqtt://192.168.1.10:1883 node scripts/smoke.mjs z2m_list_devices '{
|
|
|
187
242
|
# restores both, including on failure. Set Z2M_TEST_DEVICE to pick the device,
|
|
188
243
|
# or ROUNDTRIP_GROUPS_ONLY=1 to skip the rename.
|
|
189
244
|
Z2M_MQTT_URL=mqtt://192.168.1.10:1883 node scripts/roundtrip.mjs
|
|
245
|
+
|
|
246
|
+
# Home Assistant app image against Mosquitto and a fake Supervisor that also
|
|
247
|
+
# plays Home Assistant (needs Docker; CI runs all three modes).
|
|
248
|
+
docker build -f homeassistant-app/Dockerfile -t zigbee2mqtt-mcp-ha-app:dev .
|
|
249
|
+
scripts/ha-app-e2e.sh zigbee2mqtt-mcp-ha-app:dev socket # or tcp, nobroker
|
|
250
|
+
|
|
251
|
+
# The app as a local app that Home Assistant builds itself, to try a branch on
|
|
252
|
+
# a real Home Assistant. Copy the folder into Home Assistant's /addons over SSH;
|
|
253
|
+
# COPYFILE_DISABLE=1 keeps macOS from adding ._* files. Then Rebuild the app.
|
|
254
|
+
node scripts/ha-app-bundle.mjs /tmp/ha-app
|
|
255
|
+
COPYFILE_DISABLE=1 tar -C /tmp/ha-app -cf - zigbee2mqtt_mcp_local \
|
|
256
|
+
| ssh <user>@<home assistant> 'rm -rf /addons/zigbee2mqtt_mcp_local && tar -C /addons -xf -'
|
|
190
257
|
```
|
|
191
258
|
|
|
192
259
|
Note that an MCP server may receive requests concurrently. When testing ordering,
|
|
@@ -205,14 +272,17 @@ node scripts/mutate.mjs # every mutant
|
|
|
205
272
|
node scripts/mutate.mjs redact # only mutants whose name matches
|
|
206
273
|
```
|
|
207
274
|
|
|
208
|
-
A surviving mutant marks
|
|
275
|
+
A surviving mutant marks behavior nothing actually tests, and exits non-zero.
|
|
209
276
|
Add a mutant alongside any fix worth keeping fixed.
|
|
210
277
|
|
|
211
278
|
Releases are tag-driven: `npm version <patch|minor|major>` then
|
|
212
|
-
`git push --follow-tags`.
|
|
213
|
-
`server.json`
|
|
214
|
-
|
|
215
|
-
|
|
279
|
+
`git push --follow-tags`. The `version` script copies the new version into
|
|
280
|
+
`server.json` and `homeassistant-app/config.yaml`, so all three land in the
|
|
281
|
+
version commit, and CI fails if they ever differ. On the tag, CI publishes to
|
|
282
|
+
npm with provenance and to the MCP Registry, pushes the Home Assistant app
|
|
283
|
+
image to `ghcr.io/alexpfau/zigbee2mqtt-mcp-ha-app`, then creates the GitHub
|
|
284
|
+
release. A Home Assistant app installs the image named by the `version` in
|
|
285
|
+
`config.yaml` on the default branch, so push the tag no later than the commit.
|
|
216
286
|
|
|
217
287
|
## Safety
|
|
218
288
|
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import mqtt from "mqtt";
|
|
2
2
|
import { redactUrl, scrubSecrets } from "./redact.js";
|
|
3
3
|
import { classifyTopic } from "./topics.js";
|
|
4
|
+
/** How long a clean disconnect may wait for the broker before giving up. */
|
|
5
|
+
const DISCONNECT_GRACE_MS = 2_000;
|
|
4
6
|
/**
|
|
5
7
|
* Correlates bridge/request with bridge/response. Both sides must build the key
|
|
6
8
|
* identically or every write tool times out, so it lives in one place.
|
|
@@ -48,6 +50,10 @@ export class Z2MClient {
|
|
|
48
50
|
lastMessageAt = 0;
|
|
49
51
|
bridgeRevision = 0;
|
|
50
52
|
brokerHandshake = false;
|
|
53
|
+
/** Set by disconnect(): the process is shutting down, so no new connection. */
|
|
54
|
+
closed = false;
|
|
55
|
+
/** Fails the connection being set up, if any. */
|
|
56
|
+
abortConnect = null;
|
|
51
57
|
bridge = new Map();
|
|
52
58
|
deviceState = new Map();
|
|
53
59
|
availability = new Map();
|
|
@@ -56,26 +62,35 @@ export class Z2MClient {
|
|
|
56
62
|
waiters = new Map();
|
|
57
63
|
/** Never interpolate config.mqttUrl into a message; it may carry credentials. */
|
|
58
64
|
safeUrl;
|
|
59
|
-
|
|
65
|
+
dial;
|
|
66
|
+
disconnectGraceMs;
|
|
67
|
+
constructor(config, log, { dial = (url, options) => mqtt.connect(url, options), disconnectGraceMs = DISCONNECT_GRACE_MS } = {}) {
|
|
60
68
|
this.config = config;
|
|
61
69
|
this.log = log;
|
|
62
70
|
this.safeUrl = redactUrl(config.mqttUrl);
|
|
71
|
+
this.dial = dial;
|
|
72
|
+
this.disconnectGraceMs = disconnectGraceMs;
|
|
63
73
|
}
|
|
64
74
|
// ---------------------------------------------------------------- lifecycle
|
|
65
75
|
async connect() {
|
|
76
|
+
if (this.closed)
|
|
77
|
+
throw new Error("The MQTT client has been shut down");
|
|
78
|
+
// Checked first: the client reports connected as soon as the broker
|
|
79
|
+
// accepts it, before the subscription and the retained bridge topics are
|
|
80
|
+
// in. A second caller in that window would read an empty cache.
|
|
81
|
+
if (this.connectPromise)
|
|
82
|
+
return this.connectPromise;
|
|
66
83
|
if (this.client?.connected)
|
|
67
84
|
return;
|
|
68
|
-
// A client that exists but is not connected is mid-reconnect.
|
|
85
|
+
// A client that exists but is not connected is mid-reconnect. Dialing
|
|
69
86
|
// again would orphan it and flap the shared client ID on the broker.
|
|
70
|
-
if (this.client
|
|
87
|
+
if (this.client) {
|
|
71
88
|
await this.awaitReconnect();
|
|
72
89
|
return;
|
|
73
90
|
}
|
|
74
|
-
|
|
75
|
-
this.connectPromise =
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
}
|
|
91
|
+
this.connectPromise = this.doConnect().finally(() => {
|
|
92
|
+
this.connectPromise = null;
|
|
93
|
+
});
|
|
79
94
|
return this.connectPromise;
|
|
80
95
|
}
|
|
81
96
|
doConnect() {
|
|
@@ -96,7 +111,15 @@ export class Z2MClient {
|
|
|
96
111
|
};
|
|
97
112
|
return new Promise((resolve, reject) => {
|
|
98
113
|
this.log.debug(`connecting to ${this.safeUrl}`);
|
|
99
|
-
|
|
114
|
+
let client;
|
|
115
|
+
try {
|
|
116
|
+
client = this.dial(config.mqttUrl, options);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
// mqtt.js throws on a URL it cannot parse, quoting it with any token.
|
|
120
|
+
reject(new Error(`MQTT connection to ${this.safeUrl} failed: ${scrubSecrets(error.message, config)}`));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
100
123
|
this.client = client;
|
|
101
124
|
let settled = false;
|
|
102
125
|
const fail = (error) => {
|
|
@@ -104,10 +127,13 @@ export class Z2MClient {
|
|
|
104
127
|
return;
|
|
105
128
|
settled = true;
|
|
106
129
|
clearTimeout(timer);
|
|
130
|
+
this.abortConnect = null;
|
|
107
131
|
client.end(true);
|
|
108
|
-
this.client
|
|
132
|
+
if (this.client === client)
|
|
133
|
+
this.client = null;
|
|
109
134
|
reject(error);
|
|
110
135
|
};
|
|
136
|
+
this.abortConnect = fail;
|
|
111
137
|
const timer = setTimeout(() => fail(new Error(`Timed out connecting to ${this.safeUrl} after ${config.connectTimeoutMs}ms`)), config.connectTimeoutMs);
|
|
112
138
|
client.on("error", (error) => {
|
|
113
139
|
this.log.error("mqtt error:", scrubSecrets(error.message, config));
|
|
@@ -133,6 +159,7 @@ export class Z2MClient {
|
|
|
133
159
|
return;
|
|
134
160
|
settled = true;
|
|
135
161
|
clearTimeout(timer);
|
|
162
|
+
this.abortConnect = null;
|
|
136
163
|
resolve();
|
|
137
164
|
})
|
|
138
165
|
.catch(fail);
|
|
@@ -176,7 +203,12 @@ export class Z2MClient {
|
|
|
176
203
|
await sleep(25);
|
|
177
204
|
}
|
|
178
205
|
}
|
|
206
|
+
/** Closes the connection for good; later calls to connect() fail. */
|
|
179
207
|
async disconnect() {
|
|
208
|
+
this.closed = true;
|
|
209
|
+
// A connection still being set up may wait forever for a SUBACK, and a
|
|
210
|
+
// graceful end would wait with it, so it is dropped at once.
|
|
211
|
+
this.abortConnect?.(new Error(`Disconnected from ${this.safeUrl} while connecting`));
|
|
180
212
|
const client = this.client;
|
|
181
213
|
this.client = null;
|
|
182
214
|
if (!client)
|
|
@@ -185,7 +217,19 @@ export class Z2MClient {
|
|
|
185
217
|
// otherwise surface a spurious 'write after end'.
|
|
186
218
|
client.removeAllListeners("error");
|
|
187
219
|
client.on("error", () => undefined);
|
|
188
|
-
|
|
220
|
+
// A broker that never acknowledges must not hold up shutdown either.
|
|
221
|
+
// mqtt.js keeps waiting for the acknowledgment, and a second end(true)
|
|
222
|
+
// does not cut that short, so the socket underneath is closed instead.
|
|
223
|
+
await new Promise((resolve) => {
|
|
224
|
+
const timer = setTimeout(() => {
|
|
225
|
+
client.stream?.destroy();
|
|
226
|
+
resolve();
|
|
227
|
+
}, this.disconnectGraceMs);
|
|
228
|
+
client.end(false, {}, () => {
|
|
229
|
+
clearTimeout(timer);
|
|
230
|
+
resolve();
|
|
231
|
+
});
|
|
232
|
+
});
|
|
189
233
|
}
|
|
190
234
|
// ----------------------------------------------------------------- messages
|
|
191
235
|
/** Exposed for tests; the live path is the client's 'message' event. */
|
|
@@ -345,7 +389,7 @@ export class Z2MClient {
|
|
|
345
389
|
throw new Error("MQTT client is not connected");
|
|
346
390
|
const body = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
347
391
|
return new Promise((resolve, reject) => {
|
|
348
|
-
// Settles only on the QoS 1
|
|
392
|
+
// Settles only on the QoS 1 acknowledgment, which never arrives if the
|
|
349
393
|
// broker drops mid-publish, so bound it like request() does.
|
|
350
394
|
const timer = setTimeout(() => reject(new Error(`Timed out after ${this.config.requestTimeoutMs}ms publishing to ${topic}. ` +
|
|
351
395
|
"The message may still be queued for delivery.")), this.config.requestTimeoutMs);
|
package/dist/config.js
CHANGED
|
@@ -40,6 +40,49 @@ function oneOf(name, allowed, fallback) {
|
|
|
40
40
|
}
|
|
41
41
|
return value;
|
|
42
42
|
}
|
|
43
|
+
function port(name, fallback) {
|
|
44
|
+
const value = int(name, fallback);
|
|
45
|
+
if (value > 65_535) {
|
|
46
|
+
throw new Error(`${name} must be a port from 0 to 65535, got ${value}`);
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
function list(name) {
|
|
51
|
+
const items = (process.env[name] ?? "")
|
|
52
|
+
.split(",")
|
|
53
|
+
.map((item) => item.trim())
|
|
54
|
+
.filter(Boolean);
|
|
55
|
+
return items.length > 0 ? items : undefined;
|
|
56
|
+
}
|
|
57
|
+
function token(name) {
|
|
58
|
+
const raw = process.env[name];
|
|
59
|
+
if (!raw)
|
|
60
|
+
return undefined;
|
|
61
|
+
// A Bearer token is a single word, so one with whitespace could never match
|
|
62
|
+
// and would lock every client out. The value is not echoed back.
|
|
63
|
+
if (/\s/.test(raw)) {
|
|
64
|
+
throw new Error(`${name} must not contain whitespace`);
|
|
65
|
+
}
|
|
66
|
+
return raw;
|
|
67
|
+
}
|
|
68
|
+
export const DEFAULT_HTTP_PATH = "/mcp";
|
|
69
|
+
const PATH_SEGMENT = /^[A-Za-z0-9._~-]+$/;
|
|
70
|
+
/**
|
|
71
|
+
* Reads a URL path such as `/mcp` or `/private_x1y2`. Only unreserved URL
|
|
72
|
+
* characters are allowed, so the path a client sends is byte for byte the one
|
|
73
|
+
* configured. The value is never echoed, because it can be a secret.
|
|
74
|
+
*/
|
|
75
|
+
export function parseHttpPath(name, raw) {
|
|
76
|
+
const trimmed = (raw ?? "").trim();
|
|
77
|
+
if (trimmed === "")
|
|
78
|
+
return DEFAULT_HTTP_PATH;
|
|
79
|
+
const path = `/${trimmed.replace(/^\/+/, "").replace(/\/+$/, "")}`;
|
|
80
|
+
const segments = path.slice(1).split("/");
|
|
81
|
+
if (path === "/" || segments.some((segment) => !PATH_SEGMENT.test(segment) || /^\.+$/.test(segment))) {
|
|
82
|
+
throw new Error(`${name} must be a URL path made of letters, digits and . _ ~ - separated by single slashes, e.g. /mcp`);
|
|
83
|
+
}
|
|
84
|
+
return path;
|
|
85
|
+
}
|
|
43
86
|
export const MISSING_MQTT_URL = "Z2M_MQTT_URL is not set, e.g. mqtt://192.168.1.10:1883 " +
|
|
44
87
|
"(mqtt://, mqtts://, ws:// and wss:// are supported). " +
|
|
45
88
|
"Point it at the MQTT broker Zigbee2MQTT uses, not the Zigbee2MQTT frontend port.";
|
|
@@ -70,11 +113,17 @@ export function loadConfig({ requireMqttUrl = true } = {}) {
|
|
|
70
113
|
weakLinkThreshold: int("Z2M_WEAK_LINK_THRESHOLD", 30),
|
|
71
114
|
lowBatteryThreshold: int("Z2M_LOW_BATTERY_THRESHOLD", 20),
|
|
72
115
|
staleHours: int("Z2M_STALE_HOURS", 24),
|
|
116
|
+
transport: oneOf("Z2M_TRANSPORT", ["stdio", "http"], "stdio"),
|
|
117
|
+
httpHost: process.env.Z2M_HTTP_HOST || "127.0.0.1",
|
|
118
|
+
httpPort: port("Z2M_HTTP_PORT", 3000),
|
|
119
|
+
httpPath: parseHttpPath("Z2M_HTTP_PATH", process.env.Z2M_HTTP_PATH),
|
|
120
|
+
httpAuthToken: token("Z2M_HTTP_AUTH_TOKEN"),
|
|
121
|
+
httpAllowedHosts: list("Z2M_HTTP_ALLOWED_HOSTS"),
|
|
73
122
|
};
|
|
74
123
|
}
|
|
75
124
|
const LEVELS = { silent: 0, error: 1, warn: 2, info: 3, debug: 4 };
|
|
76
125
|
/**
|
|
77
|
-
* stdio transport owns stdout, so every diagnostic must go to stderr.
|
|
126
|
+
* The stdio transport owns stdout, so every diagnostic must go to stderr.
|
|
78
127
|
*/
|
|
79
128
|
export function createLogger(level) {
|
|
80
129
|
const emit = (at, args) => {
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { createHash, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { requireBearerAuth } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js";
|
|
3
|
+
import { InvalidTokenError } from "@modelcontextprotocol/sdk/server/auth/errors.js";
|
|
4
|
+
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
|
5
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
6
|
+
import { DEFAULT_HTTP_PATH } from "./config.js";
|
|
7
|
+
export const MCP_PATH = DEFAULT_HTTP_PATH;
|
|
8
|
+
const LOOPBACK = new Set(["127.0.0.1", "localhost", "::1"]);
|
|
9
|
+
export function isLoopback(host) {
|
|
10
|
+
return LOOPBACK.has(host);
|
|
11
|
+
}
|
|
12
|
+
const digest = (value) => createHash("sha256").update(value).digest();
|
|
13
|
+
/**
|
|
14
|
+
* Checks a presented token against the one configured token. Both are hashed
|
|
15
|
+
* first so the comparison takes the same time whatever their lengths.
|
|
16
|
+
*/
|
|
17
|
+
export function staticTokenVerifier(expected) {
|
|
18
|
+
const want = digest(expected);
|
|
19
|
+
return {
|
|
20
|
+
async verifyAccessToken(token) {
|
|
21
|
+
if (!timingSafeEqual(digest(token), want)) {
|
|
22
|
+
throw new InvalidTokenError("Invalid token");
|
|
23
|
+
}
|
|
24
|
+
// A configured token never expires, but the SDK's middleware rejects
|
|
25
|
+
// tokens without an expiry, so report one an hour past each check.
|
|
26
|
+
return {
|
|
27
|
+
token,
|
|
28
|
+
clientId: "static-token",
|
|
29
|
+
scopes: [],
|
|
30
|
+
expiresAt: Math.floor(Date.now() / 1000) + 3600,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function jsonRpcError(res, status, code, message) {
|
|
36
|
+
res.status(status).json({ jsonrpc: "2.0", error: { code, message }, id: null });
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Matches a request path against the configured one exactly, case included,
|
|
40
|
+
* allowing one trailing slash. Express routing ignores case and, under
|
|
41
|
+
* `app.use`, matches longer paths too, which would widen a path that may be
|
|
42
|
+
* the only credential. Comparing digests keeps the time taken independent of
|
|
43
|
+
* how much of a guess was right.
|
|
44
|
+
*/
|
|
45
|
+
export function pathMatcher(expected) {
|
|
46
|
+
const want = digest(expected);
|
|
47
|
+
return (path) => {
|
|
48
|
+
const trimmed = path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
|
|
49
|
+
return timingSafeEqual(digest(trimmed), want);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Serves MCP over Streamable HTTP at the configured path, `/mcp` by default.
|
|
54
|
+
* It is stateless: every request gets its own server and transport from
|
|
55
|
+
* `createServer`, so there are no sessions to expire and any number of
|
|
56
|
+
* clients can share the one process.
|
|
57
|
+
*/
|
|
58
|
+
export async function startHttp(config, createServer, log) {
|
|
59
|
+
// With no explicit list the SDK only checks the Host header on loopback
|
|
60
|
+
// binds, which is where DNS rebinding applies.
|
|
61
|
+
const app = createMcpExpressApp({ host: config.httpHost, allowedHosts: config.httpAllowedHosts });
|
|
62
|
+
const isMcpPath = pathMatcher(config.httpPath);
|
|
63
|
+
// Ahead of authentication, so no other path reveals whether a token is set.
|
|
64
|
+
app.use((req, res, next) => {
|
|
65
|
+
if (isMcpPath(req.path))
|
|
66
|
+
return next();
|
|
67
|
+
jsonRpcError(res, 404, -32000, "Not found");
|
|
68
|
+
});
|
|
69
|
+
if (config.httpAuthToken) {
|
|
70
|
+
app.use(requireBearerAuth({ verifier: staticTokenVerifier(config.httpAuthToken) }));
|
|
71
|
+
}
|
|
72
|
+
else if (!isLoopback(config.httpHost) && config.httpPath === DEFAULT_HTTP_PATH) {
|
|
73
|
+
log.warn(`listening on ${config.httpHost} without Z2M_HTTP_AUTH_TOKEN: anyone who can reach ` +
|
|
74
|
+
`the port can use every tool in write mode '${config.writeMode}'`);
|
|
75
|
+
}
|
|
76
|
+
app.post(/.*/, async (req, res) => {
|
|
77
|
+
const server = createServer();
|
|
78
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
|
79
|
+
res.on("close", () => {
|
|
80
|
+
void transport.close();
|
|
81
|
+
void server.close();
|
|
82
|
+
});
|
|
83
|
+
try {
|
|
84
|
+
await server.connect(transport);
|
|
85
|
+
await transport.handleRequest(req, res, req.body);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
log.error(`http request failed: ${error.message}`);
|
|
89
|
+
if (!res.headersSent)
|
|
90
|
+
jsonRpcError(res, 500, -32603, "Internal server error");
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
// Stateless servers have no stream to open with GET and no session to end
|
|
94
|
+
// with DELETE.
|
|
95
|
+
app.use((_req, res) => {
|
|
96
|
+
res.set("Allow", "POST");
|
|
97
|
+
jsonRpcError(res, 405, -32000, "Method not allowed");
|
|
98
|
+
});
|
|
99
|
+
// Express would otherwise answer a malformed body with an HTML page.
|
|
100
|
+
app.use((error, _req, res, next) => {
|
|
101
|
+
if (res.headersSent)
|
|
102
|
+
return next(error);
|
|
103
|
+
const status = error.status && error.status >= 400 && error.status < 500 ? error.status : 500;
|
|
104
|
+
jsonRpcError(res, status, status === 500 ? -32603 : -32700, status === 500 ? "Internal server error" : "Invalid request body");
|
|
105
|
+
});
|
|
106
|
+
const listener = await new Promise((resolve, reject) => {
|
|
107
|
+
const started = app.listen(config.httpPort, config.httpHost);
|
|
108
|
+
started.once("listening", () => resolve(started));
|
|
109
|
+
started.once("error", reject);
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
port: listener.address().port,
|
|
113
|
+
close: () => new Promise((resolve) => {
|
|
114
|
+
listener.close(() => resolve());
|
|
115
|
+
// Idle keep-alive sockets would otherwise hold the listener open.
|
|
116
|
+
listener.closeAllConnections();
|
|
117
|
+
}),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=http.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,100 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
-
import { Z2MClient } from "./client.js";
|
|
7
|
-
import { createLogger, loadConfig } from "./config.js";
|
|
8
|
-
import { redactUrl } from "./redact.js";
|
|
9
|
-
import { render, toolErrorText } from "./render.js";
|
|
10
|
-
import { selectTools } from "./tools.js";
|
|
11
|
-
const { version } = createRequire(import.meta.url)("../package.json");
|
|
12
|
-
async function main() {
|
|
13
|
-
let config;
|
|
14
|
-
let configError;
|
|
15
|
-
try {
|
|
16
|
-
config = loadConfig();
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
configError = error.message;
|
|
20
|
-
config = loadConfig({ requireMqttUrl: false });
|
|
21
|
-
}
|
|
22
|
-
const log = createLogger(config.logLevel);
|
|
23
|
-
if (configError)
|
|
24
|
-
log.error(configError);
|
|
25
|
-
const client = new Z2MClient(config, log);
|
|
26
|
-
const ctx = { client, config, configError };
|
|
27
|
-
const tools = selectTools(config.writeMode);
|
|
28
|
-
const byName = new Map(tools.map((tool) => [tool.name, tool]));
|
|
29
|
-
log.info(`write mode '${config.writeMode}' exposes ${tools.length} tools against ` +
|
|
30
|
-
`${redactUrl(config.mqttUrl)} (base topic '${config.baseTopic}')`);
|
|
31
|
-
const server = new Server({ name: "zigbee2mqtt-mcp", version }, { capabilities: { tools: {} } });
|
|
32
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
33
|
-
tools: tools.map(({ name, description, inputSchema, annotations }) => ({
|
|
34
|
-
name,
|
|
35
|
-
description,
|
|
36
|
-
inputSchema,
|
|
37
|
-
annotations,
|
|
38
|
-
})),
|
|
39
|
-
}));
|
|
40
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
41
|
-
const tool = byName.get(request.params.name);
|
|
42
|
-
// The connection diagnostic has to survive a missing URL: that is the most
|
|
43
|
-
// common misconfiguration, and it is the tool a user reaches for.
|
|
44
|
-
if (configError && !tool?.runsUnconfigured) {
|
|
45
|
-
return {
|
|
46
|
-
isError: true,
|
|
47
|
-
content: [{ type: "text", text: configError }],
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if (!tool) {
|
|
51
|
-
const known = [...byName.keys()].join(", ");
|
|
52
|
-
return {
|
|
53
|
-
isError: true,
|
|
54
|
-
content: [
|
|
55
|
-
{
|
|
56
|
-
type: "text",
|
|
57
|
-
text: `Unknown tool '${request.params.name}'. Available tools: ${known}. ` +
|
|
58
|
-
`Write mode is '${config.writeMode}'; raise Z2M_WRITE_MODE to expose more.`,
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
const result = await tool.handler(request.params.arguments ?? {}, ctx);
|
|
65
|
-
return {
|
|
66
|
-
content: [{ type: "text", text: render(result) }],
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
const text = toolErrorText(tool.name, error, config);
|
|
71
|
-
log.error(text);
|
|
72
|
-
return { isError: true, content: [{ type: "text", text }] };
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
const shutdown = async () => {
|
|
76
|
-
await client.disconnect().catch(() => undefined);
|
|
77
|
-
process.exit(0);
|
|
78
|
-
};
|
|
79
|
-
process.on("SIGINT", shutdown);
|
|
80
|
-
process.on("SIGTERM", shutdown);
|
|
81
|
-
// The open MQTT socket keeps the event loop alive, so the process would
|
|
82
|
-
// otherwise outlive the client that spawned it.
|
|
83
|
-
server.onclose = shutdown;
|
|
84
|
-
await server.connect(new StdioServerTransport());
|
|
85
|
-
log.info("ready on stdio");
|
|
86
|
-
}
|
|
87
|
-
// A throw inside an event listener would otherwise kill the session with no
|
|
88
|
-
// diagnostic on stderr, which is indistinguishable from a clean exit.
|
|
89
|
-
process.on("unhandledRejection", (reason) => {
|
|
90
|
-
console.error(`[zigbee2mqtt-mcp] unhandled rejection: ${String(reason)}`);
|
|
91
|
-
});
|
|
92
|
-
process.on("uncaughtException", (error) => {
|
|
93
|
-
console.error(`[zigbee2mqtt-mcp] uncaught exception: ${error.message}`);
|
|
94
|
-
process.exit(1);
|
|
95
|
-
});
|
|
96
|
-
main().catch((error) => {
|
|
97
|
-
console.error(`[zigbee2mqtt-mcp] fatal: ${error.message}`);
|
|
98
|
-
process.exit(1);
|
|
99
|
-
});
|
|
2
|
+
import { fatal, installCrashHandlers, start } from "./start.js";
|
|
3
|
+
installCrashHandlers();
|
|
4
|
+
start().catch(fatal);
|
|
100
5
|
//# sourceMappingURL=index.js.map
|
package/dist/redact.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/** Schemes mqtt.js accepts. Anything else is not a broker URL we should echo. */
|
|
2
2
|
const BROKER_SCHEME = /^(mqtt|mqtts|tcp|tls|ssl|ws|wss):\/\//i;
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Any URL userinfo, whatever the scheme. It ends where the authority does, so
|
|
5
|
+
* an @ in a query (?user=alice@example.com) is not taken for one.
|
|
6
|
+
*/
|
|
7
|
+
const USERINFO = /([a-z][a-z0-9+.-]*:\/\/)[^/?#@\s]+@/gi;
|
|
8
|
+
/** The query or fragment of a broker URL, where ws brokers take tokens. */
|
|
9
|
+
const BROKER_QUERY = /\b((?:mqtts?|tcp|tls|ssl|wss?):\/\/[^\s?#'"]*)[?#][^\s'"]*/gi;
|
|
5
10
|
/**
|
|
6
11
|
* Broker URLs may carry credentials as `mqtt://user:pass@host`, and ws/wss
|
|
7
12
|
* brokers accept tokens in the query string. Anything echoed back to a model
|
|
@@ -29,11 +34,13 @@ export function redactUrl(url) {
|
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
/**
|
|
32
|
-
* Last line of
|
|
37
|
+
* Last line of defense for text that leaves the process: errors bubbling up
|
|
33
38
|
* from mqtt.js quote whatever URL they were given.
|
|
34
39
|
*/
|
|
35
40
|
export function scrubSecrets(text, config) {
|
|
36
|
-
|
|
41
|
+
// mqtt.js may quote the URL rewritten, with an IPv6 host's brackets gone, so
|
|
42
|
+
// matching the configured URL verbatim is not enough.
|
|
43
|
+
let out = text.replace(USERINFO, "$1***@").replace(BROKER_QUERY, "$1?***");
|
|
37
44
|
const password = config.password;
|
|
38
45
|
// A short password would match innocuous substrings and mangle the message;
|
|
39
46
|
// userinfo in a URL is already covered above.
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import { render, toolErrorText } from "./render.js";
|
|
4
|
+
export const SERVER_NAME = "zigbee2mqtt-mcp";
|
|
5
|
+
export const SERVER_TITLE = "Zigbee2MQTT MCP";
|
|
6
|
+
/**
|
|
7
|
+
* Builds an MCP server over the given tools. A server binds to one transport,
|
|
8
|
+
* so stdio builds one for the process and HTTP builds one per request; they
|
|
9
|
+
* all share the context, and with it the single MQTT client.
|
|
10
|
+
*/
|
|
11
|
+
export function createServer(ctx, tools, log, version, name = SERVER_NAME) {
|
|
12
|
+
const { config, configError } = ctx;
|
|
13
|
+
const byName = new Map(tools.map((tool) => [tool.name, tool]));
|
|
14
|
+
const server = new Server(
|
|
15
|
+
// Clients that show a display name use the title. Home Assistant before
|
|
16
|
+
// 2026.12 shows only the name, so the Home Assistant app passes the title
|
|
17
|
+
// as its name too.
|
|
18
|
+
{ name, title: SERVER_TITLE, version }, { capabilities: { tools: {} } });
|
|
19
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
20
|
+
tools: tools.map(({ name, description, inputSchema, annotations }) => ({
|
|
21
|
+
name,
|
|
22
|
+
description,
|
|
23
|
+
inputSchema,
|
|
24
|
+
annotations,
|
|
25
|
+
})),
|
|
26
|
+
}));
|
|
27
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
28
|
+
const tool = byName.get(request.params.name);
|
|
29
|
+
// The connection diagnostic has to survive a missing URL: that is the most
|
|
30
|
+
// common misconfiguration, and it is the tool a user reaches for.
|
|
31
|
+
if (configError && !tool?.runsUnconfigured) {
|
|
32
|
+
return {
|
|
33
|
+
isError: true,
|
|
34
|
+
content: [{ type: "text", text: configError }],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (!tool) {
|
|
38
|
+
const known = [...byName.keys()].join(", ");
|
|
39
|
+
return {
|
|
40
|
+
isError: true,
|
|
41
|
+
content: [
|
|
42
|
+
{
|
|
43
|
+
type: "text",
|
|
44
|
+
text: `Unknown tool '${request.params.name}'. Available tools: ${known}. ` +
|
|
45
|
+
`Write mode is '${config.writeMode}'; raise Z2M_WRITE_MODE to expose more.`,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const result = await tool.handler(request.params.arguments ?? {}, ctx);
|
|
52
|
+
return {
|
|
53
|
+
content: [{ type: "text", text: render(result) }],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const text = toolErrorText(tool.name, error, config);
|
|
58
|
+
log.error(text);
|
|
59
|
+
return { isError: true, content: [{ type: "text", text }] };
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return server;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=server.js.map
|
package/dist/start.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { Z2MClient } from "./client.js";
|
|
4
|
+
import { createLogger, loadConfig } from "./config.js";
|
|
5
|
+
import { startHttp } from "./http.js";
|
|
6
|
+
import { redactUrl } from "./redact.js";
|
|
7
|
+
import { createServer } from "./server.js";
|
|
8
|
+
import { selectTools } from "./tools.js";
|
|
9
|
+
/** The package version; compiled tests sit one folder deeper than dist/. */
|
|
10
|
+
function packageVersion() {
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
for (const candidate of ["../package.json", "../../package.json"]) {
|
|
13
|
+
try {
|
|
14
|
+
const pkg = require(candidate);
|
|
15
|
+
if (pkg.name === "zigbee2mqtt-mcp" && pkg.version)
|
|
16
|
+
return pkg.version;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// Try the next location.
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
throw new Error("cannot find zigbee2mqtt-mcp's package.json");
|
|
23
|
+
}
|
|
24
|
+
export const version = packageVersion();
|
|
25
|
+
/**
|
|
26
|
+
* Starts the server from the environment, over stdio or HTTP, and installs the
|
|
27
|
+
* signal handlers that shut it down. Shared by the command line entry point
|
|
28
|
+
* and the Home Assistant app.
|
|
29
|
+
*/
|
|
30
|
+
export async function start({ serverName } = {}) {
|
|
31
|
+
let config;
|
|
32
|
+
let configError;
|
|
33
|
+
try {
|
|
34
|
+
config = loadConfig();
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
configError = error.message;
|
|
38
|
+
config = loadConfig({ requireMqttUrl: false });
|
|
39
|
+
}
|
|
40
|
+
const log = createLogger(config.logLevel);
|
|
41
|
+
if (configError)
|
|
42
|
+
log.error(configError);
|
|
43
|
+
const client = new Z2MClient(config, log);
|
|
44
|
+
const ctx = { client, config, configError };
|
|
45
|
+
const tools = selectTools(config.writeMode);
|
|
46
|
+
log.info(`write mode '${config.writeMode}' exposes ${tools.length} tools against ` +
|
|
47
|
+
`${redactUrl(config.mqttUrl)} (base topic '${config.baseTopic}')`);
|
|
48
|
+
let http;
|
|
49
|
+
const stopping = new AbortController();
|
|
50
|
+
const shutdown = async () => {
|
|
51
|
+
stopping.abort();
|
|
52
|
+
await http?.close().catch(() => undefined);
|
|
53
|
+
await client.disconnect().catch(() => undefined);
|
|
54
|
+
process.exit(0);
|
|
55
|
+
};
|
|
56
|
+
process.on("SIGINT", shutdown);
|
|
57
|
+
process.on("SIGTERM", shutdown);
|
|
58
|
+
if (config.transport === "http") {
|
|
59
|
+
http = await startHttp(config, () => createServer(ctx, tools, log, version, serverName), log);
|
|
60
|
+
log.info(`ready on http://${config.httpHost}:${http.port}${config.httpPath}`);
|
|
61
|
+
return { config, log, client, http, shutdownSignal: stopping.signal };
|
|
62
|
+
}
|
|
63
|
+
const server = createServer(ctx, tools, log, version, serverName);
|
|
64
|
+
// The open MQTT socket keeps the event loop alive, so the process would
|
|
65
|
+
// otherwise outlive the client that spawned it.
|
|
66
|
+
server.onclose = shutdown;
|
|
67
|
+
await server.connect(new StdioServerTransport());
|
|
68
|
+
log.info("ready on stdio");
|
|
69
|
+
return { config, log, client, shutdownSignal: stopping.signal };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A throw inside an event listener would otherwise kill the session with no
|
|
73
|
+
* diagnostic on stderr, which is indistinguishable from a clean exit.
|
|
74
|
+
*/
|
|
75
|
+
export function installCrashHandlers() {
|
|
76
|
+
process.on("unhandledRejection", (reason) => {
|
|
77
|
+
console.error(`[zigbee2mqtt-mcp] unhandled rejection: ${String(reason)}`);
|
|
78
|
+
});
|
|
79
|
+
process.on("uncaughtException", (error) => {
|
|
80
|
+
console.error(`[zigbee2mqtt-mcp] uncaught exception: ${error.message}`);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
export function fatal(error) {
|
|
85
|
+
console.error(`[zigbee2mqtt-mcp] fatal: ${error.message}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=start.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zigbee2mqtt-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"mcpName": "io.github.alexpfau/zigbee2mqtt-mcp",
|
|
5
5
|
"description": "Model Context Protocol server for administering a Zigbee2MQTT estate: health reporting, network diagnostics, OTA updates, pairing and device management over the MQTT bridge API.",
|
|
6
6
|
"keywords": [
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"main": "dist/index.js",
|
|
31
31
|
"files": [
|
|
32
32
|
"dist/**/*.js",
|
|
33
|
+
"!dist/ha/**",
|
|
33
34
|
"README.md",
|
|
34
35
|
"LICENSE"
|
|
35
36
|
],
|
|
@@ -41,13 +42,16 @@
|
|
|
41
42
|
"watch": "tsc --watch",
|
|
42
43
|
"start": "node dist/index.js",
|
|
43
44
|
"test": "tsc -p tsconfig.test.json && cd dist-test && node --test",
|
|
44
|
-
"prepublishOnly": "npm run build"
|
|
45
|
+
"prepublishOnly": "npm run build",
|
|
46
|
+
"version": "node scripts/sync-version.mjs && git add server.json homeassistant-app/config.yaml"
|
|
45
47
|
},
|
|
46
48
|
"dependencies": {
|
|
47
49
|
"@modelcontextprotocol/sdk": "^1.20.2",
|
|
50
|
+
"express": "^5.3.0",
|
|
48
51
|
"mqtt": "^5.14.1"
|
|
49
52
|
},
|
|
50
53
|
"devDependencies": {
|
|
54
|
+
"@types/express": "^5.0.6",
|
|
51
55
|
"@types/node": "^22.20.1",
|
|
52
56
|
"typescript": "^7.0.2"
|
|
53
57
|
}
|