@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/index.js CHANGED
@@ -57,7 +57,6 @@ var ProxmoxClientError = class extends Error {
57
57
  this.status = status;
58
58
  this.name = "ProxmoxClientError";
59
59
  }
60
- status;
61
60
  };
62
61
  var ProxmoxUnreachableError = class extends Error {
63
62
  constructor(cause) {
@@ -72,7 +71,6 @@ var ProxmoxClient = class {
72
71
  this.retryDelayMs = opts.retryDelayMs ?? 1e3;
73
72
  this.usesInsecureTls = cfg.tlsInsecure && cfg.url.startsWith("https://");
74
73
  }
75
- cfg;
76
74
  authHeader;
77
75
  retryDelayMs;
78
76
  usesInsecureTls;
@@ -82,6 +80,9 @@ var ProxmoxClient = class {
82
80
  async post(path2, body) {
83
81
  return this.request("POST", path2, body);
84
82
  }
83
+ async put(path2, body) {
84
+ return this.request("PUT", path2, body);
85
+ }
85
86
  async delete(path2) {
86
87
  return this.request("DELETE", path2);
87
88
  }
@@ -94,6 +95,13 @@ var ProxmoxClient = class {
94
95
  const form = new URLSearchParams();
95
96
  for (const [k, v] of Object.entries(body)) {
96
97
  if (v === void 0 || v === null) continue;
98
+ if (Array.isArray(v)) {
99
+ for (const item of v) {
100
+ if (item === void 0 || item === null) continue;
101
+ form.append(k, typeof item === "object" ? JSON.stringify(item) : String(item));
102
+ }
103
+ continue;
104
+ }
97
105
  form.append(k, typeof v === "object" ? JSON.stringify(v) : String(v));
98
106
  }
99
107
  headers["content-type"] = "application/x-www-form-urlencoded";
@@ -171,22 +179,188 @@ function nodeRequest(url, method, headers, body, rejectUnauthorized) {
171
179
  });
172
180
  }
173
181
 
182
+ // src/ssh-executor.ts
183
+ import { Client } from "ssh2";
184
+ import { readFile } from "fs/promises";
185
+ import { homedir } from "os";
186
+ var DEFAULT_MAX_OUTPUT_BYTES = 1024 * 1024;
187
+ var SshExecError = class extends Error {
188
+ constructor(phase, message) {
189
+ super(`ssh ${phase}: ${message}`);
190
+ this.phase = phase;
191
+ this.name = "SshExecError";
192
+ }
193
+ };
194
+ function expandHome(p) {
195
+ if (p.startsWith("~/")) return homedir() + p.slice(1);
196
+ if (p === "~") return homedir();
197
+ return p;
198
+ }
199
+ async function loadKey(keyPath) {
200
+ try {
201
+ return await readFile(expandHome(keyPath));
202
+ } catch (e) {
203
+ const err = e;
204
+ if (err.code === "ENOENT") {
205
+ throw new SshExecError("connect", `key file not found: ${keyPath}`);
206
+ }
207
+ throw new SshExecError("connect", `cannot read key file ${keyPath}: ${err.message}`);
208
+ }
209
+ }
210
+ function base64(s) {
211
+ return Buffer.from(s, "utf8").toString("base64");
212
+ }
213
+ function buildLxcCommand(vmid, command) {
214
+ const b64 = base64(command);
215
+ return `sudo pct exec ${vmid} -- sh -c "$(echo ${b64} | base64 -d)"`;
216
+ }
217
+ function buildDirectCommand(command) {
218
+ const b64 = base64(command);
219
+ return `sh -c "$(echo ${b64} | base64 -d)"`;
220
+ }
221
+ function resolveMaxOutputBytes() {
222
+ const raw = process.env.PROXMOX_SSH_MAX_OUTPUT_BYTES;
223
+ if (!raw) return DEFAULT_MAX_OUTPUT_BYTES;
224
+ const parsed = Number.parseInt(raw, 10);
225
+ if (!Number.isFinite(parsed) || parsed < 1024) return DEFAULT_MAX_OUTPUT_BYTES;
226
+ return parsed;
227
+ }
228
+ async function runOverSsh(cfg, remoteCommand, timeoutMs, stdin) {
229
+ const key = await loadKey(cfg.keyPath);
230
+ const maxOutputBytes = resolveMaxOutputBytes();
231
+ return new Promise((resolve, reject) => {
232
+ const conn = new Client();
233
+ let stdout = "";
234
+ let stderr = "";
235
+ let stdoutBytes = 0;
236
+ let stderrBytes = 0;
237
+ let settled = false;
238
+ const timer = setTimeout(() => {
239
+ if (settled) return;
240
+ settled = true;
241
+ try {
242
+ conn.end();
243
+ } catch {
244
+ }
245
+ try {
246
+ conn.destroy();
247
+ } catch {
248
+ }
249
+ reject(new SshExecError("timeout", `command exceeded ${timeoutMs}ms`));
250
+ }, timeoutMs);
251
+ const finish = (result) => {
252
+ if (settled) return;
253
+ settled = true;
254
+ clearTimeout(timer);
255
+ try {
256
+ conn.end();
257
+ } catch {
258
+ }
259
+ resolve(result);
260
+ };
261
+ const fail = (phase, message) => {
262
+ if (settled) return;
263
+ settled = true;
264
+ clearTimeout(timer);
265
+ try {
266
+ conn.end();
267
+ } catch {
268
+ }
269
+ try {
270
+ conn.destroy();
271
+ } catch {
272
+ }
273
+ reject(new SshExecError(phase, message));
274
+ };
275
+ const appendOutput = (streamName, chunk) => {
276
+ if (settled) return;
277
+ if (streamName === "stdout") {
278
+ stdoutBytes += chunk.length;
279
+ if (stdoutBytes > maxOutputBytes) {
280
+ fail("exec", `stdout exceeded ${maxOutputBytes} bytes`);
281
+ return;
282
+ }
283
+ stdout += chunk.toString("utf8");
284
+ return;
285
+ }
286
+ stderrBytes += chunk.length;
287
+ if (stderrBytes > maxOutputBytes) {
288
+ fail("exec", `stderr exceeded ${maxOutputBytes} bytes`);
289
+ return;
290
+ }
291
+ stderr += chunk.toString("utf8");
292
+ };
293
+ conn.on("error", (err) => fail("connect", err.message));
294
+ conn.on("ready", () => {
295
+ conn.exec(remoteCommand, (err, stream) => {
296
+ if (err) return fail("exec", err.message);
297
+ stream.on("data", (chunk) => {
298
+ appendOutput("stdout", chunk);
299
+ });
300
+ stream.stderr.on("data", (chunk) => {
301
+ appendOutput("stderr", chunk);
302
+ });
303
+ stream.on("close", (code) => {
304
+ finish({ stdout, stderr, exitCode: code ?? -1 });
305
+ });
306
+ if (stdin !== void 0) {
307
+ stream.write(stdin);
308
+ stream.end();
309
+ }
310
+ });
311
+ });
312
+ conn.connect({
313
+ host: cfg.host,
314
+ port: cfg.port,
315
+ username: cfg.user,
316
+ privateKey: key,
317
+ readyTimeout: timeoutMs
318
+ });
319
+ });
320
+ }
321
+ async function execInLxc(hostCfg, vmid, command, timeoutMs, stdin) {
322
+ return runOverSsh(hostCfg, buildLxcCommand(vmid, command), timeoutMs, stdin);
323
+ }
324
+ async function execViaDirectSsh(targetCfg, command, timeoutMs, stdin) {
325
+ return runOverSsh(targetCfg, buildDirectCommand(command), timeoutMs, stdin);
326
+ }
327
+
174
328
  // src/security.ts
175
329
  var SECRETS = /* @__PURE__ */ new Set();
176
330
  var BASE64_TOKEN_RE = /[A-Za-z0-9+/=]{12,}/g;
331
+ var MIN_SUBSTRING_LENGTH = 8;
332
+ var warnedShortSecret = false;
333
+ function escapeRegExp(s) {
334
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
335
+ }
177
336
  function registerSecret(s) {
178
- if (s && s.length > 0) SECRETS.add(s);
337
+ if (!s || s.length === 0) return;
338
+ SECRETS.add(s);
339
+ if (s.length < MIN_SUBSTRING_LENGTH && !warnedShortSecret) {
340
+ warnedShortSecret = true;
341
+ console.error(
342
+ `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.`
343
+ );
344
+ }
179
345
  }
180
346
  function maskString(s) {
181
347
  let out = s;
182
348
  for (const secret of SECRETS) {
183
- if (out.includes(secret)) out = out.split(secret).join("REDACTED");
349
+ if (!out.includes(secret)) continue;
350
+ if (secret.length >= MIN_SUBSTRING_LENGTH) {
351
+ out = out.split(secret).join("REDACTED");
352
+ } else {
353
+ out = out.replace(
354
+ new RegExp(`(^|[^A-Za-z0-9])${escapeRegExp(secret)}(?=[^A-Za-z0-9]|$)`, "g"),
355
+ (_match, left) => `${left}REDACTED`
356
+ );
357
+ }
184
358
  }
185
359
  out = out.replace(BASE64_TOKEN_RE, (token) => {
186
360
  try {
187
361
  const decoded = Buffer.from(token, "base64").toString("utf8");
188
362
  for (const secret of SECRETS) {
189
- if (decoded.includes(secret)) return "REDACTED";
363
+ if (secret.length >= MIN_SUBSTRING_LENGTH && decoded.includes(secret)) return "REDACTED";
190
364
  }
191
365
  } catch {
192
366
  }
@@ -249,6 +423,7 @@ async function resolveResource(client, vmid) {
249
423
  const where = matches.map((m) => `${m.node}/${m.type}`).join(", ");
250
424
  throw new Error(`vmid ${vmid} ambiguous - found on multiple nodes: ${where}. Refusing to proceed.`);
251
425
  }
426
+ assertSafePathSegment(matches[0].node, "node");
252
427
  return { node: matches[0].node, type: matches[0].type };
253
428
  }
254
429
  function parseTaskUpid(upid) {
@@ -259,6 +434,7 @@ function parseTaskUpid(upid) {
259
434
  if (parts.length < 8) throw new Error(`invalid UPID format: ${upid}`);
260
435
  const node = parts[1];
261
436
  if (!node) throw new Error(`UPID missing node segment: ${upid}`);
437
+ if (!SAFE_SEGMENT_RE.test(node)) throw new Error(`invalid UPID format: bad node segment "${node}"`);
262
438
  return { node };
263
439
  }
264
440
 
@@ -352,6 +528,23 @@ var Schema5 = Type5.Object(
352
528
  },
353
529
  { additionalProperties: false }
354
530
  );
531
+ var NAME2 = "proxmox_get_vm_config";
532
+ function createProxmoxGetVmConfigTool(getClient) {
533
+ return {
534
+ name: NAME2,
535
+ label: "proxmox: get VM config",
536
+ description: "Get QEMU VM config by vmid (GET /nodes/{node}/qemu/{vmid}/config). Fails if the vmid is not a QEMU VM.",
537
+ parameters: Schema5,
538
+ execute: async (_id, raw) => {
539
+ const args = validateToolArgs(Schema5, raw, NAME2);
540
+ const client = getClient();
541
+ const { node, type } = await resolveResource(client, args.vmid);
542
+ if (type !== "qemu") throw new Error(`vmid ${args.vmid} is ${type}, not qemu`);
543
+ const config = await client.get(`/nodes/${node}/qemu/${args.vmid}/config`);
544
+ return jsonToolResult({ vmid: args.vmid, node, type, config });
545
+ }
546
+ };
547
+ }
355
548
 
356
549
  // src/tools/proxmox_get_container_config.ts
357
550
  import { Type as Type6 } from "@sinclair/typebox";
@@ -361,6 +554,23 @@ var Schema6 = Type6.Object(
361
554
  },
362
555
  { additionalProperties: false }
363
556
  );
557
+ var NAME3 = "proxmox_get_container_config";
558
+ function createProxmoxGetContainerConfigTool(getClient) {
559
+ return {
560
+ name: NAME3,
561
+ label: "proxmox: get container config",
562
+ description: "Get LXC container config by vmid (GET /nodes/{node}/lxc/{vmid}/config). Fails if the vmid is not an LXC container.",
563
+ parameters: Schema6,
564
+ execute: async (_id, raw) => {
565
+ const args = validateToolArgs(Schema6, raw, NAME3);
566
+ const client = getClient();
567
+ const { node, type } = await resolveResource(client, args.vmid);
568
+ if (type !== "lxc") throw new Error(`vmid ${args.vmid} is ${type}, not lxc`);
569
+ const config = await client.get(`/nodes/${node}/lxc/${args.vmid}/config`);
570
+ return jsonToolResult({ vmid: args.vmid, node, type, config });
571
+ }
572
+ };
573
+ }
364
574
 
365
575
  // src/tools/proxmox_validate_qemu_smoke_source.ts
366
576
  import { Type as Type7 } from "@sinclair/typebox";
@@ -376,7 +586,86 @@ var Schema7 = Type7.Object(
376
586
  },
377
587
  { additionalProperties: false }
378
588
  );
589
+ var NAME4 = "proxmox_validate_qemu_smoke_source";
379
590
  var GIB = 1024 ** 3;
591
+ var UNSAFE_PREFIXES = ["hostpci", "usb"];
592
+ function truthyProxmoxValue(value) {
593
+ if (value === 1 || value === true) return true;
594
+ if (typeof value !== "string") return false;
595
+ return value === "1" || value.startsWith("enabled=1") || value.split(",").includes("enabled=1");
596
+ }
597
+ function configKeysWithPrefixes(config, prefixes) {
598
+ return Object.keys(config).filter((key) => prefixes.some((prefix) => key.startsWith(prefix)));
599
+ }
600
+ function diskSizeGiB(resource) {
601
+ return typeof resource.maxdisk === "number" ? resource.maxdisk / GIB : void 0;
602
+ }
603
+ function createProxmoxValidateQemuSmokeSourceTool(getClient) {
604
+ return {
605
+ name: NAME4,
606
+ label: "proxmox: validate QEMU smoke source",
607
+ description: "Validate that a QEMU VM is a safe live-smoke clone source. Checks passthrough devices, guest agent, running state, and disk size before cloning.",
608
+ parameters: Schema7,
609
+ execute: async (_id, raw) => {
610
+ const args = validateToolArgs(
611
+ Schema7,
612
+ raw,
613
+ NAME4
614
+ );
615
+ const client = getClient();
616
+ const { node, type } = await resolveResource(client, args.vmid);
617
+ if (type !== "qemu") throw new Error(`vmid ${args.vmid} is ${type}, not qemu`);
618
+ const resources = await client.get("/cluster/resources");
619
+ const resource = resources.find((entry) => entry.vmid === args.vmid && entry.type === "qemu");
620
+ if (!resource) throw new Error(`vmid ${args.vmid} not found in cluster resources as qemu`);
621
+ const config = await client.get(`/nodes/${node}/qemu/${args.vmid}/config`);
622
+ const blockers = [];
623
+ const warnings = [];
624
+ const unsafeKeys = configKeysWithPrefixes(config, UNSAFE_PREFIXES);
625
+ if (unsafeKeys.length > 0) {
626
+ blockers.push(`unsafe passthrough/device config present: ${unsafeKeys.join(", ")}`);
627
+ }
628
+ if (typeof config.args === "string" && config.args.length > 0) {
629
+ blockers.push("raw qemu args present");
630
+ }
631
+ if (!truthyProxmoxValue(config.agent)) {
632
+ blockers.push("QEMU guest agent is not enabled in VM config");
633
+ }
634
+ const maxDiskGb = args.max_disk_gb ?? 64;
635
+ const sizeGiB = diskSizeGiB(resource);
636
+ if (typeof sizeGiB === "number" && sizeGiB > maxDiskGb) {
637
+ blockers.push(`source disk is ${sizeGiB.toFixed(1)} GiB, over ${maxDiskGb} GiB limit`);
638
+ }
639
+ const isTemplate = resource.template === 1 || truthyProxmoxValue(config.template);
640
+ if (!isTemplate && resource.status === "running" && args.allow_running !== true) {
641
+ blockers.push("source VM is running; stop it first or pass allow_running:true");
642
+ }
643
+ if (!isTemplate && resource.status !== "stopped" && resource.status !== "running") {
644
+ warnings.push(`source VM status is ${resource.status ?? "unknown"}`);
645
+ }
646
+ return jsonToolResult({
647
+ vmid: args.vmid,
648
+ node,
649
+ ok: blockers.length === 0,
650
+ blockers,
651
+ warnings,
652
+ resource: {
653
+ name: resource.name,
654
+ status: resource.status,
655
+ template: resource.template === 1,
656
+ pool: resource.pool,
657
+ tags: resource.tags,
658
+ disk_gb: typeof sizeGiB === "number" ? Number(sizeGiB.toFixed(1)) : void 0
659
+ },
660
+ config_summary: {
661
+ agent: config.agent,
662
+ unsafe_keys: unsafeKeys,
663
+ has_raw_args: typeof config.args === "string" && config.args.length > 0
664
+ }
665
+ });
666
+ }
667
+ };
668
+ }
380
669
 
381
670
  // src/tools/proxmox_audit_permissions.ts
382
671
  import { Type as Type8 } from "@sinclair/typebox";
@@ -408,10 +697,88 @@ var Schema8 = Type8.Object(
408
697
  },
409
698
  { additionalProperties: false }
410
699
  );
700
+ var NAME5 = "proxmox_audit_permissions";
701
+ var DEFAULT_REQUIRED = [
702
+ "Datastore.AllocateSpace",
703
+ "Datastore.Audit",
704
+ "Pool.Allocate",
705
+ "Pool.Audit",
706
+ "SDN.Use",
707
+ "Sys.Audit",
708
+ "VM.Allocate",
709
+ "VM.Audit",
710
+ "VM.Backup",
711
+ "VM.Clone",
712
+ "VM.Config.Disk",
713
+ "VM.Config.Memory",
714
+ "VM.Config.Network",
715
+ "VM.Config.Options",
716
+ "VM.GuestAgent.Audit",
717
+ "VM.PowerMgmt",
718
+ "VM.Snapshot",
719
+ "VM.Snapshot.Rollback"
720
+ ];
721
+ function defaultPaths(args) {
722
+ const pool = assertSafePathSegment(args.pool ?? "mcp-smoke", "pool");
723
+ const templateStorage = assertSafePathSegment(args.template_storage ?? "local", "template_storage");
724
+ const rootStorage = assertSafePathSegment(args.root_storage ?? "local-lvm", "root_storage");
725
+ const paths = [
726
+ "/",
727
+ `/pool/${pool}`,
728
+ `/storage/${templateStorage}`,
729
+ `/storage/${rootStorage}`,
730
+ "/sdn"
731
+ ];
732
+ if (args.source_vmid !== void 0) paths.push(`/vms/${args.source_vmid}`);
733
+ if (args.target_vmid !== void 0) paths.push(`/vms/${args.target_vmid}`);
734
+ return [...new Set(paths)];
735
+ }
736
+ function withQuery(path2, params) {
737
+ const search = new URLSearchParams();
738
+ for (const [key, value] of Object.entries(params)) {
739
+ if (value !== void 0) search.append(key, value);
740
+ }
741
+ const qs = search.toString();
742
+ return qs ? `${path2}?${qs}` : path2;
743
+ }
744
+ function createProxmoxAuditPermissionsTool(getClient) {
745
+ return {
746
+ name: NAME5,
747
+ label: "proxmox: audit permissions",
748
+ description: "Read effective Proxmox permissions for the current token or a specified user/token across smoke-relevant paths (GET /access/permissions).",
749
+ parameters: Schema8,
750
+ execute: async (_id, raw) => {
751
+ const args = validateToolArgs(Schema8, raw, NAME5);
752
+ const paths = args.paths ?? defaultPaths(args);
753
+ const required = args.required_privileges ?? DEFAULT_REQUIRED;
754
+ const client = getClient();
755
+ const results = [];
756
+ for (const path2 of paths) {
757
+ const permissions = await client.get(
758
+ withQuery("/access/permissions", { path: path2, userid: args.userid })
759
+ );
760
+ const privileges = permissions[path2] ?? permissions[Object.keys(permissions)[0] ?? ""] ?? {};
761
+ const missing = required.filter((priv) => privileges[priv] !== 1);
762
+ results.push({
763
+ path: path2,
764
+ privilege_count: Object.keys(privileges).length,
765
+ missing_required: missing,
766
+ has_all_required: missing.length === 0,
767
+ privileges
768
+ });
769
+ }
770
+ return jsonToolResult({
771
+ userid: args.userid ?? "current",
772
+ required_privileges: required,
773
+ paths: results
774
+ });
775
+ }
776
+ };
777
+ }
411
778
 
412
779
  // src/tools/proxmox_recent_tasks.ts
413
780
  import { Type as Type9 } from "@sinclair/typebox";
414
- var NAME2 = "proxmox_recent_tasks";
781
+ var NAME6 = "proxmox_recent_tasks";
415
782
  var Schema9 = Type9.Object(
416
783
  {
417
784
  limit: Type9.Optional(
@@ -425,12 +792,12 @@ var Schema9 = Type9.Object(
425
792
  );
426
793
  function createProxmoxRecentTasksTool(getClient) {
427
794
  return {
428
- name: NAME2,
795
+ name: NAME6,
429
796
  label: "proxmox: recent tasks",
430
797
  description: "List recent cluster tasks (UPID, type, status, node, user, timing) via GET /cluster/tasks. Optionally filter by vmid (post-filter client-side).",
431
798
  parameters: Schema9,
432
799
  execute: async (_id, raw) => {
433
- const args = validateToolArgs(Schema9, raw, NAME2);
800
+ const args = validateToolArgs(Schema9, raw, NAME6);
434
801
  const limit = args.limit ?? 25;
435
802
  const client = getClient();
436
803
  const tasks = await client.get("/cluster/tasks");
@@ -451,7 +818,7 @@ function createProxmoxRecentTasksTool(getClient) {
451
818
 
452
819
  // src/tools/proxmox_list_backups.ts
453
820
  import { Type as Type10 } from "@sinclair/typebox";
454
- var NAME3 = "proxmox_list_backups";
821
+ var NAME7 = "proxmox_list_backups";
455
822
  var Schema10 = Type10.Object(
456
823
  {
457
824
  node: Type10.Optional(
@@ -465,12 +832,12 @@ var Schema10 = Type10.Object(
465
832
  );
466
833
  function createProxmoxListBackupsTool(getClient) {
467
834
  return {
468
- name: NAME3,
835
+ name: NAME7,
469
836
  label: "proxmox: list backups",
470
837
  description: "List backup volumes on a node. Walks each backup-capable storage via GET /nodes/{node}/storage/{storage}/content?content=backup. Optionally filter by vmid.",
471
838
  parameters: Schema10,
472
839
  execute: async (_id, raw) => {
473
- const args = validateToolArgs(Schema10, raw, NAME3);
840
+ const args = validateToolArgs(Schema10, raw, NAME7);
474
841
  const client = getClient();
475
842
  let node = args.node;
476
843
  if (!node) {
@@ -494,7 +861,7 @@ function createProxmoxListBackupsTool(getClient) {
494
861
 
495
862
  // src/tools/proxmox_resource_usage.ts
496
863
  import { Type as Type11 } from "@sinclair/typebox";
497
- var NAME4 = "proxmox_resource_usage";
864
+ var NAME8 = "proxmox_resource_usage";
498
865
  var Schema11 = Type11.Object(
499
866
  {
500
867
  vmid: Type11.Integer({ minimum: 1, description: "Container or VM ID." }),
@@ -508,12 +875,12 @@ var Schema11 = Type11.Object(
508
875
  );
509
876
  function createProxmoxResourceUsageTool(getClient) {
510
877
  return {
511
- name: NAME4,
878
+ name: NAME8,
512
879
  label: "proxmox: resource usage",
513
880
  description: "Get historical CPU/memory/disk/network samples for one LXC or VM via GET /nodes/{node}/{type}/{vmid}/rrddata?timeframe=<hour|day|week>.",
514
881
  parameters: Schema11,
515
882
  execute: async (_id, raw) => {
516
- const args = validateToolArgs(Schema11, raw, NAME4);
883
+ const args = validateToolArgs(Schema11, raw, NAME8);
517
884
  const timeframe = args.timeframe ?? "hour";
518
885
  const client = getClient();
519
886
  const { node, type } = await resolveResource(client, args.vmid);
@@ -566,16 +933,16 @@ var Schema12 = Type12.Object(
566
933
  },
567
934
  { additionalProperties: false }
568
935
  );
569
- var NAME5 = "proxmox_start_resource";
936
+ var NAME9 = "proxmox_start_resource";
570
937
  function createProxmoxStartResourceTool(getClient) {
571
938
  return {
572
- name: NAME5,
939
+ name: NAME9,
573
940
  label: "proxmox: start resource",
574
941
  description: "Start a stopped LXC container or QEMU VM by vmid. Tier-2 write; requires confirm:true.",
575
942
  parameters: Schema12,
576
943
  execute: async (_id, raw) => {
577
- assertConfirmedWrite(raw, NAME5);
578
- const args = validateToolArgs(Schema12, raw, NAME5);
944
+ assertConfirmedWrite(raw, NAME9);
945
+ const args = validateToolArgs(Schema12, raw, NAME9);
579
946
  const client = getClient();
580
947
  const { node, type } = await resolveResource(client, args.vmid);
581
948
  const upid = await client.post(
@@ -604,16 +971,16 @@ var Schema13 = Type13.Object(
604
971
  },
605
972
  { additionalProperties: false }
606
973
  );
607
- var NAME6 = "proxmox_stop_resource";
974
+ var NAME10 = "proxmox_stop_resource";
608
975
  function createProxmoxStopResourceTool(getClient) {
609
976
  return {
610
- name: NAME6,
977
+ name: NAME10,
611
978
  label: "proxmox: stop resource",
612
979
  description: "Gracefully shutdown an LXC container or QEMU VM by vmid (POST status/shutdown). Tier-2 write; requires confirm:true.",
613
980
  parameters: Schema13,
614
981
  execute: async (_id, raw) => {
615
- assertConfirmedWrite(raw, NAME6);
616
- const args = validateToolArgs(Schema13, raw, NAME6);
982
+ assertConfirmedWrite(raw, NAME10);
983
+ const args = validateToolArgs(Schema13, raw, NAME10);
617
984
  const client = getClient();
618
985
  const { node, type } = await resolveResource(client, args.vmid);
619
986
  const body = {};
@@ -640,16 +1007,16 @@ var Schema14 = Type14.Object(
640
1007
  },
641
1008
  { additionalProperties: false }
642
1009
  );
643
- var NAME7 = "proxmox_reboot_resource";
1010
+ var NAME11 = "proxmox_reboot_resource";
644
1011
  function createProxmoxRebootResourceTool(getClient) {
645
1012
  return {
646
- name: NAME7,
1013
+ name: NAME11,
647
1014
  label: "proxmox: reboot resource",
648
1015
  description: "Reboot an LXC container or QEMU VM by vmid (POST status/reboot). Tier-2 write; requires confirm:true.",
649
1016
  parameters: Schema14,
650
1017
  execute: async (_id, raw) => {
651
- assertConfirmedWrite(raw, NAME7);
652
- const args = validateToolArgs(Schema14, raw, NAME7);
1018
+ assertConfirmedWrite(raw, NAME11);
1019
+ const args = validateToolArgs(Schema14, raw, NAME11);
653
1020
  const client = getClient();
654
1021
  const { node, type } = await resolveResource(client, args.vmid);
655
1022
  const upid = await client.post(
@@ -679,19 +1046,19 @@ var Schema15 = Type15.Object(
679
1046
  },
680
1047
  { additionalProperties: false }
681
1048
  );
682
- var NAME8 = "proxmox_snapshot_resource";
1049
+ var NAME12 = "proxmox_snapshot_resource";
683
1050
  function createProxmoxSnapshotResourceTool(getClient) {
684
1051
  return {
685
- name: NAME8,
1052
+ name: NAME12,
686
1053
  label: "proxmox: snapshot resource",
687
1054
  description: "Create a snapshot of an LXC container or QEMU VM by vmid (POST /snapshot with {snapname, description?}). Tier-2 write; requires confirm:true.",
688
1055
  parameters: Schema15,
689
1056
  execute: async (_id, raw) => {
690
- assertConfirmedWrite(raw, NAME8);
1057
+ assertConfirmedWrite(raw, NAME12);
691
1058
  const args = validateToolArgs(
692
1059
  Schema15,
693
1060
  raw,
694
- NAME8
1061
+ NAME12
695
1062
  );
696
1063
  const client = getClient();
697
1064
  const { node, type } = await resolveResource(client, args.vmid);
@@ -728,38 +1095,92 @@ var Schema16 = Type16.Object(
728
1095
  },
729
1096
  { additionalProperties: false }
730
1097
  );
1098
+ var NAME13 = "proxmox_rollback_snapshot";
1099
+ function createProxmoxRollbackSnapshotTool(getClient) {
1100
+ return {
1101
+ name: NAME13,
1102
+ label: "proxmox: rollback snapshot",
1103
+ description: "Roll back an LXC container or QEMU VM to a named snapshot. Tier-3 destructive because it reverts guest state; requires confirm:true, destructive:true, and env PROXMOX_ENABLE_DESTRUCTIVE=1.",
1104
+ parameters: Schema16,
1105
+ execute: async (_id, raw) => {
1106
+ assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME13);
1107
+ assertDestructive(raw, NAME13);
1108
+ const args = validateToolArgs(Schema16, raw, NAME13);
1109
+ const client = getClient();
1110
+ const { node, type } = await resolveResource(client, args.vmid);
1111
+ const upid = await client.post(
1112
+ `/nodes/${node}/${type}/${args.vmid}/snapshot/${encodeURIComponent(args.snapname)}/rollback`,
1113
+ { start: args.start ? 1 : 0 }
1114
+ );
1115
+ return jsonToolResult({ vmid: args.vmid, node, type, snapname: args.snapname, start: args.start === true, upid });
1116
+ }
1117
+ };
1118
+ }
731
1119
 
732
1120
  // src/tools/proxmox_run_backup.ts
1121
+ import { Type as Type18 } from "@sinclair/typebox";
1122
+
1123
+ // src/tools/task-wait.ts
733
1124
  import { Type as Type17 } from "@sinclair/typebox";
734
- var Schema17 = Type17.Object(
1125
+ var taskWaitFields = {
1126
+ wait: Type17.Optional(
1127
+ Type17.Boolean({ description: "Block until the task finishes and include its exit status in the result." })
1128
+ ),
1129
+ wait_timeout: Type17.Optional(
1130
+ Type17.Integer({ minimum: 1, maximum: 3600, description: "Max seconds to wait when wait:true (default 120)." })
1131
+ )
1132
+ };
1133
+ function sleep2(ms) {
1134
+ return new Promise((resolve) => setTimeout(resolve, ms));
1135
+ }
1136
+ async function resolveTaskWait(client, upid, args, intervalMs = 1e3) {
1137
+ if (!args.wait || typeof upid !== "string" || !upid.startsWith("UPID:")) return void 0;
1138
+ const { node } = parseTaskUpid(upid);
1139
+ const deadline = Date.now() + (args.wait_timeout ?? 120) * 1e3;
1140
+ let polls = 0;
1141
+ let last = null;
1142
+ while (Date.now() <= deadline) {
1143
+ polls += 1;
1144
+ last = await client.get(`/nodes/${node}/tasks/${encodeURIComponent(upid)}/status`);
1145
+ if (last.status === "stopped" || last.exitstatus) {
1146
+ return { done: true, polls, status: last.status, exitstatus: last.exitstatus, ok: last.exitstatus === "OK" };
1147
+ }
1148
+ await sleep2(Math.min(intervalMs, Math.max(0, deadline - Date.now())));
1149
+ }
1150
+ return { done: false, polls, status: last?.status };
1151
+ }
1152
+
1153
+ // src/tools/proxmox_run_backup.ts
1154
+ var Schema17 = Type18.Object(
735
1155
  {
736
- vmid: Type17.Integer({ minimum: 1, description: "Container or VM ID to back up." }),
737
- storage: Type17.String({
1156
+ vmid: Type18.Integer({ minimum: 1, description: "Container or VM ID to back up." }),
1157
+ storage: Type18.String({
738
1158
  minLength: 1,
739
1159
  description: "PVE storage ID where the vzdump archive should be written."
740
1160
  }),
741
- mode: Type17.Optional(
742
- Type17.Union(
743
- [Type17.Literal("snapshot"), Type17.Literal("suspend"), Type17.Literal("stop")],
1161
+ mode: Type18.Optional(
1162
+ Type18.Union(
1163
+ [Type18.Literal("snapshot"), Type18.Literal("suspend"), Type18.Literal("stop")],
744
1164
  { description: "Backup mode. Defaults to 'snapshot'." }
745
1165
  )
746
1166
  ),
747
- confirm: Type17.Boolean({
1167
+ confirm: Type18.Boolean({
748
1168
  description: "Must be true to write. Tier-2 safe-write gate."
749
- })
1169
+ }),
1170
+ ...taskWaitFields
750
1171
  },
751
1172
  { additionalProperties: false }
752
1173
  );
753
- var NAME9 = "proxmox_run_backup";
1174
+ var NAME14 = "proxmox_run_backup";
754
1175
  function createProxmoxRunBackupTool(getClient) {
755
1176
  return {
756
- name: NAME9,
1177
+ name: NAME14,
757
1178
  label: "proxmox: run backup",
758
1179
  description: "Trigger a vzdump backup of a single vmid to a target storage (POST /nodes/{node}/vzdump with {vmid, storage, mode, compress:'zstd'}). Tier-2 write; requires confirm:true.",
759
1180
  parameters: Schema17,
760
1181
  execute: async (_id, raw) => {
761
- assertConfirmedWrite(raw, NAME9);
762
- const args = validateToolArgs(Schema17, raw, NAME9);
1182
+ assertConfirmedWrite(raw, NAME14);
1183
+ const args = validateToolArgs(Schema17, raw, NAME14);
763
1184
  const mode = args.mode ?? "snapshot";
764
1185
  const client = getClient();
765
1186
  const { node } = await resolveResource(client, args.vmid);
@@ -769,23 +1190,25 @@ function createProxmoxRunBackupTool(getClient) {
769
1190
  mode,
770
1191
  compress: "zstd"
771
1192
  });
1193
+ const task = await resolveTaskWait(client, upid, args);
772
1194
  return jsonToolResult({
773
1195
  vmid: args.vmid,
774
1196
  node,
775
1197
  storage: args.storage,
776
1198
  mode,
777
- upid
1199
+ upid,
1200
+ ...task ? { task } : {}
778
1201
  });
779
1202
  }
780
1203
  };
781
1204
  }
782
1205
 
783
1206
  // src/tools/proxmox_get_task_status.ts
784
- import { Type as Type18 } from "@sinclair/typebox";
785
- var NAME10 = "proxmox_get_task_status";
786
- var Schema18 = Type18.Object(
1207
+ import { Type as Type19 } from "@sinclair/typebox";
1208
+ var NAME15 = "proxmox_get_task_status";
1209
+ var Schema18 = Type19.Object(
787
1210
  {
788
- upid: Type18.String({
1211
+ upid: Type19.String({
789
1212
  minLength: 1,
790
1213
  description: "Task UPID returned by a prior write tool (e.g. start, stop, snapshot, backup)."
791
1214
  })
@@ -794,12 +1217,12 @@ var Schema18 = Type18.Object(
794
1217
  );
795
1218
  function createProxmoxGetTaskStatusTool(getClient) {
796
1219
  return {
797
- name: NAME10,
1220
+ name: NAME15,
798
1221
  label: "proxmox: get task status",
799
1222
  description: "Get the current status of a Proxmox task by UPID (running/stopped, exit status) via GET /nodes/{node}/tasks/{upid}/status. Node is parsed from the UPID.",
800
1223
  parameters: Schema18,
801
1224
  execute: async (_id, raw) => {
802
- const args = validateToolArgs(Schema18, raw, NAME10);
1225
+ const args = validateToolArgs(Schema18, raw, NAME15);
803
1226
  const { node } = parseTaskUpid(args.upid);
804
1227
  const client = getClient();
805
1228
  const status = await client.get(
@@ -811,19 +1234,19 @@ function createProxmoxGetTaskStatusTool(getClient) {
811
1234
  }
812
1235
 
813
1236
  // src/tools/proxmox_get_task_log.ts
814
- import { Type as Type19 } from "@sinclair/typebox";
815
- var NAME11 = "proxmox_get_task_log";
816
- var Schema19 = Type19.Object(
1237
+ import { Type as Type20 } from "@sinclair/typebox";
1238
+ var NAME16 = "proxmox_get_task_log";
1239
+ var Schema19 = Type20.Object(
817
1240
  {
818
- upid: Type19.String({
1241
+ upid: Type20.String({
819
1242
  minLength: 1,
820
1243
  description: "Task UPID returned by a prior write tool."
821
1244
  }),
822
- start: Type19.Optional(
823
- Type19.Integer({ minimum: 0, description: "Line offset to start from (default 0)." })
1245
+ start: Type20.Optional(
1246
+ Type20.Integer({ minimum: 0, description: "Line offset to start from (default 0)." })
824
1247
  ),
825
- limit: Type19.Optional(
826
- Type19.Integer({
1248
+ limit: Type20.Optional(
1249
+ Type20.Integer({
827
1250
  minimum: 1,
828
1251
  maximum: 500,
829
1252
  description: "Max lines to return (default 50, max 500)."
@@ -834,12 +1257,12 @@ var Schema19 = Type19.Object(
834
1257
  );
835
1258
  function createProxmoxGetTaskLogTool(getClient) {
836
1259
  return {
837
- name: NAME11,
1260
+ name: NAME16,
838
1261
  label: "proxmox: get task log",
839
1262
  description: "Tail a Proxmox task log by UPID via GET /nodes/{node}/tasks/{upid}/log?start=N&limit=M. Node is parsed from the UPID. Returns { lines, total }.",
840
1263
  parameters: Schema19,
841
1264
  execute: async (_id, raw) => {
842
- const args = validateToolArgs(Schema19, raw, NAME11);
1265
+ const args = validateToolArgs(Schema19, raw, NAME16);
843
1266
  const { node } = parseTaskUpid(args.upid);
844
1267
  const start = args.start ?? 0;
845
1268
  const limit = args.limit ?? 50;
@@ -853,19 +1276,19 @@ function createProxmoxGetTaskLogTool(getClient) {
853
1276
  }
854
1277
 
855
1278
  // src/tools/proxmox_list_templates.ts
856
- import { Type as Type20 } from "@sinclair/typebox";
857
- var NAME12 = "proxmox_list_templates";
858
- var Schema20 = Type20.Object(
1279
+ import { Type as Type21 } from "@sinclair/typebox";
1280
+ var NAME17 = "proxmox_list_templates";
1281
+ var Schema20 = Type21.Object(
859
1282
  {
860
- node: Type20.Optional(
861
- Type20.String({ minLength: 1, description: "Node to query (defaults to first node)." })
1283
+ node: Type21.Optional(
1284
+ Type21.String({ minLength: 1, description: "Node to query (defaults to first node)." })
862
1285
  ),
863
- storage: Type20.Optional(
864
- Type20.String({ minLength: 1, description: "Storage to query (defaults to 'local')." })
1286
+ storage: Type21.Optional(
1287
+ Type21.String({ minLength: 1, description: "Storage to query (defaults to 'local')." })
865
1288
  ),
866
- kind: Type20.Optional(
867
- Type20.Union(
868
- [Type20.Literal("vztmpl"), Type20.Literal("iso"), Type20.Literal("both")],
1289
+ kind: Type21.Optional(
1290
+ Type21.Union(
1291
+ [Type21.Literal("vztmpl"), Type21.Literal("iso"), Type21.Literal("both")],
869
1292
  { description: "Template kind: 'vztmpl' (CT templates), 'iso' (VM ISOs), or 'both'. Defaults to 'both'." }
870
1293
  )
871
1294
  )
@@ -874,12 +1297,12 @@ var Schema20 = Type20.Object(
874
1297
  );
875
1298
  function createProxmoxListTemplatesTool(getClient) {
876
1299
  return {
877
- name: NAME12,
1300
+ name: NAME17,
878
1301
  label: "proxmox: list templates",
879
1302
  description: "List available LXC container templates (vztmpl) and/or VM ISOs on a node/storage (GET /nodes/{node}/storage/{storage}/content?content=vztmpl|iso). Defaults to both kinds on storage 'local'.",
880
1303
  parameters: Schema20,
881
1304
  execute: async (_id, raw) => {
882
- const args = validateToolArgs(Schema20, raw, NAME12);
1305
+ const args = validateToolArgs(Schema20, raw, NAME17);
883
1306
  const client = getClient();
884
1307
  let node = args.node;
885
1308
  if (!node) {
@@ -913,147 +1336,294 @@ function createProxmoxListTemplatesTool(getClient) {
913
1336
  }
914
1337
 
915
1338
  // src/tools/proxmox_list_storage.ts
916
- import { Type as Type21 } from "@sinclair/typebox";
917
- var Schema21 = Type21.Object(
1339
+ import { Type as Type22 } from "@sinclair/typebox";
1340
+ var Schema21 = Type22.Object(
918
1341
  {
919
- node: Type21.Optional(
920
- Type21.String({ minLength: 1, description: "Node to query. Defaults to all nodes." })
1342
+ node: Type22.Optional(
1343
+ Type22.String({ minLength: 1, description: "Node to query. Defaults to all nodes." })
921
1344
  )
922
1345
  },
923
1346
  { additionalProperties: false }
924
1347
  );
1348
+ var NAME18 = "proxmox_list_storage";
1349
+ function createProxmoxListStorageTool(getClient) {
1350
+ return {
1351
+ name: NAME18,
1352
+ label: "proxmox: list storage",
1353
+ description: "List Proxmox storage status on one node or all nodes via GET /nodes/{node}/storage.",
1354
+ parameters: Schema21,
1355
+ execute: async (_id, raw = {}) => {
1356
+ const args = validateToolArgs(Schema21, raw, NAME18);
1357
+ const client = getClient();
1358
+ let nodes;
1359
+ if (args.node) {
1360
+ nodes = [args.node];
1361
+ } else {
1362
+ const resources = await client.get("/cluster/resources?type=node");
1363
+ nodes = resources.map((n) => n.node);
1364
+ if (nodes.length === 0) throw new Error("no nodes found in cluster resources");
1365
+ }
1366
+ const results = [];
1367
+ for (const node of nodes) {
1368
+ const storage = await client.get(`/nodes/${node}/storage`);
1369
+ results.push({ node, storage });
1370
+ }
1371
+ return jsonToolResult({ count: results.reduce((sum, n) => sum + n.storage.length, 0), nodes: results });
1372
+ }
1373
+ };
1374
+ }
925
1375
 
926
1376
  // src/tools/proxmox_list_snapshots.ts
927
- import { Type as Type22 } from "@sinclair/typebox";
928
- var Schema22 = Type22.Object(
1377
+ import { Type as Type23 } from "@sinclair/typebox";
1378
+ var Schema22 = Type23.Object(
929
1379
  {
930
- vmid: Type22.Integer({ minimum: 1, description: "Container or VM ID." })
1380
+ vmid: Type23.Integer({ minimum: 1, description: "Container or VM ID." })
931
1381
  },
932
1382
  { additionalProperties: false }
933
1383
  );
1384
+ var NAME19 = "proxmox_list_snapshots";
1385
+ function createProxmoxListSnapshotsTool(getClient) {
1386
+ return {
1387
+ name: NAME19,
1388
+ label: "proxmox: list snapshots",
1389
+ description: "List snapshots for one LXC container or QEMU VM via GET /nodes/{node}/{type}/{vmid}/snapshot.",
1390
+ parameters: Schema22,
1391
+ execute: async (_id, raw) => {
1392
+ const args = validateToolArgs(Schema22, raw, NAME19);
1393
+ const client = getClient();
1394
+ const { node, type } = await resolveResource(client, args.vmid);
1395
+ const snapshots = await client.get(`/nodes/${node}/${type}/${args.vmid}/snapshot`);
1396
+ return jsonToolResult({ vmid: args.vmid, node, type, count: snapshots.length, snapshots });
1397
+ }
1398
+ };
1399
+ }
934
1400
 
935
1401
  // src/tools/proxmox_guest_network.ts
936
- import { Type as Type23 } from "@sinclair/typebox";
937
- var Schema23 = Type23.Object(
1402
+ import { Type as Type24 } from "@sinclair/typebox";
1403
+ var Schema23 = Type24.Object(
938
1404
  {
939
- vmid: Type23.Integer({ minimum: 1, description: "Container or VM ID." })
1405
+ vmid: Type24.Integer({ minimum: 1, description: "Container or VM ID." })
940
1406
  },
941
1407
  { additionalProperties: false }
942
1408
  );
1409
+ var NAME20 = "proxmox_guest_network";
1410
+ function usableIpv4(ip) {
1411
+ return !ip.startsWith("127.") && !ip.startsWith("169.254.") && ip !== "0.0.0.0";
1412
+ }
1413
+ function createProxmoxGuestNetworkTool(getClient) {
1414
+ return {
1415
+ name: NAME20,
1416
+ label: "proxmox: guest network",
1417
+ description: "Return guest network interfaces and usable IPv4 addresses for a QEMU VM via guest agent or an LXC container via its interfaces endpoint.",
1418
+ parameters: Schema23,
1419
+ execute: async (_id, raw) => {
1420
+ const args = validateToolArgs(Schema23, raw, NAME20);
1421
+ const client = getClient();
1422
+ const { node, type } = await resolveResource(client, args.vmid);
1423
+ if (type === "qemu") {
1424
+ const data = await client.get(
1425
+ `/nodes/${node}/qemu/${args.vmid}/agent/network-get-interfaces`
1426
+ );
1427
+ const interfaces2 = data.result ?? [];
1428
+ const ipv42 = interfaces2.flatMap(
1429
+ (iface) => (iface["ip-addresses"] ?? []).filter((ip) => ip["ip-address-type"] === "ipv4" && ip["ip-address"] && usableIpv4(ip["ip-address"])).map((ip) => ({ interface: iface.name, address: ip["ip-address"], prefix: ip.prefix }))
1430
+ );
1431
+ return jsonToolResult({ vmid: args.vmid, node, type, ipv4: ipv42, interfaces: interfaces2 });
1432
+ }
1433
+ const interfaces = await client.get(`/nodes/${node}/lxc/${args.vmid}/interfaces`);
1434
+ const ipv4 = interfaces.filter((iface) => iface.inet && usableIpv4(iface.inet.split("/")[0])).map((iface) => {
1435
+ const [address, prefix] = iface.inet.split("/");
1436
+ return { interface: iface.name, address, prefix: prefix ? Number(prefix) : void 0 };
1437
+ });
1438
+ return jsonToolResult({ vmid: args.vmid, node, type, ipv4, interfaces });
1439
+ }
1440
+ };
1441
+ }
943
1442
 
944
1443
  // src/tools/proxmox_wait_task.ts
945
- import { Type as Type24 } from "@sinclair/typebox";
946
- var Schema24 = Type24.Object(
1444
+ import { Type as Type25 } from "@sinclair/typebox";
1445
+ var Schema24 = Type25.Object(
947
1446
  {
948
- upid: Type24.String({ minLength: 1, description: "Task UPID to wait for." }),
949
- timeoutSeconds: Type24.Optional(
950
- Type24.Integer({ minimum: 1, maximum: 3600, description: "Max wait time in seconds. Default 60." })
1447
+ upid: Type25.String({ minLength: 1, description: "Task UPID to wait for." }),
1448
+ timeoutSeconds: Type25.Optional(
1449
+ Type25.Integer({ minimum: 1, maximum: 3600, description: "Max wait time in seconds. Default 60." })
951
1450
  ),
952
- intervalMs: Type24.Optional(
953
- Type24.Integer({ minimum: 100, maximum: 1e4, description: "Polling interval in milliseconds. Default 1000." })
1451
+ intervalMs: Type25.Optional(
1452
+ Type25.Integer({ minimum: 100, maximum: 1e4, description: "Polling interval in milliseconds. Default 1000." })
954
1453
  )
955
1454
  },
956
1455
  { additionalProperties: false }
957
1456
  );
1457
+ var NAME21 = "proxmox_wait_task";
1458
+ function createProxmoxWaitTaskTool(getClient) {
1459
+ return {
1460
+ name: NAME21,
1461
+ label: "proxmox: wait task",
1462
+ description: "Poll a Proxmox task by UPID until it stops or the timeout expires. Returns done:false on timeout with the last status.",
1463
+ parameters: Schema24,
1464
+ execute: async (_id, raw) => {
1465
+ const args = validateToolArgs(Schema24, raw, NAME21);
1466
+ const { node } = parseTaskUpid(args.upid);
1467
+ const timeoutMs = (args.timeoutSeconds ?? 60) * 1e3;
1468
+ const intervalMs = args.intervalMs ?? 1e3;
1469
+ const deadline = Date.now() + timeoutMs;
1470
+ const client = getClient();
1471
+ let polls = 0;
1472
+ let lastStatus = null;
1473
+ while (Date.now() <= deadline) {
1474
+ polls += 1;
1475
+ lastStatus = await client.get(
1476
+ `/nodes/${node}/tasks/${encodeURIComponent(args.upid)}/status`
1477
+ );
1478
+ if (lastStatus.status === "stopped" || lastStatus.exitstatus) {
1479
+ return jsonToolResult({ upid: args.upid, node, done: true, polls, status: lastStatus });
1480
+ }
1481
+ await sleep3(Math.min(intervalMs, Math.max(0, deadline - Date.now())));
1482
+ }
1483
+ return jsonToolResult({ upid: args.upid, node, done: false, polls, status: lastStatus });
1484
+ }
1485
+ };
1486
+ }
1487
+ function sleep3(ms) {
1488
+ return new Promise((resolve) => setTimeout(resolve, ms));
1489
+ }
958
1490
 
959
1491
  // src/tools/proxmox_next_vmid.ts
960
- import { Type as Type25 } from "@sinclair/typebox";
961
- var Schema25 = Type25.Object({}, { additionalProperties: false });
1492
+ import { Type as Type26 } from "@sinclair/typebox";
1493
+ var Schema25 = Type26.Object({}, { additionalProperties: false });
1494
+ var NAME22 = "proxmox_next_vmid";
1495
+ function createProxmoxNextVmidTool(getClient) {
1496
+ return {
1497
+ name: NAME22,
1498
+ label: "proxmox: next vmid",
1499
+ description: "Return the next available Proxmox VMID via GET /cluster/nextid.",
1500
+ parameters: Schema25,
1501
+ execute: async (_id, raw = {}) => {
1502
+ validateToolArgs(Schema25, raw, NAME22);
1503
+ const nextid = await getClient().get("/cluster/nextid");
1504
+ return jsonToolResult({ vmid: Number(nextid) });
1505
+ }
1506
+ };
1507
+ }
962
1508
 
963
1509
  // src/tools/proxmox_list_pool_resources.ts
964
- import { Type as Type26 } from "@sinclair/typebox";
965
- var Schema26 = Type26.Object(
1510
+ import { Type as Type27 } from "@sinclair/typebox";
1511
+ var Schema26 = Type27.Object(
966
1512
  {
967
- pool: Type26.Optional(
968
- Type26.String({ minLength: 1, description: "Pool ID to inspect (default mcp-smoke)." })
1513
+ pool: Type27.Optional(
1514
+ Type27.String({ minLength: 1, description: "Pool ID to inspect (default mcp-smoke)." })
969
1515
  )
970
1516
  },
971
1517
  { additionalProperties: false }
972
1518
  );
1519
+ var NAME23 = "proxmox_list_pool_resources";
1520
+ function createProxmoxListPoolResourcesTool(getClient) {
1521
+ return {
1522
+ name: NAME23,
1523
+ label: "proxmox: list pool resources",
1524
+ description: "List resources assigned to a Proxmox pool (GET /pools/{pool}). Defaults to the mcp-smoke pool for smoke-test audits.",
1525
+ parameters: Schema26,
1526
+ execute: async (_id = "id", raw = {}) => {
1527
+ const args = validateToolArgs(Schema26, raw, NAME23);
1528
+ const pool = args.pool ?? "mcp-smoke";
1529
+ const detail = await getClient().get(`/pools/${encodeURIComponent(pool)}`);
1530
+ const members = Array.isArray(detail.members) ? detail.members : [];
1531
+ return jsonToolResult({
1532
+ pool,
1533
+ comment: detail.comment,
1534
+ count: members.length,
1535
+ resources: members
1536
+ });
1537
+ }
1538
+ };
1539
+ }
973
1540
 
974
1541
  // src/tools/proxmox_create_container.ts
975
- import { Type as Type27 } from "@sinclair/typebox";
976
- var Schema27 = Type27.Object(
1542
+ import { Type as Type28 } from "@sinclair/typebox";
1543
+ var Schema27 = Type28.Object(
977
1544
  {
978
- vmid: Type27.Integer({ minimum: 1, description: "VMID for the new container." }),
979
- hostname: Type27.String({ minLength: 1, description: "Container hostname." }),
980
- ostemplate: Type27.String({
1545
+ vmid: Type28.Integer({ minimum: 1, description: "VMID for the new container." }),
1546
+ hostname: Type28.String({ minLength: 1, description: "Container hostname." }),
1547
+ ostemplate: Type28.String({
981
1548
  minLength: 1,
982
1549
  description: "OS template volid (e.g. 'local:vztmpl/ubuntu-24.04-standard_*.tar.zst')."
983
1550
  }),
984
- node: Type27.Optional(
985
- Type27.String({ minLength: 1, description: "Node to create on (defaults to first node)." })
1551
+ node: Type28.Optional(
1552
+ Type28.String({ minLength: 1, description: "Node to create on (defaults to first node)." })
986
1553
  ),
987
- storage: Type27.Optional(
988
- Type27.String({ minLength: 1, description: "Root storage (default 'local-lvm')." })
1554
+ storage: Type28.Optional(
1555
+ Type28.String({ minLength: 1, description: "Root storage (default 'local-lvm')." })
989
1556
  ),
990
- memory: Type27.Optional(
991
- Type27.Integer({ minimum: 16, description: "Memory in MiB (default 512)." })
1557
+ memory: Type28.Optional(
1558
+ Type28.Integer({ minimum: 16, description: "Memory in MiB (default 512)." })
992
1559
  ),
993
- cores: Type27.Optional(
994
- Type27.Integer({ minimum: 1, description: "CPU cores (default 1)." })
1560
+ cores: Type28.Optional(
1561
+ Type28.Integer({ minimum: 1, description: "CPU cores (default 1)." })
995
1562
  ),
996
- rootfs_size: Type27.Optional(
997
- Type27.String({ minLength: 1, description: "Root filesystem size in GB (default '8')." })
1563
+ rootfs_size: Type28.Optional(
1564
+ Type28.String({ minLength: 1, description: "Root filesystem size in GB (default '8')." })
998
1565
  ),
999
- net: Type27.Optional(
1000
- Type27.String({
1566
+ net: Type28.Optional(
1567
+ Type28.String({
1001
1568
  minLength: 1,
1002
1569
  description: "Network config for net0 (default 'name=eth0,bridge=vmbr0,ip=dhcp')."
1003
1570
  })
1004
1571
  ),
1005
- start: Type27.Optional(
1006
- Type27.Boolean({ description: "Start after create (default false)." })
1572
+ start: Type28.Optional(
1573
+ Type28.Boolean({ description: "Start after create (default false)." })
1007
1574
  ),
1008
- pool: Type27.Optional(
1009
- Type27.String({ minLength: 1, description: "Optional resource pool ID to place the container into." })
1575
+ pool: Type28.Optional(
1576
+ Type28.String({ minLength: 1, description: "Optional resource pool ID to place the container into." })
1010
1577
  ),
1011
- onboot: Type27.Optional(
1012
- Type27.Boolean({ description: "Start container on host boot (default false)." })
1578
+ onboot: Type28.Optional(
1579
+ Type28.Boolean({ description: "Start container on host boot (default false)." })
1013
1580
  ),
1014
- unprivileged: Type27.Optional(
1015
- Type27.Boolean({ description: "Create an unprivileged container (default true)." })
1581
+ unprivileged: Type28.Optional(
1582
+ Type28.Boolean({ description: "Create an unprivileged container (default true)." })
1016
1583
  ),
1017
- protection: Type27.Optional(
1018
- Type27.Boolean({ description: "Enable Proxmox protection flag (default false)." })
1584
+ protection: Type28.Optional(
1585
+ Type28.Boolean({ description: "Enable Proxmox protection flag (default false)." })
1019
1586
  ),
1020
- features: Type27.Optional(
1021
- Type27.String({ minLength: 1, description: "Optional LXC features string, e.g. 'nesting=1'." })
1587
+ features: Type28.Optional(
1588
+ Type28.String({ minLength: 1, description: "Optional LXC features string, e.g. 'nesting=1'." })
1022
1589
  ),
1023
- description: Type27.Optional(
1024
- Type27.String({ description: "Optional container description." })
1590
+ description: Type28.Optional(
1591
+ Type28.String({ description: "Optional container description." })
1025
1592
  ),
1026
- tags: Type27.Optional(
1027
- Type27.String({ minLength: 1, description: "Optional semicolon-delimited Proxmox tags." })
1593
+ tags: Type28.Optional(
1594
+ Type28.String({ minLength: 1, description: "Optional semicolon-delimited Proxmox tags." })
1028
1595
  ),
1029
- password: Type27.Optional(
1030
- Type27.String({ description: "Root password (optional)." })
1596
+ password: Type28.Optional(
1597
+ Type28.String({ description: "Root password (optional)." })
1031
1598
  ),
1032
- ssh_public_keys: Type27.Optional(
1033
- Type27.String({ description: "SSH public keys (optional)." })
1599
+ ssh_public_keys: Type28.Optional(
1600
+ Type28.String({ description: "SSH public keys (optional)." })
1034
1601
  ),
1035
- confirm: Type27.Boolean({
1602
+ confirm: Type28.Boolean({
1036
1603
  description: "Must be true to write. Tier-2 safe-write gate."
1037
- })
1604
+ }),
1605
+ ...taskWaitFields
1038
1606
  },
1039
1607
  { additionalProperties: false }
1040
1608
  );
1041
- var NAME13 = "proxmox_create_container";
1609
+ var NAME24 = "proxmox_create_container";
1042
1610
  function createProxmoxCreateContainerTool(getClient) {
1043
1611
  return {
1044
- name: NAME13,
1612
+ name: NAME24,
1045
1613
  label: "proxmox: create container",
1046
1614
  description: "Create a new LXC container on a node (POST /nodes/{node}/lxc) with sensible defaults (storage local-lvm, 512MiB, 1 core, 8GB rootfs, DHCP net). Tier-2 write; requires confirm:true.",
1047
1615
  parameters: Schema27,
1048
1616
  execute: async (_id, raw) => {
1049
- assertConfirmedWrite(raw, NAME13);
1050
- const args = validateToolArgs(Schema27, raw, NAME13);
1617
+ assertConfirmedWrite(raw, NAME24);
1618
+ const args = validateToolArgs(Schema27, raw, NAME24);
1051
1619
  if (typeof args.password === "string" && args.password.length > 0) {
1052
1620
  registerSecret(args.password);
1053
1621
  }
1054
1622
  const client = getClient();
1055
1623
  let node = args.node;
1056
- if (!node) {
1624
+ if (node) {
1625
+ assertSafePathSegment(node, "node");
1626
+ } else {
1057
1627
  const nodes = await client.get("/cluster/resources?type=node");
1058
1628
  if (nodes.length === 0) throw new Error("no nodes found in cluster resources");
1059
1629
  node = nodes[0].node;
@@ -1091,128 +1661,133 @@ function createProxmoxCreateContainerTool(getClient) {
1091
1661
  body.tags = args.tags;
1092
1662
  }
1093
1663
  const upid = await client.post(`/nodes/${node}/lxc`, body);
1664
+ const task = await resolveTaskWait(client, upid, args);
1094
1665
  return jsonToolResult({
1095
1666
  vmid: args.vmid,
1096
1667
  node,
1097
1668
  hostname: args.hostname,
1098
- upid
1669
+ upid,
1670
+ ...task ? { task } : {}
1099
1671
  });
1100
1672
  }
1101
1673
  };
1102
1674
  }
1103
1675
 
1104
1676
  // src/tools/proxmox_create_vm.ts
1105
- import { Type as Type28 } from "@sinclair/typebox";
1106
- var Schema28 = Type28.Object(
1677
+ import { Type as Type29 } from "@sinclair/typebox";
1678
+ var Schema28 = Type29.Object(
1107
1679
  {
1108
- vmid: Type28.Integer({ minimum: 1, description: "VMID for the new VM." }),
1109
- name: Type28.String({ minLength: 1, description: "VM display name." }),
1110
- node: Type28.Optional(
1111
- Type28.String({ minLength: 1, description: "Node to create on (defaults to first node)." })
1680
+ vmid: Type29.Integer({ minimum: 1, description: "VMID for the new VM." }),
1681
+ name: Type29.String({ minLength: 1, description: "VM display name." }),
1682
+ node: Type29.Optional(
1683
+ Type29.String({ minLength: 1, description: "Node to create on (defaults to first node)." })
1112
1684
  ),
1113
- memory: Type28.Optional(
1114
- Type28.Integer({ minimum: 16, description: "Memory in MiB (default 2048)." })
1685
+ memory: Type29.Optional(
1686
+ Type29.Integer({ minimum: 16, description: "Memory in MiB (default 2048)." })
1115
1687
  ),
1116
- cores: Type28.Optional(
1117
- Type28.Integer({ minimum: 1, description: "CPU cores (default 2)." })
1688
+ cores: Type29.Optional(
1689
+ Type29.Integer({ minimum: 1, description: "CPU cores (default 2)." })
1118
1690
  ),
1119
- iso: Type28.Optional(
1120
- Type28.String({
1691
+ iso: Type29.Optional(
1692
+ Type29.String({
1121
1693
  minLength: 1,
1122
1694
  description: "ISO volid for install media (e.g. 'local:iso/ubuntu-24.04.iso'). If set, attaches as ide2 cdrom."
1123
1695
  })
1124
1696
  ),
1125
- disk_size: Type28.Optional(
1126
- Type28.String({ minLength: 1, description: "Primary disk size in GB on scsi0 (default '32')." })
1697
+ disk_size: Type29.Optional(
1698
+ Type29.String({ minLength: 1, description: "Primary disk size in GB on scsi0 (default '32')." })
1127
1699
  ),
1128
- storage: Type28.Optional(
1129
- Type28.String({ minLength: 1, description: "Disk storage (default 'local-lvm')." })
1700
+ storage: Type29.Optional(
1701
+ Type29.String({ minLength: 1, description: "Disk storage (default 'local-lvm')." })
1130
1702
  ),
1131
- net: Type28.Optional(
1132
- Type28.String({
1703
+ net: Type29.Optional(
1704
+ Type29.String({
1133
1705
  minLength: 1,
1134
1706
  description: "Network config for net0 (default 'model=virtio,bridge=vmbr0')."
1135
1707
  })
1136
1708
  ),
1137
- start: Type28.Optional(
1138
- Type28.Boolean({ description: "Start after create (default false)." })
1709
+ start: Type29.Optional(
1710
+ Type29.Boolean({ description: "Start after create (default false)." })
1139
1711
  ),
1140
- pool: Type28.Optional(
1141
- Type28.String({ minLength: 1, description: "Optional resource pool ID to place the VM into." })
1712
+ pool: Type29.Optional(
1713
+ Type29.String({ minLength: 1, description: "Optional resource pool ID to place the VM into." })
1142
1714
  ),
1143
- onboot: Type28.Optional(
1144
- Type28.Boolean({ description: "Start VM on host boot (default false)." })
1715
+ onboot: Type29.Optional(
1716
+ Type29.Boolean({ description: "Start VM on host boot (default false)." })
1145
1717
  ),
1146
- protection: Type28.Optional(
1147
- Type28.Boolean({ description: "Enable Proxmox protection flag (default false)." })
1718
+ protection: Type29.Optional(
1719
+ Type29.Boolean({ description: "Enable Proxmox protection flag (default false)." })
1148
1720
  ),
1149
- agent: Type28.Optional(
1150
- Type28.Boolean({ description: "Enable QEMU guest agent in VM config (default false)." })
1721
+ agent: Type29.Optional(
1722
+ Type29.Boolean({ description: "Enable QEMU guest agent in VM config (default false)." })
1151
1723
  ),
1152
- scsihw: Type28.Optional(
1153
- Type28.String({ minLength: 1, description: "Optional SCSI controller, e.g. 'virtio-scsi-pci'." })
1724
+ scsihw: Type29.Optional(
1725
+ Type29.String({ minLength: 1, description: "Optional SCSI controller, e.g. 'virtio-scsi-pci'." })
1154
1726
  ),
1155
- boot: Type28.Optional(
1156
- Type28.String({ minLength: 1, description: "Optional boot order string." })
1727
+ boot: Type29.Optional(
1728
+ Type29.String({ minLength: 1, description: "Optional boot order string." })
1157
1729
  ),
1158
- bios: Type28.Optional(
1159
- Type28.Union([Type28.Literal("seabios"), Type28.Literal("ovmf")], { description: "Optional VM BIOS type." })
1730
+ bios: Type29.Optional(
1731
+ Type29.Union([Type29.Literal("seabios"), Type29.Literal("ovmf")], { description: "Optional VM BIOS type." })
1160
1732
  ),
1161
- machine: Type28.Optional(
1162
- Type28.String({ minLength: 1, description: "Optional machine type." })
1733
+ machine: Type29.Optional(
1734
+ Type29.String({ minLength: 1, description: "Optional machine type." })
1163
1735
  ),
1164
- cpu: Type28.Optional(
1165
- Type28.String({ minLength: 1, description: "Optional CPU type." })
1736
+ cpu: Type29.Optional(
1737
+ Type29.String({ minLength: 1, description: "Optional CPU type." })
1166
1738
  ),
1167
- sockets: Type28.Optional(
1168
- Type28.Integer({ minimum: 1, description: "Optional socket count." })
1739
+ sockets: Type29.Optional(
1740
+ Type29.Integer({ minimum: 1, description: "Optional socket count." })
1169
1741
  ),
1170
- description: Type28.Optional(
1171
- Type28.String({ description: "Optional VM description." })
1742
+ description: Type29.Optional(
1743
+ Type29.String({ description: "Optional VM description." })
1172
1744
  ),
1173
- tags: Type28.Optional(
1174
- Type28.String({ minLength: 1, description: "Optional semicolon-delimited Proxmox tags." })
1745
+ tags: Type29.Optional(
1746
+ Type29.String({ minLength: 1, description: "Optional semicolon-delimited Proxmox tags." })
1175
1747
  ),
1176
- ciuser: Type28.Optional(
1177
- Type28.String({ minLength: 1, description: "Optional cloud-init username." })
1748
+ ciuser: Type29.Optional(
1749
+ Type29.String({ minLength: 1, description: "Optional cloud-init username." })
1178
1750
  ),
1179
- cipassword: Type28.Optional(
1180
- Type28.String({ description: "Optional cloud-init password." })
1751
+ cipassword: Type29.Optional(
1752
+ Type29.String({ description: "Optional cloud-init password." })
1181
1753
  ),
1182
- sshkeys: Type28.Optional(
1183
- Type28.String({ description: "Optional cloud-init SSH public keys." })
1754
+ sshkeys: Type29.Optional(
1755
+ Type29.String({ description: "Optional cloud-init SSH public keys." })
1184
1756
  ),
1185
- ipconfig0: Type28.Optional(
1186
- Type28.String({ minLength: 1, description: "Optional cloud-init ipconfig0, e.g. 'ip=dhcp'." })
1757
+ ipconfig0: Type29.Optional(
1758
+ Type29.String({ minLength: 1, description: "Optional cloud-init ipconfig0, e.g. 'ip=dhcp'." })
1187
1759
  ),
1188
- nameserver: Type28.Optional(
1189
- Type28.String({ minLength: 1, description: "Optional cloud-init DNS server list." })
1760
+ nameserver: Type29.Optional(
1761
+ Type29.String({ minLength: 1, description: "Optional cloud-init DNS server list." })
1190
1762
  ),
1191
- searchdomain: Type28.Optional(
1192
- Type28.String({ minLength: 1, description: "Optional cloud-init DNS search domain." })
1763
+ searchdomain: Type29.Optional(
1764
+ Type29.String({ minLength: 1, description: "Optional cloud-init DNS search domain." })
1193
1765
  ),
1194
- confirm: Type28.Boolean({
1766
+ confirm: Type29.Boolean({
1195
1767
  description: "Must be true to write. Tier-2 safe-write gate."
1196
- })
1768
+ }),
1769
+ ...taskWaitFields
1197
1770
  },
1198
1771
  { additionalProperties: false }
1199
1772
  );
1200
- var NAME14 = "proxmox_create_vm";
1773
+ var NAME25 = "proxmox_create_vm";
1201
1774
  function createProxmoxCreateVmTool(getClient) {
1202
1775
  return {
1203
- name: NAME14,
1776
+ name: NAME25,
1204
1777
  label: "proxmox: create vm",
1205
1778
  description: "Create a new QEMU VM on a node (POST /nodes/{node}/qemu) with sensible defaults (2GiB, 2 cores, 32GB disk on local-lvm, virtio net). Optionally attaches an ISO as ide2 cdrom. Tier-2 write; requires confirm:true.",
1206
1779
  parameters: Schema28,
1207
1780
  execute: async (_id, raw) => {
1208
- assertConfirmedWrite(raw, NAME14);
1209
- const args = validateToolArgs(Schema28, raw, NAME14);
1781
+ assertConfirmedWrite(raw, NAME25);
1782
+ const args = validateToolArgs(Schema28, raw, NAME25);
1210
1783
  if (typeof args.cipassword === "string" && args.cipassword.length > 0) {
1211
1784
  registerSecret(args.cipassword);
1212
1785
  }
1213
1786
  const client = getClient();
1214
1787
  let node = args.node;
1215
- if (!node) {
1788
+ if (node) {
1789
+ assertSafePathSegment(node, "node");
1790
+ } else {
1216
1791
  const nodes = await client.get("/cluster/resources?type=node");
1217
1792
  if (nodes.length === 0) throw new Error("no nodes found in cluster resources");
1218
1793
  node = nodes[0].node;
@@ -1240,57 +1815,60 @@ function createProxmoxCreateVmTool(getClient) {
1240
1815
  }
1241
1816
  if (typeof args.sockets === "number") body.sockets = args.sockets;
1242
1817
  const upid = await client.post(`/nodes/${node}/qemu`, body);
1818
+ const task = await resolveTaskWait(client, upid, args);
1243
1819
  return jsonToolResult({
1244
1820
  vmid: args.vmid,
1245
1821
  node,
1246
1822
  name: args.name,
1247
- upid
1823
+ upid,
1824
+ ...task ? { task } : {}
1248
1825
  });
1249
1826
  }
1250
1827
  };
1251
1828
  }
1252
1829
 
1253
1830
  // src/tools/proxmox_clone_resource.ts
1254
- import { Type as Type29 } from "@sinclair/typebox";
1255
- var Schema29 = Type29.Object(
1831
+ import { Type as Type30 } from "@sinclair/typebox";
1832
+ var Schema29 = Type30.Object(
1256
1833
  {
1257
- source_vmid: Type29.Integer({ minimum: 1, description: "Source CT/VM ID to clone from." }),
1258
- new_vmid: Type29.Integer({ minimum: 1, description: "VMID for the cloned resource." }),
1259
- name: Type29.String({ minLength: 1, description: "Name/hostname for the new clone." }),
1260
- full: Type29.Optional(
1261
- Type29.Boolean({ description: "Full clone (default true). Set false for a linked clone." })
1834
+ source_vmid: Type30.Integer({ minimum: 1, description: "Source CT/VM ID to clone from." }),
1835
+ new_vmid: Type30.Integer({ minimum: 1, description: "VMID for the cloned resource." }),
1836
+ name: Type30.String({ minLength: 1, description: "Name/hostname for the new clone." }),
1837
+ full: Type30.Optional(
1838
+ Type30.Boolean({ description: "Full clone (default true). Set false for a linked clone." })
1262
1839
  ),
1263
- storage: Type29.Optional(
1264
- Type29.String({ minLength: 1, description: "Target storage (default: same as source)." })
1840
+ storage: Type30.Optional(
1841
+ Type30.String({ minLength: 1, description: "Target storage (default: same as source)." })
1265
1842
  ),
1266
- target_node: Type29.Optional(
1267
- Type29.String({ minLength: 1, description: "Optional target node for the clone." })
1843
+ target_node: Type30.Optional(
1844
+ Type30.String({ minLength: 1, description: "Optional target node for the clone." })
1268
1845
  ),
1269
- pool: Type29.Optional(
1270
- Type29.String({ minLength: 1, description: "Optional resource pool ID for the clone." })
1846
+ pool: Type30.Optional(
1847
+ Type30.String({ minLength: 1, description: "Optional resource pool ID for the clone." })
1271
1848
  ),
1272
- snapname: Type29.Optional(
1273
- Type29.String({ minLength: 1, description: "Clone from a named snapshot (optional)." })
1849
+ snapname: Type30.Optional(
1850
+ Type30.String({ minLength: 1, description: "Clone from a named snapshot (optional)." })
1274
1851
  ),
1275
- description: Type29.Optional(
1276
- Type29.String({ description: "Optional description for the clone." })
1852
+ description: Type30.Optional(
1853
+ Type30.String({ description: "Optional description for the clone." })
1277
1854
  ),
1278
- confirm: Type29.Boolean({
1855
+ confirm: Type30.Boolean({
1279
1856
  description: "Must be true to write. Tier-2 safe-write gate."
1280
- })
1857
+ }),
1858
+ ...taskWaitFields
1281
1859
  },
1282
1860
  { additionalProperties: false }
1283
1861
  );
1284
- var NAME15 = "proxmox_clone_resource";
1862
+ var NAME26 = "proxmox_clone_resource";
1285
1863
  function createProxmoxCloneResourceTool(getClient) {
1286
1864
  return {
1287
- name: NAME15,
1865
+ name: NAME26,
1288
1866
  label: "proxmox: clone resource",
1289
1867
  description: "Clone an existing LXC or QEMU resource by source_vmid to a new_vmid (POST /nodes/{node}/{type}/{source_vmid}/clone). Resolves source node/type from cluster resources. Tier-2 write; requires confirm:true.",
1290
1868
  parameters: Schema29,
1291
1869
  execute: async (_id, raw) => {
1292
- assertConfirmedWrite(raw, NAME15);
1293
- const args = validateToolArgs(Schema29, raw, NAME15);
1870
+ assertConfirmedWrite(raw, NAME26);
1871
+ const args = validateToolArgs(Schema29, raw, NAME26);
1294
1872
  const client = getClient();
1295
1873
  const { node, type } = await resolveResource(client, args.source_vmid);
1296
1874
  const body = {
@@ -1317,53 +1895,56 @@ function createProxmoxCloneResourceTool(getClient) {
1317
1895
  `/nodes/${node}/${type}/${args.source_vmid}/clone`,
1318
1896
  body
1319
1897
  );
1898
+ const task = await resolveTaskWait(client, upid, args);
1320
1899
  return jsonToolResult({
1321
1900
  source_vmid: args.source_vmid,
1322
1901
  new_vmid: args.new_vmid,
1323
1902
  node,
1324
1903
  type,
1325
1904
  name: args.name,
1326
- upid
1905
+ upid,
1906
+ ...task ? { task } : {}
1327
1907
  });
1328
1908
  }
1329
1909
  };
1330
1910
  }
1331
1911
 
1332
1912
  // src/tools/proxmox_destroy_resource.ts
1333
- import { Type as Type30 } from "@sinclair/typebox";
1334
- var Schema30 = Type30.Object(
1913
+ import { Type as Type31 } from "@sinclair/typebox";
1914
+ var Schema30 = Type31.Object(
1335
1915
  {
1336
- vmid: Type30.Integer({ minimum: 1, description: "Container or VM ID to destroy." }),
1337
- purge: Type30.Optional(
1338
- Type30.Boolean({
1916
+ vmid: Type31.Integer({ minimum: 1, description: "Container or VM ID to destroy." }),
1917
+ purge: Type31.Optional(
1918
+ Type31.Boolean({
1339
1919
  description: "Remove from PVE backup/replication config too (default true)."
1340
1920
  })
1341
1921
  ),
1342
- force: Type30.Optional(
1343
- Type30.Boolean({
1922
+ force: Type31.Optional(
1923
+ Type31.Boolean({
1344
1924
  description: "Allow destroying a running VM (default false)."
1345
1925
  })
1346
1926
  ),
1347
- confirm: Type30.Boolean({
1927
+ confirm: Type31.Boolean({
1348
1928
  description: "Must be true. Tier-3 destructive gate."
1349
1929
  }),
1350
- destructive: Type30.Boolean({
1930
+ destructive: Type31.Boolean({
1351
1931
  description: "Must be true. Tier-3 destructive gate."
1352
- })
1932
+ }),
1933
+ ...taskWaitFields
1353
1934
  },
1354
1935
  { additionalProperties: false }
1355
1936
  );
1356
- var NAME16 = "proxmox_destroy_resource";
1937
+ var NAME27 = "proxmox_destroy_resource";
1357
1938
  function createProxmoxDestroyResourceTool(getClient) {
1358
1939
  return {
1359
- name: NAME16,
1940
+ name: NAME27,
1360
1941
  label: "proxmox: destroy resource",
1361
1942
  description: "Permanently delete an LXC container or QEMU VM by vmid (DELETE /nodes/{node}/{type}/{vmid}). Tier-3 destructive; requires confirm:true, destructive:true, and env PROXMOX_ENABLE_DESTRUCTIVE=1.",
1362
1943
  parameters: Schema30,
1363
1944
  execute: async (_id, raw) => {
1364
- assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME16);
1365
- assertDestructive(raw, NAME16);
1366
- const args = validateToolArgs(Schema30, raw, NAME16);
1945
+ assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME27);
1946
+ assertDestructive(raw, NAME27);
1947
+ const args = validateToolArgs(Schema30, raw, NAME27);
1367
1948
  const purge = args.purge !== false;
1368
1949
  const force = args.force === true;
1369
1950
  const client = getClient();
@@ -1377,83 +1958,177 @@ function createProxmoxDestroyResourceTool(getClient) {
1377
1958
  const qs = params.toString();
1378
1959
  const path2 = qs.length > 0 ? `/nodes/${node}/${type}/${args.vmid}?${qs}` : `/nodes/${node}/${type}/${args.vmid}`;
1379
1960
  const upid = await client.delete(path2);
1380
- return jsonToolResult({ vmid: args.vmid, node, type, upid });
1961
+ const task = await resolveTaskWait(client, upid, args);
1962
+ return jsonToolResult({ vmid: args.vmid, node, type, upid, ...task ? { task } : {} });
1381
1963
  }
1382
1964
  };
1383
1965
  }
1384
1966
 
1385
1967
  // src/tools/proxmox_cleanup_smoke_resources.ts
1386
- import { Type as Type31 } from "@sinclair/typebox";
1387
- var Schema31 = Type31.Object(
1968
+ import { Type as Type32 } from "@sinclair/typebox";
1969
+ var Schema31 = Type32.Object(
1388
1970
  {
1389
- pool: Type31.Optional(
1390
- Type31.String({ minLength: 1, description: "Pool ID to clean up (default mcp-smoke)." })
1971
+ pool: Type32.Optional(
1972
+ Type32.String({ minLength: 1, description: "Pool ID to clean up (default mcp-smoke)." })
1391
1973
  ),
1392
- name_prefix: Type31.Optional(
1393
- Type31.String({
1974
+ name_prefix: Type32.Optional(
1975
+ Type32.String({
1394
1976
  minLength: 1,
1395
1977
  description: "Only delete guest names starting with this prefix (default mcp-smoke-)."
1396
1978
  })
1397
1979
  ),
1398
- force: Type31.Optional(
1399
- Type31.Boolean({
1980
+ force: Type32.Optional(
1981
+ Type32.Boolean({
1400
1982
  description: "Allow deleting running smoke guests. Also passes force=1 for LXC cleanup (default false)."
1401
1983
  })
1402
1984
  ),
1403
- dry_run: Type31.Optional(
1404
- Type31.Boolean({ description: "Preview matching targets without deleting them (default true)." })
1985
+ dry_run: Type32.Optional(
1986
+ Type32.Boolean({ description: "Preview matching targets without deleting them (default true)." })
1405
1987
  ),
1406
- wait: Type31.Optional(
1407
- Type31.Boolean({ description: "Wait for delete tasks to finish when dry_run:false (default true)." })
1988
+ wait: Type32.Optional(
1989
+ Type32.Boolean({ description: "Wait for delete tasks to finish when dry_run:false (default true)." })
1408
1990
  ),
1409
- confirm: Type31.Optional(
1410
- Type31.Boolean({ description: "Must be true when dry_run:false. Tier-3 destructive gate." })
1991
+ confirm: Type32.Optional(
1992
+ Type32.Boolean({ description: "Must be true when dry_run:false. Tier-3 destructive gate." })
1411
1993
  ),
1412
- destructive: Type31.Optional(
1413
- Type31.Boolean({ description: "Must be true when dry_run:false. Tier-3 destructive gate." })
1994
+ destructive: Type32.Optional(
1995
+ Type32.Boolean({ description: "Must be true when dry_run:false. Tier-3 destructive gate." })
1414
1996
  ),
1415
- timeoutSeconds: Type31.Optional(
1416
- Type31.Integer({ minimum: 1, maximum: 3600, description: "Max seconds to wait per delete task (default 180)." })
1997
+ timeoutSeconds: Type32.Optional(
1998
+ Type32.Integer({ minimum: 1, maximum: 3600, description: "Max seconds to wait per delete task (default 180)." })
1417
1999
  ),
1418
- intervalMs: Type31.Optional(
1419
- Type31.Integer({ minimum: 100, maximum: 1e4, description: "Task polling interval in milliseconds (default 1000)." })
2000
+ intervalMs: Type32.Optional(
2001
+ Type32.Integer({ minimum: 100, maximum: 1e4, description: "Task polling interval in milliseconds (default 1000)." })
1420
2002
  )
1421
2003
  },
1422
2004
  { additionalProperties: false }
1423
2005
  );
2006
+ var NAME28 = "proxmox_cleanup_smoke_resources";
2007
+ function normalizeType(type) {
2008
+ if (type === "qemu") return "qemu";
2009
+ if (type === "lxc" || type === "openvz") return "lxc";
2010
+ return null;
2011
+ }
2012
+ function targetFromMember(member, namePrefix) {
2013
+ const type = normalizeType(member.type);
2014
+ const name = member.name ?? "";
2015
+ if (!type || typeof member.vmid !== "number" || !member.node || !name.startsWith(namePrefix)) return null;
2016
+ return {
2017
+ vmid: member.vmid,
2018
+ node: member.node,
2019
+ type,
2020
+ name,
2021
+ status: member.status
2022
+ };
2023
+ }
2024
+ async function waitForTask(client, upid, timeoutSeconds, intervalMs) {
2025
+ const { node } = parseTaskUpid(upid);
2026
+ const deadline = Date.now() + timeoutSeconds * 1e3;
2027
+ let polls = 0;
2028
+ let status = null;
2029
+ while (Date.now() <= deadline) {
2030
+ polls += 1;
2031
+ status = await client.get(`/nodes/${node}/tasks/${encodeURIComponent(upid)}/status`);
2032
+ if (status.status === "stopped" || status.exitstatus) {
2033
+ return { upid, node, done: true, polls, status };
2034
+ }
2035
+ await new Promise((resolve) => setTimeout(resolve, Math.min(intervalMs, Math.max(0, deadline - Date.now()))));
2036
+ }
2037
+ return { upid, node, done: false, polls, status };
2038
+ }
2039
+ function createProxmoxCleanupSmokeResourcesTool(getClient) {
2040
+ return {
2041
+ name: NAME28,
2042
+ label: "proxmox: cleanup smoke resources",
2043
+ description: "Preview or destroy smoke-test LXC/QEMU resources from a pool when their names match the smoke prefix. Defaults to dry_run:true. Actual deletion requires dry_run:false, confirm:true, destructive:true, and PROXMOX_ENABLE_DESTRUCTIVE=1.",
2044
+ parameters: Schema31,
2045
+ execute: async (_id, raw) => {
2046
+ const args = validateToolArgs(Schema31, raw, NAME28);
2047
+ const pool = args.pool ?? "mcp-smoke";
2048
+ const namePrefix = args.name_prefix ?? "mcp-smoke-";
2049
+ const force = args.force === true;
2050
+ const dryRun = args.dry_run !== false;
2051
+ const wait = args.wait !== false;
2052
+ const client = getClient();
2053
+ const detail = await client.get(`/pools/${encodeURIComponent(pool)}`);
2054
+ const members = Array.isArray(detail.members) ? detail.members : [];
2055
+ const targets = members.map((member) => targetFromMember(member, namePrefix)).filter((target) => target !== null);
2056
+ const running = targets.filter((target) => target.status === "running");
2057
+ const deleteTargets = force ? targets : targets.filter((target) => target.status !== "running");
2058
+ const skippedRunning = force ? [] : running;
2059
+ if (dryRun) {
2060
+ return jsonToolResult({
2061
+ pool,
2062
+ name_prefix: namePrefix,
2063
+ dry_run: true,
2064
+ matched: targets.length,
2065
+ targets,
2066
+ skipped_running: skippedRunning,
2067
+ skipped: members.length - targets.length + skippedRunning.length
2068
+ });
2069
+ }
2070
+ assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME28);
2071
+ assertDestructive(raw, NAME28);
2072
+ const destroyed = [];
2073
+ for (const target of deleteTargets) {
2074
+ const params = new URLSearchParams();
2075
+ params.append("purge", "1");
2076
+ params.append("destroy-unreferenced-disks", "1");
2077
+ if (force && target.type === "lxc") params.append("force", "1");
2078
+ const upid = await client.delete(
2079
+ `/nodes/${target.node}/${target.type}/${target.vmid}?${params.toString()}`
2080
+ );
2081
+ const entry = { ...target, upid };
2082
+ if (wait) {
2083
+ entry.wait = await waitForTask(client, upid, args.timeoutSeconds ?? 180, args.intervalMs ?? 1e3);
2084
+ }
2085
+ destroyed.push(entry);
2086
+ }
2087
+ return jsonToolResult({
2088
+ pool,
2089
+ name_prefix: namePrefix,
2090
+ dry_run: false,
2091
+ matched: targets.length,
2092
+ destroyed,
2093
+ skipped_running: skippedRunning,
2094
+ skipped: members.length - targets.length + skippedRunning.length
2095
+ });
2096
+ }
2097
+ };
2098
+ }
1424
2099
 
1425
2100
  // src/tools/proxmox_delete_snapshot.ts
1426
- import { Type as Type32 } from "@sinclair/typebox";
1427
- var Schema32 = Type32.Object(
2101
+ import { Type as Type33 } from "@sinclair/typebox";
2102
+ var Schema32 = Type33.Object(
1428
2103
  {
1429
- vmid: Type32.Integer({ minimum: 1, description: "Container or VM ID." }),
1430
- snapname: Type32.String({
2104
+ vmid: Type33.Integer({ minimum: 1, description: "Container or VM ID." }),
2105
+ snapname: Type33.String({
1431
2106
  minLength: 1,
1432
2107
  description: "Snapshot name to delete."
1433
2108
  }),
1434
- confirm: Type32.Boolean({
2109
+ confirm: Type33.Boolean({
1435
2110
  description: "Must be true. Tier-3 destructive gate."
1436
2111
  }),
1437
- destructive: Type32.Boolean({
2112
+ destructive: Type33.Boolean({
1438
2113
  description: "Must be true. Tier-3 destructive gate."
1439
2114
  })
1440
2115
  },
1441
2116
  { additionalProperties: false }
1442
2117
  );
1443
- var NAME17 = "proxmox_delete_snapshot";
2118
+ var NAME29 = "proxmox_delete_snapshot";
1444
2119
  function createProxmoxDeleteSnapshotTool(getClient) {
1445
2120
  return {
1446
- name: NAME17,
2121
+ name: NAME29,
1447
2122
  label: "proxmox: delete snapshot",
1448
2123
  description: "Delete a named snapshot from an LXC container or QEMU VM (DELETE /nodes/{node}/{type}/{vmid}/snapshot/{snapname}). Tier-3 destructive; requires confirm:true, destructive:true, and env PROXMOX_ENABLE_DESTRUCTIVE=1.",
1449
2124
  parameters: Schema32,
1450
2125
  execute: async (_id, raw) => {
1451
- assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME17);
1452
- assertDestructive(raw, NAME17);
2126
+ assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME29);
2127
+ assertDestructive(raw, NAME29);
1453
2128
  const args = validateToolArgs(
1454
2129
  Schema32,
1455
2130
  raw,
1456
- NAME17
2131
+ NAME29
1457
2132
  );
1458
2133
  const client = getClient();
1459
2134
  const { node, type } = await resolveResource(client, args.vmid);
@@ -1466,30 +2141,30 @@ function createProxmoxDeleteSnapshotTool(getClient) {
1466
2141
  }
1467
2142
 
1468
2143
  // src/tools/proxmox_force_stop_resource.ts
1469
- import { Type as Type33 } from "@sinclair/typebox";
1470
- var Schema33 = Type33.Object(
2144
+ import { Type as Type34 } from "@sinclair/typebox";
2145
+ var Schema33 = Type34.Object(
1471
2146
  {
1472
- vmid: Type33.Integer({ minimum: 1, description: "Container or VM ID to hard-stop." }),
1473
- confirm: Type33.Boolean({
2147
+ vmid: Type34.Integer({ minimum: 1, description: "Container or VM ID to hard-stop." }),
2148
+ confirm: Type34.Boolean({
1474
2149
  description: "Must be true. Tier-3 destructive gate."
1475
2150
  }),
1476
- destructive: Type33.Boolean({
2151
+ destructive: Type34.Boolean({
1477
2152
  description: "Must be true. Tier-3 destructive gate."
1478
2153
  })
1479
2154
  },
1480
2155
  { additionalProperties: false }
1481
2156
  );
1482
- var NAME18 = "proxmox_force_stop_resource";
2157
+ var NAME30 = "proxmox_force_stop_resource";
1483
2158
  function createProxmoxForceStopResourceTool(getClient) {
1484
2159
  return {
1485
- name: NAME18,
2160
+ name: NAME30,
1486
2161
  label: "proxmox: force stop resource",
1487
2162
  description: "Hard-kill an LXC container or QEMU VM (POST /nodes/{node}/{type}/{vmid}/status/stop). Unlike reboot/shutdown this is a non-graceful stop. Tier-3 destructive; requires confirm:true, destructive:true, and env PROXMOX_ENABLE_DESTRUCTIVE=1.",
1488
2163
  parameters: Schema33,
1489
2164
  execute: async (_id, raw) => {
1490
- assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME18);
1491
- assertDestructive(raw, NAME18);
1492
- const args = validateToolArgs(Schema33, raw, NAME18);
2165
+ assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME30);
2166
+ assertDestructive(raw, NAME30);
2167
+ const args = validateToolArgs(Schema33, raw, NAME30);
1493
2168
  const client = getClient();
1494
2169
  const { node, type } = await resolveResource(client, args.vmid);
1495
2170
  const upid = await client.post(
@@ -1502,130 +2177,2541 @@ function createProxmoxForceStopResourceTool(getClient) {
1502
2177
  }
1503
2178
 
1504
2179
  // src/tools/proxmox_exec.ts
1505
- import { Type as Type34 } from "@sinclair/typebox";
1506
- var Schema34 = Type34.Object(
2180
+ import { Type as Type35 } from "@sinclair/typebox";
2181
+
2182
+ // src/guest-agent.ts
2183
+ var GuestAgentError = class extends Error {
2184
+ constructor(message) {
2185
+ super(`guest-agent: ${message}`);
2186
+ this.name = "GuestAgentError";
2187
+ }
2188
+ };
2189
+ function sleep4(ms) {
2190
+ return new Promise((resolve) => setTimeout(resolve, ms));
2191
+ }
2192
+ async function execViaGuestAgent(client, node, vmid, command, timeoutMs, stdin, pollIntervalMs = 500) {
2193
+ const base = `/nodes/${node}/qemu/${vmid}/agent`;
2194
+ const body = { command: ["/bin/sh", "-c", command] };
2195
+ if (stdin !== void 0) body["input-data"] = stdin;
2196
+ const started = await client.post(`${base}/exec`, body);
2197
+ const pid = started?.pid;
2198
+ if (typeof pid !== "number") {
2199
+ throw new GuestAgentError(`agent/exec did not return a pid for vmid ${vmid}`);
2200
+ }
2201
+ const deadline = Date.now() + timeoutMs;
2202
+ while (Date.now() <= deadline) {
2203
+ const status = await client.get(`${base}/exec-status?pid=${pid}`);
2204
+ if (status.exited === 1 || status.exited === true) {
2205
+ return {
2206
+ stdout: status["out-data"] ?? "",
2207
+ stderr: status["err-data"] ?? "",
2208
+ exitCode: typeof status.exitcode === "number" ? status.exitcode : -1
2209
+ };
2210
+ }
2211
+ await sleep4(Math.min(pollIntervalMs, Math.max(0, deadline - Date.now())));
2212
+ }
2213
+ throw new GuestAgentError(`command in vmid ${vmid} did not finish within ${timeoutMs}ms`);
2214
+ }
2215
+
2216
+ // src/tools/ssh-target.ts
2217
+ function nonEmptyEnv(key) {
2218
+ const value = process.env[key];
2219
+ return value && value.length > 0 ? value : null;
2220
+ }
2221
+ function usableIpv42(ip) {
2222
+ if (ip.startsWith("127.")) return false;
2223
+ if (ip.startsWith("169.254.")) return false;
2224
+ if (ip === "0.0.0.0") return false;
2225
+ return true;
2226
+ }
2227
+ async function resolveQemuSshHost(client, node, vmid) {
2228
+ const envHost = nonEmptyEnv(`PROXMOX_VM_${vmid}_SSH_HOST`);
2229
+ if (envHost) return envHost;
2230
+ try {
2231
+ const data = await client.get(
2232
+ `/nodes/${node}/qemu/${vmid}/agent/network-get-interfaces`
2233
+ );
2234
+ const ifaces = data?.result ?? [];
2235
+ for (const iface of ifaces) {
2236
+ if (iface.name === "lo") continue;
2237
+ const ips = iface["ip-addresses"] ?? [];
2238
+ for (const entry of ips) {
2239
+ const ip = entry["ip-address"];
2240
+ if (!ip) continue;
2241
+ if (entry["ip-address-type"] !== "ipv4") continue;
2242
+ if (!usableIpv42(ip)) continue;
2243
+ return ip;
2244
+ }
2245
+ }
2246
+ } catch {
2247
+ }
2248
+ return null;
2249
+ }
2250
+ function qemuSshTarget(vmid, host, defaults) {
2251
+ return {
2252
+ host,
2253
+ port: 22,
2254
+ user: nonEmptyEnv(`PROXMOX_VM_${vmid}_SSH_USER`) ?? defaults.vmUser,
2255
+ keyPath: nonEmptyEnv(`PROXMOX_VM_${vmid}_SSH_KEY`) ?? defaults.vmKeyPath
2256
+ };
2257
+ }
2258
+ function missingQemuSshHostMessage(vmid) {
2259
+ 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.`;
2260
+ }
2261
+
2262
+ // src/tools/guest-command.ts
2263
+ function resolveExecBackend() {
2264
+ const v = (process.env.PROXMOX_EXEC_BACKEND ?? "ssh").toLowerCase();
2265
+ return v === "guest-agent" || v === "agent" ? "guest-agent" : "ssh";
2266
+ }
2267
+ async function execInQemuGuest(client, ssh, node, vmid, command, timeoutMs, vmDefaults, stdin) {
2268
+ if (resolveExecBackend() === "guest-agent") {
2269
+ return execViaGuestAgent(client, node, vmid, command, timeoutMs, stdin);
2270
+ }
2271
+ const host = await resolveQemuSshHost(client, node, vmid);
2272
+ if (!host) throw new Error(missingQemuSshHostMessage(vmid));
2273
+ return ssh.execViaDirectSsh(qemuSshTarget(vmid, host, vmDefaults), command, timeoutMs, stdin);
2274
+ }
2275
+ function shellSingleQuote(s) {
2276
+ return `'${s.replace(/'/g, `'\\''`)}'`;
2277
+ }
2278
+ function assertAbsoluteGuestPath(path2, toolName) {
2279
+ if (!path2.startsWith("/")) throw new Error(`${toolName} path must be absolute`);
2280
+ if (path2.includes("\0")) throw new Error(`${toolName} path cannot contain NUL bytes`);
2281
+ }
2282
+ async function runGuestCommand(client, ssh, vmDefaults, vmid, command, timeoutMs, stdin) {
2283
+ const { node, type } = await resolveResource(client, vmid);
2284
+ if (type === "lxc") {
2285
+ return { node, type, result: await ssh.execInLxc(vmid, command, timeoutMs, stdin) };
2286
+ }
2287
+ const result = await execInQemuGuest(client, ssh, node, vmid, command, timeoutMs, vmDefaults, stdin);
2288
+ return { node, type, result };
2289
+ }
2290
+
2291
+ // src/tools/proxmox_exec.ts
2292
+ var Schema34 = Type35.Object(
1507
2293
  {
1508
- vmid: Type34.Integer({ minimum: 1, description: "Container or VM id." }),
1509
- command: Type34.String({ minLength: 1, description: "Shell command to run inside the resource." }),
1510
- timeout: Type34.Optional(
1511
- Type34.Integer({ minimum: 1, maximum: 3600, description: "Timeout in seconds (default 30)." })
2294
+ vmid: Type35.Integer({ minimum: 1, description: "Container or VM id." }),
2295
+ command: Type35.String({ minLength: 1, description: "Shell command to run inside the resource." }),
2296
+ timeout: Type35.Optional(
2297
+ Type35.Integer({ minimum: 1, maximum: 3600, description: "Timeout in seconds (default 30)." })
1512
2298
  ),
1513
- confirm: Type34.Boolean({ description: "Must be true to execute. Tier-2 safe-write gate." })
2299
+ confirm: Type35.Boolean({ description: "Must be true to execute. Tier-2 safe-write gate." })
1514
2300
  },
1515
2301
  { additionalProperties: false }
1516
2302
  );
2303
+ var NAME31 = "proxmox_exec";
2304
+ function createProxmoxExecTool(getClient, getSsh, vmDefaults) {
2305
+ return {
2306
+ name: NAME31,
2307
+ label: "proxmox: exec in container or VM",
2308
+ 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.",
2309
+ parameters: Schema34,
2310
+ execute: async (_id, raw) => {
2311
+ assertConfirmedWrite(raw, NAME31);
2312
+ const args = validateToolArgs(Schema34, raw, NAME31);
2313
+ const timeoutMs = (args.timeout ?? 30) * 1e3;
2314
+ const client = getClient();
2315
+ const { node, type } = await resolveResource(client, args.vmid);
2316
+ const ssh = getSsh();
2317
+ if (type === "lxc") {
2318
+ const result2 = await ssh.execInLxc(args.vmid, args.command, timeoutMs);
2319
+ return jsonToolResult({
2320
+ vmid: args.vmid,
2321
+ type,
2322
+ stdout: result2.stdout,
2323
+ stderr: result2.stderr,
2324
+ exit_code: result2.exitCode
2325
+ });
2326
+ }
2327
+ const result = await execInQemuGuest(client, ssh, node, args.vmid, args.command, timeoutMs, vmDefaults);
2328
+ return jsonToolResult({
2329
+ vmid: args.vmid,
2330
+ type,
2331
+ stdout: result.stdout,
2332
+ stderr: result.stderr,
2333
+ exit_code: result.exitCode
2334
+ });
2335
+ }
2336
+ };
2337
+ }
1517
2338
 
1518
2339
  // src/tools/proxmox_read_file.ts
1519
- import { Type as Type35 } from "@sinclair/typebox";
1520
- var Schema35 = Type35.Object(
2340
+ import { Type as Type36 } from "@sinclair/typebox";
2341
+ var Schema35 = Type36.Object(
1521
2342
  {
1522
- vmid: Type35.Integer({ minimum: 1, description: "Container or VM id." }),
1523
- path: Type35.String({ minLength: 1, description: "Absolute file path inside the resource." }),
1524
- confirm: Type35.Boolean({ description: "Must be true to read files from inside a guest." })
2343
+ vmid: Type36.Integer({ minimum: 1, description: "Container or VM id." }),
2344
+ path: Type36.String({ minLength: 1, description: "Absolute file path inside the resource." }),
2345
+ confirm: Type36.Boolean({ description: "Must be true to read files from inside a guest." })
1525
2346
  },
1526
2347
  { additionalProperties: false }
1527
2348
  );
2349
+ var NAME32 = "proxmox_read_file";
2350
+ function shellSingleQuote2(s) {
2351
+ return `'${s.replace(/'/g, `'\\''`)}'`;
2352
+ }
2353
+ function assertAbsoluteGuestPath2(path2, toolName) {
2354
+ if (!path2.startsWith("/")) throw new Error(`${toolName} path must be absolute`);
2355
+ if (path2.includes("\0")) throw new Error(`${toolName} path cannot contain NUL bytes`);
2356
+ }
2357
+ function createProxmoxReadFileTool(getClient, getSsh, vmDefaults) {
2358
+ return {
2359
+ name: NAME32,
2360
+ label: "proxmox: read file from container or VM",
2361
+ description: "Read a file from inside an LXC container or QEMU VM. Gated guest read; requires confirm:true.",
2362
+ parameters: Schema35,
2363
+ execute: async (_id, raw) => {
2364
+ assertConfirmedWrite(raw, NAME32);
2365
+ const args = validateToolArgs(Schema35, raw, NAME32);
2366
+ assertAbsoluteGuestPath2(args.path, NAME32);
2367
+ const client = getClient();
2368
+ const { node, type } = await resolveResource(client, args.vmid);
2369
+ const command = `cat -- ${shellSingleQuote2(args.path)}`;
2370
+ const ssh = getSsh();
2371
+ const timeoutMs = 3e4;
2372
+ let result;
2373
+ if (type === "lxc") {
2374
+ result = await ssh.execInLxc(args.vmid, command, timeoutMs);
2375
+ } else {
2376
+ result = await execInQemuGuest(client, ssh, node, args.vmid, command, timeoutMs, vmDefaults);
2377
+ }
2378
+ if (result.exitCode !== 0) {
2379
+ throw new Error(result.stderr.trim() || `read_file failed with exit code ${result.exitCode}`);
2380
+ }
2381
+ return jsonToolResult({ vmid: args.vmid, path: args.path, content: result.stdout });
2382
+ }
2383
+ };
2384
+ }
1528
2385
 
1529
2386
  // src/tools/proxmox_write_file.ts
1530
- import { Type as Type36 } from "@sinclair/typebox";
2387
+ import { Type as Type37 } from "@sinclair/typebox";
1531
2388
  import path from "path";
1532
- var Schema36 = Type36.Object(
2389
+ var Schema36 = Type37.Object(
1533
2390
  {
1534
- vmid: Type36.Integer({ minimum: 1, description: "Container or VM id." }),
1535
- path: Type36.String({ minLength: 1, description: "Absolute destination path inside the resource." }),
1536
- content: Type36.String({ description: "Text content to write." }),
1537
- confirm: Type36.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
2391
+ vmid: Type37.Integer({ minimum: 1, description: "Container or VM id." }),
2392
+ path: Type37.String({ minLength: 1, description: "Absolute destination path inside the resource." }),
2393
+ content: Type37.String({ description: "Text content to write." }),
2394
+ confirm: Type37.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
1538
2395
  },
1539
2396
  { additionalProperties: false }
1540
2397
  );
2398
+ var NAME33 = "proxmox_write_file";
2399
+ function shellSingleQuote3(s) {
2400
+ return `'${s.replace(/'/g, `'\\''`)}'`;
2401
+ }
2402
+ function assertAbsoluteGuestPath3(path2, toolName) {
2403
+ if (!path2.startsWith("/")) throw new Error(`${toolName} path must be absolute`);
2404
+ if (path2.includes("\0")) throw new Error(`${toolName} path cannot contain NUL bytes`);
2405
+ }
2406
+ function createProxmoxWriteFileTool(getClient, getSsh, vmDefaults) {
2407
+ return {
2408
+ name: NAME33,
2409
+ label: "proxmox: write file to container or VM",
2410
+ description: "Write a text file to a path inside an LXC container or QEMU VM. Creates parent directories. Tier-2 write; requires confirm:true.",
2411
+ parameters: Schema36,
2412
+ execute: async (_id, raw) => {
2413
+ assertConfirmedWrite(raw, NAME33);
2414
+ const args = validateToolArgs(Schema36, raw, NAME33);
2415
+ assertAbsoluteGuestPath3(args.path, NAME33);
2416
+ const client = getClient();
2417
+ const { node, type } = await resolveResource(client, args.vmid);
2418
+ const ssh = getSsh();
2419
+ const timeoutMs = 3e4;
2420
+ const parent = path.posix.dirname(args.path);
2421
+ const mkdirCmd = `mkdir -p -- ${shellSingleQuote3(parent)}`;
2422
+ const writeCmd = `cat > ${shellSingleQuote3(args.path)}`;
2423
+ const runOne = async (command, stdin) => {
2424
+ if (type === "lxc") {
2425
+ return ssh.execInLxc(args.vmid, command, timeoutMs, stdin);
2426
+ }
2427
+ return execInQemuGuest(client, ssh, node, args.vmid, command, timeoutMs, vmDefaults, stdin);
2428
+ };
2429
+ const mkdirResult = await runOne(mkdirCmd);
2430
+ if (mkdirResult.exitCode !== 0) {
2431
+ throw new Error(mkdirResult.stderr.trim() || `mkdir failed with exit code ${mkdirResult.exitCode}`);
2432
+ }
2433
+ const writeResult = await runOne(writeCmd, args.content);
2434
+ if (writeResult.exitCode !== 0) {
2435
+ throw new Error(writeResult.stderr.trim() || `write failed with exit code ${writeResult.exitCode}`);
2436
+ }
2437
+ return jsonToolResult({
2438
+ vmid: args.vmid,
2439
+ path: args.path,
2440
+ bytes_written: Buffer.byteLength(args.content, "utf8")
2441
+ });
2442
+ }
2443
+ };
2444
+ }
1541
2445
 
1542
2446
  // src/tools/proxmox_stat_path.ts
1543
- import { Type as Type37 } from "@sinclair/typebox";
1544
- var Schema37 = Type37.Object(
2447
+ import { Type as Type38 } from "@sinclair/typebox";
2448
+ var Schema37 = Type38.Object(
1545
2449
  {
1546
- vmid: Type37.Integer({ minimum: 1, description: "Container or VM id." }),
1547
- path: Type37.String({ minLength: 1, description: "Absolute path inside the guest." }),
1548
- confirm: Type37.Boolean({ description: "Must be true to inspect guest filesystem metadata." })
2450
+ vmid: Type38.Integer({ minimum: 1, description: "Container or VM id." }),
2451
+ path: Type38.String({ minLength: 1, description: "Absolute path inside the guest." }),
2452
+ confirm: Type38.Boolean({ description: "Must be true to inspect guest filesystem metadata." })
1549
2453
  },
1550
2454
  { additionalProperties: false }
1551
2455
  );
2456
+ var NAME34 = "proxmox_stat_path";
2457
+ function parseStatOutput(stdout) {
2458
+ const fields = stdout.split("\0");
2459
+ if (fields.at(-1) === "") fields.pop();
2460
+ if (fields.length !== 7) {
2461
+ throw new Error(`${NAME34} unexpected stat output: expected 7 NUL-delimited fields, got ${fields.length}`);
2462
+ }
2463
+ const [file_type, size, owner, group, mode, mtime, name] = fields;
2464
+ return {
2465
+ file_type,
2466
+ size: Number(size),
2467
+ owner,
2468
+ group,
2469
+ mode,
2470
+ mtime: Number(mtime),
2471
+ name
2472
+ };
2473
+ }
2474
+ function createProxmoxStatPathTool(getClient, getSsh, vmDefaults) {
2475
+ return {
2476
+ name: NAME34,
2477
+ label: "proxmox: stat guest path",
2478
+ description: "Return structured metadata for a path inside an LXC container or QEMU VM. Gated guest read; requires confirm:true.",
2479
+ parameters: Schema37,
2480
+ execute: async (_id, raw) => {
2481
+ assertConfirmedWrite(raw, NAME34);
2482
+ const args = validateToolArgs(Schema37, raw, NAME34);
2483
+ assertAbsoluteGuestPath(args.path, NAME34);
2484
+ const command = `stat -Lc '%F\\0%s\\0%U\\0%G\\0%a\\0%Y\\0%n\\0' -- ${shellSingleQuote(args.path)}`;
2485
+ const { node, type, result } = await runGuestCommand(
2486
+ getClient(),
2487
+ getSsh(),
2488
+ vmDefaults,
2489
+ args.vmid,
2490
+ command,
2491
+ 3e4
2492
+ );
2493
+ if (result.exitCode !== 0) throw new Error(result.stderr.trim() || `stat failed with exit code ${result.exitCode}`);
2494
+ const stat = parseStatOutput(result.stdout);
2495
+ return jsonToolResult({
2496
+ vmid: args.vmid,
2497
+ node,
2498
+ type,
2499
+ path: args.path,
2500
+ ...stat
2501
+ });
2502
+ }
2503
+ };
2504
+ }
1552
2505
 
1553
2506
  // src/tools/proxmox_list_directory.ts
1554
- import { Type as Type38 } from "@sinclair/typebox";
1555
- var Schema38 = Type38.Object(
2507
+ import { Type as Type39 } from "@sinclair/typebox";
2508
+ var Schema38 = Type39.Object(
1556
2509
  {
1557
- vmid: Type38.Integer({ minimum: 1, description: "Container or VM id." }),
1558
- path: Type38.String({ minLength: 1, description: "Absolute directory path inside the guest." }),
1559
- confirm: Type38.Boolean({ description: "Must be true to inspect guest directory contents." })
2510
+ vmid: Type39.Integer({ minimum: 1, description: "Container or VM id." }),
2511
+ path: Type39.String({ minLength: 1, description: "Absolute directory path inside the guest." }),
2512
+ confirm: Type39.Boolean({ description: "Must be true to inspect guest directory contents." })
1560
2513
  },
1561
2514
  { additionalProperties: false }
1562
2515
  );
2516
+ var NAME35 = "proxmox_list_directory";
2517
+ function parseFindEntries(stdout) {
2518
+ if (stdout === "") return [];
2519
+ const fields = stdout.split("\0");
2520
+ if (fields.at(-1) === "") fields.pop();
2521
+ if (fields.length % 4 !== 0) {
2522
+ throw new Error(`${NAME35} unexpected find output: incomplete NUL-delimited record`);
2523
+ }
2524
+ const entries = [];
2525
+ for (let i = 0; i < fields.length; i += 4) {
2526
+ entries.push({
2527
+ name: fields[i],
2528
+ kind: fields[i + 1],
2529
+ size: Number(fields[i + 2]),
2530
+ mtime: Number(fields[i + 3])
2531
+ });
2532
+ }
2533
+ entries.sort((a, b) => a.name.localeCompare(b.name));
2534
+ return entries;
2535
+ }
2536
+ function createProxmoxListDirectoryTool(getClient, getSsh, vmDefaults) {
2537
+ return {
2538
+ name: NAME35,
2539
+ label: "proxmox: list guest directory",
2540
+ description: "List one directory inside an LXC container or QEMU VM. Gated guest read; requires confirm:true.",
2541
+ parameters: Schema38,
2542
+ execute: async (_id, raw) => {
2543
+ assertConfirmedWrite(raw, NAME35);
2544
+ const args = validateToolArgs(Schema38, raw, NAME35);
2545
+ assertAbsoluteGuestPath(args.path, NAME35);
2546
+ const command = `find ${shellSingleQuote(args.path)} -mindepth 1 -maxdepth 1 -printf '%f\\0%y\\0%s\\0%T@\\0'`;
2547
+ const { node, type, result } = await runGuestCommand(
2548
+ getClient(),
2549
+ getSsh(),
2550
+ vmDefaults,
2551
+ args.vmid,
2552
+ command,
2553
+ 3e4
2554
+ );
2555
+ if (result.exitCode !== 0) {
2556
+ throw new Error(result.stderr.trim() || `list_directory failed with exit code ${result.exitCode}`);
2557
+ }
2558
+ const entries = parseFindEntries(result.stdout);
2559
+ return jsonToolResult({ vmid: args.vmid, node, type, path: args.path, count: entries.length, entries });
2560
+ }
2561
+ };
2562
+ }
1563
2563
 
1564
2564
  // src/tools/proxmox_service_status.ts
1565
- import { Type as Type39 } from "@sinclair/typebox";
1566
- var Schema39 = Type39.Object(
2565
+ import { Type as Type40 } from "@sinclair/typebox";
2566
+ var Schema39 = Type40.Object(
1567
2567
  {
1568
- vmid: Type39.Integer({ minimum: 1, description: "Container or VM id." }),
1569
- service: Type39.String({ minLength: 1, description: "systemd service name inside the guest." }),
1570
- confirm: Type39.Boolean({ description: "Must be true to inspect guest service state." })
2568
+ vmid: Type40.Integer({ minimum: 1, description: "Container or VM id." }),
2569
+ service: Type40.String({ minLength: 1, description: "systemd service name inside the guest." }),
2570
+ confirm: Type40.Boolean({ description: "Must be true to inspect guest service state." })
1571
2571
  },
1572
2572
  { additionalProperties: false }
1573
2573
  );
2574
+ var NAME36 = "proxmox_service_status";
2575
+ function parseSystemctlShow(stdout) {
2576
+ const out = {};
2577
+ for (const line of stdout.trimEnd().split("\n")) {
2578
+ const idx = line.indexOf("=");
2579
+ if (idx <= 0) continue;
2580
+ out[line.slice(0, idx)] = line.slice(idx + 1);
2581
+ }
2582
+ return out;
2583
+ }
2584
+ function createProxmoxServiceStatusTool(getClient, getSsh, vmDefaults) {
2585
+ return {
2586
+ name: NAME36,
2587
+ label: "proxmox: guest service status",
2588
+ description: "Return systemd service status from inside an LXC container or QEMU VM. Gated guest read; requires confirm:true.",
2589
+ parameters: Schema39,
2590
+ execute: async (_id, raw) => {
2591
+ assertConfirmedWrite(raw, NAME36);
2592
+ const args = validateToolArgs(Schema39, raw, NAME36);
2593
+ if (args.service.includes("\0")) throw new Error(`${NAME36} service cannot contain NUL bytes`);
2594
+ const command = `systemctl show --no-pager --property=Id,LoadState,ActiveState,SubState,UnitFileState,Description -- ${shellSingleQuote(args.service)}`;
2595
+ const { node, type, result } = await runGuestCommand(
2596
+ getClient(),
2597
+ getSsh(),
2598
+ vmDefaults,
2599
+ args.vmid,
2600
+ command,
2601
+ 3e4
2602
+ );
2603
+ if (result.exitCode !== 0) {
2604
+ throw new Error(result.stderr.trim() || `service_status failed with exit code ${result.exitCode}`);
2605
+ }
2606
+ const status = parseSystemctlShow(result.stdout);
2607
+ return jsonToolResult({ vmid: args.vmid, node, type, service: args.service, status });
2608
+ }
2609
+ };
2610
+ }
1574
2611
 
1575
2612
  // src/tools/service-action.ts
1576
- import { Type as Type40 } from "@sinclair/typebox";
1577
-
1578
- // index.ts
1579
- function withRedactedErrors(tool) {
1580
- const orig = tool.execute.bind(tool);
2613
+ import { Type as Type41 } from "@sinclair/typebox";
2614
+ function parseSystemctlShow2(stdout) {
2615
+ const out = {};
2616
+ for (const line of stdout.trimEnd().split("\n")) {
2617
+ const idx = line.indexOf("=");
2618
+ if (idx <= 0) continue;
2619
+ out[line.slice(0, idx)] = line.slice(idx + 1);
2620
+ }
2621
+ return out;
2622
+ }
2623
+ function schemaFor(action) {
2624
+ return Type41.Object(
2625
+ {
2626
+ vmid: Type41.Integer({ minimum: 1, description: "Container or VM id." }),
2627
+ service: Type41.String({ minLength: 1, description: `systemd service name to ${action} inside the guest.` }),
2628
+ confirm: Type41.Boolean({ description: `Must be true to ${action} a guest service.` })
2629
+ },
2630
+ { additionalProperties: false }
2631
+ );
2632
+ }
2633
+ function createServiceActionTool(action, getClient, getSsh, vmDefaults) {
2634
+ const name = `proxmox_service_${action}`;
2635
+ const schema = schemaFor(action);
1581
2636
  return {
1582
- ...tool,
1583
- execute: async (id, args) => {
1584
- try {
1585
- return await orig(id, args);
1586
- } catch (e) {
1587
- const msg = redact(e.message);
1588
- return { content: [{ type: "text", text: JSON.stringify({ error: msg }) }], isError: true };
2637
+ name,
2638
+ label: `proxmox: guest service ${action}`,
2639
+ description: `${action[0].toUpperCase()}${action.slice(1)} a systemd service inside an LXC container or QEMU VM. Tier-2 write; requires confirm:true.`,
2640
+ parameters: schema,
2641
+ execute: async (_id, raw) => {
2642
+ assertConfirmedWrite(raw, name);
2643
+ const args = validateToolArgs(schema, raw, name);
2644
+ if (args.service.includes("\0")) throw new Error(`${name} service cannot contain NUL bytes`);
2645
+ const quoted = shellSingleQuote(args.service);
2646
+ const command = `systemctl ${action} -- ${quoted} && systemctl show --no-pager --property=Id,LoadState,ActiveState,SubState,UnitFileState,Description -- ${quoted}`;
2647
+ const { node, type, result } = await runGuestCommand(
2648
+ getClient(),
2649
+ getSsh(),
2650
+ vmDefaults,
2651
+ args.vmid,
2652
+ command,
2653
+ 6e4
2654
+ );
2655
+ if (result.exitCode !== 0) {
2656
+ throw new Error(result.stderr.trim() || `service_${action} failed with exit code ${result.exitCode}`);
1589
2657
  }
2658
+ return jsonToolResult({
2659
+ vmid: args.vmid,
2660
+ node,
2661
+ type,
2662
+ service: args.service,
2663
+ action,
2664
+ status: parseSystemctlShow2(result.stdout)
2665
+ });
1590
2666
  }
1591
2667
  };
1592
2668
  }
1593
- function makeFactory(cfg) {
1594
- registerSecret(cfg.tokenId);
1595
- registerSecret(cfg.tokenSecret);
1596
- registerSecret(`PVEAPIToken=${cfg.tokenId}=${cfg.tokenSecret}`);
1597
- return () => new ProxmoxClient(cfg);
2669
+
2670
+ // src/tools/proxmox_service_start.ts
2671
+ function createProxmoxServiceStartTool(getClient, getSsh, vmDefaults) {
2672
+ return createServiceActionTool("start", getClient, getSsh, vmDefaults);
1598
2673
  }
1599
- var index_default = definePluginEntry({
1600
- id: "proxmox",
1601
- name: "Proxmox",
1602
- description: "Proxmox VE control: status, container + VM lifecycle, snapshots, backups, recent tasks. Single-cluster, token auth, optional TLS-insecure. Tier-2 writes gated by confirm:true.",
1603
- register(api) {
1604
- if (api.registrationMode !== "full") return;
1605
- const cfg = resolveConfig(process.env);
1606
- const getClient = makeFactory(cfg);
1607
- const register = (t) => api.registerTool(withRedactedErrors(t));
1608
- register(createProxmoxStatusTool(getClient));
1609
- register(createProxmoxListContainersTool(getClient));
1610
- register(createProxmoxListVmsTool(getClient));
1611
- register(createProxmoxGetResourceTool(getClient));
1612
- register(createProxmoxRecentTasksTool(getClient));
1613
- register(createProxmoxListBackupsTool(getClient));
1614
- register(createProxmoxResourceUsageTool(getClient));
2674
+
2675
+ // src/tools/proxmox_service_stop.ts
2676
+ function createProxmoxServiceStopTool(getClient, getSsh, vmDefaults) {
2677
+ return createServiceActionTool("stop", getClient, getSsh, vmDefaults);
2678
+ }
2679
+
2680
+ // src/tools/proxmox_service_restart.ts
2681
+ function createProxmoxServiceRestartTool(getClient, getSsh, vmDefaults) {
2682
+ return createServiceActionTool("restart", getClient, getSsh, vmDefaults);
2683
+ }
2684
+
2685
+ // src/tools/proxmox_update_vm_config.ts
2686
+ import { Type as Type43 } from "@sinclair/typebox";
2687
+
2688
+ // src/tools/resource-config.ts
2689
+ import { Type as Type42 } from "@sinclair/typebox";
2690
+ var CONFIG_KEY_RE = /^[a-zA-Z][a-zA-Z0-9_]*$/;
2691
+ var configEditFields = {
2692
+ cores: Type42.Optional(Type42.Integer({ minimum: 1, description: "CPU cores." })),
2693
+ memory: Type42.Optional(Type42.Integer({ minimum: 16, description: "RAM in MiB." })),
2694
+ description: Type42.Optional(Type42.String({ description: "Free-form description / notes." })),
2695
+ onboot: Type42.Optional(Type42.Boolean({ description: "Start on host boot." })),
2696
+ tags: Type42.Optional(Type42.String({ description: "Semicolon-delimited Proxmox tags." })),
2697
+ cpulimit: Type42.Optional(Type42.Number({ minimum: 0, description: "CPU limit (0 = unlimited)." })),
2698
+ cpuunits: Type42.Optional(Type42.Integer({ minimum: 1, description: "CPU weight / shares." })),
2699
+ protection: Type42.Optional(
2700
+ Type42.Boolean({ description: "Protection flag (blocks destroy/disk-remove)." })
2701
+ ),
2702
+ set: Type42.Optional(
2703
+ Type42.Record(Type42.String(), Type42.Union([Type42.String(), Type42.Number(), Type42.Boolean()]), {
2704
+ description: 'Arbitrary PVE config keys to set, e.g. {"net0":"virtio,bridge=vmbr0","bios":"ovmf"}. Escape hatch for keys not exposed as typed fields.'
2705
+ })
2706
+ ),
2707
+ unset: Type42.Optional(
2708
+ Type42.Array(Type42.String(), {
2709
+ description: 'Config keys to unset/revert to default, e.g. ["tags","description"].'
2710
+ })
2711
+ ),
2712
+ digest: Type42.Optional(
2713
+ Type42.String({
2714
+ description: "SHA1 config digest for optimistic concurrency; edit is rejected if config changed."
2715
+ })
2716
+ )
2717
+ };
2718
+ function normalize(v) {
2719
+ if (typeof v === "boolean") return v ? 1 : 0;
2720
+ if (typeof v === "number") return v;
2721
+ return String(v);
2722
+ }
2723
+ function buildConfigBody(args, extraTyped, toolName) {
2724
+ const body = {};
2725
+ const typed = {
2726
+ cores: args.cores,
2727
+ memory: args.memory,
2728
+ description: args.description,
2729
+ onboot: args.onboot,
2730
+ tags: args.tags,
2731
+ cpulimit: args.cpulimit,
2732
+ cpuunits: args.cpuunits,
2733
+ protection: args.protection,
2734
+ ...extraTyped
2735
+ };
2736
+ for (const [k, v] of Object.entries(typed)) {
2737
+ if (v !== void 0) body[k] = normalize(v);
2738
+ }
2739
+ if (args.set) {
2740
+ for (const [k, v] of Object.entries(args.set)) {
2741
+ if (!CONFIG_KEY_RE.test(k)) {
2742
+ throw new ToolInputError(`${toolName}: invalid config key "${k}" in set`);
2743
+ }
2744
+ body[k] = normalize(v);
2745
+ }
2746
+ }
2747
+ const unset = (args.unset ?? []).filter((k) => k.length > 0);
2748
+ for (const k of unset) {
2749
+ if (!CONFIG_KEY_RE.test(k)) {
2750
+ throw new ToolInputError(`${toolName}: invalid config key "${k}" in unset`);
2751
+ }
2752
+ }
2753
+ if (unset.length > 0) body.delete = unset.join(",");
2754
+ if (args.digest) body.digest = args.digest;
2755
+ const mutations = Object.keys(body).filter((k) => k !== "digest");
2756
+ if (mutations.length === 0) {
2757
+ throw new ToolInputError(
2758
+ `${toolName}: no config changes supplied. Provide at least one field, a "set" entry, or an "unset" key.`
2759
+ );
2760
+ }
2761
+ return body;
2762
+ }
2763
+
2764
+ // src/tools/proxmox_update_vm_config.ts
2765
+ var Schema40 = Type43.Object(
2766
+ {
2767
+ vmid: Type43.Integer({ minimum: 1, description: "QEMU VM ID to reconfigure." }),
2768
+ name: Type43.Optional(Type43.String({ minLength: 1, description: "VM name." })),
2769
+ sockets: Type43.Optional(Type43.Integer({ minimum: 1, description: "CPU sockets." })),
2770
+ balloon: Type43.Optional(
2771
+ Type43.Integer({ minimum: 0, description: "Ballooning target in MiB (0 disables)." })
2772
+ ),
2773
+ ...configEditFields,
2774
+ confirm: Type43.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
2775
+ },
2776
+ { additionalProperties: false }
2777
+ );
2778
+ var NAME37 = "proxmox_update_vm_config";
2779
+ function createProxmoxUpdateVmConfigTool(getClient) {
2780
+ return {
2781
+ name: NAME37,
2782
+ label: "proxmox: update VM config",
2783
+ 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.",
2784
+ parameters: Schema40,
2785
+ execute: async (_id, raw) => {
2786
+ assertConfirmedWrite(raw, NAME37);
2787
+ const args = validateToolArgs(Schema40, raw, NAME37);
2788
+ const client = getClient();
2789
+ const { node, type } = await resolveResource(client, args.vmid);
2790
+ if (type !== "qemu") {
2791
+ throw new Error(`vmid ${args.vmid} is an LXC container, not a QEMU VM. Use proxmox_update_container_config.`);
2792
+ }
2793
+ const body = buildConfigBody(args, { name: args.name, sockets: args.sockets, balloon: args.balloon }, NAME37);
2794
+ const upid = await client.put(`/nodes/${node}/qemu/${args.vmid}/config`, body);
2795
+ const changed = Object.keys(body).filter((k) => k !== "digest" && k !== "delete");
2796
+ const removed = typeof body.delete === "string" ? body.delete.split(",") : [];
2797
+ return jsonToolResult({ vmid: args.vmid, node, type, changed, removed, upid: upid ?? null });
2798
+ }
2799
+ };
2800
+ }
2801
+
2802
+ // src/tools/proxmox_update_container_config.ts
2803
+ import { Type as Type44 } from "@sinclair/typebox";
2804
+ var Schema41 = Type44.Object(
2805
+ {
2806
+ vmid: Type44.Integer({ minimum: 1, description: "LXC container ID to reconfigure." }),
2807
+ hostname: Type44.Optional(Type44.String({ minLength: 1, description: "Container hostname." })),
2808
+ swap: Type44.Optional(Type44.Integer({ minimum: 0, description: "Swap in MiB." })),
2809
+ nameserver: Type44.Optional(Type44.String({ minLength: 1, description: "DNS server IP(s), space-separated." })),
2810
+ ...configEditFields,
2811
+ confirm: Type44.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
2812
+ },
2813
+ { additionalProperties: false }
2814
+ );
2815
+ var NAME38 = "proxmox_update_container_config";
2816
+ function createProxmoxUpdateContainerConfigTool(getClient) {
2817
+ return {
2818
+ name: NAME38,
2819
+ label: "proxmox: update container config",
2820
+ 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.",
2821
+ parameters: Schema41,
2822
+ execute: async (_id, raw) => {
2823
+ assertConfirmedWrite(raw, NAME38);
2824
+ const args = validateToolArgs(Schema41, raw, NAME38);
2825
+ const client = getClient();
2826
+ const { node, type } = await resolveResource(client, args.vmid);
2827
+ if (type !== "lxc") {
2828
+ throw new Error(`vmid ${args.vmid} is a QEMU VM, not an LXC container. Use proxmox_update_vm_config.`);
2829
+ }
2830
+ const body = buildConfigBody(
2831
+ args,
2832
+ { hostname: args.hostname, swap: args.swap, nameserver: args.nameserver },
2833
+ NAME38
2834
+ );
2835
+ const upid = await client.put(`/nodes/${node}/lxc/${args.vmid}/config`, body);
2836
+ const changed = Object.keys(body).filter((k) => k !== "digest" && k !== "delete");
2837
+ const removed = typeof body.delete === "string" ? body.delete.split(",") : [];
2838
+ return jsonToolResult({ vmid: args.vmid, node, type, changed, removed, upid: upid ?? null });
2839
+ }
2840
+ };
2841
+ }
2842
+
2843
+ // src/tools/proxmox_resize_disk.ts
2844
+ import { Type as Type45 } from "@sinclair/typebox";
2845
+ var DISK_KEY_RE = /^[a-zA-Z][a-zA-Z0-9_]*$/;
2846
+ var SIZE_RE = /^\+?\d+(\.\d+)?[KMGT]?$/;
2847
+ var Schema42 = Type45.Object(
2848
+ {
2849
+ vmid: Type45.Integer({ minimum: 1, description: "Container or VM ID." }),
2850
+ disk: Type45.String({
2851
+ minLength: 1,
2852
+ description: "Disk key to resize, e.g. 'scsi0', 'virtio0', 'rootfs', 'mp0'."
2853
+ }),
2854
+ size: Type45.String({
2855
+ minLength: 1,
2856
+ description: "New size ('32G') or growth increment ('+2G'). PVE grows only; shrink is refused."
2857
+ }),
2858
+ confirm: Type45.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." }),
2859
+ ...taskWaitFields
2860
+ },
2861
+ { additionalProperties: false }
2862
+ );
2863
+ var NAME39 = "proxmox_resize_disk";
2864
+ function createProxmoxResizeDiskTool(getClient) {
2865
+ return {
2866
+ name: NAME39,
2867
+ label: "proxmox: resize disk",
2868
+ 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.",
2869
+ parameters: Schema42,
2870
+ execute: async (_id, raw) => {
2871
+ assertConfirmedWrite(raw, NAME39);
2872
+ const args = validateToolArgs(
2873
+ Schema42,
2874
+ raw,
2875
+ NAME39
2876
+ );
2877
+ if (!DISK_KEY_RE.test(args.disk)) {
2878
+ throw new ToolInputError(`${NAME39}: invalid disk key "${args.disk}"`);
2879
+ }
2880
+ if (!SIZE_RE.test(args.size)) {
2881
+ throw new ToolInputError(
2882
+ `${NAME39}: invalid size "${args.size}". Use '32G' (absolute) or '+2G' (growth).`
2883
+ );
2884
+ }
2885
+ const client = getClient();
2886
+ const { node, type } = await resolveResource(client, args.vmid);
2887
+ const upid = await client.put(`/nodes/${node}/${type}/${args.vmid}/resize`, {
2888
+ disk: args.disk,
2889
+ size: args.size
2890
+ });
2891
+ const task = await resolveTaskWait(client, upid, args);
2892
+ return jsonToolResult({ vmid: args.vmid, node, type, disk: args.disk, size: args.size, upid: upid ?? null, ...task ? { task } : {} });
2893
+ }
2894
+ };
2895
+ }
2896
+
2897
+ // src/tools/proxmox_restore_backup.ts
2898
+ import { Type as Type46 } from "@sinclair/typebox";
2899
+ var Schema43 = Type46.Object(
2900
+ {
2901
+ vmid: Type46.Integer({ minimum: 1, description: "Target VMID to restore into." }),
2902
+ archive: Type46.String({
2903
+ minLength: 1,
2904
+ 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."
2905
+ }),
2906
+ type: Type46.Optional(
2907
+ Type46.Union([Type46.Literal("lxc"), Type46.Literal("qemu")], {
2908
+ description: "Guest type. Inferred from the archive name when omitted."
2909
+ })
2910
+ ),
2911
+ node: Type46.Optional(
2912
+ Type46.String({ minLength: 1, description: "Node to restore on (defaults to first node for a new vmid)." })
2913
+ ),
2914
+ storage: Type46.Optional(
2915
+ Type46.String({ minLength: 1, description: "Target storage for restored disks (defaults to the archive's)." })
2916
+ ),
2917
+ pool: Type46.Optional(Type46.String({ minLength: 1, description: "Resource pool to place the guest into." })),
2918
+ unique: Type46.Optional(
2919
+ Type46.Boolean({ description: "QEMU: regenerate MAC addresses / UUID on restore." })
2920
+ ),
2921
+ force: Type46.Optional(
2922
+ Type46.Boolean({
2923
+ description: "Overwrite an EXISTING vmid (wipes its disks). Requires the destructive gate."
2924
+ })
2925
+ ),
2926
+ confirm: Type46.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." }),
2927
+ destructive: Type46.Optional(
2928
+ Type46.Boolean({ description: "Required only when overwriting an existing vmid (force)." })
2929
+ ),
2930
+ ...taskWaitFields
2931
+ },
2932
+ { additionalProperties: false }
2933
+ );
2934
+ var NAME40 = "proxmox_restore_backup";
2935
+ function inferType(archive) {
2936
+ const a = archive.toLowerCase();
2937
+ if (a.includes("qemu") || a.includes("/vm/")) return "qemu";
2938
+ if (a.includes("lxc") || a.includes("/ct/")) return "lxc";
2939
+ return null;
2940
+ }
2941
+ function createProxmoxRestoreBackupTool(getClient) {
2942
+ return {
2943
+ name: NAME40,
2944
+ label: "proxmox: restore backup",
2945
+ 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.",
2946
+ parameters: Schema43,
2947
+ execute: async (_id, raw) => {
2948
+ assertConfirmedWrite(raw, NAME40);
2949
+ const args = validateToolArgs(Schema43, raw, NAME40);
2950
+ if (/[\r\n]/.test(args.archive)) {
2951
+ throw new ToolInputError(`${NAME40}: archive must not contain newlines`);
2952
+ }
2953
+ const type = args.type ?? inferType(args.archive);
2954
+ if (!type) {
2955
+ throw new ToolInputError(
2956
+ `${NAME40}: could not infer guest type from archive "${args.archive}". Pass type:"lxc" or "qemu".`
2957
+ );
2958
+ }
2959
+ const client = getClient();
2960
+ const resources = await client.get("/cluster/resources");
2961
+ const existing = resources.find(
2962
+ (r) => r.vmid === args.vmid && (r.type === "lxc" || r.type === "qemu")
2963
+ );
2964
+ let node;
2965
+ if (existing) {
2966
+ if (args.force !== true) {
2967
+ throw new ToolInputError(
2968
+ `${NAME40}: vmid ${args.vmid} already exists on ${existing.node}. To overwrite it, pass force:true (also requires destructive:true + PROXMOX_ENABLE_DESTRUCTIVE=1).`
2969
+ );
2970
+ }
2971
+ assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME40);
2972
+ assertDestructive(raw, NAME40);
2973
+ if (existing.type !== type) {
2974
+ throw new Error(
2975
+ `vmid ${args.vmid} exists as ${existing.type} but archive is ${type}. Refusing cross-type overwrite.`
2976
+ );
2977
+ }
2978
+ node = existing.node;
2979
+ } else {
2980
+ if (args.node) {
2981
+ assertSafePathSegment(args.node, "node");
2982
+ node = args.node;
2983
+ } else {
2984
+ const nodes = resources.filter((r) => r.type === "node");
2985
+ if (nodes.length === 0) throw new Error("no nodes found in cluster resources");
2986
+ node = nodes[0].node;
2987
+ }
2988
+ }
2989
+ const body = {
2990
+ vmid: args.vmid,
2991
+ restore: 1
2992
+ };
2993
+ if (type === "qemu") body.archive = args.archive;
2994
+ else body.ostemplate = args.archive;
2995
+ if (existing && args.force === true) body.force = 1;
2996
+ if (args.storage) body.storage = args.storage;
2997
+ if (args.pool) body.pool = args.pool;
2998
+ if (args.unique === true && type === "qemu") body.unique = 1;
2999
+ const upid = await client.post(`/nodes/${node}/${type}`, body);
3000
+ const task = await resolveTaskWait(client, upid, args);
3001
+ return jsonToolResult({
3002
+ vmid: args.vmid,
3003
+ node,
3004
+ type,
3005
+ archive: args.archive,
3006
+ overwrite: Boolean(existing),
3007
+ upid,
3008
+ ...task ? { task } : {}
3009
+ });
3010
+ }
3011
+ };
3012
+ }
3013
+
3014
+ // src/tools/proxmox_migrate_resource.ts
3015
+ import { Type as Type47 } from "@sinclair/typebox";
3016
+ var Schema44 = Type47.Object(
3017
+ {
3018
+ vmid: Type47.Integer({ minimum: 1, description: "Container or VM ID to migrate." }),
3019
+ target: Type47.String({ minLength: 1, description: "Target node name to migrate to." }),
3020
+ online: Type47.Optional(
3021
+ Type47.Boolean({ description: "QEMU: live-migrate a running VM (no downtime)." })
3022
+ ),
3023
+ restart: Type47.Optional(
3024
+ Type47.Boolean({ description: "LXC: restart-migrate a running container (brief downtime)." })
3025
+ ),
3026
+ with_local_disks: Type47.Optional(
3027
+ Type47.Boolean({ description: "QEMU: also migrate local (non-shared) disks." })
3028
+ ),
3029
+ targetstorage: Type47.Optional(
3030
+ Type47.String({ minLength: 1, description: "Map disks onto this storage on the target node." })
3031
+ ),
3032
+ bwlimit: Type47.Optional(
3033
+ Type47.Integer({ minimum: 0, description: "Bandwidth limit in KiB/s (0 = unlimited)." })
3034
+ ),
3035
+ confirm: Type47.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." }),
3036
+ ...taskWaitFields
3037
+ },
3038
+ { additionalProperties: false }
3039
+ );
3040
+ var NAME41 = "proxmox_migrate_resource";
3041
+ function createProxmoxMigrateResourceTool(getClient) {
3042
+ return {
3043
+ name: NAME41,
3044
+ label: "proxmox: migrate resource",
3045
+ 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.",
3046
+ parameters: Schema44,
3047
+ execute: async (_id, raw) => {
3048
+ assertConfirmedWrite(raw, NAME41);
3049
+ const args = validateToolArgs(Schema44, raw, NAME41);
3050
+ assertSafePathSegment(args.target, "target node");
3051
+ const client = getClient();
3052
+ const { node, type } = await resolveResource(client, args.vmid);
3053
+ if (args.target === node) {
3054
+ throw new Error(`vmid ${args.vmid} is already on node ${node}; nothing to migrate.`);
3055
+ }
3056
+ const body = { target: args.target };
3057
+ if (type === "qemu") {
3058
+ if (args.online) body.online = 1;
3059
+ if (args.with_local_disks) body["with-local-disks"] = 1;
3060
+ } else {
3061
+ if (args.restart || args.online) body.restart = 1;
3062
+ }
3063
+ if (args.targetstorage) body.targetstorage = args.targetstorage;
3064
+ if (typeof args.bwlimit === "number") body.bwlimit = args.bwlimit;
3065
+ const upid = await client.post(`/nodes/${node}/${type}/${args.vmid}/migrate`, body);
3066
+ const task = await resolveTaskWait(client, upid, args);
3067
+ return jsonToolResult({ vmid: args.vmid, node, type, target: args.target, upid, ...task ? { task } : {} });
3068
+ }
3069
+ };
3070
+ }
3071
+
3072
+ // src/tools/proxmox_suspend_resource.ts
3073
+ import { Type as Type48 } from "@sinclair/typebox";
3074
+ var Schema45 = Type48.Object(
3075
+ {
3076
+ vmid: Type48.Integer({ minimum: 1, description: "Container or VM ID." }),
3077
+ todisk: Type48.Optional(
3078
+ Type48.Boolean({ description: "QEMU: suspend to disk (hibernate) instead of to RAM." })
3079
+ ),
3080
+ confirm: Type48.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3081
+ },
3082
+ { additionalProperties: false }
3083
+ );
3084
+ var NAME42 = "proxmox_suspend_resource";
3085
+ function createProxmoxSuspendResourceTool(getClient) {
3086
+ return {
3087
+ name: NAME42,
3088
+ label: "proxmox: suspend resource",
3089
+ 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.",
3090
+ parameters: Schema45,
3091
+ execute: async (_id, raw) => {
3092
+ assertConfirmedWrite(raw, NAME42);
3093
+ const args = validateToolArgs(Schema45, raw, NAME42);
3094
+ const client = getClient();
3095
+ const { node, type } = await resolveResource(client, args.vmid);
3096
+ const body = {};
3097
+ if (args.todisk && type === "qemu") body.todisk = 1;
3098
+ const upid = await client.post(`/nodes/${node}/${type}/${args.vmid}/status/suspend`, body);
3099
+ return jsonToolResult({ vmid: args.vmid, node, type, upid });
3100
+ }
3101
+ };
3102
+ }
3103
+
3104
+ // src/tools/proxmox_resume_resource.ts
3105
+ import { Type as Type49 } from "@sinclair/typebox";
3106
+ var Schema46 = Type49.Object(
3107
+ {
3108
+ vmid: Type49.Integer({ minimum: 1, description: "Container or VM ID." }),
3109
+ confirm: Type49.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3110
+ },
3111
+ { additionalProperties: false }
3112
+ );
3113
+ var NAME43 = "proxmox_resume_resource";
3114
+ function createProxmoxResumeResourceTool(getClient) {
3115
+ return {
3116
+ name: NAME43,
3117
+ label: "proxmox: resume resource",
3118
+ description: "Resume a suspended LXC or QEMU guest (POST /nodes/{node}/{type}/{vmid}/status/resume). Tier-2 write; requires confirm:true.",
3119
+ parameters: Schema46,
3120
+ execute: async (_id, raw) => {
3121
+ assertConfirmedWrite(raw, NAME43);
3122
+ const args = validateToolArgs(Schema46, raw, NAME43);
3123
+ const client = getClient();
3124
+ const { node, type } = await resolveResource(client, args.vmid);
3125
+ const upid = await client.post(`/nodes/${node}/${type}/${args.vmid}/status/resume`, {});
3126
+ return jsonToolResult({ vmid: args.vmid, node, type, upid });
3127
+ }
3128
+ };
3129
+ }
3130
+
3131
+ // src/tools/proxmox_reset_resource.ts
3132
+ import { Type as Type50 } from "@sinclair/typebox";
3133
+ var Schema47 = Type50.Object(
3134
+ {
3135
+ vmid: Type50.Integer({ minimum: 1, description: "QEMU VM ID." }),
3136
+ confirm: Type50.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3137
+ },
3138
+ { additionalProperties: false }
3139
+ );
3140
+ var NAME44 = "proxmox_reset_resource";
3141
+ function createProxmoxResetResourceTool(getClient) {
3142
+ return {
3143
+ name: NAME44,
3144
+ label: "proxmox: reset resource",
3145
+ 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.",
3146
+ parameters: Schema47,
3147
+ execute: async (_id, raw) => {
3148
+ assertConfirmedWrite(raw, NAME44);
3149
+ const args = validateToolArgs(Schema47, raw, NAME44);
3150
+ const client = getClient();
3151
+ const { node, type } = await resolveResource(client, args.vmid);
3152
+ if (type !== "qemu") {
3153
+ throw new Error(`vmid ${args.vmid} is an LXC container; reset is QEMU-only. Use proxmox_reboot_resource.`);
3154
+ }
3155
+ const upid = await client.post(`/nodes/${node}/qemu/${args.vmid}/status/reset`, {});
3156
+ return jsonToolResult({ vmid: args.vmid, node, type, upid });
3157
+ }
3158
+ };
3159
+ }
3160
+
3161
+ // src/tools/proxmox_convert_to_template.ts
3162
+ import { Type as Type51 } from "@sinclair/typebox";
3163
+ var Schema48 = Type51.Object(
3164
+ {
3165
+ vmid: Type51.Integer({ minimum: 1, description: "Container or VM ID to convert into a template." }),
3166
+ confirm: Type51.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3167
+ },
3168
+ { additionalProperties: false }
3169
+ );
3170
+ var NAME45 = "proxmox_convert_to_template";
3171
+ function createProxmoxConvertToTemplateTool(getClient) {
3172
+ return {
3173
+ name: NAME45,
3174
+ label: "proxmox: convert to template",
3175
+ 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.",
3176
+ parameters: Schema48,
3177
+ execute: async (_id, raw) => {
3178
+ assertConfirmedWrite(raw, NAME45);
3179
+ const args = validateToolArgs(Schema48, raw, NAME45);
3180
+ const client = getClient();
3181
+ const { node, type } = await resolveResource(client, args.vmid);
3182
+ const upid = await client.post(`/nodes/${node}/${type}/${args.vmid}/template`, {});
3183
+ return jsonToolResult({ vmid: args.vmid, node, type, template: true, upid: upid ?? null });
3184
+ }
3185
+ };
3186
+ }
3187
+
3188
+ // src/tools/proxmox_list_storage_content.ts
3189
+ import { Type as Type52 } from "@sinclair/typebox";
3190
+ var Schema49 = Type52.Object(
3191
+ {
3192
+ node: Type52.String({ minLength: 1, description: "Node whose storage to inspect." }),
3193
+ storage: Type52.String({ minLength: 1, description: "Storage ID, e.g. 'local', 'local-lvm'." }),
3194
+ content: Type52.Optional(
3195
+ Type52.Union(
3196
+ [
3197
+ Type52.Literal("backup"),
3198
+ Type52.Literal("iso"),
3199
+ Type52.Literal("vztmpl"),
3200
+ Type52.Literal("images"),
3201
+ Type52.Literal("rootdir"),
3202
+ Type52.Literal("snippets")
3203
+ ],
3204
+ { description: "Filter by content type (backup, iso, vztmpl, images, rootdir, snippets)." }
3205
+ )
3206
+ ),
3207
+ vmid: Type52.Optional(Type52.Integer({ minimum: 1, description: "Filter to a single owning VMID." }))
3208
+ },
3209
+ { additionalProperties: false }
3210
+ );
3211
+ var NAME46 = "proxmox_list_storage_content";
3212
+ function createProxmoxListStorageContentTool(getClient) {
3213
+ return {
3214
+ name: NAME46,
3215
+ label: "proxmox: list storage content",
3216
+ 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.",
3217
+ parameters: Schema49,
3218
+ execute: async (_id, raw) => {
3219
+ const args = validateToolArgs(
3220
+ Schema49,
3221
+ raw,
3222
+ NAME46
3223
+ );
3224
+ assertSafePathSegment(args.node, "node");
3225
+ assertSafePathSegment(args.storage, "storage");
3226
+ const params = new URLSearchParams();
3227
+ if (args.content) params.append("content", args.content);
3228
+ if (typeof args.vmid === "number") params.append("vmid", String(args.vmid));
3229
+ const qs = params.toString();
3230
+ const path2 = `/nodes/${args.node}/storage/${args.storage}/content${qs ? `?${qs}` : ""}`;
3231
+ const items = await getClient().get(path2);
3232
+ return jsonToolResult({ node: args.node, storage: args.storage, count: items.length, content: items });
3233
+ }
3234
+ };
3235
+ }
3236
+
3237
+ // src/tools/proxmox_download_url.ts
3238
+ import { Type as Type53 } from "@sinclair/typebox";
3239
+ var Schema50 = Type53.Object(
3240
+ {
3241
+ node: Type53.String({ minLength: 1, description: "Node to download onto." }),
3242
+ storage: Type53.String({ minLength: 1, description: "Target storage ID (must allow iso/vztmpl content)." }),
3243
+ content: Type53.Union([Type53.Literal("iso"), Type53.Literal("vztmpl")], {
3244
+ description: "Content type: 'iso' for an install image, 'vztmpl' for a container template."
3245
+ }),
3246
+ url: Type53.String({ minLength: 1, description: "HTTP(S) URL to download from." }),
3247
+ filename: Type53.String({ minLength: 1, description: "Destination filename on the storage." }),
3248
+ checksum: Type53.Optional(Type53.String({ minLength: 1, description: "Expected checksum of the download." })),
3249
+ checksum_algorithm: Type53.Optional(
3250
+ Type53.Union(
3251
+ [Type53.Literal("md5"), Type53.Literal("sha1"), Type53.Literal("sha256"), Type53.Literal("sha512")],
3252
+ { description: "Algorithm for the checksum." }
3253
+ )
3254
+ ),
3255
+ verify_certificates: Type53.Optional(
3256
+ Type53.Boolean({ description: "Verify the source server's TLS cert (default true)." })
3257
+ ),
3258
+ confirm: Type53.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." }),
3259
+ ...taskWaitFields
3260
+ },
3261
+ { additionalProperties: false }
3262
+ );
3263
+ var NAME47 = "proxmox_download_url";
3264
+ function createProxmoxDownloadUrlTool(getClient) {
3265
+ return {
3266
+ name: NAME47,
3267
+ label: "proxmox: download url",
3268
+ 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.",
3269
+ parameters: Schema50,
3270
+ execute: async (_id, raw) => {
3271
+ assertConfirmedWrite(raw, NAME47);
3272
+ const args = validateToolArgs(Schema50, raw, NAME47);
3273
+ assertSafePathSegment(args.node, "node");
3274
+ assertSafePathSegment(args.storage, "storage");
3275
+ if (!/^https?:\/\//i.test(args.url)) {
3276
+ throw new ToolInputError(`${NAME47}: url must be http(s)`);
3277
+ }
3278
+ if (args.checksum && !args.checksum_algorithm) {
3279
+ throw new ToolInputError(`${NAME47}: checksum_algorithm is required when checksum is set`);
3280
+ }
3281
+ const body = {
3282
+ content: args.content,
3283
+ url: args.url,
3284
+ filename: args.filename
3285
+ };
3286
+ if (args.checksum) body.checksum = args.checksum;
3287
+ if (args.checksum_algorithm) body["checksum-algorithm"] = args.checksum_algorithm;
3288
+ if (args.verify_certificates === false) body["verify-certificates"] = 0;
3289
+ const client = getClient();
3290
+ const upid = await client.post(
3291
+ `/nodes/${args.node}/storage/${args.storage}/download-url`,
3292
+ body
3293
+ );
3294
+ const task = await resolveTaskWait(client, upid, args);
3295
+ return jsonToolResult({
3296
+ node: args.node,
3297
+ storage: args.storage,
3298
+ content: args.content,
3299
+ filename: args.filename,
3300
+ upid,
3301
+ ...task ? { task } : {}
3302
+ });
3303
+ }
3304
+ };
3305
+ }
3306
+
3307
+ // src/tools/proxmox_delete_volume.ts
3308
+ import { Type as Type54 } from "@sinclair/typebox";
3309
+ var VOLID_RE = /^[\w.-]+:[\w./-]+$/;
3310
+ var Schema51 = Type54.Object(
3311
+ {
3312
+ node: Type54.String({ minLength: 1, description: "Node the storage is on." }),
3313
+ storage: Type54.String({ minLength: 1, description: "Storage ID holding the volume." }),
3314
+ volume: Type54.String({
3315
+ minLength: 1,
3316
+ description: "Full volid to delete, e.g. 'local:backup/vzdump-lxc-100-...tar.zst'."
3317
+ }),
3318
+ confirm: Type54.Boolean({ description: "Must be true. Tier-3 destructive gate." }),
3319
+ destructive: Type54.Boolean({ description: "Must be true. Tier-3 destructive gate." })
3320
+ },
3321
+ { additionalProperties: false }
3322
+ );
3323
+ var NAME48 = "proxmox_delete_volume";
3324
+ function createProxmoxDeleteVolumeTool(getClient) {
3325
+ return {
3326
+ name: NAME48,
3327
+ label: "proxmox: delete volume",
3328
+ 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.",
3329
+ parameters: Schema51,
3330
+ execute: async (_id, raw) => {
3331
+ assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME48);
3332
+ assertDestructive(raw, NAME48);
3333
+ const args = validateToolArgs(Schema51, raw, NAME48);
3334
+ assertSafePathSegment(args.node, "node");
3335
+ assertSafePathSegment(args.storage, "storage");
3336
+ if (args.volume.includes("..") || !VOLID_RE.test(args.volume)) {
3337
+ throw new ToolInputError(`${NAME48}: invalid volume id "${args.volume}"`);
3338
+ }
3339
+ const path2 = `/nodes/${args.node}/storage/${args.storage}/content/${encodeURIComponent(args.volume)}`;
3340
+ const upid = await getClient().delete(path2);
3341
+ return jsonToolResult({ node: args.node, storage: args.storage, volume: args.volume, upid: upid ?? null });
3342
+ }
3343
+ };
3344
+ }
3345
+
3346
+ // src/tools/proxmox_list_node_services.ts
3347
+ import { Type as Type55 } from "@sinclair/typebox";
3348
+ var Schema52 = Type55.Object(
3349
+ { node: Type55.String({ minLength: 1, description: "Node to inspect." }) },
3350
+ { additionalProperties: false }
3351
+ );
3352
+ var NAME49 = "proxmox_list_node_services";
3353
+ function createProxmoxListNodeServicesTool(getClient) {
3354
+ return {
3355
+ name: NAME49,
3356
+ label: "proxmox: list node services",
3357
+ description: "List the Proxmox host's systemd services and their state (GET /nodes/{node}/services): pveproxy, pvedaemon, pve-cluster, corosync, etc. Tier-1 read.",
3358
+ parameters: Schema52,
3359
+ execute: async (_id, raw) => {
3360
+ const args = validateToolArgs(Schema52, raw, NAME49);
3361
+ assertSafePathSegment(args.node, "node");
3362
+ const services = await getClient().get(`/nodes/${args.node}/services`);
3363
+ return jsonToolResult({ node: args.node, count: services.length, services });
3364
+ }
3365
+ };
3366
+ }
3367
+
3368
+ // src/tools/proxmox_list_updates.ts
3369
+ import { Type as Type56 } from "@sinclair/typebox";
3370
+ var Schema53 = Type56.Object(
3371
+ { node: Type56.String({ minLength: 1, description: "Node to check for pending package updates." }) },
3372
+ { additionalProperties: false }
3373
+ );
3374
+ var NAME50 = "proxmox_list_updates";
3375
+ function createProxmoxListUpdatesTool(getClient) {
3376
+ return {
3377
+ name: NAME50,
3378
+ label: "proxmox: list updates",
3379
+ 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.",
3380
+ parameters: Schema53,
3381
+ execute: async (_id, raw) => {
3382
+ const args = validateToolArgs(Schema53, raw, NAME50);
3383
+ assertSafePathSegment(args.node, "node");
3384
+ const updates = await getClient().get(`/nodes/${args.node}/apt/update`);
3385
+ return jsonToolResult({ node: args.node, count: updates.length, updates });
3386
+ }
3387
+ };
3388
+ }
3389
+
3390
+ // src/tools/proxmox_list_disks.ts
3391
+ import { Type as Type57 } from "@sinclair/typebox";
3392
+ var Schema54 = Type57.Object(
3393
+ {
3394
+ node: Type57.String({ minLength: 1, description: "Node whose physical disks to list." }),
3395
+ include_partitions: Type57.Optional(
3396
+ Type57.Boolean({ description: "Include partitions in the listing (default false)." })
3397
+ )
3398
+ },
3399
+ { additionalProperties: false }
3400
+ );
3401
+ var NAME51 = "proxmox_list_disks";
3402
+ function createProxmoxListDisksTool(getClient) {
3403
+ return {
3404
+ name: NAME51,
3405
+ label: "proxmox: list disks",
3406
+ description: "List a node's physical disks with model, size, type, SMART health and wearout (GET /nodes/{node}/disks/list). Tier-1 read.",
3407
+ parameters: Schema54,
3408
+ execute: async (_id, raw) => {
3409
+ const args = validateToolArgs(Schema54, raw, NAME51);
3410
+ assertSafePathSegment(args.node, "node");
3411
+ const qs = args.include_partitions ? "?include-partitions=1" : "";
3412
+ const disks = await getClient().get(`/nodes/${args.node}/disks/list${qs}`);
3413
+ return jsonToolResult({ node: args.node, count: disks.length, disks });
3414
+ }
3415
+ };
3416
+ }
3417
+
3418
+ // src/tools/proxmox_cancel_task.ts
3419
+ import { Type as Type58 } from "@sinclair/typebox";
3420
+ var Schema55 = Type58.Object(
3421
+ {
3422
+ upid: Type58.String({ minLength: 1, description: "UPID of the running task to stop." }),
3423
+ confirm: Type58.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3424
+ },
3425
+ { additionalProperties: false }
3426
+ );
3427
+ var NAME52 = "proxmox_cancel_task";
3428
+ function createProxmoxCancelTaskTool(getClient) {
3429
+ return {
3430
+ name: NAME52,
3431
+ label: "proxmox: cancel task",
3432
+ 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.",
3433
+ parameters: Schema55,
3434
+ execute: async (_id, raw) => {
3435
+ assertConfirmedWrite(raw, NAME52);
3436
+ const args = validateToolArgs(Schema55, raw, NAME52);
3437
+ const { node } = parseTaskUpid(args.upid);
3438
+ await getClient().delete(`/nodes/${node}/tasks/${encodeURIComponent(args.upid)}`);
3439
+ return jsonToolResult({ upid: args.upid, node, stopped: true });
3440
+ }
3441
+ };
3442
+ }
3443
+
3444
+ // src/tools/proxmox_node_power.ts
3445
+ import { Type as Type59 } from "@sinclair/typebox";
3446
+ var Schema56 = Type59.Object(
3447
+ {
3448
+ node: Type59.String({ minLength: 1, description: "Node to power-cycle." }),
3449
+ command: Type59.Union([Type59.Literal("reboot"), Type59.Literal("shutdown")], {
3450
+ description: "'reboot' or 'shutdown' the physical/virtual host."
3451
+ }),
3452
+ confirm: Type59.Boolean({ description: "Must be true. Tier-3 destructive gate." }),
3453
+ destructive: Type59.Boolean({ description: "Must be true. Tier-3 destructive gate." })
3454
+ },
3455
+ { additionalProperties: false }
3456
+ );
3457
+ var NAME53 = "proxmox_node_power";
3458
+ function createProxmoxNodePowerTool(getClient) {
3459
+ return {
3460
+ name: NAME53,
3461
+ label: "proxmox: node power",
3462
+ 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.",
3463
+ parameters: Schema56,
3464
+ execute: async (_id, raw) => {
3465
+ assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME53);
3466
+ assertDestructive(raw, NAME53);
3467
+ const args = validateToolArgs(Schema56, raw, NAME53);
3468
+ assertSafePathSegment(args.node, "node");
3469
+ await getClient().post(`/nodes/${args.node}/status`, { command: args.command });
3470
+ return jsonToolResult({ node: args.node, command: args.command, issued: true });
3471
+ }
3472
+ };
3473
+ }
3474
+
3475
+ // src/tools/proxmox_list_firewall_rules.ts
3476
+ import { Type as Type61 } from "@sinclair/typebox";
3477
+
3478
+ // src/tools/firewall-target.ts
3479
+ import { Type as Type60 } from "@sinclair/typebox";
3480
+ var firewallScopeFields = {
3481
+ scope: Type60.Union(
3482
+ [Type60.Literal("cluster"), Type60.Literal("node"), Type60.Literal("guest")],
3483
+ { description: "Firewall scope: 'cluster', 'node' (needs node), or 'guest' (needs vmid)." }
3484
+ ),
3485
+ node: Type60.Optional(Type60.String({ minLength: 1, description: "Node name (required when scope='node')." })),
3486
+ vmid: Type60.Optional(Type60.Integer({ minimum: 1, description: "Guest VMID (required when scope='guest')." }))
3487
+ };
3488
+ async function resolveFirewallBase(client, args, toolName) {
3489
+ if (args.scope === "cluster") {
3490
+ return { base: "/cluster/firewall", label: "cluster" };
3491
+ }
3492
+ if (args.scope === "node") {
3493
+ if (!args.node) throw new ToolInputError(`${toolName}: node is required when scope='node'`);
3494
+ assertSafePathSegment(args.node, "node");
3495
+ return { base: `/nodes/${args.node}/firewall`, label: `node ${args.node}` };
3496
+ }
3497
+ if (typeof args.vmid !== "number") {
3498
+ throw new ToolInputError(`${toolName}: vmid is required when scope='guest'`);
3499
+ }
3500
+ const { node, type } = await resolveResource(client, args.vmid);
3501
+ return { base: `/nodes/${node}/${type}/${args.vmid}/firewall`, label: `${type} ${args.vmid}` };
3502
+ }
3503
+
3504
+ // src/tools/proxmox_list_firewall_rules.ts
3505
+ var Schema57 = Type61.Object({ ...firewallScopeFields }, { additionalProperties: false });
3506
+ var NAME54 = "proxmox_list_firewall_rules";
3507
+ function createProxmoxListFirewallRulesTool(getClient) {
3508
+ return {
3509
+ name: NAME54,
3510
+ label: "proxmox: list firewall rules",
3511
+ 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.",
3512
+ parameters: Schema57,
3513
+ execute: async (_id, raw) => {
3514
+ const args = validateToolArgs(Schema57, raw, NAME54);
3515
+ const client = getClient();
3516
+ const { base, label } = await resolveFirewallBase(client, args, NAME54);
3517
+ const rules = await client.get(`${base}/rules`);
3518
+ return jsonToolResult({ scope: label, count: Array.isArray(rules) ? rules.length : 0, rules });
3519
+ }
3520
+ };
3521
+ }
3522
+
3523
+ // src/tools/proxmox_get_firewall_options.ts
3524
+ import { Type as Type62 } from "@sinclair/typebox";
3525
+ var Schema58 = Type62.Object({ ...firewallScopeFields }, { additionalProperties: false });
3526
+ var NAME55 = "proxmox_get_firewall_options";
3527
+ function createProxmoxGetFirewallOptionsTool(getClient) {
3528
+ return {
3529
+ name: NAME55,
3530
+ label: "proxmox: get firewall options",
3531
+ 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.",
3532
+ parameters: Schema58,
3533
+ execute: async (_id, raw) => {
3534
+ const args = validateToolArgs(Schema58, raw, NAME55);
3535
+ const client = getClient();
3536
+ const { base, label } = await resolveFirewallBase(client, args, NAME55);
3537
+ const options = await client.get(`${base}/options`);
3538
+ return jsonToolResult({ scope: label, options });
3539
+ }
3540
+ };
3541
+ }
3542
+
3543
+ // src/tools/proxmox_add_firewall_rule.ts
3544
+ import { Type as Type63 } from "@sinclair/typebox";
3545
+ var Schema59 = Type63.Object(
3546
+ {
3547
+ ...firewallScopeFields,
3548
+ type: Type63.Union([Type63.Literal("in"), Type63.Literal("out"), Type63.Literal("group")], {
3549
+ description: "Rule direction: 'in', 'out', or 'group' (attach a security group)."
3550
+ }),
3551
+ action: Type63.String({
3552
+ minLength: 1,
3553
+ description: "ACCEPT, DROP, REJECT, or a security-group name when type='group'."
3554
+ }),
3555
+ source: Type63.Optional(Type63.String({ minLength: 1, description: "Source CIDR/IP/alias." })),
3556
+ dest: Type63.Optional(Type63.String({ minLength: 1, description: "Destination CIDR/IP/alias." })),
3557
+ proto: Type63.Optional(Type63.String({ minLength: 1, description: "Protocol, e.g. tcp, udp, icmp." })),
3558
+ dport: Type63.Optional(Type63.String({ minLength: 1, description: "Destination port(s), e.g. '22' or '8000:8100'." })),
3559
+ sport: Type63.Optional(Type63.String({ minLength: 1, description: "Source port(s)." })),
3560
+ macro: Type63.Optional(Type63.String({ minLength: 1, description: "Predefined macro, e.g. 'SSH', 'HTTP'." })),
3561
+ comment: Type63.Optional(Type63.String({ description: "Human-readable comment." })),
3562
+ enable: Type63.Optional(Type63.Boolean({ description: "Whether the rule is active (default true)." })),
3563
+ pos: Type63.Optional(Type63.Integer({ minimum: 0, description: "Insert position (default: prepend at 0)." })),
3564
+ confirm: Type63.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3565
+ },
3566
+ { additionalProperties: false }
3567
+ );
3568
+ var NAME56 = "proxmox_add_firewall_rule";
3569
+ function createProxmoxAddFirewallRuleTool(getClient) {
3570
+ return {
3571
+ name: NAME56,
3572
+ label: "proxmox: add firewall rule",
3573
+ description: "Add a firewall rule at the cluster, node, or guest scope (POST {base}/firewall/rules). Tier-2 write; requires confirm:true.",
3574
+ parameters: Schema59,
3575
+ execute: async (_id, raw) => {
3576
+ assertConfirmedWrite(raw, NAME56);
3577
+ const args = validateToolArgs(Schema59, raw, NAME56);
3578
+ const client = getClient();
3579
+ const { base, label } = await resolveFirewallBase(client, args, NAME56);
3580
+ const body = { type: args.type, action: args.action };
3581
+ for (const k of ["source", "dest", "proto", "dport", "sport", "macro", "comment"]) {
3582
+ const v = args[k];
3583
+ if (typeof v === "string" && v.length > 0) body[k] = v;
3584
+ }
3585
+ body.enable = args.enable === false ? 0 : 1;
3586
+ if (typeof args.pos === "number") body.pos = args.pos;
3587
+ await client.post(`${base}/rules`, body);
3588
+ return jsonToolResult({ scope: label, type: args.type, action: args.action, added: true });
3589
+ }
3590
+ };
3591
+ }
3592
+
3593
+ // src/tools/proxmox_delete_firewall_rule.ts
3594
+ import { Type as Type64 } from "@sinclair/typebox";
3595
+ var Schema60 = Type64.Object(
3596
+ {
3597
+ ...firewallScopeFields,
3598
+ pos: Type64.Integer({ minimum: 0, description: "Rule position/index to delete (see list_firewall_rules)." }),
3599
+ digest: Type64.Optional(
3600
+ Type64.String({ minLength: 1, description: "Ruleset digest for optimistic concurrency." })
3601
+ ),
3602
+ confirm: Type64.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3603
+ },
3604
+ { additionalProperties: false }
3605
+ );
3606
+ var NAME57 = "proxmox_delete_firewall_rule";
3607
+ function createProxmoxDeleteFirewallRuleTool(getClient) {
3608
+ return {
3609
+ name: NAME57,
3610
+ label: "proxmox: delete firewall rule",
3611
+ 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.",
3612
+ parameters: Schema60,
3613
+ execute: async (_id, raw) => {
3614
+ assertConfirmedWrite(raw, NAME57);
3615
+ const args = validateToolArgs(Schema60, raw, NAME57);
3616
+ const client = getClient();
3617
+ const { base, label } = await resolveFirewallBase(client, args, NAME57);
3618
+ const qs = args.digest ? `?digest=${encodeURIComponent(args.digest)}` : "";
3619
+ await client.delete(`${base}/rules/${args.pos}${qs}`);
3620
+ return jsonToolResult({ scope: label, pos: args.pos, deleted: true });
3621
+ }
3622
+ };
3623
+ }
3624
+
3625
+ // src/tools/proxmox_set_firewall_enabled.ts
3626
+ import { Type as Type65 } from "@sinclair/typebox";
3627
+ var Schema61 = Type65.Object(
3628
+ {
3629
+ ...firewallScopeFields,
3630
+ enable: Type65.Boolean({ description: "Turn the firewall on (true) or off (false) for this scope." }),
3631
+ confirm: Type65.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3632
+ },
3633
+ { additionalProperties: false }
3634
+ );
3635
+ var NAME58 = "proxmox_set_firewall_enabled";
3636
+ function createProxmoxSetFirewallEnabledTool(getClient) {
3637
+ return {
3638
+ name: NAME58,
3639
+ label: "proxmox: set firewall enabled",
3640
+ 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.",
3641
+ parameters: Schema61,
3642
+ execute: async (_id, raw) => {
3643
+ assertConfirmedWrite(raw, NAME58);
3644
+ const args = validateToolArgs(Schema61, raw, NAME58);
3645
+ const client = getClient();
3646
+ const { base, label } = await resolveFirewallBase(client, args, NAME58);
3647
+ await client.put(`${base}/options`, { enable: args.enable ? 1 : 0 });
3648
+ return jsonToolResult({ scope: label, enabled: args.enable });
3649
+ }
3650
+ };
3651
+ }
3652
+
3653
+ // src/tools/proxmox_move_disk.ts
3654
+ import { Type as Type66 } from "@sinclair/typebox";
3655
+ var DISK_KEY_RE2 = /^[a-zA-Z][a-zA-Z0-9_]*$/;
3656
+ var Schema62 = Type66.Object(
3657
+ {
3658
+ vmid: Type66.Integer({ minimum: 1, description: "Container or VM ID." }),
3659
+ disk: Type66.String({
3660
+ minLength: 1,
3661
+ description: "Disk/volume key to move, e.g. 'scsi0' (QEMU) or 'rootfs'/'mp0' (LXC)."
3662
+ }),
3663
+ target_storage: Type66.String({ minLength: 1, description: "Target storage to move the disk onto." }),
3664
+ delete_source: Type66.Optional(
3665
+ Type66.Boolean({ description: "Delete the original disk after a successful move (default false)." })
3666
+ ),
3667
+ confirm: Type66.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." }),
3668
+ ...taskWaitFields
3669
+ },
3670
+ { additionalProperties: false }
3671
+ );
3672
+ var NAME59 = "proxmox_move_disk";
3673
+ function createProxmoxMoveDiskTool(getClient) {
3674
+ return {
3675
+ name: NAME59,
3676
+ label: "proxmox: move disk",
3677
+ 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.",
3678
+ parameters: Schema62,
3679
+ execute: async (_id, raw) => {
3680
+ assertConfirmedWrite(raw, NAME59);
3681
+ const args = validateToolArgs(Schema62, raw, NAME59);
3682
+ if (!DISK_KEY_RE2.test(args.disk)) {
3683
+ throw new Error(`${NAME59}: invalid disk key "${args.disk}"`);
3684
+ }
3685
+ assertSafePathSegment(args.target_storage, "target_storage");
3686
+ const client = getClient();
3687
+ const { node, type } = await resolveResource(client, args.vmid);
3688
+ const del = args.delete_source === true ? 1 : 0;
3689
+ let upid;
3690
+ if (type === "qemu") {
3691
+ upid = await client.post(`/nodes/${node}/qemu/${args.vmid}/move_disk`, {
3692
+ disk: args.disk,
3693
+ storage: args.target_storage,
3694
+ delete: del
3695
+ });
3696
+ } else {
3697
+ upid = await client.post(`/nodes/${node}/lxc/${args.vmid}/move_volume`, {
3698
+ volume: args.disk,
3699
+ storage: args.target_storage,
3700
+ delete: del
3701
+ });
3702
+ }
3703
+ const task = await resolveTaskWait(client, upid, args);
3704
+ return jsonToolResult({
3705
+ vmid: args.vmid,
3706
+ node,
3707
+ type,
3708
+ disk: args.disk,
3709
+ target_storage: args.target_storage,
3710
+ deleted_source: del === 1,
3711
+ upid,
3712
+ ...task ? { task } : {}
3713
+ });
3714
+ }
3715
+ };
3716
+ }
3717
+
3718
+ // src/tools/proxmox_list_storage_config.ts
3719
+ import { Type as Type67 } from "@sinclair/typebox";
3720
+ var Schema63 = Type67.Object({}, { additionalProperties: false });
3721
+ var NAME60 = "proxmox_list_storage_config";
3722
+ function createProxmoxListStorageConfigTool(getClient) {
3723
+ return {
3724
+ name: NAME60,
3725
+ label: "proxmox: list storage config",
3726
+ 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.",
3727
+ parameters: Schema63,
3728
+ execute: async () => {
3729
+ const defs = await getClient().get("/storage");
3730
+ return jsonToolResult({ count: defs.length, storage: defs });
3731
+ }
3732
+ };
3733
+ }
3734
+
3735
+ // src/tools/proxmox_create_storage.ts
3736
+ import { Type as Type68 } from "@sinclair/typebox";
3737
+ var OPT_KEY_RE = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
3738
+ var Schema64 = Type68.Object(
3739
+ {
3740
+ storage: Type68.String({ minLength: 1, description: "New storage ID." }),
3741
+ type: Type68.Union(
3742
+ [
3743
+ Type68.Literal("dir"),
3744
+ Type68.Literal("nfs"),
3745
+ Type68.Literal("cifs"),
3746
+ Type68.Literal("lvm"),
3747
+ Type68.Literal("lvmthin"),
3748
+ Type68.Literal("zfspool"),
3749
+ Type68.Literal("pbs"),
3750
+ Type68.Literal("cephfs"),
3751
+ Type68.Literal("rbd")
3752
+ ],
3753
+ { description: "Storage backend type." }
3754
+ ),
3755
+ content: Type68.Optional(
3756
+ Type68.String({ minLength: 1, description: "Comma-separated content types, e.g. 'images,rootdir' or 'iso,backup,vztmpl'." })
3757
+ ),
3758
+ options: Type68.Optional(
3759
+ Type68.Record(Type68.String(), Type68.Union([Type68.String(), Type68.Number(), Type68.Boolean()]), {
3760
+ 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.'
3761
+ })
3762
+ ),
3763
+ nodes: Type68.Optional(Type68.String({ minLength: 1, description: "Restrict to these nodes (comma-separated)." })),
3764
+ disable: Type68.Optional(Type68.Boolean({ description: "Create the storage in a disabled state." })),
3765
+ confirm: Type68.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3766
+ },
3767
+ { additionalProperties: false }
3768
+ );
3769
+ var NAME61 = "proxmox_create_storage";
3770
+ function createProxmoxCreateStorageTool(getClient) {
3771
+ return {
3772
+ name: NAME61,
3773
+ label: "proxmox: create storage",
3774
+ 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.",
3775
+ parameters: Schema64,
3776
+ execute: async (_id, raw) => {
3777
+ assertConfirmedWrite(raw, NAME61);
3778
+ const args = validateToolArgs(Schema64, raw, NAME61);
3779
+ assertSafePathSegment(args.storage, "storage");
3780
+ const body = { storage: args.storage, type: args.type };
3781
+ if (args.content) body.content = args.content;
3782
+ if (args.nodes) body.nodes = args.nodes;
3783
+ if (args.disable) body.disable = 1;
3784
+ if (args.options) {
3785
+ for (const [k, v] of Object.entries(args.options)) {
3786
+ if (!OPT_KEY_RE.test(k)) throw new ToolInputError(`${NAME61}: invalid option key "${k}"`);
3787
+ body[k] = typeof v === "boolean" ? v ? 1 : 0 : v;
3788
+ }
3789
+ }
3790
+ await getClient().post(`/storage`, body);
3791
+ return jsonToolResult({ storage: args.storage, type: args.type, created: true });
3792
+ }
3793
+ };
3794
+ }
3795
+
3796
+ // src/tools/proxmox_delete_storage.ts
3797
+ import { Type as Type69 } from "@sinclair/typebox";
3798
+ var Schema65 = Type69.Object(
3799
+ {
3800
+ storage: Type69.String({ minLength: 1, description: "Storage ID to remove from the datacenter config." }),
3801
+ confirm: Type69.Boolean({ description: "Must be true. Tier-3 destructive gate." }),
3802
+ destructive: Type69.Boolean({ description: "Must be true. Tier-3 destructive gate." })
3803
+ },
3804
+ { additionalProperties: false }
3805
+ );
3806
+ var NAME62 = "proxmox_delete_storage";
3807
+ function createProxmoxDeleteStorageTool(getClient) {
3808
+ return {
3809
+ name: NAME62,
3810
+ label: "proxmox: delete storage",
3811
+ 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.",
3812
+ parameters: Schema65,
3813
+ execute: async (_id, raw) => {
3814
+ assertEnvFlag("PROXMOX_ENABLE_DESTRUCTIVE", NAME62);
3815
+ assertDestructive(raw, NAME62);
3816
+ const args = validateToolArgs(Schema65, raw, NAME62);
3817
+ assertSafePathSegment(args.storage, "storage");
3818
+ await getClient().delete(`/storage/${args.storage}`);
3819
+ return jsonToolResult({ storage: args.storage, deleted: true });
3820
+ }
3821
+ };
3822
+ }
3823
+
3824
+ // src/tools/proxmox_list_backup_jobs.ts
3825
+ import { Type as Type70 } from "@sinclair/typebox";
3826
+ var Schema66 = Type70.Object({}, { additionalProperties: false });
3827
+ var NAME63 = "proxmox_list_backup_jobs";
3828
+ function createProxmoxListBackupJobsTool(getClient) {
3829
+ return {
3830
+ name: NAME63,
3831
+ label: "proxmox: list backup jobs",
3832
+ description: "List scheduled backup (vzdump) jobs (GET /cluster/backup): id, schedule, target storage, selection, and enabled state. Tier-1 read.",
3833
+ parameters: Schema66,
3834
+ execute: async () => {
3835
+ const jobs = await getClient().get("/cluster/backup");
3836
+ return jsonToolResult({ count: jobs.length, jobs });
3837
+ }
3838
+ };
3839
+ }
3840
+
3841
+ // src/tools/proxmox_create_backup_job.ts
3842
+ import { Type as Type71 } from "@sinclair/typebox";
3843
+ var Schema67 = Type71.Object(
3844
+ {
3845
+ schedule: Type71.String({ minLength: 1, description: "Systemd-calendar schedule, e.g. '02:00' or 'mon..fri 21:00'." }),
3846
+ storage: Type71.String({ minLength: 1, description: "Target storage for the backups." }),
3847
+ all: Type71.Optional(Type71.Boolean({ description: "Back up all guests. Mutually exclusive with vmid/pool." })),
3848
+ vmid: Type71.Optional(Type71.String({ minLength: 1, description: "Comma-separated VMIDs to back up." })),
3849
+ pool: Type71.Optional(Type71.String({ minLength: 1, description: "Back up all guests in this pool." })),
3850
+ mode: Type71.Optional(
3851
+ Type71.Union([Type71.Literal("snapshot"), Type71.Literal("suspend"), Type71.Literal("stop")], {
3852
+ description: "Backup mode (default snapshot)."
3853
+ })
3854
+ ),
3855
+ compress: Type71.Optional(
3856
+ Type71.Union([Type71.Literal("zstd"), Type71.Literal("gzip"), Type71.Literal("lzo"), Type71.Literal("0")], {
3857
+ description: "Compression (default zstd)."
3858
+ })
3859
+ ),
3860
+ enabled: Type71.Optional(Type71.Boolean({ description: "Whether the job is active (default true)." })),
3861
+ mailto: Type71.Optional(Type71.String({ minLength: 1, description: "Email address for notifications." })),
3862
+ comment: Type71.Optional(Type71.String({ description: "Job comment/description." })),
3863
+ confirm: Type71.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3864
+ },
3865
+ { additionalProperties: false }
3866
+ );
3867
+ var NAME64 = "proxmox_create_backup_job";
3868
+ function createProxmoxCreateBackupJobTool(getClient) {
3869
+ return {
3870
+ name: NAME64,
3871
+ label: "proxmox: create backup job",
3872
+ 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.",
3873
+ parameters: Schema67,
3874
+ execute: async (_id, raw) => {
3875
+ assertConfirmedWrite(raw, NAME64);
3876
+ const args = validateToolArgs(Schema67, raw, NAME64);
3877
+ const selectors = [args.all ? "all" : null, args.vmid ? "vmid" : null, args.pool ? "pool" : null].filter(Boolean);
3878
+ if (selectors.length === 0) {
3879
+ throw new ToolInputError(`${NAME64}: provide exactly one selection - all, vmid, or pool.`);
3880
+ }
3881
+ if (selectors.length > 1) {
3882
+ throw new ToolInputError(`${NAME64}: selection is exclusive - pass only one of all/vmid/pool.`);
3883
+ }
3884
+ const body = {
3885
+ schedule: args.schedule,
3886
+ storage: args.storage,
3887
+ mode: args.mode ?? "snapshot",
3888
+ compress: args.compress ?? "zstd",
3889
+ enabled: args.enabled === false ? 0 : 1
3890
+ };
3891
+ if (args.all) body.all = 1;
3892
+ if (args.vmid) body.vmid = args.vmid;
3893
+ if (args.pool) body.pool = args.pool;
3894
+ if (args.mailto) body.mailto = args.mailto;
3895
+ if (typeof args.comment === "string" && args.comment.length > 0) body.comment = args.comment;
3896
+ await getClient().post(`/cluster/backup`, body);
3897
+ return jsonToolResult({ schedule: args.schedule, storage: args.storage, created: true });
3898
+ }
3899
+ };
3900
+ }
3901
+
3902
+ // src/tools/proxmox_delete_backup_job.ts
3903
+ import { Type as Type72 } from "@sinclair/typebox";
3904
+ var Schema68 = Type72.Object(
3905
+ {
3906
+ id: Type72.String({ minLength: 1, description: "Backup job ID (from proxmox_list_backup_jobs)." }),
3907
+ confirm: Type72.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
3908
+ },
3909
+ { additionalProperties: false }
3910
+ );
3911
+ var NAME65 = "proxmox_delete_backup_job";
3912
+ function createProxmoxDeleteBackupJobTool(getClient) {
3913
+ return {
3914
+ name: NAME65,
3915
+ label: "proxmox: delete backup job",
3916
+ 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.",
3917
+ parameters: Schema68,
3918
+ execute: async (_id, raw) => {
3919
+ assertConfirmedWrite(raw, NAME65);
3920
+ const args = validateToolArgs(Schema68, raw, NAME65);
3921
+ assertSafePathSegment(args.id, "id");
3922
+ await getClient().delete(`/cluster/backup/${args.id}`);
3923
+ return jsonToolResult({ id: args.id, deleted: true });
3924
+ }
3925
+ };
3926
+ }
3927
+
3928
+ // src/tools/proxmox_list_users.ts
3929
+ import { Type as Type73 } from "@sinclair/typebox";
3930
+ var Schema69 = Type73.Object({}, { additionalProperties: false });
3931
+ var NAME66 = "proxmox_list_users";
3932
+ function createProxmoxListUsersTool(getClient) {
3933
+ return {
3934
+ name: NAME66,
3935
+ label: "proxmox: list users",
3936
+ description: "List Proxmox access users (GET /access/users): userid, realm, enabled/expire state, comment. Tier-1 read.",
3937
+ parameters: Schema69,
3938
+ execute: async () => {
3939
+ const users = await getClient().get("/access/users");
3940
+ return jsonToolResult({ count: users.length, users });
3941
+ }
3942
+ };
3943
+ }
3944
+
3945
+ // src/tools/proxmox_list_roles.ts
3946
+ import { Type as Type74 } from "@sinclair/typebox";
3947
+ var Schema70 = Type74.Object({}, { additionalProperties: false });
3948
+ var NAME67 = "proxmox_list_roles";
3949
+ function createProxmoxListRolesTool(getClient) {
3950
+ return {
3951
+ name: NAME67,
3952
+ label: "proxmox: list roles",
3953
+ description: "List Proxmox roles and their privileges (GET /access/roles). Tier-1 read.",
3954
+ parameters: Schema70,
3955
+ execute: async () => {
3956
+ const roles = await getClient().get("/access/roles");
3957
+ return jsonToolResult({ count: roles.length, roles });
3958
+ }
3959
+ };
3960
+ }
3961
+
3962
+ // src/tools/proxmox_list_acl.ts
3963
+ import { Type as Type75 } from "@sinclair/typebox";
3964
+ var Schema71 = Type75.Object({}, { additionalProperties: false });
3965
+ var NAME68 = "proxmox_list_acl";
3966
+ function createProxmoxListAclTool(getClient) {
3967
+ return {
3968
+ name: NAME68,
3969
+ label: "proxmox: list ACL",
3970
+ 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.",
3971
+ parameters: Schema71,
3972
+ execute: async () => {
3973
+ const acl = await getClient().get("/access/acl");
3974
+ return jsonToolResult({ count: acl.length, acl });
3975
+ }
3976
+ };
3977
+ }
3978
+
3979
+ // src/tools/proxmox_list_pools.ts
3980
+ import { Type as Type76 } from "@sinclair/typebox";
3981
+ var Schema72 = Type76.Object({}, { additionalProperties: false });
3982
+ var NAME69 = "proxmox_list_pools";
3983
+ function createProxmoxListPoolsTool(getClient) {
3984
+ return {
3985
+ name: NAME69,
3986
+ label: "proxmox: list pools",
3987
+ description: "List all resource pools (GET /pools) with their comments. Use proxmox_list_pool_resources for a pool's members. Tier-1 read.",
3988
+ parameters: Schema72,
3989
+ execute: async () => {
3990
+ const pools = await getClient().get("/pools");
3991
+ return jsonToolResult({ count: pools.length, pools });
3992
+ }
3993
+ };
3994
+ }
3995
+
3996
+ // src/tools/proxmox_list_tokens.ts
3997
+ import { Type as Type77 } from "@sinclair/typebox";
3998
+ var USERID_RE = /^[\w.+-]+@[\w.-]+$/;
3999
+ var Schema73 = Type77.Object(
4000
+ { userid: Type77.String({ minLength: 1, description: "User to list API tokens for, e.g. 'root@pam'." }) },
4001
+ { additionalProperties: false }
4002
+ );
4003
+ var NAME70 = "proxmox_list_tokens";
4004
+ function createProxmoxListTokensTool(getClient) {
4005
+ return {
4006
+ name: NAME70,
4007
+ label: "proxmox: list tokens",
4008
+ description: "List API tokens for a user (GET /access/users/{userid}/token). Secrets are never returned by Proxmox after creation. Tier-1 read.",
4009
+ parameters: Schema73,
4010
+ execute: async (_id, raw) => {
4011
+ const args = validateToolArgs(Schema73, raw, NAME70);
4012
+ if (!USERID_RE.test(args.userid)) throw new ToolInputError(`${NAME70}: invalid userid "${args.userid}"`);
4013
+ const tokens = await getClient().get(`/access/users/${encodeURIComponent(args.userid)}/token`);
4014
+ return jsonToolResult({ userid: args.userid, count: tokens.length, tokens });
4015
+ }
4016
+ };
4017
+ }
4018
+
4019
+ // src/tools/proxmox_set_acl.ts
4020
+ import { Type as Type78 } from "@sinclair/typebox";
4021
+ var ACL_PATH_RE = /^\/[\w./-]*$/;
4022
+ var ROLE_RE = /^[A-Za-z][\w.-]*$/;
4023
+ var UGID_RE = /^[\w.+-]+(@[\w.-]+)?(![\w.-]+)?$/;
4024
+ var Schema74 = Type78.Object(
4025
+ {
4026
+ path: Type78.String({ minLength: 1, description: "ACL path, e.g. '/vms/100', '/pool/team', '/storage/local', '/'." }),
4027
+ roles: Type78.String({ minLength: 1, description: "Role name(s), comma-separated, e.g. 'PVEVMAdmin'." }),
4028
+ userid: Type78.Optional(Type78.String({ minLength: 1, description: "User or token to grant, e.g. 'bob@pve' or 'bob@pve!ci'." })),
4029
+ group: Type78.Optional(Type78.String({ minLength: 1, description: "Group to grant." })),
4030
+ propagate: Type78.Optional(Type78.Boolean({ description: "Propagate to child paths (default true)." })),
4031
+ remove: Type78.Optional(Type78.Boolean({ description: "Remove the ACL instead of adding it." })),
4032
+ confirm: Type78.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4033
+ },
4034
+ { additionalProperties: false }
4035
+ );
4036
+ var NAME71 = "proxmox_set_acl";
4037
+ function createProxmoxSetAclTool(getClient) {
4038
+ return {
4039
+ name: NAME71,
4040
+ label: "proxmox: set ACL",
4041
+ 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.",
4042
+ parameters: Schema74,
4043
+ execute: async (_id, raw) => {
4044
+ assertConfirmedWrite(raw, NAME71);
4045
+ const args = validateToolArgs(Schema74, raw, NAME71);
4046
+ if (!ACL_PATH_RE.test(args.path)) throw new ToolInputError(`${NAME71}: invalid path "${args.path}"`);
4047
+ for (const r of args.roles.split(",")) {
4048
+ if (!ROLE_RE.test(r.trim())) throw new ToolInputError(`${NAME71}: invalid role "${r}"`);
4049
+ }
4050
+ if (!args.userid && !args.group) {
4051
+ throw new ToolInputError(`${NAME71}: provide userid or group.`);
4052
+ }
4053
+ const body = { path: args.path, roles: args.roles };
4054
+ if (args.userid) {
4055
+ if (!UGID_RE.test(args.userid)) throw new ToolInputError(`${NAME71}: invalid userid "${args.userid}"`);
4056
+ if (args.userid.includes("!")) body.tokens = args.userid;
4057
+ else body.users = args.userid;
4058
+ }
4059
+ if (args.group) body.groups = args.group;
4060
+ body.propagate = args.propagate === false ? 0 : 1;
4061
+ if (args.remove === true) body.delete = 1;
4062
+ await getClient().put(`/access/acl`, body);
4063
+ return jsonToolResult({
4064
+ path: args.path,
4065
+ roles: args.roles,
4066
+ userid: args.userid,
4067
+ group: args.group,
4068
+ removed: args.remove === true
4069
+ });
4070
+ }
4071
+ };
4072
+ }
4073
+
4074
+ // src/tools/proxmox_create_token.ts
4075
+ import { Type as Type79 } from "@sinclair/typebox";
4076
+ var TOKENID_RE = /^[\w.-]+$/;
4077
+ var Schema75 = Type79.Object(
4078
+ {
4079
+ userid: Type79.String({ minLength: 1, description: "Owning user, e.g. 'automation@pve'." }),
4080
+ tokenid: Type79.String({ minLength: 1, description: "New token name (the part after '!')." }),
4081
+ comment: Type79.Optional(Type79.String({ description: "Token comment." })),
4082
+ privsep: Type79.Optional(
4083
+ Type79.Boolean({ description: "Privilege separation (default true): the token gets only ACLs granted to it directly." })
4084
+ ),
4085
+ expire: Type79.Optional(Type79.Integer({ minimum: 0, description: "Expiry as a Unix timestamp (0 = never)." })),
4086
+ confirm: Type79.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4087
+ },
4088
+ { additionalProperties: false }
4089
+ );
4090
+ var NAME72 = "proxmox_create_token";
4091
+ function createProxmoxCreateTokenTool(getClient) {
4092
+ return {
4093
+ name: NAME72,
4094
+ label: "proxmox: create token",
4095
+ 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.",
4096
+ parameters: Schema75,
4097
+ execute: async (_id, raw) => {
4098
+ assertConfirmedWrite(raw, NAME72);
4099
+ const args = validateToolArgs(Schema75, raw, NAME72);
4100
+ if (!USERID_RE.test(args.userid)) throw new ToolInputError(`${NAME72}: invalid userid "${args.userid}"`);
4101
+ if (!TOKENID_RE.test(args.tokenid)) throw new ToolInputError(`${NAME72}: invalid tokenid "${args.tokenid}"`);
4102
+ const body = { privsep: args.privsep === false ? 0 : 1 };
4103
+ if (typeof args.comment === "string" && args.comment.length > 0) body.comment = args.comment;
4104
+ if (typeof args.expire === "number") body.expire = args.expire;
4105
+ const res = await getClient().post(
4106
+ `/access/users/${encodeURIComponent(args.userid)}/token/${encodeURIComponent(args.tokenid)}`,
4107
+ body
4108
+ );
4109
+ return jsonToolResult({
4110
+ userid: args.userid,
4111
+ tokenid: args.tokenid,
4112
+ full_tokenid: res?.["full-tokenid"] ?? `${args.userid}!${args.tokenid}`,
4113
+ secret: res?.value ?? null,
4114
+ note: "Store the secret now; Proxmox will not show it again."
4115
+ });
4116
+ }
4117
+ };
4118
+ }
4119
+
4120
+ // src/tools/proxmox_delete_token.ts
4121
+ import { Type as Type80 } from "@sinclair/typebox";
4122
+ var TOKENID_RE2 = /^[\w.-]+$/;
4123
+ var Schema76 = Type80.Object(
4124
+ {
4125
+ userid: Type80.String({ minLength: 1, description: "Owning user, e.g. 'automation@pve'." }),
4126
+ tokenid: Type80.String({ minLength: 1, description: "Token name to revoke (the part after '!')." }),
4127
+ confirm: Type80.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4128
+ },
4129
+ { additionalProperties: false }
4130
+ );
4131
+ var NAME73 = "proxmox_delete_token";
4132
+ function createProxmoxDeleteTokenTool(getClient) {
4133
+ return {
4134
+ name: NAME73,
4135
+ label: "proxmox: delete token",
4136
+ description: "Revoke an API token (DELETE /access/users/{userid}/token/{tokenid}). Immediately invalidates the token. Tier-2 write; requires confirm:true.",
4137
+ parameters: Schema76,
4138
+ execute: async (_id, raw) => {
4139
+ assertConfirmedWrite(raw, NAME73);
4140
+ const args = validateToolArgs(Schema76, raw, NAME73);
4141
+ if (!USERID_RE.test(args.userid)) throw new ToolInputError(`${NAME73}: invalid userid "${args.userid}"`);
4142
+ if (!TOKENID_RE2.test(args.tokenid)) throw new ToolInputError(`${NAME73}: invalid tokenid "${args.tokenid}"`);
4143
+ await getClient().delete(
4144
+ `/access/users/${encodeURIComponent(args.userid)}/token/${encodeURIComponent(args.tokenid)}`
4145
+ );
4146
+ return jsonToolResult({ userid: args.userid, tokenid: args.tokenid, deleted: true });
4147
+ }
4148
+ };
4149
+ }
4150
+
4151
+ // src/tools/proxmox_create_pool.ts
4152
+ import { Type as Type81 } from "@sinclair/typebox";
4153
+ var Schema77 = Type81.Object(
4154
+ {
4155
+ poolid: Type81.String({ minLength: 1, description: "New pool ID." }),
4156
+ comment: Type81.Optional(Type81.String({ description: "Pool comment/description." })),
4157
+ confirm: Type81.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4158
+ },
4159
+ { additionalProperties: false }
4160
+ );
4161
+ var NAME74 = "proxmox_create_pool";
4162
+ function createProxmoxCreatePoolTool(getClient) {
4163
+ return {
4164
+ name: NAME74,
4165
+ label: "proxmox: create pool",
4166
+ description: "Create a resource pool (POST /pools). Add guests/storage to it with proxmox_update_pool. Tier-2 write; requires confirm:true.",
4167
+ parameters: Schema77,
4168
+ execute: async (_id, raw) => {
4169
+ assertConfirmedWrite(raw, NAME74);
4170
+ const args = validateToolArgs(Schema77, raw, NAME74);
4171
+ assertSafePathSegment(args.poolid, "poolid");
4172
+ const body = { poolid: args.poolid };
4173
+ if (typeof args.comment === "string" && args.comment.length > 0) body.comment = args.comment;
4174
+ await getClient().post(`/pools`, body);
4175
+ return jsonToolResult({ poolid: args.poolid, created: true });
4176
+ }
4177
+ };
4178
+ }
4179
+
4180
+ // src/tools/proxmox_update_pool.ts
4181
+ import { Type as Type82 } from "@sinclair/typebox";
4182
+ var VMID_LIST_RE = /^\d+(,\d+)*$/;
4183
+ var Schema78 = Type82.Object(
4184
+ {
4185
+ poolid: Type82.String({ minLength: 1, description: "Pool to modify." }),
4186
+ vms: Type82.Optional(Type82.String({ minLength: 1, description: "Comma-separated VMIDs to add (or remove with remove:true)." })),
4187
+ storage: Type82.Optional(Type82.String({ minLength: 1, description: "Comma-separated storage IDs to add/remove." })),
4188
+ comment: Type82.Optional(Type82.String({ description: "Update the pool comment." })),
4189
+ remove: Type82.Optional(Type82.Boolean({ description: "Remove the listed members instead of adding them." })),
4190
+ confirm: Type82.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4191
+ },
4192
+ { additionalProperties: false }
4193
+ );
4194
+ var NAME75 = "proxmox_update_pool";
4195
+ function createProxmoxUpdatePoolTool(getClient) {
4196
+ return {
4197
+ name: NAME75,
4198
+ label: "proxmox: update pool",
4199
+ 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.",
4200
+ parameters: Schema78,
4201
+ execute: async (_id, raw) => {
4202
+ assertConfirmedWrite(raw, NAME75);
4203
+ const args = validateToolArgs(Schema78, raw, NAME75);
4204
+ assertSafePathSegment(args.poolid, "poolid");
4205
+ if (args.vms && !VMID_LIST_RE.test(args.vms)) {
4206
+ throw new ToolInputError(`${NAME75}: vms must be a comma-separated list of numeric VMIDs`);
4207
+ }
4208
+ if (!args.vms && !args.storage && typeof args.comment !== "string") {
4209
+ throw new ToolInputError(`${NAME75}: provide vms, storage, or comment to change.`);
4210
+ }
4211
+ const body = {};
4212
+ if (args.vms) body.vms = args.vms;
4213
+ if (args.storage) body.storage = args.storage;
4214
+ if (typeof args.comment === "string") body.comment = args.comment;
4215
+ if (args.remove === true) body.delete = 1;
4216
+ await getClient().put(`/pools/${args.poolid}`, body);
4217
+ return jsonToolResult({
4218
+ poolid: args.poolid,
4219
+ vms: args.vms,
4220
+ storage: args.storage,
4221
+ removed: args.remove === true
4222
+ });
4223
+ }
4224
+ };
4225
+ }
4226
+
4227
+ // src/tools/proxmox_delete_pool.ts
4228
+ import { Type as Type83 } from "@sinclair/typebox";
4229
+ var Schema79 = Type83.Object(
4230
+ {
4231
+ poolid: Type83.String({ minLength: 1, description: "Pool to delete (must be empty)." }),
4232
+ confirm: Type83.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4233
+ },
4234
+ { additionalProperties: false }
4235
+ );
4236
+ var NAME76 = "proxmox_delete_pool";
4237
+ function createProxmoxDeletePoolTool(getClient) {
4238
+ return {
4239
+ name: NAME76,
4240
+ label: "proxmox: delete pool",
4241
+ 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.",
4242
+ parameters: Schema79,
4243
+ execute: async (_id, raw) => {
4244
+ assertConfirmedWrite(raw, NAME76);
4245
+ const args = validateToolArgs(Schema79, raw, NAME76);
4246
+ assertSafePathSegment(args.poolid, "poolid");
4247
+ await getClient().delete(`/pools/${args.poolid}`);
4248
+ return jsonToolResult({ poolid: args.poolid, deleted: true });
4249
+ }
4250
+ };
4251
+ }
4252
+
4253
+ // src/tools/proxmox_cluster_status.ts
4254
+ import { Type as Type84 } from "@sinclair/typebox";
4255
+ var Schema80 = Type84.Object({}, { additionalProperties: false });
4256
+ var NAME77 = "proxmox_cluster_status";
4257
+ function createProxmoxClusterStatusTool(getClient) {
4258
+ return {
4259
+ name: NAME77,
4260
+ label: "proxmox: cluster status",
4261
+ description: "Cluster membership + quorum: each node's id, IP, online state, and (on a cluster) the quorate flag. (GET /cluster/status). Tier-1 read.",
4262
+ parameters: Schema80,
4263
+ execute: async () => {
4264
+ const items = await getClient().get("/cluster/status");
4265
+ const list = Array.isArray(items) ? items : [items];
4266
+ return jsonToolResult({ count: list.length, nodes: list });
4267
+ }
4268
+ };
4269
+ }
4270
+
4271
+ // src/tools/proxmox_ha_status.ts
4272
+ import { Type as Type85 } from "@sinclair/typebox";
4273
+ var Schema81 = Type85.Object({}, { additionalProperties: false });
4274
+ var NAME78 = "proxmox_ha_status";
4275
+ function createProxmoxHaStatusTool(getClient) {
4276
+ return {
4277
+ name: NAME78,
4278
+ label: "proxmox: HA status",
4279
+ description: "Current HA manager status: quorum, fencing/CRM state, and per-resource HA state. (GET /cluster/ha/status/current). Tier-1 read.",
4280
+ parameters: Schema81,
4281
+ execute: async () => {
4282
+ const items = await getClient().get("/cluster/ha/status/current");
4283
+ const list = Array.isArray(items) ? items : [items];
4284
+ return jsonToolResult({ count: list.length, entries: list });
4285
+ }
4286
+ };
4287
+ }
4288
+
4289
+ // src/tools/proxmox_list_ha_resources.ts
4290
+ import { Type as Type86 } from "@sinclair/typebox";
4291
+ var Schema82 = Type86.Object({}, { additionalProperties: false });
4292
+ var NAME79 = "proxmox_list_ha_resources";
4293
+ function createProxmoxListHaResourcesTool(getClient) {
4294
+ return {
4295
+ name: NAME79,
4296
+ label: "proxmox: list HA resources",
4297
+ description: "HA-managed resources (sid, state, group/comment). (GET /cluster/ha/resources). Tier-1 read.",
4298
+ parameters: Schema82,
4299
+ execute: async () => {
4300
+ const items = await getClient().get("/cluster/ha/resources");
4301
+ const list = Array.isArray(items) ? items : [items];
4302
+ return jsonToolResult({ count: list.length, resources: list });
4303
+ }
4304
+ };
4305
+ }
4306
+
4307
+ // src/tools/proxmox_list_ha_rules.ts
4308
+ import { Type as Type87 } from "@sinclair/typebox";
4309
+ var Schema83 = Type87.Object({}, { additionalProperties: false });
4310
+ var NAME80 = "proxmox_list_ha_rules";
4311
+ function createProxmoxListHaRulesTool(getClient) {
4312
+ return {
4313
+ name: NAME80,
4314
+ label: "proxmox: list HA rules",
4315
+ description: "HA rules (PVE 9+ replacement for HA groups): node affinity and resource placement. (GET /cluster/ha/rules). Tier-1 read.",
4316
+ parameters: Schema83,
4317
+ execute: async () => {
4318
+ const items = await getClient().get("/cluster/ha/rules");
4319
+ const list = Array.isArray(items) ? items : [items];
4320
+ return jsonToolResult({ count: list.length, rules: list });
4321
+ }
4322
+ };
4323
+ }
4324
+
4325
+ // src/tools/proxmox_list_replication.ts
4326
+ import { Type as Type88 } from "@sinclair/typebox";
4327
+ var Schema84 = Type88.Object({}, { additionalProperties: false });
4328
+ var NAME81 = "proxmox_list_replication";
4329
+ function createProxmoxListReplicationTool(getClient) {
4330
+ return {
4331
+ name: NAME81,
4332
+ label: "proxmox: list replication",
4333
+ description: "Storage replication jobs (id, source guest, target node, schedule). (GET /cluster/replication). Tier-1 read.",
4334
+ parameters: Schema84,
4335
+ execute: async () => {
4336
+ const items = await getClient().get("/cluster/replication");
4337
+ const list = Array.isArray(items) ? items : [items];
4338
+ return jsonToolResult({ count: list.length, jobs: list });
4339
+ }
4340
+ };
4341
+ }
4342
+
4343
+ // src/tools/proxmox_list_sdn_zones.ts
4344
+ import { Type as Type89 } from "@sinclair/typebox";
4345
+ var Schema85 = Type89.Object({}, { additionalProperties: false });
4346
+ var NAME82 = "proxmox_list_sdn_zones";
4347
+ function createProxmoxListSdnZonesTool(getClient) {
4348
+ return {
4349
+ name: NAME82,
4350
+ label: "proxmox: list SDN zones",
4351
+ description: "Software-defined-networking zones. (GET /cluster/sdn/zones). Tier-1 read.",
4352
+ parameters: Schema85,
4353
+ execute: async () => {
4354
+ const items = await getClient().get("/cluster/sdn/zones");
4355
+ const list = Array.isArray(items) ? items : [items];
4356
+ return jsonToolResult({ count: list.length, zones: list });
4357
+ }
4358
+ };
4359
+ }
4360
+
4361
+ // src/tools/proxmox_list_sdn_vnets.ts
4362
+ import { Type as Type90 } from "@sinclair/typebox";
4363
+ var Schema86 = Type90.Object({}, { additionalProperties: false });
4364
+ var NAME83 = "proxmox_list_sdn_vnets";
4365
+ function createProxmoxListSdnVnetsTool(getClient) {
4366
+ return {
4367
+ name: NAME83,
4368
+ label: "proxmox: list SDN vnets",
4369
+ description: "Software-defined-networking virtual networks. (GET /cluster/sdn/vnets). Tier-1 read.",
4370
+ parameters: Schema86,
4371
+ execute: async () => {
4372
+ const items = await getClient().get("/cluster/sdn/vnets");
4373
+ const list = Array.isArray(items) ? items : [items];
4374
+ return jsonToolResult({ count: list.length, vnets: list });
4375
+ }
4376
+ };
4377
+ }
4378
+
4379
+ // src/tools/proxmox_list_metric_servers.ts
4380
+ import { Type as Type91 } from "@sinclair/typebox";
4381
+ var Schema87 = Type91.Object({}, { additionalProperties: false });
4382
+ var NAME84 = "proxmox_list_metric_servers";
4383
+ function createProxmoxListMetricServersTool(getClient) {
4384
+ return {
4385
+ name: NAME84,
4386
+ label: "proxmox: list metric servers",
4387
+ description: "External metrics servers (InfluxDB/Graphite) configured for the cluster. (GET /cluster/metrics/server). Tier-1 read.",
4388
+ parameters: Schema87,
4389
+ execute: async () => {
4390
+ const items = await getClient().get("/cluster/metrics/server");
4391
+ const list = Array.isArray(items) ? items : [items];
4392
+ return jsonToolResult({ count: list.length, servers: list });
4393
+ }
4394
+ };
4395
+ }
4396
+
4397
+ // src/tools/proxmox_get_cluster_options.ts
4398
+ import { Type as Type92 } from "@sinclair/typebox";
4399
+ var Schema88 = Type92.Object({}, { additionalProperties: false });
4400
+ var NAME85 = "proxmox_get_cluster_options";
4401
+ function createProxmoxGetClusterOptionsTool(getClient) {
4402
+ return {
4403
+ name: NAME85,
4404
+ label: "proxmox: get cluster options",
4405
+ description: "Read datacenter-wide options (GET /cluster/options): keyboard, MAC prefix, allowed tags, default migration settings, etc. Tier-1 read.",
4406
+ parameters: Schema88,
4407
+ execute: async () => {
4408
+ const options = await getClient().get("/cluster/options");
4409
+ return jsonToolResult({ options });
4410
+ }
4411
+ };
4412
+ }
4413
+
4414
+ // src/tools/proxmox_cluster_log.ts
4415
+ import { Type as Type93 } from "@sinclair/typebox";
4416
+ var Schema89 = Type93.Object(
4417
+ {
4418
+ max: Type93.Optional(
4419
+ Type93.Integer({ minimum: 1, maximum: 1e3, description: "Max number of recent log entries (default 50)." })
4420
+ )
4421
+ },
4422
+ { additionalProperties: false }
4423
+ );
4424
+ var NAME86 = "proxmox_cluster_log";
4425
+ function createProxmoxClusterLogTool(getClient) {
4426
+ return {
4427
+ name: NAME86,
4428
+ label: "proxmox: cluster log",
4429
+ description: "Read the recent cluster-wide log (GET /cluster/log): task start/end, auth, and daemon messages across all nodes. Tier-1 read.",
4430
+ parameters: Schema89,
4431
+ execute: async (_id, raw) => {
4432
+ const args = validateToolArgs(Schema89, raw, NAME86);
4433
+ const max = args.max ?? 50;
4434
+ const entries = await getClient().get(`/cluster/log?max=${max}`);
4435
+ return jsonToolResult({ count: Array.isArray(entries) ? entries.length : 0, entries });
4436
+ }
4437
+ };
4438
+ }
4439
+
4440
+ // src/tools/proxmox_add_ha_resource.ts
4441
+ import { Type as Type94 } from "@sinclair/typebox";
4442
+ var SID_RE = /^(vm|ct):\d+$/;
4443
+ var Schema90 = Type94.Object(
4444
+ {
4445
+ sid: Type94.String({ minLength: 1, description: "HA resource id, 'vm:<vmid>' or 'ct:<vmid>'." }),
4446
+ state: Type94.Optional(
4447
+ Type94.Union(
4448
+ [Type94.Literal("started"), Type94.Literal("stopped"), Type94.Literal("disabled"), Type94.Literal("ignored")],
4449
+ { description: "Requested HA state (default 'started')." }
4450
+ )
4451
+ ),
4452
+ comment: Type94.Optional(Type94.String({ description: "Comment." })),
4453
+ max_restart: Type94.Optional(Type94.Integer({ minimum: 0, description: "Max restart attempts on the same node." })),
4454
+ max_relocate: Type94.Optional(Type94.Integer({ minimum: 0, description: "Max relocation attempts to other nodes." })),
4455
+ confirm: Type94.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4456
+ },
4457
+ { additionalProperties: false }
4458
+ );
4459
+ var NAME87 = "proxmox_add_ha_resource";
4460
+ function createProxmoxAddHaResourceTool(getClient) {
4461
+ return {
4462
+ name: NAME87,
4463
+ label: "proxmox: add HA resource",
4464
+ 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.",
4465
+ parameters: Schema90,
4466
+ execute: async (_id, raw) => {
4467
+ assertConfirmedWrite(raw, NAME87);
4468
+ const args = validateToolArgs(Schema90, raw, NAME87);
4469
+ if (!SID_RE.test(args.sid)) throw new ToolInputError(`${NAME87}: sid must be 'vm:<vmid>' or 'ct:<vmid>'`);
4470
+ const body = { sid: args.sid, state: args.state ?? "started" };
4471
+ if (typeof args.comment === "string" && args.comment.length > 0) body.comment = args.comment;
4472
+ if (typeof args.max_restart === "number") body.max_restart = args.max_restart;
4473
+ if (typeof args.max_relocate === "number") body.max_relocate = args.max_relocate;
4474
+ await getClient().post(`/cluster/ha/resources`, body);
4475
+ return jsonToolResult({ sid: args.sid, state: args.state ?? "started", added: true });
4476
+ }
4477
+ };
4478
+ }
4479
+
4480
+ // src/tools/proxmox_delete_ha_resource.ts
4481
+ import { Type as Type95 } from "@sinclair/typebox";
4482
+ var SID_RE2 = /^(vm|ct):\d+$/;
4483
+ var Schema91 = Type95.Object(
4484
+ {
4485
+ sid: Type95.String({ minLength: 1, description: "HA resource id to remove, 'vm:<vmid>' or 'ct:<vmid>'." }),
4486
+ confirm: Type95.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4487
+ },
4488
+ { additionalProperties: false }
4489
+ );
4490
+ var NAME88 = "proxmox_delete_ha_resource";
4491
+ function createProxmoxDeleteHaResourceTool(getClient) {
4492
+ return {
4493
+ name: NAME88,
4494
+ label: "proxmox: delete HA resource",
4495
+ 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.",
4496
+ parameters: Schema91,
4497
+ execute: async (_id, raw) => {
4498
+ assertConfirmedWrite(raw, NAME88);
4499
+ const args = validateToolArgs(Schema91, raw, NAME88);
4500
+ if (!SID_RE2.test(args.sid)) throw new ToolInputError(`${NAME88}: sid must be 'vm:<vmid>' or 'ct:<vmid>'`);
4501
+ await getClient().delete(`/cluster/ha/resources/${encodeURIComponent(args.sid)}`);
4502
+ return jsonToolResult({ sid: args.sid, deleted: true });
4503
+ }
4504
+ };
4505
+ }
4506
+
4507
+ // src/tools/proxmox_create_replication.ts
4508
+ import { Type as Type96 } from "@sinclair/typebox";
4509
+ var Schema92 = Type96.Object(
4510
+ {
4511
+ vmid: Type96.Integer({ minimum: 1, description: "Guest to replicate." }),
4512
+ target: Type96.String({ minLength: 1, description: "Target node to replicate to (must differ from the source node)." }),
4513
+ job_number: Type96.Optional(Type96.Integer({ minimum: 0, description: "Job number, forming the id '<vmid>-<n>' (default 0)." })),
4514
+ schedule: Type96.Optional(Type96.String({ minLength: 1, description: "Replication schedule, e.g. '*/15' or '02:00' (default '*/15')." })),
4515
+ rate: Type96.Optional(Type96.Number({ minimum: 0, description: "Rate limit in MB/s (0 = unlimited)." })),
4516
+ comment: Type96.Optional(Type96.String({ description: "Comment." })),
4517
+ disable: Type96.Optional(Type96.Boolean({ description: "Create the job disabled." })),
4518
+ confirm: Type96.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4519
+ },
4520
+ { additionalProperties: false }
4521
+ );
4522
+ var NAME89 = "proxmox_create_replication";
4523
+ function createProxmoxCreateReplicationTool(getClient) {
4524
+ return {
4525
+ name: NAME89,
4526
+ label: "proxmox: create replication",
4527
+ 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.",
4528
+ parameters: Schema92,
4529
+ execute: async (_id, raw) => {
4530
+ assertConfirmedWrite(raw, NAME89);
4531
+ const args = validateToolArgs(Schema92, raw, NAME89);
4532
+ assertSafePathSegment(args.target, "target");
4533
+ const client = getClient();
4534
+ const { node } = await resolveResource(client, args.vmid);
4535
+ if (args.target === node) {
4536
+ throw new Error(`replication target ${args.target} must differ from the guest's node ${node}.`);
4537
+ }
4538
+ const id = `${args.vmid}-${args.job_number ?? 0}`;
4539
+ const body = {
4540
+ id,
4541
+ type: "local",
4542
+ target: args.target,
4543
+ schedule: args.schedule ?? "*/15"
4544
+ };
4545
+ if (typeof args.rate === "number") body.rate = args.rate;
4546
+ if (typeof args.comment === "string" && args.comment.length > 0) body.comment = args.comment;
4547
+ if (args.disable) body.disable = 1;
4548
+ await client.post(`/cluster/replication`, body);
4549
+ return jsonToolResult({ id, vmid: args.vmid, node, target: args.target, created: true });
4550
+ }
4551
+ };
4552
+ }
4553
+
4554
+ // src/tools/proxmox_delete_replication.ts
4555
+ import { Type as Type97 } from "@sinclair/typebox";
4556
+ var REPL_ID_RE = /^\d+-\d+$/;
4557
+ var Schema93 = Type97.Object(
4558
+ {
4559
+ id: Type97.String({ minLength: 1, description: "Replication job id, '<vmid>-<n>' (from proxmox_list_replication)." }),
4560
+ force: Type97.Optional(Type97.Boolean({ description: "Force removal even if the target is unreachable." })),
4561
+ confirm: Type97.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
4562
+ },
4563
+ { additionalProperties: false }
4564
+ );
4565
+ var NAME90 = "proxmox_delete_replication";
4566
+ function createProxmoxDeleteReplicationTool(getClient) {
4567
+ return {
4568
+ name: NAME90,
4569
+ label: "proxmox: delete replication",
4570
+ description: "Delete a storage replication job (DELETE /cluster/replication/{id}). Tier-2 write; requires confirm:true.",
4571
+ parameters: Schema93,
4572
+ execute: async (_id, raw) => {
4573
+ assertConfirmedWrite(raw, NAME90);
4574
+ const args = validateToolArgs(Schema93, raw, NAME90);
4575
+ if (!REPL_ID_RE.test(args.id)) throw new ToolInputError(`${NAME90}: id must be '<vmid>-<n>'`);
4576
+ const qs = args.force ? "?force=1" : "";
4577
+ await getClient().delete(`/cluster/replication/${args.id}${qs}`);
4578
+ return jsonToolResult({ id: args.id, deleted: true });
4579
+ }
4580
+ };
4581
+ }
4582
+
4583
+ // index.ts
4584
+ function withRedactedErrors(tool) {
4585
+ const orig = tool.execute.bind(tool);
4586
+ return {
4587
+ ...tool,
4588
+ execute: async (id, args) => {
4589
+ try {
4590
+ return await orig(id, args);
4591
+ } catch (e) {
4592
+ const msg = redact(e.message);
4593
+ return { content: [{ type: "text", text: JSON.stringify({ error: msg }) }], isError: true };
4594
+ }
4595
+ }
4596
+ };
4597
+ }
4598
+ function makeFactory(cfg) {
4599
+ registerSecret(cfg.tokenId);
4600
+ registerSecret(cfg.tokenSecret);
4601
+ registerSecret(`PVEAPIToken=${cfg.tokenId}=${cfg.tokenSecret}`);
4602
+ return () => new ProxmoxClient(cfg);
4603
+ }
4604
+ var index_default = definePluginEntry({
4605
+ id: "proxmox",
4606
+ name: "Proxmox",
4607
+ description: "Proxmox VE control: status, container + VM lifecycle, snapshots, backups, recent tasks. Single-cluster, token auth, optional TLS-insecure. Tier-2 writes gated by confirm:true.",
4608
+ register(api) {
4609
+ if (api.registrationMode !== "full") return;
4610
+ const cfg = resolveConfig(process.env);
4611
+ const getClient = makeFactory(cfg);
4612
+ const hostCfg = { host: cfg.ssh.host, port: cfg.ssh.port, user: cfg.ssh.user, keyPath: cfg.ssh.keyPath };
4613
+ const getSsh = () => ({
4614
+ execInLxc: (vmid, command, timeoutMs, stdin) => execInLxc(hostCfg, vmid, command, timeoutMs, stdin),
4615
+ execViaDirectSsh: (target, command, timeoutMs, stdin) => execViaDirectSsh(target, command, timeoutMs, stdin)
4616
+ });
4617
+ const vmDefaults = { vmUser: cfg.ssh.vmUser, vmKeyPath: cfg.ssh.vmKeyPath };
4618
+ const register = (t) => api.registerTool(withRedactedErrors(t));
4619
+ register(createProxmoxStatusTool(getClient));
4620
+ register(createProxmoxListContainersTool(getClient));
4621
+ register(createProxmoxListVmsTool(getClient));
4622
+ register(createProxmoxGetResourceTool(getClient));
4623
+ register(createProxmoxGetVmConfigTool(getClient));
4624
+ register(createProxmoxGetContainerConfigTool(getClient));
4625
+ register(createProxmoxValidateQemuSmokeSourceTool(getClient));
4626
+ register(createProxmoxAuditPermissionsTool(getClient));
4627
+ register(createProxmoxRecentTasksTool(getClient));
4628
+ register(createProxmoxListBackupsTool(getClient));
4629
+ register(createProxmoxResourceUsageTool(getClient));
4630
+ register(createProxmoxListTemplatesTool(getClient));
4631
+ register(createProxmoxListStorageTool(getClient));
4632
+ register(createProxmoxListSnapshotsTool(getClient));
4633
+ register(createProxmoxGuestNetworkTool(getClient));
4634
+ register(createProxmoxWaitTaskTool(getClient));
4635
+ register(createProxmoxNextVmidTool(getClient));
4636
+ register(createProxmoxListPoolResourcesTool(getClient));
4637
+ register(createProxmoxGetTaskStatusTool(getClient));
4638
+ register(createProxmoxGetTaskLogTool(getClient));
4639
+ register(createProxmoxListStorageContentTool(getClient));
4640
+ register(createProxmoxListNodeServicesTool(getClient));
4641
+ register(createProxmoxListUpdatesTool(getClient));
4642
+ register(createProxmoxListDisksTool(getClient));
4643
+ register(createProxmoxListFirewallRulesTool(getClient));
4644
+ register(createProxmoxGetFirewallOptionsTool(getClient));
4645
+ register(createProxmoxListStorageConfigTool(getClient));
4646
+ register(createProxmoxListBackupJobsTool(getClient));
4647
+ register(createProxmoxListUsersTool(getClient));
4648
+ register(createProxmoxListRolesTool(getClient));
4649
+ register(createProxmoxListAclTool(getClient));
4650
+ register(createProxmoxListPoolsTool(getClient));
4651
+ register(createProxmoxListTokensTool(getClient));
4652
+ register(createProxmoxClusterStatusTool(getClient));
4653
+ register(createProxmoxHaStatusTool(getClient));
4654
+ register(createProxmoxListHaResourcesTool(getClient));
4655
+ register(createProxmoxListHaRulesTool(getClient));
4656
+ register(createProxmoxListReplicationTool(getClient));
4657
+ register(createProxmoxListSdnZonesTool(getClient));
4658
+ register(createProxmoxListSdnVnetsTool(getClient));
4659
+ register(createProxmoxListMetricServersTool(getClient));
4660
+ register(createProxmoxGetClusterOptionsTool(getClient));
4661
+ register(createProxmoxClusterLogTool(getClient));
1615
4662
  register(createProxmoxStartResourceTool(getClient));
1616
4663
  register(createProxmoxStopResourceTool(getClient));
1617
4664
  register(createProxmoxRebootResourceTool(getClient));
4665
+ register(createProxmoxSuspendResourceTool(getClient));
4666
+ register(createProxmoxResumeResourceTool(getClient));
4667
+ register(createProxmoxResetResourceTool(getClient));
1618
4668
  register(createProxmoxSnapshotResourceTool(getClient));
1619
4669
  register(createProxmoxRunBackupTool(getClient));
1620
- register(createProxmoxGetTaskStatusTool(getClient));
1621
- register(createProxmoxGetTaskLogTool(getClient));
1622
- register(createProxmoxListTemplatesTool(getClient));
1623
4670
  register(createProxmoxCreateContainerTool(getClient));
1624
4671
  register(createProxmoxCreateVmTool(getClient));
1625
4672
  register(createProxmoxCloneResourceTool(getClient));
4673
+ register(createProxmoxConvertToTemplateTool(getClient));
4674
+ register(createProxmoxUpdateVmConfigTool(getClient));
4675
+ register(createProxmoxUpdateContainerConfigTool(getClient));
4676
+ register(createProxmoxResizeDiskTool(getClient));
4677
+ register(createProxmoxRestoreBackupTool(getClient));
4678
+ register(createProxmoxMigrateResourceTool(getClient));
4679
+ register(createProxmoxMoveDiskTool(getClient));
4680
+ register(createProxmoxCreateStorageTool(getClient));
4681
+ register(createProxmoxCreateBackupJobTool(getClient));
4682
+ register(createProxmoxDeleteBackupJobTool(getClient));
4683
+ register(createProxmoxSetAclTool(getClient));
4684
+ register(createProxmoxCreateTokenTool(getClient));
4685
+ register(createProxmoxDeleteTokenTool(getClient));
4686
+ register(createProxmoxCreatePoolTool(getClient));
4687
+ register(createProxmoxUpdatePoolTool(getClient));
4688
+ register(createProxmoxDeletePoolTool(getClient));
4689
+ register(createProxmoxAddHaResourceTool(getClient));
4690
+ register(createProxmoxDeleteHaResourceTool(getClient));
4691
+ register(createProxmoxCreateReplicationTool(getClient));
4692
+ register(createProxmoxDeleteReplicationTool(getClient));
4693
+ register(createProxmoxDownloadUrlTool(getClient));
4694
+ register(createProxmoxCancelTaskTool(getClient));
4695
+ register(createProxmoxAddFirewallRuleTool(getClient));
4696
+ register(createProxmoxDeleteFirewallRuleTool(getClient));
4697
+ register(createProxmoxSetFirewallEnabledTool(getClient));
4698
+ register(createProxmoxExecTool(getClient, getSsh, vmDefaults));
4699
+ register(createProxmoxReadFileTool(getClient, getSsh, vmDefaults));
4700
+ register(createProxmoxWriteFileTool(getClient, getSsh, vmDefaults));
4701
+ register(createProxmoxStatPathTool(getClient, getSsh, vmDefaults));
4702
+ register(createProxmoxListDirectoryTool(getClient, getSsh, vmDefaults));
4703
+ register(createProxmoxServiceStatusTool(getClient, getSsh, vmDefaults));
4704
+ register(createProxmoxServiceStartTool(getClient, getSsh, vmDefaults));
4705
+ register(createProxmoxServiceStopTool(getClient, getSsh, vmDefaults));
4706
+ register(createProxmoxServiceRestartTool(getClient, getSsh, vmDefaults));
4707
+ register(createProxmoxRollbackSnapshotTool(getClient));
1626
4708
  register(createProxmoxDestroyResourceTool(getClient));
4709
+ register(createProxmoxCleanupSmokeResourcesTool(getClient));
1627
4710
  register(createProxmoxDeleteSnapshotTool(getClient));
1628
4711
  register(createProxmoxForceStopResourceTool(getClient));
4712
+ register(createProxmoxDeleteVolumeTool(getClient));
4713
+ register(createProxmoxNodePowerTool(getClient));
4714
+ register(createProxmoxDeleteStorageTool(getClient));
1629
4715
  }
1630
4716
  });
1631
4717
  export {