@solomonneas/proxmox-mcp 0.5.1 → 0.12.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/mcp-bin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // mcp-server.ts
3
+ // src/server.ts
4
4
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
5
5
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
6
  import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
@@ -59,7 +59,6 @@ var ProxmoxClientError = class extends Error {
59
59
  this.status = status;
60
60
  this.name = "ProxmoxClientError";
61
61
  }
62
- status;
63
62
  };
64
63
  var ProxmoxUnreachableError = class extends Error {
65
64
  constructor(cause) {
@@ -74,7 +73,6 @@ var ProxmoxClient = class {
74
73
  this.retryDelayMs = opts.retryDelayMs ?? 1e3;
75
74
  this.usesInsecureTls = cfg.tlsInsecure && cfg.url.startsWith("https://");
76
75
  }
77
- cfg;
78
76
  authHeader;
79
77
  retryDelayMs;
80
78
  usesInsecureTls;
@@ -84,6 +82,9 @@ var ProxmoxClient = class {
84
82
  async post(path2, body) {
85
83
  return this.request("POST", path2, body);
86
84
  }
85
+ async put(path2, body) {
86
+ return this.request("PUT", path2, body);
87
+ }
87
88
  async delete(path2) {
88
89
  return this.request("DELETE", path2);
89
90
  }
@@ -96,6 +97,13 @@ var ProxmoxClient = class {
96
97
  const form = new URLSearchParams();
97
98
  for (const [k, v] of Object.entries(body)) {
98
99
  if (v === void 0 || v === null) continue;
100
+ if (Array.isArray(v)) {
101
+ for (const item of v) {
102
+ if (item === void 0 || item === null) continue;
103
+ form.append(k, typeof item === "object" ? JSON.stringify(item) : String(item));
104
+ }
105
+ continue;
106
+ }
99
107
  form.append(k, typeof v === "object" ? JSON.stringify(v) : String(v));
100
108
  }
101
109
  headers["content-type"] = "application/x-www-form-urlencoded";
@@ -184,7 +192,6 @@ var SshExecError = class extends Error {
184
192
  this.phase = phase;
185
193
  this.name = "SshExecError";
186
194
  }
187
- phase;
188
195
  };
189
196
  function expandHome(p) {
190
197
  if (p.startsWith("~/")) return homedir() + p.slice(1);
@@ -323,19 +330,39 @@ async function execViaDirectSsh(targetCfg, command, timeoutMs, stdin) {
323
330
  // src/security.ts
324
331
  var SECRETS = /* @__PURE__ */ new Set();
325
332
  var BASE64_TOKEN_RE = /[A-Za-z0-9+/=]{12,}/g;
333
+ var MIN_SUBSTRING_LENGTH = 8;
334
+ var warnedShortSecret = false;
335
+ function escapeRegExp(s) {
336
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
337
+ }
326
338
  function registerSecret(s) {
327
- if (s && s.length > 0) SECRETS.add(s);
339
+ if (!s || s.length === 0) return;
340
+ SECRETS.add(s);
341
+ if (s.length < MIN_SUBSTRING_LENGTH && !warnedShortSecret) {
342
+ warnedShortSecret = true;
343
+ console.error(
344
+ `proxmox-mcp: a registered secret is shorter than ${MIN_SUBSTRING_LENGTH} characters. It is still redacted, but only where it appears as a standalone value. If this is PROXMOX_TOKEN_SECRET, check that it was not truncated.`
345
+ );
346
+ }
328
347
  }
329
348
  function maskString(s) {
330
349
  let out = s;
331
350
  for (const secret of SECRETS) {
332
- if (out.includes(secret)) out = out.split(secret).join("REDACTED");
351
+ if (!out.includes(secret)) continue;
352
+ if (secret.length >= MIN_SUBSTRING_LENGTH) {
353
+ out = out.split(secret).join("REDACTED");
354
+ } else {
355
+ out = out.replace(
356
+ new RegExp(`(^|[^A-Za-z0-9])${escapeRegExp(secret)}(?=[^A-Za-z0-9]|$)`, "g"),
357
+ (_match, left) => `${left}REDACTED`
358
+ );
359
+ }
333
360
  }
334
361
  out = out.replace(BASE64_TOKEN_RE, (token) => {
335
362
  try {
336
363
  const decoded = Buffer.from(token, "base64").toString("utf8");
337
364
  for (const secret of SECRETS) {
338
- if (decoded.includes(secret)) return "REDACTED";
365
+ if (secret.length >= MIN_SUBSTRING_LENGTH && decoded.includes(secret)) return "REDACTED";
339
366
  }
340
367
  } catch {
341
368
  }
@@ -398,6 +425,7 @@ async function resolveResource(client, vmid) {
398
425
  const where = matches.map((m) => `${m.node}/${m.type}`).join(", ");
399
426
  throw new Error(`vmid ${vmid} ambiguous - found on multiple nodes: ${where}. Refusing to proceed.`);
400
427
  }
428
+ assertSafePathSegment(matches[0].node, "node");
401
429
  return { node: matches[0].node, type: matches[0].type };
402
430
  }
403
431
  function parseTaskUpid(upid) {
@@ -408,6 +436,7 @@ function parseTaskUpid(upid) {
408
436
  if (parts.length < 8) throw new Error(`invalid UPID format: ${upid}`);
409
437
  const node = parts[1];
410
438
  if (!node) throw new Error(`UPID missing node segment: ${upid}`);
439
+ if (!SAFE_SEGMENT_RE.test(node)) throw new Error(`invalid UPID format: bad node segment "${node}"`);
411
440
  return { node };
412
441
  }
413
442
 
@@ -1091,23 +1120,56 @@ function createProxmoxRollbackSnapshotTool(getClient) {
1091
1120
  }
1092
1121
 
1093
1122
  // src/tools/proxmox_run_backup.ts
1123
+ import { Type as Type18 } from "@sinclair/typebox";
1124
+
1125
+ // src/tools/task-wait.ts
1094
1126
  import { Type as Type17 } from "@sinclair/typebox";
1095
- var Schema17 = Type17.Object(
1127
+ var taskWaitFields = {
1128
+ wait: Type17.Optional(
1129
+ Type17.Boolean({ description: "Block until the task finishes and include its exit status in the result." })
1130
+ ),
1131
+ wait_timeout: Type17.Optional(
1132
+ Type17.Integer({ minimum: 1, maximum: 3600, description: "Max seconds to wait when wait:true (default 120)." })
1133
+ )
1134
+ };
1135
+ function sleep2(ms) {
1136
+ return new Promise((resolve) => setTimeout(resolve, ms));
1137
+ }
1138
+ async function resolveTaskWait(client, upid, args, intervalMs = 1e3) {
1139
+ if (!args.wait || typeof upid !== "string" || !upid.startsWith("UPID:")) return void 0;
1140
+ const { node } = parseTaskUpid(upid);
1141
+ const deadline = Date.now() + (args.wait_timeout ?? 120) * 1e3;
1142
+ let polls = 0;
1143
+ let last = null;
1144
+ while (Date.now() <= deadline) {
1145
+ polls += 1;
1146
+ last = await client.get(`/nodes/${node}/tasks/${encodeURIComponent(upid)}/status`);
1147
+ if (last.status === "stopped" || last.exitstatus) {
1148
+ return { done: true, polls, status: last.status, exitstatus: last.exitstatus, ok: last.exitstatus === "OK" };
1149
+ }
1150
+ await sleep2(Math.min(intervalMs, Math.max(0, deadline - Date.now())));
1151
+ }
1152
+ return { done: false, polls, status: last?.status };
1153
+ }
1154
+
1155
+ // src/tools/proxmox_run_backup.ts
1156
+ var Schema17 = Type18.Object(
1096
1157
  {
1097
- vmid: Type17.Integer({ minimum: 1, description: "Container or VM ID to back up." }),
1098
- storage: Type17.String({
1158
+ vmid: Type18.Integer({ minimum: 1, description: "Container or VM ID to back up." }),
1159
+ storage: Type18.String({
1099
1160
  minLength: 1,
1100
1161
  description: "PVE storage ID where the vzdump archive should be written."
1101
1162
  }),
1102
- mode: Type17.Optional(
1103
- Type17.Union(
1104
- [Type17.Literal("snapshot"), Type17.Literal("suspend"), Type17.Literal("stop")],
1163
+ mode: Type18.Optional(
1164
+ Type18.Union(
1165
+ [Type18.Literal("snapshot"), Type18.Literal("suspend"), Type18.Literal("stop")],
1105
1166
  { description: "Backup mode. Defaults to 'snapshot'." }
1106
1167
  )
1107
1168
  ),
1108
- confirm: Type17.Boolean({
1169
+ confirm: Type18.Boolean({
1109
1170
  description: "Must be true to write. Tier-2 safe-write gate."
1110
- })
1171
+ }),
1172
+ ...taskWaitFields
1111
1173
  },
1112
1174
  { additionalProperties: false }
1113
1175
  );
@@ -1130,23 +1192,25 @@ function createProxmoxRunBackupTool(getClient) {
1130
1192
  mode,
1131
1193
  compress: "zstd"
1132
1194
  });
1195
+ const task = await resolveTaskWait(client, upid, args);
1133
1196
  return jsonToolResult({
1134
1197
  vmid: args.vmid,
1135
1198
  node,
1136
1199
  storage: args.storage,
1137
1200
  mode,
1138
- upid
1201
+ upid,
1202
+ ...task ? { task } : {}
1139
1203
  });
1140
1204
  }
1141
1205
  };
1142
1206
  }
1143
1207
 
1144
1208
  // src/tools/proxmox_get_task_status.ts
1145
- import { Type as Type18 } from "@sinclair/typebox";
1209
+ import { Type as Type19 } from "@sinclair/typebox";
1146
1210
  var NAME15 = "proxmox_get_task_status";
1147
- var Schema18 = Type18.Object(
1211
+ var Schema18 = Type19.Object(
1148
1212
  {
1149
- upid: Type18.String({
1213
+ upid: Type19.String({
1150
1214
  minLength: 1,
1151
1215
  description: "Task UPID returned by a prior write tool (e.g. start, stop, snapshot, backup)."
1152
1216
  })
@@ -1172,19 +1236,19 @@ function createProxmoxGetTaskStatusTool(getClient) {
1172
1236
  }
1173
1237
 
1174
1238
  // src/tools/proxmox_get_task_log.ts
1175
- import { Type as Type19 } from "@sinclair/typebox";
1239
+ import { Type as Type20 } from "@sinclair/typebox";
1176
1240
  var NAME16 = "proxmox_get_task_log";
1177
- var Schema19 = Type19.Object(
1241
+ var Schema19 = Type20.Object(
1178
1242
  {
1179
- upid: Type19.String({
1243
+ upid: Type20.String({
1180
1244
  minLength: 1,
1181
1245
  description: "Task UPID returned by a prior write tool."
1182
1246
  }),
1183
- start: Type19.Optional(
1184
- Type19.Integer({ minimum: 0, description: "Line offset to start from (default 0)." })
1247
+ start: Type20.Optional(
1248
+ Type20.Integer({ minimum: 0, description: "Line offset to start from (default 0)." })
1185
1249
  ),
1186
- limit: Type19.Optional(
1187
- Type19.Integer({
1250
+ limit: Type20.Optional(
1251
+ Type20.Integer({
1188
1252
  minimum: 1,
1189
1253
  maximum: 500,
1190
1254
  description: "Max lines to return (default 50, max 500)."
@@ -1214,19 +1278,19 @@ function createProxmoxGetTaskLogTool(getClient) {
1214
1278
  }
1215
1279
 
1216
1280
  // src/tools/proxmox_list_templates.ts
1217
- import { Type as Type20 } from "@sinclair/typebox";
1281
+ import { Type as Type21 } from "@sinclair/typebox";
1218
1282
  var NAME17 = "proxmox_list_templates";
1219
- var Schema20 = Type20.Object(
1283
+ var Schema20 = Type21.Object(
1220
1284
  {
1221
- node: Type20.Optional(
1222
- Type20.String({ minLength: 1, description: "Node to query (defaults to first node)." })
1285
+ node: Type21.Optional(
1286
+ Type21.String({ minLength: 1, description: "Node to query (defaults to first node)." })
1223
1287
  ),
1224
- storage: Type20.Optional(
1225
- Type20.String({ minLength: 1, description: "Storage to query (defaults to 'local')." })
1288
+ storage: Type21.Optional(
1289
+ Type21.String({ minLength: 1, description: "Storage to query (defaults to 'local')." })
1226
1290
  ),
1227
- kind: Type20.Optional(
1228
- Type20.Union(
1229
- [Type20.Literal("vztmpl"), Type20.Literal("iso"), Type20.Literal("both")],
1291
+ kind: Type21.Optional(
1292
+ Type21.Union(
1293
+ [Type21.Literal("vztmpl"), Type21.Literal("iso"), Type21.Literal("both")],
1230
1294
  { description: "Template kind: 'vztmpl' (CT templates), 'iso' (VM ISOs), or 'both'. Defaults to 'both'." }
1231
1295
  )
1232
1296
  )
@@ -1274,11 +1338,11 @@ function createProxmoxListTemplatesTool(getClient) {
1274
1338
  }
1275
1339
 
1276
1340
  // src/tools/proxmox_list_storage.ts
1277
- import { Type as Type21 } from "@sinclair/typebox";
1278
- var Schema21 = Type21.Object(
1341
+ import { Type as Type22 } from "@sinclair/typebox";
1342
+ var Schema21 = Type22.Object(
1279
1343
  {
1280
- node: Type21.Optional(
1281
- Type21.String({ minLength: 1, description: "Node to query. Defaults to all nodes." })
1344
+ node: Type22.Optional(
1345
+ Type22.String({ minLength: 1, description: "Node to query. Defaults to all nodes." })
1282
1346
  )
1283
1347
  },
1284
1348
  { additionalProperties: false }
@@ -1312,10 +1376,10 @@ function createProxmoxListStorageTool(getClient) {
1312
1376
  }
1313
1377
 
1314
1378
  // src/tools/proxmox_list_snapshots.ts
1315
- import { Type as Type22 } from "@sinclair/typebox";
1316
- var Schema22 = Type22.Object(
1379
+ import { Type as Type23 } from "@sinclair/typebox";
1380
+ var Schema22 = Type23.Object(
1317
1381
  {
1318
- vmid: Type22.Integer({ minimum: 1, description: "Container or VM ID." })
1382
+ vmid: Type23.Integer({ minimum: 1, description: "Container or VM ID." })
1319
1383
  },
1320
1384
  { additionalProperties: false }
1321
1385
  );
@@ -1337,10 +1401,10 @@ function createProxmoxListSnapshotsTool(getClient) {
1337
1401
  }
1338
1402
 
1339
1403
  // src/tools/proxmox_guest_network.ts
1340
- import { Type as Type23 } from "@sinclair/typebox";
1341
- var Schema23 = Type23.Object(
1404
+ import { Type as Type24 } from "@sinclair/typebox";
1405
+ var Schema23 = Type24.Object(
1342
1406
  {
1343
- vmid: Type23.Integer({ minimum: 1, description: "Container or VM ID." })
1407
+ vmid: Type24.Integer({ minimum: 1, description: "Container or VM ID." })
1344
1408
  },
1345
1409
  { additionalProperties: false }
1346
1410
  );
@@ -1379,15 +1443,15 @@ function createProxmoxGuestNetworkTool(getClient) {
1379
1443
  }
1380
1444
 
1381
1445
  // src/tools/proxmox_wait_task.ts
1382
- import { Type as Type24 } from "@sinclair/typebox";
1383
- var Schema24 = Type24.Object(
1446
+ import { Type as Type25 } from "@sinclair/typebox";
1447
+ var Schema24 = Type25.Object(
1384
1448
  {
1385
- upid: Type24.String({ minLength: 1, description: "Task UPID to wait for." }),
1386
- timeoutSeconds: Type24.Optional(
1387
- Type24.Integer({ minimum: 1, maximum: 3600, description: "Max wait time in seconds. Default 60." })
1449
+ upid: Type25.String({ minLength: 1, description: "Task UPID to wait for." }),
1450
+ timeoutSeconds: Type25.Optional(
1451
+ Type25.Integer({ minimum: 1, maximum: 3600, description: "Max wait time in seconds. Default 60." })
1388
1452
  ),
1389
- intervalMs: Type24.Optional(
1390
- Type24.Integer({ minimum: 100, maximum: 1e4, description: "Polling interval in milliseconds. Default 1000." })
1453
+ intervalMs: Type25.Optional(
1454
+ Type25.Integer({ minimum: 100, maximum: 1e4, description: "Polling interval in milliseconds. Default 1000." })
1391
1455
  )
1392
1456
  },
1393
1457
  { additionalProperties: false }
@@ -1416,19 +1480,19 @@ function createProxmoxWaitTaskTool(getClient) {
1416
1480
  if (lastStatus.status === "stopped" || lastStatus.exitstatus) {
1417
1481
  return jsonToolResult({ upid: args.upid, node, done: true, polls, status: lastStatus });
1418
1482
  }
1419
- await sleep2(Math.min(intervalMs, Math.max(0, deadline - Date.now())));
1483
+ await sleep3(Math.min(intervalMs, Math.max(0, deadline - Date.now())));
1420
1484
  }
1421
1485
  return jsonToolResult({ upid: args.upid, node, done: false, polls, status: lastStatus });
1422
1486
  }
1423
1487
  };
1424
1488
  }
1425
- function sleep2(ms) {
1489
+ function sleep3(ms) {
1426
1490
  return new Promise((resolve) => setTimeout(resolve, ms));
1427
1491
  }
1428
1492
 
1429
1493
  // src/tools/proxmox_next_vmid.ts
1430
- import { Type as Type25 } from "@sinclair/typebox";
1431
- var Schema25 = Type25.Object({}, { additionalProperties: false });
1494
+ import { Type as Type26 } from "@sinclair/typebox";
1495
+ var Schema25 = Type26.Object({}, { additionalProperties: false });
1432
1496
  var NAME22 = "proxmox_next_vmid";
1433
1497
  function createProxmoxNextVmidTool(getClient) {
1434
1498
  return {
@@ -1445,11 +1509,11 @@ function createProxmoxNextVmidTool(getClient) {
1445
1509
  }
1446
1510
 
1447
1511
  // src/tools/proxmox_list_pool_resources.ts
1448
- import { Type as Type26 } from "@sinclair/typebox";
1449
- var Schema26 = Type26.Object(
1512
+ import { Type as Type27 } from "@sinclair/typebox";
1513
+ var Schema26 = Type27.Object(
1450
1514
  {
1451
- pool: Type26.Optional(
1452
- Type26.String({ minLength: 1, description: "Pool ID to inspect (default mcp-smoke)." })
1515
+ pool: Type27.Optional(
1516
+ Type27.String({ minLength: 1, description: "Pool ID to inspect (default mcp-smoke)." })
1453
1517
  )
1454
1518
  },
1455
1519
  { additionalProperties: false }
@@ -1477,69 +1541,70 @@ function createProxmoxListPoolResourcesTool(getClient) {
1477
1541
  }
1478
1542
 
1479
1543
  // src/tools/proxmox_create_container.ts
1480
- import { Type as Type27 } from "@sinclair/typebox";
1481
- var Schema27 = Type27.Object(
1544
+ import { Type as Type28 } from "@sinclair/typebox";
1545
+ var Schema27 = Type28.Object(
1482
1546
  {
1483
- vmid: Type27.Integer({ minimum: 1, description: "VMID for the new container." }),
1484
- hostname: Type27.String({ minLength: 1, description: "Container hostname." }),
1485
- ostemplate: Type27.String({
1547
+ vmid: Type28.Integer({ minimum: 1, description: "VMID for the new container." }),
1548
+ hostname: Type28.String({ minLength: 1, description: "Container hostname." }),
1549
+ ostemplate: Type28.String({
1486
1550
  minLength: 1,
1487
1551
  description: "OS template volid (e.g. 'local:vztmpl/ubuntu-24.04-standard_*.tar.zst')."
1488
1552
  }),
1489
- node: Type27.Optional(
1490
- Type27.String({ minLength: 1, description: "Node to create on (defaults to first node)." })
1553
+ node: Type28.Optional(
1554
+ Type28.String({ minLength: 1, description: "Node to create on (defaults to first node)." })
1491
1555
  ),
1492
- storage: Type27.Optional(
1493
- Type27.String({ minLength: 1, description: "Root storage (default 'local-lvm')." })
1556
+ storage: Type28.Optional(
1557
+ Type28.String({ minLength: 1, description: "Root storage (default 'local-lvm')." })
1494
1558
  ),
1495
- memory: Type27.Optional(
1496
- Type27.Integer({ minimum: 16, description: "Memory in MiB (default 512)." })
1559
+ memory: Type28.Optional(
1560
+ Type28.Integer({ minimum: 16, description: "Memory in MiB (default 512)." })
1497
1561
  ),
1498
- cores: Type27.Optional(
1499
- Type27.Integer({ minimum: 1, description: "CPU cores (default 1)." })
1562
+ cores: Type28.Optional(
1563
+ Type28.Integer({ minimum: 1, description: "CPU cores (default 1)." })
1500
1564
  ),
1501
- rootfs_size: Type27.Optional(
1502
- Type27.String({ minLength: 1, description: "Root filesystem size in GB (default '8')." })
1565
+ rootfs_size: Type28.Optional(
1566
+ Type28.String({ minLength: 1, description: "Root filesystem size in GB (default '8')." })
1503
1567
  ),
1504
- net: Type27.Optional(
1505
- Type27.String({
1568
+ net: Type28.Optional(
1569
+ Type28.String({
1506
1570
  minLength: 1,
1507
1571
  description: "Network config for net0 (default 'name=eth0,bridge=vmbr0,ip=dhcp')."
1508
1572
  })
1509
1573
  ),
1510
- start: Type27.Optional(
1511
- Type27.Boolean({ description: "Start after create (default false)." })
1574
+ start: Type28.Optional(
1575
+ Type28.Boolean({ description: "Start after create (default false)." })
1512
1576
  ),
1513
- pool: Type27.Optional(
1514
- Type27.String({ minLength: 1, description: "Optional resource pool ID to place the container into." })
1577
+ pool: Type28.Optional(
1578
+ Type28.String({ minLength: 1, description: "Optional resource pool ID to place the container into." })
1515
1579
  ),
1516
- onboot: Type27.Optional(
1517
- Type27.Boolean({ description: "Start container on host boot (default false)." })
1580
+ onboot: Type28.Optional(
1581
+ Type28.Boolean({ description: "Start container on host boot (default false)." })
1518
1582
  ),
1519
- unprivileged: Type27.Optional(
1520
- Type27.Boolean({ description: "Create an unprivileged container (default true)." })
1583
+ unprivileged: Type28.Optional(
1584
+ Type28.Boolean({ description: "Create an unprivileged container (default true)." })
1521
1585
  ),
1522
- protection: Type27.Optional(
1523
- Type27.Boolean({ description: "Enable Proxmox protection flag (default false)." })
1586
+ protection: Type28.Optional(
1587
+ Type28.Boolean({ description: "Enable Proxmox protection flag (default false)." })
1524
1588
  ),
1525
- features: Type27.Optional(
1526
- Type27.String({ minLength: 1, description: "Optional LXC features string, e.g. 'nesting=1'." })
1589
+ features: Type28.Optional(
1590
+ Type28.String({ minLength: 1, description: "Optional LXC features string, e.g. 'nesting=1'." })
1527
1591
  ),
1528
- description: Type27.Optional(
1529
- Type27.String({ description: "Optional container description." })
1592
+ description: Type28.Optional(
1593
+ Type28.String({ description: "Optional container description." })
1530
1594
  ),
1531
- tags: Type27.Optional(
1532
- Type27.String({ minLength: 1, description: "Optional semicolon-delimited Proxmox tags." })
1595
+ tags: Type28.Optional(
1596
+ Type28.String({ minLength: 1, description: "Optional semicolon-delimited Proxmox tags." })
1533
1597
  ),
1534
- password: Type27.Optional(
1535
- Type27.String({ description: "Root password (optional)." })
1598
+ password: Type28.Optional(
1599
+ Type28.String({ description: "Root password (optional)." })
1536
1600
  ),
1537
- ssh_public_keys: Type27.Optional(
1538
- Type27.String({ description: "SSH public keys (optional)." })
1601
+ ssh_public_keys: Type28.Optional(
1602
+ Type28.String({ description: "SSH public keys (optional)." })
1539
1603
  ),
1540
- confirm: Type27.Boolean({
1604
+ confirm: Type28.Boolean({
1541
1605
  description: "Must be true to write. Tier-2 safe-write gate."
1542
- })
1606
+ }),
1607
+ ...taskWaitFields
1543
1608
  },
1544
1609
  { additionalProperties: false }
1545
1610
  );
@@ -1558,7 +1623,9 @@ function createProxmoxCreateContainerTool(getClient) {
1558
1623
  }
1559
1624
  const client = getClient();
1560
1625
  let node = args.node;
1561
- if (!node) {
1626
+ if (node) {
1627
+ assertSafePathSegment(node, "node");
1628
+ } else {
1562
1629
  const nodes = await client.get("/cluster/resources?type=node");
1563
1630
  if (nodes.length === 0) throw new Error("no nodes found in cluster resources");
1564
1631
  node = nodes[0].node;
@@ -1596,109 +1663,112 @@ function createProxmoxCreateContainerTool(getClient) {
1596
1663
  body.tags = args.tags;
1597
1664
  }
1598
1665
  const upid = await client.post(`/nodes/${node}/lxc`, body);
1666
+ const task = await resolveTaskWait(client, upid, args);
1599
1667
  return jsonToolResult({
1600
1668
  vmid: args.vmid,
1601
1669
  node,
1602
1670
  hostname: args.hostname,
1603
- upid
1671
+ upid,
1672
+ ...task ? { task } : {}
1604
1673
  });
1605
1674
  }
1606
1675
  };
1607
1676
  }
1608
1677
 
1609
1678
  // src/tools/proxmox_create_vm.ts
1610
- import { Type as Type28 } from "@sinclair/typebox";
1611
- var Schema28 = Type28.Object(
1679
+ import { Type as Type29 } from "@sinclair/typebox";
1680
+ var Schema28 = Type29.Object(
1612
1681
  {
1613
- vmid: Type28.Integer({ minimum: 1, description: "VMID for the new VM." }),
1614
- name: Type28.String({ minLength: 1, description: "VM display name." }),
1615
- node: Type28.Optional(
1616
- Type28.String({ minLength: 1, description: "Node to create on (defaults to first node)." })
1682
+ vmid: Type29.Integer({ minimum: 1, description: "VMID for the new VM." }),
1683
+ name: Type29.String({ minLength: 1, description: "VM display name." }),
1684
+ node: Type29.Optional(
1685
+ Type29.String({ minLength: 1, description: "Node to create on (defaults to first node)." })
1617
1686
  ),
1618
- memory: Type28.Optional(
1619
- Type28.Integer({ minimum: 16, description: "Memory in MiB (default 2048)." })
1687
+ memory: Type29.Optional(
1688
+ Type29.Integer({ minimum: 16, description: "Memory in MiB (default 2048)." })
1620
1689
  ),
1621
- cores: Type28.Optional(
1622
- Type28.Integer({ minimum: 1, description: "CPU cores (default 2)." })
1690
+ cores: Type29.Optional(
1691
+ Type29.Integer({ minimum: 1, description: "CPU cores (default 2)." })
1623
1692
  ),
1624
- iso: Type28.Optional(
1625
- Type28.String({
1693
+ iso: Type29.Optional(
1694
+ Type29.String({
1626
1695
  minLength: 1,
1627
1696
  description: "ISO volid for install media (e.g. 'local:iso/ubuntu-24.04.iso'). If set, attaches as ide2 cdrom."
1628
1697
  })
1629
1698
  ),
1630
- disk_size: Type28.Optional(
1631
- Type28.String({ minLength: 1, description: "Primary disk size in GB on scsi0 (default '32')." })
1699
+ disk_size: Type29.Optional(
1700
+ Type29.String({ minLength: 1, description: "Primary disk size in GB on scsi0 (default '32')." })
1632
1701
  ),
1633
- storage: Type28.Optional(
1634
- Type28.String({ minLength: 1, description: "Disk storage (default 'local-lvm')." })
1702
+ storage: Type29.Optional(
1703
+ Type29.String({ minLength: 1, description: "Disk storage (default 'local-lvm')." })
1635
1704
  ),
1636
- net: Type28.Optional(
1637
- Type28.String({
1705
+ net: Type29.Optional(
1706
+ Type29.String({
1638
1707
  minLength: 1,
1639
1708
  description: "Network config for net0 (default 'model=virtio,bridge=vmbr0')."
1640
1709
  })
1641
1710
  ),
1642
- start: Type28.Optional(
1643
- Type28.Boolean({ description: "Start after create (default false)." })
1711
+ start: Type29.Optional(
1712
+ Type29.Boolean({ description: "Start after create (default false)." })
1644
1713
  ),
1645
- pool: Type28.Optional(
1646
- Type28.String({ minLength: 1, description: "Optional resource pool ID to place the VM into." })
1714
+ pool: Type29.Optional(
1715
+ Type29.String({ minLength: 1, description: "Optional resource pool ID to place the VM into." })
1647
1716
  ),
1648
- onboot: Type28.Optional(
1649
- Type28.Boolean({ description: "Start VM on host boot (default false)." })
1717
+ onboot: Type29.Optional(
1718
+ Type29.Boolean({ description: "Start VM on host boot (default false)." })
1650
1719
  ),
1651
- protection: Type28.Optional(
1652
- Type28.Boolean({ description: "Enable Proxmox protection flag (default false)." })
1720
+ protection: Type29.Optional(
1721
+ Type29.Boolean({ description: "Enable Proxmox protection flag (default false)." })
1653
1722
  ),
1654
- agent: Type28.Optional(
1655
- Type28.Boolean({ description: "Enable QEMU guest agent in VM config (default false)." })
1723
+ agent: Type29.Optional(
1724
+ Type29.Boolean({ description: "Enable QEMU guest agent in VM config (default false)." })
1656
1725
  ),
1657
- scsihw: Type28.Optional(
1658
- Type28.String({ minLength: 1, description: "Optional SCSI controller, e.g. 'virtio-scsi-pci'." })
1726
+ scsihw: Type29.Optional(
1727
+ Type29.String({ minLength: 1, description: "Optional SCSI controller, e.g. 'virtio-scsi-pci'." })
1659
1728
  ),
1660
- boot: Type28.Optional(
1661
- Type28.String({ minLength: 1, description: "Optional boot order string." })
1729
+ boot: Type29.Optional(
1730
+ Type29.String({ minLength: 1, description: "Optional boot order string." })
1662
1731
  ),
1663
- bios: Type28.Optional(
1664
- Type28.Union([Type28.Literal("seabios"), Type28.Literal("ovmf")], { description: "Optional VM BIOS type." })
1732
+ bios: Type29.Optional(
1733
+ Type29.Union([Type29.Literal("seabios"), Type29.Literal("ovmf")], { description: "Optional VM BIOS type." })
1665
1734
  ),
1666
- machine: Type28.Optional(
1667
- Type28.String({ minLength: 1, description: "Optional machine type." })
1735
+ machine: Type29.Optional(
1736
+ Type29.String({ minLength: 1, description: "Optional machine type." })
1668
1737
  ),
1669
- cpu: Type28.Optional(
1670
- Type28.String({ minLength: 1, description: "Optional CPU type." })
1738
+ cpu: Type29.Optional(
1739
+ Type29.String({ minLength: 1, description: "Optional CPU type." })
1671
1740
  ),
1672
- sockets: Type28.Optional(
1673
- Type28.Integer({ minimum: 1, description: "Optional socket count." })
1741
+ sockets: Type29.Optional(
1742
+ Type29.Integer({ minimum: 1, description: "Optional socket count." })
1674
1743
  ),
1675
- description: Type28.Optional(
1676
- Type28.String({ description: "Optional VM description." })
1744
+ description: Type29.Optional(
1745
+ Type29.String({ description: "Optional VM description." })
1677
1746
  ),
1678
- tags: Type28.Optional(
1679
- Type28.String({ minLength: 1, description: "Optional semicolon-delimited Proxmox tags." })
1747
+ tags: Type29.Optional(
1748
+ Type29.String({ minLength: 1, description: "Optional semicolon-delimited Proxmox tags." })
1680
1749
  ),
1681
- ciuser: Type28.Optional(
1682
- Type28.String({ minLength: 1, description: "Optional cloud-init username." })
1750
+ ciuser: Type29.Optional(
1751
+ Type29.String({ minLength: 1, description: "Optional cloud-init username." })
1683
1752
  ),
1684
- cipassword: Type28.Optional(
1685
- Type28.String({ description: "Optional cloud-init password." })
1753
+ cipassword: Type29.Optional(
1754
+ Type29.String({ description: "Optional cloud-init password." })
1686
1755
  ),
1687
- sshkeys: Type28.Optional(
1688
- Type28.String({ description: "Optional cloud-init SSH public keys." })
1756
+ sshkeys: Type29.Optional(
1757
+ Type29.String({ description: "Optional cloud-init SSH public keys." })
1689
1758
  ),
1690
- ipconfig0: Type28.Optional(
1691
- Type28.String({ minLength: 1, description: "Optional cloud-init ipconfig0, e.g. 'ip=dhcp'." })
1759
+ ipconfig0: Type29.Optional(
1760
+ Type29.String({ minLength: 1, description: "Optional cloud-init ipconfig0, e.g. 'ip=dhcp'." })
1692
1761
  ),
1693
- nameserver: Type28.Optional(
1694
- Type28.String({ minLength: 1, description: "Optional cloud-init DNS server list." })
1762
+ nameserver: Type29.Optional(
1763
+ Type29.String({ minLength: 1, description: "Optional cloud-init DNS server list." })
1695
1764
  ),
1696
- searchdomain: Type28.Optional(
1697
- Type28.String({ minLength: 1, description: "Optional cloud-init DNS search domain." })
1765
+ searchdomain: Type29.Optional(
1766
+ Type29.String({ minLength: 1, description: "Optional cloud-init DNS search domain." })
1698
1767
  ),
1699
- confirm: Type28.Boolean({
1768
+ confirm: Type29.Boolean({
1700
1769
  description: "Must be true to write. Tier-2 safe-write gate."
1701
- })
1770
+ }),
1771
+ ...taskWaitFields
1702
1772
  },
1703
1773
  { additionalProperties: false }
1704
1774
  );
@@ -1717,7 +1787,9 @@ function createProxmoxCreateVmTool(getClient) {
1717
1787
  }
1718
1788
  const client = getClient();
1719
1789
  let node = args.node;
1720
- if (!node) {
1790
+ if (node) {
1791
+ assertSafePathSegment(node, "node");
1792
+ } else {
1721
1793
  const nodes = await client.get("/cluster/resources?type=node");
1722
1794
  if (nodes.length === 0) throw new Error("no nodes found in cluster resources");
1723
1795
  node = nodes[0].node;
@@ -1745,44 +1817,47 @@ function createProxmoxCreateVmTool(getClient) {
1745
1817
  }
1746
1818
  if (typeof args.sockets === "number") body.sockets = args.sockets;
1747
1819
  const upid = await client.post(`/nodes/${node}/qemu`, body);
1820
+ const task = await resolveTaskWait(client, upid, args);
1748
1821
  return jsonToolResult({
1749
1822
  vmid: args.vmid,
1750
1823
  node,
1751
1824
  name: args.name,
1752
- upid
1825
+ upid,
1826
+ ...task ? { task } : {}
1753
1827
  });
1754
1828
  }
1755
1829
  };
1756
1830
  }
1757
1831
 
1758
1832
  // src/tools/proxmox_clone_resource.ts
1759
- import { Type as Type29 } from "@sinclair/typebox";
1760
- var Schema29 = Type29.Object(
1833
+ import { Type as Type30 } from "@sinclair/typebox";
1834
+ var Schema29 = Type30.Object(
1761
1835
  {
1762
- source_vmid: Type29.Integer({ minimum: 1, description: "Source CT/VM ID to clone from." }),
1763
- new_vmid: Type29.Integer({ minimum: 1, description: "VMID for the cloned resource." }),
1764
- name: Type29.String({ minLength: 1, description: "Name/hostname for the new clone." }),
1765
- full: Type29.Optional(
1766
- Type29.Boolean({ description: "Full clone (default true). Set false for a linked clone." })
1836
+ source_vmid: Type30.Integer({ minimum: 1, description: "Source CT/VM ID to clone from." }),
1837
+ new_vmid: Type30.Integer({ minimum: 1, description: "VMID for the cloned resource." }),
1838
+ name: Type30.String({ minLength: 1, description: "Name/hostname for the new clone." }),
1839
+ full: Type30.Optional(
1840
+ Type30.Boolean({ description: "Full clone (default true). Set false for a linked clone." })
1767
1841
  ),
1768
- storage: Type29.Optional(
1769
- Type29.String({ minLength: 1, description: "Target storage (default: same as source)." })
1842
+ storage: Type30.Optional(
1843
+ Type30.String({ minLength: 1, description: "Target storage (default: same as source)." })
1770
1844
  ),
1771
- target_node: Type29.Optional(
1772
- Type29.String({ minLength: 1, description: "Optional target node for the clone." })
1845
+ target_node: Type30.Optional(
1846
+ Type30.String({ minLength: 1, description: "Optional target node for the clone." })
1773
1847
  ),
1774
- pool: Type29.Optional(
1775
- Type29.String({ minLength: 1, description: "Optional resource pool ID for the clone." })
1848
+ pool: Type30.Optional(
1849
+ Type30.String({ minLength: 1, description: "Optional resource pool ID for the clone." })
1776
1850
  ),
1777
- snapname: Type29.Optional(
1778
- Type29.String({ minLength: 1, description: "Clone from a named snapshot (optional)." })
1851
+ snapname: Type30.Optional(
1852
+ Type30.String({ minLength: 1, description: "Clone from a named snapshot (optional)." })
1779
1853
  ),
1780
- description: Type29.Optional(
1781
- Type29.String({ description: "Optional description for the clone." })
1854
+ description: Type30.Optional(
1855
+ Type30.String({ description: "Optional description for the clone." })
1782
1856
  ),
1783
- confirm: Type29.Boolean({
1857
+ confirm: Type30.Boolean({
1784
1858
  description: "Must be true to write. Tier-2 safe-write gate."
1785
- })
1859
+ }),
1860
+ ...taskWaitFields
1786
1861
  },
1787
1862
  { additionalProperties: false }
1788
1863
  );
@@ -1822,39 +1897,42 @@ function createProxmoxCloneResourceTool(getClient) {
1822
1897
  `/nodes/${node}/${type}/${args.source_vmid}/clone`,
1823
1898
  body
1824
1899
  );
1900
+ const task = await resolveTaskWait(client, upid, args);
1825
1901
  return jsonToolResult({
1826
1902
  source_vmid: args.source_vmid,
1827
1903
  new_vmid: args.new_vmid,
1828
1904
  node,
1829
1905
  type,
1830
1906
  name: args.name,
1831
- upid
1907
+ upid,
1908
+ ...task ? { task } : {}
1832
1909
  });
1833
1910
  }
1834
1911
  };
1835
1912
  }
1836
1913
 
1837
1914
  // src/tools/proxmox_destroy_resource.ts
1838
- import { Type as Type30 } from "@sinclair/typebox";
1839
- var Schema30 = Type30.Object(
1915
+ import { Type as Type31 } from "@sinclair/typebox";
1916
+ var Schema30 = Type31.Object(
1840
1917
  {
1841
- vmid: Type30.Integer({ minimum: 1, description: "Container or VM ID to destroy." }),
1842
- purge: Type30.Optional(
1843
- Type30.Boolean({
1918
+ vmid: Type31.Integer({ minimum: 1, description: "Container or VM ID to destroy." }),
1919
+ purge: Type31.Optional(
1920
+ Type31.Boolean({
1844
1921
  description: "Remove from PVE backup/replication config too (default true)."
1845
1922
  })
1846
1923
  ),
1847
- force: Type30.Optional(
1848
- Type30.Boolean({
1924
+ force: Type31.Optional(
1925
+ Type31.Boolean({
1849
1926
  description: "Allow destroying a running VM (default false)."
1850
1927
  })
1851
1928
  ),
1852
- confirm: Type30.Boolean({
1929
+ confirm: Type31.Boolean({
1853
1930
  description: "Must be true. Tier-3 destructive gate."
1854
1931
  }),
1855
- destructive: Type30.Boolean({
1932
+ destructive: Type31.Boolean({
1856
1933
  description: "Must be true. Tier-3 destructive gate."
1857
- })
1934
+ }),
1935
+ ...taskWaitFields
1858
1936
  },
1859
1937
  { additionalProperties: false }
1860
1938
  );
@@ -1882,46 +1960,47 @@ function createProxmoxDestroyResourceTool(getClient) {
1882
1960
  const qs = params.toString();
1883
1961
  const path2 = qs.length > 0 ? `/nodes/${node}/${type}/${args.vmid}?${qs}` : `/nodes/${node}/${type}/${args.vmid}`;
1884
1962
  const upid = await client.delete(path2);
1885
- return jsonToolResult({ vmid: args.vmid, node, type, upid });
1963
+ const task = await resolveTaskWait(client, upid, args);
1964
+ return jsonToolResult({ vmid: args.vmid, node, type, upid, ...task ? { task } : {} });
1886
1965
  }
1887
1966
  };
1888
1967
  }
1889
1968
 
1890
1969
  // src/tools/proxmox_cleanup_smoke_resources.ts
1891
- import { Type as Type31 } from "@sinclair/typebox";
1892
- var Schema31 = Type31.Object(
1970
+ import { Type as Type32 } from "@sinclair/typebox";
1971
+ var Schema31 = Type32.Object(
1893
1972
  {
1894
- pool: Type31.Optional(
1895
- Type31.String({ minLength: 1, description: "Pool ID to clean up (default mcp-smoke)." })
1973
+ pool: Type32.Optional(
1974
+ Type32.String({ minLength: 1, description: "Pool ID to clean up (default mcp-smoke)." })
1896
1975
  ),
1897
- name_prefix: Type31.Optional(
1898
- Type31.String({
1976
+ name_prefix: Type32.Optional(
1977
+ Type32.String({
1899
1978
  minLength: 1,
1900
1979
  description: "Only delete guest names starting with this prefix (default mcp-smoke-)."
1901
1980
  })
1902
1981
  ),
1903
- force: Type31.Optional(
1904
- Type31.Boolean({
1982
+ force: Type32.Optional(
1983
+ Type32.Boolean({
1905
1984
  description: "Allow deleting running smoke guests. Also passes force=1 for LXC cleanup (default false)."
1906
1985
  })
1907
1986
  ),
1908
- dry_run: Type31.Optional(
1909
- Type31.Boolean({ description: "Preview matching targets without deleting them (default true)." })
1987
+ dry_run: Type32.Optional(
1988
+ Type32.Boolean({ description: "Preview matching targets without deleting them (default true)." })
1910
1989
  ),
1911
- wait: Type31.Optional(
1912
- Type31.Boolean({ description: "Wait for delete tasks to finish when dry_run:false (default true)." })
1990
+ wait: Type32.Optional(
1991
+ Type32.Boolean({ description: "Wait for delete tasks to finish when dry_run:false (default true)." })
1913
1992
  ),
1914
- confirm: Type31.Optional(
1915
- Type31.Boolean({ description: "Must be true when dry_run:false. Tier-3 destructive gate." })
1993
+ confirm: Type32.Optional(
1994
+ Type32.Boolean({ description: "Must be true when dry_run:false. Tier-3 destructive gate." })
1916
1995
  ),
1917
- destructive: Type31.Optional(
1918
- Type31.Boolean({ description: "Must be true when dry_run:false. Tier-3 destructive gate." })
1996
+ destructive: Type32.Optional(
1997
+ Type32.Boolean({ description: "Must be true when dry_run:false. Tier-3 destructive gate." })
1919
1998
  ),
1920
- timeoutSeconds: Type31.Optional(
1921
- Type31.Integer({ minimum: 1, maximum: 3600, description: "Max seconds to wait per delete task (default 180)." })
1999
+ timeoutSeconds: Type32.Optional(
2000
+ Type32.Integer({ minimum: 1, maximum: 3600, description: "Max seconds to wait per delete task (default 180)." })
1922
2001
  ),
1923
- intervalMs: Type31.Optional(
1924
- Type31.Integer({ minimum: 100, maximum: 1e4, description: "Task polling interval in milliseconds (default 1000)." })
2002
+ intervalMs: Type32.Optional(
2003
+ Type32.Integer({ minimum: 100, maximum: 1e4, description: "Task polling interval in milliseconds (default 1000)." })
1925
2004
  )
1926
2005
  },
1927
2006
  { additionalProperties: false }
@@ -2021,18 +2100,18 @@ function createProxmoxCleanupSmokeResourcesTool(getClient) {
2021
2100
  }
2022
2101
 
2023
2102
  // src/tools/proxmox_delete_snapshot.ts
2024
- import { Type as Type32 } from "@sinclair/typebox";
2025
- var Schema32 = Type32.Object(
2103
+ import { Type as Type33 } from "@sinclair/typebox";
2104
+ var Schema32 = Type33.Object(
2026
2105
  {
2027
- vmid: Type32.Integer({ minimum: 1, description: "Container or VM ID." }),
2028
- snapname: Type32.String({
2106
+ vmid: Type33.Integer({ minimum: 1, description: "Container or VM ID." }),
2107
+ snapname: Type33.String({
2029
2108
  minLength: 1,
2030
2109
  description: "Snapshot name to delete."
2031
2110
  }),
2032
- confirm: Type32.Boolean({
2111
+ confirm: Type33.Boolean({
2033
2112
  description: "Must be true. Tier-3 destructive gate."
2034
2113
  }),
2035
- destructive: Type32.Boolean({
2114
+ destructive: Type33.Boolean({
2036
2115
  description: "Must be true. Tier-3 destructive gate."
2037
2116
  })
2038
2117
  },
@@ -2064,14 +2143,14 @@ function createProxmoxDeleteSnapshotTool(getClient) {
2064
2143
  }
2065
2144
 
2066
2145
  // src/tools/proxmox_force_stop_resource.ts
2067
- import { Type as Type33 } from "@sinclair/typebox";
2068
- var Schema33 = Type33.Object(
2146
+ import { Type as Type34 } from "@sinclair/typebox";
2147
+ var Schema33 = Type34.Object(
2069
2148
  {
2070
- vmid: Type33.Integer({ minimum: 1, description: "Container or VM ID to hard-stop." }),
2071
- confirm: Type33.Boolean({
2149
+ vmid: Type34.Integer({ minimum: 1, description: "Container or VM ID to hard-stop." }),
2150
+ confirm: Type34.Boolean({
2072
2151
  description: "Must be true. Tier-3 destructive gate."
2073
2152
  }),
2074
- destructive: Type33.Boolean({
2153
+ destructive: Type34.Boolean({
2075
2154
  description: "Must be true. Tier-3 destructive gate."
2076
2155
  })
2077
2156
  },
@@ -2100,7 +2179,41 @@ function createProxmoxForceStopResourceTool(getClient) {
2100
2179
  }
2101
2180
 
2102
2181
  // src/tools/proxmox_exec.ts
2103
- import { Type as Type34 } from "@sinclair/typebox";
2182
+ import { Type as Type35 } from "@sinclair/typebox";
2183
+
2184
+ // src/guest-agent.ts
2185
+ var GuestAgentError = class extends Error {
2186
+ constructor(message) {
2187
+ super(`guest-agent: ${message}`);
2188
+ this.name = "GuestAgentError";
2189
+ }
2190
+ };
2191
+ function sleep4(ms) {
2192
+ return new Promise((resolve) => setTimeout(resolve, ms));
2193
+ }
2194
+ async function execViaGuestAgent(client, node, vmid, command, timeoutMs, stdin, pollIntervalMs = 500) {
2195
+ const base = `/nodes/${node}/qemu/${vmid}/agent`;
2196
+ const body = { command: ["/bin/sh", "-c", command] };
2197
+ if (stdin !== void 0) body["input-data"] = stdin;
2198
+ const started = await client.post(`${base}/exec`, body);
2199
+ const pid = started?.pid;
2200
+ if (typeof pid !== "number") {
2201
+ throw new GuestAgentError(`agent/exec did not return a pid for vmid ${vmid}`);
2202
+ }
2203
+ const deadline = Date.now() + timeoutMs;
2204
+ while (Date.now() <= deadline) {
2205
+ const status = await client.get(`${base}/exec-status?pid=${pid}`);
2206
+ if (status.exited === 1 || status.exited === true) {
2207
+ return {
2208
+ stdout: status["out-data"] ?? "",
2209
+ stderr: status["err-data"] ?? "",
2210
+ exitCode: typeof status.exitcode === "number" ? status.exitcode : -1
2211
+ };
2212
+ }
2213
+ await sleep4(Math.min(pollIntervalMs, Math.max(0, deadline - Date.now())));
2214
+ }
2215
+ throw new GuestAgentError(`command in vmid ${vmid} did not finish within ${timeoutMs}ms`);
2216
+ }
2104
2217
 
2105
2218
  // src/tools/ssh-target.ts
2106
2219
  function nonEmptyEnv(key) {
@@ -2148,15 +2261,44 @@ function missingQemuSshHostMessage(vmid) {
2148
2261
  return `vmid ${vmid} is QEMU and has no PROXMOX_VM_${vmid}_SSH_HOST set and guest agent did not return a usable IP. Install qemu-guest-agent in the VM and enable it with 'qm set ${vmid} --agent 1', or pin the IP via env.`;
2149
2262
  }
2150
2263
 
2264
+ // src/tools/guest-command.ts
2265
+ function resolveExecBackend() {
2266
+ const v = (process.env.PROXMOX_EXEC_BACKEND ?? "ssh").toLowerCase();
2267
+ return v === "guest-agent" || v === "agent" ? "guest-agent" : "ssh";
2268
+ }
2269
+ async function execInQemuGuest(client, ssh, node, vmid, command, timeoutMs, vmDefaults, stdin) {
2270
+ if (resolveExecBackend() === "guest-agent") {
2271
+ return execViaGuestAgent(client, node, vmid, command, timeoutMs, stdin);
2272
+ }
2273
+ const host = await resolveQemuSshHost(client, node, vmid);
2274
+ if (!host) throw new Error(missingQemuSshHostMessage(vmid));
2275
+ return ssh.execViaDirectSsh(qemuSshTarget(vmid, host, vmDefaults), command, timeoutMs, stdin);
2276
+ }
2277
+ function shellSingleQuote(s) {
2278
+ return `'${s.replace(/'/g, `'\\''`)}'`;
2279
+ }
2280
+ function assertAbsoluteGuestPath(path2, toolName) {
2281
+ if (!path2.startsWith("/")) throw new Error(`${toolName} path must be absolute`);
2282
+ if (path2.includes("\0")) throw new Error(`${toolName} path cannot contain NUL bytes`);
2283
+ }
2284
+ async function runGuestCommand(client, ssh, vmDefaults, vmid, command, timeoutMs, stdin) {
2285
+ const { node, type } = await resolveResource(client, vmid);
2286
+ if (type === "lxc") {
2287
+ return { node, type, result: await ssh.execInLxc(vmid, command, timeoutMs, stdin) };
2288
+ }
2289
+ const result = await execInQemuGuest(client, ssh, node, vmid, command, timeoutMs, vmDefaults, stdin);
2290
+ return { node, type, result };
2291
+ }
2292
+
2151
2293
  // src/tools/proxmox_exec.ts
2152
- var Schema34 = Type34.Object(
2294
+ var Schema34 = Type35.Object(
2153
2295
  {
2154
- vmid: Type34.Integer({ minimum: 1, description: "Container or VM id." }),
2155
- command: Type34.String({ minLength: 1, description: "Shell command to run inside the resource." }),
2156
- timeout: Type34.Optional(
2157
- Type34.Integer({ minimum: 1, maximum: 3600, description: "Timeout in seconds (default 30)." })
2296
+ vmid: Type35.Integer({ minimum: 1, description: "Container or VM id." }),
2297
+ command: Type35.String({ minLength: 1, description: "Shell command to run inside the resource." }),
2298
+ timeout: Type35.Optional(
2299
+ Type35.Integer({ minimum: 1, maximum: 3600, description: "Timeout in seconds (default 30)." })
2158
2300
  ),
2159
- confirm: Type34.Boolean({ description: "Must be true to execute. Tier-2 safe-write gate." })
2301
+ confirm: Type35.Boolean({ description: "Must be true to execute. Tier-2 safe-write gate." })
2160
2302
  },
2161
2303
  { additionalProperties: false }
2162
2304
  );
@@ -2165,7 +2307,7 @@ function createProxmoxExecTool(getClient, getSsh, vmDefaults) {
2165
2307
  return {
2166
2308
  name: NAME31,
2167
2309
  label: "proxmox: exec in container or VM",
2168
- description: "Run a shell command inside an LXC container (via SSH+pct exec) or QEMU VM (via direct SSH, IP from guest agent or env override). Returns stdout/stderr/exit_code. Tier-2 write; requires confirm:true.",
2310
+ description: "Run a shell command inside an LXC container (via SSH+pct exec) or QEMU VM (via direct SSH by default, or the qemu-guest-agent API when PROXMOX_EXEC_BACKEND=guest-agent - no in-guest SSH key needed). Returns stdout/stderr/exit_code. Tier-2 write; requires confirm:true.",
2169
2311
  parameters: Schema34,
2170
2312
  execute: async (_id, raw) => {
2171
2313
  assertConfirmedWrite(raw, NAME31);
@@ -2184,12 +2326,7 @@ function createProxmoxExecTool(getClient, getSsh, vmDefaults) {
2184
2326
  exit_code: result2.exitCode
2185
2327
  });
2186
2328
  }
2187
- const host = await resolveQemuSshHost(client, node, args.vmid);
2188
- if (!host) {
2189
- throw new Error(missingQemuSshHostMessage(args.vmid));
2190
- }
2191
- const target = qemuSshTarget(args.vmid, host, vmDefaults);
2192
- const result = await ssh.execViaDirectSsh(target, args.command, timeoutMs);
2329
+ const result = await execInQemuGuest(client, ssh, node, args.vmid, args.command, timeoutMs, vmDefaults);
2193
2330
  return jsonToolResult({
2194
2331
  vmid: args.vmid,
2195
2332
  type,
@@ -2202,20 +2339,20 @@ function createProxmoxExecTool(getClient, getSsh, vmDefaults) {
2202
2339
  }
2203
2340
 
2204
2341
  // src/tools/proxmox_read_file.ts
2205
- import { Type as Type35 } from "@sinclair/typebox";
2206
- var Schema35 = Type35.Object(
2342
+ import { Type as Type36 } from "@sinclair/typebox";
2343
+ var Schema35 = Type36.Object(
2207
2344
  {
2208
- vmid: Type35.Integer({ minimum: 1, description: "Container or VM id." }),
2209
- path: Type35.String({ minLength: 1, description: "Absolute file path inside the resource." }),
2210
- confirm: Type35.Boolean({ description: "Must be true to read files from inside a guest." })
2345
+ vmid: Type36.Integer({ minimum: 1, description: "Container or VM id." }),
2346
+ path: Type36.String({ minLength: 1, description: "Absolute file path inside the resource." }),
2347
+ confirm: Type36.Boolean({ description: "Must be true to read files from inside a guest." })
2211
2348
  },
2212
2349
  { additionalProperties: false }
2213
2350
  );
2214
2351
  var NAME32 = "proxmox_read_file";
2215
- function shellSingleQuote(s) {
2352
+ function shellSingleQuote2(s) {
2216
2353
  return `'${s.replace(/'/g, `'\\''`)}'`;
2217
2354
  }
2218
- function assertAbsoluteGuestPath(path2, toolName) {
2355
+ function assertAbsoluteGuestPath2(path2, toolName) {
2219
2356
  if (!path2.startsWith("/")) throw new Error(`${toolName} path must be absolute`);
2220
2357
  if (path2.includes("\0")) throw new Error(`${toolName} path cannot contain NUL bytes`);
2221
2358
  }
@@ -2228,21 +2365,17 @@ function createProxmoxReadFileTool(getClient, getSsh, vmDefaults) {
2228
2365
  execute: async (_id, raw) => {
2229
2366
  assertConfirmedWrite(raw, NAME32);
2230
2367
  const args = validateToolArgs(Schema35, raw, NAME32);
2231
- assertAbsoluteGuestPath(args.path, NAME32);
2368
+ assertAbsoluteGuestPath2(args.path, NAME32);
2232
2369
  const client = getClient();
2233
2370
  const { node, type } = await resolveResource(client, args.vmid);
2234
- const command = `cat -- ${shellSingleQuote(args.path)}`;
2371
+ const command = `cat -- ${shellSingleQuote2(args.path)}`;
2235
2372
  const ssh = getSsh();
2236
2373
  const timeoutMs = 3e4;
2237
2374
  let result;
2238
2375
  if (type === "lxc") {
2239
2376
  result = await ssh.execInLxc(args.vmid, command, timeoutMs);
2240
2377
  } else {
2241
- const host = await resolveQemuSshHost(client, node, args.vmid);
2242
- if (!host) {
2243
- throw new Error(missingQemuSshHostMessage(args.vmid));
2244
- }
2245
- result = await ssh.execViaDirectSsh(qemuSshTarget(args.vmid, host, vmDefaults), command, timeoutMs);
2378
+ result = await execInQemuGuest(client, ssh, node, args.vmid, command, timeoutMs, vmDefaults);
2246
2379
  }
2247
2380
  if (result.exitCode !== 0) {
2248
2381
  throw new Error(result.stderr.trim() || `read_file failed with exit code ${result.exitCode}`);
@@ -2253,22 +2386,22 @@ function createProxmoxReadFileTool(getClient, getSsh, vmDefaults) {
2253
2386
  }
2254
2387
 
2255
2388
  // src/tools/proxmox_write_file.ts
2256
- import { Type as Type36 } from "@sinclair/typebox";
2389
+ import { Type as Type37 } from "@sinclair/typebox";
2257
2390
  import path from "path";
2258
- var Schema36 = Type36.Object(
2391
+ var Schema36 = Type37.Object(
2259
2392
  {
2260
- vmid: Type36.Integer({ minimum: 1, description: "Container or VM id." }),
2261
- path: Type36.String({ minLength: 1, description: "Absolute destination path inside the resource." }),
2262
- content: Type36.String({ description: "Text content to write." }),
2263
- confirm: Type36.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
2393
+ vmid: Type37.Integer({ minimum: 1, description: "Container or VM id." }),
2394
+ path: Type37.String({ minLength: 1, description: "Absolute destination path inside the resource." }),
2395
+ content: Type37.String({ description: "Text content to write." }),
2396
+ confirm: Type37.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
2264
2397
  },
2265
2398
  { additionalProperties: false }
2266
2399
  );
2267
2400
  var NAME33 = "proxmox_write_file";
2268
- function shellSingleQuote2(s) {
2401
+ function shellSingleQuote3(s) {
2269
2402
  return `'${s.replace(/'/g, `'\\''`)}'`;
2270
2403
  }
2271
- function assertAbsoluteGuestPath2(path2, toolName) {
2404
+ function assertAbsoluteGuestPath3(path2, toolName) {
2272
2405
  if (!path2.startsWith("/")) throw new Error(`${toolName} path must be absolute`);
2273
2406
  if (path2.includes("\0")) throw new Error(`${toolName} path cannot contain NUL bytes`);
2274
2407
  }
@@ -2281,23 +2414,19 @@ function createProxmoxWriteFileTool(getClient, getSsh, vmDefaults) {
2281
2414
  execute: async (_id, raw) => {
2282
2415
  assertConfirmedWrite(raw, NAME33);
2283
2416
  const args = validateToolArgs(Schema36, raw, NAME33);
2284
- assertAbsoluteGuestPath2(args.path, NAME33);
2417
+ assertAbsoluteGuestPath3(args.path, NAME33);
2285
2418
  const client = getClient();
2286
2419
  const { node, type } = await resolveResource(client, args.vmid);
2287
2420
  const ssh = getSsh();
2288
2421
  const timeoutMs = 3e4;
2289
2422
  const parent = path.posix.dirname(args.path);
2290
- const mkdirCmd = `mkdir -p -- ${shellSingleQuote2(parent)}`;
2291
- const writeCmd = `cat > ${shellSingleQuote2(args.path)}`;
2423
+ const mkdirCmd = `mkdir -p -- ${shellSingleQuote3(parent)}`;
2424
+ const writeCmd = `cat > ${shellSingleQuote3(args.path)}`;
2292
2425
  const runOne = async (command, stdin) => {
2293
2426
  if (type === "lxc") {
2294
2427
  return ssh.execInLxc(args.vmid, command, timeoutMs, stdin);
2295
2428
  }
2296
- const host = await resolveQemuSshHost(client, node, args.vmid);
2297
- if (!host) {
2298
- throw new Error(missingQemuSshHostMessage(args.vmid));
2299
- }
2300
- return ssh.execViaDirectSsh(qemuSshTarget(args.vmid, host, vmDefaults), command, timeoutMs, stdin);
2429
+ return execInQemuGuest(client, ssh, node, args.vmid, command, timeoutMs, vmDefaults, stdin);
2301
2430
  };
2302
2431
  const mkdirResult = await runOne(mkdirCmd);
2303
2432
  if (mkdirResult.exitCode !== 0) {
@@ -2317,33 +2446,12 @@ function createProxmoxWriteFileTool(getClient, getSsh, vmDefaults) {
2317
2446
  }
2318
2447
 
2319
2448
  // src/tools/proxmox_stat_path.ts
2320
- import { Type as Type37 } from "@sinclair/typebox";
2321
-
2322
- // src/tools/guest-command.ts
2323
- function shellSingleQuote3(s) {
2324
- return `'${s.replace(/'/g, `'\\''`)}'`;
2325
- }
2326
- function assertAbsoluteGuestPath3(path2, toolName) {
2327
- if (!path2.startsWith("/")) throw new Error(`${toolName} path must be absolute`);
2328
- if (path2.includes("\0")) throw new Error(`${toolName} path cannot contain NUL bytes`);
2329
- }
2330
- async function runGuestCommand(client, ssh, vmDefaults, vmid, command, timeoutMs, stdin) {
2331
- const { node, type } = await resolveResource(client, vmid);
2332
- if (type === "lxc") {
2333
- return { node, type, result: await ssh.execInLxc(vmid, command, timeoutMs, stdin) };
2334
- }
2335
- const host = await resolveQemuSshHost(client, node, vmid);
2336
- if (!host) throw new Error(missingQemuSshHostMessage(vmid));
2337
- const target = qemuSshTarget(vmid, host, vmDefaults);
2338
- return { node, type, result: await ssh.execViaDirectSsh(target, command, timeoutMs, stdin) };
2339
- }
2340
-
2341
- // src/tools/proxmox_stat_path.ts
2342
- var Schema37 = Type37.Object(
2449
+ import { Type as Type38 } from "@sinclair/typebox";
2450
+ var Schema37 = Type38.Object(
2343
2451
  {
2344
- vmid: Type37.Integer({ minimum: 1, description: "Container or VM id." }),
2345
- path: Type37.String({ minLength: 1, description: "Absolute path inside the guest." }),
2346
- confirm: Type37.Boolean({ description: "Must be true to inspect guest filesystem metadata." })
2452
+ vmid: Type38.Integer({ minimum: 1, description: "Container or VM id." }),
2453
+ path: Type38.String({ minLength: 1, description: "Absolute path inside the guest." }),
2454
+ confirm: Type38.Boolean({ description: "Must be true to inspect guest filesystem metadata." })
2347
2455
  },
2348
2456
  { additionalProperties: false }
2349
2457
  );
@@ -2374,8 +2482,8 @@ function createProxmoxStatPathTool(getClient, getSsh, vmDefaults) {
2374
2482
  execute: async (_id, raw) => {
2375
2483
  assertConfirmedWrite(raw, NAME34);
2376
2484
  const args = validateToolArgs(Schema37, raw, NAME34);
2377
- assertAbsoluteGuestPath3(args.path, NAME34);
2378
- const command = `stat -Lc '%F\\0%s\\0%U\\0%G\\0%a\\0%Y\\0%n\\0' -- ${shellSingleQuote3(args.path)}`;
2485
+ assertAbsoluteGuestPath(args.path, NAME34);
2486
+ const command = `stat -Lc '%F\\0%s\\0%U\\0%G\\0%a\\0%Y\\0%n\\0' -- ${shellSingleQuote(args.path)}`;
2379
2487
  const { node, type, result } = await runGuestCommand(
2380
2488
  getClient(),
2381
2489
  getSsh(),
@@ -2398,12 +2506,12 @@ function createProxmoxStatPathTool(getClient, getSsh, vmDefaults) {
2398
2506
  }
2399
2507
 
2400
2508
  // src/tools/proxmox_list_directory.ts
2401
- import { Type as Type38 } from "@sinclair/typebox";
2402
- var Schema38 = Type38.Object(
2509
+ import { Type as Type39 } from "@sinclair/typebox";
2510
+ var Schema38 = Type39.Object(
2403
2511
  {
2404
- vmid: Type38.Integer({ minimum: 1, description: "Container or VM id." }),
2405
- path: Type38.String({ minLength: 1, description: "Absolute directory path inside the guest." }),
2406
- confirm: Type38.Boolean({ description: "Must be true to inspect guest directory contents." })
2512
+ vmid: Type39.Integer({ minimum: 1, description: "Container or VM id." }),
2513
+ path: Type39.String({ minLength: 1, description: "Absolute directory path inside the guest." }),
2514
+ confirm: Type39.Boolean({ description: "Must be true to inspect guest directory contents." })
2407
2515
  },
2408
2516
  { additionalProperties: false }
2409
2517
  );
@@ -2436,8 +2544,8 @@ function createProxmoxListDirectoryTool(getClient, getSsh, vmDefaults) {
2436
2544
  execute: async (_id, raw) => {
2437
2545
  assertConfirmedWrite(raw, NAME35);
2438
2546
  const args = validateToolArgs(Schema38, raw, NAME35);
2439
- assertAbsoluteGuestPath3(args.path, NAME35);
2440
- const command = `find ${shellSingleQuote3(args.path)} -mindepth 1 -maxdepth 1 -printf '%f\\0%y\\0%s\\0%T@\\0'`;
2547
+ assertAbsoluteGuestPath(args.path, NAME35);
2548
+ const command = `find ${shellSingleQuote(args.path)} -mindepth 1 -maxdepth 1 -printf '%f\\0%y\\0%s\\0%T@\\0'`;
2441
2549
  const { node, type, result } = await runGuestCommand(
2442
2550
  getClient(),
2443
2551
  getSsh(),
@@ -2456,12 +2564,12 @@ function createProxmoxListDirectoryTool(getClient, getSsh, vmDefaults) {
2456
2564
  }
2457
2565
 
2458
2566
  // src/tools/proxmox_service_status.ts
2459
- import { Type as Type39 } from "@sinclair/typebox";
2460
- var Schema39 = Type39.Object(
2567
+ import { Type as Type40 } from "@sinclair/typebox";
2568
+ var Schema39 = Type40.Object(
2461
2569
  {
2462
- vmid: Type39.Integer({ minimum: 1, description: "Container or VM id." }),
2463
- service: Type39.String({ minLength: 1, description: "systemd service name inside the guest." }),
2464
- confirm: Type39.Boolean({ description: "Must be true to inspect guest service state." })
2570
+ vmid: Type40.Integer({ minimum: 1, description: "Container or VM id." }),
2571
+ service: Type40.String({ minLength: 1, description: "systemd service name inside the guest." }),
2572
+ confirm: Type40.Boolean({ description: "Must be true to inspect guest service state." })
2465
2573
  },
2466
2574
  { additionalProperties: false }
2467
2575
  );
@@ -2485,7 +2593,7 @@ function createProxmoxServiceStatusTool(getClient, getSsh, vmDefaults) {
2485
2593
  assertConfirmedWrite(raw, NAME36);
2486
2594
  const args = validateToolArgs(Schema39, raw, NAME36);
2487
2595
  if (args.service.includes("\0")) throw new Error(`${NAME36} service cannot contain NUL bytes`);
2488
- const command = `systemctl show --no-pager --property=Id,LoadState,ActiveState,SubState,UnitFileState,Description -- ${shellSingleQuote3(args.service)}`;
2596
+ const command = `systemctl show --no-pager --property=Id,LoadState,ActiveState,SubState,UnitFileState,Description -- ${shellSingleQuote(args.service)}`;
2489
2597
  const { node, type, result } = await runGuestCommand(
2490
2598
  getClient(),
2491
2599
  getSsh(),
@@ -2504,7 +2612,7 @@ function createProxmoxServiceStatusTool(getClient, getSsh, vmDefaults) {
2504
2612
  }
2505
2613
 
2506
2614
  // src/tools/service-action.ts
2507
- import { Type as Type40 } from "@sinclair/typebox";
2615
+ import { Type as Type41 } from "@sinclair/typebox";
2508
2616
  function parseSystemctlShow2(stdout) {
2509
2617
  const out = {};
2510
2618
  for (const line of stdout.trimEnd().split("\n")) {
@@ -2515,11 +2623,11 @@ function parseSystemctlShow2(stdout) {
2515
2623
  return out;
2516
2624
  }
2517
2625
  function schemaFor(action) {
2518
- return Type40.Object(
2626
+ return Type41.Object(
2519
2627
  {
2520
- vmid: Type40.Integer({ minimum: 1, description: "Container or VM id." }),
2521
- service: Type40.String({ minLength: 1, description: `systemd service name to ${action} inside the guest.` }),
2522
- confirm: Type40.Boolean({ description: `Must be true to ${action} a guest service.` })
2628
+ vmid: Type41.Integer({ minimum: 1, description: "Container or VM id." }),
2629
+ service: Type41.String({ minLength: 1, description: `systemd service name to ${action} inside the guest.` }),
2630
+ confirm: Type41.Boolean({ description: `Must be true to ${action} a guest service.` })
2523
2631
  },
2524
2632
  { additionalProperties: false }
2525
2633
  );
@@ -2536,7 +2644,7 @@ function createServiceActionTool(action, getClient, getSsh, vmDefaults) {
2536
2644
  assertConfirmedWrite(raw, name);
2537
2645
  const args = validateToolArgs(schema, raw, name);
2538
2646
  if (args.service.includes("\0")) throw new Error(`${name} service cannot contain NUL bytes`);
2539
- const quoted = shellSingleQuote3(args.service);
2647
+ const quoted = shellSingleQuote(args.service);
2540
2648
  const command = `systemctl ${action} -- ${quoted} && systemctl show --no-pager --property=Id,LoadState,ActiveState,SubState,UnitFileState,Description -- ${quoted}`;
2541
2649
  const { node, type, result } = await runGuestCommand(
2542
2650
  getClient(),
@@ -2576,42 +2684,2350 @@ function createProxmoxServiceRestartTool(getClient, getSsh, vmDefaults) {
2576
2684
  return createServiceActionTool("restart", getClient, getSsh, vmDefaults);
2577
2685
  }
2578
2686
 
2579
- // src/errors.ts
2580
- function classifyToolError(error) {
2581
- const err = error instanceof Error ? error : new Error(String(error));
2582
- if (err instanceof ToolInputError) {
2583
- return { error: err.message, code: "TOOL_INPUT_INVALID", name: err.name };
2584
- }
2585
- if (err instanceof WriteGateError) {
2586
- const code = err.message.includes("requires env flag") ? "DESTRUCTIVE_ENV_REQUIRED" : err.message.includes("destructive operation") ? "DESTRUCTIVE_CONFIRMATION_REQUIRED" : "WRITE_CONFIRMATION_REQUIRED";
2587
- return { error: err.message, code, name: err.name };
2588
- }
2589
- if (err instanceof ProxmoxClientError) {
2590
- return { error: err.message, code: `PROXMOX_HTTP_${err.status}`, name: err.name, status: err.status };
2591
- }
2592
- if (err instanceof ProxmoxUnreachableError) {
2593
- return { error: err.message, code: "PROXMOX_UNREACHABLE", name: err.name };
2687
+ // src/tools/proxmox_update_vm_config.ts
2688
+ import { Type as Type43 } from "@sinclair/typebox";
2689
+
2690
+ // src/tools/resource-config.ts
2691
+ import { Type as Type42 } from "@sinclair/typebox";
2692
+ var CONFIG_KEY_RE = /^[a-zA-Z][a-zA-Z0-9_]*$/;
2693
+ var configEditFields = {
2694
+ cores: Type42.Optional(Type42.Integer({ minimum: 1, description: "CPU cores." })),
2695
+ memory: Type42.Optional(Type42.Integer({ minimum: 16, description: "RAM in MiB." })),
2696
+ description: Type42.Optional(Type42.String({ description: "Free-form description / notes." })),
2697
+ onboot: Type42.Optional(Type42.Boolean({ description: "Start on host boot." })),
2698
+ tags: Type42.Optional(Type42.String({ description: "Semicolon-delimited Proxmox tags." })),
2699
+ cpulimit: Type42.Optional(Type42.Number({ minimum: 0, description: "CPU limit (0 = unlimited)." })),
2700
+ cpuunits: Type42.Optional(Type42.Integer({ minimum: 1, description: "CPU weight / shares." })),
2701
+ protection: Type42.Optional(
2702
+ Type42.Boolean({ description: "Protection flag (blocks destroy/disk-remove)." })
2703
+ ),
2704
+ set: Type42.Optional(
2705
+ Type42.Record(Type42.String(), Type42.Union([Type42.String(), Type42.Number(), Type42.Boolean()]), {
2706
+ description: 'Arbitrary PVE config keys to set, e.g. {"net0":"virtio,bridge=vmbr0","bios":"ovmf"}. Escape hatch for keys not exposed as typed fields.'
2707
+ })
2708
+ ),
2709
+ unset: Type42.Optional(
2710
+ Type42.Array(Type42.String(), {
2711
+ description: 'Config keys to unset/revert to default, e.g. ["tags","description"].'
2712
+ })
2713
+ ),
2714
+ digest: Type42.Optional(
2715
+ Type42.String({
2716
+ description: "SHA1 config digest for optimistic concurrency; edit is rejected if config changed."
2717
+ })
2718
+ )
2719
+ };
2720
+ function normalize(v) {
2721
+ if (typeof v === "boolean") return v ? 1 : 0;
2722
+ if (typeof v === "number") return v;
2723
+ return String(v);
2724
+ }
2725
+ function buildConfigBody(args, extraTyped, toolName) {
2726
+ const body = {};
2727
+ const typed = {
2728
+ cores: args.cores,
2729
+ memory: args.memory,
2730
+ description: args.description,
2731
+ onboot: args.onboot,
2732
+ tags: args.tags,
2733
+ cpulimit: args.cpulimit,
2734
+ cpuunits: args.cpuunits,
2735
+ protection: args.protection,
2736
+ ...extraTyped
2737
+ };
2738
+ for (const [k, v] of Object.entries(typed)) {
2739
+ if (v !== void 0) body[k] = normalize(v);
2594
2740
  }
2595
- if (err instanceof SshExecError) {
2596
- return { error: err.message, code: `SSH_${err.phase.toUpperCase()}_FAILED`, name: err.name };
2741
+ if (args.set) {
2742
+ for (const [k, v] of Object.entries(args.set)) {
2743
+ if (!CONFIG_KEY_RE.test(k)) {
2744
+ throw new ToolInputError(`${toolName}: invalid config key "${k}" in set`);
2745
+ }
2746
+ body[k] = normalize(v);
2747
+ }
2597
2748
  }
2598
- if (/vmid \d+ not found in cluster resources/.test(err.message)) {
2599
- return { error: err.message, code: "VMID_NOT_FOUND", name: err.name };
2749
+ const unset = (args.unset ?? []).filter((k) => k.length > 0);
2750
+ for (const k of unset) {
2751
+ if (!CONFIG_KEY_RE.test(k)) {
2752
+ throw new ToolInputError(`${toolName}: invalid config key "${k}" in unset`);
2753
+ }
2600
2754
  }
2601
- if (/invalid UPID format/.test(err.message)) {
2602
- return { error: err.message, code: "TASK_UPID_INVALID", name: err.name };
2755
+ if (unset.length > 0) body.delete = unset.join(",");
2756
+ if (args.digest) body.digest = args.digest;
2757
+ const mutations = Object.keys(body).filter((k) => k !== "digest");
2758
+ if (mutations.length === 0) {
2759
+ throw new ToolInputError(
2760
+ `${toolName}: no config changes supplied. Provide at least one field, a "set" entry, or an "unset" key.`
2761
+ );
2603
2762
  }
2604
- if (/task did not finish OK/i.test(err.message) || /task failed/i.test(err.message)) {
2605
- return { error: err.message, code: "TASK_FAILED", name: err.name };
2763
+ return body;
2764
+ }
2765
+
2766
+ // src/tools/proxmox_update_vm_config.ts
2767
+ var Schema40 = Type43.Object(
2768
+ {
2769
+ vmid: Type43.Integer({ minimum: 1, description: "QEMU VM ID to reconfigure." }),
2770
+ name: Type43.Optional(Type43.String({ minLength: 1, description: "VM name." })),
2771
+ sockets: Type43.Optional(Type43.Integer({ minimum: 1, description: "CPU sockets." })),
2772
+ balloon: Type43.Optional(
2773
+ Type43.Integer({ minimum: 0, description: "Ballooning target in MiB (0 disables)." })
2774
+ ),
2775
+ ...configEditFields,
2776
+ confirm: Type43.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
2777
+ },
2778
+ { additionalProperties: false }
2779
+ );
2780
+ var NAME37 = "proxmox_update_vm_config";
2781
+ function createProxmoxUpdateVmConfigTool(getClient) {
2782
+ return {
2783
+ name: NAME37,
2784
+ label: "proxmox: update VM config",
2785
+ description: "Edit an existing QEMU VM's config (PUT /nodes/{node}/qemu/{vmid}/config): cores, memory, sockets, balloon, name, description, onboot, tags, plus arbitrary keys via `set` and key removal via `unset`. Some changes (CPU/mem/disk on a running VM) apply as pending until reboot. Tier-2 write; requires confirm:true.",
2786
+ parameters: Schema40,
2787
+ execute: async (_id, raw) => {
2788
+ assertConfirmedWrite(raw, NAME37);
2789
+ const args = validateToolArgs(Schema40, raw, NAME37);
2790
+ const client = getClient();
2791
+ const { node, type } = await resolveResource(client, args.vmid);
2792
+ if (type !== "qemu") {
2793
+ throw new Error(`vmid ${args.vmid} is an LXC container, not a QEMU VM. Use proxmox_update_container_config.`);
2794
+ }
2795
+ const body = buildConfigBody(args, { name: args.name, sockets: args.sockets, balloon: args.balloon }, NAME37);
2796
+ const upid = await client.put(`/nodes/${node}/qemu/${args.vmid}/config`, body);
2797
+ const changed = Object.keys(body).filter((k) => k !== "digest" && k !== "delete");
2798
+ const removed = typeof body.delete === "string" ? body.delete.split(",") : [];
2799
+ return jsonToolResult({ vmid: args.vmid, node, type, changed, removed, upid: upid ?? null });
2800
+ }
2801
+ };
2802
+ }
2803
+
2804
+ // src/tools/proxmox_update_container_config.ts
2805
+ import { Type as Type44 } from "@sinclair/typebox";
2806
+ var Schema41 = Type44.Object(
2807
+ {
2808
+ vmid: Type44.Integer({ minimum: 1, description: "LXC container ID to reconfigure." }),
2809
+ hostname: Type44.Optional(Type44.String({ minLength: 1, description: "Container hostname." })),
2810
+ swap: Type44.Optional(Type44.Integer({ minimum: 0, description: "Swap in MiB." })),
2811
+ nameserver: Type44.Optional(Type44.String({ minLength: 1, description: "DNS server IP(s), space-separated." })),
2812
+ ...configEditFields,
2813
+ confirm: Type44.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
2814
+ },
2815
+ { additionalProperties: false }
2816
+ );
2817
+ var NAME38 = "proxmox_update_container_config";
2818
+ function createProxmoxUpdateContainerConfigTool(getClient) {
2819
+ return {
2820
+ name: NAME38,
2821
+ label: "proxmox: update container config",
2822
+ description: "Edit an existing LXC container's config (PUT /nodes/{node}/lxc/{vmid}/config): cores, memory, swap, hostname, nameserver, description, onboot, tags, plus arbitrary keys via `set` and key removal via `unset`. Tier-2 write; requires confirm:true.",
2823
+ parameters: Schema41,
2824
+ execute: async (_id, raw) => {
2825
+ assertConfirmedWrite(raw, NAME38);
2826
+ const args = validateToolArgs(Schema41, raw, NAME38);
2827
+ const client = getClient();
2828
+ const { node, type } = await resolveResource(client, args.vmid);
2829
+ if (type !== "lxc") {
2830
+ throw new Error(`vmid ${args.vmid} is a QEMU VM, not an LXC container. Use proxmox_update_vm_config.`);
2831
+ }
2832
+ const body = buildConfigBody(
2833
+ args,
2834
+ { hostname: args.hostname, swap: args.swap, nameserver: args.nameserver },
2835
+ NAME38
2836
+ );
2837
+ const upid = await client.put(`/nodes/${node}/lxc/${args.vmid}/config`, body);
2838
+ const changed = Object.keys(body).filter((k) => k !== "digest" && k !== "delete");
2839
+ const removed = typeof body.delete === "string" ? body.delete.split(",") : [];
2840
+ return jsonToolResult({ vmid: args.vmid, node, type, changed, removed, upid: upid ?? null });
2841
+ }
2842
+ };
2843
+ }
2844
+
2845
+ // src/tools/proxmox_resize_disk.ts
2846
+ import { Type as Type45 } from "@sinclair/typebox";
2847
+ var DISK_KEY_RE = /^[a-zA-Z][a-zA-Z0-9_]*$/;
2848
+ var SIZE_RE = /^\+?\d+(\.\d+)?[KMGT]?$/;
2849
+ var Schema42 = Type45.Object(
2850
+ {
2851
+ vmid: Type45.Integer({ minimum: 1, description: "Container or VM ID." }),
2852
+ disk: Type45.String({
2853
+ minLength: 1,
2854
+ description: "Disk key to resize, e.g. 'scsi0', 'virtio0', 'rootfs', 'mp0'."
2855
+ }),
2856
+ size: Type45.String({
2857
+ minLength: 1,
2858
+ description: "New size ('32G') or growth increment ('+2G'). PVE grows only; shrink is refused."
2859
+ }),
2860
+ confirm: Type45.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." }),
2861
+ ...taskWaitFields
2862
+ },
2863
+ { additionalProperties: false }
2864
+ );
2865
+ var NAME39 = "proxmox_resize_disk";
2866
+ function createProxmoxResizeDiskTool(getClient) {
2867
+ return {
2868
+ name: NAME39,
2869
+ label: "proxmox: resize disk",
2870
+ description: "Grow a VM or container disk (PUT /nodes/{node}/{type}/{vmid}/resize) with {disk,size}. Size is absolute ('32G') or an increment ('+2G'); Proxmox only grows disks. Tier-2 write; requires confirm:true.",
2871
+ parameters: Schema42,
2872
+ execute: async (_id, raw) => {
2873
+ assertConfirmedWrite(raw, NAME39);
2874
+ const args = validateToolArgs(
2875
+ Schema42,
2876
+ raw,
2877
+ NAME39
2878
+ );
2879
+ if (!DISK_KEY_RE.test(args.disk)) {
2880
+ throw new ToolInputError(`${NAME39}: invalid disk key "${args.disk}"`);
2881
+ }
2882
+ if (!SIZE_RE.test(args.size)) {
2883
+ throw new ToolInputError(
2884
+ `${NAME39}: invalid size "${args.size}". Use '32G' (absolute) or '+2G' (growth).`
2885
+ );
2886
+ }
2887
+ const client = getClient();
2888
+ const { node, type } = await resolveResource(client, args.vmid);
2889
+ const upid = await client.put(`/nodes/${node}/${type}/${args.vmid}/resize`, {
2890
+ disk: args.disk,
2891
+ size: args.size
2892
+ });
2893
+ const task = await resolveTaskWait(client, upid, args);
2894
+ return jsonToolResult({ vmid: args.vmid, node, type, disk: args.disk, size: args.size, upid: upid ?? null, ...task ? { task } : {} });
2895
+ }
2896
+ };
2897
+ }
2898
+
2899
+ // src/tools/proxmox_restore_backup.ts
2900
+ import { Type as Type46 } from "@sinclair/typebox";
2901
+ var Schema43 = Type46.Object(
2902
+ {
2903
+ vmid: Type46.Integer({ minimum: 1, description: "Target VMID to restore into." }),
2904
+ archive: Type46.String({
2905
+ minLength: 1,
2906
+ description: "Backup archive volid or path, e.g. 'local:backup/vzdump-lxc-115-2026_01_01-00_00_00.tar.zst' or a PBS volid."
2907
+ }),
2908
+ type: Type46.Optional(
2909
+ Type46.Union([Type46.Literal("lxc"), Type46.Literal("qemu")], {
2910
+ description: "Guest type. Inferred from the archive name when omitted."
2911
+ })
2912
+ ),
2913
+ node: Type46.Optional(
2914
+ Type46.String({ minLength: 1, description: "Node to restore on (defaults to first node for a new vmid)." })
2915
+ ),
2916
+ storage: Type46.Optional(
2917
+ Type46.String({ minLength: 1, description: "Target storage for restored disks (defaults to the archive's)." })
2918
+ ),
2919
+ pool: Type46.Optional(Type46.String({ minLength: 1, description: "Resource pool to place the guest into." })),
2920
+ unique: Type46.Optional(
2921
+ Type46.Boolean({ description: "QEMU: regenerate MAC addresses / UUID on restore." })
2922
+ ),
2923
+ force: Type46.Optional(
2924
+ Type46.Boolean({
2925
+ description: "Overwrite an EXISTING vmid (wipes its disks). Requires the destructive gate."
2926
+ })
2927
+ ),
2928
+ confirm: Type46.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." }),
2929
+ destructive: Type46.Optional(
2930
+ Type46.Boolean({ description: "Required only when overwriting an existing vmid (force)." })
2931
+ ),
2932
+ ...taskWaitFields
2933
+ },
2934
+ { additionalProperties: false }
2935
+ );
2936
+ var NAME40 = "proxmox_restore_backup";
2937
+ function inferType(archive) {
2938
+ const a = archive.toLowerCase();
2939
+ if (a.includes("qemu") || a.includes("/vm/")) return "qemu";
2940
+ if (a.includes("lxc") || a.includes("/ct/")) return "lxc";
2941
+ return null;
2942
+ }
2943
+ function createProxmoxRestoreBackupTool(getClient) {
2944
+ return {
2945
+ name: NAME40,
2946
+ label: "proxmox: restore backup",
2947
+ description: "Restore a vzdump/PBS backup into a VMID (POST /nodes/{node}/{type}/{vmid} with restore=1). Restoring to a new VMID is Tier-2 (confirm:true). Overwriting an EXISTING VMID wipes its disks and additionally requires force:true, destructive:true, and env PROXMOX_ENABLE_DESTRUCTIVE=1.",
2948
+ parameters: Schema43,
2949
+ execute: async (_id, raw) => {
2950
+ assertConfirmedWrite(raw, NAME40);
2951
+ const args = validateToolArgs(Schema43, raw, NAME40);
2952
+ if (/[\r\n]/.test(args.archive)) {
2953
+ throw new ToolInputError(`${NAME40}: archive must not contain newlines`);
2954
+ }
2955
+ const type = args.type ?? inferType(args.archive);
2956
+ if (!type) {
2957
+ throw new ToolInputError(
2958
+ `${NAME40}: could not infer guest type from archive "${args.archive}". Pass type:"lxc" or "qemu".`
2959
+ );
2960
+ }
2961
+ const client = getClient();
2962
+ const resources = await client.get("/cluster/resources");
2963
+ const existing = resources.find(
2964
+ (r) => r.vmid === args.vmid && (r.type === "lxc" || r.type === "qemu")
2965
+ );
2966
+ let node;
2967
+ if (existing) {
2968
+ if (args.force !== true) {
2969
+ throw new ToolInputError(
2970
+ `${NAME40}: vmid ${args.vmid} already exists on ${existing.node}. To overwrite it, pass force:true (also requires destructive:true + PROXMOX_ENABLE_DESTRUCTIVE=1).`
2971
+ );
2972
+ }
2973
+ assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME40);
2974
+ assertDestructive(raw, NAME40);
2975
+ if (existing.type !== type) {
2976
+ throw new Error(
2977
+ `vmid ${args.vmid} exists as ${existing.type} but archive is ${type}. Refusing cross-type overwrite.`
2978
+ );
2979
+ }
2980
+ node = existing.node;
2981
+ } else {
2982
+ if (args.node) {
2983
+ assertSafePathSegment(args.node, "node");
2984
+ node = args.node;
2985
+ } else {
2986
+ const nodes = resources.filter((r) => r.type === "node");
2987
+ if (nodes.length === 0) throw new Error("no nodes found in cluster resources");
2988
+ node = nodes[0].node;
2989
+ }
2990
+ }
2991
+ const body = {
2992
+ vmid: args.vmid,
2993
+ restore: 1
2994
+ };
2995
+ if (type === "qemu") body.archive = args.archive;
2996
+ else body.ostemplate = args.archive;
2997
+ if (existing && args.force === true) body.force = 1;
2998
+ if (args.storage) body.storage = args.storage;
2999
+ if (args.pool) body.pool = args.pool;
3000
+ if (args.unique === true && type === "qemu") body.unique = 1;
3001
+ const upid = await client.post(`/nodes/${node}/${type}`, body);
3002
+ const task = await resolveTaskWait(client, upid, args);
3003
+ return jsonToolResult({
3004
+ vmid: args.vmid,
3005
+ node,
3006
+ type,
3007
+ archive: args.archive,
3008
+ overwrite: Boolean(existing),
3009
+ upid,
3010
+ ...task ? { task } : {}
3011
+ });
3012
+ }
3013
+ };
3014
+ }
3015
+
3016
+ // src/tools/proxmox_migrate_resource.ts
3017
+ import { Type as Type47 } from "@sinclair/typebox";
3018
+ var Schema44 = Type47.Object(
3019
+ {
3020
+ vmid: Type47.Integer({ minimum: 1, description: "Container or VM ID to migrate." }),
3021
+ target: Type47.String({ minLength: 1, description: "Target node name to migrate to." }),
3022
+ online: Type47.Optional(
3023
+ Type47.Boolean({ description: "QEMU: live-migrate a running VM (no downtime)." })
3024
+ ),
3025
+ restart: Type47.Optional(
3026
+ Type47.Boolean({ description: "LXC: restart-migrate a running container (brief downtime)." })
3027
+ ),
3028
+ with_local_disks: Type47.Optional(
3029
+ Type47.Boolean({ description: "QEMU: also migrate local (non-shared) disks." })
3030
+ ),
3031
+ targetstorage: Type47.Optional(
3032
+ Type47.String({ minLength: 1, description: "Map disks onto this storage on the target node." })
3033
+ ),
3034
+ bwlimit: Type47.Optional(
3035
+ Type47.Integer({ minimum: 0, description: "Bandwidth limit in KiB/s (0 = unlimited)." })
3036
+ ),
3037
+ confirm: Type47.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." }),
3038
+ ...taskWaitFields
3039
+ },
3040
+ { additionalProperties: false }
3041
+ );
3042
+ var NAME41 = "proxmox_migrate_resource";
3043
+ function createProxmoxMigrateResourceTool(getClient) {
3044
+ return {
3045
+ name: NAME41,
3046
+ label: "proxmox: migrate resource",
3047
+ description: "Migrate a VM or container to another node (POST /nodes/{node}/{type}/{vmid}/migrate). QEMU supports online (live) migration; LXC uses restart mode. Tier-2 write; requires confirm:true.",
3048
+ parameters: Schema44,
3049
+ execute: async (_id, raw) => {
3050
+ assertConfirmedWrite(raw, NAME41);
3051
+ const args = validateToolArgs(Schema44, raw, NAME41);
3052
+ assertSafePathSegment(args.target, "target node");
3053
+ const client = getClient();
3054
+ const { node, type } = await resolveResource(client, args.vmid);
3055
+ if (args.target === node) {
3056
+ throw new Error(`vmid ${args.vmid} is already on node ${node}; nothing to migrate.`);
3057
+ }
3058
+ const body = { target: args.target };
3059
+ if (type === "qemu") {
3060
+ if (args.online) body.online = 1;
3061
+ if (args.with_local_disks) body["with-local-disks"] = 1;
3062
+ } else {
3063
+ if (args.restart || args.online) body.restart = 1;
3064
+ }
3065
+ if (args.targetstorage) body.targetstorage = args.targetstorage;
3066
+ if (typeof args.bwlimit === "number") body.bwlimit = args.bwlimit;
3067
+ const upid = await client.post(`/nodes/${node}/${type}/${args.vmid}/migrate`, body);
3068
+ const task = await resolveTaskWait(client, upid, args);
3069
+ return jsonToolResult({ vmid: args.vmid, node, type, target: args.target, upid, ...task ? { task } : {} });
3070
+ }
3071
+ };
3072
+ }
3073
+
3074
+ // src/tools/proxmox_suspend_resource.ts
3075
+ import { Type as Type48 } from "@sinclair/typebox";
3076
+ var Schema45 = Type48.Object(
3077
+ {
3078
+ vmid: Type48.Integer({ minimum: 1, description: "Container or VM ID." }),
3079
+ todisk: Type48.Optional(
3080
+ Type48.Boolean({ description: "QEMU: suspend to disk (hibernate) instead of to RAM." })
3081
+ ),
3082
+ confirm: Type48.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3083
+ },
3084
+ { additionalProperties: false }
3085
+ );
3086
+ var NAME42 = "proxmox_suspend_resource";
3087
+ function createProxmoxSuspendResourceTool(getClient) {
3088
+ return {
3089
+ name: NAME42,
3090
+ label: "proxmox: suspend resource",
3091
+ description: "Suspend (pause) a running LXC or QEMU guest (POST /nodes/{node}/{type}/{vmid}/status/suspend). QEMU can suspend to disk with todisk:true. Tier-2 write; requires confirm:true.",
3092
+ parameters: Schema45,
3093
+ execute: async (_id, raw) => {
3094
+ assertConfirmedWrite(raw, NAME42);
3095
+ const args = validateToolArgs(Schema45, raw, NAME42);
3096
+ const client = getClient();
3097
+ const { node, type } = await resolveResource(client, args.vmid);
3098
+ const body = {};
3099
+ if (args.todisk && type === "qemu") body.todisk = 1;
3100
+ const upid = await client.post(`/nodes/${node}/${type}/${args.vmid}/status/suspend`, body);
3101
+ return jsonToolResult({ vmid: args.vmid, node, type, upid });
3102
+ }
3103
+ };
3104
+ }
3105
+
3106
+ // src/tools/proxmox_resume_resource.ts
3107
+ import { Type as Type49 } from "@sinclair/typebox";
3108
+ var Schema46 = Type49.Object(
3109
+ {
3110
+ vmid: Type49.Integer({ minimum: 1, description: "Container or VM ID." }),
3111
+ confirm: Type49.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3112
+ },
3113
+ { additionalProperties: false }
3114
+ );
3115
+ var NAME43 = "proxmox_resume_resource";
3116
+ function createProxmoxResumeResourceTool(getClient) {
3117
+ return {
3118
+ name: NAME43,
3119
+ label: "proxmox: resume resource",
3120
+ description: "Resume a suspended LXC or QEMU guest (POST /nodes/{node}/{type}/{vmid}/status/resume). Tier-2 write; requires confirm:true.",
3121
+ parameters: Schema46,
3122
+ execute: async (_id, raw) => {
3123
+ assertConfirmedWrite(raw, NAME43);
3124
+ const args = validateToolArgs(Schema46, raw, NAME43);
3125
+ const client = getClient();
3126
+ const { node, type } = await resolveResource(client, args.vmid);
3127
+ const upid = await client.post(`/nodes/${node}/${type}/${args.vmid}/status/resume`, {});
3128
+ return jsonToolResult({ vmid: args.vmid, node, type, upid });
3129
+ }
3130
+ };
3131
+ }
3132
+
3133
+ // src/tools/proxmox_reset_resource.ts
3134
+ import { Type as Type50 } from "@sinclair/typebox";
3135
+ var Schema47 = Type50.Object(
3136
+ {
3137
+ vmid: Type50.Integer({ minimum: 1, description: "QEMU VM ID." }),
3138
+ confirm: Type50.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3139
+ },
3140
+ { additionalProperties: false }
3141
+ );
3142
+ var NAME44 = "proxmox_reset_resource";
3143
+ function createProxmoxResetResourceTool(getClient) {
3144
+ return {
3145
+ name: NAME44,
3146
+ label: "proxmox: reset resource",
3147
+ description: "Hard-reset a running QEMU VM (POST /nodes/{node}/qemu/{vmid}/status/reset) - equivalent to the reset button, no graceful shutdown. QEMU only. Tier-2 write; requires confirm:true.",
3148
+ parameters: Schema47,
3149
+ execute: async (_id, raw) => {
3150
+ assertConfirmedWrite(raw, NAME44);
3151
+ const args = validateToolArgs(Schema47, raw, NAME44);
3152
+ const client = getClient();
3153
+ const { node, type } = await resolveResource(client, args.vmid);
3154
+ if (type !== "qemu") {
3155
+ throw new Error(`vmid ${args.vmid} is an LXC container; reset is QEMU-only. Use proxmox_reboot_resource.`);
3156
+ }
3157
+ const upid = await client.post(`/nodes/${node}/qemu/${args.vmid}/status/reset`, {});
3158
+ return jsonToolResult({ vmid: args.vmid, node, type, upid });
3159
+ }
3160
+ };
3161
+ }
3162
+
3163
+ // src/tools/proxmox_convert_to_template.ts
3164
+ import { Type as Type51 } from "@sinclair/typebox";
3165
+ var Schema48 = Type51.Object(
3166
+ {
3167
+ vmid: Type51.Integer({ minimum: 1, description: "Container or VM ID to convert into a template." }),
3168
+ confirm: Type51.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3169
+ },
3170
+ { additionalProperties: false }
3171
+ );
3172
+ var NAME45 = "proxmox_convert_to_template";
3173
+ function createProxmoxConvertToTemplateTool(getClient) {
3174
+ return {
3175
+ name: NAME45,
3176
+ label: "proxmox: convert to template",
3177
+ description: "Convert a stopped VM or container into a template (POST /nodes/{node}/{type}/{vmid}/template). One-way: a template cannot be started, only cloned from. Tier-2 write; requires confirm:true.",
3178
+ parameters: Schema48,
3179
+ execute: async (_id, raw) => {
3180
+ assertConfirmedWrite(raw, NAME45);
3181
+ const args = validateToolArgs(Schema48, raw, NAME45);
3182
+ const client = getClient();
3183
+ const { node, type } = await resolveResource(client, args.vmid);
3184
+ const upid = await client.post(`/nodes/${node}/${type}/${args.vmid}/template`, {});
3185
+ return jsonToolResult({ vmid: args.vmid, node, type, template: true, upid: upid ?? null });
3186
+ }
3187
+ };
3188
+ }
3189
+
3190
+ // src/tools/proxmox_list_storage_content.ts
3191
+ import { Type as Type52 } from "@sinclair/typebox";
3192
+ var Schema49 = Type52.Object(
3193
+ {
3194
+ node: Type52.String({ minLength: 1, description: "Node whose storage to inspect." }),
3195
+ storage: Type52.String({ minLength: 1, description: "Storage ID, e.g. 'local', 'local-lvm'." }),
3196
+ content: Type52.Optional(
3197
+ Type52.Union(
3198
+ [
3199
+ Type52.Literal("backup"),
3200
+ Type52.Literal("iso"),
3201
+ Type52.Literal("vztmpl"),
3202
+ Type52.Literal("images"),
3203
+ Type52.Literal("rootdir"),
3204
+ Type52.Literal("snippets")
3205
+ ],
3206
+ { description: "Filter by content type (backup, iso, vztmpl, images, rootdir, snippets)." }
3207
+ )
3208
+ ),
3209
+ vmid: Type52.Optional(Type52.Integer({ minimum: 1, description: "Filter to a single owning VMID." }))
3210
+ },
3211
+ { additionalProperties: false }
3212
+ );
3213
+ var NAME46 = "proxmox_list_storage_content";
3214
+ function createProxmoxListStorageContentTool(getClient) {
3215
+ return {
3216
+ name: NAME46,
3217
+ label: "proxmox: list storage content",
3218
+ description: "List volumes on a storage (GET /nodes/{node}/storage/{storage}/content): ISOs, container templates, disk images, and backups, with size + owning vmid. Optionally filter by content type or vmid. Tier-1 read.",
3219
+ parameters: Schema49,
3220
+ execute: async (_id, raw) => {
3221
+ const args = validateToolArgs(
3222
+ Schema49,
3223
+ raw,
3224
+ NAME46
3225
+ );
3226
+ assertSafePathSegment(args.node, "node");
3227
+ assertSafePathSegment(args.storage, "storage");
3228
+ const params = new URLSearchParams();
3229
+ if (args.content) params.append("content", args.content);
3230
+ if (typeof args.vmid === "number") params.append("vmid", String(args.vmid));
3231
+ const qs = params.toString();
3232
+ const path2 = `/nodes/${args.node}/storage/${args.storage}/content${qs ? `?${qs}` : ""}`;
3233
+ const items = await getClient().get(path2);
3234
+ return jsonToolResult({ node: args.node, storage: args.storage, count: items.length, content: items });
3235
+ }
3236
+ };
3237
+ }
3238
+
3239
+ // src/tools/proxmox_download_url.ts
3240
+ import { Type as Type53 } from "@sinclair/typebox";
3241
+ var Schema50 = Type53.Object(
3242
+ {
3243
+ node: Type53.String({ minLength: 1, description: "Node to download onto." }),
3244
+ storage: Type53.String({ minLength: 1, description: "Target storage ID (must allow iso/vztmpl content)." }),
3245
+ content: Type53.Union([Type53.Literal("iso"), Type53.Literal("vztmpl")], {
3246
+ description: "Content type: 'iso' for an install image, 'vztmpl' for a container template."
3247
+ }),
3248
+ url: Type53.String({ minLength: 1, description: "HTTP(S) URL to download from." }),
3249
+ filename: Type53.String({ minLength: 1, description: "Destination filename on the storage." }),
3250
+ checksum: Type53.Optional(Type53.String({ minLength: 1, description: "Expected checksum of the download." })),
3251
+ checksum_algorithm: Type53.Optional(
3252
+ Type53.Union(
3253
+ [Type53.Literal("md5"), Type53.Literal("sha1"), Type53.Literal("sha256"), Type53.Literal("sha512")],
3254
+ { description: "Algorithm for the checksum." }
3255
+ )
3256
+ ),
3257
+ verify_certificates: Type53.Optional(
3258
+ Type53.Boolean({ description: "Verify the source server's TLS cert (default true)." })
3259
+ ),
3260
+ confirm: Type53.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." }),
3261
+ ...taskWaitFields
3262
+ },
3263
+ { additionalProperties: false }
3264
+ );
3265
+ var NAME47 = "proxmox_download_url";
3266
+ function createProxmoxDownloadUrlTool(getClient) {
3267
+ return {
3268
+ name: NAME47,
3269
+ label: "proxmox: download url",
3270
+ description: "Download an ISO or container template from a URL onto a storage (POST /nodes/{node}/storage/{storage}/download-url). Optional checksum verification. Tier-2 write; requires confirm:true.",
3271
+ parameters: Schema50,
3272
+ execute: async (_id, raw) => {
3273
+ assertConfirmedWrite(raw, NAME47);
3274
+ const args = validateToolArgs(Schema50, raw, NAME47);
3275
+ assertSafePathSegment(args.node, "node");
3276
+ assertSafePathSegment(args.storage, "storage");
3277
+ if (!/^https?:\/\//i.test(args.url)) {
3278
+ throw new ToolInputError(`${NAME47}: url must be http(s)`);
3279
+ }
3280
+ if (args.checksum && !args.checksum_algorithm) {
3281
+ throw new ToolInputError(`${NAME47}: checksum_algorithm is required when checksum is set`);
3282
+ }
3283
+ const body = {
3284
+ content: args.content,
3285
+ url: args.url,
3286
+ filename: args.filename
3287
+ };
3288
+ if (args.checksum) body.checksum = args.checksum;
3289
+ if (args.checksum_algorithm) body["checksum-algorithm"] = args.checksum_algorithm;
3290
+ if (args.verify_certificates === false) body["verify-certificates"] = 0;
3291
+ const client = getClient();
3292
+ const upid = await client.post(
3293
+ `/nodes/${args.node}/storage/${args.storage}/download-url`,
3294
+ body
3295
+ );
3296
+ const task = await resolveTaskWait(client, upid, args);
3297
+ return jsonToolResult({
3298
+ node: args.node,
3299
+ storage: args.storage,
3300
+ content: args.content,
3301
+ filename: args.filename,
3302
+ upid,
3303
+ ...task ? { task } : {}
3304
+ });
3305
+ }
3306
+ };
3307
+ }
3308
+
3309
+ // src/tools/proxmox_delete_volume.ts
3310
+ import { Type as Type54 } from "@sinclair/typebox";
3311
+ var VOLID_RE = /^[\w.-]+:[\w./-]+$/;
3312
+ var Schema51 = Type54.Object(
3313
+ {
3314
+ node: Type54.String({ minLength: 1, description: "Node the storage is on." }),
3315
+ storage: Type54.String({ minLength: 1, description: "Storage ID holding the volume." }),
3316
+ volume: Type54.String({
3317
+ minLength: 1,
3318
+ description: "Full volid to delete, e.g. 'local:backup/vzdump-lxc-100-...tar.zst'."
3319
+ }),
3320
+ confirm: Type54.Boolean({ description: "Must be true. Tier-3 destructive gate." }),
3321
+ destructive: Type54.Boolean({ description: "Must be true. Tier-3 destructive gate." })
3322
+ },
3323
+ { additionalProperties: false }
3324
+ );
3325
+ var NAME48 = "proxmox_delete_volume";
3326
+ function createProxmoxDeleteVolumeTool(getClient) {
3327
+ return {
3328
+ name: NAME48,
3329
+ label: "proxmox: delete volume",
3330
+ description: "Permanently delete a storage volume - a backup archive, ISO, template, or disk image (DELETE /nodes/{node}/storage/{storage}/content/{volume}). Tier-3 destructive; requires confirm:true, destructive:true, and env PROXMOX_ENABLE_DESTRUCTIVE=1.",
3331
+ parameters: Schema51,
3332
+ execute: async (_id, raw) => {
3333
+ assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME48);
3334
+ assertDestructive(raw, NAME48);
3335
+ const args = validateToolArgs(Schema51, raw, NAME48);
3336
+ assertSafePathSegment(args.node, "node");
3337
+ assertSafePathSegment(args.storage, "storage");
3338
+ if (args.volume.includes("..") || !VOLID_RE.test(args.volume)) {
3339
+ throw new ToolInputError(`${NAME48}: invalid volume id "${args.volume}"`);
3340
+ }
3341
+ const path2 = `/nodes/${args.node}/storage/${args.storage}/content/${encodeURIComponent(args.volume)}`;
3342
+ const upid = await getClient().delete(path2);
3343
+ return jsonToolResult({ node: args.node, storage: args.storage, volume: args.volume, upid: upid ?? null });
3344
+ }
3345
+ };
3346
+ }
3347
+
3348
+ // src/tools/proxmox_list_node_services.ts
3349
+ import { Type as Type55 } from "@sinclair/typebox";
3350
+ var Schema52 = Type55.Object(
3351
+ { node: Type55.String({ minLength: 1, description: "Node to inspect." }) },
3352
+ { additionalProperties: false }
3353
+ );
3354
+ var NAME49 = "proxmox_list_node_services";
3355
+ function createProxmoxListNodeServicesTool(getClient) {
3356
+ return {
3357
+ name: NAME49,
3358
+ label: "proxmox: list node services",
3359
+ description: "List the Proxmox host's systemd services and their state (GET /nodes/{node}/services): pveproxy, pvedaemon, pve-cluster, corosync, etc. Tier-1 read.",
3360
+ parameters: Schema52,
3361
+ execute: async (_id, raw) => {
3362
+ const args = validateToolArgs(Schema52, raw, NAME49);
3363
+ assertSafePathSegment(args.node, "node");
3364
+ const services = await getClient().get(`/nodes/${args.node}/services`);
3365
+ return jsonToolResult({ node: args.node, count: services.length, services });
3366
+ }
3367
+ };
3368
+ }
3369
+
3370
+ // src/tools/proxmox_list_updates.ts
3371
+ import { Type as Type56 } from "@sinclair/typebox";
3372
+ var Schema53 = Type56.Object(
3373
+ { node: Type56.String({ minLength: 1, description: "Node to check for pending package updates." }) },
3374
+ { additionalProperties: false }
3375
+ );
3376
+ var NAME50 = "proxmox_list_updates";
3377
+ function createProxmoxListUpdatesTool(getClient) {
3378
+ return {
3379
+ name: NAME50,
3380
+ label: "proxmox: list updates",
3381
+ description: "List pending APT package updates on a node (GET /nodes/{node}/apt/update): package, current and candidate versions. Read-only; does not refresh the index or install anything. Note: Proxmox gates this endpoint behind the Sys.Modify privilege, so an audit-only token gets 403. Tier-1 read.",
3382
+ parameters: Schema53,
3383
+ execute: async (_id, raw) => {
3384
+ const args = validateToolArgs(Schema53, raw, NAME50);
3385
+ assertSafePathSegment(args.node, "node");
3386
+ const updates = await getClient().get(`/nodes/${args.node}/apt/update`);
3387
+ return jsonToolResult({ node: args.node, count: updates.length, updates });
3388
+ }
3389
+ };
3390
+ }
3391
+
3392
+ // src/tools/proxmox_list_disks.ts
3393
+ import { Type as Type57 } from "@sinclair/typebox";
3394
+ var Schema54 = Type57.Object(
3395
+ {
3396
+ node: Type57.String({ minLength: 1, description: "Node whose physical disks to list." }),
3397
+ include_partitions: Type57.Optional(
3398
+ Type57.Boolean({ description: "Include partitions in the listing (default false)." })
3399
+ )
3400
+ },
3401
+ { additionalProperties: false }
3402
+ );
3403
+ var NAME51 = "proxmox_list_disks";
3404
+ function createProxmoxListDisksTool(getClient) {
3405
+ return {
3406
+ name: NAME51,
3407
+ label: "proxmox: list disks",
3408
+ description: "List a node's physical disks with model, size, type, SMART health and wearout (GET /nodes/{node}/disks/list). Tier-1 read.",
3409
+ parameters: Schema54,
3410
+ execute: async (_id, raw) => {
3411
+ const args = validateToolArgs(Schema54, raw, NAME51);
3412
+ assertSafePathSegment(args.node, "node");
3413
+ const qs = args.include_partitions ? "?include-partitions=1" : "";
3414
+ const disks = await getClient().get(`/nodes/${args.node}/disks/list${qs}`);
3415
+ return jsonToolResult({ node: args.node, count: disks.length, disks });
3416
+ }
3417
+ };
3418
+ }
3419
+
3420
+ // src/tools/proxmox_cancel_task.ts
3421
+ import { Type as Type58 } from "@sinclair/typebox";
3422
+ var Schema55 = Type58.Object(
3423
+ {
3424
+ upid: Type58.String({ minLength: 1, description: "UPID of the running task to stop." }),
3425
+ confirm: Type58.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3426
+ },
3427
+ { additionalProperties: false }
3428
+ );
3429
+ var NAME52 = "proxmox_cancel_task";
3430
+ function createProxmoxCancelTaskTool(getClient) {
3431
+ return {
3432
+ name: NAME52,
3433
+ label: "proxmox: cancel task",
3434
+ description: "Stop a running Proxmox task by UPID (DELETE /nodes/{node}/tasks/{upid}) - e.g. abort a stuck migration or backup. The node is parsed from the UPID. Tier-2 write; requires confirm:true.",
3435
+ parameters: Schema55,
3436
+ execute: async (_id, raw) => {
3437
+ assertConfirmedWrite(raw, NAME52);
3438
+ const args = validateToolArgs(Schema55, raw, NAME52);
3439
+ const { node } = parseTaskUpid(args.upid);
3440
+ await getClient().delete(`/nodes/${node}/tasks/${encodeURIComponent(args.upid)}`);
3441
+ return jsonToolResult({ upid: args.upid, node, stopped: true });
3442
+ }
3443
+ };
3444
+ }
3445
+
3446
+ // src/tools/proxmox_node_power.ts
3447
+ import { Type as Type59 } from "@sinclair/typebox";
3448
+ var Schema56 = Type59.Object(
3449
+ {
3450
+ node: Type59.String({ minLength: 1, description: "Node to power-cycle." }),
3451
+ command: Type59.Union([Type59.Literal("reboot"), Type59.Literal("shutdown")], {
3452
+ description: "'reboot' or 'shutdown' the physical/virtual host."
3453
+ }),
3454
+ confirm: Type59.Boolean({ description: "Must be true. Tier-3 destructive gate." }),
3455
+ destructive: Type59.Boolean({ description: "Must be true. Tier-3 destructive gate." })
3456
+ },
3457
+ { additionalProperties: false }
3458
+ );
3459
+ var NAME53 = "proxmox_node_power";
3460
+ function createProxmoxNodePowerTool(getClient) {
3461
+ return {
3462
+ name: NAME53,
3463
+ label: "proxmox: node power",
3464
+ description: "Reboot or shut down an entire Proxmox node (POST /nodes/{node}/status), which takes down every guest on it. Tier-3 destructive; requires confirm:true, destructive:true, and env PROXMOX_ENABLE_DESTRUCTIVE=1.",
3465
+ parameters: Schema56,
3466
+ execute: async (_id, raw) => {
3467
+ assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME53);
3468
+ assertDestructive(raw, NAME53);
3469
+ const args = validateToolArgs(Schema56, raw, NAME53);
3470
+ assertSafePathSegment(args.node, "node");
3471
+ await getClient().post(`/nodes/${args.node}/status`, { command: args.command });
3472
+ return jsonToolResult({ node: args.node, command: args.command, issued: true });
3473
+ }
3474
+ };
3475
+ }
3476
+
3477
+ // src/tools/proxmox_list_firewall_rules.ts
3478
+ import { Type as Type61 } from "@sinclair/typebox";
3479
+
3480
+ // src/tools/firewall-target.ts
3481
+ import { Type as Type60 } from "@sinclair/typebox";
3482
+ var firewallScopeFields = {
3483
+ scope: Type60.Union(
3484
+ [Type60.Literal("cluster"), Type60.Literal("node"), Type60.Literal("guest")],
3485
+ { description: "Firewall scope: 'cluster', 'node' (needs node), or 'guest' (needs vmid)." }
3486
+ ),
3487
+ node: Type60.Optional(Type60.String({ minLength: 1, description: "Node name (required when scope='node')." })),
3488
+ vmid: Type60.Optional(Type60.Integer({ minimum: 1, description: "Guest VMID (required when scope='guest')." }))
3489
+ };
3490
+ async function resolveFirewallBase(client, args, toolName) {
3491
+ if (args.scope === "cluster") {
3492
+ return { base: "/cluster/firewall", label: "cluster" };
3493
+ }
3494
+ if (args.scope === "node") {
3495
+ if (!args.node) throw new ToolInputError(`${toolName}: node is required when scope='node'`);
3496
+ assertSafePathSegment(args.node, "node");
3497
+ return { base: `/nodes/${args.node}/firewall`, label: `node ${args.node}` };
3498
+ }
3499
+ if (typeof args.vmid !== "number") {
3500
+ throw new ToolInputError(`${toolName}: vmid is required when scope='guest'`);
3501
+ }
3502
+ const { node, type } = await resolveResource(client, args.vmid);
3503
+ return { base: `/nodes/${node}/${type}/${args.vmid}/firewall`, label: `${type} ${args.vmid}` };
3504
+ }
3505
+
3506
+ // src/tools/proxmox_list_firewall_rules.ts
3507
+ var Schema57 = Type61.Object({ ...firewallScopeFields }, { additionalProperties: false });
3508
+ var NAME54 = "proxmox_list_firewall_rules";
3509
+ function createProxmoxListFirewallRulesTool(getClient) {
3510
+ return {
3511
+ name: NAME54,
3512
+ label: "proxmox: list firewall rules",
3513
+ description: "List firewall rules at the cluster, node, or guest scope (GET {base}/firewall/rules). Returns rule position, action, direction, and match fields. Tier-1 read.",
3514
+ parameters: Schema57,
3515
+ execute: async (_id, raw) => {
3516
+ const args = validateToolArgs(Schema57, raw, NAME54);
3517
+ const client = getClient();
3518
+ const { base, label } = await resolveFirewallBase(client, args, NAME54);
3519
+ const rules = await client.get(`${base}/rules`);
3520
+ return jsonToolResult({ scope: label, count: Array.isArray(rules) ? rules.length : 0, rules });
3521
+ }
3522
+ };
3523
+ }
3524
+
3525
+ // src/tools/proxmox_get_firewall_options.ts
3526
+ import { Type as Type62 } from "@sinclair/typebox";
3527
+ var Schema58 = Type62.Object({ ...firewallScopeFields }, { additionalProperties: false });
3528
+ var NAME55 = "proxmox_get_firewall_options";
3529
+ function createProxmoxGetFirewallOptionsTool(getClient) {
3530
+ return {
3531
+ name: NAME55,
3532
+ label: "proxmox: get firewall options",
3533
+ description: "Read firewall options at the cluster, node, or guest scope (GET {base}/firewall/options): whether the firewall is enabled, default in/out policy, logging. Tier-1 read.",
3534
+ parameters: Schema58,
3535
+ execute: async (_id, raw) => {
3536
+ const args = validateToolArgs(Schema58, raw, NAME55);
3537
+ const client = getClient();
3538
+ const { base, label } = await resolveFirewallBase(client, args, NAME55);
3539
+ const options = await client.get(`${base}/options`);
3540
+ return jsonToolResult({ scope: label, options });
3541
+ }
3542
+ };
3543
+ }
3544
+
3545
+ // src/tools/proxmox_add_firewall_rule.ts
3546
+ import { Type as Type63 } from "@sinclair/typebox";
3547
+ var Schema59 = Type63.Object(
3548
+ {
3549
+ ...firewallScopeFields,
3550
+ type: Type63.Union([Type63.Literal("in"), Type63.Literal("out"), Type63.Literal("group")], {
3551
+ description: "Rule direction: 'in', 'out', or 'group' (attach a security group)."
3552
+ }),
3553
+ action: Type63.String({
3554
+ minLength: 1,
3555
+ description: "ACCEPT, DROP, REJECT, or a security-group name when type='group'."
3556
+ }),
3557
+ source: Type63.Optional(Type63.String({ minLength: 1, description: "Source CIDR/IP/alias." })),
3558
+ dest: Type63.Optional(Type63.String({ minLength: 1, description: "Destination CIDR/IP/alias." })),
3559
+ proto: Type63.Optional(Type63.String({ minLength: 1, description: "Protocol, e.g. tcp, udp, icmp." })),
3560
+ dport: Type63.Optional(Type63.String({ minLength: 1, description: "Destination port(s), e.g. '22' or '8000:8100'." })),
3561
+ sport: Type63.Optional(Type63.String({ minLength: 1, description: "Source port(s)." })),
3562
+ macro: Type63.Optional(Type63.String({ minLength: 1, description: "Predefined macro, e.g. 'SSH', 'HTTP'." })),
3563
+ comment: Type63.Optional(Type63.String({ description: "Human-readable comment." })),
3564
+ enable: Type63.Optional(Type63.Boolean({ description: "Whether the rule is active (default true)." })),
3565
+ pos: Type63.Optional(Type63.Integer({ minimum: 0, description: "Insert position (default: prepend at 0)." })),
3566
+ confirm: Type63.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3567
+ },
3568
+ { additionalProperties: false }
3569
+ );
3570
+ var NAME56 = "proxmox_add_firewall_rule";
3571
+ function createProxmoxAddFirewallRuleTool(getClient) {
3572
+ return {
3573
+ name: NAME56,
3574
+ label: "proxmox: add firewall rule",
3575
+ description: "Add a firewall rule at the cluster, node, or guest scope (POST {base}/firewall/rules). Tier-2 write; requires confirm:true.",
3576
+ parameters: Schema59,
3577
+ execute: async (_id, raw) => {
3578
+ assertConfirmedWrite(raw, NAME56);
3579
+ const args = validateToolArgs(Schema59, raw, NAME56);
3580
+ const client = getClient();
3581
+ const { base, label } = await resolveFirewallBase(client, args, NAME56);
3582
+ const body = { type: args.type, action: args.action };
3583
+ for (const k of ["source", "dest", "proto", "dport", "sport", "macro", "comment"]) {
3584
+ const v = args[k];
3585
+ if (typeof v === "string" && v.length > 0) body[k] = v;
3586
+ }
3587
+ body.enable = args.enable === false ? 0 : 1;
3588
+ if (typeof args.pos === "number") body.pos = args.pos;
3589
+ await client.post(`${base}/rules`, body);
3590
+ return jsonToolResult({ scope: label, type: args.type, action: args.action, added: true });
3591
+ }
3592
+ };
3593
+ }
3594
+
3595
+ // src/tools/proxmox_delete_firewall_rule.ts
3596
+ import { Type as Type64 } from "@sinclair/typebox";
3597
+ var Schema60 = Type64.Object(
3598
+ {
3599
+ ...firewallScopeFields,
3600
+ pos: Type64.Integer({ minimum: 0, description: "Rule position/index to delete (see list_firewall_rules)." }),
3601
+ digest: Type64.Optional(
3602
+ Type64.String({ minLength: 1, description: "Ruleset digest for optimistic concurrency." })
3603
+ ),
3604
+ confirm: Type64.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3605
+ },
3606
+ { additionalProperties: false }
3607
+ );
3608
+ var NAME57 = "proxmox_delete_firewall_rule";
3609
+ function createProxmoxDeleteFirewallRuleTool(getClient) {
3610
+ return {
3611
+ name: NAME57,
3612
+ label: "proxmox: delete firewall rule",
3613
+ description: "Delete a firewall rule by position at the cluster, node, or guest scope (DELETE {base}/firewall/rules/{pos}). Tier-2 write; requires confirm:true.",
3614
+ parameters: Schema60,
3615
+ execute: async (_id, raw) => {
3616
+ assertConfirmedWrite(raw, NAME57);
3617
+ const args = validateToolArgs(Schema60, raw, NAME57);
3618
+ const client = getClient();
3619
+ const { base, label } = await resolveFirewallBase(client, args, NAME57);
3620
+ const qs = args.digest ? `?digest=${encodeURIComponent(args.digest)}` : "";
3621
+ await client.delete(`${base}/rules/${args.pos}${qs}`);
3622
+ return jsonToolResult({ scope: label, pos: args.pos, deleted: true });
3623
+ }
3624
+ };
3625
+ }
3626
+
3627
+ // src/tools/proxmox_set_firewall_enabled.ts
3628
+ import { Type as Type65 } from "@sinclair/typebox";
3629
+ var Schema61 = Type65.Object(
3630
+ {
3631
+ ...firewallScopeFields,
3632
+ enable: Type65.Boolean({ description: "Turn the firewall on (true) or off (false) for this scope." }),
3633
+ confirm: Type65.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3634
+ },
3635
+ { additionalProperties: false }
3636
+ );
3637
+ var NAME58 = "proxmox_set_firewall_enabled";
3638
+ function createProxmoxSetFirewallEnabledTool(getClient) {
3639
+ return {
3640
+ name: NAME58,
3641
+ label: "proxmox: set firewall enabled",
3642
+ description: "Enable or disable the firewall at the cluster, node, or guest scope (PUT {base}/firewall/options with enable). Note: the cluster-level switch gates all others. Tier-2 write; requires confirm:true.",
3643
+ parameters: Schema61,
3644
+ execute: async (_id, raw) => {
3645
+ assertConfirmedWrite(raw, NAME58);
3646
+ const args = validateToolArgs(Schema61, raw, NAME58);
3647
+ const client = getClient();
3648
+ const { base, label } = await resolveFirewallBase(client, args, NAME58);
3649
+ await client.put(`${base}/options`, { enable: args.enable ? 1 : 0 });
3650
+ return jsonToolResult({ scope: label, enabled: args.enable });
3651
+ }
3652
+ };
3653
+ }
3654
+
3655
+ // src/tools/proxmox_move_disk.ts
3656
+ import { Type as Type66 } from "@sinclair/typebox";
3657
+ var DISK_KEY_RE2 = /^[a-zA-Z][a-zA-Z0-9_]*$/;
3658
+ var Schema62 = Type66.Object(
3659
+ {
3660
+ vmid: Type66.Integer({ minimum: 1, description: "Container or VM ID." }),
3661
+ disk: Type66.String({
3662
+ minLength: 1,
3663
+ description: "Disk/volume key to move, e.g. 'scsi0' (QEMU) or 'rootfs'/'mp0' (LXC)."
3664
+ }),
3665
+ target_storage: Type66.String({ minLength: 1, description: "Target storage to move the disk onto." }),
3666
+ delete_source: Type66.Optional(
3667
+ Type66.Boolean({ description: "Delete the original disk after a successful move (default false)." })
3668
+ ),
3669
+ confirm: Type66.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." }),
3670
+ ...taskWaitFields
3671
+ },
3672
+ { additionalProperties: false }
3673
+ );
3674
+ var NAME59 = "proxmox_move_disk";
3675
+ function createProxmoxMoveDiskTool(getClient) {
3676
+ return {
3677
+ name: NAME59,
3678
+ label: "proxmox: move disk",
3679
+ description: "Relocate a VM disk (POST /nodes/{node}/qemu/{vmid}/move_disk) or container volume (POST /nodes/{node}/lxc/{vmid}/move_volume) to another storage. Optionally deletes the source after a successful copy. Tier-2 write; requires confirm:true.",
3680
+ parameters: Schema62,
3681
+ execute: async (_id, raw) => {
3682
+ assertConfirmedWrite(raw, NAME59);
3683
+ const args = validateToolArgs(Schema62, raw, NAME59);
3684
+ if (!DISK_KEY_RE2.test(args.disk)) {
3685
+ throw new Error(`${NAME59}: invalid disk key "${args.disk}"`);
3686
+ }
3687
+ assertSafePathSegment(args.target_storage, "target_storage");
3688
+ const client = getClient();
3689
+ const { node, type } = await resolveResource(client, args.vmid);
3690
+ const del = args.delete_source === true ? 1 : 0;
3691
+ let upid;
3692
+ if (type === "qemu") {
3693
+ upid = await client.post(`/nodes/${node}/qemu/${args.vmid}/move_disk`, {
3694
+ disk: args.disk,
3695
+ storage: args.target_storage,
3696
+ delete: del
3697
+ });
3698
+ } else {
3699
+ upid = await client.post(`/nodes/${node}/lxc/${args.vmid}/move_volume`, {
3700
+ volume: args.disk,
3701
+ storage: args.target_storage,
3702
+ delete: del
3703
+ });
3704
+ }
3705
+ const task = await resolveTaskWait(client, upid, args);
3706
+ return jsonToolResult({
3707
+ vmid: args.vmid,
3708
+ node,
3709
+ type,
3710
+ disk: args.disk,
3711
+ target_storage: args.target_storage,
3712
+ deleted_source: del === 1,
3713
+ upid,
3714
+ ...task ? { task } : {}
3715
+ });
3716
+ }
3717
+ };
3718
+ }
3719
+
3720
+ // src/tools/proxmox_list_storage_config.ts
3721
+ import { Type as Type67 } from "@sinclair/typebox";
3722
+ var Schema63 = Type67.Object({}, { additionalProperties: false });
3723
+ var NAME60 = "proxmox_list_storage_config";
3724
+ function createProxmoxListStorageConfigTool(getClient) {
3725
+ return {
3726
+ name: NAME60,
3727
+ label: "proxmox: list storage config",
3728
+ description: "List datacenter storage definitions (GET /storage): id, type, allowed content, node restrictions, shared/disabled flags. This is the cluster storage configuration, distinct from per-node status. Tier-1 read.",
3729
+ parameters: Schema63,
3730
+ execute: async () => {
3731
+ const defs = await getClient().get("/storage");
3732
+ return jsonToolResult({ count: defs.length, storage: defs });
3733
+ }
3734
+ };
3735
+ }
3736
+
3737
+ // src/tools/proxmox_create_storage.ts
3738
+ import { Type as Type68 } from "@sinclair/typebox";
3739
+ var OPT_KEY_RE = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
3740
+ var Schema64 = Type68.Object(
3741
+ {
3742
+ storage: Type68.String({ minLength: 1, description: "New storage ID." }),
3743
+ type: Type68.Union(
3744
+ [
3745
+ Type68.Literal("dir"),
3746
+ Type68.Literal("nfs"),
3747
+ Type68.Literal("cifs"),
3748
+ Type68.Literal("lvm"),
3749
+ Type68.Literal("lvmthin"),
3750
+ Type68.Literal("zfspool"),
3751
+ Type68.Literal("pbs"),
3752
+ Type68.Literal("cephfs"),
3753
+ Type68.Literal("rbd")
3754
+ ],
3755
+ { description: "Storage backend type." }
3756
+ ),
3757
+ content: Type68.Optional(
3758
+ Type68.String({ minLength: 1, description: "Comma-separated content types, e.g. 'images,rootdir' or 'iso,backup,vztmpl'." })
3759
+ ),
3760
+ options: Type68.Optional(
3761
+ Type68.Record(Type68.String(), Type68.Union([Type68.String(), Type68.Number(), Type68.Boolean()]), {
3762
+ description: 'Type-specific keys, e.g. {"path":"/mnt/data"} for dir, {"server":"1.2.3.4","export":"/nfs"} for nfs, {"vgname":"pve","thinpool":"data"} for lvmthin.'
3763
+ })
3764
+ ),
3765
+ nodes: Type68.Optional(Type68.String({ minLength: 1, description: "Restrict to these nodes (comma-separated)." })),
3766
+ disable: Type68.Optional(Type68.Boolean({ description: "Create the storage in a disabled state." })),
3767
+ confirm: Type68.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3768
+ },
3769
+ { additionalProperties: false }
3770
+ );
3771
+ var NAME61 = "proxmox_create_storage";
3772
+ function createProxmoxCreateStorageTool(getClient) {
3773
+ return {
3774
+ name: NAME61,
3775
+ label: "proxmox: create storage",
3776
+ description: "Define a new datacenter storage (POST /storage) of a given type with content types and type-specific keys via `options`. Tier-2 write; requires confirm:true.",
3777
+ parameters: Schema64,
3778
+ execute: async (_id, raw) => {
3779
+ assertConfirmedWrite(raw, NAME61);
3780
+ const args = validateToolArgs(Schema64, raw, NAME61);
3781
+ assertSafePathSegment(args.storage, "storage");
3782
+ const body = { storage: args.storage, type: args.type };
3783
+ if (args.content) body.content = args.content;
3784
+ if (args.nodes) body.nodes = args.nodes;
3785
+ if (args.disable) body.disable = 1;
3786
+ if (args.options) {
3787
+ for (const [k, v] of Object.entries(args.options)) {
3788
+ if (!OPT_KEY_RE.test(k)) throw new ToolInputError(`${NAME61}: invalid option key "${k}"`);
3789
+ body[k] = typeof v === "boolean" ? v ? 1 : 0 : v;
3790
+ }
3791
+ }
3792
+ await getClient().post(`/storage`, body);
3793
+ return jsonToolResult({ storage: args.storage, type: args.type, created: true });
3794
+ }
3795
+ };
3796
+ }
3797
+
3798
+ // src/tools/proxmox_delete_storage.ts
3799
+ import { Type as Type69 } from "@sinclair/typebox";
3800
+ var Schema65 = Type69.Object(
3801
+ {
3802
+ storage: Type69.String({ minLength: 1, description: "Storage ID to remove from the datacenter config." }),
3803
+ confirm: Type69.Boolean({ description: "Must be true. Tier-3 destructive gate." }),
3804
+ destructive: Type69.Boolean({ description: "Must be true. Tier-3 destructive gate." })
3805
+ },
3806
+ { additionalProperties: false }
3807
+ );
3808
+ var NAME62 = "proxmox_delete_storage";
3809
+ function createProxmoxDeleteStorageTool(getClient) {
3810
+ return {
3811
+ name: NAME62,
3812
+ label: "proxmox: delete storage",
3813
+ description: "Remove a storage definition from the datacenter config (DELETE /storage/{id}). Does not erase the underlying data, but detaches it from Proxmox. Tier-3 destructive; requires confirm:true, destructive:true, and env PROXMOX_ENABLE_DESTRUCTIVE=1.",
3814
+ parameters: Schema65,
3815
+ execute: async (_id, raw) => {
3816
+ assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME62);
3817
+ assertDestructive(raw, NAME62);
3818
+ const args = validateToolArgs(Schema65, raw, NAME62);
3819
+ assertSafePathSegment(args.storage, "storage");
3820
+ await getClient().delete(`/storage/${args.storage}`);
3821
+ return jsonToolResult({ storage: args.storage, deleted: true });
3822
+ }
3823
+ };
3824
+ }
3825
+
3826
+ // src/tools/proxmox_list_backup_jobs.ts
3827
+ import { Type as Type70 } from "@sinclair/typebox";
3828
+ var Schema66 = Type70.Object({}, { additionalProperties: false });
3829
+ var NAME63 = "proxmox_list_backup_jobs";
3830
+ function createProxmoxListBackupJobsTool(getClient) {
3831
+ return {
3832
+ name: NAME63,
3833
+ label: "proxmox: list backup jobs",
3834
+ description: "List scheduled backup (vzdump) jobs (GET /cluster/backup): id, schedule, target storage, selection, and enabled state. Tier-1 read.",
3835
+ parameters: Schema66,
3836
+ execute: async () => {
3837
+ const jobs = await getClient().get("/cluster/backup");
3838
+ return jsonToolResult({ count: jobs.length, jobs });
3839
+ }
3840
+ };
3841
+ }
3842
+
3843
+ // src/tools/proxmox_create_backup_job.ts
3844
+ import { Type as Type71 } from "@sinclair/typebox";
3845
+ var Schema67 = Type71.Object(
3846
+ {
3847
+ schedule: Type71.String({ minLength: 1, description: "Systemd-calendar schedule, e.g. '02:00' or 'mon..fri 21:00'." }),
3848
+ storage: Type71.String({ minLength: 1, description: "Target storage for the backups." }),
3849
+ all: Type71.Optional(Type71.Boolean({ description: "Back up all guests. Mutually exclusive with vmid/pool." })),
3850
+ vmid: Type71.Optional(Type71.String({ minLength: 1, description: "Comma-separated VMIDs to back up." })),
3851
+ pool: Type71.Optional(Type71.String({ minLength: 1, description: "Back up all guests in this pool." })),
3852
+ mode: Type71.Optional(
3853
+ Type71.Union([Type71.Literal("snapshot"), Type71.Literal("suspend"), Type71.Literal("stop")], {
3854
+ description: "Backup mode (default snapshot)."
3855
+ })
3856
+ ),
3857
+ compress: Type71.Optional(
3858
+ Type71.Union([Type71.Literal("zstd"), Type71.Literal("gzip"), Type71.Literal("lzo"), Type71.Literal("0")], {
3859
+ description: "Compression (default zstd)."
3860
+ })
3861
+ ),
3862
+ enabled: Type71.Optional(Type71.Boolean({ description: "Whether the job is active (default true)." })),
3863
+ mailto: Type71.Optional(Type71.String({ minLength: 1, description: "Email address for notifications." })),
3864
+ comment: Type71.Optional(Type71.String({ description: "Job comment/description." })),
3865
+ confirm: Type71.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3866
+ },
3867
+ { additionalProperties: false }
3868
+ );
3869
+ var NAME64 = "proxmox_create_backup_job";
3870
+ function createProxmoxCreateBackupJobTool(getClient) {
3871
+ return {
3872
+ name: NAME64,
3873
+ label: "proxmox: create backup job",
3874
+ description: "Create a scheduled backup (vzdump) job (POST /cluster/backup). Specify a schedule + storage and a selection (all, vmid list, or pool). Tier-2 write; requires confirm:true.",
3875
+ parameters: Schema67,
3876
+ execute: async (_id, raw) => {
3877
+ assertConfirmedWrite(raw, NAME64);
3878
+ const args = validateToolArgs(Schema67, raw, NAME64);
3879
+ const selectors = [args.all ? "all" : null, args.vmid ? "vmid" : null, args.pool ? "pool" : null].filter(Boolean);
3880
+ if (selectors.length === 0) {
3881
+ throw new ToolInputError(`${NAME64}: provide exactly one selection - all, vmid, or pool.`);
3882
+ }
3883
+ if (selectors.length > 1) {
3884
+ throw new ToolInputError(`${NAME64}: selection is exclusive - pass only one of all/vmid/pool.`);
3885
+ }
3886
+ const body = {
3887
+ schedule: args.schedule,
3888
+ storage: args.storage,
3889
+ mode: args.mode ?? "snapshot",
3890
+ compress: args.compress ?? "zstd",
3891
+ enabled: args.enabled === false ? 0 : 1
3892
+ };
3893
+ if (args.all) body.all = 1;
3894
+ if (args.vmid) body.vmid = args.vmid;
3895
+ if (args.pool) body.pool = args.pool;
3896
+ if (args.mailto) body.mailto = args.mailto;
3897
+ if (typeof args.comment === "string" && args.comment.length > 0) body.comment = args.comment;
3898
+ await getClient().post(`/cluster/backup`, body);
3899
+ return jsonToolResult({ schedule: args.schedule, storage: args.storage, created: true });
3900
+ }
3901
+ };
3902
+ }
3903
+
3904
+ // src/tools/proxmox_delete_backup_job.ts
3905
+ import { Type as Type72 } from "@sinclair/typebox";
3906
+ var Schema68 = Type72.Object(
3907
+ {
3908
+ id: Type72.String({ minLength: 1, description: "Backup job ID (from proxmox_list_backup_jobs)." }),
3909
+ confirm: Type72.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3910
+ },
3911
+ { additionalProperties: false }
3912
+ );
3913
+ var NAME65 = "proxmox_delete_backup_job";
3914
+ function createProxmoxDeleteBackupJobTool(getClient) {
3915
+ return {
3916
+ name: NAME65,
3917
+ label: "proxmox: delete backup job",
3918
+ description: "Delete a scheduled backup job by id (DELETE /cluster/backup/{id}). Removes the schedule only; existing backup archives are untouched. Tier-2 write; requires confirm:true.",
3919
+ parameters: Schema68,
3920
+ execute: async (_id, raw) => {
3921
+ assertConfirmedWrite(raw, NAME65);
3922
+ const args = validateToolArgs(Schema68, raw, NAME65);
3923
+ assertSafePathSegment(args.id, "id");
3924
+ await getClient().delete(`/cluster/backup/${args.id}`);
3925
+ return jsonToolResult({ id: args.id, deleted: true });
3926
+ }
3927
+ };
3928
+ }
3929
+
3930
+ // src/tools/proxmox_list_users.ts
3931
+ import { Type as Type73 } from "@sinclair/typebox";
3932
+ var Schema69 = Type73.Object({}, { additionalProperties: false });
3933
+ var NAME66 = "proxmox_list_users";
3934
+ function createProxmoxListUsersTool(getClient) {
3935
+ return {
3936
+ name: NAME66,
3937
+ label: "proxmox: list users",
3938
+ description: "List Proxmox access users (GET /access/users): userid, realm, enabled/expire state, comment. Tier-1 read.",
3939
+ parameters: Schema69,
3940
+ execute: async () => {
3941
+ const users = await getClient().get("/access/users");
3942
+ return jsonToolResult({ count: users.length, users });
3943
+ }
3944
+ };
3945
+ }
3946
+
3947
+ // src/tools/proxmox_list_roles.ts
3948
+ import { Type as Type74 } from "@sinclair/typebox";
3949
+ var Schema70 = Type74.Object({}, { additionalProperties: false });
3950
+ var NAME67 = "proxmox_list_roles";
3951
+ function createProxmoxListRolesTool(getClient) {
3952
+ return {
3953
+ name: NAME67,
3954
+ label: "proxmox: list roles",
3955
+ description: "List Proxmox roles and their privileges (GET /access/roles). Tier-1 read.",
3956
+ parameters: Schema70,
3957
+ execute: async () => {
3958
+ const roles = await getClient().get("/access/roles");
3959
+ return jsonToolResult({ count: roles.length, roles });
3960
+ }
3961
+ };
3962
+ }
3963
+
3964
+ // src/tools/proxmox_list_acl.ts
3965
+ import { Type as Type75 } from "@sinclair/typebox";
3966
+ var Schema71 = Type75.Object({}, { additionalProperties: false });
3967
+ var NAME68 = "proxmox_list_acl";
3968
+ function createProxmoxListAclTool(getClient) {
3969
+ return {
3970
+ name: NAME68,
3971
+ label: "proxmox: list ACL",
3972
+ description: "List access-control entries (GET /access/acl): which user/group/token holds which role on which path, and whether it propagates. Tier-1 read.",
3973
+ parameters: Schema71,
3974
+ execute: async () => {
3975
+ const acl = await getClient().get("/access/acl");
3976
+ return jsonToolResult({ count: acl.length, acl });
3977
+ }
3978
+ };
3979
+ }
3980
+
3981
+ // src/tools/proxmox_list_pools.ts
3982
+ import { Type as Type76 } from "@sinclair/typebox";
3983
+ var Schema72 = Type76.Object({}, { additionalProperties: false });
3984
+ var NAME69 = "proxmox_list_pools";
3985
+ function createProxmoxListPoolsTool(getClient) {
3986
+ return {
3987
+ name: NAME69,
3988
+ label: "proxmox: list pools",
3989
+ description: "List all resource pools (GET /pools) with their comments. Use proxmox_list_pool_resources for a pool's members. Tier-1 read.",
3990
+ parameters: Schema72,
3991
+ execute: async () => {
3992
+ const pools = await getClient().get("/pools");
3993
+ return jsonToolResult({ count: pools.length, pools });
3994
+ }
3995
+ };
3996
+ }
3997
+
3998
+ // src/tools/proxmox_list_tokens.ts
3999
+ import { Type as Type77 } from "@sinclair/typebox";
4000
+ var USERID_RE = /^[\w.+-]+@[\w.-]+$/;
4001
+ var Schema73 = Type77.Object(
4002
+ { userid: Type77.String({ minLength: 1, description: "User to list API tokens for, e.g. 'root@pam'." }) },
4003
+ { additionalProperties: false }
4004
+ );
4005
+ var NAME70 = "proxmox_list_tokens";
4006
+ function createProxmoxListTokensTool(getClient) {
4007
+ return {
4008
+ name: NAME70,
4009
+ label: "proxmox: list tokens",
4010
+ description: "List API tokens for a user (GET /access/users/{userid}/token). Secrets are never returned by Proxmox after creation. Tier-1 read.",
4011
+ parameters: Schema73,
4012
+ execute: async (_id, raw) => {
4013
+ const args = validateToolArgs(Schema73, raw, NAME70);
4014
+ if (!USERID_RE.test(args.userid)) throw new ToolInputError(`${NAME70}: invalid userid "${args.userid}"`);
4015
+ const tokens = await getClient().get(`/access/users/${encodeURIComponent(args.userid)}/token`);
4016
+ return jsonToolResult({ userid: args.userid, count: tokens.length, tokens });
4017
+ }
4018
+ };
4019
+ }
4020
+
4021
+ // src/tools/proxmox_set_acl.ts
4022
+ import { Type as Type78 } from "@sinclair/typebox";
4023
+ var ACL_PATH_RE = /^\/[\w./-]*$/;
4024
+ var ROLE_RE = /^[A-Za-z][\w.-]*$/;
4025
+ var UGID_RE = /^[\w.+-]+(@[\w.-]+)?(![\w.-]+)?$/;
4026
+ var Schema74 = Type78.Object(
4027
+ {
4028
+ path: Type78.String({ minLength: 1, description: "ACL path, e.g. '/vms/100', '/pool/team', '/storage/local', '/'." }),
4029
+ roles: Type78.String({ minLength: 1, description: "Role name(s), comma-separated, e.g. 'PVEVMAdmin'." }),
4030
+ userid: Type78.Optional(Type78.String({ minLength: 1, description: "User or token to grant, e.g. 'bob@pve' or 'bob@pve!ci'." })),
4031
+ group: Type78.Optional(Type78.String({ minLength: 1, description: "Group to grant." })),
4032
+ propagate: Type78.Optional(Type78.Boolean({ description: "Propagate to child paths (default true)." })),
4033
+ remove: Type78.Optional(Type78.Boolean({ description: "Remove the ACL instead of adding it." })),
4034
+ confirm: Type78.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4035
+ },
4036
+ { additionalProperties: false }
4037
+ );
4038
+ var NAME71 = "proxmox_set_acl";
4039
+ function createProxmoxSetAclTool(getClient) {
4040
+ return {
4041
+ name: NAME71,
4042
+ label: "proxmox: set ACL",
4043
+ description: "Grant or remove a role for a user/token or group on a path (PUT /access/acl). Set remove:true to revoke. Tier-2 write; requires confirm:true.",
4044
+ parameters: Schema74,
4045
+ execute: async (_id, raw) => {
4046
+ assertConfirmedWrite(raw, NAME71);
4047
+ const args = validateToolArgs(Schema74, raw, NAME71);
4048
+ if (!ACL_PATH_RE.test(args.path)) throw new ToolInputError(`${NAME71}: invalid path "${args.path}"`);
4049
+ for (const r of args.roles.split(",")) {
4050
+ if (!ROLE_RE.test(r.trim())) throw new ToolInputError(`${NAME71}: invalid role "${r}"`);
4051
+ }
4052
+ if (!args.userid && !args.group) {
4053
+ throw new ToolInputError(`${NAME71}: provide userid or group.`);
4054
+ }
4055
+ const body = { path: args.path, roles: args.roles };
4056
+ if (args.userid) {
4057
+ if (!UGID_RE.test(args.userid)) throw new ToolInputError(`${NAME71}: invalid userid "${args.userid}"`);
4058
+ if (args.userid.includes("!")) body.tokens = args.userid;
4059
+ else body.users = args.userid;
4060
+ }
4061
+ if (args.group) body.groups = args.group;
4062
+ body.propagate = args.propagate === false ? 0 : 1;
4063
+ if (args.remove === true) body.delete = 1;
4064
+ await getClient().put(`/access/acl`, body);
4065
+ return jsonToolResult({
4066
+ path: args.path,
4067
+ roles: args.roles,
4068
+ userid: args.userid,
4069
+ group: args.group,
4070
+ removed: args.remove === true
4071
+ });
4072
+ }
4073
+ };
4074
+ }
4075
+
4076
+ // src/tools/proxmox_create_token.ts
4077
+ import { Type as Type79 } from "@sinclair/typebox";
4078
+ var TOKENID_RE = /^[\w.-]+$/;
4079
+ var Schema75 = Type79.Object(
4080
+ {
4081
+ userid: Type79.String({ minLength: 1, description: "Owning user, e.g. 'automation@pve'." }),
4082
+ tokenid: Type79.String({ minLength: 1, description: "New token name (the part after '!')." }),
4083
+ comment: Type79.Optional(Type79.String({ description: "Token comment." })),
4084
+ privsep: Type79.Optional(
4085
+ Type79.Boolean({ description: "Privilege separation (default true): the token gets only ACLs granted to it directly." })
4086
+ ),
4087
+ expire: Type79.Optional(Type79.Integer({ minimum: 0, description: "Expiry as a Unix timestamp (0 = never)." })),
4088
+ confirm: Type79.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4089
+ },
4090
+ { additionalProperties: false }
4091
+ );
4092
+ var NAME72 = "proxmox_create_token";
4093
+ function createProxmoxCreateTokenTool(getClient) {
4094
+ return {
4095
+ name: NAME72,
4096
+ label: "proxmox: create token",
4097
+ description: "Create an API token for a user (POST /access/users/{userid}/token/{tokenid}). Returns the secret ONCE - it cannot be retrieved later. With privsep (default), grant it access separately via proxmox_set_acl. Tier-2 write; requires confirm:true.",
4098
+ parameters: Schema75,
4099
+ execute: async (_id, raw) => {
4100
+ assertConfirmedWrite(raw, NAME72);
4101
+ const args = validateToolArgs(Schema75, raw, NAME72);
4102
+ if (!USERID_RE.test(args.userid)) throw new ToolInputError(`${NAME72}: invalid userid "${args.userid}"`);
4103
+ if (!TOKENID_RE.test(args.tokenid)) throw new ToolInputError(`${NAME72}: invalid tokenid "${args.tokenid}"`);
4104
+ const body = { privsep: args.privsep === false ? 0 : 1 };
4105
+ if (typeof args.comment === "string" && args.comment.length > 0) body.comment = args.comment;
4106
+ if (typeof args.expire === "number") body.expire = args.expire;
4107
+ const res = await getClient().post(
4108
+ `/access/users/${encodeURIComponent(args.userid)}/token/${encodeURIComponent(args.tokenid)}`,
4109
+ body
4110
+ );
4111
+ return jsonToolResult({
4112
+ userid: args.userid,
4113
+ tokenid: args.tokenid,
4114
+ full_tokenid: res?.["full-tokenid"] ?? `${args.userid}!${args.tokenid}`,
4115
+ secret: res?.value ?? null,
4116
+ note: "Store the secret now; Proxmox will not show it again."
4117
+ });
4118
+ }
4119
+ };
4120
+ }
4121
+
4122
+ // src/tools/proxmox_delete_token.ts
4123
+ import { Type as Type80 } from "@sinclair/typebox";
4124
+ var TOKENID_RE2 = /^[\w.-]+$/;
4125
+ var Schema76 = Type80.Object(
4126
+ {
4127
+ userid: Type80.String({ minLength: 1, description: "Owning user, e.g. 'automation@pve'." }),
4128
+ tokenid: Type80.String({ minLength: 1, description: "Token name to revoke (the part after '!')." }),
4129
+ confirm: Type80.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4130
+ },
4131
+ { additionalProperties: false }
4132
+ );
4133
+ var NAME73 = "proxmox_delete_token";
4134
+ function createProxmoxDeleteTokenTool(getClient) {
4135
+ return {
4136
+ name: NAME73,
4137
+ label: "proxmox: delete token",
4138
+ description: "Revoke an API token (DELETE /access/users/{userid}/token/{tokenid}). Immediately invalidates the token. Tier-2 write; requires confirm:true.",
4139
+ parameters: Schema76,
4140
+ execute: async (_id, raw) => {
4141
+ assertConfirmedWrite(raw, NAME73);
4142
+ const args = validateToolArgs(Schema76, raw, NAME73);
4143
+ if (!USERID_RE.test(args.userid)) throw new ToolInputError(`${NAME73}: invalid userid "${args.userid}"`);
4144
+ if (!TOKENID_RE2.test(args.tokenid)) throw new ToolInputError(`${NAME73}: invalid tokenid "${args.tokenid}"`);
4145
+ await getClient().delete(
4146
+ `/access/users/${encodeURIComponent(args.userid)}/token/${encodeURIComponent(args.tokenid)}`
4147
+ );
4148
+ return jsonToolResult({ userid: args.userid, tokenid: args.tokenid, deleted: true });
4149
+ }
4150
+ };
4151
+ }
4152
+
4153
+ // src/tools/proxmox_create_pool.ts
4154
+ import { Type as Type81 } from "@sinclair/typebox";
4155
+ var Schema77 = Type81.Object(
4156
+ {
4157
+ poolid: Type81.String({ minLength: 1, description: "New pool ID." }),
4158
+ comment: Type81.Optional(Type81.String({ description: "Pool comment/description." })),
4159
+ confirm: Type81.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4160
+ },
4161
+ { additionalProperties: false }
4162
+ );
4163
+ var NAME74 = "proxmox_create_pool";
4164
+ function createProxmoxCreatePoolTool(getClient) {
4165
+ return {
4166
+ name: NAME74,
4167
+ label: "proxmox: create pool",
4168
+ description: "Create a resource pool (POST /pools). Add guests/storage to it with proxmox_update_pool. Tier-2 write; requires confirm:true.",
4169
+ parameters: Schema77,
4170
+ execute: async (_id, raw) => {
4171
+ assertConfirmedWrite(raw, NAME74);
4172
+ const args = validateToolArgs(Schema77, raw, NAME74);
4173
+ assertSafePathSegment(args.poolid, "poolid");
4174
+ const body = { poolid: args.poolid };
4175
+ if (typeof args.comment === "string" && args.comment.length > 0) body.comment = args.comment;
4176
+ await getClient().post(`/pools`, body);
4177
+ return jsonToolResult({ poolid: args.poolid, created: true });
4178
+ }
4179
+ };
4180
+ }
4181
+
4182
+ // src/tools/proxmox_update_pool.ts
4183
+ import { Type as Type82 } from "@sinclair/typebox";
4184
+ var VMID_LIST_RE = /^\d+(,\d+)*$/;
4185
+ var Schema78 = Type82.Object(
4186
+ {
4187
+ poolid: Type82.String({ minLength: 1, description: "Pool to modify." }),
4188
+ vms: Type82.Optional(Type82.String({ minLength: 1, description: "Comma-separated VMIDs to add (or remove with remove:true)." })),
4189
+ storage: Type82.Optional(Type82.String({ minLength: 1, description: "Comma-separated storage IDs to add/remove." })),
4190
+ comment: Type82.Optional(Type82.String({ description: "Update the pool comment." })),
4191
+ remove: Type82.Optional(Type82.Boolean({ description: "Remove the listed members instead of adding them." })),
4192
+ confirm: Type82.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4193
+ },
4194
+ { additionalProperties: false }
4195
+ );
4196
+ var NAME75 = "proxmox_update_pool";
4197
+ function createProxmoxUpdatePoolTool(getClient) {
4198
+ return {
4199
+ name: NAME75,
4200
+ label: "proxmox: update pool",
4201
+ description: "Add or remove guests/storage in a resource pool, or update its comment (PUT /pools/{poolid}). Set remove:true to detach the listed members. Tier-2 write; requires confirm:true.",
4202
+ parameters: Schema78,
4203
+ execute: async (_id, raw) => {
4204
+ assertConfirmedWrite(raw, NAME75);
4205
+ const args = validateToolArgs(Schema78, raw, NAME75);
4206
+ assertSafePathSegment(args.poolid, "poolid");
4207
+ if (args.vms && !VMID_LIST_RE.test(args.vms)) {
4208
+ throw new ToolInputError(`${NAME75}: vms must be a comma-separated list of numeric VMIDs`);
4209
+ }
4210
+ if (!args.vms && !args.storage && typeof args.comment !== "string") {
4211
+ throw new ToolInputError(`${NAME75}: provide vms, storage, or comment to change.`);
4212
+ }
4213
+ const body = {};
4214
+ if (args.vms) body.vms = args.vms;
4215
+ if (args.storage) body.storage = args.storage;
4216
+ if (typeof args.comment === "string") body.comment = args.comment;
4217
+ if (args.remove === true) body.delete = 1;
4218
+ await getClient().put(`/pools/${args.poolid}`, body);
4219
+ return jsonToolResult({
4220
+ poolid: args.poolid,
4221
+ vms: args.vms,
4222
+ storage: args.storage,
4223
+ removed: args.remove === true
4224
+ });
4225
+ }
4226
+ };
4227
+ }
4228
+
4229
+ // src/tools/proxmox_delete_pool.ts
4230
+ import { Type as Type83 } from "@sinclair/typebox";
4231
+ var Schema79 = Type83.Object(
4232
+ {
4233
+ poolid: Type83.String({ minLength: 1, description: "Pool to delete (must be empty)." }),
4234
+ confirm: Type83.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4235
+ },
4236
+ { additionalProperties: false }
4237
+ );
4238
+ var NAME76 = "proxmox_delete_pool";
4239
+ function createProxmoxDeletePoolTool(getClient) {
4240
+ return {
4241
+ name: NAME76,
4242
+ label: "proxmox: delete pool",
4243
+ description: "Delete a resource pool (DELETE /pools/{poolid}). Proxmox requires the pool to be empty first; guests/storage are not deleted, only the grouping. Tier-2 write; requires confirm:true.",
4244
+ parameters: Schema79,
4245
+ execute: async (_id, raw) => {
4246
+ assertConfirmedWrite(raw, NAME76);
4247
+ const args = validateToolArgs(Schema79, raw, NAME76);
4248
+ assertSafePathSegment(args.poolid, "poolid");
4249
+ await getClient().delete(`/pools/${args.poolid}`);
4250
+ return jsonToolResult({ poolid: args.poolid, deleted: true });
4251
+ }
4252
+ };
4253
+ }
4254
+
4255
+ // src/tools/proxmox_cluster_status.ts
4256
+ import { Type as Type84 } from "@sinclair/typebox";
4257
+ var Schema80 = Type84.Object({}, { additionalProperties: false });
4258
+ var NAME77 = "proxmox_cluster_status";
4259
+ function createProxmoxClusterStatusTool(getClient) {
4260
+ return {
4261
+ name: NAME77,
4262
+ label: "proxmox: cluster status",
4263
+ description: "Cluster membership + quorum: each node's id, IP, online state, and (on a cluster) the quorate flag. (GET /cluster/status). Tier-1 read.",
4264
+ parameters: Schema80,
4265
+ execute: async () => {
4266
+ const items = await getClient().get("/cluster/status");
4267
+ const list = Array.isArray(items) ? items : [items];
4268
+ return jsonToolResult({ count: list.length, nodes: list });
4269
+ }
4270
+ };
4271
+ }
4272
+
4273
+ // src/tools/proxmox_ha_status.ts
4274
+ import { Type as Type85 } from "@sinclair/typebox";
4275
+ var Schema81 = Type85.Object({}, { additionalProperties: false });
4276
+ var NAME78 = "proxmox_ha_status";
4277
+ function createProxmoxHaStatusTool(getClient) {
4278
+ return {
4279
+ name: NAME78,
4280
+ label: "proxmox: HA status",
4281
+ description: "Current HA manager status: quorum, fencing/CRM state, and per-resource HA state. (GET /cluster/ha/status/current). Tier-1 read.",
4282
+ parameters: Schema81,
4283
+ execute: async () => {
4284
+ const items = await getClient().get("/cluster/ha/status/current");
4285
+ const list = Array.isArray(items) ? items : [items];
4286
+ return jsonToolResult({ count: list.length, entries: list });
4287
+ }
4288
+ };
4289
+ }
4290
+
4291
+ // src/tools/proxmox_list_ha_resources.ts
4292
+ import { Type as Type86 } from "@sinclair/typebox";
4293
+ var Schema82 = Type86.Object({}, { additionalProperties: false });
4294
+ var NAME79 = "proxmox_list_ha_resources";
4295
+ function createProxmoxListHaResourcesTool(getClient) {
4296
+ return {
4297
+ name: NAME79,
4298
+ label: "proxmox: list HA resources",
4299
+ description: "HA-managed resources (sid, state, group/comment). (GET /cluster/ha/resources). Tier-1 read.",
4300
+ parameters: Schema82,
4301
+ execute: async () => {
4302
+ const items = await getClient().get("/cluster/ha/resources");
4303
+ const list = Array.isArray(items) ? items : [items];
4304
+ return jsonToolResult({ count: list.length, resources: list });
4305
+ }
4306
+ };
4307
+ }
4308
+
4309
+ // src/tools/proxmox_list_ha_rules.ts
4310
+ import { Type as Type87 } from "@sinclair/typebox";
4311
+ var Schema83 = Type87.Object({}, { additionalProperties: false });
4312
+ var NAME80 = "proxmox_list_ha_rules";
4313
+ function createProxmoxListHaRulesTool(getClient) {
4314
+ return {
4315
+ name: NAME80,
4316
+ label: "proxmox: list HA rules",
4317
+ description: "HA rules (PVE 9+ replacement for HA groups): node affinity and resource placement. (GET /cluster/ha/rules). Tier-1 read.",
4318
+ parameters: Schema83,
4319
+ execute: async () => {
4320
+ const items = await getClient().get("/cluster/ha/rules");
4321
+ const list = Array.isArray(items) ? items : [items];
4322
+ return jsonToolResult({ count: list.length, rules: list });
4323
+ }
4324
+ };
4325
+ }
4326
+
4327
+ // src/tools/proxmox_list_replication.ts
4328
+ import { Type as Type88 } from "@sinclair/typebox";
4329
+ var Schema84 = Type88.Object({}, { additionalProperties: false });
4330
+ var NAME81 = "proxmox_list_replication";
4331
+ function createProxmoxListReplicationTool(getClient) {
4332
+ return {
4333
+ name: NAME81,
4334
+ label: "proxmox: list replication",
4335
+ description: "Storage replication jobs (id, source guest, target node, schedule). (GET /cluster/replication). Tier-1 read.",
4336
+ parameters: Schema84,
4337
+ execute: async () => {
4338
+ const items = await getClient().get("/cluster/replication");
4339
+ const list = Array.isArray(items) ? items : [items];
4340
+ return jsonToolResult({ count: list.length, jobs: list });
4341
+ }
4342
+ };
4343
+ }
4344
+
4345
+ // src/tools/proxmox_list_sdn_zones.ts
4346
+ import { Type as Type89 } from "@sinclair/typebox";
4347
+ var Schema85 = Type89.Object({}, { additionalProperties: false });
4348
+ var NAME82 = "proxmox_list_sdn_zones";
4349
+ function createProxmoxListSdnZonesTool(getClient) {
4350
+ return {
4351
+ name: NAME82,
4352
+ label: "proxmox: list SDN zones",
4353
+ description: "Software-defined-networking zones. (GET /cluster/sdn/zones). Tier-1 read.",
4354
+ parameters: Schema85,
4355
+ execute: async () => {
4356
+ const items = await getClient().get("/cluster/sdn/zones");
4357
+ const list = Array.isArray(items) ? items : [items];
4358
+ return jsonToolResult({ count: list.length, zones: list });
4359
+ }
4360
+ };
4361
+ }
4362
+
4363
+ // src/tools/proxmox_list_sdn_vnets.ts
4364
+ import { Type as Type90 } from "@sinclair/typebox";
4365
+ var Schema86 = Type90.Object({}, { additionalProperties: false });
4366
+ var NAME83 = "proxmox_list_sdn_vnets";
4367
+ function createProxmoxListSdnVnetsTool(getClient) {
4368
+ return {
4369
+ name: NAME83,
4370
+ label: "proxmox: list SDN vnets",
4371
+ description: "Software-defined-networking virtual networks. (GET /cluster/sdn/vnets). Tier-1 read.",
4372
+ parameters: Schema86,
4373
+ execute: async () => {
4374
+ const items = await getClient().get("/cluster/sdn/vnets");
4375
+ const list = Array.isArray(items) ? items : [items];
4376
+ return jsonToolResult({ count: list.length, vnets: list });
4377
+ }
4378
+ };
4379
+ }
4380
+
4381
+ // src/tools/proxmox_list_metric_servers.ts
4382
+ import { Type as Type91 } from "@sinclair/typebox";
4383
+ var Schema87 = Type91.Object({}, { additionalProperties: false });
4384
+ var NAME84 = "proxmox_list_metric_servers";
4385
+ function createProxmoxListMetricServersTool(getClient) {
4386
+ return {
4387
+ name: NAME84,
4388
+ label: "proxmox: list metric servers",
4389
+ description: "External metrics servers (InfluxDB/Graphite) configured for the cluster. (GET /cluster/metrics/server). Tier-1 read.",
4390
+ parameters: Schema87,
4391
+ execute: async () => {
4392
+ const items = await getClient().get("/cluster/metrics/server");
4393
+ const list = Array.isArray(items) ? items : [items];
4394
+ return jsonToolResult({ count: list.length, servers: list });
4395
+ }
4396
+ };
4397
+ }
4398
+
4399
+ // src/tools/proxmox_get_cluster_options.ts
4400
+ import { Type as Type92 } from "@sinclair/typebox";
4401
+ var Schema88 = Type92.Object({}, { additionalProperties: false });
4402
+ var NAME85 = "proxmox_get_cluster_options";
4403
+ function createProxmoxGetClusterOptionsTool(getClient) {
4404
+ return {
4405
+ name: NAME85,
4406
+ label: "proxmox: get cluster options",
4407
+ description: "Read datacenter-wide options (GET /cluster/options): keyboard, MAC prefix, allowed tags, default migration settings, etc. Tier-1 read.",
4408
+ parameters: Schema88,
4409
+ execute: async () => {
4410
+ const options = await getClient().get("/cluster/options");
4411
+ return jsonToolResult({ options });
4412
+ }
4413
+ };
4414
+ }
4415
+
4416
+ // src/tools/proxmox_cluster_log.ts
4417
+ import { Type as Type93 } from "@sinclair/typebox";
4418
+ var Schema89 = Type93.Object(
4419
+ {
4420
+ max: Type93.Optional(
4421
+ Type93.Integer({ minimum: 1, maximum: 1e3, description: "Max number of recent log entries (default 50)." })
4422
+ )
4423
+ },
4424
+ { additionalProperties: false }
4425
+ );
4426
+ var NAME86 = "proxmox_cluster_log";
4427
+ function createProxmoxClusterLogTool(getClient) {
4428
+ return {
4429
+ name: NAME86,
4430
+ label: "proxmox: cluster log",
4431
+ description: "Read the recent cluster-wide log (GET /cluster/log): task start/end, auth, and daemon messages across all nodes. Tier-1 read.",
4432
+ parameters: Schema89,
4433
+ execute: async (_id, raw) => {
4434
+ const args = validateToolArgs(Schema89, raw, NAME86);
4435
+ const max = args.max ?? 50;
4436
+ const entries = await getClient().get(`/cluster/log?max=${max}`);
4437
+ return jsonToolResult({ count: Array.isArray(entries) ? entries.length : 0, entries });
4438
+ }
4439
+ };
4440
+ }
4441
+
4442
+ // src/tools/proxmox_add_ha_resource.ts
4443
+ import { Type as Type94 } from "@sinclair/typebox";
4444
+ var SID_RE = /^(vm|ct):\d+$/;
4445
+ var Schema90 = Type94.Object(
4446
+ {
4447
+ sid: Type94.String({ minLength: 1, description: "HA resource id, 'vm:<vmid>' or 'ct:<vmid>'." }),
4448
+ state: Type94.Optional(
4449
+ Type94.Union(
4450
+ [Type94.Literal("started"), Type94.Literal("stopped"), Type94.Literal("disabled"), Type94.Literal("ignored")],
4451
+ { description: "Requested HA state (default 'started')." }
4452
+ )
4453
+ ),
4454
+ comment: Type94.Optional(Type94.String({ description: "Comment." })),
4455
+ max_restart: Type94.Optional(Type94.Integer({ minimum: 0, description: "Max restart attempts on the same node." })),
4456
+ max_relocate: Type94.Optional(Type94.Integer({ minimum: 0, description: "Max relocation attempts to other nodes." })),
4457
+ confirm: Type94.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4458
+ },
4459
+ { additionalProperties: false }
4460
+ );
4461
+ var NAME87 = "proxmox_add_ha_resource";
4462
+ function createProxmoxAddHaResourceTool(getClient) {
4463
+ return {
4464
+ name: NAME87,
4465
+ label: "proxmox: add HA resource",
4466
+ description: "Place a VM or container under HA management (POST /cluster/ha/resources). Only meaningful on a quorate multi-node cluster. Tier-2 write; requires confirm:true.",
4467
+ parameters: Schema90,
4468
+ execute: async (_id, raw) => {
4469
+ assertConfirmedWrite(raw, NAME87);
4470
+ const args = validateToolArgs(Schema90, raw, NAME87);
4471
+ if (!SID_RE.test(args.sid)) throw new ToolInputError(`${NAME87}: sid must be 'vm:<vmid>' or 'ct:<vmid>'`);
4472
+ const body = { sid: args.sid, state: args.state ?? "started" };
4473
+ if (typeof args.comment === "string" && args.comment.length > 0) body.comment = args.comment;
4474
+ if (typeof args.max_restart === "number") body.max_restart = args.max_restart;
4475
+ if (typeof args.max_relocate === "number") body.max_relocate = args.max_relocate;
4476
+ await getClient().post(`/cluster/ha/resources`, body);
4477
+ return jsonToolResult({ sid: args.sid, state: args.state ?? "started", added: true });
4478
+ }
4479
+ };
4480
+ }
4481
+
4482
+ // src/tools/proxmox_delete_ha_resource.ts
4483
+ import { Type as Type95 } from "@sinclair/typebox";
4484
+ var SID_RE2 = /^(vm|ct):\d+$/;
4485
+ var Schema91 = Type95.Object(
4486
+ {
4487
+ sid: Type95.String({ minLength: 1, description: "HA resource id to remove, 'vm:<vmid>' or 'ct:<vmid>'." }),
4488
+ confirm: Type95.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4489
+ },
4490
+ { additionalProperties: false }
4491
+ );
4492
+ var NAME88 = "proxmox_delete_ha_resource";
4493
+ function createProxmoxDeleteHaResourceTool(getClient) {
4494
+ return {
4495
+ name: NAME88,
4496
+ label: "proxmox: delete HA resource",
4497
+ description: "Remove a VM or container from HA management (DELETE /cluster/ha/resources/{sid}). The guest keeps running; only HA management stops. Tier-2 write; requires confirm:true.",
4498
+ parameters: Schema91,
4499
+ execute: async (_id, raw) => {
4500
+ assertConfirmedWrite(raw, NAME88);
4501
+ const args = validateToolArgs(Schema91, raw, NAME88);
4502
+ if (!SID_RE2.test(args.sid)) throw new ToolInputError(`${NAME88}: sid must be 'vm:<vmid>' or 'ct:<vmid>'`);
4503
+ await getClient().delete(`/cluster/ha/resources/${encodeURIComponent(args.sid)}`);
4504
+ return jsonToolResult({ sid: args.sid, deleted: true });
4505
+ }
4506
+ };
4507
+ }
4508
+
4509
+ // src/tools/proxmox_create_replication.ts
4510
+ import { Type as Type96 } from "@sinclair/typebox";
4511
+ var Schema92 = Type96.Object(
4512
+ {
4513
+ vmid: Type96.Integer({ minimum: 1, description: "Guest to replicate." }),
4514
+ target: Type96.String({ minLength: 1, description: "Target node to replicate to (must differ from the source node)." }),
4515
+ job_number: Type96.Optional(Type96.Integer({ minimum: 0, description: "Job number, forming the id '<vmid>-<n>' (default 0)." })),
4516
+ schedule: Type96.Optional(Type96.String({ minLength: 1, description: "Replication schedule, e.g. '*/15' or '02:00' (default '*/15')." })),
4517
+ rate: Type96.Optional(Type96.Number({ minimum: 0, description: "Rate limit in MB/s (0 = unlimited)." })),
4518
+ comment: Type96.Optional(Type96.String({ description: "Comment." })),
4519
+ disable: Type96.Optional(Type96.Boolean({ description: "Create the job disabled." })),
4520
+ confirm: Type96.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4521
+ },
4522
+ { additionalProperties: false }
4523
+ );
4524
+ var NAME89 = "proxmox_create_replication";
4525
+ function createProxmoxCreateReplicationTool(getClient) {
4526
+ return {
4527
+ name: NAME89,
4528
+ label: "proxmox: create replication",
4529
+ description: "Create a storage replication job for a guest to another node (POST /cluster/replication). Requires a multi-node cluster with a different target node. Tier-2 write; requires confirm:true.",
4530
+ parameters: Schema92,
4531
+ execute: async (_id, raw) => {
4532
+ assertConfirmedWrite(raw, NAME89);
4533
+ const args = validateToolArgs(Schema92, raw, NAME89);
4534
+ assertSafePathSegment(args.target, "target");
4535
+ const client = getClient();
4536
+ const { node } = await resolveResource(client, args.vmid);
4537
+ if (args.target === node) {
4538
+ throw new Error(`replication target ${args.target} must differ from the guest's node ${node}.`);
4539
+ }
4540
+ const id = `${args.vmid}-${args.job_number ?? 0}`;
4541
+ const body = {
4542
+ id,
4543
+ type: "local",
4544
+ target: args.target,
4545
+ schedule: args.schedule ?? "*/15"
4546
+ };
4547
+ if (typeof args.rate === "number") body.rate = args.rate;
4548
+ if (typeof args.comment === "string" && args.comment.length > 0) body.comment = args.comment;
4549
+ if (args.disable) body.disable = 1;
4550
+ await client.post(`/cluster/replication`, body);
4551
+ return jsonToolResult({ id, vmid: args.vmid, node, target: args.target, created: true });
4552
+ }
4553
+ };
4554
+ }
4555
+
4556
+ // src/tools/proxmox_delete_replication.ts
4557
+ import { Type as Type97 } from "@sinclair/typebox";
4558
+ var REPL_ID_RE = /^\d+-\d+$/;
4559
+ var Schema93 = Type97.Object(
4560
+ {
4561
+ id: Type97.String({ minLength: 1, description: "Replication job id, '<vmid>-<n>' (from proxmox_list_replication)." }),
4562
+ force: Type97.Optional(Type97.Boolean({ description: "Force removal even if the target is unreachable." })),
4563
+ confirm: Type97.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4564
+ },
4565
+ { additionalProperties: false }
4566
+ );
4567
+ var NAME90 = "proxmox_delete_replication";
4568
+ function createProxmoxDeleteReplicationTool(getClient) {
4569
+ return {
4570
+ name: NAME90,
4571
+ label: "proxmox: delete replication",
4572
+ description: "Delete a storage replication job (DELETE /cluster/replication/{id}). Tier-2 write; requires confirm:true.",
4573
+ parameters: Schema93,
4574
+ execute: async (_id, raw) => {
4575
+ assertConfirmedWrite(raw, NAME90);
4576
+ const args = validateToolArgs(Schema93, raw, NAME90);
4577
+ if (!REPL_ID_RE.test(args.id)) throw new ToolInputError(`${NAME90}: id must be '<vmid>-<n>'`);
4578
+ const qs = args.force ? "?force=1" : "";
4579
+ await getClient().delete(`/cluster/replication/${args.id}${qs}`);
4580
+ return jsonToolResult({ id: args.id, deleted: true });
4581
+ }
4582
+ };
4583
+ }
4584
+
4585
+ // src/errors.ts
4586
+ function classifyToolError(error) {
4587
+ const err = error instanceof Error ? error : new Error(String(error));
4588
+ if (err instanceof ToolInputError) {
4589
+ return { error: err.message, code: "TOOL_INPUT_INVALID", name: err.name };
4590
+ }
4591
+ if (err instanceof WriteGateError) {
4592
+ const code = err.message.includes("requires env flag") ? "DESTRUCTIVE_ENV_REQUIRED" : err.message.includes("destructive operation") ? "DESTRUCTIVE_CONFIRMATION_REQUIRED" : "WRITE_CONFIRMATION_REQUIRED";
4593
+ return { error: err.message, code, name: err.name };
4594
+ }
4595
+ if (err instanceof ProxmoxClientError) {
4596
+ return { error: err.message, code: `PROXMOX_HTTP_${err.status}`, name: err.name, status: err.status };
4597
+ }
4598
+ if (err instanceof ProxmoxUnreachableError) {
4599
+ return { error: err.message, code: "PROXMOX_UNREACHABLE", name: err.name };
4600
+ }
4601
+ if (err instanceof SshExecError) {
4602
+ return { error: err.message, code: `SSH_${err.phase.toUpperCase()}_FAILED`, name: err.name };
4603
+ }
4604
+ if (/vmid \d+ not found in cluster resources/.test(err.message)) {
4605
+ return { error: err.message, code: "VMID_NOT_FOUND", name: err.name };
4606
+ }
4607
+ if (/invalid UPID format/.test(err.message)) {
4608
+ return { error: err.message, code: "TASK_UPID_INVALID", name: err.name };
4609
+ }
4610
+ if (/task did not finish OK/i.test(err.message) || /task failed/i.test(err.message)) {
4611
+ return { error: err.message, code: "TASK_FAILED", name: err.name };
2606
4612
  }
2607
4613
  return { error: err.message, code: "TOOL_ERROR", name: err.name };
2608
4614
  }
2609
4615
 
2610
- // mcp-server.ts
2611
- import { realpathSync } from "fs";
2612
- import { pathToFileURL } from "url";
2613
- async function startServer() {
2614
- const cfg = resolveConfig(process.env);
4616
+ // src/registry.ts
4617
+ var TOOL_TIERS = {
4618
+ "proxmox_add_firewall_rule": "safe-write",
4619
+ "proxmox_add_ha_resource": "safe-write",
4620
+ "proxmox_audit_permissions": "read",
4621
+ "proxmox_cancel_task": "safe-write",
4622
+ "proxmox_cleanup_smoke_resources": "destructive",
4623
+ "proxmox_clone_resource": "safe-write",
4624
+ "proxmox_cluster_log": "read",
4625
+ "proxmox_cluster_status": "read",
4626
+ "proxmox_convert_to_template": "safe-write",
4627
+ "proxmox_create_backup_job": "safe-write",
4628
+ "proxmox_create_container": "safe-write",
4629
+ "proxmox_create_pool": "safe-write",
4630
+ "proxmox_create_replication": "safe-write",
4631
+ "proxmox_create_storage": "safe-write",
4632
+ "proxmox_create_token": "safe-write",
4633
+ "proxmox_create_vm": "safe-write",
4634
+ "proxmox_delete_backup_job": "safe-write",
4635
+ "proxmox_delete_firewall_rule": "safe-write",
4636
+ "proxmox_delete_ha_resource": "safe-write",
4637
+ "proxmox_delete_pool": "safe-write",
4638
+ "proxmox_delete_replication": "safe-write",
4639
+ "proxmox_delete_snapshot": "destructive",
4640
+ "proxmox_delete_storage": "destructive",
4641
+ "proxmox_delete_token": "safe-write",
4642
+ "proxmox_delete_volume": "destructive",
4643
+ "proxmox_destroy_resource": "destructive",
4644
+ "proxmox_download_url": "safe-write",
4645
+ "proxmox_exec": "safe-write",
4646
+ "proxmox_force_stop_resource": "destructive",
4647
+ "proxmox_get_cluster_options": "read",
4648
+ "proxmox_get_container_config": "read",
4649
+ "proxmox_get_firewall_options": "read",
4650
+ "proxmox_get_resource": "read",
4651
+ "proxmox_get_task_log": "read",
4652
+ "proxmox_get_task_status": "read",
4653
+ "proxmox_get_vm_config": "read",
4654
+ "proxmox_guest_network": "read",
4655
+ "proxmox_ha_status": "read",
4656
+ "proxmox_list_acl": "read",
4657
+ "proxmox_list_backup_jobs": "read",
4658
+ "proxmox_list_backups": "read",
4659
+ "proxmox_list_containers": "read",
4660
+ "proxmox_list_directory": "safe-write",
4661
+ "proxmox_list_disks": "read",
4662
+ "proxmox_list_firewall_rules": "read",
4663
+ "proxmox_list_ha_resources": "read",
4664
+ "proxmox_list_ha_rules": "read",
4665
+ "proxmox_list_metric_servers": "read",
4666
+ "proxmox_list_node_services": "read",
4667
+ "proxmox_list_pool_resources": "read",
4668
+ "proxmox_list_pools": "read",
4669
+ "proxmox_list_replication": "read",
4670
+ "proxmox_list_roles": "read",
4671
+ "proxmox_list_sdn_vnets": "read",
4672
+ "proxmox_list_sdn_zones": "read",
4673
+ "proxmox_list_snapshots": "read",
4674
+ "proxmox_list_storage_config": "read",
4675
+ "proxmox_list_storage_content": "read",
4676
+ "proxmox_list_storage": "read",
4677
+ "proxmox_list_templates": "read",
4678
+ "proxmox_list_tokens": "read",
4679
+ "proxmox_list_updates": "read",
4680
+ "proxmox_list_users": "read",
4681
+ "proxmox_list_vms": "read",
4682
+ "proxmox_migrate_resource": "safe-write",
4683
+ "proxmox_move_disk": "safe-write",
4684
+ "proxmox_next_vmid": "read",
4685
+ "proxmox_node_power": "destructive",
4686
+ "proxmox_read_file": "safe-write",
4687
+ "proxmox_reboot_resource": "safe-write",
4688
+ "proxmox_recent_tasks": "read",
4689
+ "proxmox_reset_resource": "safe-write",
4690
+ "proxmox_resize_disk": "safe-write",
4691
+ "proxmox_resource_usage": "read",
4692
+ "proxmox_restore_backup": "destructive",
4693
+ "proxmox_resume_resource": "safe-write",
4694
+ "proxmox_rollback_snapshot": "destructive",
4695
+ "proxmox_run_backup": "safe-write",
4696
+ "proxmox_service_restart": "safe-write",
4697
+ "proxmox_service_start": "safe-write",
4698
+ "proxmox_service_status": "safe-write",
4699
+ "proxmox_service_stop": "safe-write",
4700
+ "proxmox_set_acl": "safe-write",
4701
+ "proxmox_set_firewall_enabled": "safe-write",
4702
+ "proxmox_snapshot_resource": "safe-write",
4703
+ "proxmox_start_resource": "safe-write",
4704
+ "proxmox_stat_path": "safe-write",
4705
+ "proxmox_status": "read",
4706
+ "proxmox_stop_resource": "safe-write",
4707
+ "proxmox_suspend_resource": "safe-write",
4708
+ "proxmox_update_container_config": "safe-write",
4709
+ "proxmox_update_pool": "safe-write",
4710
+ "proxmox_update_vm_config": "safe-write",
4711
+ "proxmox_validate_qemu_smoke_source": "read",
4712
+ "proxmox_wait_task": "read",
4713
+ "proxmox_write_file": "safe-write"
4714
+ };
4715
+ function annotationsForTier(tier) {
4716
+ switch (tier) {
4717
+ case "read":
4718
+ return { readOnlyHint: true };
4719
+ case "safe-write":
4720
+ return { readOnlyHint: false, destructiveHint: false };
4721
+ case "destructive":
4722
+ return { readOnlyHint: false, destructiveHint: true };
4723
+ }
4724
+ }
4725
+ function tierForTool(name) {
4726
+ const tier = TOOL_TIERS[name];
4727
+ if (tier === void 0) {
4728
+ throw new Error(`registry: no access tier declared for tool "${name}"`);
4729
+ }
4730
+ return tier;
4731
+ }
4732
+
4733
+ // src/search.ts
4734
+ var DOMAINS = [
4735
+ "resources",
4736
+ "storage",
4737
+ "backups",
4738
+ "firewall",
4739
+ "identity",
4740
+ "cluster",
4741
+ "ha",
4742
+ "guest-ops"
4743
+ ];
4744
+ var STOPWORDS = /* @__PURE__ */ new Set([
4745
+ "the",
4746
+ "a",
4747
+ "an",
4748
+ "of",
4749
+ "on",
4750
+ "in",
4751
+ "to",
4752
+ "and",
4753
+ "or",
4754
+ "for",
4755
+ "with",
4756
+ "me",
4757
+ "my",
4758
+ "is",
4759
+ "are",
4760
+ "it",
4761
+ "its",
4762
+ "that",
4763
+ "this",
4764
+ "at",
4765
+ "by",
4766
+ "from",
4767
+ "into",
4768
+ "then",
4769
+ "please",
4770
+ "all",
4771
+ "any",
4772
+ "some",
4773
+ "which",
4774
+ "what",
4775
+ "where",
4776
+ "how",
4777
+ "do",
4778
+ "does"
4779
+ ]);
4780
+ function tokenize(text) {
4781
+ return text.toLowerCase().split(/[^a-z0-9]+/).filter((t) => t.length > 1 && !STOPWORDS.has(t));
4782
+ }
4783
+ var stem = (name) => name.replace(/^proxmox_/, "");
4784
+ function buildIdf(index) {
4785
+ const n = index.length;
4786
+ const df = /* @__PURE__ */ new Map();
4787
+ for (const rec of index) {
4788
+ const terms = /* @__PURE__ */ new Set([
4789
+ ...tokenize(stem(rec.name)),
4790
+ ...rec.keywords.flatMap((k) => tokenize(k)),
4791
+ ...tokenize(rec.description)
4792
+ ]);
4793
+ for (const t of terms) df.set(t, (df.get(t) ?? 0) + 1);
4794
+ }
4795
+ return (term) => Math.max(1, Math.log((n + 1) / ((df.get(term) ?? 0) + 0.5)));
4796
+ }
4797
+ function scoreRecord(queryTerms, rec, idf) {
4798
+ if (queryTerms.length === 0) return 0;
4799
+ const keywordSet = new Set(rec.keywords.map((k) => k.toLowerCase()));
4800
+ const nameTokens = new Set(tokenize(stem(rec.name)));
4801
+ const descTokens = new Set(tokenize(rec.description));
4802
+ let score = 0;
4803
+ for (const term of queryTerms) {
4804
+ const w = idf(term);
4805
+ if (keywordSet.has(term)) score += 10 * w;
4806
+ else if ([...keywordSet].some((k) => k.includes(term) || term.includes(k))) score += 5 * w;
4807
+ if (nameTokens.has(term)) score += 6 * w;
4808
+ if (term === rec.domain || rec.domain.includes(term)) score += 2 * w;
4809
+ if (descTokens.has(term)) score += 3 * w;
4810
+ }
4811
+ return score;
4812
+ }
4813
+ function buildSearchIndex(descriptors, meta) {
4814
+ return descriptors.map((d) => {
4815
+ const m = meta[d.name];
4816
+ if (m === void 0) {
4817
+ throw new Error(`search: no search metadata (domain/keywords) for tool "${d.name}"`);
4818
+ }
4819
+ return { name: d.name, description: d.description, domain: m.domain, keywords: m.keywords };
4820
+ });
4821
+ }
4822
+ function splitIntents(query) {
4823
+ const parts = query.split(/\b(?:then|and)\b|[,;]+/i).map((s) => s.trim()).filter((s) => s.length > 0);
4824
+ return parts.length > 0 ? parts : [query];
4825
+ }
4826
+ function searchTools(query, index, opts = {}) {
4827
+ const { limit = 5, domain } = opts;
4828
+ const segments = splitIntents(query).map(tokenize);
4829
+ const idf = buildIdf(index);
4830
+ const pool = domain ? index.filter((r) => r.domain === domain) : index;
4831
+ return pool.map((rec) => ({
4832
+ name: rec.name,
4833
+ // A tool's score is its best fit to any single intent, not the blurred whole.
4834
+ score: Math.max(...segments.map((terms) => scoreRecord(terms, rec, idf))),
4835
+ domain: rec.domain
4836
+ })).filter((h) => h.score > 0).sort((a, b) => b.score - a.score || a.name.localeCompare(b.name)).slice(0, limit);
4837
+ }
4838
+ var TOOL_SEARCH_META = {
4839
+ "proxmox_add_firewall_rule": { domain: "firewall", keywords: ["allow", "block", "traffic", "ingress", "egress", "permit", "deny"] },
4840
+ "proxmox_add_ha_resource": { domain: "ha", keywords: ["protect", "failover", "availability", "fencing", "placement", "managed"] },
4841
+ "proxmox_audit_permissions": { domain: "identity", keywords: ["access", "rights", "privileges", "grants", "inspect", "who can"] },
4842
+ "proxmox_cancel_task": { domain: "cluster", keywords: ["abort", "terminate", "interrupt", "halt", "running", "job"] },
4843
+ "proxmox_cleanup_smoke_resources": { domain: "resources", keywords: ["purge", "leftovers", "testing", "preview", "dryrun", "tear down"] },
4844
+ "proxmox_clone_resource": { domain: "resources", keywords: ["copy", "duplicate", "fork", "instantiate", "source", "linked"] },
4845
+ "proxmox_cluster_log": { domain: "cluster", keywords: ["events", "history", "messages", "daemon", "entries", "audit"] },
4846
+ "proxmox_cluster_status": { domain: "cluster", keywords: ["membership", "quorum", "online", "health", "voting", "members"] },
4847
+ "proxmox_convert_to_template": { domain: "resources", keywords: ["golden", "image", "master", "reusable", "freeze", "base"] },
4848
+ "proxmox_create_backup_job": { domain: "backups", keywords: ["schedule", "vzdump", "nightly", "recurring", "automate", "retention"] },
4849
+ "proxmox_create_container": { domain: "resources", keywords: ["lxc", "provision", "instantiate", "deploy", "guest", "spin up"] },
4850
+ "proxmox_create_pool": { domain: "identity", keywords: ["group", "collection", "organize", "bucket", "membership", "grouping"] },
4851
+ "proxmox_create_replication": { domain: "ha", keywords: ["mirror", "synchronize", "failover", "remote", "target", "zfs"] },
4852
+ "proxmox_create_storage": { domain: "storage", keywords: ["datastore", "capacity", "backend", "attach", "volume", "define"] },
4853
+ "proxmox_create_token": { domain: "identity", keywords: ["apikey", "credential", "secret", "generate", "account", "auth"] },
4854
+ "proxmox_create_vm": { domain: "resources", keywords: ["qemu", "machine", "virtual", "provision", "guest", "spin up"] },
4855
+ "proxmox_delete_backup_job": { domain: "backups", keywords: ["unschedule", "remove", "recurring", "vzdump", "cancel", "nightly"] },
4856
+ "proxmox_delete_firewall_rule": { domain: "firewall", keywords: ["remove", "discard", "clear", "retract", "eliminate", "drop"] },
4857
+ "proxmox_delete_ha_resource": { domain: "ha", keywords: ["unmanage", "detach", "remove", "failover", "release", "availability"] },
4858
+ "proxmox_delete_pool": { domain: "identity", keywords: ["disband", "empty", "remove", "group", "collection", "tear down"] },
4859
+ "proxmox_delete_replication": { domain: "ha", keywords: ["unsync", "mirror", "cancel", "remove", "teardown", "stop"] },
4860
+ "proxmox_delete_snapshot": { domain: "resources", keywords: ["discard", "remove", "checkpoint", "recovery", "purge", "clear"] },
4861
+ "proxmox_delete_storage": { domain: "storage", keywords: ["detach", "unmount", "disconnect", "remove", "deprovision", "undefine"] },
4862
+ "proxmox_delete_token": { domain: "identity", keywords: ["revoke", "invalidate", "disable", "expire", "credential", "apikey"] },
4863
+ "proxmox_delete_volume": { domain: "storage", keywords: ["erase", "discard", "decommission", "archive", "image", "purge"] },
4864
+ "proxmox_destroy_resource": { domain: "resources", keywords: ["permanent", "decommission", "wipe", "remove", "guest", "delete"] },
4865
+ "proxmox_download_url": { domain: "storage", keywords: ["fetch", "installer", "checksum", "remote", "import", "iso"] },
4866
+ "proxmox_exec": { domain: "guest-ops", keywords: ["shell", "terminal", "command", "script", "stdout", "inside"] },
4867
+ "proxmox_force_stop_resource": { domain: "resources", keywords: ["hardkill", "emergency", "shutdown", "terminate", "poweroff", "kill"] },
4868
+ "proxmox_get_cluster_options": { domain: "cluster", keywords: ["datacenter", "settings", "keyboard", "migration", "defaults", "global"] },
4869
+ "proxmox_get_container_config": { domain: "resources", keywords: ["lxc", "settings", "hardware", "inspect", "properties", "show"] },
4870
+ "proxmox_get_firewall_options": { domain: "firewall", keywords: ["policy", "inbound", "outbound", "logging", "enabled", "default"] },
4871
+ "proxmox_get_resource": { domain: "resources", keywords: ["inspect", "guest", "details", "current", "health", "state"] },
4872
+ "proxmox_get_task_log": { domain: "cluster", keywords: ["tail", "output", "messages", "progress", "diagnose", "upid"] },
4873
+ "proxmox_get_task_status": { domain: "cluster", keywords: ["progress", "running", "completed", "exit", "operation", "upid"] },
4874
+ "proxmox_get_vm_config": { domain: "resources", keywords: ["qemu", "settings", "hardware", "inspect", "properties", "show"] },
4875
+ "proxmox_guest_network": { domain: "guest-ops", keywords: ["address", "interfaces", "ipvfour", "ethernet", "agent", "ip"] },
4876
+ "proxmox_ha_status": { domain: "ha", keywords: ["availability", "fencing", "quorum", "failover", "manager", "crm"] },
4877
+ "proxmox_list_acl": { domain: "identity", keywords: ["access", "entries", "grants", "bindings", "propagation", "permissions"] },
4878
+ "proxmox_list_backup_jobs": { domain: "backups", keywords: ["schedules", "vzdump", "automation", "retention", "archives", "recurring"] },
4879
+ "proxmox_list_backups": { domain: "backups", keywords: ["archives", "recovery", "copies", "vzdump", "restorepoints", "dumps"] },
4880
+ "proxmox_list_containers": { domain: "resources", keywords: ["lxc", "guests", "inventory", "workloads", "instances", "running"] },
4881
+ "proxmox_list_directory": { domain: "guest-ops", keywords: ["browse", "filesystem", "folder", "files", "enumerate", "inside"] },
4882
+ "proxmox_list_disks": { domain: "storage", keywords: ["drives", "smart", "wearout", "capacity", "hardware", "physical"] },
4883
+ "proxmox_list_firewall_rules": { domain: "firewall", keywords: ["policies", "filters", "traffic", "allow", "deny", "security"] },
4884
+ "proxmox_list_ha_resources": { domain: "ha", keywords: ["managed", "guests", "availability", "failover", "assignments", "protected"] },
4885
+ "proxmox_list_ha_rules": { domain: "ha", keywords: ["affinity", "placement", "constraints", "colocation", "preference", "policy"] },
4886
+ "proxmox_list_metric_servers": { domain: "cluster", keywords: ["monitoring", "telemetry", "influxdb", "graphite", "endpoints", "observability"] },
4887
+ "proxmox_list_node_services": { domain: "cluster", keywords: ["systemd", "daemons", "pveproxy", "pvedaemon", "corosync", "host"] },
4888
+ "proxmox_list_pool_resources": { domain: "identity", keywords: ["members", "grouping", "guests", "contents", "assignment", "belongs"] },
4889
+ "proxmox_list_pools": { domain: "identity", keywords: ["groups", "collections", "comments", "categories", "organization", "groupings"] },
4890
+ "proxmox_list_replication": { domain: "ha", keywords: ["mirroring", "synchronization", "failover", "source", "target", "sync jobs"] },
4891
+ "proxmox_list_roles": { domain: "identity", keywords: ["privileges", "rbac", "access", "permissions", "capabilities", "levels"] },
4892
+ "proxmox_list_sdn_vnets": { domain: "cluster", keywords: ["networks", "vlans", "overlays", "segments", "switches", "virtual"] },
4893
+ "proxmox_list_sdn_zones": { domain: "cluster", keywords: ["networks", "boundaries", "routing", "segments", "regions", "isolation"] },
4894
+ "proxmox_list_snapshots": { domain: "resources", keywords: ["checkpoints", "restorepoints", "history", "recovery", "savedstate", "rollback"] },
4895
+ "proxmox_list_storage": { domain: "storage", keywords: ["capacity", "free", "datastore", "space", "usage", "available"] },
4896
+ "proxmox_list_storage_config": { domain: "storage", keywords: ["datastores", "backends", "definitions", "shared", "restrictions", "setup"] },
4897
+ "proxmox_list_storage_content": { domain: "storage", keywords: ["volumes", "isos", "images", "archives", "templates", "files"] },
4898
+ "proxmox_list_templates": { domain: "storage", keywords: ["vztmpl", "isos", "images", "media", "bootable", "appliance"] },
4899
+ "proxmox_list_tokens": { domain: "identity", keywords: ["apikeys", "credentials", "secrets", "accounts", "authentication", "keys"] },
4900
+ "proxmox_list_updates": { domain: "cluster", keywords: ["patches", "packages", "upgrades", "apt", "outdated", "pending"] },
4901
+ "proxmox_list_users": { domain: "identity", keywords: ["accounts", "realms", "logins", "enabled", "access", "members"] },
4902
+ "proxmox_list_vms": { domain: "resources", keywords: ["qemu", "machines", "guests", "inventory", "workloads", "running"] },
4903
+ "proxmox_migrate_resource": { domain: "resources", keywords: ["relocate", "transfer", "live", "host", "rebalance", "move"] },
4904
+ "proxmox_move_disk": { domain: "storage", keywords: ["relocate", "volume", "backend", "transfer", "datastore", "reassign"] },
4905
+ "proxmox_next_vmid": { domain: "cluster", keywords: ["available", "identifier", "unused", "allocate", "number", "free"] },
4906
+ "proxmox_node_power": { domain: "cluster", keywords: ["reboot", "shutdown", "hypervisor", "restart", "host", "halt"] },
4907
+ "proxmox_read_file": { domain: "guest-ops", keywords: ["cat", "contents", "text", "document", "inspect", "inside"] },
4908
+ "proxmox_reboot_resource": { domain: "resources", keywords: ["restart", "cycle", "guest", "bounce", "powercycle", "graceful"] },
4909
+ "proxmox_recent_tasks": { domain: "cluster", keywords: ["activity", "history", "operations", "queue", "audit", "jobs"] },
4910
+ "proxmox_reset_resource": { domain: "resources", keywords: ["hardrestart", "button", "ungraceful", "reboot", "powercycle", "forced"] },
4911
+ "proxmox_resize_disk": { domain: "storage", keywords: ["grow", "expand", "increase", "capacity", "extend", "enlarge"] },
4912
+ "proxmox_resource_usage": { domain: "resources", keywords: ["metrics", "statistics", "cpu", "memory", "performance", "graphs"] },
4913
+ "proxmox_restore_backup": { domain: "backups", keywords: ["recover", "recreate", "overwrite", "vzdump", "archive", "revert"] },
4914
+ "proxmox_resume_resource": { domain: "resources", keywords: ["unpause", "continue", "wake", "thaw", "reawaken", "unfreeze"] },
4915
+ "proxmox_rollback_snapshot": { domain: "resources", keywords: ["revert", "undo", "previous", "checkpoint", "recover", "restore"] },
4916
+ "proxmox_run_backup": { domain: "backups", keywords: ["trigger", "vzdump", "archive", "save", "protect", "execute"] },
4917
+ "proxmox_service_restart": { domain: "guest-ops", keywords: ["systemd", "bounce", "reload", "daemon", "inside", "unit"] },
4918
+ "proxmox_service_start": { domain: "guest-ops", keywords: ["systemd", "launch", "boot", "daemon", "inside", "activate"] },
4919
+ "proxmox_service_status": { domain: "guest-ops", keywords: ["systemd", "running", "daemon", "health", "inside", "check"] },
4920
+ "proxmox_service_stop": { domain: "guest-ops", keywords: ["systemd", "halt", "kill", "daemon", "inside", "deactivate"] },
4921
+ "proxmox_set_acl": { domain: "identity", keywords: ["grant", "revoke", "permissions", "rights", "privileges", "assign"] },
4922
+ "proxmox_set_firewall_enabled": { domain: "firewall", keywords: ["toggle", "activate", "deactivate", "switch", "policy", "turn on"] },
4923
+ "proxmox_snapshot_resource": { domain: "resources", keywords: ["checkpoint", "capture", "freeze", "save", "restorepoint", "point in time"] },
4924
+ "proxmox_start_resource": { domain: "resources", keywords: ["boot", "poweron", "launch", "activate", "bringup", "turn on"] },
4925
+ "proxmox_stat_path": { domain: "guest-ops", keywords: ["metadata", "size", "permissions", "directory", "details", "exists"] },
4926
+ "proxmox_status": { domain: "cluster", keywords: ["version", "health", "nodes", "uptime", "overview", "summary"] },
4927
+ "proxmox_stop_resource": { domain: "resources", keywords: ["shutdown", "halt", "graceful", "poweroff", "deactivate", "turn off"] },
4928
+ "proxmox_suspend_resource": { domain: "resources", keywords: ["pause", "freeze", "sleep", "hibernate", "interrupt", "hold"] },
4929
+ "proxmox_update_container_config": { domain: "resources", keywords: ["edit", "modify", "lxc", "settings", "hostname", "cores"] },
4930
+ "proxmox_update_pool": { domain: "identity", keywords: ["modify", "members", "group", "comment", "detach", "edit"] },
4931
+ "proxmox_update_vm_config": { domain: "resources", keywords: ["edit", "modify", "qemu", "settings", "sockets", "cores"] },
4932
+ "proxmox_validate_qemu_smoke_source": { domain: "resources", keywords: ["verify", "safe", "clone", "agent", "passthrough", "readiness"] },
4933
+ "proxmox_wait_task": { domain: "cluster", keywords: ["poll", "monitor", "watch", "timeout", "complete", "block"] },
4934
+ "proxmox_write_file": { domain: "guest-ops", keywords: ["save", "upload", "text", "contents", "directories", "inside"] }
4935
+ };
4936
+
4937
+ // src/deferred.ts
4938
+ import { Type as Type98 } from "@sinclair/typebox";
4939
+ var SEARCH_TOOL_NAME = "proxmox_search_tools";
4940
+ var DEFERRED_ENV_FLAG = "PROXMOX_DEFERRED_TOOLS";
4941
+ var TRUTHY = ["true", "1", "yes"];
4942
+ function deferredModeEnabled(env = process.env) {
4943
+ const value = env[DEFERRED_ENV_FLAG];
4944
+ return typeof value === "string" && TRUTHY.includes(value.toLowerCase());
4945
+ }
4946
+ var SEARCH_TOOL_DESCRIPTION = `Find Proxmox tools by describing the task in plain language, then call the tool this returns. Only this search tool is loaded at first; matching tools are added to your tool list on demand, so re-read your tool list after calling this and then call the chosen tool directly with its own arguments. Describe the whole task in one query ("snapshot 110 then resize its disk") and each intent is matched separately. Results carry the tool's access tier and the gate arguments it will require; the gates are enforced by the tool itself, so a tool appearing here is not permission to skip them.`;
4947
+ var searchToolParameters = Type98.Object(
4948
+ {
4949
+ query: Type98.String({
4950
+ description: "What you are trying to do, in plain language. Multiple intents are fine.",
4951
+ minLength: 1
4952
+ }),
4953
+ domain: Type98.Optional(
4954
+ Type98.Union(
4955
+ DOMAINS.map((d) => Type98.Literal(d)),
4956
+ { description: "Optional hard filter to a single tool domain." }
4957
+ )
4958
+ ),
4959
+ limit: Type98.Optional(
4960
+ Type98.Integer({
4961
+ minimum: 1,
4962
+ maximum: 25,
4963
+ default: 5,
4964
+ description: "Maximum tools to return and load (default 5)."
4965
+ })
4966
+ )
4967
+ },
4968
+ { additionalProperties: false }
4969
+ );
4970
+ var GATE_HINTS = {
4971
+ read: null,
4972
+ "safe-write": { confirm: true },
4973
+ destructive: { confirm: true, destructive: true, env: "PROXMOX_ENABLE_DESTRUCTIVE=1" }
4974
+ };
4975
+ function createDeferredSession() {
4976
+ const loaded = /* @__PURE__ */ new Set();
4977
+ return {
4978
+ isLoaded: (name) => loaded.has(name),
4979
+ loadedTools: () => [...loaded],
4980
+ load(names) {
4981
+ const added = [];
4982
+ for (const name of names) {
4983
+ if (!loaded.has(name)) {
4984
+ loaded.add(name);
4985
+ added.push(name);
4986
+ }
4987
+ }
4988
+ return added;
4989
+ }
4990
+ };
4991
+ }
4992
+ function runToolSearch(args, index, session) {
4993
+ const query = args.query;
4994
+ if (typeof query !== "string" || query.trim() === "") {
4995
+ throw new ToolInputError(`${SEARCH_TOOL_NAME} requires a non-empty "query" string.`);
4996
+ }
4997
+ const domain = args.domain === void 0 ? void 0 : args.domain;
4998
+ if (domain !== void 0 && !DOMAINS.includes(domain)) {
4999
+ throw new ToolInputError(
5000
+ `${SEARCH_TOOL_NAME}: unknown domain "${String(args.domain)}". Valid domains: ${DOMAINS.join(", ")}.`
5001
+ );
5002
+ }
5003
+ const limit = typeof args.limit === "number" ? args.limit : 5;
5004
+ const hits = searchTools(query, index, { limit, domain }).map((h) => {
5005
+ const tier = TOOL_TIERS[h.name] ?? "safe-write";
5006
+ return {
5007
+ name: h.name,
5008
+ tier,
5009
+ domain: h.domain,
5010
+ description: index.find((r) => r.name === h.name)?.description ?? "",
5011
+ requires: GATE_HINTS[tier]
5012
+ };
5013
+ });
5014
+ const added = session.load(hits.map((h) => h.name));
5015
+ return {
5016
+ hits,
5017
+ added,
5018
+ result: jsonToolResult({
5019
+ query,
5020
+ matched: hits.length,
5021
+ loaded: added,
5022
+ already_loaded: hits.filter((h) => !added.includes(h.name)).map((h) => h.name),
5023
+ tools: hits,
5024
+ next_step: hits.length === 0 ? "No tool matched. Try naming the Proxmox object (snapshot, storage, ACL, backup job) rather than the outcome." : "These tools are now in your tool list. Re-read it, then call the one you want directly with its own arguments."
5025
+ })
5026
+ };
5027
+ }
5028
+
5029
+ // src/server.ts
5030
+ function createMcpServer(cfg = resolveConfig(process.env)) {
2615
5031
  registerSecret(cfg.tokenId);
2616
5032
  registerSecret(cfg.tokenSecret);
2617
5033
  registerSecret(`PVEAPIToken=${cfg.tokenId}=${cfg.tokenSecret}`);
@@ -2669,14 +5085,122 @@ async function startServer() {
2669
5085
  createProxmoxServiceStatusTool(getClient, getSsh, vmDefaults),
2670
5086
  createProxmoxServiceStartTool(getClient, getSsh, vmDefaults),
2671
5087
  createProxmoxServiceStopTool(getClient, getSsh, vmDefaults),
2672
- createProxmoxServiceRestartTool(getClient, getSsh, vmDefaults)
5088
+ createProxmoxServiceRestartTool(getClient, getSsh, vmDefaults),
5089
+ createProxmoxUpdateVmConfigTool(getClient),
5090
+ createProxmoxUpdateContainerConfigTool(getClient),
5091
+ createProxmoxResizeDiskTool(getClient),
5092
+ createProxmoxRestoreBackupTool(getClient),
5093
+ createProxmoxMigrateResourceTool(getClient),
5094
+ createProxmoxSuspendResourceTool(getClient),
5095
+ createProxmoxResumeResourceTool(getClient),
5096
+ createProxmoxResetResourceTool(getClient),
5097
+ createProxmoxConvertToTemplateTool(getClient),
5098
+ createProxmoxListStorageContentTool(getClient),
5099
+ createProxmoxDownloadUrlTool(getClient),
5100
+ createProxmoxDeleteVolumeTool(getClient),
5101
+ createProxmoxListNodeServicesTool(getClient),
5102
+ createProxmoxListUpdatesTool(getClient),
5103
+ createProxmoxListDisksTool(getClient),
5104
+ createProxmoxCancelTaskTool(getClient),
5105
+ createProxmoxNodePowerTool(getClient),
5106
+ createProxmoxListFirewallRulesTool(getClient),
5107
+ createProxmoxGetFirewallOptionsTool(getClient),
5108
+ createProxmoxAddFirewallRuleTool(getClient),
5109
+ createProxmoxDeleteFirewallRuleTool(getClient),
5110
+ createProxmoxSetFirewallEnabledTool(getClient),
5111
+ createProxmoxMoveDiskTool(getClient),
5112
+ createProxmoxListStorageConfigTool(getClient),
5113
+ createProxmoxCreateStorageTool(getClient),
5114
+ createProxmoxDeleteStorageTool(getClient),
5115
+ createProxmoxListBackupJobsTool(getClient),
5116
+ createProxmoxCreateBackupJobTool(getClient),
5117
+ createProxmoxDeleteBackupJobTool(getClient),
5118
+ createProxmoxListUsersTool(getClient),
5119
+ createProxmoxListRolesTool(getClient),
5120
+ createProxmoxListAclTool(getClient),
5121
+ createProxmoxListPoolsTool(getClient),
5122
+ createProxmoxListTokensTool(getClient),
5123
+ createProxmoxSetAclTool(getClient),
5124
+ createProxmoxCreateTokenTool(getClient),
5125
+ createProxmoxDeleteTokenTool(getClient),
5126
+ createProxmoxCreatePoolTool(getClient),
5127
+ createProxmoxUpdatePoolTool(getClient),
5128
+ createProxmoxDeletePoolTool(getClient),
5129
+ createProxmoxClusterStatusTool(getClient),
5130
+ createProxmoxHaStatusTool(getClient),
5131
+ createProxmoxListHaResourcesTool(getClient),
5132
+ createProxmoxListHaRulesTool(getClient),
5133
+ createProxmoxListReplicationTool(getClient),
5134
+ createProxmoxListSdnZonesTool(getClient),
5135
+ createProxmoxListSdnVnetsTool(getClient),
5136
+ createProxmoxListMetricServersTool(getClient),
5137
+ createProxmoxGetClusterOptionsTool(getClient),
5138
+ createProxmoxClusterLogTool(getClient),
5139
+ createProxmoxAddHaResourceTool(getClient),
5140
+ createProxmoxDeleteHaResourceTool(getClient),
5141
+ createProxmoxCreateReplicationTool(getClient),
5142
+ createProxmoxDeleteReplicationTool(getClient)
2673
5143
  ];
2674
5144
  const toolMap = new Map(tools.map((t) => [t.name, t]));
2675
- const server = new Server({ name: "proxmox-mcp", version: "0.5.0" }, { capabilities: { tools: {} } });
2676
- server.setRequestHandler(ListToolsRequestSchema, async () => ({
2677
- tools: tools.map((t) => ({ name: t.name, description: t.description, inputSchema: t.parameters }))
2678
- }));
5145
+ {
5146
+ const registered = new Set(tools.map((t) => t.name));
5147
+ const declared = new Set(Object.keys(TOOL_TIERS));
5148
+ const missing = [...registered].filter((n) => !declared.has(n));
5149
+ const extra = [...declared].filter((n) => !registered.has(n));
5150
+ if (missing.length > 0 || extra.length > 0) {
5151
+ throw new Error(
5152
+ `registry/tool drift: missing tier for [${missing.join(", ")}]; tier declared for unregistered [${extra.join(", ")}]`
5153
+ );
5154
+ }
5155
+ }
5156
+ const deferred = deferredModeEnabled(process.env);
5157
+ const session = deferred ? createDeferredSession() : null;
5158
+ const searchIndex = deferred ? buildSearchIndex(
5159
+ tools.map((t) => ({ name: t.name, description: t.description })),
5160
+ TOOL_SEARCH_META
5161
+ ) : null;
5162
+ if (toolMap.has(SEARCH_TOOL_NAME)) {
5163
+ throw new Error(`search tool name ${SEARCH_TOOL_NAME} collides with a registered tool`);
5164
+ }
5165
+ const server = new Server(
5166
+ { name: "proxmox-mcp", version: "0.12.0" },
5167
+ { capabilities: { tools: deferred ? { listChanged: true } : {} } }
5168
+ );
5169
+ const descriptorFor = (t) => ({
5170
+ name: t.name,
5171
+ description: t.description,
5172
+ inputSchema: t.parameters,
5173
+ annotations: annotationsForTier(tierForTool(t.name))
5174
+ });
5175
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
5176
+ if (!deferred || session === null) return { tools: tools.map(descriptorFor) };
5177
+ return {
5178
+ tools: [
5179
+ {
5180
+ name: SEARCH_TOOL_NAME,
5181
+ description: SEARCH_TOOL_DESCRIPTION,
5182
+ inputSchema: searchToolParameters,
5183
+ annotations: { readOnlyHint: true }
5184
+ },
5185
+ ...tools.filter((t) => session.isLoaded(t.name)).map(descriptorFor)
5186
+ ]
5187
+ };
5188
+ });
2679
5189
  server.setRequestHandler(CallToolRequestSchema, async (req) => {
5190
+ if (deferred && session !== null && searchIndex !== null && req.params.name === SEARCH_TOOL_NAME) {
5191
+ try {
5192
+ const outcome = runToolSearch(
5193
+ req.params.arguments ?? {},
5194
+ searchIndex,
5195
+ session
5196
+ );
5197
+ if (outcome.added.length > 0) await server.sendToolListChanged();
5198
+ return outcome.result;
5199
+ } catch (e) {
5200
+ const payload = redact(classifyToolError(e));
5201
+ return { content: [{ type: "text", text: JSON.stringify(payload) }], isError: true };
5202
+ }
5203
+ }
2680
5204
  const t = toolMap.get(req.params.name);
2681
5205
  if (!t) {
2682
5206
  return {
@@ -2691,6 +5215,7 @@ async function startServer() {
2691
5215
  isError: true
2692
5216
  };
2693
5217
  }
5218
+ if (deferred && session !== null) session.load([t.name]);
2694
5219
  try {
2695
5220
  return await t.execute(req.params.name, req.params.arguments ?? {});
2696
5221
  } catch (e) {
@@ -2698,12 +5223,16 @@ async function startServer() {
2698
5223
  return { content: [{ type: "text", text: JSON.stringify(payload) }], isError: true };
2699
5224
  }
2700
5225
  });
5226
+ return server;
5227
+ }
5228
+ async function startServer() {
5229
+ const server = createMcpServer();
2701
5230
  const transport = new StdioServerTransport();
2702
5231
  const __send = transport.send.bind(transport);
2703
5232
  transport.send = (message) => {
2704
- const tools2 = message?.result?.tools;
2705
- if (Array.isArray(tools2)) {
2706
- for (const t of tools2) {
5233
+ const tools = message?.result?.tools;
5234
+ if (Array.isArray(tools)) {
5235
+ for (const t of tools) {
2707
5236
  if (t?.inputSchema) delete t.inputSchema.$schema;
2708
5237
  if (t?.outputSchema) delete t.outputSchema.$schema;
2709
5238
  }
@@ -2712,21 +5241,6 @@ async function startServer() {
2712
5241
  };
2713
5242
  await server.connect(transport);
2714
5243
  }
2715
- var isEntrypoint = (() => {
2716
- const arg = process.argv[1];
2717
- if (typeof arg !== "string") return false;
2718
- try {
2719
- return import.meta.url === pathToFileURL(realpathSync(arg)).href;
2720
- } catch {
2721
- return false;
2722
- }
2723
- })();
2724
- if (isEntrypoint) {
2725
- startServer().catch((error) => {
2726
- console.error(`proxmox-mcp fatal: ${error instanceof Error ? error.message : String(error)}`);
2727
- process.exit(1);
2728
- });
2729
- }
2730
5244
 
2731
5245
  // mcp-bin.ts
2732
5246
  startServer().catch((error) => {