cloudgpu-mcp 0.9.0 → 0.10.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 +12 -0
- package/package.json +1 -1
- package/src/index.js +4 -1
- package/src/task-templates.js +109 -0
package/README.md
CHANGED
|
@@ -305,3 +305,15 @@ After completion, inspect `get_job.output_collection`: only `succeeded` confirms
|
|
|
305
305
|
### Job log snapshot safety
|
|
306
306
|
|
|
307
307
|
Version 0.8.0 still has a credential-filter gap in `save_job_output`; upgrading to 0.8.0 did not fix it. The 0.9.0 candidate rejects quoted JSON credential keys, common prefixed/aliased secret fields, authorization schemes, queried/user-info URLs and bounded common escaped representations before any storage operation. Safe logs remain byte-identical. This is a conservative recognizable-pattern check, not a guarantee that arbitrary, encrypted or unknown credentials will be detected. Save only logs you know are sanitized, with explicit user approval; no actual exposure is established by this fix.
|
|
308
|
+
|
|
309
|
+
## Reusable task drafts (D16 first slice)
|
|
310
|
+
|
|
311
|
+
`list_task_templates` and `prepare_task_template` are local, read-only tools: no account is required, no API call is made, and preparing a draft never rents a GPU. Start with `gpu-check`, `csv-summary`, or `workspace-python`. CSV work normally belongs on your local CPU; do not rent a GPU merely to process a small CSV.
|
|
312
|
+
|
|
313
|
+
```json
|
|
314
|
+
{"template_id":"gpu-check","persist_results":false}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
For an existing project, pass `workspace-python`, an immutable `workspace_version_id`, and a reviewed relative `.py` entrypoint. The script runs in the restored project; prepare its dependencies yourself. Inference/training compatibility is not certified. For ComfyUI model/workflow preparation, keep using `prepare_model_deployment`; complete ComfyUI and LoRA batch recipes are not included in this slice.
|
|
318
|
+
|
|
319
|
+
The returned `run_job_draft` deliberately omits GPU selection, quote, budget, time limit, approval and idempotency key. Request a live quote, obtain explicit approval, then call existing `run_job`. Failed tasks are not automatically retried. To preserve results, explicitly request `persist_results`; normal storage eligibility, retention, quota and fees apply. `workspace-python` also requires the exact `output_files` your script writes under `$CLOUDGPU_OUTPUT_DIR`. Storage-fee consent defaults to false and is separate from GPU approval.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudgpu-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.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/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {registerTaskTemplateTools} from './task-templates.js';
|
|
2
3
|
import {resolveModelReference} from "./model-references.js";
|
|
3
4
|
// CloudGPU MCP server (stdio). Lets an AI coding assistant rent a GPU on cloudgpu.app, run a job,
|
|
4
5
|
// fetch the results and shut the GPU down.
|
|
@@ -32,7 +33,7 @@ import {
|
|
|
32
33
|
shq,
|
|
33
34
|
} from "./guards.js";
|
|
34
35
|
|
|
35
|
-
const VERSION = "0.
|
|
36
|
+
const VERSION = "0.10.0";
|
|
36
37
|
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
37
38
|
const RULES = fs.readFileSync(path.join(HERE, "..", "rules", "cloudgpu.md"), "utf8");
|
|
38
39
|
|
|
@@ -58,6 +59,7 @@ const quotes = new Quotes();
|
|
|
58
59
|
const session = new Map();
|
|
59
60
|
|
|
60
61
|
const INSTRUCTIONS = `CloudGPU (cloudgpu.app) rents GPUs billed per minute from a prepaid balance.
|
|
62
|
+
Task recipes: list_task_templates and prepare_task_template return local read-only drafts, never a paid submission. Check prerequisites, quote and obtain explicit approval before run_job. Prefer local CPU processing when a GPU is unnecessary.
|
|
61
63
|
Workflow: get_account and list_gpus -> estimate_cost -> show the quote to the user and get an explicit yes -> create_instance -> get_status until running -> upload -> run_command (background for long jobs) -> tail_logs -> download results -> stop_instance -> report the actual cost.
|
|
62
64
|
Rules: never rent without the user's yes on a quote; always set a budget and time limit (the platform shuts the instance down when either is hit); download results before stop_instance because destroying an instance erases its disk; never change passwords, SSH config, the firewall or the platform's monitoring agent on the instance; if anything fails, download what exists and stop the instance rather than leaving it running.
|
|
63
65
|
Jobs: for a batch task (one command that writes its results somewhere), run_job does the whole thing on CloudGPU's servers: start a GPU, run the command, destroy the GPU, with the same per-job budget and time limit. Check it with get_job. The GPU disk is erased on release. When automatic_output_collection is enabled, declare explicit outputs and write them under $CLOUDGPU_OUTPUT_DIR; inspect output_collection and download ready file IDs afterward. Otherwise upload results yourself or print them; get_job returns the last ~4 KB of logs. Saving output shares the same GPU budget and existing storage quota/fees; never infer storage-fee acceptance.
|
|
@@ -65,6 +67,7 @@ No API key yet? connect_account gives the user a link to approve this assistant
|
|
|
65
67
|
The same API key also works for the OpenAI-compatible model API at ${cfg.baseUrl}/v1 (see list_models).`;
|
|
66
68
|
|
|
67
69
|
const server = new McpServer({ name: "cloudgpu", version: VERSION }, { instructions: INSTRUCTIONS });
|
|
70
|
+
registerTaskTemplateTools(server, {wrap, ok});
|
|
68
71
|
registerStorageTools(server, { api, wrap, ok, fail, readOnly: cfg.readOnly, expandHome });
|
|
69
72
|
registerJobResultTools(server, { api, wrap, ok, readOnly: cfg.readOnly });
|
|
70
73
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// 只读任务准备:不访问 API、不租 GPU、不安装依赖,也不推断预算或存储同意。
|
|
2
|
+
import {createHash} from 'node:crypto';
|
|
3
|
+
import {z} from 'zod';
|
|
4
|
+
|
|
5
|
+
const TASKS = [
|
|
6
|
+
{id:'gpu-check',version:1,title:'Check the allocated GPU',requires_workspace:false,requirements:['Python 3','nvidia-smi'],result_files:['gpu-check.json'],description:'Report visible GPU names and total memory. No model download or benchmark.'},
|
|
7
|
+
{id:'csv-summary',version:1,title:'Summarize a Workspace CSV',requires_workspace:true,requirements:['Python 3','Immutable Workspace version','UTF-8 CSV, at most 32 MiB'],result_files:['csv-summary.json'],description:'Count rows, columns and inconsistent row widths without logging cell values. Usually a CPU task; prefer local execution when a GPU is unnecessary.'},
|
|
8
|
+
{id:'workspace-python',version:1,title:'Run a reviewed Workspace Python script',requires_workspace:true,requirements:['Python 3','Immutable Workspace version','User-reviewed Python entrypoint and dependencies already prepared'],result_files:[],description:'Reuse your own inference or training script. Does not install packages, supply a model, or certify application compatibility.'},
|
|
9
|
+
];
|
|
10
|
+
const id=z.enum(TASKS.map(t=>t.id));
|
|
11
|
+
const relative=z.string().min(1).max(240).regex(/^[A-Za-z0-9_][A-Za-z0-9_./-]*$/).refine(p=>p.split('/').every(s=>s && s!=='.' && s!=='..' && !s.startsWith('.')),'Use a relative path without traversal or hidden components');
|
|
12
|
+
const schema=z.object({
|
|
13
|
+
template_id:id,
|
|
14
|
+
workspace_version_id:z.string().regex(/^wsv_[0-9a-f]{32}$/).optional(),
|
|
15
|
+
input_path:relative.optional(),
|
|
16
|
+
entrypoint:relative.refine(p=>p.endsWith('.py'),'Entrypoint must be a Python file').optional(),
|
|
17
|
+
persist_results:z.boolean().default(false),
|
|
18
|
+
output_files:z.array(relative).min(1).max(16).optional(),
|
|
19
|
+
accept_storage_charges:z.boolean().default(false),
|
|
20
|
+
}).strict();
|
|
21
|
+
const programs={
|
|
22
|
+
'gpu-check':`import json,subprocess
|
|
23
|
+
r=subprocess.run(['nvidia-smi','--query-gpu=name,memory.total','--format=csv,noheader,nounits'],capture_output=True,text=True,timeout=15)
|
|
24
|
+
if r.returncode: raise RuntimeError('GPU query failed; no automatic retry')
|
|
25
|
+
gpus=[]
|
|
26
|
+
for line in r.stdout.splitlines():
|
|
27
|
+
name,memory=line.rsplit(',',1)
|
|
28
|
+
gpus.append({'name':name.strip(),'memory_mib':int(memory.strip())})
|
|
29
|
+
if not gpus: raise RuntimeError('No visible GPU; no automatic retry')
|
|
30
|
+
result={'gpus':gpus}
|
|
31
|
+
`,
|
|
32
|
+
'csv-summary':`import csv,json,os,pathlib,stat
|
|
33
|
+
root=pathlib.Path.cwd().resolve()
|
|
34
|
+
p=root.joinpath(options['input_path'])
|
|
35
|
+
for component in p.relative_to(root).parts:
|
|
36
|
+
root=root/component
|
|
37
|
+
if root.is_symlink(): raise ValueError('Input must not use symlinks')
|
|
38
|
+
flags=os.O_RDONLY|getattr(os,'O_NOFOLLOW',0)|os.O_NONBLOCK
|
|
39
|
+
fd=os.open(str(p),flags)
|
|
40
|
+
meta=os.fstat(fd)
|
|
41
|
+
if not stat.S_ISREG(meta.st_mode) or meta.st_size>33554432:
|
|
42
|
+
os.close(fd)
|
|
43
|
+
raise ValueError('Input must be a regular CSV of at most 32 MiB')
|
|
44
|
+
csv.field_size_limit(1048576)
|
|
45
|
+
with os.fdopen(fd,'r',encoding='utf-8',newline='') as f:
|
|
46
|
+
reader=csv.reader(f)
|
|
47
|
+
header=next(reader,None)
|
|
48
|
+
columns=len(header) if header is not None else 0
|
|
49
|
+
rows=0
|
|
50
|
+
inconsistent=0
|
|
51
|
+
for row in reader:
|
|
52
|
+
rows+=1
|
|
53
|
+
inconsistent+=int(len(row)!=columns)
|
|
54
|
+
if rows>1000000: raise ValueError('CSV row limit exceeded')
|
|
55
|
+
result={'rows':rows,'columns':columns,'inconsistent_rows':inconsistent,'input_bytes':meta.st_size,'header_assumed':True}
|
|
56
|
+
`,
|
|
57
|
+
'workspace-python':`import os,pathlib,stat,sys
|
|
58
|
+
root=pathlib.Path.cwd().resolve()
|
|
59
|
+
p=root.joinpath(options['entrypoint'])
|
|
60
|
+
check=root
|
|
61
|
+
for component in p.relative_to(root).parts:
|
|
62
|
+
check=check/component
|
|
63
|
+
if check.is_symlink(): raise ValueError('Entrypoint must not use symlinks')
|
|
64
|
+
if not stat.S_ISREG(p.stat().st_mode): raise ValueError('Entrypoint must be a regular file')
|
|
65
|
+
os.execv(sys.executable,[sys.executable,str(p)])
|
|
66
|
+
`,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export function listTaskTemplates(){
|
|
70
|
+
return {preparation_only:true,starts_gpu:false,templates:structuredClone(TASKS),
|
|
71
|
+
note:'Preparation costs no GPU time. Running a Job costs money and requires a fresh quote, explicit GPU/budget/time approval and a new idempotency key. No automatic retry or dependency installation. ComfyUI workflow preparation remains available through prepare_model_deployment; these are not prevalidated ComfyUI or LoRA end-to-end recipes.'};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function prepareTaskTemplate(raw){
|
|
75
|
+
const p=schema.parse(raw),t=TASKS.find(t=>t.id===p.template_id);
|
|
76
|
+
if(t.requires_workspace && !p.workspace_version_id)throw Error('Select an immutable Workspace version before preparing this task');
|
|
77
|
+
if(!t.requires_workspace && p.workspace_version_id)throw Error('gpu-check does not use a Workspace');
|
|
78
|
+
if(p.template_id==='csv-summary' ? !p.input_path : p.input_path!==undefined)throw Error('input_path is required only for csv-summary');
|
|
79
|
+
if(p.template_id==='workspace-python' ? !p.entrypoint : p.entrypoint!==undefined)throw Error('entrypoint is required only for workspace-python');
|
|
80
|
+
if(p.accept_storage_charges && !p.persist_results)throw Error('Storage consent is only relevant when persisting results');
|
|
81
|
+
if(p.output_files && (!p.persist_results || p.template_id!=='workspace-python'))throw Error('Explicit output_files are only for persistent workspace-python results');
|
|
82
|
+
if(p.persist_results && p.template_id==='workspace-python' && !p.output_files)throw Error('List the exact result files your reviewed script writes under CLOUDGPU_OUTPUT_DIR');
|
|
83
|
+
if(p.output_files && new Set(p.output_files).size!==p.output_files.length)throw Error('Result paths must be distinct');
|
|
84
|
+
const options={...(p.input_path?{input_path:p.input_path}:{}),...(p.entrypoint?{entrypoint:p.entrypoint}:{})};
|
|
85
|
+
let program='import json\noptions=json.loads('+JSON.stringify(JSON.stringify(options))+')\n'+programs[p.template_id];
|
|
86
|
+
if(p.template_id!=='workspace-python'){
|
|
87
|
+
program+=`import os,pathlib\nencoded=json.dumps(result,sort_keys=True)\n`;
|
|
88
|
+
if(p.persist_results)program+=`dest=pathlib.Path(os.environ['CLOUDGPU_OUTPUT_DIR'])/${JSON.stringify(t.result_files[0])}\nwith dest.open('x',encoding='utf-8') as f: f.write(encoded+'\\n')\n`;
|
|
89
|
+
program+="print(encoded)\n";
|
|
90
|
+
}
|
|
91
|
+
const command="set -eu\numask 077\npython3 - <<'CGPU_TASK_TEMPLATE'\n"+program+"CGPU_TASK_TEMPLATE\n";
|
|
92
|
+
const draft={command,...(p.workspace_version_id?{workspace_version_id:p.workspace_version_id}:{})};
|
|
93
|
+
if(p.persist_results)draft.outputs={files:p.output_files||t.result_files,max_bytes:10485760,accept_storage_charges:p.accept_storage_charges};
|
|
94
|
+
return {preparation_only:true,starts_gpu:false,template_id:t.id,template_version:t.version,
|
|
95
|
+
command_sha256:createHash('sha256').update(command).digest('hex'),run_job_draft:draft,
|
|
96
|
+
requirements:t.requirements,missing_fields:['gpu_model or quote_id','max_spend_usd','max_hours','user_confirmed','idempotency_key'],
|
|
97
|
+
next_steps:['Review the task, Workspace expiry and required dependencies; prefer local CPU execution for CSV-only work.',
|
|
98
|
+
'Check live compute capabilities and request a fresh quote for a compatible GPU. Do not assume image compatibility from this draft.',
|
|
99
|
+
'Ask the user to approve GPU, spending cap and time limit. Separately obtain paid-storage consent if needed; scoped keys may not enable paid storage.',
|
|
100
|
+
'Call run_job only after approval with a new idempotency key; retain that key for transport retries of the SAME submission.',
|
|
101
|
+
'Poll get_job until terminal, inspect output_collection if requested and verify GPU release. Do not automatically retry failed tasks.'],
|
|
102
|
+
storage_note:p.persist_results?'Existing storage eligibility, quota, retention and charges apply; transfer uses the same GPU time budget. Explicit result paths are not a content-safety guarantee.':'No persistent storage requested; only the ended Job log tail remains available. GPU disk is erased at release.'};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function registerTaskTemplateTools(server,{wrap,ok}){
|
|
106
|
+
const annotations={readOnlyHint:true,destructiveHint:false,idempotentHint:true,openWorldHint:false};
|
|
107
|
+
server.registerTool('list_task_templates',{title:'List reusable Job task drafts',description:'Public, local and read-only. Inspect small task recipes and requirements before quoting. Does not call an API, rent a GPU, install dependencies or reserve capacity.',inputSchema:{},annotations},wrap(async()=>ok(listTaskTemplates())));
|
|
108
|
+
server.registerTool('prepare_task_template',{title:'Prepare a Job task draft',description:'Local preparation only. Returns a command and optional Workspace/output fields; never submits or spends money. Quote, explicit GPU/budget/time approval and existing storage consent are still required by run_job. No guaranteed application compatibility or automatic retry.',inputSchema:schema.shape,annotations},wrap(async input=>ok(prepareTaskTemplate(input))));
|
|
109
|
+
}
|