@solomonneas/librenms-mcp 0.1.0 → 0.2.1
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 +164 -56
- package/dist/cli.js +1180 -0
- package/dist/index.js +162 -7
- package/dist/mcp-bin.js +733 -0
- package/dist/mcp-server.js +241 -64
- package/openclaw.plugin.json +1 -1
- package/package.json +51 -13
package/dist/mcp-server.js
CHANGED
|
@@ -45,10 +45,10 @@ var LibreNmsUnreachableError = class extends Error {
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
var LibreNmsClient = class {
|
|
48
|
-
constructor(
|
|
49
|
-
this.cfg =
|
|
48
|
+
constructor(cfg, opts = {}) {
|
|
49
|
+
this.cfg = cfg;
|
|
50
50
|
this.retryDelayMs = opts.retryDelayMs ?? 1e3;
|
|
51
|
-
if (
|
|
51
|
+
if (cfg.tlsInsecure && cfg.url.startsWith("https://")) {
|
|
52
52
|
this.dispatcher = new UndiciAgent({ connect: { rejectUnauthorized: false } });
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -67,6 +67,9 @@ var LibreNmsClient = class {
|
|
|
67
67
|
async put(path, body) {
|
|
68
68
|
return this.request("PUT", path, body);
|
|
69
69
|
}
|
|
70
|
+
async delete(path) {
|
|
71
|
+
return this.request("DELETE", path);
|
|
72
|
+
}
|
|
70
73
|
async request(method, path, body) {
|
|
71
74
|
const url = this.cfg.url + "/api/v0" + path;
|
|
72
75
|
const headers = { "x-auth-token": this.cfg.token };
|
|
@@ -145,6 +148,34 @@ function redact(value) {
|
|
|
145
148
|
return value;
|
|
146
149
|
}
|
|
147
150
|
|
|
151
|
+
// src/validate.ts
|
|
152
|
+
import { TypeCompiler } from "@sinclair/typebox/compiler";
|
|
153
|
+
var ValidationError = class extends Error {
|
|
154
|
+
constructor(message) {
|
|
155
|
+
super(message);
|
|
156
|
+
this.name = "ValidationError";
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var compiledCache = /* @__PURE__ */ new WeakMap();
|
|
160
|
+
function getChecker(schema) {
|
|
161
|
+
let checker = compiledCache.get(schema);
|
|
162
|
+
if (!checker) {
|
|
163
|
+
checker = TypeCompiler.Compile(schema);
|
|
164
|
+
compiledCache.set(schema, checker);
|
|
165
|
+
}
|
|
166
|
+
return checker;
|
|
167
|
+
}
|
|
168
|
+
function validateToolArgs(schema, toolName, args) {
|
|
169
|
+
const checker = getChecker(schema);
|
|
170
|
+
if (checker.Check(args)) return;
|
|
171
|
+
const first = checker.Errors(args).First();
|
|
172
|
+
const where = first?.path ? ` at ${first.path}` : "";
|
|
173
|
+
const detail = first ? `${first.message}${where}` : "schema mismatch";
|
|
174
|
+
throw new ValidationError(
|
|
175
|
+
`Invalid arguments for ${toolName}: ${detail}`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
148
179
|
// src/tools/librenms_status.ts
|
|
149
180
|
import { Type } from "@sinclair/typebox";
|
|
150
181
|
|
|
@@ -154,17 +185,29 @@ function jsonToolResult(payload) {
|
|
|
154
185
|
content: [{ type: "text", text: JSON.stringify(payload, null, 2) }]
|
|
155
186
|
};
|
|
156
187
|
}
|
|
188
|
+
function safeInt(value, label, opts = {}) {
|
|
189
|
+
const n = typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;
|
|
190
|
+
if (!Number.isInteger(n)) {
|
|
191
|
+
throw new Error(`${label} must be an integer, got: ${String(value)}`);
|
|
192
|
+
}
|
|
193
|
+
const min = opts.min ?? 1;
|
|
194
|
+
if (n < min) throw new Error(`${label} must be >= ${min}, got: ${n}`);
|
|
195
|
+
if (opts.max !== void 0 && n > opts.max) {
|
|
196
|
+
throw new Error(`${label} must be <= ${opts.max}, got: ${n}`);
|
|
197
|
+
}
|
|
198
|
+
return n;
|
|
199
|
+
}
|
|
157
200
|
|
|
158
201
|
// src/tools/librenms_status.ts
|
|
159
202
|
var Schema = Type.Object({}, { additionalProperties: false });
|
|
160
|
-
function createLibrenmsStatusTool(
|
|
203
|
+
function createLibrenmsStatusTool(getClient) {
|
|
161
204
|
return {
|
|
162
205
|
name: "librenms_status",
|
|
163
206
|
label: "librenms: status",
|
|
164
207
|
description: "LibreNMS system health (version, totals, last poll) via GET /api/v0/system.",
|
|
165
208
|
parameters: Schema,
|
|
166
209
|
execute: async () => {
|
|
167
|
-
const client =
|
|
210
|
+
const client = getClient();
|
|
168
211
|
const r = await client.get("/system");
|
|
169
212
|
return jsonToolResult({ system: r.system?.[0] ?? null });
|
|
170
213
|
}
|
|
@@ -190,7 +233,7 @@ var Schema2 = Type2.Object(
|
|
|
190
233
|
},
|
|
191
234
|
{ additionalProperties: false }
|
|
192
235
|
);
|
|
193
|
-
function createLibrenmsListDevicesTool(
|
|
236
|
+
function createLibrenmsListDevicesTool(getClient) {
|
|
194
237
|
return {
|
|
195
238
|
name: "librenms_list_devices",
|
|
196
239
|
label: "librenms: list devices",
|
|
@@ -198,8 +241,8 @@ function createLibrenmsListDevicesTool(getClient2) {
|
|
|
198
241
|
parameters: Schema2,
|
|
199
242
|
execute: async (_id, raw) => {
|
|
200
243
|
const args = raw ?? {};
|
|
201
|
-
const path = args.type ? `/devices?type=${args.type}` : "/devices";
|
|
202
|
-
const client =
|
|
244
|
+
const path = args.type ? `/devices?type=${encodeURIComponent(args.type)}` : "/devices";
|
|
245
|
+
const client = getClient();
|
|
203
246
|
const r = await client.get(path);
|
|
204
247
|
return jsonToolResult({ devices: r.devices ?? [] });
|
|
205
248
|
}
|
|
@@ -216,7 +259,7 @@ var Schema3 = Type3.Object(
|
|
|
216
259
|
},
|
|
217
260
|
{ additionalProperties: false }
|
|
218
261
|
);
|
|
219
|
-
function createLibrenmsGetDeviceTool(
|
|
262
|
+
function createLibrenmsGetDeviceTool(getClient) {
|
|
220
263
|
return {
|
|
221
264
|
name: "librenms_get_device",
|
|
222
265
|
label: "librenms: get device",
|
|
@@ -224,7 +267,7 @@ function createLibrenmsGetDeviceTool(getClient2) {
|
|
|
224
267
|
parameters: Schema3,
|
|
225
268
|
execute: async (_id, raw) => {
|
|
226
269
|
const args = raw;
|
|
227
|
-
const client =
|
|
270
|
+
const client = getClient();
|
|
228
271
|
const r = await client.get(`/devices/${encodeURIComponent(args.hostname)}`);
|
|
229
272
|
return jsonToolResult({ device: r.devices?.[0] ?? null });
|
|
230
273
|
}
|
|
@@ -242,7 +285,7 @@ var Schema4 = Type4.Object(
|
|
|
242
285
|
{ additionalProperties: false }
|
|
243
286
|
);
|
|
244
287
|
var COLUMNS = "ifName,ifAdminStatus,ifOperStatus,ifInErrors,ifOutErrors,ifSpeed,ifDescr";
|
|
245
|
-
function createLibrenmsListPortsTool(
|
|
288
|
+
function createLibrenmsListPortsTool(getClient) {
|
|
246
289
|
return {
|
|
247
290
|
name: "librenms_list_ports",
|
|
248
291
|
label: "librenms: list ports",
|
|
@@ -250,7 +293,7 @@ function createLibrenmsListPortsTool(getClient2) {
|
|
|
250
293
|
parameters: Schema4,
|
|
251
294
|
execute: async (_id, raw) => {
|
|
252
295
|
const args = raw;
|
|
253
|
-
const client =
|
|
296
|
+
const client = getClient();
|
|
254
297
|
const r = await client.get(`/devices/${encodeURIComponent(args.hostname)}/ports?columns=${COLUMNS}`);
|
|
255
298
|
return jsonToolResult({ ports: r.ports ?? [] });
|
|
256
299
|
}
|
|
@@ -281,7 +324,7 @@ var Schema5 = Type5.Object(
|
|
|
281
324
|
{ additionalProperties: false }
|
|
282
325
|
);
|
|
283
326
|
var COLUMNS2 = "device_id,ifName,ifInErrors,ifOutErrors,ifSpeed,ifInOctets,ifOutOctets";
|
|
284
|
-
function createLibrenmsPortHealthTool(
|
|
327
|
+
function createLibrenmsPortHealthTool(getClient) {
|
|
285
328
|
return {
|
|
286
329
|
name: "librenms_port_health",
|
|
287
330
|
label: "librenms: port health",
|
|
@@ -291,7 +334,7 @@ function createLibrenmsPortHealthTool(getClient2) {
|
|
|
291
334
|
const args = raw ?? {};
|
|
292
335
|
const limit = args.limit ?? 10;
|
|
293
336
|
const metric = args.metric ?? "errors_in";
|
|
294
|
-
const client =
|
|
337
|
+
const client = getClient();
|
|
295
338
|
const r = await client.get(`/ports?columns=${COLUMNS2}`);
|
|
296
339
|
const ports = r.ports ?? [];
|
|
297
340
|
const sorted = ports.slice().sort((a, b) => {
|
|
@@ -323,7 +366,7 @@ var Schema6 = Type6.Object(
|
|
|
323
366
|
},
|
|
324
367
|
{ additionalProperties: false }
|
|
325
368
|
);
|
|
326
|
-
function createLibrenmsListAlertsTool(
|
|
369
|
+
function createLibrenmsListAlertsTool(getClient) {
|
|
327
370
|
return {
|
|
328
371
|
name: "librenms_list_alerts",
|
|
329
372
|
label: "librenms: list alerts",
|
|
@@ -331,8 +374,8 @@ function createLibrenmsListAlertsTool(getClient2) {
|
|
|
331
374
|
parameters: Schema6,
|
|
332
375
|
execute: async (_id, raw) => {
|
|
333
376
|
const args = raw ?? {};
|
|
334
|
-
const path = args.state !== void 0 ? `/alerts?state=${args.state}` : "/alerts";
|
|
335
|
-
const client =
|
|
377
|
+
const path = args.state !== void 0 ? `/alerts?state=${encodeURIComponent(args.state)}` : "/alerts";
|
|
378
|
+
const client = getClient();
|
|
336
379
|
const r = await client.get(path);
|
|
337
380
|
return jsonToolResult({ alerts: r.alerts ?? [] });
|
|
338
381
|
}
|
|
@@ -347,7 +390,7 @@ var Schema7 = Type7.Object(
|
|
|
347
390
|
},
|
|
348
391
|
{ additionalProperties: false }
|
|
349
392
|
);
|
|
350
|
-
function createLibrenmsGetAlertTool(
|
|
393
|
+
function createLibrenmsGetAlertTool(getClient) {
|
|
351
394
|
return {
|
|
352
395
|
name: "librenms_get_alert",
|
|
353
396
|
label: "librenms: get alert",
|
|
@@ -355,8 +398,9 @@ function createLibrenmsGetAlertTool(getClient2) {
|
|
|
355
398
|
parameters: Schema7,
|
|
356
399
|
execute: async (_id, raw) => {
|
|
357
400
|
const args = raw;
|
|
358
|
-
const
|
|
359
|
-
const
|
|
401
|
+
const id = safeInt(args.id, "id");
|
|
402
|
+
const client = getClient();
|
|
403
|
+
const r = await client.get(`/alerts/${encodeURIComponent(id)}`);
|
|
360
404
|
return jsonToolResult({ alert: r.alerts?.[0] ?? null });
|
|
361
405
|
}
|
|
362
406
|
};
|
|
@@ -381,7 +425,7 @@ var Schema8 = Type8.Object(
|
|
|
381
425
|
},
|
|
382
426
|
{ additionalProperties: false }
|
|
383
427
|
);
|
|
384
|
-
function createLibrenmsAlertHistoryTool(
|
|
428
|
+
function createLibrenmsAlertHistoryTool(getClient) {
|
|
385
429
|
return {
|
|
386
430
|
name: "librenms_alert_history",
|
|
387
431
|
label: "librenms: alert history",
|
|
@@ -389,9 +433,11 @@ function createLibrenmsAlertHistoryTool(getClient2) {
|
|
|
389
433
|
parameters: Schema8,
|
|
390
434
|
execute: async (_id, raw) => {
|
|
391
435
|
const args = raw ?? {};
|
|
392
|
-
const limit = args.limit ?? 25;
|
|
393
|
-
const path = args.device_id ? `/logs/alertlog/${
|
|
394
|
-
|
|
436
|
+
const limit = safeInt(args.limit ?? 25, "limit");
|
|
437
|
+
const path = args.device_id !== void 0 ? `/logs/alertlog/${encodeURIComponent(
|
|
438
|
+
safeInt(args.device_id, "device_id")
|
|
439
|
+
)}?limit=${encodeURIComponent(limit)}` : `/logs/alertlog?limit=${encodeURIComponent(limit)}`;
|
|
440
|
+
const client = getClient();
|
|
395
441
|
const r = await client.get(path);
|
|
396
442
|
return jsonToolResult({
|
|
397
443
|
count: r.logs?.length ?? 0,
|
|
@@ -436,7 +482,7 @@ var Schema9 = Type9.Object(
|
|
|
436
482
|
{ additionalProperties: false }
|
|
437
483
|
);
|
|
438
484
|
var NAME = "librenms_ack_alert";
|
|
439
|
-
function createLibrenmsAckAlertTool(
|
|
485
|
+
function createLibrenmsAckAlertTool(getClient) {
|
|
440
486
|
return {
|
|
441
487
|
name: NAME,
|
|
442
488
|
label: "librenms: ack alert",
|
|
@@ -445,12 +491,13 @@ function createLibrenmsAckAlertTool(getClient2) {
|
|
|
445
491
|
execute: async (_id, raw) => {
|
|
446
492
|
assertConfirmedWrite(raw, NAME);
|
|
447
493
|
const args = raw;
|
|
448
|
-
const
|
|
494
|
+
const id = safeInt(args.id, "id");
|
|
495
|
+
const client = getClient();
|
|
449
496
|
const body = {};
|
|
450
497
|
if (args.note !== void 0) body.note = args.note;
|
|
451
498
|
if (args.until_clear !== void 0) body.until_clear = args.until_clear;
|
|
452
|
-
const r = await client.put(`/alerts/${
|
|
453
|
-
return jsonToolResult({ alert_id:
|
|
499
|
+
const r = await client.put(`/alerts/${encodeURIComponent(id)}`, body);
|
|
500
|
+
return jsonToolResult({ alert_id: id, acked: true, response: r });
|
|
454
501
|
}
|
|
455
502
|
};
|
|
456
503
|
}
|
|
@@ -483,7 +530,7 @@ var Schema10 = Type10.Object(
|
|
|
483
530
|
{ additionalProperties: false }
|
|
484
531
|
);
|
|
485
532
|
var NAME2 = "librenms_set_maintenance";
|
|
486
|
-
function createLibrenmsSetMaintenanceTool(
|
|
533
|
+
function createLibrenmsSetMaintenanceTool(getClient) {
|
|
487
534
|
return {
|
|
488
535
|
name: NAME2,
|
|
489
536
|
label: "librenms: set maintenance",
|
|
@@ -502,7 +549,7 @@ function createLibrenmsSetMaintenanceTool(getClient2) {
|
|
|
502
549
|
`start must be Y-m-d H:i:00 format (e.g. "2026-05-17 14:30:00"), got: ${args.start}`
|
|
503
550
|
);
|
|
504
551
|
}
|
|
505
|
-
const client =
|
|
552
|
+
const client = getClient();
|
|
506
553
|
const body = { duration: args.duration };
|
|
507
554
|
if (args.title) body.title = args.title;
|
|
508
555
|
if (args.notes) body.notes = args.notes;
|
|
@@ -516,38 +563,168 @@ function createLibrenmsSetMaintenanceTool(getClient2) {
|
|
|
516
563
|
};
|
|
517
564
|
}
|
|
518
565
|
|
|
566
|
+
// src/tools/librenms_get_port.ts
|
|
567
|
+
import { Type as Type11 } from "@sinclair/typebox";
|
|
568
|
+
var Schema11 = Type11.Object(
|
|
569
|
+
{
|
|
570
|
+
port_id: Type11.Integer({
|
|
571
|
+
minimum: 1,
|
|
572
|
+
description: "LibreNMS internal port id (from librenms_list_ports response rows)."
|
|
573
|
+
})
|
|
574
|
+
},
|
|
575
|
+
{ additionalProperties: false }
|
|
576
|
+
);
|
|
577
|
+
function createLibrenmsGetPortTool(getClient) {
|
|
578
|
+
return {
|
|
579
|
+
name: "librenms_get_port",
|
|
580
|
+
label: "librenms: get port",
|
|
581
|
+
description: "Single-port detail via GET /api/v0/ports/{port_id}. Returns full column set (admin/oper state, traffic + error counters, ifAlias, etc.).",
|
|
582
|
+
parameters: Schema11,
|
|
583
|
+
execute: async (_id, raw) => {
|
|
584
|
+
const args = raw;
|
|
585
|
+
const portId = safeInt(args.port_id, "port_id");
|
|
586
|
+
const client = getClient();
|
|
587
|
+
const r = await client.get(`/ports/${encodeURIComponent(portId)}`);
|
|
588
|
+
return jsonToolResult({ port: r.port?.[0] ?? null });
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// src/tools/librenms_event_log.ts
|
|
594
|
+
import { Type as Type12 } from "@sinclair/typebox";
|
|
595
|
+
var Schema12 = Type12.Object(
|
|
596
|
+
{
|
|
597
|
+
device_id: Type12.Optional(
|
|
598
|
+
Type12.Integer({
|
|
599
|
+
minimum: 1,
|
|
600
|
+
description: "Optional device id to scope the event log."
|
|
601
|
+
})
|
|
602
|
+
),
|
|
603
|
+
limit: Type12.Optional(
|
|
604
|
+
Type12.Integer({
|
|
605
|
+
minimum: 1,
|
|
606
|
+
description: "Max number of log entries. Default 25."
|
|
607
|
+
})
|
|
608
|
+
)
|
|
609
|
+
},
|
|
610
|
+
{ additionalProperties: false }
|
|
611
|
+
);
|
|
612
|
+
function createLibrenmsEventLogTool(getClient) {
|
|
613
|
+
return {
|
|
614
|
+
name: "librenms_event_log",
|
|
615
|
+
label: "librenms: event log",
|
|
616
|
+
description: "Recent device events via GET /api/v0/logs/eventlog (optionally scoped to a device_id). Covers device up/down, syslog ingestion, etc. Distinct from alertlog.",
|
|
617
|
+
parameters: Schema12,
|
|
618
|
+
execute: async (_id, raw) => {
|
|
619
|
+
const args = raw ?? {};
|
|
620
|
+
const limit = safeInt(args.limit ?? 25, "limit");
|
|
621
|
+
const path = args.device_id !== void 0 ? `/logs/eventlog/${encodeURIComponent(
|
|
622
|
+
safeInt(args.device_id, "device_id")
|
|
623
|
+
)}?limit=${encodeURIComponent(limit)}` : `/logs/eventlog?limit=${encodeURIComponent(limit)}`;
|
|
624
|
+
const client = getClient();
|
|
625
|
+
const r = await client.get(path);
|
|
626
|
+
return jsonToolResult({
|
|
627
|
+
count: r.logs?.length ?? 0,
|
|
628
|
+
logs: r.logs ?? []
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// src/tools/librenms_unmute_alert.ts
|
|
635
|
+
import { Type as Type13 } from "@sinclair/typebox";
|
|
636
|
+
var Schema13 = Type13.Object(
|
|
637
|
+
{
|
|
638
|
+
id: Type13.Integer({ minimum: 1, description: "Alert id to unmute." }),
|
|
639
|
+
note: Type13.Optional(
|
|
640
|
+
Type13.String({
|
|
641
|
+
description: "Optional note appended to the alert audit trail (LibreNMS prefixes it with the API user + timestamp)."
|
|
642
|
+
})
|
|
643
|
+
),
|
|
644
|
+
confirm: Type13.Boolean({
|
|
645
|
+
description: "Must be true to write. Tier-2 safe-write gate."
|
|
646
|
+
})
|
|
647
|
+
},
|
|
648
|
+
{ additionalProperties: false }
|
|
649
|
+
);
|
|
650
|
+
var NAME3 = "librenms_unmute_alert";
|
|
651
|
+
function createLibrenmsUnmuteAlertTool(getClient) {
|
|
652
|
+
return {
|
|
653
|
+
name: NAME3,
|
|
654
|
+
label: "librenms: unmute alert",
|
|
655
|
+
description: "Unmute an alert by id via PUT /api/v0/alerts/unmute/{id} (companion to librenms_ack_alert). Tier-2 write; requires confirm:true.",
|
|
656
|
+
parameters: Schema13,
|
|
657
|
+
execute: async (_id, raw) => {
|
|
658
|
+
assertConfirmedWrite(raw, NAME3);
|
|
659
|
+
const args = raw;
|
|
660
|
+
const id = safeInt(args.id, "id");
|
|
661
|
+
const client = getClient();
|
|
662
|
+
const body = {};
|
|
663
|
+
if (args.note !== void 0) body.note = args.note;
|
|
664
|
+
const r = await client.put(`/alerts/unmute/${encodeURIComponent(id)}`, body);
|
|
665
|
+
return jsonToolResult({ alert_id: id, unmuted: true, response: r });
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
|
|
519
670
|
// mcp-server.ts
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
server
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
671
|
+
function createServer() {
|
|
672
|
+
const cfg = resolveConfig(process.env);
|
|
673
|
+
registerSecret(cfg.token);
|
|
674
|
+
const getClient = () => new LibreNmsClient(cfg);
|
|
675
|
+
const tools = [
|
|
676
|
+
createLibrenmsStatusTool(getClient),
|
|
677
|
+
createLibrenmsListDevicesTool(getClient),
|
|
678
|
+
createLibrenmsGetDeviceTool(getClient),
|
|
679
|
+
createLibrenmsListPortsTool(getClient),
|
|
680
|
+
createLibrenmsPortHealthTool(getClient),
|
|
681
|
+
createLibrenmsListAlertsTool(getClient),
|
|
682
|
+
createLibrenmsGetAlertTool(getClient),
|
|
683
|
+
createLibrenmsAlertHistoryTool(getClient),
|
|
684
|
+
createLibrenmsAckAlertTool(getClient),
|
|
685
|
+
createLibrenmsSetMaintenanceTool(getClient),
|
|
686
|
+
createLibrenmsGetPortTool(getClient),
|
|
687
|
+
createLibrenmsEventLogTool(getClient),
|
|
688
|
+
createLibrenmsUnmuteAlertTool(getClient)
|
|
689
|
+
];
|
|
690
|
+
const toolMap = new Map(tools.map((t) => [t.name, t]));
|
|
691
|
+
const server = new Server({ name: "librenms-mcp", version: "0.2.0" }, { capabilities: { tools: {} } });
|
|
692
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
693
|
+
tools: tools.map((t) => ({ name: t.name, description: t.description, inputSchema: t.parameters }))
|
|
694
|
+
}));
|
|
695
|
+
server.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
696
|
+
const t = toolMap.get(req.params.name);
|
|
697
|
+
if (!t) {
|
|
698
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: `unknown tool: ${req.params.name}` }) }], isError: true };
|
|
699
|
+
}
|
|
700
|
+
try {
|
|
701
|
+
const args = req.params.arguments ?? {};
|
|
702
|
+
validateToolArgs(t.parameters, t.name, args);
|
|
703
|
+
return await t.execute(req.params.name, args);
|
|
704
|
+
} catch (e) {
|
|
705
|
+
const msg = redact(e.message);
|
|
706
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: msg }) }], isError: true };
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
return server;
|
|
710
|
+
}
|
|
711
|
+
async function serve() {
|
|
712
|
+
const server = createServer();
|
|
713
|
+
const transport = new StdioServerTransport();
|
|
714
|
+
const __send = transport.send.bind(transport);
|
|
715
|
+
transport.send = (message) => {
|
|
716
|
+
const tools = message?.result?.tools;
|
|
717
|
+
if (Array.isArray(tools)) {
|
|
718
|
+
for (const t of tools) {
|
|
719
|
+
if (t?.inputSchema) delete t.inputSchema.$schema;
|
|
720
|
+
if (t?.outputSchema) delete t.outputSchema.$schema;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return __send(message);
|
|
724
|
+
};
|
|
725
|
+
await server.connect(transport);
|
|
726
|
+
}
|
|
727
|
+
export {
|
|
728
|
+
createServer,
|
|
729
|
+
serve
|
|
730
|
+
};
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"id": "librenms",
|
|
4
4
|
"name": "LibreNMS",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.2.0",
|
|
6
6
|
"description": "LibreNMS read + safe-write tools: devices, ports, alerts, ack, maintenance.",
|
|
7
7
|
"entry": "./dist/index.js",
|
|
8
8
|
"activation": { "onStartup": true },
|
package/package.json
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solomonneas/librenms-mcp",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "librenmsctrl operator CLI for LibreNMS with an MCP-compatible adapter",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"librenms",
|
|
7
|
+
"librenmsctrl",
|
|
8
|
+
"network-monitoring",
|
|
9
|
+
"observability",
|
|
10
|
+
"mcp",
|
|
11
|
+
"model-context-protocol"
|
|
12
|
+
],
|
|
5
13
|
"type": "module",
|
|
6
14
|
"openclaw": {
|
|
7
|
-
"extensions": [
|
|
15
|
+
"extensions": [
|
|
16
|
+
"./index.ts"
|
|
17
|
+
],
|
|
8
18
|
"compat": {
|
|
9
19
|
"pluginApi": ">=2026.3.24-beta.2",
|
|
10
20
|
"minGatewayVersion": "2026.3.24-beta.2"
|
|
@@ -14,32 +24,60 @@
|
|
|
14
24
|
"pluginSdkVersion": "2026.5.17"
|
|
15
25
|
}
|
|
16
26
|
},
|
|
17
|
-
"bin": {
|
|
27
|
+
"bin": {
|
|
28
|
+
"librenmsctrl": "dist/cli.js",
|
|
29
|
+
"librenmsctl": "dist/cli.js",
|
|
30
|
+
"librenms-mcp": "dist/mcp-bin.js"
|
|
31
|
+
},
|
|
18
32
|
"scripts": {
|
|
19
33
|
"typecheck": "tsc --noEmit",
|
|
20
34
|
"build": "tsup",
|
|
21
|
-
"start": "node dist/
|
|
22
|
-
"dev": "tsx mcp-
|
|
35
|
+
"start": "node dist/cli.js mcp",
|
|
36
|
+
"dev": "tsx mcp-bin.ts",
|
|
23
37
|
"test": "vitest run",
|
|
24
38
|
"test:watch": "vitest",
|
|
25
39
|
"prepublishOnly": "npm run typecheck && npm test && npm run build"
|
|
26
40
|
},
|
|
27
|
-
"files": [
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"openclaw.plugin.json",
|
|
44
|
+
"README.md",
|
|
45
|
+
"LICENSE"
|
|
46
|
+
],
|
|
28
47
|
"dependencies": {
|
|
29
48
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
30
|
-
"@sinclair/typebox": "^0.34.0"
|
|
49
|
+
"@sinclair/typebox": "^0.34.0",
|
|
50
|
+
"undici": "^7.28.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"openclaw": "^2026.4.22"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"openclaw": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
31
59
|
},
|
|
32
|
-
"peerDependencies": { "openclaw": "^2026.4.22" },
|
|
33
|
-
"peerDependenciesMeta": { "openclaw": { "optional": true } },
|
|
34
60
|
"devDependencies": {
|
|
35
61
|
"@types/node": "^25.6.2",
|
|
36
|
-
"openclaw": "^2026.
|
|
62
|
+
"openclaw": "^2026.6.11",
|
|
37
63
|
"tsup": "^8.4.0",
|
|
38
64
|
"tsx": "^4.19.0",
|
|
39
65
|
"typescript": "^6.0.3",
|
|
40
66
|
"vitest": "^4.1.5"
|
|
41
67
|
},
|
|
42
|
-
"engines": {
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=20"
|
|
70
|
+
},
|
|
43
71
|
"license": "MIT",
|
|
44
|
-
"repository": {
|
|
72
|
+
"repository": {
|
|
73
|
+
"type": "git",
|
|
74
|
+
"url": "git+https://github.com/lidless-labs/librenmsctrl.git"
|
|
75
|
+
},
|
|
76
|
+
"packageManager": "npm@10.9.7",
|
|
77
|
+
"publishConfig": {
|
|
78
|
+
"access": "public"
|
|
79
|
+
},
|
|
80
|
+
"overrides": {
|
|
81
|
+
"esbuild": "0.28.1"
|
|
82
|
+
}
|
|
45
83
|
}
|