@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/index.js
CHANGED
|
@@ -62,7 +62,7 @@ import {
|
|
|
62
62
|
updateSummaryLine,
|
|
63
63
|
allToolModules2,
|
|
64
64
|
selectToolModules2
|
|
65
|
-
} from "./shared/library-
|
|
65
|
+
} from "./shared/library-7wcv2ckk.js";
|
|
66
66
|
|
|
67
67
|
// node_modules/ajv/dist/compile/codegen/code.js
|
|
68
68
|
var require_code = __commonJS(function(exports) {
|
|
@@ -15004,7 +15004,11 @@ function substitutePrompt(body, vars) {
|
|
|
15004
15004
|
const value = Object.hasOwn(vars, key) ? vars[key] : undefined;
|
|
15005
15005
|
if (value === undefined || value === null || value === "")
|
|
15006
15006
|
return whole;
|
|
15007
|
-
|
|
15007
|
+
if (typeof value === "string")
|
|
15008
|
+
return value;
|
|
15009
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint")
|
|
15010
|
+
return String(value);
|
|
15011
|
+
return JSON.stringify(value) ?? whole;
|
|
15008
15012
|
});
|
|
15009
15013
|
}
|
|
15010
15014
|
|
|
@@ -15245,6 +15249,22 @@ ${TRANSACTION_WORKFLOW}`;
|
|
|
15245
15249
|
}
|
|
15246
15250
|
if (getConfig2().memory.enabled)
|
|
15247
15251
|
instructions += MEMORY_INSTRUCTIONS;
|
|
15252
|
+
if (!readOnly && availableTools.has("update_mcp_settings")) {
|
|
15253
|
+
instructions += `
|
|
15254
|
+
|
|
15255
|
+
MCP host settings (not RouterOS configuration):
|
|
15256
|
+
Use get_mcp_settings_schema, then get_mcp_settings and preview_mcp_settings.
|
|
15257
|
+
Show changed fields and restart requirements; apply only explicit user-approved
|
|
15258
|
+
changes with update_mcp_settings, the preview revision and confirm=true.
|
|
15259
|
+
Read back with get_mcp_settings; confirm_mcp_settings before the deadline or
|
|
15260
|
+
rollback_mcp_settings. The tool creates a local config backup automatically;
|
|
15261
|
+
no router snapshot or device argument is needed. Never restart while pending:
|
|
15262
|
+
the rollback timer only runs while this process is alive. Configured values do
|
|
15263
|
+
not prove startup-only components are active; restart separately after confirmation.
|
|
15264
|
+
Protected settings (devices, credentials, listeners, paths, access, readOnly,
|
|
15265
|
+
tool restrictions and probe allowlists) require the operator, not a workaround.
|
|
15266
|
+
If another workflow owns a pending change, finish it there before applying.`;
|
|
15267
|
+
}
|
|
15248
15268
|
if (!getConfig2().disableUpdateCheck) {
|
|
15249
15269
|
const cached = loadFileCacheSync();
|
|
15250
15270
|
if (cached) {
|
|
@@ -4,7 +4,11 @@ import {
|
|
|
4
4
|
DEFAULT_SNAPSHOT_DB2,
|
|
5
5
|
DEFAULT_BACKUP_DIR2,
|
|
6
6
|
DEFAULT_CONFIG_HISTORY_DIR2,
|
|
7
|
+
McpServerSettingsSchema2,
|
|
7
8
|
DeviceConfigSchema2,
|
|
9
|
+
DashboardConfigSchema2,
|
|
10
|
+
MemoryConfigSchema2,
|
|
11
|
+
SSHConfigSchema2,
|
|
8
12
|
ToolFilterSchema2,
|
|
9
13
|
AccessConfigSchema2,
|
|
10
14
|
MikrotikConfigSchema2,
|
|
@@ -17,8 +21,12 @@ export {
|
|
|
17
21
|
DEFAULT_CONFIG_HISTORY_DIR2 as DEFAULT_CONFIG_HISTORY_DIR,
|
|
18
22
|
DEFAULT_DASHBOARD_DB2 as DEFAULT_DASHBOARD_DB,
|
|
19
23
|
DEFAULT_SNAPSHOT_DB2 as DEFAULT_SNAPSHOT_DB,
|
|
24
|
+
DashboardConfigSchema2 as DashboardConfigSchema,
|
|
20
25
|
DeviceConfigSchema2 as DeviceConfigSchema,
|
|
26
|
+
McpServerSettingsSchema2 as McpServerSettingsSchema,
|
|
27
|
+
MemoryConfigSchema2 as MemoryConfigSchema,
|
|
21
28
|
MikrotikConfigSchema2 as MikrotikConfigSchema,
|
|
29
|
+
SSHConfigSchema2 as SSHConfigSchema,
|
|
22
30
|
ToolFilterSchema2 as ToolFilterSchema,
|
|
23
31
|
getConfigSource2 as getConfigSource,
|
|
24
32
|
loadConfig2 as loadConfig
|
|
@@ -8446,7 +8446,7 @@ var DEFAULT_BACKUP_DIR2 = join(homedir(), ".mikrotik-mcp", "backups");
|
|
|
8446
8446
|
var DEFAULT_CONFIG_HISTORY_DIR = join(homedir(), ".mikrotik-mcp", "config-history");
|
|
8447
8447
|
var DEFAULT_CONFIG_FILE = join(homedir(), ".mikrotik-mcp", "config.json");
|
|
8448
8448
|
var TransportSchema = _enum(["stdio", "sse", "streamable-http"]);
|
|
8449
|
-
var
|
|
8449
|
+
var McpServerSettingsSchema2 = object({
|
|
8450
8450
|
transport: TransportSchema.default("stdio"),
|
|
8451
8451
|
host: string().default("0.0.0.0"),
|
|
8452
8452
|
port: exports_coerce.number().int().positive().default(8000),
|
|
@@ -8578,7 +8578,7 @@ var SchedulesConfigSchema = object({
|
|
|
8578
8578
|
tickSeconds: exports_coerce.number().int().positive().default(30),
|
|
8579
8579
|
retainDays: exports_coerce.number().int().positive().default(90)
|
|
8580
8580
|
});
|
|
8581
|
-
var
|
|
8581
|
+
var DashboardConfigSchema2 = object({
|
|
8582
8582
|
enabled: boolean().default(false),
|
|
8583
8583
|
host: string().default("0.0.0.0"),
|
|
8584
8584
|
port: exports_coerce.number().int().positive().default(9090),
|
|
@@ -8590,11 +8590,11 @@ var DashboardConfigSchema = object({
|
|
|
8590
8590
|
token: string().optional(),
|
|
8591
8591
|
feedLimit: exports_coerce.number().int().positive().max(1e4).default(200)
|
|
8592
8592
|
});
|
|
8593
|
-
var
|
|
8593
|
+
var MemoryConfigSchema2 = object({
|
|
8594
8594
|
enabled: boolean().default(true),
|
|
8595
8595
|
dbPath: string().default(DEFAULT_MEMORY_DB)
|
|
8596
8596
|
});
|
|
8597
|
-
var
|
|
8597
|
+
var SSHConfigSchema2 = object({
|
|
8598
8598
|
keepAlive: boolean().default(true),
|
|
8599
8599
|
keepAliveInterval: exports_coerce.number().int().nonnegative().default(1e4),
|
|
8600
8600
|
idleTimeout: exports_coerce.number().int().positive().default(30000)
|
|
@@ -8618,19 +8618,19 @@ var MikrotikConfigSchema2 = object({
|
|
|
8618
8618
|
serviceProbes: ServiceProbeConfigSchema.default(() => ServiceProbeConfigSchema.parse({})),
|
|
8619
8619
|
devices: record(string(), DeviceConfigSchema2).default(() => ({ default: DeviceConfigSchema2.parse({}) })),
|
|
8620
8620
|
defaultDevice: string().default("default"),
|
|
8621
|
-
mcp:
|
|
8621
|
+
mcp: McpServerSettingsSchema2.default(() => McpServerSettingsSchema2.parse({})),
|
|
8622
8622
|
s3: S3ConfigSchema.optional(),
|
|
8623
|
-
dashboard:
|
|
8623
|
+
dashboard: DashboardConfigSchema2.default(() => DashboardConfigSchema2.parse({})),
|
|
8624
8624
|
alerts: AlertsConfigSchema.optional(),
|
|
8625
8625
|
flows: FlowsConfigSchema.default(() => FlowsConfigSchema.parse({})),
|
|
8626
8626
|
policy: PolicyConfigSchema.default(() => PolicyConfigSchema.parse({})),
|
|
8627
8627
|
schedules: SchedulesConfigSchema.default(() => SchedulesConfigSchema.parse({})),
|
|
8628
8628
|
attacks: AttacksConfigSchema.default(() => AttacksConfigSchema.parse({})),
|
|
8629
|
-
ssh:
|
|
8629
|
+
ssh: SSHConfigSchema2.default(() => SSHConfigSchema2.parse({})),
|
|
8630
8630
|
readOnly: boolean().default(false),
|
|
8631
8631
|
access: AccessConfigSchema.default(() => AccessConfigSchema.parse({})),
|
|
8632
8632
|
tools: ToolFilterSchema.default(() => ToolFilterSchema.parse({})),
|
|
8633
|
-
memory:
|
|
8633
|
+
memory: MemoryConfigSchema2.default(() => MemoryConfigSchema2.parse({})),
|
|
8634
8634
|
backupDir: string().optional(),
|
|
8635
8635
|
disableUpdateCheck: boolean().default(false)
|
|
8636
8636
|
});
|
|
@@ -8715,6 +8715,9 @@ function parseDevicesSource(raw, fromFile) {
|
|
|
8715
8715
|
};
|
|
8716
8716
|
}
|
|
8717
8717
|
var configSource = { path: DEFAULT_CONFIG_FILE, fromFile: false };
|
|
8718
|
+
function getConfigSource2() {
|
|
8719
|
+
return configSource;
|
|
8720
|
+
}
|
|
8718
8721
|
function loadConfig2(argv = process.argv.slice(2)) {
|
|
8719
8722
|
const flags = parseFlags(argv);
|
|
8720
8723
|
const pick = (flag, ...envNames) => flags[flag] ?? env(...envNames);
|
|
@@ -11372,10 +11375,10 @@ function toConsoleText(json, req) {
|
|
|
11372
11375
|
const entries = Object.entries(json);
|
|
11373
11376
|
if (entries.length === 0)
|
|
11374
11377
|
return "";
|
|
11375
|
-
return entries.map(([k, v]) => ` ${k}: ${typeof v === "string" ? v :
|
|
11378
|
+
return entries.map(([k, v]) => ` ${k}: ${typeof v === "string" ? v : JSON.stringify(v) ?? ""}`).join(`
|
|
11376
11379
|
`);
|
|
11377
11380
|
}
|
|
11378
|
-
return
|
|
11381
|
+
return typeof json === "string" ? json : JSON.stringify(json) ?? "";
|
|
11379
11382
|
}
|
|
11380
11383
|
|
|
11381
11384
|
// src/rest/client.ts
|
|
@@ -12227,7 +12230,7 @@ async function tryProbe(command, ctx) {
|
|
|
12227
12230
|
return null;
|
|
12228
12231
|
return out;
|
|
12229
12232
|
} catch (e) {
|
|
12230
|
-
logger.debug(`[capability] probe '${command}' failed: ${e instanceof Error ? e.message : e}`);
|
|
12233
|
+
logger.debug(`[capability] probe '${command}' failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
12231
12234
|
return null;
|
|
12232
12235
|
}
|
|
12233
12236
|
}
|
|
@@ -14821,13 +14824,13 @@ async function undoMigration(id, confirm, selected) {
|
|
|
14821
14824
|
throw new Error("Undo lost Safe Mode or exceeded its time budget.");
|
|
14822
14825
|
await checkedRead(item.undo, createContext(undefined, device));
|
|
14823
14826
|
}
|
|
14824
|
-
const beforeTarget = (await import("./library-
|
|
14825
|
-
const db = await beforeTarget((await import("./library-
|
|
14827
|
+
const beforeTarget = (await import("./library-ppnv0f07.js")).openSnapshotStore;
|
|
14828
|
+
const db = await beforeTarget((await import("./library-f3be6g03.js")).DEFAULT_SNAPSHOT_DB);
|
|
14826
14829
|
try {
|
|
14827
14830
|
const original = db.get(p.snapshots.target);
|
|
14828
14831
|
if (!original)
|
|
14829
14832
|
throw new Error("Original target snapshot unavailable.");
|
|
14830
|
-
const { normalizeExport } = await import("./library-
|
|
14833
|
+
const { normalizeExport } = await import("./library-tqrvrykj.js");
|
|
14831
14834
|
if (normalizeExport((await migrationInventory(device)).export) !== normalizeExport(original.body))
|
|
14832
14835
|
throw new Error("Target differs from its backup. Undo verification failed.");
|
|
14833
14836
|
} finally {
|
|
@@ -25425,7 +25428,7 @@ var cache2 = null;
|
|
|
25425
25428
|
async function gateway() {
|
|
25426
25429
|
if (cache2)
|
|
25427
25430
|
return cache2;
|
|
25428
|
-
const { moduleCatalog } = await import("./library-
|
|
25431
|
+
const { moduleCatalog } = await import("./library-z7qsdq88.js");
|
|
25429
25432
|
const forIndex = [];
|
|
25430
25433
|
const byName = new Map;
|
|
25431
25434
|
for (const mod of moduleCatalog) {
|
|
@@ -47424,7 +47427,7 @@ var riskByTool = null;
|
|
|
47424
47427
|
async function riskIndex() {
|
|
47425
47428
|
if (riskByTool)
|
|
47426
47429
|
return riskByTool;
|
|
47427
|
-
const { moduleCatalog } = await import("./library-
|
|
47430
|
+
const { moduleCatalog } = await import("./library-z7qsdq88.js");
|
|
47428
47431
|
const index = new Map;
|
|
47429
47432
|
for (const mod of moduleCatalog) {
|
|
47430
47433
|
for (const tool of mod.tools)
|
|
@@ -50933,8 +50936,389 @@ var serverPulseTools = [
|
|
|
50933
50936
|
})
|
|
50934
50937
|
];
|
|
50935
50938
|
|
|
50939
|
+
// src/observability/config-admin.ts
|
|
50940
|
+
import { createHash as createHash7, randomUUID as randomUUID9 } from "crypto";
|
|
50941
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
50942
|
+
|
|
50943
|
+
// src/config-write.ts
|
|
50944
|
+
import { randomUUID as randomUUID8 } from "crypto";
|
|
50945
|
+
import { mkdirSync as mkdirSync15, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
50946
|
+
import { dirname as dirname16 } from "path";
|
|
50947
|
+
var SCHEMA_REF = "./schemas/config.schema.json";
|
|
50948
|
+
function serializeConfig(config) {
|
|
50949
|
+
const body = config && typeof config === "object" && !Array.isArray(config) ? config : {};
|
|
50950
|
+
const { $schema: _drop, ...rest } = body;
|
|
50951
|
+
return `${JSON.stringify({ $schema: SCHEMA_REF, ...rest }, null, 2)}
|
|
50952
|
+
`;
|
|
50953
|
+
}
|
|
50954
|
+
function backupName(path, ts) {
|
|
50955
|
+
return `${path}.bak-${ts}`;
|
|
50956
|
+
}
|
|
50957
|
+
function atomicWrite(path, text) {
|
|
50958
|
+
mkdirSync15(dirname16(path), { recursive: true });
|
|
50959
|
+
const tmp = `${path}.tmp-${randomUUID8()}`;
|
|
50960
|
+
try {
|
|
50961
|
+
writeFileSync4(tmp, text, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
50962
|
+
renameSync2(tmp, path);
|
|
50963
|
+
} finally {
|
|
50964
|
+
rmSync2(tmp, { force: true });
|
|
50965
|
+
}
|
|
50966
|
+
}
|
|
50967
|
+
|
|
50968
|
+
// src/observability/config-admin.ts
|
|
50969
|
+
function createConfigAdmin(deps) {
|
|
50970
|
+
let pending = null;
|
|
50971
|
+
let lastTimestamp = 0;
|
|
50972
|
+
const salt = randomUUID9();
|
|
50973
|
+
const fingerprint = (config, source, contents) => createHash7("sha256").update(salt).update(JSON.stringify([config, source, contents])).digest("hex");
|
|
50974
|
+
const revision = () => {
|
|
50975
|
+
const source = deps.source();
|
|
50976
|
+
return fingerprint(deps.getConfig(), source, deps.readFile(source.path));
|
|
50977
|
+
};
|
|
50978
|
+
const currentPending = () => {
|
|
50979
|
+
if (pending && pending.revision !== revision()) {
|
|
50980
|
+
deps.cancel(pending.timer);
|
|
50981
|
+
pending = null;
|
|
50982
|
+
logger.warn("Config changed outside its pending transaction; preserved newer settings. Backup retained.");
|
|
50983
|
+
}
|
|
50984
|
+
return pending;
|
|
50985
|
+
};
|
|
50986
|
+
const rollback = (id) => {
|
|
50987
|
+
const active = currentPending();
|
|
50988
|
+
if (!active || active.id !== id)
|
|
50989
|
+
return false;
|
|
50990
|
+
const { backupPath, previous, timer, path } = active;
|
|
50991
|
+
const backup = deps.readFile(backupPath);
|
|
50992
|
+
if (backup == null)
|
|
50993
|
+
throw new Error("Configuration backup is unavailable; rollback was not applied.");
|
|
50994
|
+
deps.writeText(path, backup);
|
|
50995
|
+
deps.setConfig(previous);
|
|
50996
|
+
deps.cancel(timer);
|
|
50997
|
+
pending = null;
|
|
50998
|
+
return true;
|
|
50999
|
+
};
|
|
51000
|
+
const applyConfig = (parsed, rollbackMs) => {
|
|
51001
|
+
if ((currentPending()?.rollbackMs ?? 0) > 0)
|
|
51002
|
+
throw new Error("Another configuration change awaits confirmation. Keep or roll it back first.");
|
|
51003
|
+
const src = deps.source();
|
|
51004
|
+
const previous = deps.getConfig();
|
|
51005
|
+
const ts = Math.max(deps.now(), lastTimestamp + 1);
|
|
51006
|
+
lastTimestamp = ts;
|
|
51007
|
+
const id = `cfg_${ts}`;
|
|
51008
|
+
const backupPath = backupName(src.path, ts);
|
|
51009
|
+
const existing = deps.readFile(src.path) ?? serializeConfig(previous);
|
|
51010
|
+
const contents = serializeConfig(parsed);
|
|
51011
|
+
const nextRevision = fingerprint(parsed, src, contents);
|
|
51012
|
+
deps.writeText(backupPath, existing);
|
|
51013
|
+
deps.writeText(src.path, contents);
|
|
51014
|
+
deps.setConfig(parsed);
|
|
51015
|
+
const timer = rollbackMs > 0 ? deps.schedule(() => {
|
|
51016
|
+
try {
|
|
51017
|
+
rollback(id);
|
|
51018
|
+
} catch {
|
|
51019
|
+
logger.error("Configuration auto-rollback failed; backup retained. Retry rollback or restore it manually.");
|
|
51020
|
+
}
|
|
51021
|
+
}, rollbackMs) : null;
|
|
51022
|
+
pending = {
|
|
51023
|
+
id,
|
|
51024
|
+
backupPath,
|
|
51025
|
+
previous,
|
|
51026
|
+
timer,
|
|
51027
|
+
rollbackMs,
|
|
51028
|
+
path: src.path,
|
|
51029
|
+
revision: nextRevision
|
|
51030
|
+
};
|
|
51031
|
+
return {
|
|
51032
|
+
pendingId: id,
|
|
51033
|
+
rollbackMs,
|
|
51034
|
+
path: src.path,
|
|
51035
|
+
fromFile: src.fromFile,
|
|
51036
|
+
backupPath,
|
|
51037
|
+
expiresAt: rollbackMs > 0 ? deps.now() + rollbackMs : null
|
|
51038
|
+
};
|
|
51039
|
+
};
|
|
51040
|
+
const keepConfig = (id) => {
|
|
51041
|
+
const active = currentPending();
|
|
51042
|
+
if (!active || active.id !== id)
|
|
51043
|
+
return false;
|
|
51044
|
+
deps.cancel(active.timer);
|
|
51045
|
+
pending = null;
|
|
51046
|
+
return true;
|
|
51047
|
+
};
|
|
51048
|
+
return {
|
|
51049
|
+
applyConfig,
|
|
51050
|
+
keepConfig,
|
|
51051
|
+
rollback,
|
|
51052
|
+
pendingId: () => {
|
|
51053
|
+
const active = currentPending();
|
|
51054
|
+
return active && active.rollbackMs > 0 ? active.id : null;
|
|
51055
|
+
},
|
|
51056
|
+
revision
|
|
51057
|
+
};
|
|
51058
|
+
}
|
|
51059
|
+
var sharedAdmin;
|
|
51060
|
+
function getConfigAdmin() {
|
|
51061
|
+
return sharedAdmin ??= createConfigAdmin({
|
|
51062
|
+
getConfig: getConfig2,
|
|
51063
|
+
setConfig: setConfig2,
|
|
51064
|
+
source: getConfigSource2,
|
|
51065
|
+
readFile: (path) => {
|
|
51066
|
+
try {
|
|
51067
|
+
return readFileSync9(path, "utf8");
|
|
51068
|
+
} catch (error) {
|
|
51069
|
+
if (error.code === "ENOENT")
|
|
51070
|
+
return null;
|
|
51071
|
+
throw new Error("Cannot read the MCP configuration file; check host-side file permissions.");
|
|
51072
|
+
}
|
|
51073
|
+
},
|
|
51074
|
+
writeText: atomicWrite,
|
|
51075
|
+
now: Date.now,
|
|
51076
|
+
schedule: (fn, ms) => setTimeout(fn, ms),
|
|
51077
|
+
cancel: (timer) => {
|
|
51078
|
+
if (timer)
|
|
51079
|
+
clearTimeout(timer);
|
|
51080
|
+
}
|
|
51081
|
+
});
|
|
51082
|
+
}
|
|
51083
|
+
|
|
51084
|
+
// src/core/mcp-settings.ts
|
|
51085
|
+
var McpSettingsPatchSchema = object({
|
|
51086
|
+
mcp: object({
|
|
51087
|
+
toolPageSize: McpServerSettingsSchema2.shape.toolPageSize.removeDefault().optional(),
|
|
51088
|
+
appViews: McpServerSettingsSchema2.shape.appViews.removeDefault().optional(),
|
|
51089
|
+
capabilityGating: McpServerSettingsSchema2.shape.capabilityGating.removeDefault().optional()
|
|
51090
|
+
}).strict().optional(),
|
|
51091
|
+
ssh: object({
|
|
51092
|
+
keepAlive: SSHConfigSchema2.shape.keepAlive.removeDefault().optional(),
|
|
51093
|
+
keepAliveInterval: SSHConfigSchema2.shape.keepAliveInterval.removeDefault().optional(),
|
|
51094
|
+
idleTimeout: SSHConfigSchema2.shape.idleTimeout.removeDefault().optional()
|
|
51095
|
+
}).strict().optional(),
|
|
51096
|
+
dashboard: object({
|
|
51097
|
+
maxEvents: DashboardConfigSchema2.shape.maxEvents.removeDefault().optional(),
|
|
51098
|
+
captureBody: DashboardConfigSchema2.shape.captureBody.removeDefault().optional(),
|
|
51099
|
+
redactInput: literal(true).optional().describe("May enable redaction, never disable it."),
|
|
51100
|
+
maxBodyBytes: DashboardConfigSchema2.shape.maxBodyBytes.removeDefault().optional(),
|
|
51101
|
+
feedLimit: DashboardConfigSchema2.shape.feedLimit.removeDefault().optional()
|
|
51102
|
+
}).strict().optional(),
|
|
51103
|
+
memory: object({
|
|
51104
|
+
enabled: MemoryConfigSchema2.shape.enabled.removeDefault().optional()
|
|
51105
|
+
}).strict().optional(),
|
|
51106
|
+
disableUpdateCheck: MikrotikConfigSchema2.shape.disableUpdateCheck.removeDefault().optional()
|
|
51107
|
+
}).strict();
|
|
51108
|
+
var McpSettingsUpdateSchema = object({
|
|
51109
|
+
changes: McpSettingsPatchSchema,
|
|
51110
|
+
revision: string().length(64).describe("Current revision from get_mcp_settings or preview_mcp_settings."),
|
|
51111
|
+
confirm: literal(true).describe("Only set after the user authorizes these exact changes."),
|
|
51112
|
+
rollback_seconds: number().int().min(30).max(600).default(60)
|
|
51113
|
+
}).strict();
|
|
51114
|
+
var McpSettingsPendingSchema = object({
|
|
51115
|
+
pending_id: string().min(1),
|
|
51116
|
+
revision: string().length(64).describe("Revision returned by update_mcp_settings or get_mcp_settings.")
|
|
51117
|
+
}).strict();
|
|
51118
|
+
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.";
|
|
51119
|
+
function settings(cfg) {
|
|
51120
|
+
return {
|
|
51121
|
+
mcp: {
|
|
51122
|
+
toolPageSize: cfg.mcp.toolPageSize,
|
|
51123
|
+
appViews: cfg.mcp.appViews,
|
|
51124
|
+
capabilityGating: cfg.mcp.capabilityGating
|
|
51125
|
+
},
|
|
51126
|
+
ssh: {
|
|
51127
|
+
keepAlive: cfg.ssh.keepAlive,
|
|
51128
|
+
keepAliveInterval: cfg.ssh.keepAliveInterval,
|
|
51129
|
+
idleTimeout: cfg.ssh.idleTimeout
|
|
51130
|
+
},
|
|
51131
|
+
dashboard: {
|
|
51132
|
+
maxEvents: cfg.dashboard.maxEvents,
|
|
51133
|
+
captureBody: cfg.dashboard.captureBody,
|
|
51134
|
+
redactInput: cfg.dashboard.redactInput,
|
|
51135
|
+
maxBodyBytes: cfg.dashboard.maxBodyBytes,
|
|
51136
|
+
feedLimit: cfg.dashboard.feedLimit
|
|
51137
|
+
},
|
|
51138
|
+
memory: { enabled: cfg.memory.enabled },
|
|
51139
|
+
disableUpdateCheck: cfg.disableUpdateCheck
|
|
51140
|
+
};
|
|
51141
|
+
}
|
|
51142
|
+
function createMcpSettingsService(deps) {
|
|
51143
|
+
let owned = null;
|
|
51144
|
+
const read = () => {
|
|
51145
|
+
const id = deps.admin.pendingId();
|
|
51146
|
+
const source = deps.source();
|
|
51147
|
+
return {
|
|
51148
|
+
revision: deps.admin.revision(),
|
|
51149
|
+
settings: settings(deps.getConfig()),
|
|
51150
|
+
pending: id ? { id, owned: id === owned?.id, expiresAt: id === owned?.id ? owned.expiresAt : null } : null,
|
|
51151
|
+
persistence: {
|
|
51152
|
+
path: source.path,
|
|
51153
|
+
fromFile: source.fromFile,
|
|
51154
|
+
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."
|
|
51155
|
+
},
|
|
51156
|
+
boundary: BOUNDARY
|
|
51157
|
+
};
|
|
51158
|
+
};
|
|
51159
|
+
const prepare = (raw) => {
|
|
51160
|
+
const parsed = McpSettingsPatchSchema.safeParse(raw);
|
|
51161
|
+
if (!parsed.success)
|
|
51162
|
+
throw new Error("Invalid or protected MCP setting. Use get_mcp_settings_schema for allowed fields and values.");
|
|
51163
|
+
const changes = parsed.data;
|
|
51164
|
+
const current = deps.getConfig();
|
|
51165
|
+
const next = MikrotikConfigSchema2.parse({
|
|
51166
|
+
...current,
|
|
51167
|
+
...changes,
|
|
51168
|
+
mcp: { ...current.mcp, ...changes.mcp },
|
|
51169
|
+
ssh: { ...current.ssh, ...changes.ssh },
|
|
51170
|
+
dashboard: { ...current.dashboard, ...changes.dashboard },
|
|
51171
|
+
memory: { ...current.memory, ...changes.memory }
|
|
51172
|
+
});
|
|
51173
|
+
if (changes.dashboard?.captureBody === true && !next.dashboard.redactInput)
|
|
51174
|
+
throw new Error("Enabling body capture also requires dashboard.redactInput=true.");
|
|
51175
|
+
const before = settings(current);
|
|
51176
|
+
const after = settings(next);
|
|
51177
|
+
const changedPaths = [];
|
|
51178
|
+
for (const key of ["mcp", "ssh", "dashboard", "memory"]) {
|
|
51179
|
+
for (const [field, value] of Object.entries(after[key])) {
|
|
51180
|
+
if (value !== before[key][field])
|
|
51181
|
+
changedPaths.push(`${key}.${field}`);
|
|
51182
|
+
}
|
|
51183
|
+
}
|
|
51184
|
+
if (before.disableUpdateCheck !== after.disableUpdateCheck)
|
|
51185
|
+
changedPaths.push("disableUpdateCheck");
|
|
51186
|
+
const restartRequired = changedPaths.some((path) => path.startsWith("mcp.") || path.startsWith("dashboard.") || path === "disableUpdateCheck");
|
|
51187
|
+
const diff = diffLines(JSON.stringify(before, null, 2), JSON.stringify(after, null, 2), {
|
|
51188
|
+
fromLabel: "current MCP settings",
|
|
51189
|
+
toLabel: "proposed MCP settings"
|
|
51190
|
+
});
|
|
51191
|
+
return {
|
|
51192
|
+
next,
|
|
51193
|
+
preview: {
|
|
51194
|
+
revision: deps.admin.revision(),
|
|
51195
|
+
changedPaths,
|
|
51196
|
+
before,
|
|
51197
|
+
after,
|
|
51198
|
+
summary: diff.summary,
|
|
51199
|
+
unified: diff.unified,
|
|
51200
|
+
restartRequired,
|
|
51201
|
+
activation: [
|
|
51202
|
+
"Memory enable/disable is checked on the next memory operation; disabling does not delete stored knowledge.",
|
|
51203
|
+
"SSH pool changes affect subsequent calls/new connections and newly armed idle timers; existing connections are not forcibly closed.",
|
|
51204
|
+
"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."
|
|
51205
|
+
]
|
|
51206
|
+
}
|
|
51207
|
+
};
|
|
51208
|
+
};
|
|
51209
|
+
const checkWrite = (revision) => {
|
|
51210
|
+
if (deps.getConfig().readOnly)
|
|
51211
|
+
throw new Error("MCP settings writes are disabled in read-only mode.");
|
|
51212
|
+
if (revision !== deps.admin.revision())
|
|
51213
|
+
throw new Error("MCP settings changed. Read and preview again before writing.");
|
|
51214
|
+
};
|
|
51215
|
+
return {
|
|
51216
|
+
read,
|
|
51217
|
+
schema: () => ({
|
|
51218
|
+
schema: toJSONSchema(McpSettingsPatchSchema, { target: "draft-2020-12" }),
|
|
51219
|
+
boundary: BOUNDARY
|
|
51220
|
+
}),
|
|
51221
|
+
preview: (changes) => prepare(changes).preview,
|
|
51222
|
+
update: (raw) => {
|
|
51223
|
+
const input = McpSettingsUpdateSchema.safeParse(raw);
|
|
51224
|
+
if (!input.success)
|
|
51225
|
+
throw new Error("Invalid settings update. A current revision, allowed changes, confirm=true and 30\u2013600 second rollback window are required.");
|
|
51226
|
+
checkWrite(input.data.revision);
|
|
51227
|
+
if (deps.admin.pendingId())
|
|
51228
|
+
throw new Error("Another configuration change is pending. Confirm or roll back its owning workflow first.");
|
|
51229
|
+
const { next, preview } = prepare(input.data.changes);
|
|
51230
|
+
if (!preview.changedPaths.length)
|
|
51231
|
+
return { applied: false, ...preview, ...read() };
|
|
51232
|
+
const applied = deps.admin.applyConfig(next, input.data.rollback_seconds * 1000);
|
|
51233
|
+
owned = { id: applied.pendingId, expiresAt: applied.expiresAt };
|
|
51234
|
+
return { applied: true, ...preview, ...applied, ...read() };
|
|
51235
|
+
},
|
|
51236
|
+
finish: (raw, action) => {
|
|
51237
|
+
const result = McpSettingsPendingSchema.safeParse(raw);
|
|
51238
|
+
if (!result.success)
|
|
51239
|
+
throw new Error("A pending_id and current revision are required.");
|
|
51240
|
+
const input = result.data;
|
|
51241
|
+
checkWrite(input.revision);
|
|
51242
|
+
if (!owned || owned.id !== input.pending_id || deps.admin.pendingId() !== owned.id)
|
|
51243
|
+
throw new Error("This transaction is not pending in MCP settings. It may have expired or belong to the dashboard.");
|
|
51244
|
+
const ok = action === "confirm" ? deps.admin.keepConfig(owned.id) : deps.admin.rollback(owned.id);
|
|
51245
|
+
if (!ok)
|
|
51246
|
+
throw new Error("Configuration changed before confirmation; read settings again.");
|
|
51247
|
+
owned = null;
|
|
51248
|
+
return { action, ok, ...read() };
|
|
51249
|
+
}
|
|
51250
|
+
};
|
|
51251
|
+
}
|
|
51252
|
+
var service;
|
|
51253
|
+
function getMcpSettingsService() {
|
|
51254
|
+
return service ??= createMcpSettingsService({
|
|
51255
|
+
admin: getConfigAdmin(),
|
|
51256
|
+
getConfig: getConfig2,
|
|
51257
|
+
source: getConfigSource2
|
|
51258
|
+
});
|
|
51259
|
+
}
|
|
51260
|
+
|
|
51261
|
+
// src/tools/mcp-settings.ts
|
|
51262
|
+
var render = (value) => JSON.stringify(value, null, 2);
|
|
51263
|
+
var mcpSettingsTools = [
|
|
51264
|
+
defineTool2({
|
|
51265
|
+
name: "get_mcp_settings",
|
|
51266
|
+
title: "Read MCP Server Settings",
|
|
51267
|
+
noDevice: true,
|
|
51268
|
+
annotations: READ,
|
|
51269
|
+
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.",
|
|
51270
|
+
handler: () => render(getMcpSettingsService().read())
|
|
51271
|
+
}),
|
|
51272
|
+
defineTool2({
|
|
51273
|
+
name: "get_mcp_settings_schema",
|
|
51274
|
+
title: "Describe Editable MCP Settings",
|
|
51275
|
+
noDevice: true,
|
|
51276
|
+
annotations: READ,
|
|
51277
|
+
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.",
|
|
51278
|
+
handler: () => render(getMcpSettingsService().schema())
|
|
51279
|
+
}),
|
|
51280
|
+
defineTool2({
|
|
51281
|
+
name: "preview_mcp_settings",
|
|
51282
|
+
title: "Validate and Preview MCP Settings",
|
|
51283
|
+
noDevice: true,
|
|
51284
|
+
annotations: READ,
|
|
51285
|
+
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.",
|
|
51286
|
+
inputSchema: {
|
|
51287
|
+
changes: McpSettingsPatchSchema.describe("Only the fields to change; omitted values are preserved.")
|
|
51288
|
+
},
|
|
51289
|
+
handler: (args) => render(getMcpSettingsService().preview(args.changes))
|
|
51290
|
+
}),
|
|
51291
|
+
defineTool2({
|
|
51292
|
+
name: "update_mcp_settings",
|
|
51293
|
+
title: "Safely Update MCP Settings",
|
|
51294
|
+
noDevice: true,
|
|
51295
|
+
annotations: WRITE,
|
|
51296
|
+
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.",
|
|
51297
|
+
inputSchema: McpSettingsUpdateSchema.shape,
|
|
51298
|
+
handler: (args) => render(getMcpSettingsService().update(args))
|
|
51299
|
+
}),
|
|
51300
|
+
defineTool2({
|
|
51301
|
+
name: "confirm_mcp_settings",
|
|
51302
|
+
title: "Keep a Pending MCP Settings Change",
|
|
51303
|
+
noDevice: true,
|
|
51304
|
+
annotations: WRITE,
|
|
51305
|
+
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.",
|
|
51306
|
+
inputSchema: McpSettingsPendingSchema.shape,
|
|
51307
|
+
handler: (args) => render(getMcpSettingsService().finish(args, "confirm"))
|
|
51308
|
+
}),
|
|
51309
|
+
defineTool2({
|
|
51310
|
+
name: "rollback_mcp_settings",
|
|
51311
|
+
title: "Revert a Pending MCP Settings Change",
|
|
51312
|
+
noDevice: true,
|
|
51313
|
+
annotations: WRITE,
|
|
51314
|
+
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.",
|
|
51315
|
+
inputSchema: McpSettingsPendingSchema.shape,
|
|
51316
|
+
handler: (args) => render(getMcpSettingsService().finish(args, "rollback"))
|
|
51317
|
+
})
|
|
51318
|
+
];
|
|
51319
|
+
|
|
50936
51320
|
// src/tools/capability.ts
|
|
50937
|
-
function
|
|
51321
|
+
function render2(deviceName, caps) {
|
|
50938
51322
|
const lines = [`DEVICE CAPABILITIES \u2014 ${deviceName}`, ""];
|
|
50939
51323
|
if (!caps.version && caps.packages.size === 0 && !caps.board) {
|
|
50940
51324
|
return `${lines.join(`
|
|
@@ -50997,7 +51381,7 @@ var capabilityTools = [
|
|
|
50997
51381
|
async handler(_a, ctx) {
|
|
50998
51382
|
const name = resolveDeviceName2(ctx.device);
|
|
50999
51383
|
ctx.info(`Reading device capabilities: ${name}`);
|
|
51000
|
-
return
|
|
51384
|
+
return render2(name, await getCapabilities(ctx.device));
|
|
51001
51385
|
}
|
|
51002
51386
|
}),
|
|
51003
51387
|
defineTool2({
|
|
@@ -51010,7 +51394,7 @@ var capabilityTools = [
|
|
|
51010
51394
|
const name = resolveDeviceName2(ctx.device);
|
|
51011
51395
|
ctx.info(`Refreshing device capabilities: ${name}`);
|
|
51012
51396
|
invalidateCapabilities(ctx.device);
|
|
51013
|
-
return
|
|
51397
|
+
return render2(name, await getCapabilities(ctx.device));
|
|
51014
51398
|
}
|
|
51015
51399
|
})
|
|
51016
51400
|
];
|
|
@@ -56491,6 +56875,13 @@ var moduleCatalog2 = [
|
|
|
56491
56875
|
description: "Server self-awareness: running version, update availability, release notes, " + "upgrade path, and server vitals. No RouterOS device is contacted.",
|
|
56492
56876
|
tools: serverPulseTools
|
|
56493
56877
|
},
|
|
56878
|
+
{
|
|
56879
|
+
label: "MCP Settings",
|
|
56880
|
+
slug: "mcp-settings",
|
|
56881
|
+
group: "Discovery & Meta",
|
|
56882
|
+
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.",
|
|
56883
|
+
tools: mcpSettingsTools
|
|
56884
|
+
},
|
|
56494
56885
|
{
|
|
56495
56886
|
label: "Device Capabilities",
|
|
56496
56887
|
slug: "device-capabilities",
|
|
@@ -57473,4 +57864,4 @@ function selectToolModules2(filter = {}, catalog = moduleCatalog2) {
|
|
|
57473
57864
|
}).map((m) => m.tools);
|
|
57474
57865
|
}
|
|
57475
57866
|
|
|
57476
|
-
export { __toESM, __commonJS, clone, normalizeParams, own, installLazyProp, $constructor, parse, parseAsync, safeParse, safeParseAsync, $ZodType, $ZodObject, toJSONSchema, string, number, boolean, _null, unknown, array, object, looseObject, union, discriminatedUnion, intersection, record, _enum, literal, ZodOptional, optional, custom, preprocess, datetime, DEFAULT_DASHBOARD_DB2, DEFAULT_SNAPSHOT_DB2, DEFAULT_BACKUP_DIR2, DeviceConfigSchema2, MikrotikConfigSchema2, loadConfig2, logger, MikroTikSSHClient2, setConfig2, getConfig2, listDevices2, deviceLabels, resolveDeviceName2, deviceDirectory, getDevice2, SafeModeManager2, getSafeModeManager2, executeMikrotikCommand2, defineTool2, registerTools2, PROMPTS_DIR, registerUiResources, VERSION2, WEBSITE_URL, LOGO_URL, SERVER_TITLE, SERVER_DESCRIPTION, SERVER_NAME2, loadFileCacheSync, updateSummaryLine, parseExportMeta2, normalizeExport2, contentSha2, countLines2, openSnapshotStore2, moduleCatalog2, allToolModules2, selectToolModules2 };
|
|
57867
|
+
export { __toESM, __commonJS, clone, normalizeParams, own, installLazyProp, $constructor, parse, parseAsync, safeParse, safeParseAsync, $ZodType, $ZodObject, toJSONSchema, string, number, boolean, _null, unknown, array, object, looseObject, union, discriminatedUnion, intersection, record, _enum, literal, ZodOptional, optional, custom, preprocess, datetime, DEFAULT_DASHBOARD_DB2, DEFAULT_SNAPSHOT_DB2, DEFAULT_BACKUP_DIR2, McpServerSettingsSchema2, DeviceConfigSchema2, DashboardConfigSchema2, MemoryConfigSchema2, SSHConfigSchema2, MikrotikConfigSchema2, getConfigSource2, loadConfig2, logger, MikroTikSSHClient2, setConfig2, getConfig2, listDevices2, deviceLabels, resolveDeviceName2, deviceDirectory, getDevice2, SafeModeManager2, getSafeModeManager2, executeMikrotikCommand2, defineTool2, registerTools2, PROMPTS_DIR, registerUiResources, VERSION2, WEBSITE_URL, LOGO_URL, SERVER_TITLE, SERVER_DESCRIPTION, SERVER_NAME2, loadFileCacheSync, updateSummaryLine, parseExportMeta2, normalizeExport2, contentSha2, countLines2, openSnapshotStore2, moduleCatalog2, allToolModules2, selectToolModules2 };
|
|
@@ -3,15 +3,25 @@ import {
|
|
|
3
3
|
DEFAULT_DASHBOARD_DB2,
|
|
4
4
|
DEFAULT_SNAPSHOT_DB2,
|
|
5
5
|
DEFAULT_BACKUP_DIR2,
|
|
6
|
+
McpServerSettingsSchema2,
|
|
6
7
|
DeviceConfigSchema2,
|
|
8
|
+
DashboardConfigSchema2,
|
|
9
|
+
MemoryConfigSchema2,
|
|
10
|
+
SSHConfigSchema2,
|
|
7
11
|
MikrotikConfigSchema2,
|
|
12
|
+
getConfigSource2,
|
|
8
13
|
loadConfig2
|
|
9
|
-
} from "./library-
|
|
14
|
+
} from "./library-7wcv2ckk.js";
|
|
10
15
|
export {
|
|
11
16
|
DEFAULT_BACKUP_DIR2 as DEFAULT_BACKUP_DIR,
|
|
12
17
|
DEFAULT_DASHBOARD_DB2 as DEFAULT_DASHBOARD_DB,
|
|
13
18
|
DEFAULT_SNAPSHOT_DB2 as DEFAULT_SNAPSHOT_DB,
|
|
19
|
+
DashboardConfigSchema2 as DashboardConfigSchema,
|
|
14
20
|
DeviceConfigSchema2 as DeviceConfigSchema,
|
|
21
|
+
McpServerSettingsSchema2 as McpServerSettingsSchema,
|
|
22
|
+
MemoryConfigSchema2 as MemoryConfigSchema,
|
|
15
23
|
MikrotikConfigSchema2 as MikrotikConfigSchema,
|
|
24
|
+
SSHConfigSchema2 as SSHConfigSchema,
|
|
25
|
+
getConfigSource2 as getConfigSource,
|
|
16
26
|
loadConfig2 as loadConfig
|
|
17
27
|
};
|