@usex/mikrotik-mcp 5.18.0 → 5.19.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 +49 -5
- package/dist/cli.js +533 -198
- package/dist/index.js +22 -2
- package/dist/shared/{cli-97csvm6f.js → cli-j07tbrke.js} +8 -0
- package/dist/shared/{library-552hdvw2.js → library-7wcv2ckk.js} +411 -20
- package/dist/shared/{library-gmx9pzx3.js → library-f3be6g03.js} +11 -1
- package/dist/shared/{library-w5tyng4c.js → library-ppnv0f07.js} +1 -1
- package/dist/shared/{library-xbg1d52n.js → library-tqrvrykj.js} +1 -1
- package/dist/shared/{library-08g0pwc9.js → library-z7qsdq88.js} +1 -1
- package/dist/ui/observability.html +74 -74
- package/package.json +1 -1
- package/schemas/README.md +1 -1
- package/schemas/devtools-manifest.json +72 -1
- package/schemas/tool-catalog.json +315 -2
- package/schemas/tools/confirm_mcp_settings.json +19 -0
- package/schemas/tools/get_mcp_settings.json +7 -0
- package/schemas/tools/get_mcp_settings_schema.json +7 -0
- package/schemas/tools/preview_mcp_settings.json +94 -0
- package/schemas/tools/rollback_mcp_settings.json +19 -0
- package/schemas/tools/update_mcp_settings.json +110 -0
- /package/dist/shared/{cli-ff6yww2e.js → cli-gtq5bw8q.js} +0 -0
- /package/dist/shared/{cli-s423xk9v.js → cli-s0rxncz4.js} +0 -0
- /package/dist/shared/{cli-3zrj182m.js → cli-y00nwzxx.js} +0 -0
package/dist/cli.js
CHANGED
|
@@ -15007,7 +15007,7 @@ var DEFAULT_BACKUP_DIR2 = join(homedir(), ".mikrotik-mcp", "backups");
|
|
|
15007
15007
|
var DEFAULT_CONFIG_HISTORY_DIR2 = join(homedir(), ".mikrotik-mcp", "config-history");
|
|
15008
15008
|
var DEFAULT_CONFIG_FILE = join(homedir(), ".mikrotik-mcp", "config.json");
|
|
15009
15009
|
var TransportSchema = _enum(["stdio", "sse", "streamable-http"]);
|
|
15010
|
-
var
|
|
15010
|
+
var McpServerSettingsSchema2 = object({
|
|
15011
15011
|
transport: TransportSchema.default("stdio"),
|
|
15012
15012
|
host: string2().default("0.0.0.0"),
|
|
15013
15013
|
port: exports_coerce.number().int().positive().default(8000),
|
|
@@ -15139,7 +15139,7 @@ var SchedulesConfigSchema = object({
|
|
|
15139
15139
|
tickSeconds: exports_coerce.number().int().positive().default(30),
|
|
15140
15140
|
retainDays: exports_coerce.number().int().positive().default(90)
|
|
15141
15141
|
});
|
|
15142
|
-
var
|
|
15142
|
+
var DashboardConfigSchema2 = object({
|
|
15143
15143
|
enabled: boolean2().default(false),
|
|
15144
15144
|
host: string2().default("0.0.0.0"),
|
|
15145
15145
|
port: exports_coerce.number().int().positive().default(9090),
|
|
@@ -15151,11 +15151,11 @@ var DashboardConfigSchema = object({
|
|
|
15151
15151
|
token: string2().optional(),
|
|
15152
15152
|
feedLimit: exports_coerce.number().int().positive().max(1e4).default(200)
|
|
15153
15153
|
});
|
|
15154
|
-
var
|
|
15154
|
+
var MemoryConfigSchema2 = object({
|
|
15155
15155
|
enabled: boolean2().default(true),
|
|
15156
15156
|
dbPath: string2().default(DEFAULT_MEMORY_DB)
|
|
15157
15157
|
});
|
|
15158
|
-
var
|
|
15158
|
+
var SSHConfigSchema2 = object({
|
|
15159
15159
|
keepAlive: boolean2().default(true),
|
|
15160
15160
|
keepAliveInterval: exports_coerce.number().int().nonnegative().default(1e4),
|
|
15161
15161
|
idleTimeout: exports_coerce.number().int().positive().default(30000)
|
|
@@ -15179,19 +15179,19 @@ var MikrotikConfigSchema2 = object({
|
|
|
15179
15179
|
serviceProbes: ServiceProbeConfigSchema.default(() => ServiceProbeConfigSchema.parse({})),
|
|
15180
15180
|
devices: record(string2(), DeviceConfigSchema2).default(() => ({ default: DeviceConfigSchema2.parse({}) })),
|
|
15181
15181
|
defaultDevice: string2().default("default"),
|
|
15182
|
-
mcp:
|
|
15182
|
+
mcp: McpServerSettingsSchema2.default(() => McpServerSettingsSchema2.parse({})),
|
|
15183
15183
|
s3: S3ConfigSchema.optional(),
|
|
15184
|
-
dashboard:
|
|
15184
|
+
dashboard: DashboardConfigSchema2.default(() => DashboardConfigSchema2.parse({})),
|
|
15185
15185
|
alerts: AlertsConfigSchema.optional(),
|
|
15186
15186
|
flows: FlowsConfigSchema.default(() => FlowsConfigSchema.parse({})),
|
|
15187
15187
|
policy: PolicyConfigSchema.default(() => PolicyConfigSchema.parse({})),
|
|
15188
15188
|
schedules: SchedulesConfigSchema.default(() => SchedulesConfigSchema.parse({})),
|
|
15189
15189
|
attacks: AttacksConfigSchema.default(() => AttacksConfigSchema.parse({})),
|
|
15190
|
-
ssh:
|
|
15190
|
+
ssh: SSHConfigSchema2.default(() => SSHConfigSchema2.parse({})),
|
|
15191
15191
|
readOnly: boolean2().default(false),
|
|
15192
15192
|
access: AccessConfigSchema2.default(() => AccessConfigSchema2.parse({})),
|
|
15193
15193
|
tools: ToolFilterSchema2.default(() => ToolFilterSchema2.parse({})),
|
|
15194
|
-
memory:
|
|
15194
|
+
memory: MemoryConfigSchema2.default(() => MemoryConfigSchema2.parse({})),
|
|
15195
15195
|
backupDir: string2().optional(),
|
|
15196
15196
|
disableUpdateCheck: boolean2().default(false)
|
|
15197
15197
|
});
|
|
@@ -17954,10 +17954,10 @@ function toConsoleText(json, req) {
|
|
|
17954
17954
|
const entries = Object.entries(json);
|
|
17955
17955
|
if (entries.length === 0)
|
|
17956
17956
|
return "";
|
|
17957
|
-
return entries.map(([k, v]) => ` ${k}: ${typeof v === "string" ? v :
|
|
17957
|
+
return entries.map(([k, v]) => ` ${k}: ${typeof v === "string" ? v : JSON.stringify(v) ?? ""}`).join(`
|
|
17958
17958
|
`);
|
|
17959
17959
|
}
|
|
17960
|
-
return
|
|
17960
|
+
return typeof json === "string" ? json : JSON.stringify(json) ?? "";
|
|
17961
17961
|
}
|
|
17962
17962
|
|
|
17963
17963
|
// src/rest/client.ts
|
|
@@ -18828,7 +18828,7 @@ async function tryProbe(command, ctx) {
|
|
|
18828
18828
|
return null;
|
|
18829
18829
|
return out;
|
|
18830
18830
|
} catch (e) {
|
|
18831
|
-
logger.debug(`[capability] probe '${command}' failed: ${e instanceof Error ? e.message : e}`);
|
|
18831
|
+
logger.debug(`[capability] probe '${command}' failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
18832
18832
|
return null;
|
|
18833
18833
|
}
|
|
18834
18834
|
}
|
|
@@ -20242,7 +20242,7 @@ class AlertEngine {
|
|
|
20242
20242
|
setRules(rules) {
|
|
20243
20243
|
this.rules = rules;
|
|
20244
20244
|
const ids = new Set(rules.map((r) => r.id));
|
|
20245
|
-
for (const key of
|
|
20245
|
+
for (const key of this.states.keys()) {
|
|
20246
20246
|
if (!ids.has(splitKey(key).ruleId))
|
|
20247
20247
|
this.states.delete(key);
|
|
20248
20248
|
}
|
|
@@ -21871,13 +21871,13 @@ async function undoMigration(id, confirm, selected) {
|
|
|
21871
21871
|
throw new Error("Undo lost Safe Mode or exceeded its time budget.");
|
|
21872
21872
|
await checkedRead(item.undo, createContext(undefined, device));
|
|
21873
21873
|
}
|
|
21874
|
-
const beforeTarget = (await import("./shared/cli-
|
|
21875
|
-
const db = await beforeTarget((await import("./shared/cli-
|
|
21874
|
+
const beforeTarget = (await import("./shared/cli-s0rxncz4.js")).openSnapshotStore;
|
|
21875
|
+
const db = await beforeTarget((await import("./shared/cli-j07tbrke.js")).DEFAULT_SNAPSHOT_DB);
|
|
21876
21876
|
try {
|
|
21877
21877
|
const original = db.get(p.snapshots.target);
|
|
21878
21878
|
if (!original)
|
|
21879
21879
|
throw new Error("Original target snapshot unavailable.");
|
|
21880
|
-
const { normalizeExport } = await import("./shared/cli-
|
|
21880
|
+
const { normalizeExport } = await import("./shared/cli-gtq5bw8q.js");
|
|
21881
21881
|
if (normalizeExport((await migrationInventory(device)).export) !== normalizeExport(original.body))
|
|
21882
21882
|
throw new Error("Target differs from its backup. Undo verification failed.");
|
|
21883
21883
|
} finally {
|
|
@@ -32690,7 +32690,7 @@ var cache2 = null;
|
|
|
32690
32690
|
async function gateway() {
|
|
32691
32691
|
if (cache2)
|
|
32692
32692
|
return cache2;
|
|
32693
|
-
const { moduleCatalog } = await import("./shared/cli-
|
|
32693
|
+
const { moduleCatalog } = await import("./shared/cli-y00nwzxx.js");
|
|
32694
32694
|
const forIndex = [];
|
|
32695
32695
|
const byName = new Map;
|
|
32696
32696
|
for (const mod of moduleCatalog) {
|
|
@@ -54937,7 +54937,7 @@ var riskByTool = null;
|
|
|
54937
54937
|
async function riskIndex() {
|
|
54938
54938
|
if (riskByTool)
|
|
54939
54939
|
return riskByTool;
|
|
54940
|
-
const { moduleCatalog } = await import("./shared/cli-
|
|
54940
|
+
const { moduleCatalog } = await import("./shared/cli-y00nwzxx.js");
|
|
54941
54941
|
const index = new Map;
|
|
54942
54942
|
for (const mod of moduleCatalog) {
|
|
54943
54943
|
for (const tool of mod.tools)
|
|
@@ -58571,8 +58571,462 @@ var serverPulseTools = [
|
|
|
58571
58571
|
})
|
|
58572
58572
|
];
|
|
58573
58573
|
|
|
58574
|
+
// src/observability/config-admin.ts
|
|
58575
|
+
import { createHash as createHash7, randomUUID as randomUUID9 } from "crypto";
|
|
58576
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
58577
|
+
|
|
58578
|
+
// src/config-write.ts
|
|
58579
|
+
import { randomUUID as randomUUID8 } from "crypto";
|
|
58580
|
+
import { mkdirSync as mkdirSync15, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
58581
|
+
import { dirname as dirname16 } from "path";
|
|
58582
|
+
|
|
58583
|
+
// src/config-device-draft.ts
|
|
58584
|
+
var CREDENTIAL_SOURCE = "$credentialsFrom";
|
|
58585
|
+
function selectConfigScope(cfg, scope) {
|
|
58586
|
+
return Object.fromEntries(Object.entries(cfg).filter(([key]) => scope === "devices" ? key === "devices" || key === "defaultDevice" : key !== "devices" && key !== "defaultDevice"));
|
|
58587
|
+
}
|
|
58588
|
+
function scopeConfigDraft(raw, current, scope) {
|
|
58589
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
58590
|
+
return raw;
|
|
58591
|
+
return {
|
|
58592
|
+
...selectConfigScope(current, scope === "devices" ? "server" : "devices"),
|
|
58593
|
+
...selectConfigScope(raw, scope)
|
|
58594
|
+
};
|
|
58595
|
+
}
|
|
58596
|
+
|
|
58597
|
+
// src/config-write.ts
|
|
58598
|
+
var SCHEMA_REF = "./schemas/config.schema.json";
|
|
58599
|
+
function mergeSecrets(incoming, current) {
|
|
58600
|
+
if (incoming === REDACTED) {
|
|
58601
|
+
return typeof current === "string" ? current : undefined;
|
|
58602
|
+
}
|
|
58603
|
+
if (Array.isArray(incoming)) {
|
|
58604
|
+
const cur = Array.isArray(current) ? current : [];
|
|
58605
|
+
return incoming.map((v, i) => mergeSecrets(v, cur[i]));
|
|
58606
|
+
}
|
|
58607
|
+
if (incoming && typeof incoming === "object") {
|
|
58608
|
+
const curObj = current && typeof current === "object" && !Array.isArray(current) ? current : {};
|
|
58609
|
+
const out = {};
|
|
58610
|
+
for (const [k, v] of Object.entries(incoming)) {
|
|
58611
|
+
const merged = mergeSecrets(v, curObj[k]);
|
|
58612
|
+
if (merged !== undefined)
|
|
58613
|
+
out[k] = merged;
|
|
58614
|
+
}
|
|
58615
|
+
return out;
|
|
58616
|
+
}
|
|
58617
|
+
return incoming;
|
|
58618
|
+
}
|
|
58619
|
+
function mergeDeviceDraft(incoming, name, devices) {
|
|
58620
|
+
if (!incoming || typeof incoming !== "object" || Array.isArray(incoming))
|
|
58621
|
+
return incoming;
|
|
58622
|
+
const { [CREDENTIAL_SOURCE]: source, ...draft } = incoming;
|
|
58623
|
+
if (source !== undefined && (typeof source !== "string" || !Object.hasOwn(devices, source)))
|
|
58624
|
+
throw new Error("Credential source is unavailable. Reopen the editor or enter new credentials.");
|
|
58625
|
+
const key = typeof source === "string" ? source : name;
|
|
58626
|
+
return mergeSecrets(draft, Object.hasOwn(devices, key) ? devices[key] : undefined);
|
|
58627
|
+
}
|
|
58628
|
+
function mergeConfigDraft(incoming, current) {
|
|
58629
|
+
if (!incoming || typeof incoming !== "object" || Array.isArray(incoming))
|
|
58630
|
+
return incoming;
|
|
58631
|
+
const draft = incoming;
|
|
58632
|
+
if (!draft.devices || typeof draft.devices !== "object" || Array.isArray(draft.devices))
|
|
58633
|
+
return mergeSecrets(incoming, current);
|
|
58634
|
+
const { devices: _devices, ...rest } = draft;
|
|
58635
|
+
const currentDevices = current?.devices ?? {};
|
|
58636
|
+
return {
|
|
58637
|
+
...mergeSecrets(rest, current),
|
|
58638
|
+
devices: Object.fromEntries(Object.entries(draft.devices).map(([name, device]) => [
|
|
58639
|
+
name,
|
|
58640
|
+
mergeDeviceDraft(device, name, currentDevices)
|
|
58641
|
+
]))
|
|
58642
|
+
};
|
|
58643
|
+
}
|
|
58644
|
+
function serializeConfig(config) {
|
|
58645
|
+
const body = config && typeof config === "object" && !Array.isArray(config) ? config : {};
|
|
58646
|
+
const { $schema: _drop, ...rest } = body;
|
|
58647
|
+
return `${JSON.stringify({ $schema: SCHEMA_REF, ...rest }, null, 2)}
|
|
58648
|
+
`;
|
|
58649
|
+
}
|
|
58650
|
+
function backupName(path, ts) {
|
|
58651
|
+
return `${path}.bak-${ts}`;
|
|
58652
|
+
}
|
|
58653
|
+
function atomicWrite(path, text) {
|
|
58654
|
+
mkdirSync15(dirname16(path), { recursive: true });
|
|
58655
|
+
const tmp = `${path}.tmp-${randomUUID8()}`;
|
|
58656
|
+
try {
|
|
58657
|
+
writeFileSync4(tmp, text, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
58658
|
+
renameSync2(tmp, path);
|
|
58659
|
+
} finally {
|
|
58660
|
+
rmSync2(tmp, { force: true });
|
|
58661
|
+
}
|
|
58662
|
+
}
|
|
58663
|
+
|
|
58664
|
+
// src/observability/config-admin.ts
|
|
58665
|
+
function validateConfig(raw) {
|
|
58666
|
+
const r = MikrotikConfigSchema2.safeParse(raw);
|
|
58667
|
+
if (r.success)
|
|
58668
|
+
return { ok: true, errors: [], value: r.data };
|
|
58669
|
+
return {
|
|
58670
|
+
ok: false,
|
|
58671
|
+
errors: r.error.issues.map((i) => ({
|
|
58672
|
+
path: i.path.join(".") || "(root)",
|
|
58673
|
+
message: i.message
|
|
58674
|
+
}))
|
|
58675
|
+
};
|
|
58676
|
+
}
|
|
58677
|
+
function createConfigAdmin(deps) {
|
|
58678
|
+
let pending = null;
|
|
58679
|
+
let lastTimestamp = 0;
|
|
58680
|
+
const salt = randomUUID9();
|
|
58681
|
+
const fingerprint = (config, source, contents) => createHash7("sha256").update(salt).update(JSON.stringify([config, source, contents])).digest("hex");
|
|
58682
|
+
const revision = () => {
|
|
58683
|
+
const source = deps.source();
|
|
58684
|
+
return fingerprint(deps.getConfig(), source, deps.readFile(source.path));
|
|
58685
|
+
};
|
|
58686
|
+
const currentPending = () => {
|
|
58687
|
+
if (pending && pending.revision !== revision()) {
|
|
58688
|
+
deps.cancel(pending.timer);
|
|
58689
|
+
pending = null;
|
|
58690
|
+
logger.warn("Config changed outside its pending transaction; preserved newer settings. Backup retained.");
|
|
58691
|
+
}
|
|
58692
|
+
return pending;
|
|
58693
|
+
};
|
|
58694
|
+
const rollback = (id) => {
|
|
58695
|
+
const active = currentPending();
|
|
58696
|
+
if (!active || active.id !== id)
|
|
58697
|
+
return false;
|
|
58698
|
+
const { backupPath, previous, timer, path } = active;
|
|
58699
|
+
const backup = deps.readFile(backupPath);
|
|
58700
|
+
if (backup == null)
|
|
58701
|
+
throw new Error("Configuration backup is unavailable; rollback was not applied.");
|
|
58702
|
+
deps.writeText(path, backup);
|
|
58703
|
+
deps.setConfig(previous);
|
|
58704
|
+
deps.cancel(timer);
|
|
58705
|
+
pending = null;
|
|
58706
|
+
return true;
|
|
58707
|
+
};
|
|
58708
|
+
const applyConfig = (parsed, rollbackMs) => {
|
|
58709
|
+
if ((currentPending()?.rollbackMs ?? 0) > 0)
|
|
58710
|
+
throw new Error("Another configuration change awaits confirmation. Keep or roll it back first.");
|
|
58711
|
+
const src = deps.source();
|
|
58712
|
+
const previous = deps.getConfig();
|
|
58713
|
+
const ts = Math.max(deps.now(), lastTimestamp + 1);
|
|
58714
|
+
lastTimestamp = ts;
|
|
58715
|
+
const id = `cfg_${ts}`;
|
|
58716
|
+
const backupPath = backupName(src.path, ts);
|
|
58717
|
+
const existing = deps.readFile(src.path) ?? serializeConfig(previous);
|
|
58718
|
+
const contents = serializeConfig(parsed);
|
|
58719
|
+
const nextRevision = fingerprint(parsed, src, contents);
|
|
58720
|
+
deps.writeText(backupPath, existing);
|
|
58721
|
+
deps.writeText(src.path, contents);
|
|
58722
|
+
deps.setConfig(parsed);
|
|
58723
|
+
const timer = rollbackMs > 0 ? deps.schedule(() => {
|
|
58724
|
+
try {
|
|
58725
|
+
rollback(id);
|
|
58726
|
+
} catch {
|
|
58727
|
+
logger.error("Configuration auto-rollback failed; backup retained. Retry rollback or restore it manually.");
|
|
58728
|
+
}
|
|
58729
|
+
}, rollbackMs) : null;
|
|
58730
|
+
pending = {
|
|
58731
|
+
id,
|
|
58732
|
+
backupPath,
|
|
58733
|
+
previous,
|
|
58734
|
+
timer,
|
|
58735
|
+
rollbackMs,
|
|
58736
|
+
path: src.path,
|
|
58737
|
+
revision: nextRevision
|
|
58738
|
+
};
|
|
58739
|
+
return {
|
|
58740
|
+
pendingId: id,
|
|
58741
|
+
rollbackMs,
|
|
58742
|
+
path: src.path,
|
|
58743
|
+
fromFile: src.fromFile,
|
|
58744
|
+
backupPath,
|
|
58745
|
+
expiresAt: rollbackMs > 0 ? deps.now() + rollbackMs : null
|
|
58746
|
+
};
|
|
58747
|
+
};
|
|
58748
|
+
const keepConfig = (id) => {
|
|
58749
|
+
const active = currentPending();
|
|
58750
|
+
if (!active || active.id !== id)
|
|
58751
|
+
return false;
|
|
58752
|
+
deps.cancel(active.timer);
|
|
58753
|
+
pending = null;
|
|
58754
|
+
return true;
|
|
58755
|
+
};
|
|
58756
|
+
return {
|
|
58757
|
+
applyConfig,
|
|
58758
|
+
keepConfig,
|
|
58759
|
+
rollback,
|
|
58760
|
+
pendingId: () => {
|
|
58761
|
+
const active = currentPending();
|
|
58762
|
+
return active && active.rollbackMs > 0 ? active.id : null;
|
|
58763
|
+
},
|
|
58764
|
+
revision
|
|
58765
|
+
};
|
|
58766
|
+
}
|
|
58767
|
+
var sharedAdmin;
|
|
58768
|
+
function getConfigAdmin() {
|
|
58769
|
+
return sharedAdmin ??= createConfigAdmin({
|
|
58770
|
+
getConfig,
|
|
58771
|
+
setConfig,
|
|
58772
|
+
source: getConfigSource2,
|
|
58773
|
+
readFile: (path) => {
|
|
58774
|
+
try {
|
|
58775
|
+
return readFileSync9(path, "utf8");
|
|
58776
|
+
} catch (error) {
|
|
58777
|
+
if (error.code === "ENOENT")
|
|
58778
|
+
return null;
|
|
58779
|
+
throw new Error("Cannot read the MCP configuration file; check host-side file permissions.");
|
|
58780
|
+
}
|
|
58781
|
+
},
|
|
58782
|
+
writeText: atomicWrite,
|
|
58783
|
+
now: Date.now,
|
|
58784
|
+
schedule: (fn, ms) => setTimeout(fn, ms),
|
|
58785
|
+
cancel: (timer) => {
|
|
58786
|
+
if (timer)
|
|
58787
|
+
clearTimeout(timer);
|
|
58788
|
+
}
|
|
58789
|
+
});
|
|
58790
|
+
}
|
|
58791
|
+
|
|
58792
|
+
// src/core/mcp-settings.ts
|
|
58793
|
+
var McpSettingsPatchSchema = object({
|
|
58794
|
+
mcp: object({
|
|
58795
|
+
toolPageSize: McpServerSettingsSchema2.shape.toolPageSize.removeDefault().optional(),
|
|
58796
|
+
appViews: McpServerSettingsSchema2.shape.appViews.removeDefault().optional(),
|
|
58797
|
+
capabilityGating: McpServerSettingsSchema2.shape.capabilityGating.removeDefault().optional()
|
|
58798
|
+
}).strict().optional(),
|
|
58799
|
+
ssh: object({
|
|
58800
|
+
keepAlive: SSHConfigSchema2.shape.keepAlive.removeDefault().optional(),
|
|
58801
|
+
keepAliveInterval: SSHConfigSchema2.shape.keepAliveInterval.removeDefault().optional(),
|
|
58802
|
+
idleTimeout: SSHConfigSchema2.shape.idleTimeout.removeDefault().optional()
|
|
58803
|
+
}).strict().optional(),
|
|
58804
|
+
dashboard: object({
|
|
58805
|
+
maxEvents: DashboardConfigSchema2.shape.maxEvents.removeDefault().optional(),
|
|
58806
|
+
captureBody: DashboardConfigSchema2.shape.captureBody.removeDefault().optional(),
|
|
58807
|
+
redactInput: literal(true).optional().describe("May enable redaction, never disable it."),
|
|
58808
|
+
maxBodyBytes: DashboardConfigSchema2.shape.maxBodyBytes.removeDefault().optional(),
|
|
58809
|
+
feedLimit: DashboardConfigSchema2.shape.feedLimit.removeDefault().optional()
|
|
58810
|
+
}).strict().optional(),
|
|
58811
|
+
memory: object({
|
|
58812
|
+
enabled: MemoryConfigSchema2.shape.enabled.removeDefault().optional()
|
|
58813
|
+
}).strict().optional(),
|
|
58814
|
+
disableUpdateCheck: MikrotikConfigSchema2.shape.disableUpdateCheck.removeDefault().optional()
|
|
58815
|
+
}).strict();
|
|
58816
|
+
var McpSettingsUpdateSchema = object({
|
|
58817
|
+
changes: McpSettingsPatchSchema,
|
|
58818
|
+
revision: string2().length(64).describe("Current revision from get_mcp_settings or preview_mcp_settings."),
|
|
58819
|
+
confirm: literal(true).describe("Only set after the user authorizes these exact changes."),
|
|
58820
|
+
rollback_seconds: number2().int().min(30).max(600).default(60)
|
|
58821
|
+
}).strict();
|
|
58822
|
+
var McpSettingsPendingSchema = object({
|
|
58823
|
+
pending_id: string2().min(1),
|
|
58824
|
+
revision: string2().length(64).describe("Revision returned by update_mcp_settings or get_mcp_settings.")
|
|
58825
|
+
}).strict();
|
|
58826
|
+
var BOUNDARY = "Only the listed fields are editable. Devices, credentials, file paths, listeners, access, readOnly, tools and service probe allowlists remain operator-managed. No router is contacted.";
|
|
58827
|
+
function settings(cfg) {
|
|
58828
|
+
return {
|
|
58829
|
+
mcp: {
|
|
58830
|
+
toolPageSize: cfg.mcp.toolPageSize,
|
|
58831
|
+
appViews: cfg.mcp.appViews,
|
|
58832
|
+
capabilityGating: cfg.mcp.capabilityGating
|
|
58833
|
+
},
|
|
58834
|
+
ssh: {
|
|
58835
|
+
keepAlive: cfg.ssh.keepAlive,
|
|
58836
|
+
keepAliveInterval: cfg.ssh.keepAliveInterval,
|
|
58837
|
+
idleTimeout: cfg.ssh.idleTimeout
|
|
58838
|
+
},
|
|
58839
|
+
dashboard: {
|
|
58840
|
+
maxEvents: cfg.dashboard.maxEvents,
|
|
58841
|
+
captureBody: cfg.dashboard.captureBody,
|
|
58842
|
+
redactInput: cfg.dashboard.redactInput,
|
|
58843
|
+
maxBodyBytes: cfg.dashboard.maxBodyBytes,
|
|
58844
|
+
feedLimit: cfg.dashboard.feedLimit
|
|
58845
|
+
},
|
|
58846
|
+
memory: { enabled: cfg.memory.enabled },
|
|
58847
|
+
disableUpdateCheck: cfg.disableUpdateCheck
|
|
58848
|
+
};
|
|
58849
|
+
}
|
|
58850
|
+
function createMcpSettingsService(deps) {
|
|
58851
|
+
let owned = null;
|
|
58852
|
+
const read = () => {
|
|
58853
|
+
const id = deps.admin.pendingId();
|
|
58854
|
+
const source = deps.source();
|
|
58855
|
+
return {
|
|
58856
|
+
revision: deps.admin.revision(),
|
|
58857
|
+
settings: settings(deps.getConfig()),
|
|
58858
|
+
pending: id ? { id, owned: id === owned?.id, expiresAt: id === owned?.id ? owned.expiresAt : null } : null,
|
|
58859
|
+
persistence: {
|
|
58860
|
+
path: source.path,
|
|
58861
|
+
fromFile: source.fromFile,
|
|
58862
|
+
note: source.fromFile ? "Saved to the source config file; CLI/environment overrides may still take precedence on restart." : "Saved to the default config file. Start with --config pointing to the returned path to reuse it; environment/CLI overrides may still take precedence."
|
|
58863
|
+
},
|
|
58864
|
+
boundary: BOUNDARY
|
|
58865
|
+
};
|
|
58866
|
+
};
|
|
58867
|
+
const prepare = (raw) => {
|
|
58868
|
+
const parsed = McpSettingsPatchSchema.safeParse(raw);
|
|
58869
|
+
if (!parsed.success)
|
|
58870
|
+
throw new Error("Invalid or protected MCP setting. Use get_mcp_settings_schema for allowed fields and values.");
|
|
58871
|
+
const changes = parsed.data;
|
|
58872
|
+
const current = deps.getConfig();
|
|
58873
|
+
const next = MikrotikConfigSchema2.parse({
|
|
58874
|
+
...current,
|
|
58875
|
+
...changes,
|
|
58876
|
+
mcp: { ...current.mcp, ...changes.mcp },
|
|
58877
|
+
ssh: { ...current.ssh, ...changes.ssh },
|
|
58878
|
+
dashboard: { ...current.dashboard, ...changes.dashboard },
|
|
58879
|
+
memory: { ...current.memory, ...changes.memory }
|
|
58880
|
+
});
|
|
58881
|
+
if (changes.dashboard?.captureBody === true && !next.dashboard.redactInput)
|
|
58882
|
+
throw new Error("Enabling body capture also requires dashboard.redactInput=true.");
|
|
58883
|
+
const before = settings(current);
|
|
58884
|
+
const after = settings(next);
|
|
58885
|
+
const changedPaths = [];
|
|
58886
|
+
for (const key of ["mcp", "ssh", "dashboard", "memory"]) {
|
|
58887
|
+
for (const [field, value] of Object.entries(after[key])) {
|
|
58888
|
+
if (value !== before[key][field])
|
|
58889
|
+
changedPaths.push(`${key}.${field}`);
|
|
58890
|
+
}
|
|
58891
|
+
}
|
|
58892
|
+
if (before.disableUpdateCheck !== after.disableUpdateCheck)
|
|
58893
|
+
changedPaths.push("disableUpdateCheck");
|
|
58894
|
+
const restartRequired = changedPaths.some((path) => path.startsWith("mcp.") || path.startsWith("dashboard.") || path === "disableUpdateCheck");
|
|
58895
|
+
const diff = diffLines(JSON.stringify(before, null, 2), JSON.stringify(after, null, 2), {
|
|
58896
|
+
fromLabel: "current MCP settings",
|
|
58897
|
+
toLabel: "proposed MCP settings"
|
|
58898
|
+
});
|
|
58899
|
+
return {
|
|
58900
|
+
next,
|
|
58901
|
+
preview: {
|
|
58902
|
+
revision: deps.admin.revision(),
|
|
58903
|
+
changedPaths,
|
|
58904
|
+
before,
|
|
58905
|
+
after,
|
|
58906
|
+
summary: diff.summary,
|
|
58907
|
+
unified: diff.unified,
|
|
58908
|
+
restartRequired,
|
|
58909
|
+
activation: [
|
|
58910
|
+
"Memory enable/disable is checked on the next memory operation; disabling does not delete stored knowledge.",
|
|
58911
|
+
"SSH pool changes affect subsequent calls/new connections and newly armed idle timers; existing connections are not forcibly closed.",
|
|
58912
|
+
"MCP presentation, dashboard recorder and startup update-check settings require a server restart for full activation. Confirm the change before restarting; an in-process rollback timer cannot survive process exit."
|
|
58913
|
+
]
|
|
58914
|
+
}
|
|
58915
|
+
};
|
|
58916
|
+
};
|
|
58917
|
+
const checkWrite = (revision) => {
|
|
58918
|
+
if (deps.getConfig().readOnly)
|
|
58919
|
+
throw new Error("MCP settings writes are disabled in read-only mode.");
|
|
58920
|
+
if (revision !== deps.admin.revision())
|
|
58921
|
+
throw new Error("MCP settings changed. Read and preview again before writing.");
|
|
58922
|
+
};
|
|
58923
|
+
return {
|
|
58924
|
+
read,
|
|
58925
|
+
schema: () => ({
|
|
58926
|
+
schema: toJSONSchema(McpSettingsPatchSchema, { target: "draft-2020-12" }),
|
|
58927
|
+
boundary: BOUNDARY
|
|
58928
|
+
}),
|
|
58929
|
+
preview: (changes) => prepare(changes).preview,
|
|
58930
|
+
update: (raw) => {
|
|
58931
|
+
const input = McpSettingsUpdateSchema.safeParse(raw);
|
|
58932
|
+
if (!input.success)
|
|
58933
|
+
throw new Error("Invalid settings update. A current revision, allowed changes, confirm=true and 30\u2013600 second rollback window are required.");
|
|
58934
|
+
checkWrite(input.data.revision);
|
|
58935
|
+
if (deps.admin.pendingId())
|
|
58936
|
+
throw new Error("Another configuration change is pending. Confirm or roll back its owning workflow first.");
|
|
58937
|
+
const { next, preview } = prepare(input.data.changes);
|
|
58938
|
+
if (!preview.changedPaths.length)
|
|
58939
|
+
return { applied: false, ...preview, ...read() };
|
|
58940
|
+
const applied = deps.admin.applyConfig(next, input.data.rollback_seconds * 1000);
|
|
58941
|
+
owned = { id: applied.pendingId, expiresAt: applied.expiresAt };
|
|
58942
|
+
return { applied: true, ...preview, ...applied, ...read() };
|
|
58943
|
+
},
|
|
58944
|
+
finish: (raw, action) => {
|
|
58945
|
+
const result = McpSettingsPendingSchema.safeParse(raw);
|
|
58946
|
+
if (!result.success)
|
|
58947
|
+
throw new Error("A pending_id and current revision are required.");
|
|
58948
|
+
const input = result.data;
|
|
58949
|
+
checkWrite(input.revision);
|
|
58950
|
+
if (!owned || owned.id !== input.pending_id || deps.admin.pendingId() !== owned.id)
|
|
58951
|
+
throw new Error("This transaction is not pending in MCP settings. It may have expired or belong to the dashboard.");
|
|
58952
|
+
const ok = action === "confirm" ? deps.admin.keepConfig(owned.id) : deps.admin.rollback(owned.id);
|
|
58953
|
+
if (!ok)
|
|
58954
|
+
throw new Error("Configuration changed before confirmation; read settings again.");
|
|
58955
|
+
owned = null;
|
|
58956
|
+
return { action, ok, ...read() };
|
|
58957
|
+
}
|
|
58958
|
+
};
|
|
58959
|
+
}
|
|
58960
|
+
var service;
|
|
58961
|
+
function getMcpSettingsService() {
|
|
58962
|
+
return service ??= createMcpSettingsService({
|
|
58963
|
+
admin: getConfigAdmin(),
|
|
58964
|
+
getConfig,
|
|
58965
|
+
source: getConfigSource2
|
|
58966
|
+
});
|
|
58967
|
+
}
|
|
58968
|
+
|
|
58969
|
+
// src/tools/mcp-settings.ts
|
|
58970
|
+
var render = (value) => JSON.stringify(value, null, 2);
|
|
58971
|
+
var mcpSettingsTools = [
|
|
58972
|
+
defineTool({
|
|
58973
|
+
name: "get_mcp_settings",
|
|
58974
|
+
title: "Read MCP Server Settings",
|
|
58975
|
+
noDevice: true,
|
|
58976
|
+
annotations: READ,
|
|
58977
|
+
description: "Read the MCP host's editable settings, opaque revision and pending change. Covers tool presentation, SSH pooling, dashboard recording, Memory enablement and startup update checks. Contains no credentials; never contacts a router. These are configured values, not proof a startup-only component has restarted. Read before preview_mcp_settings or update_mcp_settings.",
|
|
58978
|
+
handler: () => render(getMcpSettingsService().read())
|
|
58979
|
+
}),
|
|
58980
|
+
defineTool({
|
|
58981
|
+
name: "get_mcp_settings_schema",
|
|
58982
|
+
title: "Describe Editable MCP Settings",
|
|
58983
|
+
noDevice: true,
|
|
58984
|
+
annotations: READ,
|
|
58985
|
+
description: "Get the exact JSON Schema for the partial changes accepted by preview_mcp_settings and update_mcp_settings. Unknown/protected fields are rejected, omitted fields stay unchanged. Credentials, listeners, file paths, device inventory and permission ceilings are operator-managed. No device or file changes.",
|
|
58986
|
+
handler: () => render(getMcpSettingsService().schema())
|
|
58987
|
+
}),
|
|
58988
|
+
defineTool({
|
|
58989
|
+
name: "preview_mcp_settings",
|
|
58990
|
+
title: "Validate and Preview MCP Settings",
|
|
58991
|
+
noDevice: true,
|
|
58992
|
+
annotations: READ,
|
|
58993
|
+
description: "Validate a partial MCP settings change against live configuration and return changed paths, a secret-free diff, revision and restart requirements. No file writes or router contact. Show the preview and obtain user approval before applying; never guess setting names.",
|
|
58994
|
+
inputSchema: {
|
|
58995
|
+
changes: McpSettingsPatchSchema.describe("Only the fields to change; omitted values are preserved.")
|
|
58996
|
+
},
|
|
58997
|
+
handler: (args) => render(getMcpSettingsService().preview(args.changes))
|
|
58998
|
+
}),
|
|
58999
|
+
defineTool({
|
|
59000
|
+
name: "update_mcp_settings",
|
|
59001
|
+
title: "Safely Update MCP Settings",
|
|
59002
|
+
noDevice: true,
|
|
59003
|
+
annotations: WRITE,
|
|
59004
|
+
description: "Apply explicitly user-approved MCP host settings, not RouterOS configuration. First get_mcp_settings_schema and preview_mcp_settings; supply that revision and confirm=true. Backs up the config locally, saves atomically and arms a 30\u2013600s in-process rollback (default 60s). Conflicts with another pending dashboard/tool edit are rejected. Verify configured values with get_mcp_settings, then confirm_mcp_settings before the deadline or rollback_mcp_settings. Never restart while pending: the rollback timer does not survive process exit. Restart-required settings are only fully activated after confirmation and a separate operator-controlled restart. Does not widen access scopes or change router addresses/credentials.",
|
|
59005
|
+
inputSchema: McpSettingsUpdateSchema.shape,
|
|
59006
|
+
handler: (args) => render(getMcpSettingsService().update(args))
|
|
59007
|
+
}),
|
|
59008
|
+
defineTool({
|
|
59009
|
+
name: "confirm_mcp_settings",
|
|
59010
|
+
title: "Keep a Pending MCP Settings Change",
|
|
59011
|
+
noDevice: true,
|
|
59012
|
+
annotations: WRITE,
|
|
59013
|
+
description: "Keep the exact pending change created by update_mcp_settings after reading back its values. Cancels its rollback timer. Requires the current revision and pending_id; cannot confirm dashboard-owned, expired or superseded changes. Does not restart the MCP server or contact routers.",
|
|
59014
|
+
inputSchema: McpSettingsPendingSchema.shape,
|
|
59015
|
+
handler: (args) => render(getMcpSettingsService().finish(args, "confirm"))
|
|
59016
|
+
}),
|
|
59017
|
+
defineTool({
|
|
59018
|
+
name: "rollback_mcp_settings",
|
|
59019
|
+
title: "Revert a Pending MCP Settings Change",
|
|
59020
|
+
noDevice: true,
|
|
59021
|
+
annotations: WRITE,
|
|
59022
|
+
description: "Restore the host-side config backup for a still-pending update_mcp_settings change. Requires its pending_id and current revision. Refuses dashboard-owned transactions or changes that would overwrite newer configuration. Restores configured values only; no router changes, server restart or deletion of knowledge data.",
|
|
59023
|
+
inputSchema: McpSettingsPendingSchema.shape,
|
|
59024
|
+
handler: (args) => render(getMcpSettingsService().finish(args, "rollback"))
|
|
59025
|
+
})
|
|
59026
|
+
];
|
|
59027
|
+
|
|
58574
59028
|
// src/tools/capability.ts
|
|
58575
|
-
function
|
|
59029
|
+
function render2(deviceName, caps) {
|
|
58576
59030
|
const lines = [`DEVICE CAPABILITIES \u2014 ${deviceName}`, ""];
|
|
58577
59031
|
if (!caps.version && caps.packages.size === 0 && !caps.board) {
|
|
58578
59032
|
return `${lines.join(`
|
|
@@ -58635,7 +59089,7 @@ var capabilityTools = [
|
|
|
58635
59089
|
async handler(_a, ctx) {
|
|
58636
59090
|
const name = resolveDeviceName(ctx.device);
|
|
58637
59091
|
ctx.info(`Reading device capabilities: ${name}`);
|
|
58638
|
-
return
|
|
59092
|
+
return render2(name, await getCapabilities(ctx.device));
|
|
58639
59093
|
}
|
|
58640
59094
|
}),
|
|
58641
59095
|
defineTool({
|
|
@@ -58648,7 +59102,7 @@ var capabilityTools = [
|
|
|
58648
59102
|
const name = resolveDeviceName(ctx.device);
|
|
58649
59103
|
ctx.info(`Refreshing device capabilities: ${name}`);
|
|
58650
59104
|
invalidateCapabilities(ctx.device);
|
|
58651
|
-
return
|
|
59105
|
+
return render2(name, await getCapabilities(ctx.device));
|
|
58652
59106
|
}
|
|
58653
59107
|
})
|
|
58654
59108
|
];
|
|
@@ -64168,6 +64622,13 @@ var moduleCatalog2 = [
|
|
|
64168
64622
|
description: "Server self-awareness: running version, update availability, release notes, " + "upgrade path, and server vitals. No RouterOS device is contacted.",
|
|
64169
64623
|
tools: serverPulseTools
|
|
64170
64624
|
},
|
|
64625
|
+
{
|
|
64626
|
+
label: "MCP Settings",
|
|
64627
|
+
slug: "mcp-settings",
|
|
64628
|
+
group: "Discovery & Meta",
|
|
64629
|
+
description: "Read, validate, preview and safely update MCP host settings with local backups, " + "revision checks and timed rollback. Never changes routers, credentials or access ceilings.",
|
|
64630
|
+
tools: mcpSettingsTools
|
|
64631
|
+
},
|
|
64171
64632
|
{
|
|
64172
64633
|
label: "Device Capabilities",
|
|
64173
64634
|
slug: "device-capabilities",
|
|
@@ -65155,7 +65616,7 @@ import { existsSync as existsSync6 } from "fs";
|
|
|
65155
65616
|
|
|
65156
65617
|
// src/observability/dashboard.ts
|
|
65157
65618
|
import { spawn } from "child_process";
|
|
65158
|
-
import { readFileSync as
|
|
65619
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
65159
65620
|
import { homedir as homedir6, networkInterfaces as networkInterfaces2 } from "os";
|
|
65160
65621
|
import { dirname as dirname22, join as join15 } from "path";
|
|
65161
65622
|
var {serve } = globalThis.Bun;
|
|
@@ -65233,89 +65694,8 @@ function applyModuleToggle(filter, slug, enabled) {
|
|
|
65233
65694
|
return { enabledModules, disabledModules, enabledGroups, disabledGroups };
|
|
65234
65695
|
}
|
|
65235
65696
|
|
|
65236
|
-
// src/config-write.ts
|
|
65237
|
-
import { mkdirSync as mkdirSync15, renameSync as renameSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
65238
|
-
import { dirname as dirname16 } from "path";
|
|
65239
|
-
|
|
65240
|
-
// src/config-device-draft.ts
|
|
65241
|
-
var CREDENTIAL_SOURCE = "$credentialsFrom";
|
|
65242
|
-
function selectConfigScope(cfg, scope) {
|
|
65243
|
-
return Object.fromEntries(Object.entries(cfg).filter(([key]) => scope === "devices" ? key === "devices" || key === "defaultDevice" : key !== "devices" && key !== "defaultDevice"));
|
|
65244
|
-
}
|
|
65245
|
-
function scopeConfigDraft(raw, current, scope) {
|
|
65246
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
65247
|
-
return raw;
|
|
65248
|
-
return {
|
|
65249
|
-
...selectConfigScope(current, scope === "devices" ? "server" : "devices"),
|
|
65250
|
-
...selectConfigScope(raw, scope)
|
|
65251
|
-
};
|
|
65252
|
-
}
|
|
65253
|
-
|
|
65254
|
-
// src/config-write.ts
|
|
65255
|
-
var SCHEMA_REF = "./schemas/config.schema.json";
|
|
65256
|
-
function mergeSecrets(incoming, current) {
|
|
65257
|
-
if (incoming === REDACTED) {
|
|
65258
|
-
return typeof current === "string" ? current : undefined;
|
|
65259
|
-
}
|
|
65260
|
-
if (Array.isArray(incoming)) {
|
|
65261
|
-
const cur = Array.isArray(current) ? current : [];
|
|
65262
|
-
return incoming.map((v, i) => mergeSecrets(v, cur[i]));
|
|
65263
|
-
}
|
|
65264
|
-
if (incoming && typeof incoming === "object") {
|
|
65265
|
-
const curObj = current && typeof current === "object" && !Array.isArray(current) ? current : {};
|
|
65266
|
-
const out = {};
|
|
65267
|
-
for (const [k, v] of Object.entries(incoming)) {
|
|
65268
|
-
const merged = mergeSecrets(v, curObj[k]);
|
|
65269
|
-
if (merged !== undefined)
|
|
65270
|
-
out[k] = merged;
|
|
65271
|
-
}
|
|
65272
|
-
return out;
|
|
65273
|
-
}
|
|
65274
|
-
return incoming;
|
|
65275
|
-
}
|
|
65276
|
-
function mergeDeviceDraft(incoming, name, devices) {
|
|
65277
|
-
if (!incoming || typeof incoming !== "object" || Array.isArray(incoming))
|
|
65278
|
-
return incoming;
|
|
65279
|
-
const { [CREDENTIAL_SOURCE]: source, ...draft } = incoming;
|
|
65280
|
-
if (source !== undefined && (typeof source !== "string" || !Object.hasOwn(devices, source)))
|
|
65281
|
-
throw new Error("Credential source is unavailable. Reopen the editor or enter new credentials.");
|
|
65282
|
-
const key = typeof source === "string" ? source : name;
|
|
65283
|
-
return mergeSecrets(draft, Object.hasOwn(devices, key) ? devices[key] : undefined);
|
|
65284
|
-
}
|
|
65285
|
-
function mergeConfigDraft(incoming, current) {
|
|
65286
|
-
if (!incoming || typeof incoming !== "object" || Array.isArray(incoming))
|
|
65287
|
-
return incoming;
|
|
65288
|
-
const draft = incoming;
|
|
65289
|
-
if (!draft.devices || typeof draft.devices !== "object" || Array.isArray(draft.devices))
|
|
65290
|
-
return mergeSecrets(incoming, current);
|
|
65291
|
-
const { devices: _devices, ...rest } = draft;
|
|
65292
|
-
const currentDevices = current?.devices ?? {};
|
|
65293
|
-
return {
|
|
65294
|
-
...mergeSecrets(rest, current),
|
|
65295
|
-
devices: Object.fromEntries(Object.entries(draft.devices).map(([name, device]) => [
|
|
65296
|
-
name,
|
|
65297
|
-
mergeDeviceDraft(device, name, currentDevices)
|
|
65298
|
-
]))
|
|
65299
|
-
};
|
|
65300
|
-
}
|
|
65301
|
-
function serializeConfig(config) {
|
|
65302
|
-
const body = config && typeof config === "object" && !Array.isArray(config) ? config : {};
|
|
65303
|
-
const { $schema: _drop, ...rest } = body;
|
|
65304
|
-
return `${JSON.stringify({ $schema: SCHEMA_REF, ...rest }, null, 2)}
|
|
65305
|
-
`;
|
|
65306
|
-
}
|
|
65307
|
-
function backupName(path, ts) {
|
|
65308
|
-
return `${path}.bak-${ts}`;
|
|
65309
|
-
}
|
|
65310
|
-
function atomicWrite(path, text) {
|
|
65311
|
-
mkdirSync15(dirname16(path), { recursive: true });
|
|
65312
|
-
const tmp = `${path}.tmp-${process.pid}`;
|
|
65313
|
-
writeFileSync4(tmp, text, "utf8");
|
|
65314
|
-
renameSync2(tmp, path);
|
|
65315
|
-
}
|
|
65316
|
-
|
|
65317
65697
|
// src/observability/ssh-key-inventory.ts
|
|
65318
|
-
import { createHash as
|
|
65698
|
+
import { createHash as createHash8 } from "crypto";
|
|
65319
65699
|
import { constants } from "fs";
|
|
65320
65700
|
import { access, lstat, open as open2, readdir } from "fs/promises";
|
|
65321
65701
|
import { homedir as homedir3 } from "os";
|
|
@@ -65369,7 +65749,7 @@ async function listSshKeys(configuredPaths, directory = join9(homedir3(), ".ssh"
|
|
|
65369
65749
|
path,
|
|
65370
65750
|
name: basename2(path),
|
|
65371
65751
|
type: key.type,
|
|
65372
|
-
fingerprint: `SHA256:${
|
|
65752
|
+
fingerprint: `SHA256:${createHash8("sha256").update(key.getPublicSSH()).digest("base64").replace(/=+$/, "")}`,
|
|
65373
65753
|
publicKey: line,
|
|
65374
65754
|
usable
|
|
65375
65755
|
});
|
|
@@ -65526,7 +65906,7 @@ async function workspaceRoutes(req, url) {
|
|
|
65526
65906
|
}
|
|
65527
65907
|
|
|
65528
65908
|
// src/client-check/routes.ts
|
|
65529
|
-
import { readFileSync as
|
|
65909
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
65530
65910
|
import { join as join10 } from "path";
|
|
65531
65911
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
65532
65912
|
var MiB = 1048576;
|
|
@@ -65534,7 +65914,7 @@ var budgets = new Map;
|
|
|
65534
65914
|
async function clientCheckRoutes(req, url, peer = "unknown") {
|
|
65535
65915
|
if (url.pathname === "/client-check" && req.method === "GET") {
|
|
65536
65916
|
try {
|
|
65537
|
-
return new Response(
|
|
65917
|
+
return new Response(readFileSync10(join10(PROJECT_ROOT, "dist/ui/client-check.html"), "utf8"), {
|
|
65538
65918
|
headers: {
|
|
65539
65919
|
"content-type": "text/html;charset=utf-8",
|
|
65540
65920
|
"cache-control": "no-store",
|
|
@@ -65791,7 +66171,7 @@ async function roundTripRoutes(req, url) {
|
|
|
65791
66171
|
}
|
|
65792
66172
|
|
|
65793
66173
|
// src/observability/um-report-cache.ts
|
|
65794
|
-
import { createHash as
|
|
66174
|
+
import { createHash as createHash9, randomUUID as randomUUID10 } from "crypto";
|
|
65795
66175
|
import { mkdir, readFile, rename, stat, unlink, writeFile } from "fs/promises";
|
|
65796
66176
|
import { dirname as dirname17, join as join11 } from "path";
|
|
65797
66177
|
var MAX_BYTES = 32 * 1024 * 1024;
|
|
@@ -65821,7 +66201,7 @@ function umReportCachePath(device) {
|
|
|
65821
66201
|
chain.push([name, target]);
|
|
65822
66202
|
name = target?.jumpVia;
|
|
65823
66203
|
}
|
|
65824
|
-
const key =
|
|
66204
|
+
const key = createHash9("sha256").update(JSON.stringify(chain)).digest("hex");
|
|
65825
66205
|
return join11(`${config.dashboard.dbPath}.um-reports`, `${key}.json`);
|
|
65826
66206
|
}
|
|
65827
66207
|
async function loadUmReportCache(path, device, fields) {
|
|
@@ -65853,7 +66233,7 @@ async function loadUmReportCache(path, device, fields) {
|
|
|
65853
66233
|
async function saveUmReportCache(path, snapshot) {
|
|
65854
66234
|
if (!path || Object.values(snapshot.sources).some((source) => source.error))
|
|
65855
66235
|
return false;
|
|
65856
|
-
const temp = `${path}.${
|
|
66236
|
+
const temp = `${path}.${randomUUID10()}.tmp`;
|
|
65857
66237
|
try {
|
|
65858
66238
|
const text = JSON.stringify({ version: 1, snapshot });
|
|
65859
66239
|
if (Buffer.byteLength(text) > MAX_BYTES)
|
|
@@ -66419,66 +66799,13 @@ function buildUmReport(snapshot, query) {
|
|
|
66419
66799
|
};
|
|
66420
66800
|
}
|
|
66421
66801
|
|
|
66422
|
-
// src/observability/config-admin.ts
|
|
66423
|
-
function validateConfig(raw) {
|
|
66424
|
-
const r = MikrotikConfigSchema2.safeParse(raw);
|
|
66425
|
-
if (r.success)
|
|
66426
|
-
return { ok: true, errors: [], value: r.data };
|
|
66427
|
-
return {
|
|
66428
|
-
ok: false,
|
|
66429
|
-
errors: r.error.issues.map((i) => ({
|
|
66430
|
-
path: i.path.join(".") || "(root)",
|
|
66431
|
-
message: i.message
|
|
66432
|
-
}))
|
|
66433
|
-
};
|
|
66434
|
-
}
|
|
66435
|
-
function createConfigAdmin(deps) {
|
|
66436
|
-
let pending = null;
|
|
66437
|
-
const rollback = (id) => {
|
|
66438
|
-
if (!pending || pending.id !== id)
|
|
66439
|
-
return false;
|
|
66440
|
-
const { backupPath, previous, timer } = pending;
|
|
66441
|
-
deps.cancel(timer);
|
|
66442
|
-
pending = null;
|
|
66443
|
-
const backup = deps.readFile(backupPath);
|
|
66444
|
-
if (backup != null)
|
|
66445
|
-
deps.writeText(deps.source().path, backup);
|
|
66446
|
-
deps.setConfig(previous);
|
|
66447
|
-
return true;
|
|
66448
|
-
};
|
|
66449
|
-
const applyConfig = (parsed, rollbackMs) => {
|
|
66450
|
-
if (pending)
|
|
66451
|
-
deps.cancel(pending.timer);
|
|
66452
|
-
const src = deps.source();
|
|
66453
|
-
const previous = deps.getConfig();
|
|
66454
|
-
const ts = deps.now();
|
|
66455
|
-
const id = `cfg_${ts}`;
|
|
66456
|
-
const backupPath = backupName(src.path, ts);
|
|
66457
|
-
const existing = deps.readFile(src.path) ?? serializeConfig(previous);
|
|
66458
|
-
deps.writeText(backupPath, existing);
|
|
66459
|
-
deps.writeText(src.path, serializeConfig(parsed));
|
|
66460
|
-
deps.setConfig(parsed);
|
|
66461
|
-
const timer = rollbackMs > 0 ? deps.schedule(() => void rollback(id), rollbackMs) : null;
|
|
66462
|
-
pending = { id, backupPath, previous, timer };
|
|
66463
|
-
return { pendingId: id, rollbackMs, path: src.path, fromFile: src.fromFile };
|
|
66464
|
-
};
|
|
66465
|
-
const keepConfig = (id) => {
|
|
66466
|
-
if (!pending || pending.id !== id)
|
|
66467
|
-
return false;
|
|
66468
|
-
deps.cancel(pending.timer);
|
|
66469
|
-
pending = null;
|
|
66470
|
-
return true;
|
|
66471
|
-
};
|
|
66472
|
-
return { applyConfig, keepConfig, rollback, pendingId: () => pending?.id ?? null };
|
|
66473
|
-
}
|
|
66474
|
-
|
|
66475
66802
|
// src/observability/config-history.ts
|
|
66476
66803
|
import {
|
|
66477
66804
|
existsSync as existsSync5,
|
|
66478
66805
|
mkdirSync as mkdirSync16,
|
|
66479
|
-
readFileSync as
|
|
66806
|
+
readFileSync as readFileSync11,
|
|
66480
66807
|
readdirSync as readdirSync3,
|
|
66481
|
-
rmSync as
|
|
66808
|
+
rmSync as rmSync3,
|
|
66482
66809
|
statSync as statSync3,
|
|
66483
66810
|
writeFileSync as writeFileSync5
|
|
66484
66811
|
} from "fs";
|
|
@@ -66501,7 +66828,7 @@ function listVersions() {
|
|
|
66501
66828
|
if (!/^v\d+\.json$/.test(f))
|
|
66502
66829
|
continue;
|
|
66503
66830
|
try {
|
|
66504
|
-
const raw =
|
|
66831
|
+
const raw = readFileSync11(join12(dir, f), "utf8");
|
|
66505
66832
|
const parsed = JSON.parse(raw);
|
|
66506
66833
|
out.push({
|
|
66507
66834
|
id: f.replace(/\.json$/, ""),
|
|
@@ -66515,14 +66842,14 @@ function listVersions() {
|
|
|
66515
66842
|
return out.sort((a, b) => b.ts - a.ts);
|
|
66516
66843
|
}
|
|
66517
66844
|
function readVersion(id) {
|
|
66518
|
-
const raw =
|
|
66845
|
+
const raw = readFileSync11(join12(historyDir(), idToFile(id)), "utf8");
|
|
66519
66846
|
return JSON.parse(raw);
|
|
66520
66847
|
}
|
|
66521
66848
|
function deleteVersion(id) {
|
|
66522
66849
|
const p = join12(historyDir(), idToFile(id));
|
|
66523
66850
|
if (!existsSync5(p))
|
|
66524
66851
|
return false;
|
|
66525
|
-
|
|
66852
|
+
rmSync3(p);
|
|
66526
66853
|
return true;
|
|
66527
66854
|
}
|
|
66528
66855
|
function recordVersion(config, kind, now, label) {
|
|
@@ -66549,7 +66876,7 @@ function pruneAuto(dir) {
|
|
|
66549
66876
|
return;
|
|
66550
66877
|
for (const v of autos.slice(AUTO_RETENTION)) {
|
|
66551
66878
|
try {
|
|
66552
|
-
|
|
66879
|
+
rmSync3(join12(dir, `${v.id}.json`));
|
|
66553
66880
|
} catch {}
|
|
66554
66881
|
}
|
|
66555
66882
|
}
|
|
@@ -66575,7 +66902,7 @@ function historyBytes() {
|
|
|
66575
66902
|
}
|
|
66576
66903
|
|
|
66577
66904
|
// src/prompts/index.ts
|
|
66578
|
-
import { readFileSync as
|
|
66905
|
+
import { readFileSync as readFileSync12, readdirSync as readdirSync4 } from "fs";
|
|
66579
66906
|
import { join as join13 } from "path";
|
|
66580
66907
|
|
|
66581
66908
|
// src/txn/guidance.ts
|
|
@@ -66647,7 +66974,11 @@ function substitutePrompt(body, vars) {
|
|
|
66647
66974
|
const value = Object.hasOwn(vars, key) ? vars[key] : undefined;
|
|
66648
66975
|
if (value === undefined || value === null || value === "")
|
|
66649
66976
|
return whole;
|
|
66650
|
-
|
|
66977
|
+
if (typeof value === "string")
|
|
66978
|
+
return value;
|
|
66979
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint")
|
|
66980
|
+
return String(value);
|
|
66981
|
+
return JSON.stringify(value) ?? whole;
|
|
66651
66982
|
});
|
|
66652
66983
|
}
|
|
66653
66984
|
|
|
@@ -66722,7 +67053,7 @@ function listPrompts() {
|
|
|
66722
67053
|
const out = [];
|
|
66723
67054
|
for (const file of files) {
|
|
66724
67055
|
try {
|
|
66725
|
-
const parsed = parseFrontmatter(
|
|
67056
|
+
const parsed = parseFrontmatter(readFileSync12(join13(PROMPTS_DIR, file), "utf8"));
|
|
66726
67057
|
if (parsed) {
|
|
66727
67058
|
out.push({
|
|
66728
67059
|
name: parsed.name,
|
|
@@ -66749,7 +67080,7 @@ function registerPrompts(server, opts = {}) {
|
|
|
66749
67080
|
for (const file of files) {
|
|
66750
67081
|
let parsed;
|
|
66751
67082
|
try {
|
|
66752
|
-
parsed = parseFrontmatter(
|
|
67083
|
+
parsed = parseFrontmatter(readFileSync12(join13(PROMPTS_DIR, file), "utf8"));
|
|
66753
67084
|
} catch (e) {
|
|
66754
67085
|
logger.warn(`Skipping prompt ${file}: ${String(e)}`);
|
|
66755
67086
|
continue;
|
|
@@ -68156,7 +68487,7 @@ async function postureRoutes(req, url) {
|
|
|
68156
68487
|
}
|
|
68157
68488
|
|
|
68158
68489
|
// src/observability/access-settings.ts
|
|
68159
|
-
import { createHash as
|
|
68490
|
+
import { createHash as createHash10 } from "crypto";
|
|
68160
68491
|
var list2 = array(string2().trim().min(1).max(200)).max(200);
|
|
68161
68492
|
var accessSchema = AccessConfigSchema2.extend({
|
|
68162
68493
|
devices: list2,
|
|
@@ -68186,7 +68517,7 @@ function createAccessSettingsRoutes(admin, deps = {
|
|
|
68186
68517
|
}) {
|
|
68187
68518
|
let pending = null;
|
|
68188
68519
|
const tools = moduleCatalog2.flatMap((m) => m.tools.map((t) => ({ name: t.name, risk: riskOf(t.annotations), noDevice: !!t.noDevice })));
|
|
68189
|
-
const revision = () =>
|
|
68520
|
+
const revision = () => createHash10("sha256").update(JSON.stringify([deps.getConfig(), deps.getAccessPolicy()])).digest("hex");
|
|
68190
68521
|
const payload = () => {
|
|
68191
68522
|
const cfg = deps.getConfig();
|
|
68192
68523
|
const id = admin.pendingId();
|
|
@@ -69701,7 +70032,7 @@ spawn error: ${String(e)}` });
|
|
|
69701
70032
|
}
|
|
69702
70033
|
function dashboardHtml() {
|
|
69703
70034
|
try {
|
|
69704
|
-
return
|
|
70035
|
+
return readFileSync13(join15(UI_DIST_DIR, "observability.html"), "utf8");
|
|
69705
70036
|
} catch {
|
|
69706
70037
|
return `<!doctype html><meta charset=utf-8><body style="font:14px system-ui;padding:24px;background:#0b0d10;color:#e8eaed">
|
|
69707
70038
|
<h2>MikroTik MCP \u2014 Observability Dashboard</h2>
|
|
@@ -70761,25 +71092,7 @@ async function runDashboard(cfg, transportLabel) {
|
|
|
70761
71092
|
} catch (e) {
|
|
70762
71093
|
logger.warn(`[${SERVER_TAG3}] could not seed config history baseline: ${String(e)}`);
|
|
70763
71094
|
}
|
|
70764
|
-
const configAdmin =
|
|
70765
|
-
getConfig,
|
|
70766
|
-
setConfig,
|
|
70767
|
-
source: getConfigSource2,
|
|
70768
|
-
readFile: (pth) => {
|
|
70769
|
-
try {
|
|
70770
|
-
return readFileSync12(pth, "utf8");
|
|
70771
|
-
} catch {
|
|
70772
|
-
return null;
|
|
70773
|
-
}
|
|
70774
|
-
},
|
|
70775
|
-
writeText: atomicWrite,
|
|
70776
|
-
now: Date.now,
|
|
70777
|
-
schedule: (fn, ms) => setTimeout(fn, ms),
|
|
70778
|
-
cancel: (h) => {
|
|
70779
|
-
if (h)
|
|
70780
|
-
clearTimeout(h);
|
|
70781
|
-
}
|
|
70782
|
-
});
|
|
71095
|
+
const configAdmin = getConfigAdmin();
|
|
70783
71096
|
const tokenOk = (req, url) => {
|
|
70784
71097
|
if (!cfg.token)
|
|
70785
71098
|
return true;
|
|
@@ -71060,7 +71373,9 @@ async function runDashboard(cfg, transportLabel) {
|
|
|
71060
71373
|
}
|
|
71061
71374
|
if (url.pathname === "/api/upgrade" && req.method === "POST") {
|
|
71062
71375
|
const body = await readJson(req);
|
|
71063
|
-
|
|
71376
|
+
if (body?.version != null && typeof body.version !== "string")
|
|
71377
|
+
return json15({ ok: false, error: 'Version must be "latest" or an x.y.z string.' }, 400);
|
|
71378
|
+
const version = body?.version ?? "latest";
|
|
71064
71379
|
if (version !== "latest" && !/^\d+\.\d+\.\d+$/.test(version)) {
|
|
71065
71380
|
return json15({ ok: false, error: `Invalid version "${version}" (use "latest" or x.y.z).` }, 400);
|
|
71066
71381
|
}
|
|
@@ -71189,7 +71504,7 @@ async function runDashboard(cfg, transportLabel) {
|
|
|
71189
71504
|
}
|
|
71190
71505
|
|
|
71191
71506
|
// src/transport/http.ts
|
|
71192
|
-
import { randomUUID as
|
|
71507
|
+
import { randomUUID as randomUUID11 } from "crypto";
|
|
71193
71508
|
var {serve: serve2 } = globalThis.Bun;
|
|
71194
71509
|
|
|
71195
71510
|
// node_modules/content-type/index.js
|
|
@@ -80484,6 +80799,22 @@ ${TRANSACTION_WORKFLOW}`;
|
|
|
80484
80799
|
}
|
|
80485
80800
|
if (getConfig().memory.enabled)
|
|
80486
80801
|
instructions += MEMORY_INSTRUCTIONS;
|
|
80802
|
+
if (!readOnly && availableTools.has("update_mcp_settings")) {
|
|
80803
|
+
instructions += `
|
|
80804
|
+
|
|
80805
|
+
MCP host settings (not RouterOS configuration):
|
|
80806
|
+
Use get_mcp_settings_schema, then get_mcp_settings and preview_mcp_settings.
|
|
80807
|
+
Show changed fields and restart requirements; apply only explicit user-approved
|
|
80808
|
+
changes with update_mcp_settings, the preview revision and confirm=true.
|
|
80809
|
+
Read back with get_mcp_settings; confirm_mcp_settings before the deadline or
|
|
80810
|
+
rollback_mcp_settings. The tool creates a local config backup automatically;
|
|
80811
|
+
no router snapshot or device argument is needed. Never restart while pending:
|
|
80812
|
+
the rollback timer only runs while this process is alive. Configured values do
|
|
80813
|
+
not prove startup-only components are active; restart separately after confirmation.
|
|
80814
|
+
Protected settings (devices, credentials, listeners, paths, access, readOnly,
|
|
80815
|
+
tool restrictions and probe allowlists) require the operator, not a workaround.
|
|
80816
|
+
If another workflow owns a pending change, finish it there before applying.`;
|
|
80817
|
+
}
|
|
80487
80818
|
if (!getConfig().disableUpdateCheck) {
|
|
80488
80819
|
const cached = loadFileCacheSync();
|
|
80489
80820
|
if (cached) {
|
|
@@ -80595,7 +80926,7 @@ async function runHttp(mcp) {
|
|
|
80595
80926
|
if (existing)
|
|
80596
80927
|
return existing;
|
|
80597
80928
|
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
80598
|
-
sessionIdGenerator: () =>
|
|
80929
|
+
sessionIdGenerator: () => randomUUID11(),
|
|
80599
80930
|
enableJsonResponse: true,
|
|
80600
80931
|
...security,
|
|
80601
80932
|
onsessioninitialized: (id) => {
|
|
@@ -80889,7 +81220,7 @@ async function lastSeen(t) {
|
|
|
80889
81220
|
newest = at;
|
|
80890
81221
|
}
|
|
80891
81222
|
} catch (e) {
|
|
80892
|
-
logger.debug(`[alerts] snapshot lookup failed: ${e instanceof Error ? e.message : e}`);
|
|
81223
|
+
logger.debug(`[alerts] snapshot lookup failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
80893
81224
|
return Date.now();
|
|
80894
81225
|
}
|
|
80895
81226
|
return newest;
|
|
@@ -81152,7 +81483,11 @@ export {
|
|
|
81152
81483
|
DEFAULT_SNAPSHOT_DB2,
|
|
81153
81484
|
DEFAULT_BACKUP_DIR2,
|
|
81154
81485
|
DEFAULT_CONFIG_HISTORY_DIR2,
|
|
81486
|
+
McpServerSettingsSchema2,
|
|
81155
81487
|
DeviceConfigSchema2,
|
|
81488
|
+
DashboardConfigSchema2,
|
|
81489
|
+
MemoryConfigSchema2,
|
|
81490
|
+
SSHConfigSchema2,
|
|
81156
81491
|
ToolFilterSchema2,
|
|
81157
81492
|
AccessConfigSchema2,
|
|
81158
81493
|
MikrotikConfigSchema2,
|