zigbee2mqtt-mcp 0.5.0 → 0.6.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 +2 -2
- package/dist/client.js +17 -1
- package/dist/config.js +6 -2
- package/dist/index.js +5 -3
- package/dist/tools.js +19 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -123,7 +123,7 @@ Opt in to the destructive tier only when you want it:
|
|
|
123
123
|
|
|
124
124
|
| Tool | Purpose |
|
|
125
125
|
| --- | --- |
|
|
126
|
-
| `z2m_connection_status` | Broker reachability, TLS posture and cached message counts — reports instead of throwing when
|
|
126
|
+
| `z2m_connection_status` | Broker reachability, TLS posture and cached message counts — reports instead of throwing, even when nothing is configured yet |
|
|
127
127
|
| `z2m_bridge_info` | Version, coordinator, channel, PAN ID, permit_join, restart_required, runtime stats |
|
|
128
128
|
| `z2m_list_devices` | Filter and sort devices by type, availability, link quality, battery, pending update |
|
|
129
129
|
| `z2m_get_device` | Exposes, settable options, endpoints, bindings, configured reportings, current state |
|
|
@@ -154,7 +154,7 @@ Some fields depend on your Zigbee2MQTT configuration. The server detects what is
|
|
|
154
154
|
|
|
155
155
|
## Security notes
|
|
156
156
|
|
|
157
|
-
- 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.
|
|
157
|
+
- 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.
|
|
158
158
|
- `safe` mode can actuate anything on the mesh via `z2m_set_state`, including locks, valves and sirens. Use `off` if that matters.
|
|
159
159
|
- `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.
|
|
160
160
|
|
package/dist/client.js
CHANGED
|
@@ -47,6 +47,7 @@ export class Z2MClient {
|
|
|
47
47
|
transactionCounter = 0;
|
|
48
48
|
lastMessageAt = 0;
|
|
49
49
|
bridgeRevision = 0;
|
|
50
|
+
brokerHandshake = false;
|
|
50
51
|
bridge = new Map();
|
|
51
52
|
deviceState = new Map();
|
|
52
53
|
availability = new Map();
|
|
@@ -107,6 +108,7 @@ export class Z2MClient {
|
|
|
107
108
|
});
|
|
108
109
|
client.on("message", (topic, payload) => this.handleMessage(topic, payload));
|
|
109
110
|
client.on("connect", () => {
|
|
111
|
+
this.brokerHandshake = true;
|
|
110
112
|
this.log.debug("connected, subscribing");
|
|
111
113
|
client.subscribe(`${config.baseTopic}/#`, { qos: 1 }, (error) => {
|
|
112
114
|
if (error) {
|
|
@@ -178,7 +180,8 @@ export class Z2MClient {
|
|
|
178
180
|
push(this.logs, LOG_BUFFER, {
|
|
179
181
|
received_at: new Date().toISOString(),
|
|
180
182
|
level: String(entry.level ?? "info"),
|
|
181
|
-
|
|
183
|
+
// Zigbee2MQTT logs its own broker URL at startup, credentials included.
|
|
184
|
+
message: scrubSecrets(String(entry.message ?? raw), this.config),
|
|
182
185
|
namespace: entry.namespace,
|
|
183
186
|
});
|
|
184
187
|
}
|
|
@@ -196,6 +199,12 @@ export class Z2MClient {
|
|
|
196
199
|
return;
|
|
197
200
|
}
|
|
198
201
|
case "bridge":
|
|
202
|
+
// We subscribe to the whole base topic, so our own publishes to
|
|
203
|
+
// bridge/request/* come straight back. Caching them would inflate the
|
|
204
|
+
// topic count and, worse, satisfy awaitBridgeRefresh before
|
|
205
|
+
// Zigbee2MQTT has republished anything.
|
|
206
|
+
if (route.name.startsWith("request/"))
|
|
207
|
+
return;
|
|
199
208
|
this.bridge.set(route.name, parsed ?? raw);
|
|
200
209
|
this.bridgeRevision++;
|
|
201
210
|
return;
|
|
@@ -213,6 +222,12 @@ export class Z2MClient {
|
|
|
213
222
|
this.deviceState.set(route.device, parsed);
|
|
214
223
|
}
|
|
215
224
|
return;
|
|
225
|
+
default: {
|
|
226
|
+
// Adding a TopicRoute variant without handling it is a compile error,
|
|
227
|
+
// rather than messages being silently dropped.
|
|
228
|
+
const unhandled = route;
|
|
229
|
+
void unhandled;
|
|
230
|
+
}
|
|
216
231
|
}
|
|
217
232
|
}
|
|
218
233
|
resolveWaiter(subTopic, parsed) {
|
|
@@ -324,6 +339,7 @@ export class Z2MClient {
|
|
|
324
339
|
client_certificate: this.config.cert !== undefined,
|
|
325
340
|
},
|
|
326
341
|
authenticated: this.config.username !== undefined,
|
|
342
|
+
broker_handshake: this.brokerHandshake,
|
|
327
343
|
cached: {
|
|
328
344
|
bridge_topics: this.bridge.size,
|
|
329
345
|
device_state: this.deviceState.size,
|
package/dist/config.js
CHANGED
|
@@ -3,10 +3,14 @@ function int(name, fallback) {
|
|
|
3
3
|
const raw = process.env[name];
|
|
4
4
|
if (raw === undefined || raw === "")
|
|
5
5
|
return fallback;
|
|
6
|
-
|
|
7
|
-
if (
|
|
6
|
+
// parseInt would accept '12abc' as 12, which hides a typo in a timeout.
|
|
7
|
+
if (!/^-?\d+$/.test(raw.trim())) {
|
|
8
8
|
throw new Error(`${name} must be an integer, got ${JSON.stringify(raw)}`);
|
|
9
9
|
}
|
|
10
|
+
const parsed = Number.parseInt(raw, 10);
|
|
11
|
+
if (parsed < 0) {
|
|
12
|
+
throw new Error(`${name} must not be negative, got ${JSON.stringify(raw)}`);
|
|
13
|
+
}
|
|
10
14
|
return parsed;
|
|
11
15
|
}
|
|
12
16
|
function bool(name, fallback) {
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ async function main() {
|
|
|
22
22
|
if (configError)
|
|
23
23
|
log.error(configError);
|
|
24
24
|
const client = new Z2MClient(config, log);
|
|
25
|
-
const ctx = { client, config };
|
|
25
|
+
const ctx = { client, config, configError };
|
|
26
26
|
const tools = selectTools(config.writeMode);
|
|
27
27
|
const byName = new Map(tools.map((tool) => [tool.name, tool]));
|
|
28
28
|
log.info(`write mode '${config.writeMode}' exposes ${tools.length} tools against ` +
|
|
@@ -37,13 +37,15 @@ async function main() {
|
|
|
37
37
|
})),
|
|
38
38
|
}));
|
|
39
39
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
40
|
-
|
|
40
|
+
const tool = byName.get(request.params.name);
|
|
41
|
+
// The connection diagnostic has to survive a missing URL: that is the most
|
|
42
|
+
// common misconfiguration, and it is the tool a user reaches for.
|
|
43
|
+
if (configError && !tool?.runsUnconfigured) {
|
|
41
44
|
return {
|
|
42
45
|
isError: true,
|
|
43
46
|
content: [{ type: "text", text: configError }],
|
|
44
47
|
};
|
|
45
48
|
}
|
|
46
|
-
const tool = byName.get(request.params.name);
|
|
47
49
|
if (!tool) {
|
|
48
50
|
const known = [...byName.keys()].join(", ");
|
|
49
51
|
return {
|
package/dist/tools.js
CHANGED
|
@@ -88,14 +88,24 @@ const readTools = [
|
|
|
88
88
|
name: "z2m_connection_status",
|
|
89
89
|
tier: "read",
|
|
90
90
|
annotations: readOnly("Check MQTT connection"),
|
|
91
|
+
runsUnconfigured: true,
|
|
91
92
|
description: "Check whether this server can reach the MQTT broker and whether Zigbee2MQTT is publishing to it. " +
|
|
92
|
-
"Read-only, and the only tool that reports rather than throws when the connection is down
|
|
93
|
-
"it first when any other tool fails with a connection or timeout error.
|
|
94
|
-
"broker from a reachable broker carrying no Zigbee2MQTT data, which
|
|
95
|
-
"does not match the mqtt.base_topic setting in Zigbee2MQTT. Reports
|
|
96
|
-
"redacted, TLS settings, cached message counts and the
|
|
93
|
+
"Read-only, and the only tool that reports rather than throws when the connection is down or not " +
|
|
94
|
+
"configured at all, so call it first when any other tool fails with a connection or timeout error. " +
|
|
95
|
+
"Distinguishes an unreachable broker from a reachable broker carrying no Zigbee2MQTT data, which " +
|
|
96
|
+
"usually means Z2M_BASE_TOPIC does not match the mqtt.base_topic setting in Zigbee2MQTT. Reports " +
|
|
97
|
+
"the broker URL with credentials redacted, TLS settings, cached message counts and the write mode.",
|
|
97
98
|
inputSchema: EMPTY,
|
|
98
99
|
handler: async (_args, ctx) => {
|
|
100
|
+
if (ctx.configError) {
|
|
101
|
+
return {
|
|
102
|
+
configured: false,
|
|
103
|
+
broker_reachable: false,
|
|
104
|
+
zigbee2mqtt_responding: false,
|
|
105
|
+
error: ctx.configError,
|
|
106
|
+
hints: ["Set Z2M_MQTT_URL in the server's environment, then call this tool again."],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
99
109
|
let brokerReachable = true;
|
|
100
110
|
let zigbee2mqttResponding = true;
|
|
101
111
|
let error;
|
|
@@ -105,9 +115,9 @@ const readTools = [
|
|
|
105
115
|
catch (e) {
|
|
106
116
|
error = scrubSecrets(e.message, ctx.config);
|
|
107
117
|
zigbee2mqttResponding = false;
|
|
108
|
-
//
|
|
109
|
-
// from
|
|
110
|
-
brokerReachable = e instanceof NoBridgeDataError;
|
|
118
|
+
// Whether the broker answered is a fact the client observed, not
|
|
119
|
+
// something to infer from which error happened to surface.
|
|
120
|
+
brokerReachable = ctx.client.status().broker_handshake || e instanceof NoBridgeDataError;
|
|
111
121
|
}
|
|
112
122
|
const status = ctx.client.status();
|
|
113
123
|
const hints = [];
|
|
@@ -124,6 +134,7 @@ const readTools = [
|
|
|
124
134
|
hints.push("TLS certificate verification is disabled, so the broker's identity is not checked.");
|
|
125
135
|
}
|
|
126
136
|
return {
|
|
137
|
+
configured: true,
|
|
127
138
|
broker_reachable: brokerReachable,
|
|
128
139
|
zigbee2mqtt_responding: zigbee2mqttResponding,
|
|
129
140
|
...status,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zigbee2mqtt-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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": [
|