@usex/mikrotik-mcp 6.14.0 → 6.16.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 +3366 -527
- package/dist/index.d.ts +115 -101
- package/dist/index.js +24 -10
- package/dist/shared/cli-8hn9vb7c.js +115 -0
- package/dist/shared/{cli-rcx7e9h4.js → cli-8j89p9xc.js} +4 -2
- package/dist/shared/cli-kb8zq3rx.js +9 -0
- package/dist/shared/{cli-w6km895r.js → cli-p7bt2fa3.js} +1 -1
- package/dist/shared/{cli-4xzq2n6j.js → cli-rmtax5nd.js} +1 -1
- package/dist/shared/{cli-r1ng5cjy.js → cli-rs00sr7q.js} +1 -1
- package/dist/shared/{cli-1vn2bbpy.js → cli-vf68spka.js} +5115 -1935
- package/dist/shared/cli-znnh8xtd.js +15 -0
- package/dist/shared/{library-1swafsvq.js → library-m6wrdeqa.js} +1 -1
- package/dist/shared/{library-0qn06vwr.js → library-nbtg49vh.js} +1 -1
- package/dist/shared/{library-1nhmbsv0.js → library-rc32xwsh.js} +1 -1
- package/dist/shared/{library-2wd7mt3g.js → library-rrzzp9qg.js} +4786 -1581
- package/dist/shared/{library-jpmbkkz7.js → library-s31n8vk4.js} +1 -1
- package/dist/ui/observability.html +296 -124
- package/package.json +25 -17
- package/schemas/README.md +5 -5
- package/schemas/config.schema.json +288 -6
- package/schemas/devtools-manifest.json +301 -5
- package/schemas/tool-catalog.json +1116 -42
- package/schemas/tools/add_alert_rule.json +1 -1
- package/schemas/tools/apply_config_template.json +56 -0
- package/schemas/tools/apply_wireless_to_wifi_migration.json +30 -0
- package/schemas/tools/deploy_container_stack.json +112 -0
- package/schemas/tools/design_zone_firewall.json +81 -0
- package/schemas/tools/discover_unmanaged_devices.json +49 -0
- package/schemas/tools/enrol_device.json +56 -0
- package/schemas/tools/expire_wireguard_users.json +19 -0
- package/schemas/tools/export_logs.json +2 -1
- package/schemas/tools/find_tools.json +1 -1
- package/schemas/tools/firmware_check.json +0 -5
- package/schemas/tools/firmware_post_upgrade.json +29 -0
- package/schemas/tools/firmware_repo_fetch.json +30 -0
- package/schemas/tools/firmware_repo_list.json +7 -0
- package/schemas/tools/firmware_stage_from_repo.json +19 -0
- package/schemas/tools/follow_ipv6_prefix.json +51 -0
- package/schemas/tools/generate_hotspot_vouchers.json +37 -1
- package/schemas/tools/get_container_logs.json +20 -0
- package/schemas/tools/get_logs.json +2 -1
- package/schemas/tools/get_logs_by_severity.json +2 -1
- package/schemas/tools/get_logs_by_topic.json +2 -1
- package/schemas/tools/get_security_logs.json +2 -1
- package/schemas/tools/get_system_events.json +2 -1
- package/schemas/tools/list_config_templates.json +7 -0
- package/schemas/tools/list_voucher_batches.json +7 -0
- package/schemas/tools/list_wireguard_users.json +12 -0
- package/schemas/tools/onboard_wireguard_user.json +17 -2
- package/schemas/tools/plan_wireless_to_wifi_migration.json +14 -0
- package/schemas/tools/protect_hotspot_login.json +32 -0
- package/schemas/tools/remove_config_template.json +14 -0
- package/schemas/tools/remove_threat_feed.json +1 -0
- package/schemas/tools/remove_voucher_batch.json +24 -0
- package/schemas/tools/remove_zone_firewall.json +14 -0
- package/schemas/tools/revoke_wireguard_user.json +1 -0
- package/schemas/tools/run_routeros_command.json +6 -1
- package/schemas/tools/save_config_template.json +20 -0
- package/schemas/tools/search_logs.json +2 -1
- package/schemas/tools/subscribe_threat_feed.json +1 -0
- package/schemas/tools/test_alert_channel.json +1 -1
- package/schemas/tools/unfollow_ipv6_prefix.json +18 -0
- package/schemas/tools/unprotect_hotspot_login.json +7 -0
- package/schemas/tools/update_alert_rule.json +1 -1
- package/schemas/tools/upgrade_container_image.json +29 -0
- package/schemas/tools/validate_routeros_command.json +13 -0
- package/scripts/service.ts +242 -34
package/scripts/service.ts
CHANGED
|
@@ -187,7 +187,7 @@ export function psQuote(value: string): string {
|
|
|
187
187
|
|
|
188
188
|
/** Render a per-user Linux unit with loopback listeners and restart supervision. */
|
|
189
189
|
export function linuxUnit(state: ServiceState): string {
|
|
190
|
-
return `[Unit]\nDescription=MikroTik MCP shared service\nAfter=network.target\n\n[Service]\nType=simple\nWorkingDirectory=${systemdQuote(state.cwd)}\nExecStart=${[state.bun, state.cli, ...state.args].map((arg) => systemdQuote(arg, true)).join(" ")}\nRestart=always\nRestartSec=5\nTimeoutStopSec=30\nUMask=0077\
|
|
190
|
+
return `[Unit]\nDescription=MikroTik MCP shared service\nAfter=network.target\n\n[Service]\nType=simple\nWorkingDirectory=${systemdQuote(state.cwd)}\nExecStart=${[state.bun, state.cli, ...state.args].map((arg) => systemdQuote(arg, true)).join(" ")}\nRestart=always\nRestartSec=5\nTimeoutStopSec=30\nUMask=0077\n\n[Install]\nWantedBy=default.target\n`;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
/** Create a password-free, current-user Windows logon task with bounded restart retries. */
|
|
@@ -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,18 +456,63 @@ 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(
|
|
442
|
-
`https://registry.npmjs.org/${PACKAGE.
|
|
515
|
+
`https://registry.npmjs.org/${PACKAGE.replaceAll("/", "%2f")}/latest`,
|
|
443
516
|
{
|
|
444
517
|
signal: AbortSignal.timeout(2500),
|
|
445
518
|
},
|
|
@@ -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")
|
|
@@ -693,7 +814,6 @@ async function register(state: ServiceState): Promise<void> {
|
|
|
693
814
|
ExitTimeOut: 30,
|
|
694
815
|
ThrottleInterval: 10,
|
|
695
816
|
Umask: 63,
|
|
696
|
-
EnvironmentVariables: { MIKROTIK_LOG_LEVEL: "warn" },
|
|
697
817
|
StandardOutPath: join(state.cwd, "service.stdout.log"),
|
|
698
818
|
StandardErrorPath: join(state.cwd, "service.stderr.log"),
|
|
699
819
|
}),
|
|
@@ -814,7 +934,8 @@ export async function installCommands(
|
|
|
814
934
|
}
|
|
815
935
|
|
|
816
936
|
/** Verify the CLI and the live MCP version after service activation. */
|
|
817
|
-
|
|
937
|
+
/** Wait until the running server answers as the installed version; returns that version. */
|
|
938
|
+
async function waitReady(state: ServiceState): Promise<string> {
|
|
818
939
|
const version = await command([state.bun, state.cli, "--version"]);
|
|
819
940
|
await upgrade({
|
|
820
941
|
install: async () => {},
|
|
@@ -823,9 +944,30 @@ async function waitReady(state: ServiceState): Promise<void> {
|
|
|
823
944
|
ready: (v) => ready(`http://127.0.0.1:${state.port}/mcp`, v),
|
|
824
945
|
wait: () => sleep(1000),
|
|
825
946
|
});
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
947
|
+
return version;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/** The `--help` screen. */
|
|
951
|
+
export function renderHelp(on: boolean): string {
|
|
952
|
+
const c = palette(on);
|
|
953
|
+
const row = (commandLine: string, what: string): string =>
|
|
954
|
+
` ${c.bold(commandLine.padEnd(46))}${c.dim(what)}`;
|
|
955
|
+
return [
|
|
956
|
+
banner("help", on),
|
|
957
|
+
"",
|
|
958
|
+
row("mikrotik-mcp-service install", "Install and start the service"),
|
|
959
|
+
row(" [--config devices.json]", "Use an existing config file"),
|
|
960
|
+
row(" [--mcp-port 8000] [--dashboard-port 9090]", "Choose the local ports"),
|
|
961
|
+
row("mikrotik-mcp-service status", "Service, versions, endpoints and devices"),
|
|
962
|
+
row("mikrotik-mcp-service restart", "Restart without updating"),
|
|
963
|
+
row("mikrotik-mcp-upgrade", "Install the latest version and restart"),
|
|
964
|
+
row("mikrotik-mcp-service uninstall", "Stop and remove automatic startup"),
|
|
965
|
+
"",
|
|
966
|
+
` ${c.dim("No config? Install creates a disabled example router; configure it in the dashboard.")}`,
|
|
967
|
+
` ${c.dim("Runs as your login user: macOS launchd, Linux systemd --user, Windows logon task.")}`,
|
|
968
|
+
` ${c.dim("Uninstall keeps your config, keys and history. Bun required. No sudo.")}`,
|
|
969
|
+
"",
|
|
970
|
+
].join("\n");
|
|
829
971
|
}
|
|
830
972
|
|
|
831
973
|
/** Parse a deliberately small CLI with strict options and explicit install-only flags. */
|
|
@@ -866,15 +1008,18 @@ export function serviceOptions(argv: string[]): {
|
|
|
866
1008
|
export async function main(argv = process.argv.slice(2)): Promise<void> {
|
|
867
1009
|
const options = serviceOptions(argv);
|
|
868
1010
|
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
|
-
);
|
|
1011
|
+
console.warn(renderHelp(useColor()));
|
|
872
1012
|
return;
|
|
873
1013
|
}
|
|
874
1014
|
if (!["darwin", "linux", "win32"].includes(process.platform))
|
|
875
1015
|
throw new Error("Supported platforms: Windows, macOS, Linux with systemd.");
|
|
876
1016
|
if (process.getuid?.() === 0) throw new Error("Run as your regular login user, without sudo.");
|
|
877
1017
|
const platform = process.platform as Platform;
|
|
1018
|
+
const on = useColor();
|
|
1019
|
+
const c = palette(on);
|
|
1020
|
+
const say = (line: string): void => console.warn(` ${line}`);
|
|
1021
|
+
const tidy = (path: string): string =>
|
|
1022
|
+
homedir() && path.startsWith(homedir()) ? `~${path.slice(homedir().length)}` : path;
|
|
878
1023
|
const directory = join(homedir(), ".mikrotik-mcp", "service");
|
|
879
1024
|
const metadata = join(directory, "service.json");
|
|
880
1025
|
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
@@ -893,6 +1038,8 @@ export async function main(argv = process.argv.slice(2)): Promise<void> {
|
|
|
893
1038
|
throw new Error("Incompatible service metadata; nothing changed.");
|
|
894
1039
|
if (!state && platform === "darwin") state = await adoptMac();
|
|
895
1040
|
if (options.action === "install") {
|
|
1041
|
+
console.warn(`${banner("install", on)}\n`);
|
|
1042
|
+
const fresh = !state;
|
|
896
1043
|
if (state) {
|
|
897
1044
|
if (
|
|
898
1045
|
(options.config && resolve(options.config) !== state.config) ||
|
|
@@ -1001,27 +1148,71 @@ export async function main(argv = process.argv.slice(2)): Promise<void> {
|
|
|
1001
1148
|
await save(metadata, JSON.stringify(state, null, 2));
|
|
1002
1149
|
}
|
|
1003
1150
|
await save(metadata, JSON.stringify(state, null, 2));
|
|
1004
|
-
|
|
1151
|
+
say(
|
|
1152
|
+
fresh
|
|
1153
|
+
? `${c.ok("✓")} Config ${tidy(state.config)}`
|
|
1154
|
+
: `${c.dim("•")} Already installed ${c.dim("— checking that it runs")}`,
|
|
1155
|
+
);
|
|
1156
|
+
await installCommands(directory, state.bun, true);
|
|
1157
|
+
const bin = join(state.installRoot, "bin");
|
|
1158
|
+
say(`${c.ok("✓")} Commands ${tidy(bin)}`);
|
|
1005
1159
|
await ensureStarted(state);
|
|
1006
|
-
|
|
1160
|
+
say(`${c.ok("✓")} Registered ${c.dim(SUPERVISOR[platform])}`);
|
|
1161
|
+
say(`${c.sky("◆")} Waiting ${c.dim("for the server to answer …")}`);
|
|
1162
|
+
const version = await waitReady(state);
|
|
1163
|
+
say(`${c.ok("✓")} Ready ${c.dim("the server answers as")} ${c.bold(version)}`);
|
|
1164
|
+
const mcp = `http://127.0.0.1:${state.port}/mcp`;
|
|
1165
|
+
const onPath = (process.env.PATH ?? "").split(platform === "win32" ? ";" : ":").includes(bin);
|
|
1166
|
+
console.warn(
|
|
1167
|
+
[
|
|
1168
|
+
"",
|
|
1169
|
+
panel(
|
|
1170
|
+
fresh ? "Service installed" : "Service running",
|
|
1171
|
+
[
|
|
1172
|
+
["Version", c.bold(version)],
|
|
1173
|
+
["MCP", c.sky(mcp)],
|
|
1174
|
+
["Dashboard", c.sky(`http://127.0.0.1:${state.dashboardPort}`)],
|
|
1175
|
+
["Config", tidy(state.config)],
|
|
1176
|
+
],
|
|
1177
|
+
on,
|
|
1178
|
+
),
|
|
1179
|
+
"",
|
|
1180
|
+
` ${c.dim("Add this URL to your MCP clients:")} ${mcp}`,
|
|
1181
|
+
// Only when it matters: the commands are not reachable from this shell.
|
|
1182
|
+
...(onPath
|
|
1183
|
+
? []
|
|
1184
|
+
: [
|
|
1185
|
+
` ${c.warn("!")} ${tidy(bin)} is not on your PATH. Add it to run the commands by name.`,
|
|
1186
|
+
]),
|
|
1187
|
+
` ${c.dim("Next: mikrotik-mcp-service status · mikrotik-mcp-upgrade")}`,
|
|
1188
|
+
"",
|
|
1189
|
+
].join("\n"),
|
|
1190
|
+
);
|
|
1007
1191
|
return;
|
|
1008
1192
|
}
|
|
1009
1193
|
if (!state)
|
|
1010
1194
|
throw new Error("Service is not installed. Run mikrotik-mcp-service install first.");
|
|
1011
1195
|
if (options.action === "uninstall") {
|
|
1196
|
+
console.warn(`${banner("uninstall", on)}\n`);
|
|
1012
1197
|
await control(state, "remove");
|
|
1013
1198
|
if (platform !== "win32") await unlink(nativeFile(platform));
|
|
1014
1199
|
if (platform === "linux") await command(["systemctl", "--user", "daemon-reload"]);
|
|
1015
1200
|
await unlink(metadata).catch((error) => {
|
|
1016
1201
|
if (error.code !== "ENOENT") throw error;
|
|
1017
1202
|
});
|
|
1203
|
+
say(`${c.ok("✓")} Stopped ${c.dim("and removed from automatic startup")}`);
|
|
1018
1204
|
console.warn(
|
|
1019
|
-
|
|
1205
|
+
`\n${panel(
|
|
1206
|
+
"Service removed · kept on this machine",
|
|
1207
|
+
[
|
|
1208
|
+
["Config", tidy(state.config)],
|
|
1209
|
+
["Data", `${tidy(state.cwd)} ${c.dim("history, snapshots, SSH keys")}`],
|
|
1210
|
+
["Package", `${tidy(dirname(dirname(state.cli)))}`],
|
|
1211
|
+
],
|
|
1212
|
+
on,
|
|
1213
|
+
)}\n\n ${c.dim("Enable it again: mikrotik-mcp-service install")}\n`,
|
|
1020
1214
|
);
|
|
1021
1215
|
} else if (options.action === "upgrade") {
|
|
1022
|
-
const on = useColor();
|
|
1023
|
-
const c = palette(on);
|
|
1024
|
-
const say = (line: string): void => console.warn(` ${line}`);
|
|
1025
1216
|
const mcp = `http://127.0.0.1:${state.port}/mcp`;
|
|
1026
1217
|
console.warn(`${banner("upgrade", on)}\n`);
|
|
1027
1218
|
const before = (await probe(mcp)).version;
|
|
@@ -1099,10 +1290,27 @@ export async function main(argv = process.argv.slice(2)): Promise<void> {
|
|
|
1099
1290
|
throw error;
|
|
1100
1291
|
}
|
|
1101
1292
|
} else if (options.action === "status") {
|
|
1102
|
-
console.warn(renderStatus(await inspect(state),
|
|
1293
|
+
console.warn(renderStatus(await inspect(state), on));
|
|
1103
1294
|
} else {
|
|
1295
|
+
console.warn(`${banner("restart", on)}\n`);
|
|
1296
|
+
const started = Date.now();
|
|
1104
1297
|
await control(state, "restart");
|
|
1105
|
-
|
|
1298
|
+
say(`${c.ok("✓")} Restarted ${c.dim(SUPERVISOR[platform].split(" · ")[0])}`);
|
|
1299
|
+
say(`${c.sky("◆")} Waiting ${c.dim("for the server to answer …")}`);
|
|
1300
|
+
const version = await waitReady(state);
|
|
1301
|
+
say(`${c.ok("✓")} Ready ${c.dim("the server answers as")} ${c.bold(version)}`);
|
|
1302
|
+
console.warn(
|
|
1303
|
+
`\n${panel(
|
|
1304
|
+
"Service restarted",
|
|
1305
|
+
[
|
|
1306
|
+
["Version", c.bold(version)],
|
|
1307
|
+
["Took", `${Math.max(1, Math.round((Date.now() - started) / 1000))}s`],
|
|
1308
|
+
["MCP", c.sky(`http://127.0.0.1:${state.port}/mcp`)],
|
|
1309
|
+
["Dashboard", c.sky(`http://127.0.0.1:${state.dashboardPort}`)],
|
|
1310
|
+
],
|
|
1311
|
+
on,
|
|
1312
|
+
)}\n\n ${c.dim("Reconnect your MCP clients if they do not reconnect by themselves.")}\n`,
|
|
1313
|
+
);
|
|
1106
1314
|
}
|
|
1107
1315
|
} finally {
|
|
1108
1316
|
await rmdir(lock);
|