@usex/mikrotik-mcp 6.14.0 → 6.15.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/dist/cli.js +1389 -445
- package/dist/index.d.ts +106 -101
- package/dist/index.js +1 -1
- package/dist/shared/{cli-4xzq2n6j.js → cli-4aqtcr9k.js} +1 -1
- package/dist/shared/{cli-1vn2bbpy.js → cli-4n039739.js} +65 -22
- package/dist/shared/{cli-w6km895r.js → cli-57nggfz3.js} +1 -1
- package/dist/shared/{cli-rcx7e9h4.js → cli-5hgbedxa.js} +4 -2
- package/dist/shared/{cli-r1ng5cjy.js → cli-9x2ne7hp.js} +1 -1
- package/dist/shared/cli-b7rbwm6j.js +109 -0
- package/dist/shared/{library-1nhmbsv0.js → library-1sy0ph9r.js} +1 -1
- package/dist/shared/{library-1swafsvq.js → library-28w0j1ny.js} +1 -1
- package/dist/shared/{library-2wd7mt3g.js → library-7qr2sc9x.js} +62 -19
- package/dist/shared/{library-0qn06vwr.js → library-nt9fygza.js} +1 -1
- package/dist/shared/{library-jpmbkkz7.js → library-twpgma2r.js} +1 -1
- package/dist/ui/observability.html +293 -90
- package/package.json +5 -1
- package/schemas/config.schema.json +16 -2
- package/schemas/devtools-manifest.json +1 -1
- package/schemas/tool-catalog.json +1 -1
- package/scripts/service.ts +240 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usex/mikrotik-mcp",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.15.0",
|
|
4
4
|
"description": "MCP server for MikroTik RouterOS — 780+ tools over SSH for firewall, NAT, routing, DHCP, DNS, WireGuard, wireless, QoS and more.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -136,16 +136,20 @@
|
|
|
136
136
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
137
137
|
"@vitest/coverage-v8": "5.1.0",
|
|
138
138
|
"@vitest/ui": "5.1.0",
|
|
139
|
+
"@xterm/addon-fit": "0.11.0",
|
|
140
|
+
"@xterm/xterm": "6.0.0",
|
|
139
141
|
"bunup": "^0.16.32",
|
|
140
142
|
"class-variance-authority": "^0.7.1",
|
|
141
143
|
"clsx": "^2.1.1",
|
|
142
144
|
"date-fns": "^4.4.0",
|
|
143
145
|
"devframe": "1.3.5",
|
|
146
|
+
"dockview-react": "8.9.0",
|
|
144
147
|
"gsap": "^3.15.1",
|
|
145
148
|
"happy-dom": "^21.0.4",
|
|
146
149
|
"lenis": "^1.3.27",
|
|
147
150
|
"license-checker": "^25.0.1",
|
|
148
151
|
"lucide-react": "^1.73.0",
|
|
152
|
+
"mcp-remote": "0.14.3",
|
|
149
153
|
"motion": "^14.14.0",
|
|
150
154
|
"qrcode-generator": "^2.0.4",
|
|
151
155
|
"radix-ui": "^1.8.1",
|
|
@@ -261,6 +261,7 @@
|
|
|
261
261
|
"allowedHosts": "",
|
|
262
262
|
"allowedOrigins": "",
|
|
263
263
|
"corsOrigins": "",
|
|
264
|
+
"sessionIdleTimeout": 86400000,
|
|
264
265
|
"toolPageSize": 0,
|
|
265
266
|
"toolSurface": "full",
|
|
266
267
|
"coreTools": "",
|
|
@@ -296,6 +297,12 @@
|
|
|
296
297
|
"default": "",
|
|
297
298
|
"type": "string"
|
|
298
299
|
},
|
|
300
|
+
"sessionIdleTimeout": {
|
|
301
|
+
"default": 86400000,
|
|
302
|
+
"type": "integer",
|
|
303
|
+
"exclusiveMinimum": 0,
|
|
304
|
+
"maximum": 9007199254740991
|
|
305
|
+
},
|
|
299
306
|
"toolPageSize": {
|
|
300
307
|
"default": 0,
|
|
301
308
|
"type": "integer",
|
|
@@ -328,6 +335,7 @@
|
|
|
328
335
|
"allowedHosts",
|
|
329
336
|
"allowedOrigins",
|
|
330
337
|
"corsOrigins",
|
|
338
|
+
"sessionIdleTimeout",
|
|
331
339
|
"toolPageSize",
|
|
332
340
|
"toolSurface",
|
|
333
341
|
"coreTools",
|
|
@@ -381,7 +389,8 @@
|
|
|
381
389
|
"captureBody": true,
|
|
382
390
|
"redactInput": false,
|
|
383
391
|
"maxBodyBytes": 16384,
|
|
384
|
-
"feedLimit": 200
|
|
392
|
+
"feedLimit": 200,
|
|
393
|
+
"terminal": true
|
|
385
394
|
},
|
|
386
395
|
"type": "object",
|
|
387
396
|
"properties": {
|
|
@@ -431,6 +440,10 @@
|
|
|
431
440
|
"type": "integer",
|
|
432
441
|
"exclusiveMinimum": 0,
|
|
433
442
|
"maximum": 10000
|
|
443
|
+
},
|
|
444
|
+
"terminal": {
|
|
445
|
+
"default": true,
|
|
446
|
+
"type": "boolean"
|
|
434
447
|
}
|
|
435
448
|
},
|
|
436
449
|
"required": [
|
|
@@ -442,7 +455,8 @@
|
|
|
442
455
|
"captureBody",
|
|
443
456
|
"redactInput",
|
|
444
457
|
"maxBodyBytes",
|
|
445
|
-
"feedLimit"
|
|
458
|
+
"feedLimit",
|
|
459
|
+
"terminal"
|
|
446
460
|
],
|
|
447
461
|
"additionalProperties": false
|
|
448
462
|
},
|
package/scripts/service.ts
CHANGED
|
@@ -376,13 +376,41 @@ export interface ServiceReport {
|
|
|
376
376
|
dashboard: string;
|
|
377
377
|
dashboardUp: boolean;
|
|
378
378
|
config: string;
|
|
379
|
-
|
|
379
|
+
/** Configured routers. Empty list = none configured; undefined = config unreadable. */
|
|
380
|
+
devices?: DeviceRow[];
|
|
381
|
+
/** True when `devices` carries live health from the running server. */
|
|
382
|
+
devicesLive: boolean;
|
|
380
383
|
data: string;
|
|
381
384
|
logs: string;
|
|
382
385
|
commands: string;
|
|
383
386
|
bun: string;
|
|
384
387
|
}
|
|
385
388
|
|
|
389
|
+
/** One configured router, with the health the running server last measured. */
|
|
390
|
+
export interface DeviceRow {
|
|
391
|
+
name: string;
|
|
392
|
+
isDefault: boolean;
|
|
393
|
+
disabled: boolean;
|
|
394
|
+
/** true = reachable, false = unreachable, null = not probed (or no live data). */
|
|
395
|
+
reachable: boolean | null;
|
|
396
|
+
version?: string;
|
|
397
|
+
latencyMs?: number;
|
|
398
|
+
cpuLoad?: number;
|
|
399
|
+
memUsedPct?: number;
|
|
400
|
+
uptime?: string;
|
|
401
|
+
error?: string;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** Keep text from a config file or a router on one line of the terminal. */
|
|
405
|
+
function oneLine(text: unknown, max = 60): string {
|
|
406
|
+
const flat = [...String(text ?? "")]
|
|
407
|
+
.map((char) => (char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127 ? " " : char))
|
|
408
|
+
.join("")
|
|
409
|
+
.replace(/ {2,}/g, " ")
|
|
410
|
+
.trim();
|
|
411
|
+
return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
|
|
412
|
+
}
|
|
413
|
+
|
|
386
414
|
const SUPERVISOR: Record<Platform, string> = {
|
|
387
415
|
darwin: "launchd LaunchAgent · starts at login · restarts if it stops",
|
|
388
416
|
linux: "systemd user unit · restarts after exit",
|
|
@@ -428,14 +456,59 @@ async function inspect(state: ServiceState): Promise<ServiceReport> {
|
|
|
428
456
|
"LaunchAgent StandardErrorPath / StandardOutPath"
|
|
429
457
|
);
|
|
430
458
|
};
|
|
431
|
-
const devices = async (): Promise<{
|
|
432
|
-
const
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
)
|
|
438
|
-
|
|
459
|
+
const devices = async (): Promise<{ rows: DeviceRow[]; live: boolean }> => {
|
|
460
|
+
const config = JSON.parse((await optionalFile(state.config)) ?? "{}") as {
|
|
461
|
+
devices?: Record<string, { disabled?: boolean }>;
|
|
462
|
+
defaultDevice?: string;
|
|
463
|
+
dashboard?: { token?: string };
|
|
464
|
+
};
|
|
465
|
+
const configured: DeviceRow[] = Object.entries(config.devices ?? {}).map(([name, device]) => ({
|
|
466
|
+
name: oneLine(name, 40),
|
|
467
|
+
isDefault: name === config.defaultDevice,
|
|
468
|
+
disabled: device?.disabled === true,
|
|
469
|
+
reachable: null,
|
|
470
|
+
}));
|
|
471
|
+
// Live health comes from the running server's dashboard API — the same
|
|
472
|
+
// numbers the dashboard shows, with no extra connection to any router.
|
|
473
|
+
try {
|
|
474
|
+
const flag = state.args.indexOf("--dashboard-token");
|
|
475
|
+
const token = config.dashboard?.token ?? (flag >= 0 ? state.args[flag + 1] : undefined);
|
|
476
|
+
const response = await fetch(`${dashboard}/api/devices`, {
|
|
477
|
+
headers: token ? { authorization: `Bearer ${token}` } : {},
|
|
478
|
+
signal: AbortSignal.timeout(2500),
|
|
479
|
+
});
|
|
480
|
+
if (!response.ok) return { rows: configured, live: false };
|
|
481
|
+
const body = (await response.json()) as {
|
|
482
|
+
devices?: {
|
|
483
|
+
name?: unknown;
|
|
484
|
+
isDefault?: unknown;
|
|
485
|
+
disabled?: unknown;
|
|
486
|
+
status?: Record<string, unknown> | null;
|
|
487
|
+
}[];
|
|
488
|
+
};
|
|
489
|
+
if (!Array.isArray(body.devices)) return { rows: configured, live: false };
|
|
490
|
+
const number = (value: unknown): number | undefined =>
|
|
491
|
+
typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
492
|
+
const text = (value: unknown): string | undefined =>
|
|
493
|
+
typeof value === "string" && value ? oneLine(value) : undefined;
|
|
494
|
+
return {
|
|
495
|
+
live: true,
|
|
496
|
+
rows: body.devices.map((device) => ({
|
|
497
|
+
name: oneLine(device.name, 40),
|
|
498
|
+
isDefault: device.isDefault === true,
|
|
499
|
+
disabled: device.disabled === true,
|
|
500
|
+
reachable: typeof device.status?.reachable === "boolean" ? device.status.reachable : null,
|
|
501
|
+
version: text(device.status?.version),
|
|
502
|
+
latencyMs: number(device.status?.latencyMs),
|
|
503
|
+
cpuLoad: number(device.status?.cpuLoad),
|
|
504
|
+
memUsedPct: number(device.status?.memUsedPct),
|
|
505
|
+
uptime: text(device.status?.uptime),
|
|
506
|
+
error: text(device.status?.error),
|
|
507
|
+
})),
|
|
508
|
+
};
|
|
509
|
+
} catch {
|
|
510
|
+
return { rows: configured, live: false };
|
|
511
|
+
}
|
|
439
512
|
};
|
|
440
513
|
const latest = async (): Promise<string | undefined> => {
|
|
441
514
|
const response = await fetch(
|
|
@@ -483,7 +556,8 @@ async function inspect(state: ServiceState): Promise<ServiceReport> {
|
|
|
483
556
|
dashboard,
|
|
484
557
|
dashboardUp: dashboardUp === true,
|
|
485
558
|
config: state.config,
|
|
486
|
-
devices: deviceCount,
|
|
559
|
+
devices: deviceCount?.rows,
|
|
560
|
+
devicesLive: deviceCount?.live === true,
|
|
487
561
|
data: state.cwd,
|
|
488
562
|
logs: logPath ?? "",
|
|
489
563
|
commands: join(state.installRoot, "bin"),
|
|
@@ -555,11 +629,56 @@ export function renderStatus(report: ServiceReport, on: boolean): string {
|
|
|
555
629
|
];
|
|
556
630
|
if (report.tools !== undefined)
|
|
557
631
|
service.push(["Tools", `${report.tools} ${c.dim("in tools/list")}`]);
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
:
|
|
632
|
+
const fleet = report.devices ?? [];
|
|
633
|
+
const count = {
|
|
634
|
+
disabled: fleet.filter((d) => d.disabled).length,
|
|
635
|
+
online: fleet.filter((d) => !d.disabled && d.reachable === true).length,
|
|
636
|
+
offline: fleet.filter((d) => !d.disabled && d.reachable === false).length,
|
|
637
|
+
};
|
|
638
|
+
const pending = fleet.length - count.disabled - count.online - count.offline;
|
|
639
|
+
const summary = [`${c.bold(String(fleet.length))} configured`];
|
|
640
|
+
if (report.devicesLive) {
|
|
641
|
+
summary.push(`${c.ok(String(count.online))} online`);
|
|
642
|
+
if (count.offline) summary.push(`${c.bad(String(count.offline))} offline`);
|
|
643
|
+
if (pending) summary.push(`${pending} not checked yet`);
|
|
644
|
+
} else summary.push(`${fleet.length - count.disabled} enabled`);
|
|
645
|
+
if (count.disabled) summary.push(`${count.disabled} disabled`);
|
|
646
|
+
const MAX_DEVICE_ROWS = 12;
|
|
647
|
+
const nameWidth = Math.max(0, ...fleet.slice(0, MAX_DEVICE_ROWS).map((d) => d.name.length));
|
|
648
|
+
const deviceLine = (d: DeviceRow): string => {
|
|
649
|
+
const name = `${c.bold(d.name.padEnd(nameWidth))} ${d.isDefault ? c.violet("★") : " "}`;
|
|
650
|
+
if (d.disabled) return `${c.dim("◌")} ${name} ${c.dim("disabled")}`;
|
|
651
|
+
if (d.reachable === true) {
|
|
652
|
+
const facts = [
|
|
653
|
+
d.version ? `RouterOS ${d.version.replace(/\s*\(.*\)$/, "")}` : undefined,
|
|
654
|
+
d.latencyMs !== undefined ? `${Math.round(d.latencyMs)} ms` : undefined,
|
|
655
|
+
d.cpuLoad !== undefined ? `CPU ${Math.round(d.cpuLoad)}%` : undefined,
|
|
656
|
+
d.memUsedPct !== undefined ? `RAM ${Math.round(d.memUsedPct)}%` : undefined,
|
|
657
|
+
// Seconds are noise next to days and hours.
|
|
658
|
+
d.uptime ? `up ${d.uptime.replace(/(?<=[wdhm])\d+s$/, "")}` : undefined,
|
|
659
|
+
].filter(Boolean);
|
|
660
|
+
return `${c.ok("●")} ${name} ${c.ok("online ")} ${c.dim(facts.join(" · "))}`;
|
|
661
|
+
}
|
|
662
|
+
if (d.reachable === false)
|
|
663
|
+
return `${c.bad("○")} ${name} ${c.bad("offline")} ${c.dim(d.error ?? "no answer")}`;
|
|
664
|
+
return `${c.dim("·")} ${name} ${c.dim(report.devicesLive ? "not checked yet" : "state unknown")}`;
|
|
665
|
+
};
|
|
666
|
+
const devices: Rows = [["Summary", summary.join(c.dim(" · "))]];
|
|
667
|
+
if (!report.devices) devices[0] = ["Summary", c.dim("the config file could not be read")];
|
|
668
|
+
fleet
|
|
669
|
+
.slice(0, MAX_DEVICE_ROWS)
|
|
670
|
+
.forEach((d, i) => devices.push([i === 0 ? "Routers" : "", deviceLine(d)]));
|
|
671
|
+
if (fleet.length > MAX_DEVICE_ROWS)
|
|
672
|
+
devices.push(["", c.dim(`… and ${fleet.length - MAX_DEVICE_ROWS} more (see the dashboard)`)]);
|
|
673
|
+
if (report.devices && !report.devicesLive && fleet.length)
|
|
674
|
+
devices.push(["", c.dim("Live state needs the running service and its dashboard.")]);
|
|
675
|
+
if (count.offline)
|
|
676
|
+
advice.push(
|
|
677
|
+
`${c.warn("!")} ${count.offline} device${count.offline === 1 ? " is" : "s are"} offline: ${fleet
|
|
678
|
+
.filter((d) => !d.disabled && d.reachable === false)
|
|
679
|
+
.map((d) => d.name)
|
|
680
|
+
.join(", ")}`,
|
|
681
|
+
);
|
|
563
682
|
|
|
564
683
|
const urlWidth = Math.max(report.mcp.length, report.dashboard.length);
|
|
565
684
|
const endpoints: Rows = [
|
|
@@ -567,7 +686,7 @@ export function renderStatus(report: ServiceReport, on: boolean): string {
|
|
|
567
686
|
["Dashboard", `${c.sky(report.dashboard.padEnd(urlWidth))} ${mark(report.dashboardUp)}`],
|
|
568
687
|
];
|
|
569
688
|
const files: Rows = [
|
|
570
|
-
["Config",
|
|
689
|
+
["Config", tidy(report.config)],
|
|
571
690
|
["Data", tidy(report.data)],
|
|
572
691
|
["Logs", tidy(report.logs)],
|
|
573
692
|
["Commands", tidy(report.commands)],
|
|
@@ -577,6 +696,7 @@ export function renderStatus(report: ServiceReport, on: boolean): string {
|
|
|
577
696
|
const min = Math.max(
|
|
578
697
|
panelWidth("Service", service),
|
|
579
698
|
panelWidth("Endpoints", endpoints),
|
|
699
|
+
panelWidth("Devices", devices),
|
|
580
700
|
panelWidth("Files", files),
|
|
581
701
|
);
|
|
582
702
|
|
|
@@ -584,6 +704,7 @@ export function renderStatus(report: ServiceReport, on: boolean): string {
|
|
|
584
704
|
banner("status", on),
|
|
585
705
|
panel("Service", service, on, min),
|
|
586
706
|
panel("Endpoints", endpoints, on, min),
|
|
707
|
+
panel("Devices", devices, on, min),
|
|
587
708
|
panel("Files", files, on, min),
|
|
588
709
|
advice.length
|
|
589
710
|
? advice.map((line) => ` ${line}`).join("\n")
|
|
@@ -814,7 +935,8 @@ export async function installCommands(
|
|
|
814
935
|
}
|
|
815
936
|
|
|
816
937
|
/** Verify the CLI and the live MCP version after service activation. */
|
|
817
|
-
|
|
938
|
+
/** Wait until the running server answers as the installed version; returns that version. */
|
|
939
|
+
async function waitReady(state: ServiceState): Promise<string> {
|
|
818
940
|
const version = await command([state.bun, state.cli, "--version"]);
|
|
819
941
|
await upgrade({
|
|
820
942
|
install: async () => {},
|
|
@@ -823,9 +945,30 @@ async function waitReady(state: ServiceState): Promise<void> {
|
|
|
823
945
|
ready: (v) => ready(`http://127.0.0.1:${state.port}/mcp`, v),
|
|
824
946
|
wait: () => sleep(1000),
|
|
825
947
|
});
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
948
|
+
return version;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
/** The `--help` screen. */
|
|
952
|
+
export function renderHelp(on: boolean): string {
|
|
953
|
+
const c = palette(on);
|
|
954
|
+
const row = (commandLine: string, what: string): string =>
|
|
955
|
+
` ${c.bold(commandLine.padEnd(46))}${c.dim(what)}`;
|
|
956
|
+
return [
|
|
957
|
+
banner("help", on),
|
|
958
|
+
"",
|
|
959
|
+
row("mikrotik-mcp-service install", "Install and start the service"),
|
|
960
|
+
row(" [--config devices.json]", "Use an existing config file"),
|
|
961
|
+
row(" [--mcp-port 8000] [--dashboard-port 9090]", "Choose the local ports"),
|
|
962
|
+
row("mikrotik-mcp-service status", "Service, versions, endpoints and devices"),
|
|
963
|
+
row("mikrotik-mcp-service restart", "Restart without updating"),
|
|
964
|
+
row("mikrotik-mcp-upgrade", "Install the latest version and restart"),
|
|
965
|
+
row("mikrotik-mcp-service uninstall", "Stop and remove automatic startup"),
|
|
966
|
+
"",
|
|
967
|
+
` ${c.dim("No config? Install creates a disabled example router; configure it in the dashboard.")}`,
|
|
968
|
+
` ${c.dim("Runs as your login user: macOS launchd, Linux systemd --user, Windows logon task.")}`,
|
|
969
|
+
` ${c.dim("Uninstall keeps your config, keys and history. Bun required. No sudo.")}`,
|
|
970
|
+
"",
|
|
971
|
+
].join("\n");
|
|
829
972
|
}
|
|
830
973
|
|
|
831
974
|
/** Parse a deliberately small CLI with strict options and explicit install-only flags. */
|
|
@@ -866,15 +1009,18 @@ export function serviceOptions(argv: string[]): {
|
|
|
866
1009
|
export async function main(argv = process.argv.slice(2)): Promise<void> {
|
|
867
1010
|
const options = serviceOptions(argv);
|
|
868
1011
|
if (options.action === "help") {
|
|
869
|
-
console.warn(
|
|
870
|
-
`MikroTik MCP shared service (Bun required)\n\n mikrotik-mcp-service install [--config devices.json]\n mikrotik-mcp-upgrade\n mikrotik-mcp-service restart | status | uninstall\n\nOptional install ports: --mcp-port 8000 --dashboard-port 9090\nNo config? Install creates a disabled example router; configure it in the dashboard.\nRuns as your login user: macOS launchd, Linux systemd --user, Windows logon task.\nUninstall keeps your config, keys and history. No sudo required.`,
|
|
871
|
-
);
|
|
1012
|
+
console.warn(renderHelp(useColor()));
|
|
872
1013
|
return;
|
|
873
1014
|
}
|
|
874
1015
|
if (!["darwin", "linux", "win32"].includes(process.platform))
|
|
875
1016
|
throw new Error("Supported platforms: Windows, macOS, Linux with systemd.");
|
|
876
1017
|
if (process.getuid?.() === 0) throw new Error("Run as your regular login user, without sudo.");
|
|
877
1018
|
const platform = process.platform as Platform;
|
|
1019
|
+
const on = useColor();
|
|
1020
|
+
const c = palette(on);
|
|
1021
|
+
const say = (line: string): void => console.warn(` ${line}`);
|
|
1022
|
+
const tidy = (path: string): string =>
|
|
1023
|
+
homedir() && path.startsWith(homedir()) ? `~${path.slice(homedir().length)}` : path;
|
|
878
1024
|
const directory = join(homedir(), ".mikrotik-mcp", "service");
|
|
879
1025
|
const metadata = join(directory, "service.json");
|
|
880
1026
|
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
@@ -893,6 +1039,8 @@ export async function main(argv = process.argv.slice(2)): Promise<void> {
|
|
|
893
1039
|
throw new Error("Incompatible service metadata; nothing changed.");
|
|
894
1040
|
if (!state && platform === "darwin") state = await adoptMac();
|
|
895
1041
|
if (options.action === "install") {
|
|
1042
|
+
console.warn(`${banner("install", on)}\n`);
|
|
1043
|
+
const fresh = !state;
|
|
896
1044
|
if (state) {
|
|
897
1045
|
if (
|
|
898
1046
|
(options.config && resolve(options.config) !== state.config) ||
|
|
@@ -1001,27 +1149,71 @@ export async function main(argv = process.argv.slice(2)): Promise<void> {
|
|
|
1001
1149
|
await save(metadata, JSON.stringify(state, null, 2));
|
|
1002
1150
|
}
|
|
1003
1151
|
await save(metadata, JSON.stringify(state, null, 2));
|
|
1004
|
-
|
|
1152
|
+
say(
|
|
1153
|
+
fresh
|
|
1154
|
+
? `${c.ok("✓")} Config ${tidy(state.config)}`
|
|
1155
|
+
: `${c.dim("•")} Already installed ${c.dim("— checking that it runs")}`,
|
|
1156
|
+
);
|
|
1157
|
+
await installCommands(directory, state.bun, true);
|
|
1158
|
+
const bin = join(state.installRoot, "bin");
|
|
1159
|
+
say(`${c.ok("✓")} Commands ${tidy(bin)}`);
|
|
1005
1160
|
await ensureStarted(state);
|
|
1006
|
-
|
|
1161
|
+
say(`${c.ok("✓")} Registered ${c.dim(SUPERVISOR[platform])}`);
|
|
1162
|
+
say(`${c.sky("◆")} Waiting ${c.dim("for the server to answer …")}`);
|
|
1163
|
+
const version = await waitReady(state);
|
|
1164
|
+
say(`${c.ok("✓")} Ready ${c.dim("the server answers as")} ${c.bold(version)}`);
|
|
1165
|
+
const mcp = `http://127.0.0.1:${state.port}/mcp`;
|
|
1166
|
+
const onPath = (process.env.PATH ?? "").split(platform === "win32" ? ";" : ":").includes(bin);
|
|
1167
|
+
console.warn(
|
|
1168
|
+
[
|
|
1169
|
+
"",
|
|
1170
|
+
panel(
|
|
1171
|
+
fresh ? "Service installed" : "Service running",
|
|
1172
|
+
[
|
|
1173
|
+
["Version", c.bold(version)],
|
|
1174
|
+
["MCP", c.sky(mcp)],
|
|
1175
|
+
["Dashboard", c.sky(`http://127.0.0.1:${state.dashboardPort}`)],
|
|
1176
|
+
["Config", tidy(state.config)],
|
|
1177
|
+
],
|
|
1178
|
+
on,
|
|
1179
|
+
),
|
|
1180
|
+
"",
|
|
1181
|
+
` ${c.dim("Add this URL to your MCP clients:")} ${mcp}`,
|
|
1182
|
+
// Only when it matters: the commands are not reachable from this shell.
|
|
1183
|
+
...(onPath
|
|
1184
|
+
? []
|
|
1185
|
+
: [
|
|
1186
|
+
` ${c.warn("!")} ${tidy(bin)} is not on your PATH. Add it to run the commands by name.`,
|
|
1187
|
+
]),
|
|
1188
|
+
` ${c.dim("Next: mikrotik-mcp-service status · mikrotik-mcp-upgrade")}`,
|
|
1189
|
+
"",
|
|
1190
|
+
].join("\n"),
|
|
1191
|
+
);
|
|
1007
1192
|
return;
|
|
1008
1193
|
}
|
|
1009
1194
|
if (!state)
|
|
1010
1195
|
throw new Error("Service is not installed. Run mikrotik-mcp-service install first.");
|
|
1011
1196
|
if (options.action === "uninstall") {
|
|
1197
|
+
console.warn(`${banner("uninstall", on)}\n`);
|
|
1012
1198
|
await control(state, "remove");
|
|
1013
1199
|
if (platform !== "win32") await unlink(nativeFile(platform));
|
|
1014
1200
|
if (platform === "linux") await command(["systemctl", "--user", "daemon-reload"]);
|
|
1015
1201
|
await unlink(metadata).catch((error) => {
|
|
1016
1202
|
if (error.code !== "ENOENT") throw error;
|
|
1017
1203
|
});
|
|
1204
|
+
say(`${c.ok("✓")} Stopped ${c.dim("and removed from automatic startup")}`);
|
|
1018
1205
|
console.warn(
|
|
1019
|
-
|
|
1206
|
+
`\n${panel(
|
|
1207
|
+
"Service removed · kept on this machine",
|
|
1208
|
+
[
|
|
1209
|
+
["Config", tidy(state.config)],
|
|
1210
|
+
["Data", `${tidy(state.cwd)} ${c.dim("history, snapshots, SSH keys")}`],
|
|
1211
|
+
["Package", `${tidy(dirname(dirname(state.cli)))}`],
|
|
1212
|
+
],
|
|
1213
|
+
on,
|
|
1214
|
+
)}\n\n ${c.dim("Enable it again: mikrotik-mcp-service install")}\n`,
|
|
1020
1215
|
);
|
|
1021
1216
|
} else if (options.action === "upgrade") {
|
|
1022
|
-
const on = useColor();
|
|
1023
|
-
const c = palette(on);
|
|
1024
|
-
const say = (line: string): void => console.warn(` ${line}`);
|
|
1025
1217
|
const mcp = `http://127.0.0.1:${state.port}/mcp`;
|
|
1026
1218
|
console.warn(`${banner("upgrade", on)}\n`);
|
|
1027
1219
|
const before = (await probe(mcp)).version;
|
|
@@ -1099,10 +1291,27 @@ export async function main(argv = process.argv.slice(2)): Promise<void> {
|
|
|
1099
1291
|
throw error;
|
|
1100
1292
|
}
|
|
1101
1293
|
} else if (options.action === "status") {
|
|
1102
|
-
console.warn(renderStatus(await inspect(state),
|
|
1294
|
+
console.warn(renderStatus(await inspect(state), on));
|
|
1103
1295
|
} else {
|
|
1296
|
+
console.warn(`${banner("restart", on)}\n`);
|
|
1297
|
+
const started = Date.now();
|
|
1104
1298
|
await control(state, "restart");
|
|
1105
|
-
|
|
1299
|
+
say(`${c.ok("✓")} Restarted ${c.dim(SUPERVISOR[platform].split(" · ")[0])}`);
|
|
1300
|
+
say(`${c.sky("◆")} Waiting ${c.dim("for the server to answer …")}`);
|
|
1301
|
+
const version = await waitReady(state);
|
|
1302
|
+
say(`${c.ok("✓")} Ready ${c.dim("the server answers as")} ${c.bold(version)}`);
|
|
1303
|
+
console.warn(
|
|
1304
|
+
`\n${panel(
|
|
1305
|
+
"Service restarted",
|
|
1306
|
+
[
|
|
1307
|
+
["Version", c.bold(version)],
|
|
1308
|
+
["Took", `${Math.max(1, Math.round((Date.now() - started) / 1000))}s`],
|
|
1309
|
+
["MCP", c.sky(`http://127.0.0.1:${state.port}/mcp`)],
|
|
1310
|
+
["Dashboard", c.sky(`http://127.0.0.1:${state.dashboardPort}`)],
|
|
1311
|
+
],
|
|
1312
|
+
on,
|
|
1313
|
+
)}\n\n ${c.dim("Reconnect your MCP clients if they do not reconnect by themselves.")}\n`,
|
|
1314
|
+
);
|
|
1106
1315
|
}
|
|
1107
1316
|
} finally {
|
|
1108
1317
|
await rmdir(lock);
|