cloudgpu-mcp 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -182,7 +182,7 @@ cloudgpu down <id> # destroys it and stops billing (asks first; --
182
182
  | `login` | Save an API key (input hidden, or piped on stdin); checked against the API first |
183
183
  | `offers [--template ID]` | GPU models, VRAM, live price per GPU-hour, availability |
184
184
  | `templates` | Ready-made images and the GPU each recommends |
185
- | `up --gpu MODEL [--template ID] [--count N] [--max-minutes N] [--max-spend USD] [--idle-minutes N] [--wait]` | Rent an instance; `--wait` polls until it is running or failed, then prints the SSH command and URL |
185
+ | `up --gpu MODEL [--template ID] [--count N] [--max-minutes N] [--max-spend USD] [--idle-minutes N] [--setup FILE] [--wait]` | Rent an instance; `--setup` runs a bash script once as root after hand-over (log in `/root/cloudgpu-setup.log`); `--wait` polls until it is running or failed, then prints the SSH command and URL |
186
186
  | `ls` / `status <id>` | Instances with status, minutes run and cost so far |
187
187
  | `ssh <id> [-- ARGS]` | Run `ssh` with the instance's host, port and user; `--show-password` prints the password if there is one |
188
188
  | `down <id> [--yes]` | Destroy the instance; its disk is erased, so download results first |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudgpu-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "mcpName": "io.github.mrhy7176/cloudgpu-mcp",
5
5
  "description": "MCP server and command-line tool for cloudgpu.app: let Claude Code, Cursor, Cline, opencode, goose and other MCP clients (or you, from a terminal) rent a GPU per minute, run a job, fetch the results and shut it down, with spending limits the platform enforces.",
6
6
  "type": "module",
package/src/cli-core.js CHANGED
@@ -66,7 +66,7 @@ const COMMANDS = {
66
66
  up: {
67
67
  summary: "Rent a GPU instance",
68
68
  usage:
69
- 'cloudgpu up --gpu "RTX 4090" [--template <id>] [--count N] [--max-minutes N] [--max-spend USD] [--idle-minutes N] [--wait] [--json]',
69
+ 'cloudgpu up --gpu "RTX 4090" [--template <id>] [--count N] [--max-minutes N] [--max-spend USD] [--idle-minutes N] [--setup FILE] [--wait] [--json]',
70
70
  details: [
71
71
  "--gpu <model> GPU model as `cloudgpu offers` lists it (required)",
72
72
  "--template <id> template id from `cloudgpu templates`; omit for a plain GPU with Python and CUDA",
@@ -74,6 +74,8 @@ const COMMANDS = {
74
74
  "--max-minutes N destroy the instance N minutes after it starts (enforced by the server)",
75
75
  "--max-spend USD destroy the instance before it costs more than this (enforced by the server)",
76
76
  "--idle-minutes N destroy after the GPU is idle this long; 0 = off, otherwise 10-1440",
77
+ "--setup FILE bash script run once as root after the instance is handed over (up to 16 KB);",
78
+ " output in /root/cloudgpu-setup.log on the instance",
77
79
  "--wait poll until the instance is running or failed, then print SSH and URLs",
78
80
  "--show-password with --wait, also print the SSH password if the API returns one",
79
81
  "Costs money: billing is per minute from your prepaid balance until the instance is destroyed.",
@@ -87,6 +89,7 @@ const COMMANDS = {
87
89
  "max-minutes": { type: "string" },
88
90
  "max-spend": { type: "string" },
89
91
  "idle-minutes": { type: "string" },
92
+ setup: { type: "string" },
90
93
  wait: { type: "boolean" },
91
94
  },
92
95
  args: [],
@@ -209,6 +212,8 @@ function intOpt(values, name, min, max) {
209
212
  return Number(v);
210
213
  }
211
214
 
215
+ export const SETUP_MAX_CHARS = 16384;
216
+
212
217
  /** 把 up 的选项变成 POST /v1/gpu/instances 的请求体(gpu_model 稍后用 offers 校正大小写)。 */
213
218
  export function buildCreateBody(values) {
214
219
  if (!values.gpu || !values.gpu.trim()) throw new UsageError('--gpu is required, e.g. --gpu "RTX 4090" (see `cloudgpu offers`)', "up");
@@ -228,6 +233,19 @@ export function buildCreateBody(values) {
228
233
  if (idle > 0 && idle < 10) throw new UsageError("--idle-minutes must be 0 (off) or from 10 to 1440", "up");
229
234
  body.idle_minutes = idle;
230
235
  }
236
+ if (values.setup !== undefined) {
237
+ // 启动脚本从文件读,服务器上限 16 KB(按字符算),这里先挡一道
238
+ let script;
239
+ try {
240
+ script = fs.readFileSync(values.setup, "utf8");
241
+ } catch (e) {
242
+ throw new UsageError(`--setup: cannot read ${values.setup} (${e.code || e.message})`, "up");
243
+ }
244
+ script = script.replace(/\r\n/g, "\n").trim();
245
+ if (!script) throw new UsageError(`--setup: ${values.setup} is empty`, "up");
246
+ if (script.length > SETUP_MAX_CHARS) throw new UsageError(`--setup: script is ${script.length} characters; the limit is ${SETUP_MAX_CHARS}`, "up");
247
+ body.setup_script = script;
248
+ }
231
249
  return body;
232
250
  }
233
251
 
package/src/index.js CHANGED
@@ -27,7 +27,7 @@ import {
27
27
  shq,
28
28
  } from "./guards.js";
29
29
 
30
- const VERSION = "0.2.0";
30
+ const VERSION = "0.3.0";
31
31
  const HERE = path.dirname(fileURLToPath(import.meta.url));
32
32
  const RULES = fs.readFileSync(path.join(HERE, "..", "rules", "cloudgpu.md"), "utf8");
33
33
 
@@ -283,7 +283,8 @@ if (!cfg.readOnly) {
283
283
  description:
284
284
  "Rents the GPU from a quote. Costs money. Requires a quote_id from estimate_cost that the user has approved. " +
285
285
  "max_spend_usd and max_hours are enforced by CloudGPU's servers: the instance is destroyed when either is reached, even if this assistant has disconnected. " +
286
- "idle_minutes destroys it after the GPU sits idle that long (installing packages and downloading data count as idle, so allow for setup).",
286
+ "idle_minutes destroys it after the GPU sits idle that long (installing packages and downloading data count as idle, so allow for setup). " +
287
+ "setup_script (optional bash) runs once as root after the instance is handed over; its output is in /root/cloudgpu-setup.log.",
287
288
  inputSchema: {
288
289
  quote_id: z.string(),
289
290
  user_confirmed: z.boolean().describe("true only if the user explicitly approved this quote in the conversation"),
@@ -296,10 +297,15 @@ if (!cfg.readOnly) {
296
297
  .max(1440)
297
298
  .default(60)
298
299
  .describe("Destroy after the GPU has been idle this long; 0 turns it off; otherwise at least 10"),
300
+ setup_script: z
301
+ .string()
302
+ .max(16384)
303
+ .optional()
304
+ .describe("Optional bash script run once as root in the background after the instance is handed over; output in /root/cloudgpu-setup.log"),
299
305
  },
300
306
  annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true },
301
307
  },
302
- wrap(async ({ quote_id, user_confirmed, max_spend_usd, max_hours, idle_minutes = 60 }) => {
308
+ wrap(async ({ quote_id, user_confirmed, max_spend_usd, max_hours, idle_minutes = 60, setup_script }) => {
303
309
  if (user_confirmed !== true) {
304
310
  return fail("Not rented: show the quote to the user and wait for an explicit yes, then call again with user_confirmed=true.");
305
311
  }
@@ -330,6 +336,7 @@ if (!cfg.readOnly) {
330
336
  idle_minutes,
331
337
  };
332
338
  if (quote.template) body.template = quote.template;
339
+ if (setup_script && setup_script.trim()) body.setup_script = setup_script;
333
340
  const inst = await api.create(body);
334
341
  track(inst.id);
335
342
  return ok({