@usex/mikrotik-mcp 3.60.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -106,7 +106,7 @@ import {
106
106
  updateAaaEntity,
107
107
  updateSummaryLine,
108
108
  writeBackup
109
- } from "./shared/cli-ghatyv7e.js";
109
+ } from "./shared/cli-athwegwy.js";
110
110
 
111
111
  // src/cli.ts
112
112
  import { existsSync as existsSync2 } from "fs";
@@ -1564,9 +1564,14 @@ function configPayload() {
1564
1564
  devices: cfg.devices,
1565
1565
  defaultDevice: cfg.defaultDevice,
1566
1566
  mcp: cfg.mcp,
1567
+ s3: cfg.s3,
1567
1568
  dashboard: cfg.dashboard,
1569
+ ssh: cfg.ssh,
1568
1570
  readOnly: cfg.readOnly,
1569
- s3: cfg.s3
1571
+ tools: cfg.tools,
1572
+ memory: cfg.memory,
1573
+ backupDir: cfg.backupDir,
1574
+ disableUpdateCheck: cfg.disableUpdateCheck
1570
1575
  });
1571
1576
  }
1572
1577
  function sseResponse(transportLabel) {
package/dist/index.d.ts CHANGED
@@ -308,10 +308,20 @@ declare class SafeModeManager {
308
308
  rollback(): Promise<string>;
309
309
  status(): string;
310
310
  /**
311
- * Read from the channel until `isDone(cleaned)` is satisfied or the timeout
312
- * elapses. Defaults to "any RouterOS prompt appeared". Mode transitions pass a
311
+ * Read from the channel until `isDone(cleaned)` is satisfied or the shell goes
312
+ * SILENT. Defaults to "any RouterOS prompt appeared". Mode transitions pass a
313
313
  * stricter predicate so they wait for the prompt that reflects the NEW state
314
314
  * (safe-mode marker present/absent), not merely the first prompt-shaped line.
315
+ *
316
+ * The timeout is an IDLE timeout, not a total budget: every data chunk resets
317
+ * it, so a legitimately slow-but-streaming command (`/terse` on a large
318
+ * config can emit for tens of seconds) never trips it — only a genuine wedge,
319
+ * where no byte has arrived for `idleMs`, does. A separate hard cap (`hardCapMs`)
320
+ * bounds the pathological "dribbles a byte forever" case so the read can't hang
321
+ * indefinitely. Either expiry resolves with `timedOut: true` so callers can tell
322
+ * "the prompt appeared" from "the shell stopped answering" — the latter means the
323
+ * interactive Safe-Mode session is wedged and must abort rather than letting every
324
+ * subsequent command burn its own timeout.
315
325
  */
316
326
  private readUntilPrompt;
317
327
  /**
package/dist/index.js CHANGED
@@ -29,7 +29,7 @@ import {
29
29
  selectToolModules,
30
30
  setConfig,
31
31
  updateSummaryLine
32
- } from "./shared/library-7j22z9a8.js";
32
+ } from "./shared/library-f5kwsqv2.js";
33
33
  // src/server.ts
34
34
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
35
35
  import { ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
@@ -436,7 +436,22 @@ function parseDevicesSource(raw, fromFile) {
436
436
  const mcp = structured && obj.mcp && typeof obj.mcp === "object" ? obj.mcp : undefined;
437
437
  const ssh = structured && obj.ssh && typeof obj.ssh === "object" ? obj.ssh : undefined;
438
438
  const memory = structured && obj.memory && typeof obj.memory === "object" ? obj.memory : undefined;
439
- return { devices, defaultDevice, s3, dashboard, tools, mcp, ssh, memory };
439
+ const readOnly = structured && typeof obj.readOnly === "boolean" ? obj.readOnly : undefined;
440
+ const disableUpdateCheck = structured && typeof obj.disableUpdateCheck === "boolean" ? obj.disableUpdateCheck : undefined;
441
+ const backupDir = structured && typeof obj.backupDir === "string" ? obj.backupDir : undefined;
442
+ return {
443
+ devices,
444
+ defaultDevice,
445
+ s3,
446
+ dashboard,
447
+ tools,
448
+ mcp,
449
+ ssh,
450
+ memory,
451
+ readOnly,
452
+ disableUpdateCheck,
453
+ backupDir
454
+ };
440
455
  }
441
456
  var configSource = { path: DEFAULT_CONFIG_FILE, fromFile: false };
442
457
  function getConfigSource() {
@@ -445,6 +460,13 @@ function getConfigSource() {
445
460
  function loadConfig(argv = process.argv.slice(2)) {
446
461
  const flags = parseFlags(argv);
447
462
  const pick = (flag, ...envNames) => flags[flag] ?? env(...envNames);
463
+ const overlay = (file, over) => {
464
+ const out = { ...file };
465
+ for (const [k, v] of Object.entries(over))
466
+ if (v !== undefined)
467
+ out[k] = v;
468
+ return out;
469
+ };
448
470
  const jumpHostName = pick("jump-host", "MIKROTIK_JUMP_HOST");
449
471
  const jumpHost = jumpHostName ? {
450
472
  host: jumpHostName,
@@ -485,6 +507,9 @@ function loadConfig(argv = process.argv.slice(2)) {
485
507
  let fileMcp;
486
508
  let fileSsh;
487
509
  let fileMemory;
510
+ let fileReadOnly;
511
+ let fileDisableUpdateCheck;
512
+ let fileBackupDir;
488
513
  if (configFile || devicesInline) {
489
514
  const src = configFile ? parseDevicesSource(configFile, true) : parseDevicesSource(devicesInline, false);
490
515
  for (const [name, dc] of Object.entries(src.devices))
@@ -499,8 +524,11 @@ function loadConfig(argv = process.argv.slice(2)) {
499
524
  fileMcp = src.mcp;
500
525
  fileSsh = src.ssh;
501
526
  fileMemory = src.memory;
527
+ fileReadOnly = src.readOnly;
528
+ fileDisableUpdateCheck = src.disableUpdateCheck;
529
+ fileBackupDir = src.backupDir;
502
530
  }
503
- const s3 = {
531
+ const s3 = overlay(fileS3, {
504
532
  accessKeyId: pick("s3-access-key-id", "S3_ACCESS_KEY_ID", "AWS_ACCESS_KEY_ID"),
505
533
  secretAccessKey: pick("s3-secret-access-key", "S3_SECRET_ACCESS_KEY", "AWS_SECRET_ACCESS_KEY"),
506
534
  sessionToken: pick("s3-session-token", "S3_SESSION_TOKEN", "AWS_SESSION_TOKEN"),
@@ -508,12 +536,11 @@ function loadConfig(argv = process.argv.slice(2)) {
508
536
  endpoint: pick("s3-endpoint", "S3_ENDPOINT", "AWS_ENDPOINT"),
509
537
  bucket: pick("s3-bucket", "S3_BUCKET", "AWS_BUCKET"),
510
538
  prefix: pick("s3-prefix", "MIKROTIK_S3_PREFIX"),
511
- presignExpiresIn: pick("s3-presign-expires-in", "MIKROTIK_S3_PRESIGN_EXPIRES_IN"),
512
- ...fileS3
513
- };
539
+ presignExpiresIn: pick("s3-presign-expires-in", "MIKROTIK_S3_PRESIGN_EXPIRES_IN")
540
+ });
514
541
  const appViewsRaw = pick("app-views", "MIKROTIK_MCP__APP_VIEWS");
515
542
  const appViewsEnv = appViewsRaw === undefined ? undefined : !/^(0|false|no|off)$/i.test(appViewsRaw);
516
- const mcp = {
543
+ const mcp = overlay(fileMcp, {
517
544
  transport: pick("transport", "MIKROTIK_MCP__TRANSPORT", "MCP_TRANSPORT"),
518
545
  host: pick("mcp-host", "MIKROTIK_MCP__HOST"),
519
546
  port: pick("mcp-port", "MIKROTIK_MCP__PORT"),
@@ -521,22 +548,22 @@ function loadConfig(argv = process.argv.slice(2)) {
521
548
  allowedOrigins: pick("mcp-allowed-origins", "MIKROTIK_MCP__ALLOWED_ORIGINS"),
522
549
  corsOrigins: pick("mcp-cors-origins", "MIKROTIK_MCP__CORS_ORIGINS"),
523
550
  toolPageSize: pick("tool-page-size", "MIKROTIK_MCP__TOOL_PAGE_SIZE"),
524
- appViews: appViewsEnv,
525
- ...fileMcp
526
- };
551
+ appViews: appViewsEnv
552
+ });
527
553
  const isTruthy = (v) => /^(1|true|yes|on)$/i.test(v ?? "");
528
- const readOnly = isTruthy(pick("read-only", "MIKROTIK_READ_ONLY"));
529
- const disableUpdateCheck = isTruthy(pick("disable-update-check", "MIKROTIK_DISABLE_UPDATE_CHECK"));
554
+ const boolFileFlag = (flagVal, fileVal) => flagVal !== undefined ? isTruthy(flagVal) : fileVal;
555
+ const readOnly = boolFileFlag(pick("read-only", "MIKROTIK_READ_ONLY"), fileReadOnly);
556
+ const disableUpdateCheck = boolFileFlag(pick("disable-update-check", "MIKROTIK_DISABLE_UPDATE_CHECK"), fileDisableUpdateCheck);
557
+ const backupDir = pick("backup-dir", "MIKROTIK_BACKUP_DIR") ?? fileBackupDir;
530
558
  const csv = (v) => v === undefined ? undefined : v.split(",").map((s) => s.trim()).filter(Boolean);
531
- const tools = {
559
+ const tools = overlay(fileTools, {
532
560
  enabledModules: csv(pick("tools-enabled-modules", "MIKROTIK_TOOLS__ENABLED_MODULES")),
533
561
  disabledModules: csv(pick("tools-disabled-modules", "MIKROTIK_TOOLS__DISABLED_MODULES")),
534
562
  enabledGroups: csv(pick("tools-enabled-groups", "MIKROTIK_TOOLS__ENABLED_GROUPS")),
535
- disabledGroups: csv(pick("tools-disabled-groups", "MIKROTIK_TOOLS__DISABLED_GROUPS")),
536
- ...fileTools
537
- };
563
+ disabledGroups: csv(pick("tools-disabled-groups", "MIKROTIK_TOOLS__DISABLED_GROUPS"))
564
+ });
538
565
  const boolOpt = (v) => v === undefined ? undefined : isTruthy(v);
539
- const dashboard = {
566
+ const dashboard = overlay(fileDashboard, {
540
567
  enabled: boolOpt(pick("dashboard", "MIKROTIK_DASHBOARD__ENABLED", "MIKROTIK_DASHBOARD")),
541
568
  host: pick("dashboard-host", "MIKROTIK_DASHBOARD__HOST"),
542
569
  port: pick("dashboard-port", "MIKROTIK_DASHBOARD__PORT"),
@@ -545,20 +572,17 @@ function loadConfig(argv = process.argv.slice(2)) {
545
572
  captureBody: boolOpt(pick("dashboard-capture-body", "MIKROTIK_DASHBOARD__CAPTURE_BODY")),
546
573
  redactInput: boolOpt(pick("dashboard-redact-input", "MIKROTIK_DASHBOARD__REDACT_INPUT")),
547
574
  maxBodyBytes: pick("dashboard-max-body-bytes", "MIKROTIK_DASHBOARD__MAX_BODY_BYTES"),
548
- token: pick("dashboard-token", "MIKROTIK_DASHBOARD__TOKEN"),
549
- ...fileDashboard
550
- };
551
- const ssh = {
575
+ token: pick("dashboard-token", "MIKROTIK_DASHBOARD__TOKEN")
576
+ });
577
+ const ssh = overlay(fileSsh, {
552
578
  keepAlive: boolOpt(pick("ssh-keep-alive", "MIKROTIK_SSH__KEEP_ALIVE")),
553
579
  keepAliveInterval: pick("ssh-keepalive-interval", "MIKROTIK_SSH__KEEPALIVE_INTERVAL"),
554
- idleTimeout: pick("ssh-idle-timeout", "MIKROTIK_SSH__IDLE_TIMEOUT"),
555
- ...fileSsh
556
- };
557
- const memory = {
580
+ idleTimeout: pick("ssh-idle-timeout", "MIKROTIK_SSH__IDLE_TIMEOUT")
581
+ });
582
+ const memory = overlay(fileMemory, {
558
583
  enabled: boolOpt(pick("memory-enabled", "MIKROTIK_MEMORY__ENABLED")),
559
- dbPath: pick("memory-db", "MIKROTIK_MEMORY__DB_PATH"),
560
- ...fileMemory
561
- };
584
+ dbPath: pick("memory-db", "MIKROTIK_MEMORY__DB_PATH")
585
+ });
562
586
  const hasS3 = !!(s3.accessKeyId || s3.bucket || s3.endpoint);
563
587
  const raw = {
564
588
  devices: Object.keys(devices).length ? devices : { default: {} },
@@ -567,6 +591,7 @@ function loadConfig(argv = process.argv.slice(2)) {
567
591
  dashboard,
568
592
  readOnly,
569
593
  disableUpdateCheck,
594
+ backupDir,
570
595
  tools,
571
596
  ssh,
572
597
  memory,
@@ -1208,6 +1233,8 @@ function stripAnsi(text) {
1208
1233
  return text.replace(ANSI_RE, "");
1209
1234
  }
1210
1235
  var CTRL_X = "\x18";
1236
+ var IDLE_TIMEOUT_MS = 15000;
1237
+ var HARD_CAP_MS = 120000;
1211
1238
  function isSafeModeActivated(response) {
1212
1239
  if (response.includes("<SAFE>"))
1213
1240
  return true;
@@ -1283,7 +1310,7 @@ class SafeModeManager {
1283
1310
  `);
1284
1311
  const { text, timedOut } = await this.readUntilPrompt();
1285
1312
  if (timedOut) {
1286
- throw new Error(`Safe Mode shell did not return a prompt within 15s (command: ${command}). The interactive ` + "session appears wedged \u2014 some RouterOS builds/terminals don't support Safe Mode over SSH. " + "Apply the change with the direct write tools instead (verify each with a read).");
1313
+ throw new Error(`Safe Mode shell went silent for ${IDLE_TIMEOUT_MS / 1000}s (command: ${command}). The ` + "interactive session appears wedged \u2014 some RouterOS builds/terminals don't support Safe " + "Mode over SSH. Apply the change with the direct write tools instead (verify each with a read).");
1287
1314
  }
1288
1315
  return this.extractOutput(text, command);
1289
1316
  });
@@ -1337,25 +1364,32 @@ class SafeModeManager {
1337
1364
  status() {
1338
1365
  return this.active ? "Safe mode is ACTIVE. Changes are pending \u2014 they are NOT yet persisted. " + "Call commit_safe_mode to persist or rollback_safe_mode to revert." : "Safe mode is NOT active. Changes take effect and persist immediately.";
1339
1366
  }
1340
- readUntilPrompt(timeoutMs = 15000, isDone = (c) => PROMPT_RE.test(c)) {
1367
+ readUntilPrompt(idleMs = IDLE_TIMEOUT_MS, isDone = (c) => PROMPT_RE.test(c), hardCapMs = HARD_CAP_MS) {
1341
1368
  const channel = this.channel;
1342
1369
  if (!channel)
1343
1370
  return Promise.resolve({ text: "", timedOut: false });
1344
1371
  return new Promise((resolve2) => {
1345
1372
  let buf = "";
1346
- let timer;
1373
+ let idleTimer;
1374
+ const hardTimer = setTimeout(() => finish(stripAnsi(buf), true), hardCapMs);
1375
+ function armIdle2() {
1376
+ clearTimeout(idleTimer);
1377
+ idleTimer = setTimeout(() => finish(stripAnsi(buf), true), idleMs);
1378
+ }
1347
1379
  function onData(chunk) {
1348
1380
  buf += decodeOutput(chunk);
1381
+ armIdle2();
1349
1382
  const cleaned = stripAnsi(buf);
1350
1383
  if (isDone(cleaned))
1351
1384
  finish(cleaned, false);
1352
1385
  }
1353
1386
  function finish(result, timedOut) {
1354
- clearTimeout(timer);
1387
+ clearTimeout(idleTimer);
1388
+ clearTimeout(hardTimer);
1355
1389
  channel.removeListener("data", onData);
1356
1390
  resolve2({ text: result, timedOut });
1357
1391
  }
1358
- timer = setTimeout(() => finish(stripAnsi(buf), true), timeoutMs);
1392
+ armIdle2();
1359
1393
  channel.on("data", onData);
1360
1394
  });
1361
1395
  }
@@ -5264,7 +5298,7 @@ var changePlanTools = [
5264
5298
  const enabled2 = await safe.enable();
5265
5299
  if (enabled2.startsWith("Error"))
5266
5300
  throw new Error(enabled2);
5267
- const APPLY_BUDGET_MS = 90000;
5301
+ const APPLY_BUDGET_MS = 180000;
5268
5302
  const startedAt = Date.now();
5269
5303
  const overBudget = () => Date.now() - startedAt > APPLY_BUDGET_MS;
5270
5304
  const applyAndDiff = async () => {
@@ -8330,7 +8364,7 @@ var cache = null;
8330
8364
  async function gateway() {
8331
8365
  if (cache)
8332
8366
  return cache;
8333
- const { moduleCatalog } = await import("./cli-7yjsmkwg.js");
8367
+ const { moduleCatalog } = await import("./cli-cjrk8g04.js");
8334
8368
  const forIndex = [];
8335
8369
  const byName = new Map;
8336
8370
  for (const mod of moduleCatalog) {
@@ -22181,7 +22215,7 @@ ${result}`;
22181
22215
  name: "check_route_path",
22182
22216
  title: "Check IPv4 Route Path",
22183
22217
  annotations: READ,
22184
- description: "Resolves which nexthop RouterOS would use for a given IPv4 destination " + '\u2014 answers "which gateway will this packet take?" without sending any traffic. ' + "Version-aware: uses `/ip route check` on v6, falls back to " + "`/ip route print where dst-address in <dest> active=yes` on v7+ where the check " + "command was removed. Optionally scoped by `routing_table` (v7) / `routing_mark` (v6) " + "for policy-routing table lookups. " + "For listing all known routes use list_routes; for a named-table view use get_routing_table. " + "Returns the resolved nexthop and interface detail.",
22218
+ description: "Resolves which nexthop RouterOS would use for a given IPv4 destination " + '\u2014 answers "which gateway will this packet take?" without sending any traffic. ' + "Version-aware: uses `/ip route check` on v6, falls back to " + "`/ip route print where <dest> in dst-address active=yes` on v7+ where the check " + "command was removed. Optionally scoped by `routing_table` (v7) / `routing_mark` (v6) " + "for policy-routing table lookups. " + "For listing all known routes use list_routes; for a named-table view use get_routing_table. " + "Returns the resolved nexthop and interface detail.",
22185
22219
  inputSchema: {
22186
22220
  destination: z88.string(),
22187
22221
  routing_table: z88.string().optional().describe('Policy-routing table name (v7) or routing-mark (v6), e.g. "VPN"')
@@ -22196,7 +22230,7 @@ ${result}`;
22196
22230
 
22197
22231
  ${v6Result}`;
22198
22232
  }
22199
- const where = [`dst-address in ${a.destination}`, "active=yes"];
22233
+ const where = [`${a.destination} in dst-address`, "active=yes"];
22200
22234
  if (table && table !== "main")
22201
22235
  where.push(`routing-table=${quoteValue(table)}`);
22202
22236
  const v7Cmd = `/ip route print detail where ${where.join(" ")}`;
@@ -24991,13 +25025,15 @@ async function fetchLatestRelease() {
24991
25025
  throw new Error(`GitHub API ${res.status}`);
24992
25026
  const gh = await res.json();
24993
25027
  const latestVersion = gh.tag_name.replace(/^v/, "");
25028
+ const cmp = compareVersions(latestVersion, VERSION);
24994
25029
  const data = {
24995
25030
  version: latestVersion,
24996
25031
  name: gh.name || `v${latestVersion}`,
24997
25032
  body: gh.body || "",
24998
25033
  publishedAt: gh.published_at,
24999
25034
  url: gh.html_url,
25000
- isNewer: compareVersions(latestVersion, VERSION) > 0,
25035
+ isNewer: cmp > 0,
25036
+ isAhead: cmp < 0,
25001
25037
  currentVersion: VERSION
25002
25038
  };
25003
25039
  memoryCache = { data, fetchedAt: Date.now() };
@@ -25105,14 +25141,18 @@ var serverPulseTools = [
25105
25141
  const sep = "\u2500".repeat(50);
25106
25142
  sections.push(`SERVER PULSE \u2014 ${SERVER_TITLE} v${VERSION}`, sep, "Package: @usex/mikrotik-mcp", `Version: ${VERSION}`, `Uptime: ${formatUptime(uptime)}`, `Website: ${WEBSITE_URL}`);
25107
25143
  if (result.release) {
25108
- const freshness = assessFreshness(VERSION, result.release.version);
25109
- const label = freshnessLabel(freshness);
25110
25144
  const age = timeAgo(result.release.publishedAt);
25111
- sections.push("", `UPDATE STATUS: ${label}`, sep, `Current: v${VERSION}`, `Latest: v${result.release.version} (${result.release.name})`, `Published: ${age}`, `Freshness: ${freshness.toUpperCase()}`);
25112
- if (result.release.isNewer) {
25113
- sections.push("", ">>> A newer version is available! <<<");
25145
+ if (result.release.isAhead) {
25146
+ sections.push("", "UPDATE STATUS: AHEAD OF LATEST RELEASE", sep, `Current: v${VERSION}`, `Published: v${result.release.version} (${result.release.name})`, `Released: ${age}`, `Freshness: DEV BUILD`, "", "You are running ahead of the latest published release.");
25114
25147
  } else {
25115
- sections.push("", "You are running the latest version.");
25148
+ const freshness = assessFreshness(VERSION, result.release.version);
25149
+ const label = freshnessLabel(freshness);
25150
+ sections.push("", `UPDATE STATUS: ${label}`, sep, `Current: v${VERSION}`, `Latest: v${result.release.version} (${result.release.name})`, `Published: ${age}`, `Freshness: ${freshness.toUpperCase()}`);
25151
+ if (result.release.isNewer) {
25152
+ sections.push("", ">>> A newer version is available! <<<");
25153
+ } else {
25154
+ sections.push("", "You are running the latest version.");
25155
+ }
25116
25156
  }
25117
25157
  if (result.release.isNewer) {
25118
25158
  sections.push("", "UPGRADE", sep);
@@ -4,7 +4,7 @@ import {
4
4
  allToolModules,
5
5
  moduleCatalog,
6
6
  selectToolModules
7
- } from "./cli-ghatyv7e.js";
7
+ } from "./cli-athwegwy.js";
8
8
  export {
9
9
  selectToolModules,
10
10
  moduleCatalog,
@@ -4,7 +4,7 @@ import {
4
4
  allToolModules,
5
5
  moduleCatalog,
6
6
  selectToolModules
7
- } from "./library-7j22z9a8.js";
7
+ } from "./library-f5kwsqv2.js";
8
8
  export {
9
9
  selectToolModules,
10
10
  moduleCatalog,
@@ -436,12 +436,34 @@ function parseDevicesSource(raw, fromFile) {
436
436
  const mcp = structured && obj.mcp && typeof obj.mcp === "object" ? obj.mcp : undefined;
437
437
  const ssh = structured && obj.ssh && typeof obj.ssh === "object" ? obj.ssh : undefined;
438
438
  const memory = structured && obj.memory && typeof obj.memory === "object" ? obj.memory : undefined;
439
- return { devices, defaultDevice, s3, dashboard, tools, mcp, ssh, memory };
439
+ const readOnly = structured && typeof obj.readOnly === "boolean" ? obj.readOnly : undefined;
440
+ const disableUpdateCheck = structured && typeof obj.disableUpdateCheck === "boolean" ? obj.disableUpdateCheck : undefined;
441
+ const backupDir = structured && typeof obj.backupDir === "string" ? obj.backupDir : undefined;
442
+ return {
443
+ devices,
444
+ defaultDevice,
445
+ s3,
446
+ dashboard,
447
+ tools,
448
+ mcp,
449
+ ssh,
450
+ memory,
451
+ readOnly,
452
+ disableUpdateCheck,
453
+ backupDir
454
+ };
440
455
  }
441
456
  var configSource = { path: DEFAULT_CONFIG_FILE, fromFile: false };
442
457
  function loadConfig(argv = process.argv.slice(2)) {
443
458
  const flags = parseFlags(argv);
444
459
  const pick = (flag, ...envNames) => flags[flag] ?? env(...envNames);
460
+ const overlay = (file, over) => {
461
+ const out = { ...file };
462
+ for (const [k, v] of Object.entries(over))
463
+ if (v !== undefined)
464
+ out[k] = v;
465
+ return out;
466
+ };
445
467
  const jumpHostName = pick("jump-host", "MIKROTIK_JUMP_HOST");
446
468
  const jumpHost = jumpHostName ? {
447
469
  host: jumpHostName,
@@ -482,6 +504,9 @@ function loadConfig(argv = process.argv.slice(2)) {
482
504
  let fileMcp;
483
505
  let fileSsh;
484
506
  let fileMemory;
507
+ let fileReadOnly;
508
+ let fileDisableUpdateCheck;
509
+ let fileBackupDir;
485
510
  if (configFile || devicesInline) {
486
511
  const src = configFile ? parseDevicesSource(configFile, true) : parseDevicesSource(devicesInline, false);
487
512
  for (const [name, dc] of Object.entries(src.devices))
@@ -496,8 +521,11 @@ function loadConfig(argv = process.argv.slice(2)) {
496
521
  fileMcp = src.mcp;
497
522
  fileSsh = src.ssh;
498
523
  fileMemory = src.memory;
524
+ fileReadOnly = src.readOnly;
525
+ fileDisableUpdateCheck = src.disableUpdateCheck;
526
+ fileBackupDir = src.backupDir;
499
527
  }
500
- const s3 = {
528
+ const s3 = overlay(fileS3, {
501
529
  accessKeyId: pick("s3-access-key-id", "S3_ACCESS_KEY_ID", "AWS_ACCESS_KEY_ID"),
502
530
  secretAccessKey: pick("s3-secret-access-key", "S3_SECRET_ACCESS_KEY", "AWS_SECRET_ACCESS_KEY"),
503
531
  sessionToken: pick("s3-session-token", "S3_SESSION_TOKEN", "AWS_SESSION_TOKEN"),
@@ -505,12 +533,11 @@ function loadConfig(argv = process.argv.slice(2)) {
505
533
  endpoint: pick("s3-endpoint", "S3_ENDPOINT", "AWS_ENDPOINT"),
506
534
  bucket: pick("s3-bucket", "S3_BUCKET", "AWS_BUCKET"),
507
535
  prefix: pick("s3-prefix", "MIKROTIK_S3_PREFIX"),
508
- presignExpiresIn: pick("s3-presign-expires-in", "MIKROTIK_S3_PRESIGN_EXPIRES_IN"),
509
- ...fileS3
510
- };
536
+ presignExpiresIn: pick("s3-presign-expires-in", "MIKROTIK_S3_PRESIGN_EXPIRES_IN")
537
+ });
511
538
  const appViewsRaw = pick("app-views", "MIKROTIK_MCP__APP_VIEWS");
512
539
  const appViewsEnv = appViewsRaw === undefined ? undefined : !/^(0|false|no|off)$/i.test(appViewsRaw);
513
- const mcp = {
540
+ const mcp = overlay(fileMcp, {
514
541
  transport: pick("transport", "MIKROTIK_MCP__TRANSPORT", "MCP_TRANSPORT"),
515
542
  host: pick("mcp-host", "MIKROTIK_MCP__HOST"),
516
543
  port: pick("mcp-port", "MIKROTIK_MCP__PORT"),
@@ -518,22 +545,22 @@ function loadConfig(argv = process.argv.slice(2)) {
518
545
  allowedOrigins: pick("mcp-allowed-origins", "MIKROTIK_MCP__ALLOWED_ORIGINS"),
519
546
  corsOrigins: pick("mcp-cors-origins", "MIKROTIK_MCP__CORS_ORIGINS"),
520
547
  toolPageSize: pick("tool-page-size", "MIKROTIK_MCP__TOOL_PAGE_SIZE"),
521
- appViews: appViewsEnv,
522
- ...fileMcp
523
- };
548
+ appViews: appViewsEnv
549
+ });
524
550
  const isTruthy = (v) => /^(1|true|yes|on)$/i.test(v ?? "");
525
- const readOnly = isTruthy(pick("read-only", "MIKROTIK_READ_ONLY"));
526
- const disableUpdateCheck = isTruthy(pick("disable-update-check", "MIKROTIK_DISABLE_UPDATE_CHECK"));
551
+ const boolFileFlag = (flagVal, fileVal) => flagVal !== undefined ? isTruthy(flagVal) : fileVal;
552
+ const readOnly = boolFileFlag(pick("read-only", "MIKROTIK_READ_ONLY"), fileReadOnly);
553
+ const disableUpdateCheck = boolFileFlag(pick("disable-update-check", "MIKROTIK_DISABLE_UPDATE_CHECK"), fileDisableUpdateCheck);
554
+ const backupDir = pick("backup-dir", "MIKROTIK_BACKUP_DIR") ?? fileBackupDir;
527
555
  const csv = (v) => v === undefined ? undefined : v.split(",").map((s) => s.trim()).filter(Boolean);
528
- const tools = {
556
+ const tools = overlay(fileTools, {
529
557
  enabledModules: csv(pick("tools-enabled-modules", "MIKROTIK_TOOLS__ENABLED_MODULES")),
530
558
  disabledModules: csv(pick("tools-disabled-modules", "MIKROTIK_TOOLS__DISABLED_MODULES")),
531
559
  enabledGroups: csv(pick("tools-enabled-groups", "MIKROTIK_TOOLS__ENABLED_GROUPS")),
532
- disabledGroups: csv(pick("tools-disabled-groups", "MIKROTIK_TOOLS__DISABLED_GROUPS")),
533
- ...fileTools
534
- };
560
+ disabledGroups: csv(pick("tools-disabled-groups", "MIKROTIK_TOOLS__DISABLED_GROUPS"))
561
+ });
535
562
  const boolOpt = (v) => v === undefined ? undefined : isTruthy(v);
536
- const dashboard = {
563
+ const dashboard = overlay(fileDashboard, {
537
564
  enabled: boolOpt(pick("dashboard", "MIKROTIK_DASHBOARD__ENABLED", "MIKROTIK_DASHBOARD")),
538
565
  host: pick("dashboard-host", "MIKROTIK_DASHBOARD__HOST"),
539
566
  port: pick("dashboard-port", "MIKROTIK_DASHBOARD__PORT"),
@@ -542,20 +569,17 @@ function loadConfig(argv = process.argv.slice(2)) {
542
569
  captureBody: boolOpt(pick("dashboard-capture-body", "MIKROTIK_DASHBOARD__CAPTURE_BODY")),
543
570
  redactInput: boolOpt(pick("dashboard-redact-input", "MIKROTIK_DASHBOARD__REDACT_INPUT")),
544
571
  maxBodyBytes: pick("dashboard-max-body-bytes", "MIKROTIK_DASHBOARD__MAX_BODY_BYTES"),
545
- token: pick("dashboard-token", "MIKROTIK_DASHBOARD__TOKEN"),
546
- ...fileDashboard
547
- };
548
- const ssh = {
572
+ token: pick("dashboard-token", "MIKROTIK_DASHBOARD__TOKEN")
573
+ });
574
+ const ssh = overlay(fileSsh, {
549
575
  keepAlive: boolOpt(pick("ssh-keep-alive", "MIKROTIK_SSH__KEEP_ALIVE")),
550
576
  keepAliveInterval: pick("ssh-keepalive-interval", "MIKROTIK_SSH__KEEPALIVE_INTERVAL"),
551
- idleTimeout: pick("ssh-idle-timeout", "MIKROTIK_SSH__IDLE_TIMEOUT"),
552
- ...fileSsh
553
- };
554
- const memory = {
577
+ idleTimeout: pick("ssh-idle-timeout", "MIKROTIK_SSH__IDLE_TIMEOUT")
578
+ });
579
+ const memory = overlay(fileMemory, {
555
580
  enabled: boolOpt(pick("memory-enabled", "MIKROTIK_MEMORY__ENABLED")),
556
- dbPath: pick("memory-db", "MIKROTIK_MEMORY__DB_PATH"),
557
- ...fileMemory
558
- };
581
+ dbPath: pick("memory-db", "MIKROTIK_MEMORY__DB_PATH")
582
+ });
559
583
  const hasS3 = !!(s3.accessKeyId || s3.bucket || s3.endpoint);
560
584
  const raw = {
561
585
  devices: Object.keys(devices).length ? devices : { default: {} },
@@ -564,6 +588,7 @@ function loadConfig(argv = process.argv.slice(2)) {
564
588
  dashboard,
565
589
  readOnly,
566
590
  disableUpdateCheck,
591
+ backupDir,
567
592
  tools,
568
593
  ssh,
569
594
  memory,
@@ -1189,6 +1214,8 @@ function stripAnsi(text) {
1189
1214
  return text.replace(ANSI_RE, "");
1190
1215
  }
1191
1216
  var CTRL_X = "\x18";
1217
+ var IDLE_TIMEOUT_MS = 15000;
1218
+ var HARD_CAP_MS = 120000;
1192
1219
  function isSafeModeActivated(response) {
1193
1220
  if (response.includes("<SAFE>"))
1194
1221
  return true;
@@ -1264,7 +1291,7 @@ class SafeModeManager {
1264
1291
  `);
1265
1292
  const { text, timedOut } = await this.readUntilPrompt();
1266
1293
  if (timedOut) {
1267
- throw new Error(`Safe Mode shell did not return a prompt within 15s (command: ${command}). The interactive ` + "session appears wedged \u2014 some RouterOS builds/terminals don't support Safe Mode over SSH. " + "Apply the change with the direct write tools instead (verify each with a read).");
1294
+ throw new Error(`Safe Mode shell went silent for ${IDLE_TIMEOUT_MS / 1000}s (command: ${command}). The ` + "interactive session appears wedged \u2014 some RouterOS builds/terminals don't support Safe " + "Mode over SSH. Apply the change with the direct write tools instead (verify each with a read).");
1268
1295
  }
1269
1296
  return this.extractOutput(text, command);
1270
1297
  });
@@ -1318,25 +1345,32 @@ class SafeModeManager {
1318
1345
  status() {
1319
1346
  return this.active ? "Safe mode is ACTIVE. Changes are pending \u2014 they are NOT yet persisted. " + "Call commit_safe_mode to persist or rollback_safe_mode to revert." : "Safe mode is NOT active. Changes take effect and persist immediately.";
1320
1347
  }
1321
- readUntilPrompt(timeoutMs = 15000, isDone = (c) => PROMPT_RE.test(c)) {
1348
+ readUntilPrompt(idleMs = IDLE_TIMEOUT_MS, isDone = (c) => PROMPT_RE.test(c), hardCapMs = HARD_CAP_MS) {
1322
1349
  const channel = this.channel;
1323
1350
  if (!channel)
1324
1351
  return Promise.resolve({ text: "", timedOut: false });
1325
1352
  return new Promise((resolve2) => {
1326
1353
  let buf = "";
1327
- let timer;
1354
+ let idleTimer;
1355
+ const hardTimer = setTimeout(() => finish(stripAnsi(buf), true), hardCapMs);
1356
+ function armIdle2() {
1357
+ clearTimeout(idleTimer);
1358
+ idleTimer = setTimeout(() => finish(stripAnsi(buf), true), idleMs);
1359
+ }
1328
1360
  function onData(chunk) {
1329
1361
  buf += decodeOutput(chunk);
1362
+ armIdle2();
1330
1363
  const cleaned = stripAnsi(buf);
1331
1364
  if (isDone(cleaned))
1332
1365
  finish(cleaned, false);
1333
1366
  }
1334
1367
  function finish(result, timedOut) {
1335
- clearTimeout(timer);
1368
+ clearTimeout(idleTimer);
1369
+ clearTimeout(hardTimer);
1336
1370
  channel.removeListener("data", onData);
1337
1371
  resolve2({ text: result, timedOut });
1338
1372
  }
1339
- timer = setTimeout(() => finish(stripAnsi(buf), true), timeoutMs);
1373
+ armIdle2();
1340
1374
  channel.on("data", onData);
1341
1375
  });
1342
1376
  }
@@ -5194,7 +5228,7 @@ var changePlanTools = [
5194
5228
  const enabled2 = await safe.enable();
5195
5229
  if (enabled2.startsWith("Error"))
5196
5230
  throw new Error(enabled2);
5197
- const APPLY_BUDGET_MS = 90000;
5231
+ const APPLY_BUDGET_MS = 180000;
5198
5232
  const startedAt = Date.now();
5199
5233
  const overBudget = () => Date.now() - startedAt > APPLY_BUDGET_MS;
5200
5234
  const applyAndDiff = async () => {
@@ -8260,7 +8294,7 @@ var cache = null;
8260
8294
  async function gateway() {
8261
8295
  if (cache)
8262
8296
  return cache;
8263
- const { moduleCatalog } = await import("./library-1hs18tmh.js");
8297
+ const { moduleCatalog } = await import("./library-4fpy49qb.js");
8264
8298
  const forIndex = [];
8265
8299
  const byName = new Map;
8266
8300
  for (const mod of moduleCatalog) {
@@ -22111,7 +22145,7 @@ ${result}`;
22111
22145
  name: "check_route_path",
22112
22146
  title: "Check IPv4 Route Path",
22113
22147
  annotations: READ,
22114
- description: "Resolves which nexthop RouterOS would use for a given IPv4 destination " + '\u2014 answers "which gateway will this packet take?" without sending any traffic. ' + "Version-aware: uses `/ip route check` on v6, falls back to " + "`/ip route print where dst-address in <dest> active=yes` on v7+ where the check " + "command was removed. Optionally scoped by `routing_table` (v7) / `routing_mark` (v6) " + "for policy-routing table lookups. " + "For listing all known routes use list_routes; for a named-table view use get_routing_table. " + "Returns the resolved nexthop and interface detail.",
22148
+ description: "Resolves which nexthop RouterOS would use for a given IPv4 destination " + '\u2014 answers "which gateway will this packet take?" without sending any traffic. ' + "Version-aware: uses `/ip route check` on v6, falls back to " + "`/ip route print where <dest> in dst-address active=yes` on v7+ where the check " + "command was removed. Optionally scoped by `routing_table` (v7) / `routing_mark` (v6) " + "for policy-routing table lookups. " + "For listing all known routes use list_routes; for a named-table view use get_routing_table. " + "Returns the resolved nexthop and interface detail.",
22115
22149
  inputSchema: {
22116
22150
  destination: z88.string(),
22117
22151
  routing_table: z88.string().optional().describe('Policy-routing table name (v7) or routing-mark (v6), e.g. "VPN"')
@@ -22126,7 +22160,7 @@ ${result}`;
22126
22160
 
22127
22161
  ${v6Result}`;
22128
22162
  }
22129
- const where = [`dst-address in ${a.destination}`, "active=yes"];
22163
+ const where = [`${a.destination} in dst-address`, "active=yes"];
22130
22164
  if (table && table !== "main")
22131
22165
  where.push(`routing-table=${quoteValue(table)}`);
22132
22166
  const v7Cmd = `/ip route print detail where ${where.join(" ")}`;
@@ -24920,13 +24954,15 @@ async function fetchLatestRelease() {
24920
24954
  throw new Error(`GitHub API ${res.status}`);
24921
24955
  const gh = await res.json();
24922
24956
  const latestVersion = gh.tag_name.replace(/^v/, "");
24957
+ const cmp = compareVersions(latestVersion, VERSION);
24923
24958
  const data = {
24924
24959
  version: latestVersion,
24925
24960
  name: gh.name || `v${latestVersion}`,
24926
24961
  body: gh.body || "",
24927
24962
  publishedAt: gh.published_at,
24928
24963
  url: gh.html_url,
24929
- isNewer: compareVersions(latestVersion, VERSION) > 0,
24964
+ isNewer: cmp > 0,
24965
+ isAhead: cmp < 0,
24930
24966
  currentVersion: VERSION
24931
24967
  };
24932
24968
  memoryCache = { data, fetchedAt: Date.now() };
@@ -25034,14 +25070,18 @@ var serverPulseTools = [
25034
25070
  const sep = "\u2500".repeat(50);
25035
25071
  sections.push(`SERVER PULSE \u2014 ${SERVER_TITLE} v${VERSION}`, sep, "Package: @usex/mikrotik-mcp", `Version: ${VERSION}`, `Uptime: ${formatUptime(uptime)}`, `Website: ${WEBSITE_URL}`);
25036
25072
  if (result.release) {
25037
- const freshness = assessFreshness(VERSION, result.release.version);
25038
- const label = freshnessLabel(freshness);
25039
25073
  const age = timeAgo(result.release.publishedAt);
25040
- sections.push("", `UPDATE STATUS: ${label}`, sep, `Current: v${VERSION}`, `Latest: v${result.release.version} (${result.release.name})`, `Published: ${age}`, `Freshness: ${freshness.toUpperCase()}`);
25041
- if (result.release.isNewer) {
25042
- sections.push("", ">>> A newer version is available! <<<");
25074
+ if (result.release.isAhead) {
25075
+ sections.push("", "UPDATE STATUS: AHEAD OF LATEST RELEASE", sep, `Current: v${VERSION}`, `Published: v${result.release.version} (${result.release.name})`, `Released: ${age}`, `Freshness: DEV BUILD`, "", "You are running ahead of the latest published release.");
25043
25076
  } else {
25044
- sections.push("", "You are running the latest version.");
25077
+ const freshness = assessFreshness(VERSION, result.release.version);
25078
+ const label = freshnessLabel(freshness);
25079
+ sections.push("", `UPDATE STATUS: ${label}`, sep, `Current: v${VERSION}`, `Latest: v${result.release.version} (${result.release.name})`, `Published: ${age}`, `Freshness: ${freshness.toUpperCase()}`);
25080
+ if (result.release.isNewer) {
25081
+ sections.push("", ">>> A newer version is available! <<<");
25082
+ } else {
25083
+ sections.push("", "You are running the latest version.");
25084
+ }
25045
25085
  }
25046
25086
  if (result.release.isNewer) {
25047
25087
  sections.push("", "UPGRADE", sep);