zigbee2mqtt-mcp 0.2.2 → 0.2.3

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/dist/config.js CHANGED
@@ -36,14 +36,21 @@ function oneOf(name, allowed, fallback) {
36
36
  }
37
37
  return value;
38
38
  }
39
- export function loadConfig() {
39
+ export const MISSING_MQTT_URL = "Z2M_MQTT_URL is not set, e.g. mqtt://192.168.1.10:1883 " +
40
+ "(mqtt://, mqtts://, ws:// and wss:// are supported). " +
41
+ "Point it at the MQTT broker Zigbee2MQTT uses, not the Zigbee2MQTT frontend port.";
42
+ /**
43
+ * `requireMqttUrl: false` lets the server start unconfigured so clients and
44
+ * directory scanners can still enumerate tools; calls then fail with a clear
45
+ * message rather than the process refusing to start.
46
+ */
47
+ export function loadConfig({ requireMqttUrl = true } = {}) {
40
48
  const mqttUrl = process.env.Z2M_MQTT_URL;
41
- if (!mqttUrl) {
42
- throw new Error("Z2M_MQTT_URL is required, e.g. mqtt://192.168.1.10:1883 " +
43
- "(mqtt://, mqtts://, ws:// and wss:// are supported).");
49
+ if (!mqttUrl && requireMqttUrl) {
50
+ throw new Error(MISSING_MQTT_URL);
44
51
  }
45
52
  return {
46
- mqttUrl,
53
+ mqttUrl: mqttUrl || "mqtt://unconfigured.invalid:1883",
47
54
  username: process.env.Z2M_MQTT_USERNAME || undefined,
48
55
  password: process.env.Z2M_MQTT_PASSWORD || undefined,
49
56
  baseTopic: (process.env.Z2M_BASE_TOPIC || "zigbee2mqtt").replace(/\/+$/, ""),
package/dist/index.js CHANGED
@@ -8,8 +8,18 @@ import { createLogger, loadConfig } from "./config.js";
8
8
  import { selectTools } from "./tools.js";
9
9
  const { version } = createRequire(import.meta.url)("../package.json");
10
10
  async function main() {
11
- const config = loadConfig();
11
+ let config;
12
+ let configError;
13
+ try {
14
+ config = loadConfig();
15
+ }
16
+ catch (error) {
17
+ configError = error.message;
18
+ config = loadConfig({ requireMqttUrl: false });
19
+ }
12
20
  const log = createLogger(config.logLevel);
21
+ if (configError)
22
+ log.error(configError);
13
23
  const client = new Z2MClient(config, log);
14
24
  const ctx = { client, config };
15
25
  const tools = selectTools(config.writeMode);
@@ -21,6 +31,12 @@ async function main() {
21
31
  tools: tools.map(({ name, description, inputSchema }) => ({ name, description, inputSchema })),
22
32
  }));
23
33
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
34
+ if (configError) {
35
+ return {
36
+ isError: true,
37
+ content: [{ type: "text", text: configError }],
38
+ };
39
+ }
24
40
  const tool = byName.get(request.params.name);
25
41
  if (!tool) {
26
42
  const known = [...byName.keys()].join(", ");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zigbee2mqtt-mcp",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
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": [