@solomonneas/proxmox-mcp 0.1.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/LICENSE +21 -0
- package/README.md +137 -0
- package/dist/index.js +645 -0
- package/dist/mcp-server.js +638 -0
- package/openclaw.plugin.json +12 -0
- package/package.json +45 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// index.ts
|
|
4
|
+
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
5
|
+
|
|
6
|
+
// src/config.ts
|
|
7
|
+
var ConfigError = class extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "ConfigError";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
function isTruthy(value) {
|
|
14
|
+
if (!value) return false;
|
|
15
|
+
return ["true", "1", "yes"].includes(value.toLowerCase());
|
|
16
|
+
}
|
|
17
|
+
function resolveConfig(env) {
|
|
18
|
+
const url = env.PROXMOX_URL;
|
|
19
|
+
const tokenId = env.PROXMOX_TOKEN_ID;
|
|
20
|
+
const tokenSecret = env.PROXMOX_TOKEN_SECRET;
|
|
21
|
+
if (!url) throw new ConfigError("PROXMOX_URL is required");
|
|
22
|
+
if (!tokenId) throw new ConfigError("PROXMOX_TOKEN_ID is required");
|
|
23
|
+
if (!tokenSecret) throw new ConfigError("PROXMOX_TOKEN_SECRET is required");
|
|
24
|
+
return {
|
|
25
|
+
url: url.replace(/\/+$/, ""),
|
|
26
|
+
tokenId,
|
|
27
|
+
tokenSecret,
|
|
28
|
+
tlsInsecure: isTruthy(env.PROXMOX_TLS_INSECURE)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/proxmox-client.ts
|
|
33
|
+
import { Agent as UndiciAgent } from "undici";
|
|
34
|
+
var ProxmoxClientError = class extends Error {
|
|
35
|
+
constructor(status, message) {
|
|
36
|
+
super(`Proxmox ${status}: ${message}`);
|
|
37
|
+
this.status = status;
|
|
38
|
+
this.name = "ProxmoxClientError";
|
|
39
|
+
}
|
|
40
|
+
status;
|
|
41
|
+
};
|
|
42
|
+
var ProxmoxUnreachableError = class extends Error {
|
|
43
|
+
constructor(cause) {
|
|
44
|
+
super(`Proxmox unreachable: ${cause}`);
|
|
45
|
+
this.name = "ProxmoxUnreachableError";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var ProxmoxClient = class {
|
|
49
|
+
constructor(cfg, opts = {}) {
|
|
50
|
+
this.cfg = cfg;
|
|
51
|
+
this.authHeader = `PVEAPIToken=${cfg.tokenId}=${cfg.tokenSecret}`;
|
|
52
|
+
this.retryDelayMs = opts.retryDelayMs ?? 1e3;
|
|
53
|
+
if (cfg.tlsInsecure && cfg.url.startsWith("https://")) {
|
|
54
|
+
this.dispatcher = new UndiciAgent({ connect: { rejectUnauthorized: false } });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
cfg;
|
|
58
|
+
authHeader;
|
|
59
|
+
retryDelayMs;
|
|
60
|
+
// Node's global fetch (undici) ignores node:https.Agent. To actually skip
|
|
61
|
+
// cert verification for self-signed PVE hosts we pass an undici Agent via
|
|
62
|
+
// the `dispatcher` init option.
|
|
63
|
+
dispatcher;
|
|
64
|
+
async get(path) {
|
|
65
|
+
return this.request("GET", path);
|
|
66
|
+
}
|
|
67
|
+
async post(path, body) {
|
|
68
|
+
return this.request("POST", path, body);
|
|
69
|
+
}
|
|
70
|
+
async request(method, path, body) {
|
|
71
|
+
const url = this.cfg.url + "/api2/json" + path;
|
|
72
|
+
const headers = { authorization: this.authHeader };
|
|
73
|
+
let bodyStr;
|
|
74
|
+
if (body !== void 0) {
|
|
75
|
+
if (body && typeof body === "object" && !Array.isArray(body)) {
|
|
76
|
+
const form = new URLSearchParams();
|
|
77
|
+
for (const [k, v] of Object.entries(body)) {
|
|
78
|
+
if (v === void 0 || v === null) continue;
|
|
79
|
+
form.append(k, typeof v === "object" ? JSON.stringify(v) : String(v));
|
|
80
|
+
}
|
|
81
|
+
headers["content-type"] = "application/x-www-form-urlencoded";
|
|
82
|
+
bodyStr = form.toString();
|
|
83
|
+
} else {
|
|
84
|
+
headers["content-type"] = "application/json";
|
|
85
|
+
bodyStr = JSON.stringify(body);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
let lastErr;
|
|
89
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
90
|
+
try {
|
|
91
|
+
const init = { method, headers, body: bodyStr };
|
|
92
|
+
if (this.dispatcher) init.dispatcher = this.dispatcher;
|
|
93
|
+
const res = await fetch(url, init);
|
|
94
|
+
if (res.status >= 200 && res.status < 300) {
|
|
95
|
+
const text = await res.text();
|
|
96
|
+
if (!text) return void 0;
|
|
97
|
+
const parsed = JSON.parse(text);
|
|
98
|
+
return parsed && typeof parsed === "object" && "data" in parsed ? parsed.data : parsed;
|
|
99
|
+
}
|
|
100
|
+
if (res.status >= 500) {
|
|
101
|
+
lastErr = new ProxmoxUnreachableError(`HTTP ${res.status}`);
|
|
102
|
+
if (attempt === 0) await sleep(this.retryDelayMs);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const errText = await res.text();
|
|
106
|
+
let msg = errText;
|
|
107
|
+
try {
|
|
108
|
+
msg = JSON.parse(errText).message ?? errText;
|
|
109
|
+
} catch {
|
|
110
|
+
}
|
|
111
|
+
throw new ProxmoxClientError(res.status, msg);
|
|
112
|
+
} catch (e) {
|
|
113
|
+
if (e instanceof ProxmoxClientError) throw e;
|
|
114
|
+
lastErr = new ProxmoxUnreachableError(e.message);
|
|
115
|
+
if (attempt === 0) await sleep(this.retryDelayMs);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
throw lastErr ?? new ProxmoxUnreachableError("unknown");
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
function sleep(ms) {
|
|
122
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/security.ts
|
|
126
|
+
var SECRETS = /* @__PURE__ */ new Set();
|
|
127
|
+
var BASE64_TOKEN_RE = /[A-Za-z0-9+/=]{12,}/g;
|
|
128
|
+
function registerSecret(s) {
|
|
129
|
+
if (s && s.length > 0) SECRETS.add(s);
|
|
130
|
+
}
|
|
131
|
+
function maskString(s) {
|
|
132
|
+
let out = s;
|
|
133
|
+
for (const secret of SECRETS) {
|
|
134
|
+
if (out.includes(secret)) out = out.split(secret).join("REDACTED");
|
|
135
|
+
}
|
|
136
|
+
out = out.replace(BASE64_TOKEN_RE, (token) => {
|
|
137
|
+
try {
|
|
138
|
+
const decoded = Buffer.from(token, "base64").toString("utf8");
|
|
139
|
+
for (const secret of SECRETS) {
|
|
140
|
+
if (decoded.includes(secret)) return "REDACTED";
|
|
141
|
+
}
|
|
142
|
+
} catch {
|
|
143
|
+
}
|
|
144
|
+
return token;
|
|
145
|
+
});
|
|
146
|
+
return out;
|
|
147
|
+
}
|
|
148
|
+
function redact(value) {
|
|
149
|
+
if (typeof value === "string") return maskString(value);
|
|
150
|
+
if (Array.isArray(value)) return value.map(redact);
|
|
151
|
+
if (value && typeof value === "object") {
|
|
152
|
+
const out = {};
|
|
153
|
+
for (const [k, v] of Object.entries(value)) out[k] = redact(v);
|
|
154
|
+
return out;
|
|
155
|
+
}
|
|
156
|
+
return value;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// src/tools/proxmox_status.ts
|
|
160
|
+
import { Type } from "@sinclair/typebox";
|
|
161
|
+
|
|
162
|
+
// src/tools/_util.ts
|
|
163
|
+
function jsonToolResult(payload) {
|
|
164
|
+
return {
|
|
165
|
+
content: [{ type: "text", text: JSON.stringify(payload, null, 2) }]
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
async function resolveResource(client, vmid) {
|
|
169
|
+
const resources = await client.get(
|
|
170
|
+
"/cluster/resources"
|
|
171
|
+
);
|
|
172
|
+
const matches = resources.filter((x) => x.vmid === vmid && (x.type === "lxc" || x.type === "qemu"));
|
|
173
|
+
if (matches.length === 0) {
|
|
174
|
+
throw new Error(`vmid ${vmid} not found in cluster resources (not an LXC or VM)`);
|
|
175
|
+
}
|
|
176
|
+
if (matches.length > 1) {
|
|
177
|
+
const where = matches.map((m) => `${m.node}/${m.type}`).join(", ");
|
|
178
|
+
throw new Error(`vmid ${vmid} ambiguous - found on multiple nodes: ${where}. Refusing to proceed.`);
|
|
179
|
+
}
|
|
180
|
+
return { node: matches[0].node, type: matches[0].type };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// src/tools/proxmox_status.ts
|
|
184
|
+
var Schema = Type.Object({}, { additionalProperties: false });
|
|
185
|
+
function createProxmoxStatusTool(getClient) {
|
|
186
|
+
return {
|
|
187
|
+
name: "proxmox_status",
|
|
188
|
+
label: "proxmox: status",
|
|
189
|
+
description: "Get PVE version + per-node status (online state, CPU, memory, uptime) via GET /version + GET /cluster/resources?type=node.",
|
|
190
|
+
parameters: Schema,
|
|
191
|
+
execute: async () => {
|
|
192
|
+
const client = getClient();
|
|
193
|
+
const [version, nodes] = await Promise.all([
|
|
194
|
+
client.get("/version"),
|
|
195
|
+
client.get("/cluster/resources?type=node")
|
|
196
|
+
]);
|
|
197
|
+
return jsonToolResult({ version: version.version, release: version.release, nodes });
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// src/tools/proxmox_list_containers.ts
|
|
203
|
+
import { Type as Type2 } from "@sinclair/typebox";
|
|
204
|
+
var Schema2 = Type2.Object({}, { additionalProperties: false });
|
|
205
|
+
function createProxmoxListContainersTool(getClient) {
|
|
206
|
+
return {
|
|
207
|
+
name: "proxmox_list_containers",
|
|
208
|
+
label: "proxmox: list containers",
|
|
209
|
+
description: "List every LXC container across the cluster (vmid, name, node, status, CPU/mem) via GET /cluster/resources?type=vm filtered client-side to type=lxc.",
|
|
210
|
+
parameters: Schema2,
|
|
211
|
+
execute: async () => {
|
|
212
|
+
const client = getClient();
|
|
213
|
+
const all = await client.get("/cluster/resources?type=vm");
|
|
214
|
+
const containers = all.filter((r) => r.type === "lxc");
|
|
215
|
+
return jsonToolResult({ count: containers.length, containers });
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/tools/proxmox_list_vms.ts
|
|
221
|
+
import { Type as Type3 } from "@sinclair/typebox";
|
|
222
|
+
var Schema3 = Type3.Object({}, { additionalProperties: false });
|
|
223
|
+
function createProxmoxListVmsTool(getClient) {
|
|
224
|
+
return {
|
|
225
|
+
name: "proxmox_list_vms",
|
|
226
|
+
label: "proxmox: list VMs",
|
|
227
|
+
description: "List every QEMU VM across the cluster (vmid, name, node, status, CPU/mem) via GET /cluster/resources?type=vm filtered client-side to type=qemu.",
|
|
228
|
+
parameters: Schema3,
|
|
229
|
+
execute: async () => {
|
|
230
|
+
const client = getClient();
|
|
231
|
+
const all = await client.get("/cluster/resources?type=vm");
|
|
232
|
+
const vms = all.filter((r) => r.type === "qemu");
|
|
233
|
+
return jsonToolResult({ count: vms.length, vms });
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/tools/proxmox_get_resource.ts
|
|
239
|
+
import { Type as Type4 } from "@sinclair/typebox";
|
|
240
|
+
var Schema4 = Type4.Object(
|
|
241
|
+
{
|
|
242
|
+
vmid: Type4.Integer({ minimum: 1, description: "Container or VM ID." })
|
|
243
|
+
},
|
|
244
|
+
{ additionalProperties: false }
|
|
245
|
+
);
|
|
246
|
+
function createProxmoxGetResourceTool(getClient) {
|
|
247
|
+
return {
|
|
248
|
+
name: "proxmox_get_resource",
|
|
249
|
+
label: "proxmox: get resource",
|
|
250
|
+
description: "Get full current status for one LXC or VM by vmid (resolves node+type from cluster resources, then GET /nodes/{node}/{type}/{vmid}/status/current).",
|
|
251
|
+
parameters: Schema4,
|
|
252
|
+
execute: async (_id, raw) => {
|
|
253
|
+
const args = raw;
|
|
254
|
+
const client = getClient();
|
|
255
|
+
const { node, type } = await resolveResource(client, args.vmid);
|
|
256
|
+
const status = await client.get(
|
|
257
|
+
`/nodes/${node}/${type}/${args.vmid}/status/current`
|
|
258
|
+
);
|
|
259
|
+
return jsonToolResult({ vmid: args.vmid, node, type, status });
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// src/tools/proxmox_recent_tasks.ts
|
|
265
|
+
import { Type as Type5 } from "@sinclair/typebox";
|
|
266
|
+
var Schema5 = Type5.Object(
|
|
267
|
+
{
|
|
268
|
+
limit: Type5.Optional(
|
|
269
|
+
Type5.Integer({ minimum: 1, maximum: 500, description: "Max tasks to return (default 25)." })
|
|
270
|
+
),
|
|
271
|
+
vmid: Type5.Optional(
|
|
272
|
+
Type5.Integer({ minimum: 1, description: "Filter tasks by vmid (post-filter)." })
|
|
273
|
+
)
|
|
274
|
+
},
|
|
275
|
+
{ additionalProperties: false }
|
|
276
|
+
);
|
|
277
|
+
function createProxmoxRecentTasksTool(getClient) {
|
|
278
|
+
return {
|
|
279
|
+
name: "proxmox_recent_tasks",
|
|
280
|
+
label: "proxmox: recent tasks",
|
|
281
|
+
description: "List recent cluster tasks (UPID, type, status, node, user, timing) via GET /cluster/tasks. Optionally filter by vmid (post-filter client-side).",
|
|
282
|
+
parameters: Schema5,
|
|
283
|
+
execute: async (_id, raw) => {
|
|
284
|
+
const args = raw;
|
|
285
|
+
const limit = args.limit ?? 25;
|
|
286
|
+
const client = getClient();
|
|
287
|
+
const tasks = await client.get("/cluster/tasks");
|
|
288
|
+
let filtered = tasks;
|
|
289
|
+
if (args.vmid !== void 0) {
|
|
290
|
+
const needle = String(args.vmid);
|
|
291
|
+
filtered = tasks.filter((t) => {
|
|
292
|
+
if (t.id === needle) return true;
|
|
293
|
+
if (typeof t.upid === "string" && t.upid.includes(`:${needle}:`)) return true;
|
|
294
|
+
return false;
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
const trimmed = filtered.slice(0, limit);
|
|
298
|
+
return jsonToolResult({ count: trimmed.length, tasks: trimmed });
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// src/tools/proxmox_list_backups.ts
|
|
304
|
+
import { Type as Type6 } from "@sinclair/typebox";
|
|
305
|
+
var Schema6 = Type6.Object(
|
|
306
|
+
{
|
|
307
|
+
node: Type6.Optional(
|
|
308
|
+
Type6.String({ minLength: 1, description: "Node to query (defaults to first node)." })
|
|
309
|
+
),
|
|
310
|
+
vmid: Type6.Optional(
|
|
311
|
+
Type6.Integer({ minimum: 1, description: "Filter backups to a single vmid (post-filter)." })
|
|
312
|
+
)
|
|
313
|
+
},
|
|
314
|
+
{ additionalProperties: false }
|
|
315
|
+
);
|
|
316
|
+
function createProxmoxListBackupsTool(getClient) {
|
|
317
|
+
return {
|
|
318
|
+
name: "proxmox_list_backups",
|
|
319
|
+
label: "proxmox: list backups",
|
|
320
|
+
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.",
|
|
321
|
+
parameters: Schema6,
|
|
322
|
+
execute: async (_id, raw) => {
|
|
323
|
+
const args = raw;
|
|
324
|
+
const client = getClient();
|
|
325
|
+
let node = args.node;
|
|
326
|
+
if (!node) {
|
|
327
|
+
const nodes = await client.get("/cluster/resources?type=node");
|
|
328
|
+
if (nodes.length === 0) throw new Error("no nodes found in cluster resources");
|
|
329
|
+
node = nodes[0].node;
|
|
330
|
+
}
|
|
331
|
+
const storages = await client.get(`/nodes/${node}/storage?content=backup`);
|
|
332
|
+
const all = [];
|
|
333
|
+
for (const s of storages) {
|
|
334
|
+
const entries = await client.get(
|
|
335
|
+
`/nodes/${node}/storage/${s.storage}/content?content=backup`
|
|
336
|
+
);
|
|
337
|
+
for (const e of entries) all.push({ ...e, storage: s.storage });
|
|
338
|
+
}
|
|
339
|
+
const filtered = args.vmid !== void 0 ? all.filter((b) => b.vmid === args.vmid) : all;
|
|
340
|
+
return jsonToolResult({ node, count: filtered.length, backups: filtered });
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// src/tools/proxmox_resource_usage.ts
|
|
346
|
+
import { Type as Type7 } from "@sinclair/typebox";
|
|
347
|
+
var Schema7 = Type7.Object(
|
|
348
|
+
{
|
|
349
|
+
vmid: Type7.Integer({ minimum: 1, description: "Container or VM ID." }),
|
|
350
|
+
timeframe: Type7.Optional(
|
|
351
|
+
Type7.Union([Type7.Literal("hour"), Type7.Literal("day"), Type7.Literal("week")], {
|
|
352
|
+
description: "RRD timeframe window (default hour)."
|
|
353
|
+
})
|
|
354
|
+
)
|
|
355
|
+
},
|
|
356
|
+
{ additionalProperties: false }
|
|
357
|
+
);
|
|
358
|
+
function createProxmoxResourceUsageTool(getClient) {
|
|
359
|
+
return {
|
|
360
|
+
name: "proxmox_resource_usage",
|
|
361
|
+
label: "proxmox: resource usage",
|
|
362
|
+
description: "Get historical CPU/memory/disk/network samples for one LXC or VM via GET /nodes/{node}/{type}/{vmid}/rrddata?timeframe=<hour|day|week>.",
|
|
363
|
+
parameters: Schema7,
|
|
364
|
+
execute: async (_id, raw) => {
|
|
365
|
+
const args = raw;
|
|
366
|
+
const timeframe = args.timeframe ?? "hour";
|
|
367
|
+
const client = getClient();
|
|
368
|
+
const { node, type } = await resolveResource(client, args.vmid);
|
|
369
|
+
const samples = await client.get(
|
|
370
|
+
`/nodes/${node}/${type}/${args.vmid}/rrddata?timeframe=${timeframe}`
|
|
371
|
+
);
|
|
372
|
+
return jsonToolResult({ vmid: args.vmid, node, type, timeframe, samples });
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// src/tools/proxmox_start_resource.ts
|
|
378
|
+
import { Type as Type8 } from "@sinclair/typebox";
|
|
379
|
+
|
|
380
|
+
// src/gates.ts
|
|
381
|
+
var WriteGateError = class extends Error {
|
|
382
|
+
constructor(message) {
|
|
383
|
+
super(message);
|
|
384
|
+
this.name = "WriteGateError";
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
function assertConfirmedWrite(args, toolName) {
|
|
388
|
+
if (args.confirm !== true) {
|
|
389
|
+
throw new WriteGateError(`${toolName} is a write operation. Pass {"confirm": true} to proceed.`);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// src/tools/proxmox_start_resource.ts
|
|
394
|
+
var Schema8 = Type8.Object(
|
|
395
|
+
{
|
|
396
|
+
vmid: Type8.Integer({ minimum: 1, description: "Container or VM ID." }),
|
|
397
|
+
confirm: Type8.Boolean({
|
|
398
|
+
description: "Must be true to write. Tier-2 safe-write gate."
|
|
399
|
+
})
|
|
400
|
+
},
|
|
401
|
+
{ additionalProperties: false }
|
|
402
|
+
);
|
|
403
|
+
var NAME = "proxmox_start_resource";
|
|
404
|
+
function createProxmoxStartResourceTool(getClient) {
|
|
405
|
+
return {
|
|
406
|
+
name: NAME,
|
|
407
|
+
label: "proxmox: start resource",
|
|
408
|
+
description: "Start a stopped LXC container or QEMU VM by vmid. Tier-2 write; requires confirm:true.",
|
|
409
|
+
parameters: Schema8,
|
|
410
|
+
execute: async (_id, raw) => {
|
|
411
|
+
assertConfirmedWrite(raw, NAME);
|
|
412
|
+
const args = raw;
|
|
413
|
+
const client = getClient();
|
|
414
|
+
const { node, type } = await resolveResource(client, args.vmid);
|
|
415
|
+
const upid = await client.post(
|
|
416
|
+
`/nodes/${node}/${type}/${args.vmid}/status/start`,
|
|
417
|
+
{}
|
|
418
|
+
);
|
|
419
|
+
return jsonToolResult({ vmid: args.vmid, node, type, upid });
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/tools/proxmox_stop_resource.ts
|
|
425
|
+
import { Type as Type9 } from "@sinclair/typebox";
|
|
426
|
+
var Schema9 = Type9.Object(
|
|
427
|
+
{
|
|
428
|
+
vmid: Type9.Integer({ minimum: 1, description: "Container or VM ID." }),
|
|
429
|
+
confirm: Type9.Boolean({
|
|
430
|
+
description: "Must be true to write. Tier-2 safe-write gate."
|
|
431
|
+
}),
|
|
432
|
+
timeoutSeconds: Type9.Optional(
|
|
433
|
+
Type9.Integer({
|
|
434
|
+
minimum: 1,
|
|
435
|
+
description: "Optional shutdown timeout in seconds (passed through to PVE as `timeout`)."
|
|
436
|
+
})
|
|
437
|
+
)
|
|
438
|
+
},
|
|
439
|
+
{ additionalProperties: false }
|
|
440
|
+
);
|
|
441
|
+
var NAME2 = "proxmox_stop_resource";
|
|
442
|
+
function createProxmoxStopResourceTool(getClient) {
|
|
443
|
+
return {
|
|
444
|
+
name: NAME2,
|
|
445
|
+
label: "proxmox: stop resource",
|
|
446
|
+
description: "Gracefully shutdown an LXC container or QEMU VM by vmid (POST status/shutdown). Tier-2 write; requires confirm:true.",
|
|
447
|
+
parameters: Schema9,
|
|
448
|
+
execute: async (_id, raw) => {
|
|
449
|
+
assertConfirmedWrite(raw, NAME2);
|
|
450
|
+
const args = raw;
|
|
451
|
+
const client = getClient();
|
|
452
|
+
const { node, type } = await resolveResource(client, args.vmid);
|
|
453
|
+
const body = {};
|
|
454
|
+
if (typeof args.timeoutSeconds === "number") {
|
|
455
|
+
body.timeout = args.timeoutSeconds;
|
|
456
|
+
}
|
|
457
|
+
const upid = await client.post(
|
|
458
|
+
`/nodes/${node}/${type}/${args.vmid}/status/shutdown`,
|
|
459
|
+
body
|
|
460
|
+
);
|
|
461
|
+
return jsonToolResult({ vmid: args.vmid, node, type, upid });
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// src/tools/proxmox_reboot_resource.ts
|
|
467
|
+
import { Type as Type10 } from "@sinclair/typebox";
|
|
468
|
+
var Schema10 = Type10.Object(
|
|
469
|
+
{
|
|
470
|
+
vmid: Type10.Integer({ minimum: 1, description: "Container or VM ID." }),
|
|
471
|
+
confirm: Type10.Boolean({
|
|
472
|
+
description: "Must be true to write. Tier-2 safe-write gate."
|
|
473
|
+
})
|
|
474
|
+
},
|
|
475
|
+
{ additionalProperties: false }
|
|
476
|
+
);
|
|
477
|
+
var NAME3 = "proxmox_reboot_resource";
|
|
478
|
+
function createProxmoxRebootResourceTool(getClient) {
|
|
479
|
+
return {
|
|
480
|
+
name: NAME3,
|
|
481
|
+
label: "proxmox: reboot resource",
|
|
482
|
+
description: "Reboot an LXC container or QEMU VM by vmid (POST status/reboot). Tier-2 write; requires confirm:true.",
|
|
483
|
+
parameters: Schema10,
|
|
484
|
+
execute: async (_id, raw) => {
|
|
485
|
+
assertConfirmedWrite(raw, NAME3);
|
|
486
|
+
const args = raw;
|
|
487
|
+
const client = getClient();
|
|
488
|
+
const { node, type } = await resolveResource(client, args.vmid);
|
|
489
|
+
const upid = await client.post(
|
|
490
|
+
`/nodes/${node}/${type}/${args.vmid}/status/reboot`,
|
|
491
|
+
{}
|
|
492
|
+
);
|
|
493
|
+
return jsonToolResult({ vmid: args.vmid, node, type, upid });
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// src/tools/proxmox_snapshot_resource.ts
|
|
499
|
+
import { Type as Type11 } from "@sinclair/typebox";
|
|
500
|
+
var Schema11 = Type11.Object(
|
|
501
|
+
{
|
|
502
|
+
vmid: Type11.Integer({ minimum: 1, description: "Container or VM ID." }),
|
|
503
|
+
snapname: Type11.String({
|
|
504
|
+
minLength: 1,
|
|
505
|
+
description: "Snapshot name (PVE convention: lowercase, no spaces)."
|
|
506
|
+
}),
|
|
507
|
+
description: Type11.Optional(
|
|
508
|
+
Type11.String({ description: "Optional human description for the snapshot." })
|
|
509
|
+
),
|
|
510
|
+
confirm: Type11.Boolean({
|
|
511
|
+
description: "Must be true to write. Tier-2 safe-write gate."
|
|
512
|
+
})
|
|
513
|
+
},
|
|
514
|
+
{ additionalProperties: false }
|
|
515
|
+
);
|
|
516
|
+
var NAME4 = "proxmox_snapshot_resource";
|
|
517
|
+
function createProxmoxSnapshotResourceTool(getClient) {
|
|
518
|
+
return {
|
|
519
|
+
name: NAME4,
|
|
520
|
+
label: "proxmox: snapshot resource",
|
|
521
|
+
description: "Create a snapshot of an LXC container or QEMU VM by vmid (POST /snapshot with {snapname, description?}). Tier-2 write; requires confirm:true.",
|
|
522
|
+
parameters: Schema11,
|
|
523
|
+
execute: async (_id, raw) => {
|
|
524
|
+
assertConfirmedWrite(raw, NAME4);
|
|
525
|
+
const args = raw;
|
|
526
|
+
const client = getClient();
|
|
527
|
+
const { node, type } = await resolveResource(client, args.vmid);
|
|
528
|
+
const body = { snapname: args.snapname };
|
|
529
|
+
if (typeof args.description === "string" && args.description.length > 0) {
|
|
530
|
+
body.description = args.description;
|
|
531
|
+
}
|
|
532
|
+
const upid = await client.post(
|
|
533
|
+
`/nodes/${node}/${type}/${args.vmid}/snapshot`,
|
|
534
|
+
body
|
|
535
|
+
);
|
|
536
|
+
return jsonToolResult({
|
|
537
|
+
vmid: args.vmid,
|
|
538
|
+
node,
|
|
539
|
+
type,
|
|
540
|
+
snapname: args.snapname,
|
|
541
|
+
upid
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// src/tools/proxmox_run_backup.ts
|
|
548
|
+
import { Type as Type12 } from "@sinclair/typebox";
|
|
549
|
+
var Schema12 = Type12.Object(
|
|
550
|
+
{
|
|
551
|
+
vmid: Type12.Integer({ minimum: 1, description: "Container or VM ID to back up." }),
|
|
552
|
+
storage: Type12.String({
|
|
553
|
+
minLength: 1,
|
|
554
|
+
description: "PVE storage ID where the vzdump archive should be written."
|
|
555
|
+
}),
|
|
556
|
+
mode: Type12.Optional(
|
|
557
|
+
Type12.Union(
|
|
558
|
+
[Type12.Literal("snapshot"), Type12.Literal("suspend"), Type12.Literal("stop")],
|
|
559
|
+
{ description: "Backup mode. Defaults to 'snapshot'." }
|
|
560
|
+
)
|
|
561
|
+
),
|
|
562
|
+
confirm: Type12.Boolean({
|
|
563
|
+
description: "Must be true to write. Tier-2 safe-write gate."
|
|
564
|
+
})
|
|
565
|
+
},
|
|
566
|
+
{ additionalProperties: false }
|
|
567
|
+
);
|
|
568
|
+
var NAME5 = "proxmox_run_backup";
|
|
569
|
+
function createProxmoxRunBackupTool(getClient) {
|
|
570
|
+
return {
|
|
571
|
+
name: NAME5,
|
|
572
|
+
label: "proxmox: run backup",
|
|
573
|
+
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.",
|
|
574
|
+
parameters: Schema12,
|
|
575
|
+
execute: async (_id, raw) => {
|
|
576
|
+
assertConfirmedWrite(raw, NAME5);
|
|
577
|
+
const args = raw;
|
|
578
|
+
const mode = args.mode ?? "snapshot";
|
|
579
|
+
const client = getClient();
|
|
580
|
+
const { node } = await resolveResource(client, args.vmid);
|
|
581
|
+
const upid = await client.post(`/nodes/${node}/vzdump`, {
|
|
582
|
+
vmid: args.vmid,
|
|
583
|
+
storage: args.storage,
|
|
584
|
+
mode,
|
|
585
|
+
compress: "zstd"
|
|
586
|
+
});
|
|
587
|
+
return jsonToolResult({
|
|
588
|
+
vmid: args.vmid,
|
|
589
|
+
node,
|
|
590
|
+
storage: args.storage,
|
|
591
|
+
mode,
|
|
592
|
+
upid
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// index.ts
|
|
599
|
+
function withRedactedErrors(tool) {
|
|
600
|
+
const orig = tool.execute.bind(tool);
|
|
601
|
+
return {
|
|
602
|
+
...tool,
|
|
603
|
+
execute: async (id, args) => {
|
|
604
|
+
try {
|
|
605
|
+
return await orig(id, args);
|
|
606
|
+
} catch (e) {
|
|
607
|
+
const msg = redact(e.message);
|
|
608
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: msg }) }], isError: true };
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
function makeFactory(cfg) {
|
|
614
|
+
registerSecret(cfg.tokenId);
|
|
615
|
+
registerSecret(cfg.tokenSecret);
|
|
616
|
+
registerSecret(`PVEAPIToken=${cfg.tokenId}=${cfg.tokenSecret}`);
|
|
617
|
+
return () => new ProxmoxClient(cfg);
|
|
618
|
+
}
|
|
619
|
+
var index_default = definePluginEntry({
|
|
620
|
+
id: "proxmox",
|
|
621
|
+
name: "Proxmox",
|
|
622
|
+
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.",
|
|
623
|
+
register(api) {
|
|
624
|
+
if (api.registrationMode !== "full") return;
|
|
625
|
+
const cfg = resolveConfig(process.env);
|
|
626
|
+
const getClient = makeFactory(cfg);
|
|
627
|
+
const register = (t) => api.registerTool(withRedactedErrors(t));
|
|
628
|
+
register(createProxmoxStatusTool(getClient));
|
|
629
|
+
register(createProxmoxListContainersTool(getClient));
|
|
630
|
+
register(createProxmoxListVmsTool(getClient));
|
|
631
|
+
register(createProxmoxGetResourceTool(getClient));
|
|
632
|
+
register(createProxmoxRecentTasksTool(getClient));
|
|
633
|
+
register(createProxmoxListBackupsTool(getClient));
|
|
634
|
+
register(createProxmoxResourceUsageTool(getClient));
|
|
635
|
+
register(createProxmoxStartResourceTool(getClient));
|
|
636
|
+
register(createProxmoxStopResourceTool(getClient));
|
|
637
|
+
register(createProxmoxRebootResourceTool(getClient));
|
|
638
|
+
register(createProxmoxSnapshotResourceTool(getClient));
|
|
639
|
+
register(createProxmoxRunBackupTool(getClient));
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
export {
|
|
643
|
+
index_default as default,
|
|
644
|
+
withRedactedErrors
|
|
645
|
+
};
|