From 030a4f013d94a6bc57a0323db5cacc5b3105c19c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 26 Oct 2026 20:27:08 +0000 Subject: [PATCH 1/4] LICENSE: copyright holder is CloudGPU.app Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0186WCw6KmBtLrDY6Pb4HLxY --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index c175984..b321e3c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2026 Shanxi Qingsuan Technology Co., Ltd. +Copyright (c) 2026 CloudGPU.app Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 75c1f1b5924dc02adfd799f25ddd217a049e563c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 26 Oct 2026 20:44:28 +0000 Subject: [PATCH 2/4] Add mcp-server: MCP server that lets AI coding assistants rent a GPU, run a job, fetch results and shut it down Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0186WCw6KmBtLrDY6Pb4HLxY --- README.md | 10 + mcp-server/.gitignore | 3 + mcp-server/LICENSE | 21 + mcp-server/README.md | 132 ++++ mcp-server/package-lock.json | 1299 ++++++++++++++++++++++++++++++++ mcp-server/package.json | 48 ++ mcp-server/rules/cloudgpu.md | 43 ++ mcp-server/src/api.js | 99 +++ mcp-server/src/guards.js | 118 +++ mcp-server/src/index.js | 557 ++++++++++++++ mcp-server/src/ssh.js | 233 ++++++ mcp-server/test/guards.test.js | 36 + 12 files changed, 2599 insertions(+) create mode 100644 mcp-server/.gitignore create mode 100644 mcp-server/LICENSE create mode 100644 mcp-server/README.md create mode 100644 mcp-server/package-lock.json create mode 100644 mcp-server/package.json create mode 100644 mcp-server/rules/cloudgpu.md create mode 100644 mcp-server/src/api.js create mode 100644 mcp-server/src/guards.js create mode 100644 mcp-server/src/index.js create mode 100644 mcp-server/src/ssh.js create mode 100644 mcp-server/test/guards.test.js diff --git a/README.md b/README.md index 7fd3c11..739fda1 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,16 @@ Code examples for [cloudgpu.app](https://cloudgpu.app/?utm_source=github): GPU r Everything here runs against the public endpoint `https://cloudgpu.app/v1`. It is OpenAI-compatible, so the official OpenAI SDKs work unchanged: set `base_url` and use a CloudGPU API key. +## Let your AI coding assistant rent the GPU + +[`mcp-server/`](mcp-server/README.md) is an MCP server for Cursor, Cline, opencode, Claude Code, VS Code and other MCP clients. Ask the assistant to fine-tune or run something on a GPU, and it quotes the price, rents a GPU once you agree, runs the job, downloads the results and shuts the GPU down. CloudGPU's servers enforce a budget and time limit on every instance it rents. + +```bash +claude mcp add cloudgpu --env CLOUDGPU_API_KEY=cgw-sk-... -- npx -y https://cloudgpu.app/mcp/cloudgpu-mcp-0.1.0.tgz +``` + +Setup for every client: https://cloudgpu.app/docs/mcp + ## Claude at half the official price Claude Opus, Sonnet and Fable are on the same endpoint, at 50% of the official per-token price. Full examples and tool guides: [`claude/`](claude/README.md). diff --git a/mcp-server/.gitignore b/mcp-server/.gitignore new file mode 100644 index 0000000..53a89d1 --- /dev/null +++ b/mcp-server/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +*.log +.env diff --git a/mcp-server/LICENSE b/mcp-server/LICENSE new file mode 100644 index 0000000..b321e3c --- /dev/null +++ b/mcp-server/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 CloudGPU.app + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/mcp-server/README.md b/mcp-server/README.md new file mode 100644 index 0000000..17fd056 --- /dev/null +++ b/mcp-server/README.md @@ -0,0 +1,132 @@ +# CloudGPU MCP server + +Let your AI coding assistant rent a GPU on [CloudGPU](https://cloudgpu.app), run a job, bring the results back and shut the GPU down. + +> "Fine-tune Qwen2.5-7B with LoRA on data/train.jsonl on a 4090 and put the adapter in ./outputs." + +The assistant checks live prices and quotes you, rents the GPU once you say yes, uploads your code and data, starts training in the background, watches the logs, downloads the adapter and destroys the instance. You get the files and the final cost. + +Works with any MCP client that can start a local server: **Cursor, Cline, opencode, Claude Code, VS Code, Windsurf, Continue, Claude Desktop**. + +## Install + +1. Create an API key at [cloudgpu.app/api](https://cloudgpu.app/api). The same key and balance also cover the OpenAI-compatible [model API](https://cloudgpu.app/api/docs). +2. Add the server to your client (Node.js 18+). + +
+Cursor / Windsurf / Cline / Claude Desktop + +```json +{ + "mcpServers": { + "cloudgpu": { + "command": "npx", + "args": ["-y", "https://cloudgpu.app/mcp/cloudgpu-mcp-0.1.0.tgz"], + "env": { "CLOUDGPU_API_KEY": "cgw-sk-..." } + } + } +} +``` +Cursor: `~/.cursor/mcp.json` · Cline: MCP Servers → Configure · Claude Desktop: `claude_desktop_config.json` +
+ +
+Claude Code + +```bash +claude mcp add cloudgpu --env CLOUDGPU_API_KEY=cgw-sk-... -- npx -y https://cloudgpu.app/mcp/cloudgpu-mcp-0.1.0.tgz +``` +
+ +
+opencode (opencode.json) + +```json +{ + "mcp": { + "cloudgpu": { + "type": "local", + "command": ["npx", "-y", "https://cloudgpu.app/mcp/cloudgpu-mcp-0.1.0.tgz"], + "environment": { "CLOUDGPU_API_KEY": "cgw-sk-..." } + } + } +} +``` +
+ +
+VS Code (.vscode/mcp.json) + +```json +{ + "servers": { + "cloudgpu": { + "command": "npx", + "args": ["-y", "https://cloudgpu.app/mcp/cloudgpu-mcp-0.1.0.tgz"], + "env": { "CLOUDGPU_API_KEY": "cgw-sk-..." } + } + } +} +``` +
+ +3. Optional but recommended: copy [`rules/cloudgpu.md`](rules/cloudgpu.md) into your project as `AGENTS.md`, `.cursor/rules/cloudgpu.md`, `.clinerules/cloudgpu.md` or `CLAUDE.md`. It tells the assistant to quote before renting, download before shutting down, and never leave a GPU running. + +## Tools + +| Tool | What it does | +|---|---| +| `get_account` | Balance, and how many instances the account may run at once | +| `list_gpus` | GPU models with VRAM, live price per GPU-hour and availability | +| `list_templates` | Ready-made images: JupyterLab, Ollama, ComfyUI, LLaMA-Factory, … | +| `estimate_cost` | Live quote for a GPU and a number of hours, plus your balance afterwards; returns a `quote_id` | +| `create_instance` | Rents from an approved quote, with a budget, a time limit and an idle limit | +| `get_status` / `list_instances` | Status, minutes run, cost so far, auto-shutdown limits | +| `run_command` | Runs a command on the instance; `background=true` for long jobs | +| `tail_logs` | Latest log lines, whether the job finished, GPU utilisation | +| `upload` / `download` | Files and folders between your computer and the instance (SFTP) | +| `stop_instance` | Destroys the instance and stops billing | +| `list_models` | Models on the OpenAI-compatible API, for inference without renting a GPU | + +The server also provides the rules as a resource (`cloudgpu://rules`) and a `train_on_cloudgpu` prompt. + +## Guardrails + +- **A quote first.** `create_instance` only takes a `quote_id` from `estimate_cost` and `user_confirmed=true`. +- **Server-side limits.** Every instance is created with `max_spend_usd`, `max_hours` and an idle limit (60 minutes by default). CloudGPU's servers check them every minute and destroy the instance when one is hit, even if your client has disconnected or your laptop is asleep. +- **Your own ceiling.** `CLOUDGPU_MAX_SPEND_USD` (default 50) and `CLOUDGPU_MAX_HOURS` (default 24) cap what the assistant may set. +- **Results before shutdown.** After commands have run, `stop_instance` refuses until something has been downloaded, unless the user confirms `force=true`. +- **Secrets stay out of the chat.** The instance's SSH login is used inside this process and never returned to the model. Tool output is scrubbed of the API key and login details. Uploading `.ssh`, `.env`, key files or your whole home directory needs `allow_sensitive=true`. +- **The instance stays manageable.** Commands that change the root password, SSH configuration, firewall or the platform's monitoring agent are refused. CloudGPU shuts down instances that it can no longer monitor. +- **Read-only mode.** `CLOUDGPU_READ_ONLY=1` registers only the look-up tools. + +## Configuration + +| Env | Default | | +|---|---|---| +| `CLOUDGPU_API_KEY` | (required) | From https://cloudgpu.app/api | +| `CLOUDGPU_MAX_SPEND_USD` | `50` | Highest budget the assistant may set for one instance | +| `CLOUDGPU_MAX_HOURS` | `24` | Longest time limit the assistant may set | +| `CLOUDGPU_READ_ONLY` | off | `1` = look-up tools only | + +## Without MCP + +The server wraps the public REST API, which any agent or script can call with the same key: + +```bash +curl https://cloudgpu.app/v1/gpu/offers -H "Authorization: Bearer $CLOUDGPU_API_KEY" + +curl -X POST https://cloudgpu.app/v1/gpu/instances \ + -H "Authorization: Bearer $CLOUDGPU_API_KEY" -H "Content-Type: application/json" \ + -d '{"gpu_model":"RTX 4090","max_minutes":120,"max_spend_usd":2,"idle_minutes":30}' +``` + +Reference: [cloudgpu.app/api/docs](https://cloudgpu.app/api/docs#gpu) · OpenAPI: [cloudgpu.app/openapi.json](https://cloudgpu.app/openapi.json) · For LLMs: [cloudgpu.app/llms.txt](https://cloudgpu.app/llms.txt) + +## Billing + +Prepaid USD balance, GPUs billed per minute; top up at [cloudgpu.app/billing](https://cloudgpu.app/billing). When the balance runs out, running instances are destroyed and their disks erased, so keep enough balance for the job and download results as you go. + +## License + +MIT diff --git a/mcp-server/package-lock.json b/mcp-server/package-lock.json new file mode 100644 index 0000000..6e26b06 --- /dev/null +++ b/mcp-server/package-lock.json @@ -0,0 +1,1299 @@ +{ + "name": "cloudgpu-mcp", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "cloudgpu-mcp", + "version": "0.1.0", + "license": "MIT", + "dependencies": { + "@modelcontextprotocol/sdk": "^1.32.2", + "ssh2": "^1.17.0", + "zod": "^3.25.0" + }, + "bin": { + "cloudgpu-mcp": "src/index.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@hono/node-server": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.1.5.tgz", + "integrity": "sha512-MgP/I06GdvsilDspMk/qmRzpk8LOUStP6jFAbSRi40W09DhoyUn+Mj7eyKICPqeYKybOjVFLVIAQzvu1bfIa7Q==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "peerDependencies": { + "hono": "^4 || ^5.0.0-0" + } + }, + "node_modules/@modelcontextprotocol/sdk": { + "version": "1.32.2", + "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.32.2.tgz", + "integrity": "sha512-SWsVtH/0vULSQStoZ6xxH2K09Li8fXYTMC64ZeogCdpZ3XSi1eCPOByV1OpuJxuI3OcmHhosDWYyii07tpPsLw==", + "license": "MIT", + "dependencies": { + "@hono/node-server": "^1.19.9 || ^2.0.5", + "ajv": "^8.17.1", + "ajv-formats": "^3.0.1", + "content-type": "^1.0.5", + "cors": "^2.8.5", + "cross-spawn": "^7.0.5", + "eventsource": "^3.0.2", + "eventsource-parser": "^3.0.0", + "express": "^5.2.1", + "express-rate-limit": "^8.2.1", + "hono": "^4.11.4", + "jose": "^6.1.3", + "json-schema-typed": "^8.0.2", + "pkce-challenge": "^5.0.0", + "raw-body": "^3.0.0", + "zod": "^3.25 || ^4.0", + "zod-to-json-schema": "^3.25.1" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@cfworker/json-schema": "^4.1.1", + "zod": "^3.25 || ^4.0" + }, + "peerDependenciesMeta": { + "@cfworker/json-schema": { + "optional": true + }, + "zod": { + "optional": false + } + } + }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ajv": { + "version": "8.20.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", + "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/asn1": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz", + "integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==", + "license": "MIT", + "dependencies": { + "safer-buffer": "~2.1.0" + } + }, + "node_modules/bcrypt-pbkdf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", + "integrity": "sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==", + "license": "BSD-3-Clause", + "dependencies": { + "tweetnacl": "^0.14.3" + } + }, + "node_modules/body-parser": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.4.0.tgz", + "integrity": "sha512-Ifk1KcLrxaGt1occQagQNFNNOqRt1LFuehEnHHzB8Z6cRgIxRU1TBaiIsUiCdA+gy5PL7Y1IX31DNKkRmxtXjQ==", + "license": "MIT", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^2.1.0", + "debug": "^4.4.3", + "http-errors": "^2.0.1", + "iconv-lite": "^0.7.3", + "on-finished": "^2.4.1", + "qs": "^6.16.1", + "raw-body": "^3.0.2", + "type-is": "^2.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/body-parser/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/buildcheck": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/buildcheck/-/buildcheck-0.0.7.tgz", + "integrity": "sha512-lHblz4ahamxpTmnsk+MNTRWsjYKv965MwOrSJyeD588rR3Jcu7swE+0wN5F+PbL5cjgu/9ObkhfzEPuofEMwLA==", + "optional": true, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-2.0.1.tgz", + "integrity": "sha512-e+H0ZXHSWYrENhQzw1LPuP4oF5MzVKmDU6d3hxlvaPEYLLg62MxtQNPRx4SYSuYJSBUgnQIG4HIN2tEtNv7Dog==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, + "node_modules/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/cpu-features": { + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/cpu-features/-/cpu-features-0.0.10.tgz", + "integrity": "sha512-9IkYqtX3YHPCzoVg1Py+o9057a3i0fp7S530UWokCSaFVTc7CwXPRiOjRjBQQ18ZCNafx78YfnG+HALxtVmOGA==", + "hasInstallScript": true, + "optional": true, + "dependencies": { + "buildcheck": "~0.0.6", + "nan": "^2.19.0" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", + "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/eventsource": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.7.tgz", + "integrity": "sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA==", + "license": "MIT", + "dependencies": { + "eventsource-parser": "^3.0.1" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/eventsource-parser": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.1.1.tgz", + "integrity": "sha512-EKN1vKAMcZ8MlYMpaNuxN6R9yakzH6uajHcHVTqWJzvu5pWw9DyhbP35HH8MVBQ+dZjAfDxk+A8NiR9KWaXiyQ==", + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/express": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/express/-/express-5.3.0.tgz", + "integrity": "sha512-qCqy1xSoaugxOD4IVHb1ZWdkvCF2W3aE2okKouWj8VwJ+ztskSiXoBnCSJqfKT+cVPJhuJqe9YLbY425+Zh00g==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.3.0", + "content-disposition": "^2.0.1", + "content-type": "^2.0.0", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "depd": "^2.0.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.8", + "qs": "^6.16.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.1.0", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/express-rate-limit": { + "version": "8.7.1", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.7.1.tgz", + "integrity": "sha512-2FXbqkygil3mZiXzEtM0IjE/UBmBNot0J1GEVrJT4JbrvwOSoEtqtO+wHbiMQELWe1eNvHoYRg2dkjOid+6JkA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "ip-address": "^10.2.0" + }, + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/express-rate-limit" + }, + "peerDependencies": { + "express": ">= 4.11" + } + }, + "node_modules/express/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "license": "MIT" + }, + "node_modules/fast-uri": { + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.9.tgz", + "integrity": "sha512-hS/0Wt3Ya043oKXs0sIxrMpKQITXhMLIrVAKKXi4gozGC9v7YRWVnXIZzjNPTO02M9BdxLCWqK1yRXgNziVyJQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/finalhandler": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", + "integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/hono": { + "version": "4.13.14", + "resolved": "https://registry.npmjs.org/hono/-/hono-4.13.14.tgz", + "integrity": "sha512-yhRLQ21U6qa9Hsu2N7Qcbh8tE+WKEcoErjIo56LeSGiGXGp9sA7UpE86Ui9uexb61KakiGwuHMn2QdV7w6i6kQ==", + "license": "MIT", + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.3.tgz", + "integrity": "sha512-IKXpvIzjnC9XTAUbVBcMfGS0EPaIXtW6v+zr+RRp+hqULEpo0owZax6wyRwPOJbWbzjYspQwusTsfVr0ifh4uQ==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ip-address": { + "version": "10.7.5", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.5.tgz", + "integrity": "sha512-t2v0rkILYv9WXmSL7TpAaU3HXgaFYOPUcH3QHgwQ++gpJuH3bqyMy4Fvt/DJCTKwzH3Cf+bAp5W/mFL39KPLzA==", + "license": "MIT", + "engines": { + "node": ">= 12" + } + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "license": "ISC" + }, + "node_modules/jose": { + "version": "6.2.13", + "resolved": "https://registry.npmjs.org/jose/-/jose-6.2.13.tgz", + "integrity": "sha512-7TIg10ZE1x82YediN+lcrPNvGMKge9yFHQD+Qho/b8y2adfugU3AsvvHfxV0fzyFllT6l9xCjf4RWY9g/Z9PJQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, + "node_modules/json-schema-typed": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/json-schema-typed/-/json-schema-typed-8.0.2.tgz", + "integrity": "sha512-fQhoXdcvc3V28x7C7BMs4P5+kNlgUURe2jmUT1T//oBRMDrqy1QPelJimwZGo7Hg9VPV3EQV5Bnq4hbFy2vetA==", + "license": "BSD-2-Clause" + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.1.tgz", + "integrity": "sha512-yz3xRaG20c6/BOzvYoDaGtPmGscs7YivItZEEqe6GbwNfHuxu9YNmvnEkMzKldAGY4/80pRcQRZSEnhquk9XuQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", + "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/nan": { + "version": "2.30.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.30.0.tgz", + "integrity": "sha512-P5mokDkSvCGBz6mZDD/2l+w9QoICRXdCyZ9ONGmTePr40oihJg3Kpn0YU3twKd6PJnwSlLBWNQeOT6yWEV2c4A==", + "license": "MIT", + "optional": true + }, + "node_modules/negotiator": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.1.0.tgz", + "integrity": "sha512-NMPBRMJgiQHjbd8phG3Vebdx4kZ1H121rbl5IkMqeOsahptB9BKo/d7oJ3zTXqTgagn2bWlNSXkh0QUGM31RYg==", + "license": "MIT", + "dependencies": { + "content-type": "^2.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/negotiator/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.2.tgz", + "integrity": "sha512-ATWUv387i+nLD49EiDoOft5scf32Vsdz3ktrQJG9bi7jRFmaXTssvyvj1EmeKVVgvesbqUtvQQvaS2TpTukAZQ==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-to-regexp": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz", + "integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/pkce-challenge": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/pkce-challenge/-/pkce-challenge-5.0.1.tgz", + "integrity": "sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ==", + "license": "MIT", + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/proxy-addr": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz", + "integrity": "sha512-5nnx0yGyVUcY6t9RnWcARWtwT9F1D8O9rt08htPvnd49W1IgZtmLkhu9WfMzQj1cFxjHIO6connUNVW5k7AVyQ==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/qs": { + "version": "6.16.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.1.tgz", + "integrity": "sha512-5Px6J7rfHBAGUhNQ3es4YzcOdBBw0SDcVtThJml4RdnKw4tKs2epA0kPZ+K8X+WiHktT93RHVcQ/3ym5aTCgtg==", + "license": "BSD-3-Clause", + "dependencies": { + "es-define-property": "^1.0.1", + "side-channel": "^1.1.1" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.3.0.tgz", + "integrity": "sha512-hek2mFQpPuI4E1BBKrSto+BU3e3x4xuarsbiwr3+lf7p44juvFMV0XFWQAP3xUyqXA4RrXLIoaSUGbSt056ZMw==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/raw-body": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", + "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.7.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", + "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.1", + "mime-types": "^3.0.2", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/serve-static": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz", + "integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/side-channel": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz", + "integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4", + "side-channel-list": "^1.0.1", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", + "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/ssh2": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/ssh2/-/ssh2-1.17.0.tgz", + "integrity": "sha512-wPldCk3asibAjQ/kziWQQt1Wh3PgDFpC0XpwclzKcdT1vql6KeYxf5LIt4nlFkUeR8WuphYMKqUA56X4rjbfgQ==", + "hasInstallScript": true, + "dependencies": { + "asn1": "^0.2.6", + "bcrypt-pbkdf": "^1.0.2" + }, + "engines": { + "node": ">=10.16.0" + }, + "optionalDependencies": { + "cpu-features": "~0.0.10", + "nan": "^2.23.0" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==", + "license": "Unlicense" + }, + "node_modules/type-is": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz", + "integrity": "sha512-faYHw0anBbc/kWF3zFTEnxSFOAGUX9GFbOBthvDdLsIlEoWOFOtS0zgCiQYwIskL9iGXZL3kAXD8OoZ4GmMATA==", + "license": "MIT", + "dependencies": { + "content-type": "^2.0.0", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/type-is/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, + "node_modules/zod": { + "version": "3.25.76", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz", + "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, + "node_modules/zod-to-json-schema": { + "version": "3.25.2", + "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.25.2.tgz", + "integrity": "sha512-O/PgfnpT1xKSDeQYSCfRI5Gy3hPf91mKVDuYLUHZJMiDFptvP41MSnWofm8dnCm0256ZNfZIM7DSzuSMAFnjHA==", + "license": "ISC", + "peerDependencies": { + "zod": "^3.25.28 || ^4" + } + } + } +} diff --git a/mcp-server/package.json b/mcp-server/package.json new file mode 100644 index 0000000..0059f54 --- /dev/null +++ b/mcp-server/package.json @@ -0,0 +1,48 @@ +{ + "name": "cloudgpu-mcp", + "version": "0.1.0", + "description": "MCP server for CloudGPU.app: let Cursor, Cline, opencode, Claude Code and other AI coding assistants rent a GPU, run a job, fetch the results and shut the GPU down, with spending limits the platform enforces.", + "type": "module", + "bin": { + "cloudgpu-mcp": "src/index.js" + }, + "main": "src/index.js", + "files": [ + "src", + "rules", + "README.md", + "LICENSE" + ], + "engines": { + "node": ">=18" + }, + "scripts": { + "test": "node --test test/*.test.js" + }, + "keywords": [ + "mcp", + "model-context-protocol", + "gpu", + "cloud-gpu", + "gpu-rental", + "cursor", + "cline", + "opencode", + "claude-code", + "fine-tuning", + "lora", + "cloudgpu" + ], + "homepage": "https://cloudgpu.app/docs/mcp", + "repository": { + "type": "git", + "url": "git+https://github.com/mrhy7176/cloudgpu-examples.git" + }, + "license": "MIT", + "author": "CloudGPU.app ", + "dependencies": { + "@modelcontextprotocol/sdk": "^1.32.2", + "ssh2": "^1.17.0", + "zod": "^3.25.0" + } +} diff --git a/mcp-server/rules/cloudgpu.md b/mcp-server/rules/cloudgpu.md new file mode 100644 index 0000000..e090834 --- /dev/null +++ b/mcp-server/rules/cloudgpu.md @@ -0,0 +1,43 @@ +# CloudGPU rules for AI assistants + +Use these rules whenever you rent or use a GPU on CloudGPU (cloudgpu.app) through the `cloudgpu` MCP tools. +Copy this file into your project as `AGENTS.md`, `.cursor/rules/cloudgpu.md`, `.clinerules/cloudgpu.md` or `CLAUDE.md` if your assistant reads one of those. + +## Before renting + +1. Call `get_account` and `list_gpus`. Pick a GPU with enough VRAM for the job, and don't rent more GPU than the job needs. As a rough guide, LoRA on a 7–8B model fits in 24 GB, and a full fine-tune of the same model needs 80 GB or more. +2. Call `estimate_cost` with a realistic number of hours. +3. Show the user a short quote before you rent anything: + - the GPU and how many, + - the price per hour, + - the estimated hours and cost, + - the budget and time limit you will set, + - their balance after the job. +4. Rent only after the user says yes. Pass `user_confirmed=true` only in that case. + +## Renting + +- Always set `max_spend_usd` and `max_hours`. CloudGPU's servers destroy the instance when either is reached, even if you have disconnected. +- Keep `idle_minutes` on (default 60). Raise it if setup will take long, because installing packages and downloading models leave the GPU idle. +- Poll `get_status` every 30–60 seconds until the instance is `running`. This usually takes about 2 minutes. +- `failed` instances are not charged. Tell the user, then offer another GPU. + +## Working on the instance + +- Put code and data on the instance with `upload`. Do not upload credentials. +- Use `run_command` for short steps. For training, long installs or big downloads, use `background=true` and follow progress with `tail_logs`. +- Instances come with Python and CUDA. Check with `python -c "import torch; print(torch.__version__, torch.cuda.is_available())"` and install the PyTorch build you need if it is missing. +- **Do not** change the root password, edit the SSH configuration, change the firewall, or stop the platform's monitoring agent (`cgpu-*` processes). The platform must keep its access to the instance; if that access is lost, the platform shuts the instance down. The MCP server refuses such commands. +- Never use the GPU for cryptocurrency mining or anything the [acceptable use policy](https://cloudgpu.app/aup) forbids. Instances that do so are shut down. + +## Finishing (always) + +1. Download every result: model weights, adapters, checkpoints, logs, metrics. Destroying an instance erases its disk, and CloudGPU has no persistent storage. +2. Call `stop_instance`. +3. Tell the user what ran, where the results are on their computer, and the final cost from `stop_instance`. + +If anything goes wrong mid-way, do not leave the instance running. Download whatever exists, stop the instance, then explain what happened. + +## Only need a model, not a GPU? + +The same API key works for CloudGPU's OpenAI-compatible model API at `https://cloudgpu.app/v1`. Call `list_models` to see the models. For inference on a hosted model this is usually quicker and cheaper than renting a GPU. diff --git a/mcp-server/src/api.js b/mcp-server/src/api.js new file mode 100644 index 0000000..0e081a4 --- /dev/null +++ b/mcp-server/src/api.js @@ -0,0 +1,99 @@ +// CloudGPU REST client. Talks only to the public API (https://cloudgpu.app/v1/...), +// with the user's own API key. Nothing here knows or needs anything that is not public. + +export class ApiError extends Error { + constructor(status, code, message) { + super(message); + this.status = status; + this.code = code; + } +} + +export class CloudGpuApi { + constructor({ apiKey, baseUrl = "https://cloudgpu.app", fetchImpl = globalThis.fetch } = {}) { + this.apiKey = apiKey; + this.baseUrl = baseUrl.replace(/\/+$/, ""); + this.fetch = fetchImpl; + } + + async request(method, path, body) { + if (!this.apiKey) { + throw new ApiError( + 401, + "missing_api_key", + "CLOUDGPU_API_KEY is not set. Create a key at https://cloudgpu.app/api and add it to this MCP server's env.", + ); + } + let lastErr; + // Retry only on network errors and 502/503/504; never on 4xx (a create must not run twice). + const attempts = method === "GET" ? 3 : 1; + for (let i = 0; i < attempts; i++) { + try { + const res = await this.fetch(this.baseUrl + path, { + method, + headers: { + Authorization: `Bearer ${this.apiKey}`, + "Content-Type": "application/json", + "User-Agent": "cloudgpu-mcp/0.1", + }, + body: body === undefined ? undefined : JSON.stringify(body), + }); + const text = await res.text(); + let json; + try { + json = text ? JSON.parse(text) : {}; + } catch { + json = null; + } + if (!res.ok) { + const e = json && json.error ? json.error : {}; + const err = new ApiError(res.status, e.code || `http_${res.status}`, e.message || `HTTP ${res.status}`); + if (method === "GET" && res.status >= 502 && res.status <= 504 && i < attempts - 1) { + lastErr = err; + await sleep(1000 * (i + 1)); + continue; + } + throw err; + } + if (json === null) { + throw new ApiError(res.status, "bad_response", "The server returned something that is not JSON."); + } + return json; + } catch (err) { + if (err instanceof ApiError) throw err; + lastErr = new ApiError(0, "network_error", `Could not reach ${this.baseUrl}: ${err.message}`); + if (i < attempts - 1) await sleep(1000 * (i + 1)); + } + } + throw lastErr; + } + + account() { + return this.request("GET", "/v1/gpu/account"); + } + offers() { + return this.request("GET", "/v1/gpu/offers").then((r) => r.data || []); + } + templates() { + return this.request("GET", "/v1/gpu/templates").then((r) => r.data || []); + } + instances() { + return this.request("GET", "/v1/gpu/instances").then((r) => r.data || []); + } + instance(id) { + return this.request("GET", `/v1/gpu/instances/${encodeURIComponent(id)}`); + } + create(body) { + return this.request("POST", "/v1/gpu/instances", body); + } + destroy(id) { + return this.request("DELETE", `/v1/gpu/instances/${encodeURIComponent(id)}`); + } + models() { + return this.request("GET", "/v1/models").then((r) => r.data || []); + } +} + +export function sleep(ms) { + return new Promise((r) => setTimeout(r, ms)); +} diff --git a/mcp-server/src/guards.js b/mcp-server/src/guards.js new file mode 100644 index 0000000..589937d --- /dev/null +++ b/mcp-server/src/guards.js @@ -0,0 +1,118 @@ +// Guardrails that run on this machine, before anything reaches the API or the instance. +// The hard limits (auto-shutdown on time, budget and idle GPU) are enforced by CloudGPU's servers; +// these catch mistakes early and keep secrets out of the model's context. +import os from "node:os"; +import path from "node:path"; +import crypto from "node:crypto"; + +// ── Commands that would break the instance ─────────────────────────────────── +// +// Every CloudGPU instance runs a small platform monitoring agent, and the platform checks on it +// over SSH. Changing the root password, rewriting the SSH config or killing the agent locks that +// check out, and the platform then shuts the instance down. These patterns stop an assistant from +// doing that by accident (for example while "hardening" SSH or "cleaning up" processes). +const BLOCKED = [ + { re: /\b(passwd|chpasswd)\b/, why: "changes a login password" }, + { re: /\busermod\b[^\n]*\s-p\b/, why: "changes a login password" }, + { re: /sshd_config|\/etc\/ssh\//, why: "edits the SSH server configuration" }, + { re: /\b(systemctl|service)\s+(stop|disable|mask|restart)\s+(ssh|sshd)\b/, why: "stops the SSH server" }, + { re: /cgpu-(watchdog|agent)/, why: "touches the platform monitoring agent" }, + { re: /\bkill\s+(-9\s+|-KILL\s+|-s\s+KILL\s+)?-1\b/, why: "kills every process on the machine" }, + { re: /\bpkill\s+(-9\s+)?(-f\s+)?(bash|sh|sshd)\b/, why: "kills the shells the platform relies on" }, + { re: /\bkillall\s+(-9\s+)?(bash|sh|sshd)\b/, why: "kills the shells the platform relies on" }, + { re: /\b(iptables|nft|ufw)\b/, why: "changes the firewall" }, +]; + +export function checkCommand(command) { + for (const b of BLOCKED) { + if (b.re.test(command)) { + return ( + `Refused: this command ${b.why}. CloudGPU instances must stay reachable for the platform's ` + + `monitoring, otherwise the instance is shut down. Do the task another way.` + ); + } + } + return null; +} + +// ── Local files that should not be shipped to a rented machine by default ───── +const SENSITIVE = [ + /(^|\/)\.ssh(\/|$)/, + /(^|\/)\.aws(\/|$)/, + /(^|\/)\.gnupg(\/|$)/, + /(^|\/)\.config\/gcloud(\/|$)/, + /(^|\/)\.kube(\/|$)/, + /(^|\/)\.docker\/config\.json$/, + /(^|\/)\.netrc$/, + /(^|\/)\.npmrc$/, + /(^|\/)\.pypirc$/, + /(^|\/)\.env(\..*)?$/, + /\.(pem|key|p12|pfx)$/, + /(^|\/)id_(rsa|ed25519|ecdsa|dsa)(\.pub)?$/, +]; + +export function sensitiveReason(localPath) { + const abs = path.resolve(expandHome(localPath)).replace(/\\/g, "/"); + if (abs === os.homedir().replace(/\\/g, "/")) return "it is your whole home directory"; + for (const re of SENSITIVE) if (re.test(abs)) return "it looks like credentials or a secrets file"; + return null; +} + +export function expandHome(p) { + if (!p) return p; + return p === "~" ? os.homedir() : p.startsWith("~/") ? path.join(os.homedir(), p.slice(2)) : p; +} + +// ── Redaction ───────────────────────────────────────────────────────────── +/** Remove secrets (API key, SSH password, SSH host) from any text going back to the model. */ +export function redact(text, secrets) { + if (text == null) return text; + let out = String(text); + for (const s of secrets) { + if (s && String(s).length >= 4) out = out.split(String(s)).join("[redacted]"); + } + out = out.replace(/\bsk-[A-Za-z0-9_-]{16,}/g, "sk-[redacted]"); + return out; +} + +/** Instance object as the model sees it: no SSH host, user or password. */ +export function publicInstance(inst) { + if (!inst) return inst; + const { ssh, ...rest } = inst; + return { ...rest, ssh_ready: !!(ssh && ssh.host && inst.status === "running") }; +} + +// ── Quotes ──────────────────────────────────────────────────────────────── +// +// create_instance only accepts a quote_id from estimate_cost, so the assistant always has the +// real hourly price, the estimate and the balance in hand (and shows them) before renting. +export class Quotes { + constructor(ttlMs = 15 * 60 * 1000) { + this.ttlMs = ttlMs; + this.map = new Map(); + } + put(q) { + const id = "q_" + crypto.randomBytes(6).toString("hex"); + this.map.set(id, { ...q, id, at: Date.now() }); + return id; + } + take(id) { + const q = this.map.get(id); + if (!q) return { error: "Unknown quote_id. Call estimate_cost first and show the quote to the user." }; + if (Date.now() - q.at > this.ttlMs) { + this.map.delete(id); + return { error: "This quote expired (quotes last 15 minutes). Call estimate_cost again; prices are live." }; + } + this.map.delete(id); + return { quote: q }; + } +} + +export function round2(n) { + return Math.round(n * 100) / 100; +} + +/** Shell-quote one argument for bash. */ +export function shq(s) { + return `'${String(s).replace(/'/g, `'\\''`)}'`; +} diff --git a/mcp-server/src/index.js b/mcp-server/src/index.js new file mode 100644 index 0000000..55bc377 --- /dev/null +++ b/mcp-server/src/index.js @@ -0,0 +1,557 @@ +#!/usr/bin/env node +// CloudGPU MCP server (stdio). Lets an AI coding assistant rent a GPU on cloudgpu.app, run a job, +// fetch the results and shut the GPU down. +// +// Env: +// CLOUDGPU_API_KEY required; create one at https://cloudgpu.app/api +// CLOUDGPU_MAX_SPEND_USD optional; highest budget the assistant may set for one instance (default 50) +// CLOUDGPU_MAX_HOURS optional; longest run the assistant may set for one instance (default 24) +// CLOUDGPU_READ_ONLY optional; "1" registers only the tools that look things up +// CLOUDGPU_BASE_URL optional; default https://cloudgpu.app +import fs from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; +import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; +import { z } from "zod"; +import { CloudGpuApi, ApiError } from "./api.js"; +import { SshPool, exec, upload, download, writeFile } from "./ssh.js"; +import { + checkCommand, + sensitiveReason, + expandHome, + redact, + publicInstance, + Quotes, + round2, + shq, +} from "./guards.js"; + +const VERSION = "0.1.0"; +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const RULES = fs.readFileSync(path.join(HERE, "..", "rules", "cloudgpu.md"), "utf8"); + +const cfg = { + apiKey: (process.env.CLOUDGPU_API_KEY || "").trim(), + baseUrl: process.env.CLOUDGPU_BASE_URL || "https://cloudgpu.app", + maxSpend: num(process.env.CLOUDGPU_MAX_SPEND_USD, 50), + maxHours: num(process.env.CLOUDGPU_MAX_HOURS, 24), + readOnly: /^(1|true|yes)$/i.test(process.env.CLOUDGPU_READ_ONLY || ""), +}; + +function num(v, d) { + const n = Number(v); + return Number.isFinite(n) && n > 0 ? n : d; +} + +const api = new CloudGpuApi({ apiKey: cfg.apiKey, baseUrl: cfg.baseUrl }); +const pool = new SshPool(); +const quotes = new Quotes(); +// Instances this session touched: did we run anything, did we download anything. +const session = new Map(); + +const INSTRUCTIONS = `CloudGPU (cloudgpu.app) rents GPUs billed per minute from a prepaid balance. +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. +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. +The same API key also works for the OpenAI-compatible model API at ${cfg.baseUrl}/v1 (see list_models).`; + +const server = new McpServer({ name: "cloudgpu", version: VERSION }, { instructions: INSTRUCTIONS }); + +// ── helpers ────────────────────────────────────────────────────────────── + +function ok(obj) { + const text = typeof obj === "string" ? obj : JSON.stringify(obj, null, 2); + return { content: [{ type: "text", text: redact(text, [cfg.apiKey]) }] }; +} + +function fail(msg) { + return { content: [{ type: "text", text: redact(msg, [cfg.apiKey]) }], isError: true }; +} + +function wrap(fn) { + return async (args) => { + try { + return await fn(args || {}); + } catch (err) { + if (err instanceof ApiError) { + let hint = ""; + if (err.status === 401) hint = " Check CLOUDGPU_API_KEY (create one at https://cloudgpu.app/api)."; + if (err.status === 402) hint = " Top up at https://cloudgpu.app/billing."; + return fail(`CloudGPU API error ${err.status} ${err.code}: ${err.message}${hint}`); + } + return fail(`Error: ${err && err.message ? err.message : String(err)}`); + } + }; +} + +function track(id) { + if (!session.has(id)) session.set(id, { ran: false, downloaded: false }); + return session.get(id); +} + +/** Running instance + SSH client; throws a readable error otherwise. */ +async function connectTo(id) { + const inst = await api.instance(id); + if (inst.status !== "running") { + throw new Error( + `Instance ${id} is ${inst.status}` + + (inst.status === "creating" ? "; wait for it with get_status (usually about 2 minutes)." : "."), + ); + } + if (!inst.ssh || !inst.ssh.host) throw new Error(`Instance ${id} has no SSH access yet; try get_status again shortly.`); + const client = await pool.get(id, inst.ssh); + const secrets = [cfg.apiKey, inst.ssh.password, inst.ssh.host]; + return { inst, client, secrets }; +} + +const JOBS = ".cloudgpu/jobs"; +// bash -i so conda / venv set up in ~/.bashrc are active, the same as an interactive login. +const NOISE = /^bash: (cannot set terminal process group|no job control in this shell).*\n?/gm; + +function cleanOut(s, secrets) { + return redact((s || "").replace(NOISE, ""), secrets); +} + +// ── account and catalogue ──────────────────────────────────────────────── + +server.registerTool( + "get_account", + { + title: "CloudGPU account", + description: "Balance in USD, how many instances this account may run at once, and how many are running now.", + inputSchema: {}, + annotations: { readOnlyHint: true, openWorldHint: true }, + }, + wrap(async () => ok(await api.account())), +); + +server.registerTool( + "list_gpus", + { + title: "List GPUs", + description: + "GPU models you can rent now, with VRAM, live price per GPU-hour in USD and availability (ok / low / none). Prices are live; never assume them.", + inputSchema: { + min_vram_gb: z.number().optional().describe("Only GPUs with at least this much VRAM per card"), + gpu_model: z.string().optional().describe("Filter by name, e.g. 4090, A100, H20"), + }, + annotations: { readOnlyHint: true, openWorldHint: true }, + }, + wrap(async ({ min_vram_gb, gpu_model }) => { + let rows = await api.offers(); + if (min_vram_gb) rows = rows.filter((r) => (r.vram_gb || 0) >= min_vram_gb); + if (gpu_model) { + const q = gpu_model.toLowerCase().replace(/\s+/g, ""); + rows = rows.filter((r) => String(r.gpu_model).toLowerCase().replace(/\s+/g, "").includes(q)); + } + return ok({ + gpus: rows.map((r) => ({ + gpu_model: r.gpu_model, + vram_gb: r.vram_gb, + usd_per_gpu_hour: r.hourly_usd, + available: r.available, + min_gpu_count: r.min_gpu_count, + })), + note: "Billed per minute. 'available' is live and can change before you rent.", + }); + }), +); + +server.registerTool( + "list_templates", + { + title: "List templates", + description: + "Ready-made instance images (e.g. JupyterLab, Ollama, ComfyUI, LLaMA-Factory) with the GPU each recommends. Templates with has_api_endpoint get a public HTTPS api_url.", + inputSchema: {}, + annotations: { readOnlyHint: true, openWorldHint: true }, + }, + wrap(async () => ok({ templates: await api.templates() })), +); + +server.registerTool( + "estimate_cost", + { + title: "Quote a rental", + description: + "Live price and estimated cost for a GPU, plus your balance after it. Returns a quote_id that create_instance needs. Show the quote to the user and get an explicit yes before renting.", + inputSchema: { + gpu_model: z.string().describe("GPU model exactly as list_gpus returns it"), + gpu_count: z.number().int().min(1).max(8).default(1), + hours: z.number().positive().describe("Expected run time in hours"), + template: z.string().optional().describe("Template id from list_templates; omit for a plain GPU with Python and CUDA"), + }, + annotations: { readOnlyHint: true, openWorldHint: true }, + }, + wrap(async ({ gpu_model, gpu_count = 1, hours, template }) => { + const [offers, account] = await Promise.all([api.offers(), api.account().catch(() => null)]); + const offer = offers.find((o) => String(o.gpu_model).toLowerCase() === gpu_model.toLowerCase()); + if (!offer) { + return fail(`No GPU named "${gpu_model}". Available: ${offers.map((o) => o.gpu_model).join(", ")}`); + } + if (gpu_count < (offer.min_gpu_count || 1)) { + return fail(`${offer.gpu_model} is rented in groups of at least ${offer.min_gpu_count} GPUs.`); + } + const hourly = round2(Number(offer.hourly_usd) * gpu_count); + const estimate = round2(hourly * hours); + const balance = account ? Number(account.balance_usd) : null; + const warnings = []; + if (offer.available === "none") warnings.push("This GPU is out of stock right now; renting will likely fail. Pick another."); + if (offer.available === "low") warnings.push("Only a few of these are free; renting may fail."); + if (balance != null && balance < estimate * 1.1) { + warnings.push( + `Balance $${balance} does not cover the estimate plus a 10% buffer. When the balance runs out the instance is destroyed and its disk erased. Top up at https://cloudgpu.app/billing.`, + ); + } + const quote_id = quotes.put({ gpu_model: offer.gpu_model, gpu_count, template, hourly, hours, estimate }); + return ok({ + quote_id, + gpu_model: offer.gpu_model, + gpu_count, + template: template || null, + usd_per_hour: hourly, + hours, + estimated_cost_usd: estimate, + balance_usd: balance, + balance_after_usd: balance == null ? null : round2(balance - estimate), + suggested_max_spend_usd: round2(Math.min(cfg.maxSpend, Math.max(1, estimate * 1.25))), + warnings, + next: "Show this quote to the user. Only after they say yes, call create_instance with this quote_id.", + }); + }), +); + +server.registerTool( + "list_models", + { + title: "List hosted models", + description: + "Models on CloudGPU's OpenAI-compatible API (same key, same balance). Use them from code with base_url " + + `${cfg.baseUrl}/v1 instead of renting a GPU when you only need inference.`, + inputSchema: {}, + annotations: { readOnlyHint: true, openWorldHint: true }, + }, + wrap(async () => { + const models = await api.models(); + return ok({ + base_url: `${cfg.baseUrl}/v1`, + auth: "Authorization: Bearer ", + models: models.map((m) => m.id), + pricing: `${cfg.baseUrl}/pricing`, + }); + }), +); + +// ── instances (read) ───────────────────────────────────────────────────── + +server.registerTool( + "get_status", + { + title: "Instance status", + description: + "Status (creating / running / stopped / failed), minutes run, cost so far, whether SSH is ready, the public api_url if the template has one, and the auto-shutdown limits.", + inputSchema: { instance_id: z.string() }, + annotations: { readOnlyHint: true, openWorldHint: true }, + }, + wrap(async ({ instance_id }) => ok(publicInstance(await api.instance(instance_id)))), +); + +server.registerTool( + "list_instances", + { + title: "List instances", + description: "Instances on this account: running, starting, and those stopped in the last 7 days, with cost.", + inputSchema: {}, + annotations: { readOnlyHint: true, openWorldHint: true }, + }, + wrap(async () => ok({ instances: (await api.instances()).map(publicInstance) })), +); + +// ── instances (act) ────────────────────────────────────────────────────── + +if (!cfg.readOnly) { + server.registerTool( + "create_instance", + { + title: "Rent a GPU", + description: + "Rents the GPU from a quote. Costs money. Requires a quote_id from estimate_cost that the user has approved. " + + "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. " + + "idle_minutes destroys it after the GPU sits idle that long (installing packages and downloading data count as idle, so allow for setup).", + inputSchema: { + quote_id: z.string(), + user_confirmed: z.boolean().describe("true only if the user explicitly approved this quote in the conversation"), + max_spend_usd: z.number().positive().describe(`Budget for this instance in USD (at most ${cfg.maxSpend})`), + max_hours: z.number().positive().describe(`Hard time limit in hours (at most ${cfg.maxHours})`), + idle_minutes: z + .number() + .int() + .min(0) + .max(1440) + .default(60) + .describe("Destroy after the GPU has been idle this long; 0 turns it off; otherwise at least 10"), + }, + annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true }, + }, + wrap(async ({ quote_id, user_confirmed, max_spend_usd, max_hours, idle_minutes = 60 }) => { + if (user_confirmed !== true) { + return fail("Not rented: show the quote to the user and wait for an explicit yes, then call again with user_confirmed=true."); + } + if (max_spend_usd > cfg.maxSpend) { + return fail( + `max_spend_usd ${max_spend_usd} is above this server's cap of ${cfg.maxSpend} (CLOUDGPU_MAX_SPEND_USD). Ask the user to raise the cap in the MCP config if they want more.`, + ); + } + if (max_hours > cfg.maxHours) { + return fail(`max_hours ${max_hours} is above this server's cap of ${cfg.maxHours} (CLOUDGPU_MAX_HOURS).`); + } + if (idle_minutes > 0 && idle_minutes < 10) return fail("idle_minutes must be 0 (off) or at least 10."); + const { quote, error } = quotes.take(quote_id); + if (error) return fail(error); + const account = await api.account(); + const balance = Number(account.balance_usd); + const needed = round2(Math.min(max_spend_usd, quote.estimate) * 1.1); + if (balance < needed) { + return fail( + `Not rented: balance $${balance} is below $${needed} (the estimate or budget plus 10%). If the balance runs out the instance is destroyed and its disk erased. Top up at https://cloudgpu.app/billing.`, + ); + } + const body = { + gpu_model: quote.gpu_model, + gpu_count: quote.gpu_count, + max_minutes: Math.ceil(max_hours * 60), + max_spend_usd, + idle_minutes, + }; + if (quote.template) body.template = quote.template; + const inst = await api.create(body); + track(inst.id); + return ok({ + ...publicInstance(inst), + next: "Poll get_status every 30-60 seconds until status is running (usually about 2 minutes; templates and multi-GPU machines can take longer). Then upload and run_command.", + }); + }), + ); + + server.registerTool( + "run_command", + { + title: "Run a command on the instance", + description: + "Runs a bash command on the instance as root, in an interactive-style shell so conda/venv from ~/.bashrc are active. " + + "Foreground returns the exit code and the last 20k characters of output. For anything longer than a few minutes (training, big downloads) use background=true, then tail_logs.", + inputSchema: { + instance_id: z.string(), + command: z.string().describe("bash command or script"), + background: z.boolean().default(false), + timeout_sec: z.number().int().min(5).max(3600).default(600).describe("Foreground only"), + workdir: z.string().default("~").describe("Directory to run in"), + }, + annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true }, + }, + wrap(async ({ instance_id, command, background = false, timeout_sec = 600, workdir = "~" }) => { + const blocked = checkCommand(command); + if (blocked) return fail(blocked); + const { client, secrets } = await connectTo(instance_id); + track(instance_id).ran = true; + const job = "j" + Date.now().toString(36); + const cd = workdir === "~" ? "cd ~" : workdir.startsWith("~/") ? `cd ~/${shq(workdir.slice(2))}` : `cd ${shq(workdir)}`; + await writeFile(client, `${JOBS}/${job}.sh`, `${cd} || exit 97\n${command}\n`); + if (background) { + const r = await exec( + client, + `cd ~ && setsid nohup bash -c 'bash -i ${JOBS}/${job}.sh > ${JOBS}/${job}.log 2>&1 < /dev/null; echo $? > ${JOBS}/${job}.exit' > /dev/null 2>&1 < /dev/null & echo started`, + { timeoutSec: 30 }, + ); + if (!/started/.test(r.stdout)) return fail(`Could not start the job: ${cleanOut(r.stderr, secrets)}`); + return ok({ + job_id: job, + log: `~/${JOBS}/${job}.log`, + next: "Check progress with tail_logs (job_id). The job keeps running if this assistant disconnects; the instance's limits still apply.", + }); + } + const r = await exec(client, `cd ~ && timeout ${timeout_sec} bash -i ${JOBS}/${job}.sh 2>&1 < /dev/null`, { + timeoutSec: timeout_sec + 15, + }); + const out = cleanOut(r.stdout + (r.stderr ? "\n" + r.stderr : ""), secrets); + return ok({ + exit_code: r.timedOut || r.code === 124 ? null : r.code, + timed_out: r.timedOut || r.code === 124, + output: out, + ...(r.timedOut || r.code === 124 ? { hint: "Timed out. Re-run long work with background=true." } : {}), + }); + }), + ); + + server.registerTool( + "upload", + { + title: "Upload to the instance", + description: + "Copies a local file or directory (this computer) to the instance over SFTP. node_modules, .git and __pycache__ are skipped. Credentials files (.ssh, .env, keys) are refused unless allow_sensitive is true and the user asked for it.", + inputSchema: { + instance_id: z.string(), + local_path: z.string(), + remote_path: z.string().describe("Destination on the instance, e.g. /root/project or /root/data/"), + allow_sensitive: z.boolean().default(false), + }, + annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true }, + }, + wrap(async ({ instance_id, local_path, remote_path, allow_sensitive = false }) => { + const local = path.resolve(expandHome(local_path)); + if (!fs.existsSync(local)) return fail(`No such local path: ${local}`); + const why = sensitiveReason(local); + if (why && !allow_sensitive) { + return fail(`Refused to upload ${local}: ${why}. If the user explicitly wants it on the instance, call again with allow_sensitive=true.`); + } + const { client } = await connectTo(instance_id); + const remote = remote_path.startsWith("~/") ? remote_path.slice(2) : remote_path; + const r = await upload(client, local, remote); + return ok({ uploaded_files: r.files, bytes: r.bytes, remote_path }); + }), + ); + + server.registerTool( + "download", + { + title: "Download from the instance", + description: + "Copies a file or directory from the instance to this computer. Do this for every result before stop_instance: destroying an instance erases its disk.", + inputSchema: { + instance_id: z.string(), + remote_path: z.string(), + local_path: z.string().describe("Local destination file or directory, e.g. ./outputs/"), + }, + annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true }, + }, + wrap(async ({ instance_id, remote_path, local_path }) => { + const { client } = await connectTo(instance_id); + const remote = remote_path.startsWith("~/") ? remote_path.slice(2) : remote_path; + const r = await download(client, remote, path.resolve(expandHome(local_path))); + track(instance_id).downloaded = true; + return ok({ + files: r.files.slice(0, 200), + file_count: r.files.length, + bytes: r.bytes, + }); + }), + ); + + server.registerTool( + "tail_logs", + { + title: "Job logs and GPU use", + description: + "Last lines of a background job's log (job_id) or any log file (path), whether the job is still running and its exit code, plus current GPU utilisation and memory.", + inputSchema: { + instance_id: z.string(), + job_id: z.string().optional(), + path: z.string().optional(), + lines: z.number().int().min(1).max(2000).default(100), + }, + annotations: { readOnlyHint: true, openWorldHint: true }, + }, + wrap(async ({ instance_id, job_id, path: logPath, lines = 100 }) => { + if (!job_id && !logPath) return fail("Give job_id (from run_command background=true) or path."); + if (job_id && !/^[a-z0-9]+$/i.test(job_id)) return fail("Bad job_id."); + const { client, secrets } = await connectTo(instance_id); + const file = job_id ? `${JOBS}/${job_id}.log` : logPath.startsWith("~/") ? logPath.slice(2) : logPath; + const exitFile = job_id ? `${JOBS}/${job_id}.exit` : "/nonexistent"; + const r = await exec( + client, + `cd ~; echo '<&1; echo 'LOG>>'; ` + + `if [ -f ${shq(exitFile)} ]; then echo "EXIT=$(cat ${shq(exitFile)})"; fi; ` + + `nvidia-smi --query-gpu=index,utilization.gpu,memory.used,memory.total --format=csv,noheader,nounits 2>/dev/null | sed 's/^/GPU=/'`, + { timeoutSec: 60 }, + ); + const s = r.stdout; + const log = s.includes("<>")) : s; + const exitM = s.match(/EXIT=(\d+)/); + const gpus = [...s.matchAll(/GPU=(\d+), (\d+), (\d+), (\d+)/g)].map((m) => ({ + gpu: Number(m[1]), + utilization_pct: Number(m[2]), + memory_used_mb: Number(m[3]), + memory_total_mb: Number(m[4]), + })); + return ok({ + log: cleanOut(log, secrets), + ...(job_id ? { running: !exitM, exit_code: exitM ? Number(exitM[1]) : null } : {}), + gpus, + }); + }), + ); + + server.registerTool( + "stop_instance", + { + title: "Destroy an instance", + description: + "Destroys the instance and stops billing. Its disk is erased. If commands were run on it in this session and nothing was downloaded, this refuses unless force=true (only after the user confirms the results are not needed).", + inputSchema: { + instance_id: z.string(), + force: z.boolean().default(false), + }, + annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: true }, + }, + wrap(async ({ instance_id, force = false }) => { + const s = session.get(instance_id); + if (s && s.ran && !s.downloaded && !force) { + return fail( + "Not stopped: nothing has been downloaded from this instance yet, and stopping erases its disk. Download the results first, or ask the user and call again with force=true.", + ); + } + pool.close(instance_id); + try { + const inst = await api.destroy(instance_id); + session.delete(instance_id); + return ok({ ...publicInstance(inst), note: "Destroyed. Billing has stopped." }); + } catch (err) { + if (err instanceof ApiError && err.code === "instance_provisioning") { + return fail("The instance is still starting and cannot be destroyed yet. Wait for get_status to show running (or failed; failed instances are not charged), then call stop_instance again."); + } + throw err; + } + }), + ); +} + +// ── rules for the assistant ────────────────────────────────────────────── + +server.registerResource( + "rules", + "cloudgpu://rules", + { title: "CloudGPU agent rules", description: "How to rent, run and shut down safely", mimeType: "text/markdown" }, + async (uri) => ({ contents: [{ uri: uri.href, mimeType: "text/markdown", text: RULES }] }), +); + +server.registerPrompt( + "train_on_cloudgpu", + { + title: "Run a job on a CloudGPU GPU", + description: "Rent a GPU, run a training or fine-tuning job, bring the results back and shut down", + argsSchema: { task: z.string().describe("What to run, e.g. 'LoRA fine-tune Qwen2.5-7B on data/train.jsonl'") }, + }, + ({ task }) => ({ + messages: [{ role: "user", content: { type: "text", text: `${RULES}\n\n---\n\nTask: ${task}` } }], + }), +); + +// ── start ──────────────────────────────────────────────────────────────── + +if (process.argv.includes("--version")) { + console.log(VERSION); + process.exit(0); +} + +const transport = new StdioServerTransport(); +await server.connect(transport); +const bye = () => { + pool.closeAll(); + process.exit(0); +}; +process.on("SIGINT", bye); +process.on("SIGTERM", bye); +process.stdin.on("close", bye); +if (!cfg.apiKey) { + console.error("cloudgpu-mcp: CLOUDGPU_API_KEY is not set; tools will return an error until it is. Create a key at https://cloudgpu.app/api"); +} diff --git a/mcp-server/src/ssh.js b/mcp-server/src/ssh.js new file mode 100644 index 0000000..6a3e441 --- /dev/null +++ b/mcp-server/src/ssh.js @@ -0,0 +1,233 @@ +// SSH to a rented instance: run commands, upload, download. +// +// The SSH password comes from the API and stays inside this process. It is never put in a tool +// result, so it never reaches the model's context or the chat log. +import { Client } from "ssh2"; +import fs from "node:fs"; +import path from "node:path"; +import { sleep } from "./api.js"; + +const MAX_OUTPUT = 20000; // characters of command output returned to the model + +export class SshPool { + constructor() { + this.conns = new Map(); // instanceId -> { client, key } + } + + async get(instanceId, ssh) { + const key = `${ssh.host}:${ssh.port}:${ssh.user}`; + const cur = this.conns.get(instanceId); + if (cur && cur.key === key && cur.ready) return cur.client; + if (cur) this.close(instanceId); + // Some instance gateways drop several connections opened back to back, so retry with backoff. + let lastErr; + for (let i = 0; i < 4; i++) { + try { + const client = await connect(ssh); + const entry = { client, key, ready: true }; + client.on("close", () => { + entry.ready = false; + }); + client.on("error", () => { + entry.ready = false; + }); + this.conns.set(instanceId, entry); + return client; + } catch (err) { + lastErr = err; + await sleep(2000 * (i + 1)); + } + } + throw new Error(`SSH connection failed: ${lastErr && lastErr.message}`); + } + + close(instanceId) { + const cur = this.conns.get(instanceId); + if (cur) { + try { + cur.client.end(); + } catch { + /* already closed */ + } + this.conns.delete(instanceId); + } + } + + closeAll() { + for (const id of [...this.conns.keys()]) this.close(id); + } +} + +function connect(ssh) { + return new Promise((resolve, reject) => { + const c = new Client(); + const timer = setTimeout(() => { + c.end(); + reject(new Error("timed out")); + }, 25000); + c.on("ready", () => { + clearTimeout(timer); + resolve(c); + }); + c.on("error", (e) => { + clearTimeout(timer); + reject(e); + }); + c.connect({ + host: ssh.host, + port: ssh.port || 22, + username: ssh.user || "root", + password: ssh.password, + readyTimeout: 20000, + keepaliveInterval: 15000, + keepaliveCountMax: 4, + tryKeyboard: true, + }); + c.on("keyboard-interactive", (_n, _i, _l, prompts, finish) => finish(prompts.map(() => ssh.password))); + }); +} + +/** Run a command; resolves { code, stdout, stderr } (both truncated to the tail). */ +export function exec(client, command, { timeoutSec = 600 } = {}) { + return new Promise((resolve, reject) => { + client.exec(command, (err, stream) => { + if (err) return reject(err); + let out = ""; + let errOut = ""; + let done = false; + const timer = setTimeout(() => { + if (done) return; + done = true; + try { + stream.close(); + } catch { + /* ignore */ + } + resolve({ code: null, timedOut: true, stdout: tail(out), stderr: tail(errOut) }); + }, timeoutSec * 1000); + stream.on("data", (d) => { + out = keepTail(out + d.toString("utf8")); + }); + stream.stderr.on("data", (d) => { + errOut = keepTail(errOut + d.toString("utf8")); + }); + stream.on("close", (code) => { + if (done) return; + done = true; + clearTimeout(timer); + resolve({ code, timedOut: false, stdout: tail(out), stderr: tail(errOut) }); + }); + }); + }); +} + +function keepTail(s) { + return s.length > MAX_OUTPUT * 2 ? s.slice(-MAX_OUTPUT * 2) : s; +} + +function tail(s) { + return s.length > MAX_OUTPUT ? "…(earlier output cut)…\n" + s.slice(-MAX_OUTPUT) : s; +} + +function sftpOf(client) { + return new Promise((resolve, reject) => client.sftp((err, sftp) => (err ? reject(err) : resolve(sftp)))); +} + +const p = (fn) => + new Promise((resolve, reject) => fn((err, v) => (err ? reject(err) : resolve(v)))); + +async function mkdirp(sftp, dir) { + const parts = dir.split("/").filter(Boolean); + let cur = dir.startsWith("/") ? "" : "."; + for (const part of parts) { + cur = `${cur}/${part}`; + try { + await p((cb) => sftp.stat(cur, cb)); + } catch { + await p((cb) => sftp.mkdir(cur, cb)).catch(() => {}); + } + } +} + +/** Upload a local file or directory. Returns { files, bytes }. */ +export async function upload(client, localPath, remotePath) { + const sftp = await sftpOf(client); + try { + const st = fs.statSync(localPath); + let files = 0; + let bytes = 0; + const put = async (src, dst) => { + await mkdirp(sftp, path.posix.dirname(dst)); + await p((cb) => sftp.fastPut(src, dst, cb)); + files += 1; + bytes += fs.statSync(src).size; + }; + if (st.isDirectory()) { + const walk = async (dir, rel) => { + for (const ent of fs.readdirSync(dir, { withFileTypes: true })) { + if (ent.name === "node_modules" || ent.name === ".git" || ent.name === "__pycache__") continue; + const src = path.join(dir, ent.name); + const dst = path.posix.join(remotePath, rel, ent.name); + if (ent.isDirectory()) await walk(src, path.posix.join(rel, ent.name)); + else if (ent.isFile()) await put(src, dst); + } + }; + await mkdirp(sftp, remotePath); + await walk(localPath, ""); + } else { + await put(localPath, remotePath.endsWith("/") ? path.posix.join(remotePath, path.basename(localPath)) : remotePath); + } + return { files, bytes }; + } finally { + sftp.end(); + } +} + +/** Download a remote file or directory. Returns { files: [{path, bytes}], bytes }. */ +export async function download(client, remotePath, localPath) { + const sftp = await sftpOf(client); + try { + const st = await p((cb) => sftp.stat(remotePath, cb)); + const files = []; + let bytes = 0; + const get = async (src, dst, size) => { + fs.mkdirSync(path.dirname(dst), { recursive: true }); + await p((cb) => sftp.fastGet(src, dst, cb)); + files.push({ path: dst, bytes: size }); + bytes += size; + }; + if (st.isDirectory()) { + const walk = async (dir, rel) => { + const list = await p((cb) => sftp.readdir(dir, cb)); + for (const ent of list) { + const src = path.posix.join(dir, ent.filename); + const dst = path.join(localPath, rel, ent.filename); + if (ent.attrs.isDirectory()) await walk(src, path.join(rel, ent.filename)); + else if (ent.attrs.isFile()) await get(src, dst, ent.attrs.size); + } + }; + fs.mkdirSync(localPath, { recursive: true }); + await walk(remotePath, ""); + } else { + let dst = localPath; + if (fs.existsSync(localPath) && fs.statSync(localPath).isDirectory()) { + dst = path.join(localPath, path.posix.basename(remotePath)); + } + await get(remotePath, dst, st.size); + } + return { files, bytes }; + } finally { + sftp.end(); + } +} + +/** Write a small text file on the instance. */ +export async function writeFile(client, remotePath, content) { + const sftp = await sftpOf(client); + try { + await mkdirp(sftp, path.posix.dirname(remotePath)); + await p((cb) => sftp.writeFile(remotePath, content, { mode: 0o700 }, cb)); + } finally { + sftp.end(); + } +} diff --git a/mcp-server/test/guards.test.js b/mcp-server/test/guards.test.js new file mode 100644 index 0000000..2f208d0 --- /dev/null +++ b/mcp-server/test/guards.test.js @@ -0,0 +1,36 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { checkCommand, sensitiveReason, redact, publicInstance, Quotes } from "../src/guards.js"; + +test("blocks commands that would lock the platform out", () => { + for (const c of ["passwd root", "echo 'root:x' | chpasswd", "sed -i 's/yes/no/' /etc/ssh/sshd_config", + "systemctl stop sshd", "pkill -f cgpu-watchdog", "kill -9 -1", "iptables -F", "pkill -9 bash"]) { + assert.ok(checkCommand(c), c); + } + for (const c of ["python train.py", "pip install torch", "nvidia-smi", "kill 1234", "pkill -f train.py", "ls ~/.ssh"]) { + assert.equal(checkCommand(c), null, c); + } +}); + +test("refuses credential uploads by default", () => { + assert.ok(sensitiveReason("~/.ssh/id_ed25519")); + assert.ok(sensitiveReason("./.env")); + assert.ok(sensitiveReason("~")); + assert.equal(sensitiveReason("./data/train.jsonl"), null); +}); + +test("redacts secrets and hides ssh details", () => { + assert.equal(redact("pw hunter22 at 1.2.3.4 key sk-abcdefghijklmnopqrstu", ["hunter22", "1.2.3.4"]), + "pw [redacted] at [redacted] key sk-[redacted]"); + const p = publicInstance({ id: "1", status: "running", ssh: { host: "1.2.3.4", port: 22, user: "root", password: "x" } }); + assert.equal(p.ssh, undefined); + assert.equal(p.ssh_ready, true); + assert.ok(!JSON.stringify(p).includes("1.2.3.4")); +}); + +test("quotes are single use and expire", () => { + const q = new Quotes(50); + const id = q.put({ gpu_model: "RTX 4090" }); + assert.ok(q.take(id).quote); + assert.ok(q.take(id).error); +}); From b2405438824367d5cb2395a3b8d23932a4024184 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 26 Oct 2026 22:02:14 +0000 Subject: [PATCH 3/4] mcp-server: clearer results for instances the platform already stopped; PyTorch and no-GPU guidance in the agent rules Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0186WCw6KmBtLrDY6Pb4HLxY --- mcp-server/rules/cloudgpu.md | 4 +++- mcp-server/src/index.js | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mcp-server/rules/cloudgpu.md b/mcp-server/rules/cloudgpu.md index e090834..63a98cb 100644 --- a/mcp-server/rules/cloudgpu.md +++ b/mcp-server/rules/cloudgpu.md @@ -26,7 +26,9 @@ Copy this file into your project as `AGENTS.md`, `.cursor/rules/cloudgpu.md`, `. - Put code and data on the instance with `upload`. Do not upload credentials. - Use `run_command` for short steps. For training, long installs or big downloads, use `background=true` and follow progress with `tail_logs`. -- Instances come with Python and CUDA. Check with `python -c "import torch; print(torch.__version__, torch.cuda.is_available())"` and install the PyTorch build you need if it is missing. +- Instances come with Python and CUDA, but not always PyTorch. Check first: `nvidia-smi -L` and `python -c "import torch; print(torch.__version__, torch.cuda.is_available())"`. +- If PyTorch is missing, plain `pip install torch` installs a current CUDA build. It is a few GB, so run it with `background=true`. Index URLs for older CUDA versions (for example `.../whl/cu124`) may have no wheel for the machine's Python, which can be as new as 3.14. Only use them if the project needs that CUDA version, and then create an environment with an older Python first (`conda create -y -n work python=3.12`, then `conda activate work && ...` in each command). +- If `nvidia-smi` shows no GPU a few minutes after start, stop and tell the user. CloudGPU detects such machines, shuts them down and refunds them automatically. - **Do not** change the root password, edit the SSH configuration, change the firewall, or stop the platform's monitoring agent (`cgpu-*` processes). The platform must keep its access to the instance; if that access is lost, the platform shuts the instance down. The MCP server refuses such commands. - Never use the GPU for cryptocurrency mining or anything the [acceptable use policy](https://cloudgpu.app/aup) forbids. Instances that do so are shut down. diff --git a/mcp-server/src/index.js b/mcp-server/src/index.js index 55bc377..b3d4052 100644 --- a/mcp-server/src/index.js +++ b/mcp-server/src/index.js @@ -95,7 +95,13 @@ async function connectTo(id) { if (inst.status !== "running") { throw new Error( `Instance ${id} is ${inst.status}` + - (inst.status === "creating" ? "; wait for it with get_status (usually about 2 minutes)." : "."), + (inst.status === "creating" + ? "; wait for it with get_status (usually about 2 minutes)." + : inst.failure_reason + ? `: ${inst.failure_reason}` + : inst.limits && inst.limits.stopped_by + ? ` (stopped by its ${inst.limits.stopped_by} limit).` + : "."), ); } if (!inst.ssh || !inst.ssh.host) throw new Error(`Instance ${id} has no SSH access yet; try get_status again shortly.`); @@ -506,6 +512,14 @@ if (!cfg.readOnly) { session.delete(instance_id); return ok({ ...publicInstance(inst), note: "Destroyed. Billing has stopped." }); } catch (err) { + if (err instanceof ApiError && err.code === "cannot_destroy") { + // 已经停了(限额到线、余额用完、开出来没 GPU 被平台退款):告诉助手结果,而不是报错 + const inst = await api.instance(instance_id).catch(() => null); + if (inst && inst.status !== "running") { + session.delete(instance_id); + return ok({ ...publicInstance(inst), note: "Already stopped; nothing more to do. Billing has stopped." }); + } + } if (err instanceof ApiError && err.code === "instance_provisioning") { return fail("The instance is still starting and cannot be destroyed yet. Wait for get_status to show running (or failed; failed instances are not charged), then call stop_instance again."); } From 01db4d6b7d766ee96034bfd0e88e940a333183ce Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 27 Oct 2026 14:13:24 +0000 Subject: [PATCH 4/4] MCP server moved to its own repo (mrhy7176/cloudgpu-mcp, on npm as cloudgpu-mcp); link there instead of a copy Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0186WCw6KmBtLrDY6Pb4HLxY --- README.md | 4 +- mcp-server/.gitignore | 3 - mcp-server/LICENSE | 21 - mcp-server/README.md | 132 ---- mcp-server/package-lock.json | 1299 -------------------------------- mcp-server/package.json | 48 -- mcp-server/rules/cloudgpu.md | 45 -- mcp-server/src/api.js | 99 --- mcp-server/src/guards.js | 118 --- mcp-server/src/index.js | 571 -------------- mcp-server/src/ssh.js | 233 ------ mcp-server/test/guards.test.js | 36 - 12 files changed, 2 insertions(+), 2607 deletions(-) delete mode 100644 mcp-server/.gitignore delete mode 100644 mcp-server/LICENSE delete mode 100644 mcp-server/README.md delete mode 100644 mcp-server/package-lock.json delete mode 100644 mcp-server/package.json delete mode 100644 mcp-server/rules/cloudgpu.md delete mode 100644 mcp-server/src/api.js delete mode 100644 mcp-server/src/guards.js delete mode 100644 mcp-server/src/index.js delete mode 100644 mcp-server/src/ssh.js delete mode 100644 mcp-server/test/guards.test.js diff --git a/README.md b/README.md index 739fda1..13e4d48 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ Everything here runs against the public endpoint `https://cloudgpu.app/v1`. It i ## Let your AI coding assistant rent the GPU -[`mcp-server/`](mcp-server/README.md) is an MCP server for Cursor, Cline, opencode, Claude Code, VS Code and other MCP clients. Ask the assistant to fine-tune or run something on a GPU, and it quotes the price, rents a GPU once you agree, runs the job, downloads the results and shuts the GPU down. CloudGPU's servers enforce a budget and time limit on every instance it rents. +[cloudgpu-mcp](https://github.com/mrhy7176/cloudgpu-mcp) is an MCP server for Cursor, Cline, opencode, Claude Code, VS Code and other MCP clients. Ask the assistant to fine-tune or run something on a GPU, and it quotes the price, rents a GPU once you agree, runs the job, downloads the results and shuts the GPU down. CloudGPU's servers enforce a budget and time limit on every instance it rents. ```bash -claude mcp add cloudgpu --env CLOUDGPU_API_KEY=cgw-sk-... -- npx -y https://cloudgpu.app/mcp/cloudgpu-mcp-0.1.0.tgz +claude mcp add cloudgpu --env CLOUDGPU_API_KEY=cgw-sk-... -- npx -y cloudgpu-mcp ``` Setup for every client: https://cloudgpu.app/docs/mcp diff --git a/mcp-server/.gitignore b/mcp-server/.gitignore deleted file mode 100644 index 53a89d1..0000000 --- a/mcp-server/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules/ -*.log -.env diff --git a/mcp-server/LICENSE b/mcp-server/LICENSE deleted file mode 100644 index b321e3c..0000000 --- a/mcp-server/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2026 CloudGPU.app - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/mcp-server/README.md b/mcp-server/README.md deleted file mode 100644 index 17fd056..0000000 --- a/mcp-server/README.md +++ /dev/null @@ -1,132 +0,0 @@ -# CloudGPU MCP server - -Let your AI coding assistant rent a GPU on [CloudGPU](https://cloudgpu.app), run a job, bring the results back and shut the GPU down. - -> "Fine-tune Qwen2.5-7B with LoRA on data/train.jsonl on a 4090 and put the adapter in ./outputs." - -The assistant checks live prices and quotes you, rents the GPU once you say yes, uploads your code and data, starts training in the background, watches the logs, downloads the adapter and destroys the instance. You get the files and the final cost. - -Works with any MCP client that can start a local server: **Cursor, Cline, opencode, Claude Code, VS Code, Windsurf, Continue, Claude Desktop**. - -## Install - -1. Create an API key at [cloudgpu.app/api](https://cloudgpu.app/api). The same key and balance also cover the OpenAI-compatible [model API](https://cloudgpu.app/api/docs). -2. Add the server to your client (Node.js 18+). - -
-Cursor / Windsurf / Cline / Claude Desktop - -```json -{ - "mcpServers": { - "cloudgpu": { - "command": "npx", - "args": ["-y", "https://cloudgpu.app/mcp/cloudgpu-mcp-0.1.0.tgz"], - "env": { "CLOUDGPU_API_KEY": "cgw-sk-..." } - } - } -} -``` -Cursor: `~/.cursor/mcp.json` · Cline: MCP Servers → Configure · Claude Desktop: `claude_desktop_config.json` -
- -
-Claude Code - -```bash -claude mcp add cloudgpu --env CLOUDGPU_API_KEY=cgw-sk-... -- npx -y https://cloudgpu.app/mcp/cloudgpu-mcp-0.1.0.tgz -``` -
- -
-opencode (opencode.json) - -```json -{ - "mcp": { - "cloudgpu": { - "type": "local", - "command": ["npx", "-y", "https://cloudgpu.app/mcp/cloudgpu-mcp-0.1.0.tgz"], - "environment": { "CLOUDGPU_API_KEY": "cgw-sk-..." } - } - } -} -``` -
- -
-VS Code (.vscode/mcp.json) - -```json -{ - "servers": { - "cloudgpu": { - "command": "npx", - "args": ["-y", "https://cloudgpu.app/mcp/cloudgpu-mcp-0.1.0.tgz"], - "env": { "CLOUDGPU_API_KEY": "cgw-sk-..." } - } - } -} -``` -
- -3. Optional but recommended: copy [`rules/cloudgpu.md`](rules/cloudgpu.md) into your project as `AGENTS.md`, `.cursor/rules/cloudgpu.md`, `.clinerules/cloudgpu.md` or `CLAUDE.md`. It tells the assistant to quote before renting, download before shutting down, and never leave a GPU running. - -## Tools - -| Tool | What it does | -|---|---| -| `get_account` | Balance, and how many instances the account may run at once | -| `list_gpus` | GPU models with VRAM, live price per GPU-hour and availability | -| `list_templates` | Ready-made images: JupyterLab, Ollama, ComfyUI, LLaMA-Factory, … | -| `estimate_cost` | Live quote for a GPU and a number of hours, plus your balance afterwards; returns a `quote_id` | -| `create_instance` | Rents from an approved quote, with a budget, a time limit and an idle limit | -| `get_status` / `list_instances` | Status, minutes run, cost so far, auto-shutdown limits | -| `run_command` | Runs a command on the instance; `background=true` for long jobs | -| `tail_logs` | Latest log lines, whether the job finished, GPU utilisation | -| `upload` / `download` | Files and folders between your computer and the instance (SFTP) | -| `stop_instance` | Destroys the instance and stops billing | -| `list_models` | Models on the OpenAI-compatible API, for inference without renting a GPU | - -The server also provides the rules as a resource (`cloudgpu://rules`) and a `train_on_cloudgpu` prompt. - -## Guardrails - -- **A quote first.** `create_instance` only takes a `quote_id` from `estimate_cost` and `user_confirmed=true`. -- **Server-side limits.** Every instance is created with `max_spend_usd`, `max_hours` and an idle limit (60 minutes by default). CloudGPU's servers check them every minute and destroy the instance when one is hit, even if your client has disconnected or your laptop is asleep. -- **Your own ceiling.** `CLOUDGPU_MAX_SPEND_USD` (default 50) and `CLOUDGPU_MAX_HOURS` (default 24) cap what the assistant may set. -- **Results before shutdown.** After commands have run, `stop_instance` refuses until something has been downloaded, unless the user confirms `force=true`. -- **Secrets stay out of the chat.** The instance's SSH login is used inside this process and never returned to the model. Tool output is scrubbed of the API key and login details. Uploading `.ssh`, `.env`, key files or your whole home directory needs `allow_sensitive=true`. -- **The instance stays manageable.** Commands that change the root password, SSH configuration, firewall or the platform's monitoring agent are refused. CloudGPU shuts down instances that it can no longer monitor. -- **Read-only mode.** `CLOUDGPU_READ_ONLY=1` registers only the look-up tools. - -## Configuration - -| Env | Default | | -|---|---|---| -| `CLOUDGPU_API_KEY` | (required) | From https://cloudgpu.app/api | -| `CLOUDGPU_MAX_SPEND_USD` | `50` | Highest budget the assistant may set for one instance | -| `CLOUDGPU_MAX_HOURS` | `24` | Longest time limit the assistant may set | -| `CLOUDGPU_READ_ONLY` | off | `1` = look-up tools only | - -## Without MCP - -The server wraps the public REST API, which any agent or script can call with the same key: - -```bash -curl https://cloudgpu.app/v1/gpu/offers -H "Authorization: Bearer $CLOUDGPU_API_KEY" - -curl -X POST https://cloudgpu.app/v1/gpu/instances \ - -H "Authorization: Bearer $CLOUDGPU_API_KEY" -H "Content-Type: application/json" \ - -d '{"gpu_model":"RTX 4090","max_minutes":120,"max_spend_usd":2,"idle_minutes":30}' -``` - -Reference: [cloudgpu.app/api/docs](https://cloudgpu.app/api/docs#gpu) · OpenAPI: [cloudgpu.app/openapi.json](https://cloudgpu.app/openapi.json) · For LLMs: [cloudgpu.app/llms.txt](https://cloudgpu.app/llms.txt) - -## Billing - -Prepaid USD balance, GPUs billed per minute; top up at [cloudgpu.app/billing](https://cloudgpu.app/billing). When the balance runs out, running instances are destroyed and their disks erased, so keep enough balance for the job and download results as you go. - -## License - -MIT diff --git a/mcp-server/package-lock.json b/mcp-server/package-lock.json deleted file mode 100644 index 6e26b06..0000000 --- a/mcp-server/package-lock.json +++ /dev/null @@ -1,1299 +0,0 @@ -{ - "name": "cloudgpu-mcp", - "version": "0.1.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "cloudgpu-mcp", - "version": "0.1.0", - "license": "MIT", - "dependencies": { - "@modelcontextprotocol/sdk": "^1.32.2", - "ssh2": "^1.17.0", - "zod": "^3.25.0" - }, - "bin": { - "cloudgpu-mcp": "src/index.js" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/@hono/node-server": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.1.5.tgz", - "integrity": "sha512-MgP/I06GdvsilDspMk/qmRzpk8LOUStP6jFAbSRi40W09DhoyUn+Mj7eyKICPqeYKybOjVFLVIAQzvu1bfIa7Q==", - "license": "MIT", - "engines": { - "node": ">=20" - }, - "peerDependencies": { - "hono": "^4 || ^5.0.0-0" - } - }, - "node_modules/@modelcontextprotocol/sdk": { - "version": "1.32.2", - "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.32.2.tgz", - "integrity": "sha512-SWsVtH/0vULSQStoZ6xxH2K09Li8fXYTMC64ZeogCdpZ3XSi1eCPOByV1OpuJxuI3OcmHhosDWYyii07tpPsLw==", - "license": "MIT", - "dependencies": { - "@hono/node-server": "^1.19.9 || ^2.0.5", - "ajv": "^8.17.1", - "ajv-formats": "^3.0.1", - "content-type": "^1.0.5", - "cors": "^2.8.5", - "cross-spawn": "^7.0.5", - "eventsource": "^3.0.2", - "eventsource-parser": "^3.0.0", - "express": "^5.2.1", - "express-rate-limit": "^8.2.1", - "hono": "^4.11.4", - "jose": "^6.1.3", - "json-schema-typed": "^8.0.2", - "pkce-challenge": "^5.0.0", - "raw-body": "^3.0.0", - "zod": "^3.25 || ^4.0", - "zod-to-json-schema": "^3.25.1" - }, - "engines": { - "node": ">=18" - }, - "peerDependencies": { - "@cfworker/json-schema": "^4.1.1", - "zod": "^3.25 || ^4.0" - }, - "peerDependenciesMeta": { - "@cfworker/json-schema": { - "optional": true - }, - "zod": { - "optional": false - } - } - }, - "node_modules/accepts": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", - "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", - "license": "MIT", - "dependencies": { - "mime-types": "^3.0.0", - "negotiator": "^1.0.0" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/ajv": { - "version": "8.20.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", - "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", - "license": "MIT", - "dependencies": { - "fast-deep-equal": "^3.1.3", - "fast-uri": "^3.0.1", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/ajv-formats": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", - "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", - "license": "MIT", - "dependencies": { - "ajv": "^8.0.0" - }, - "peerDependencies": { - "ajv": "^8.0.0" - }, - "peerDependenciesMeta": { - "ajv": { - "optional": true - } - } - }, - "node_modules/asn1": { - "version": "0.2.6", - "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz", - "integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==", - "license": "MIT", - "dependencies": { - "safer-buffer": "~2.1.0" - } - }, - "node_modules/bcrypt-pbkdf": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", - "integrity": "sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==", - "license": "BSD-3-Clause", - "dependencies": { - "tweetnacl": "^0.14.3" - } - }, - "node_modules/body-parser": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.4.0.tgz", - "integrity": "sha512-Ifk1KcLrxaGt1occQagQNFNNOqRt1LFuehEnHHzB8Z6cRgIxRU1TBaiIsUiCdA+gy5PL7Y1IX31DNKkRmxtXjQ==", - "license": "MIT", - "dependencies": { - "bytes": "^3.1.2", - "content-type": "^2.1.0", - "debug": "^4.4.3", - "http-errors": "^2.0.1", - "iconv-lite": "^0.7.3", - "on-finished": "^2.4.1", - "qs": "^6.16.1", - "raw-body": "^3.0.2", - "type-is": "^2.1.0" - }, - "engines": { - "node": ">=18" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/body-parser/node_modules/content-type": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", - "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/buildcheck": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/buildcheck/-/buildcheck-0.0.7.tgz", - "integrity": "sha512-lHblz4ahamxpTmnsk+MNTRWsjYKv965MwOrSJyeD588rR3Jcu7swE+0wN5F+PbL5cjgu/9ObkhfzEPuofEMwLA==", - "optional": true, - "engines": { - "node": ">=10.0.0" - } - }, - "node_modules/bytes": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", - "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/call-bind-apply-helpers": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", - "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "function-bind": "^1.1.2" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/call-bound": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", - "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", - "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.2", - "get-intrinsic": "^1.3.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/content-disposition": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-2.0.1.tgz", - "integrity": "sha512-e+H0ZXHSWYrENhQzw1LPuP4oF5MzVKmDU6d3hxlvaPEYLLg62MxtQNPRx4SYSuYJSBUgnQIG4HIN2tEtNv7Dog==", - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/content-type": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", - "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/cookie": { - "version": "0.7.2", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", - "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/cookie-signature": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", - "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", - "license": "MIT", - "engines": { - "node": ">=6.6.0" - } - }, - "node_modules/cors": { - "version": "2.8.6", - "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", - "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", - "license": "MIT", - "dependencies": { - "object-assign": "^4", - "vary": "^1" - }, - "engines": { - "node": ">= 0.10" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/cpu-features": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/cpu-features/-/cpu-features-0.0.10.tgz", - "integrity": "sha512-9IkYqtX3YHPCzoVg1Py+o9057a3i0fp7S530UWokCSaFVTc7CwXPRiOjRjBQQ18ZCNafx78YfnG+HALxtVmOGA==", - "hasInstallScript": true, - "optional": true, - "dependencies": { - "buildcheck": "~0.0.6", - "nan": "^2.19.0" - }, - "engines": { - "node": ">=10.0.0" - } - }, - "node_modules/cross-spawn": { - "version": "7.0.6", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", - "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", - "license": "MIT", - "dependencies": { - "path-key": "^3.1.0", - "shebang-command": "^2.0.0", - "which": "^2.0.1" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/debug": { - "version": "4.4.3", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", - "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", - "license": "MIT", - "dependencies": { - "ms": "^2.1.3" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/depd": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", - "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/dunder-proto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", - "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", - "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.1", - "es-errors": "^1.3.0", - "gopd": "^1.2.0" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/ee-first": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", - "license": "MIT" - }, - "node_modules/encodeurl": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", - "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/es-define-property": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", - "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-errors": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", - "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-object-atoms": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", - "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/escape-html": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", - "license": "MIT" - }, - "node_modules/etag": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", - "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/eventsource": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.7.tgz", - "integrity": "sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA==", - "license": "MIT", - "dependencies": { - "eventsource-parser": "^3.0.1" - }, - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/eventsource-parser": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.1.1.tgz", - "integrity": "sha512-EKN1vKAMcZ8MlYMpaNuxN6R9yakzH6uajHcHVTqWJzvu5pWw9DyhbP35HH8MVBQ+dZjAfDxk+A8NiR9KWaXiyQ==", - "license": "MIT", - "engines": { - "node": ">=18.0.0" - } - }, - "node_modules/express": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/express/-/express-5.3.0.tgz", - "integrity": "sha512-qCqy1xSoaugxOD4IVHb1ZWdkvCF2W3aE2okKouWj8VwJ+ztskSiXoBnCSJqfKT+cVPJhuJqe9YLbY425+Zh00g==", - "license": "MIT", - "dependencies": { - "accepts": "^2.0.0", - "body-parser": "^2.3.0", - "content-disposition": "^2.0.1", - "content-type": "^2.0.0", - "cookie": "^0.7.1", - "cookie-signature": "^1.2.1", - "debug": "^4.4.0", - "depd": "^2.0.0", - "encodeurl": "^2.0.0", - "escape-html": "^1.0.3", - "etag": "^1.8.1", - "finalhandler": "^2.1.0", - "fresh": "^2.0.0", - "http-errors": "^2.0.0", - "merge-descriptors": "^2.0.0", - "mime-types": "^3.0.0", - "on-finished": "^2.4.1", - "once": "^1.4.0", - "parseurl": "^1.3.3", - "proxy-addr": "^2.0.8", - "qs": "^6.16.0", - "range-parser": "^1.2.1", - "router": "^2.2.0", - "send": "^1.1.0", - "serve-static": "^2.2.0", - "statuses": "^2.0.1", - "type-is": "^2.1.0", - "vary": "^1.1.2" - }, - "engines": { - "node": ">= 18" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/express-rate-limit": { - "version": "8.7.1", - "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.7.1.tgz", - "integrity": "sha512-2FXbqkygil3mZiXzEtM0IjE/UBmBNot0J1GEVrJT4JbrvwOSoEtqtO+wHbiMQELWe1eNvHoYRg2dkjOid+6JkA==", - "license": "MIT", - "dependencies": { - "debug": "^4.4.3", - "ip-address": "^10.2.0" - }, - "engines": { - "node": ">= 16" - }, - "funding": { - "url": "https://github.com/sponsors/express-rate-limit" - }, - "peerDependencies": { - "express": ">= 4.11" - } - }, - "node_modules/express/node_modules/content-type": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", - "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/fast-deep-equal": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "license": "MIT" - }, - "node_modules/fast-uri": { - "version": "3.1.9", - "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.9.tgz", - "integrity": "sha512-hS/0Wt3Ya043oKXs0sIxrMpKQITXhMLIrVAKKXi4gozGC9v7YRWVnXIZzjNPTO02M9BdxLCWqK1yRXgNziVyJQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/fastify" - }, - { - "type": "opencollective", - "url": "https://opencollective.com/fastify" - } - ], - "license": "BSD-3-Clause" - }, - "node_modules/finalhandler": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", - "integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==", - "license": "MIT", - "dependencies": { - "debug": "^4.4.0", - "encodeurl": "^2.0.0", - "escape-html": "^1.0.3", - "on-finished": "^2.4.1", - "parseurl": "^1.3.3", - "statuses": "^2.0.1" - }, - "engines": { - "node": ">= 18.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/forwarded": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", - "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/fresh": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", - "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/function-bind": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", - "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/get-intrinsic": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", - "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", - "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.2", - "es-define-property": "^1.0.1", - "es-errors": "^1.3.0", - "es-object-atoms": "^1.1.1", - "function-bind": "^1.1.2", - "get-proto": "^1.0.1", - "gopd": "^1.2.0", - "has-symbols": "^1.1.0", - "hasown": "^2.0.2", - "math-intrinsics": "^1.1.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/get-proto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", - "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", - "license": "MIT", - "dependencies": { - "dunder-proto": "^1.0.1", - "es-object-atoms": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/gopd": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", - "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-symbols": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", - "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/hasown": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", - "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", - "license": "MIT", - "dependencies": { - "function-bind": "^1.1.2" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/hono": { - "version": "4.13.14", - "resolved": "https://registry.npmjs.org/hono/-/hono-4.13.14.tgz", - "integrity": "sha512-yhRLQ21U6qa9Hsu2N7Qcbh8tE+WKEcoErjIo56LeSGiGXGp9sA7UpE86Ui9uexb61KakiGwuHMn2QdV7w6i6kQ==", - "license": "MIT", - "engines": { - "node": ">=16.9.0" - } - }, - "node_modules/http-errors": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", - "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", - "license": "MIT", - "dependencies": { - "depd": "~2.0.0", - "inherits": "~2.0.4", - "setprototypeof": "~1.2.0", - "statuses": "~2.0.2", - "toidentifier": "~1.0.1" - }, - "engines": { - "node": ">= 0.8" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/iconv-lite": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.3.tgz", - "integrity": "sha512-IKXpvIzjnC9XTAUbVBcMfGS0EPaIXtW6v+zr+RRp+hqULEpo0owZax6wyRwPOJbWbzjYspQwusTsfVr0ifh4uQ==", - "license": "MIT", - "dependencies": { - "safer-buffer": ">= 2.1.2 < 3.0.0" - }, - "engines": { - "node": ">=0.10.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "license": "ISC" - }, - "node_modules/ip-address": { - "version": "10.7.5", - "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.5.tgz", - "integrity": "sha512-t2v0rkILYv9WXmSL7TpAaU3HXgaFYOPUcH3QHgwQ++gpJuH3bqyMy4Fvt/DJCTKwzH3Cf+bAp5W/mFL39KPLzA==", - "license": "MIT", - "engines": { - "node": ">= 12" - } - }, - "node_modules/ipaddr.js": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", - "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", - "license": "MIT", - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/is-promise": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", - "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", - "license": "MIT" - }, - "node_modules/isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", - "license": "ISC" - }, - "node_modules/jose": { - "version": "6.2.13", - "resolved": "https://registry.npmjs.org/jose/-/jose-6.2.13.tgz", - "integrity": "sha512-7TIg10ZE1x82YediN+lcrPNvGMKge9yFHQD+Qho/b8y2adfugU3AsvvHfxV0fzyFllT6l9xCjf4RWY9g/Z9PJQ==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/panva" - } - }, - "node_modules/json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "license": "MIT" - }, - "node_modules/json-schema-typed": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/json-schema-typed/-/json-schema-typed-8.0.2.tgz", - "integrity": "sha512-fQhoXdcvc3V28x7C7BMs4P5+kNlgUURe2jmUT1T//oBRMDrqy1QPelJimwZGo7Hg9VPV3EQV5Bnq4hbFy2vetA==", - "license": "BSD-2-Clause" - }, - "node_modules/math-intrinsics": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", - "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/media-typer": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.1.tgz", - "integrity": "sha512-yz3xRaG20c6/BOzvYoDaGtPmGscs7YivItZEEqe6GbwNfHuxu9YNmvnEkMzKldAGY4/80pRcQRZSEnhquk9XuQ==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/merge-descriptors": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", - "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/mime-db": { - "version": "1.54.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", - "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", - "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", - "license": "MIT", - "dependencies": { - "mime-db": "^1.54.0" - }, - "engines": { - "node": ">=18" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "license": "MIT" - }, - "node_modules/nan": { - "version": "2.30.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.30.0.tgz", - "integrity": "sha512-P5mokDkSvCGBz6mZDD/2l+w9QoICRXdCyZ9ONGmTePr40oihJg3Kpn0YU3twKd6PJnwSlLBWNQeOT6yWEV2c4A==", - "license": "MIT", - "optional": true - }, - "node_modules/negotiator": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.1.0.tgz", - "integrity": "sha512-NMPBRMJgiQHjbd8phG3Vebdx4kZ1H121rbl5IkMqeOsahptB9BKo/d7oJ3zTXqTgagn2bWlNSXkh0QUGM31RYg==", - "license": "MIT", - "dependencies": { - "content-type": "^2.1.0" - }, - "engines": { - "node": ">=18" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/negotiator/node_modules/content-type": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", - "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/object-inspect": { - "version": "1.13.4", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", - "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/on-finished": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.2.tgz", - "integrity": "sha512-ATWUv387i+nLD49EiDoOft5scf32Vsdz3ktrQJG9bi7jRFmaXTssvyvj1EmeKVVgvesbqUtvQQvaS2TpTukAZQ==", - "license": "MIT", - "dependencies": { - "ee-first": "1.1.1" - }, - "engines": { - "node": ">= 0.8" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "license": "ISC", - "dependencies": { - "wrappy": "1" - } - }, - "node_modules/parseurl": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", - "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/path-key": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", - "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/path-to-regexp": { - "version": "8.4.2", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz", - "integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==", - "license": "MIT", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/pkce-challenge": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/pkce-challenge/-/pkce-challenge-5.0.1.tgz", - "integrity": "sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ==", - "license": "MIT", - "engines": { - "node": ">=16.20.0" - } - }, - "node_modules/proxy-addr": { - "version": "2.0.8", - "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz", - "integrity": "sha512-5nnx0yGyVUcY6t9RnWcARWtwT9F1D8O9rt08htPvnd49W1IgZtmLkhu9WfMzQj1cFxjHIO6connUNVW5k7AVyQ==", - "license": "MIT", - "dependencies": { - "forwarded": "0.2.0", - "ipaddr.js": "1.9.1" - }, - "engines": { - "node": ">= 0.10" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/qs": { - "version": "6.16.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.1.tgz", - "integrity": "sha512-5Px6J7rfHBAGUhNQ3es4YzcOdBBw0SDcVtThJml4RdnKw4tKs2epA0kPZ+K8X+WiHktT93RHVcQ/3ym5aTCgtg==", - "license": "BSD-3-Clause", - "dependencies": { - "es-define-property": "^1.0.1", - "side-channel": "^1.1.1" - }, - "engines": { - "node": ">=0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/range-parser": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.3.0.tgz", - "integrity": "sha512-hek2mFQpPuI4E1BBKrSto+BU3e3x4xuarsbiwr3+lf7p44juvFMV0XFWQAP3xUyqXA4RrXLIoaSUGbSt056ZMw==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/raw-body": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", - "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", - "license": "MIT", - "dependencies": { - "bytes": "~3.1.2", - "http-errors": "~2.0.1", - "iconv-lite": "~0.7.0", - "unpipe": "~1.0.0" - }, - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/require-from-string": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", - "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/router": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", - "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", - "license": "MIT", - "dependencies": { - "debug": "^4.4.0", - "depd": "^2.0.0", - "is-promise": "^4.0.0", - "parseurl": "^1.3.3", - "path-to-regexp": "^8.0.0" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/safer-buffer": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "license": "MIT" - }, - "node_modules/send": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", - "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", - "license": "MIT", - "dependencies": { - "debug": "^4.4.3", - "encodeurl": "^2.0.0", - "escape-html": "^1.0.3", - "etag": "^1.8.1", - "fresh": "^2.0.0", - "http-errors": "^2.0.1", - "mime-types": "^3.0.2", - "ms": "^2.1.3", - "on-finished": "^2.4.1", - "range-parser": "^1.2.1", - "statuses": "^2.0.2" - }, - "engines": { - "node": ">= 18" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/serve-static": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz", - "integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==", - "license": "MIT", - "dependencies": { - "encodeurl": "^2.0.0", - "escape-html": "^1.0.3", - "parseurl": "^1.3.3", - "send": "^1.2.0" - }, - "engines": { - "node": ">= 18" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/setprototypeof": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", - "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", - "license": "ISC" - }, - "node_modules/shebang-command": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", - "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", - "license": "MIT", - "dependencies": { - "shebang-regex": "^3.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/shebang-regex": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", - "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/side-channel": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz", - "integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "object-inspect": "^1.13.4", - "side-channel-list": "^1.0.1", - "side-channel-map": "^1.0.1", - "side-channel-weakmap": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/side-channel-list": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", - "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "object-inspect": "^1.13.4" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/side-channel-map": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", - "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", - "license": "MIT", - "dependencies": { - "call-bound": "^1.0.2", - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.5", - "object-inspect": "^1.13.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/side-channel-weakmap": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", - "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", - "license": "MIT", - "dependencies": { - "call-bound": "^1.0.2", - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.5", - "object-inspect": "^1.13.3", - "side-channel-map": "^1.0.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/ssh2": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/ssh2/-/ssh2-1.17.0.tgz", - "integrity": "sha512-wPldCk3asibAjQ/kziWQQt1Wh3PgDFpC0XpwclzKcdT1vql6KeYxf5LIt4nlFkUeR8WuphYMKqUA56X4rjbfgQ==", - "hasInstallScript": true, - "dependencies": { - "asn1": "^0.2.6", - "bcrypt-pbkdf": "^1.0.2" - }, - "engines": { - "node": ">=10.16.0" - }, - "optionalDependencies": { - "cpu-features": "~0.0.10", - "nan": "^2.23.0" - } - }, - "node_modules/statuses": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", - "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/toidentifier": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", - "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", - "license": "MIT", - "engines": { - "node": ">=0.6" - } - }, - "node_modules/tweetnacl": { - "version": "0.14.5", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "integrity": "sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==", - "license": "Unlicense" - }, - "node_modules/type-is": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz", - "integrity": "sha512-faYHw0anBbc/kWF3zFTEnxSFOAGUX9GFbOBthvDdLsIlEoWOFOtS0zgCiQYwIskL9iGXZL3kAXD8OoZ4GmMATA==", - "license": "MIT", - "dependencies": { - "content-type": "^2.0.0", - "media-typer": "^1.1.0", - "mime-types": "^3.0.0" - }, - "engines": { - "node": ">= 18" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/type-is/node_modules/content-type": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", - "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/express" - } - }, - "node_modules/unpipe": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/vary": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", - "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", - "license": "MIT", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/which": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "license": "ISC", - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "node-which": "bin/node-which" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "license": "ISC" - }, - "node_modules/zod": { - "version": "3.25.76", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz", - "integrity": "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/colinhacks" - } - }, - "node_modules/zod-to-json-schema": { - "version": "3.25.2", - "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.25.2.tgz", - "integrity": "sha512-O/PgfnpT1xKSDeQYSCfRI5Gy3hPf91mKVDuYLUHZJMiDFptvP41MSnWofm8dnCm0256ZNfZIM7DSzuSMAFnjHA==", - "license": "ISC", - "peerDependencies": { - "zod": "^3.25.28 || ^4" - } - } - } -} diff --git a/mcp-server/package.json b/mcp-server/package.json deleted file mode 100644 index 0059f54..0000000 --- a/mcp-server/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "cloudgpu-mcp", - "version": "0.1.0", - "description": "MCP server for CloudGPU.app: let Cursor, Cline, opencode, Claude Code and other AI coding assistants rent a GPU, run a job, fetch the results and shut the GPU down, with spending limits the platform enforces.", - "type": "module", - "bin": { - "cloudgpu-mcp": "src/index.js" - }, - "main": "src/index.js", - "files": [ - "src", - "rules", - "README.md", - "LICENSE" - ], - "engines": { - "node": ">=18" - }, - "scripts": { - "test": "node --test test/*.test.js" - }, - "keywords": [ - "mcp", - "model-context-protocol", - "gpu", - "cloud-gpu", - "gpu-rental", - "cursor", - "cline", - "opencode", - "claude-code", - "fine-tuning", - "lora", - "cloudgpu" - ], - "homepage": "https://cloudgpu.app/docs/mcp", - "repository": { - "type": "git", - "url": "git+https://github.com/mrhy7176/cloudgpu-examples.git" - }, - "license": "MIT", - "author": "CloudGPU.app ", - "dependencies": { - "@modelcontextprotocol/sdk": "^1.32.2", - "ssh2": "^1.17.0", - "zod": "^3.25.0" - } -} diff --git a/mcp-server/rules/cloudgpu.md b/mcp-server/rules/cloudgpu.md deleted file mode 100644 index 63a98cb..0000000 --- a/mcp-server/rules/cloudgpu.md +++ /dev/null @@ -1,45 +0,0 @@ -# CloudGPU rules for AI assistants - -Use these rules whenever you rent or use a GPU on CloudGPU (cloudgpu.app) through the `cloudgpu` MCP tools. -Copy this file into your project as `AGENTS.md`, `.cursor/rules/cloudgpu.md`, `.clinerules/cloudgpu.md` or `CLAUDE.md` if your assistant reads one of those. - -## Before renting - -1. Call `get_account` and `list_gpus`. Pick a GPU with enough VRAM for the job, and don't rent more GPU than the job needs. As a rough guide, LoRA on a 7–8B model fits in 24 GB, and a full fine-tune of the same model needs 80 GB or more. -2. Call `estimate_cost` with a realistic number of hours. -3. Show the user a short quote before you rent anything: - - the GPU and how many, - - the price per hour, - - the estimated hours and cost, - - the budget and time limit you will set, - - their balance after the job. -4. Rent only after the user says yes. Pass `user_confirmed=true` only in that case. - -## Renting - -- Always set `max_spend_usd` and `max_hours`. CloudGPU's servers destroy the instance when either is reached, even if you have disconnected. -- Keep `idle_minutes` on (default 60). Raise it if setup will take long, because installing packages and downloading models leave the GPU idle. -- Poll `get_status` every 30–60 seconds until the instance is `running`. This usually takes about 2 minutes. -- `failed` instances are not charged. Tell the user, then offer another GPU. - -## Working on the instance - -- Put code and data on the instance with `upload`. Do not upload credentials. -- Use `run_command` for short steps. For training, long installs or big downloads, use `background=true` and follow progress with `tail_logs`. -- Instances come with Python and CUDA, but not always PyTorch. Check first: `nvidia-smi -L` and `python -c "import torch; print(torch.__version__, torch.cuda.is_available())"`. -- If PyTorch is missing, plain `pip install torch` installs a current CUDA build. It is a few GB, so run it with `background=true`. Index URLs for older CUDA versions (for example `.../whl/cu124`) may have no wheel for the machine's Python, which can be as new as 3.14. Only use them if the project needs that CUDA version, and then create an environment with an older Python first (`conda create -y -n work python=3.12`, then `conda activate work && ...` in each command). -- If `nvidia-smi` shows no GPU a few minutes after start, stop and tell the user. CloudGPU detects such machines, shuts them down and refunds them automatically. -- **Do not** change the root password, edit the SSH configuration, change the firewall, or stop the platform's monitoring agent (`cgpu-*` processes). The platform must keep its access to the instance; if that access is lost, the platform shuts the instance down. The MCP server refuses such commands. -- Never use the GPU for cryptocurrency mining or anything the [acceptable use policy](https://cloudgpu.app/aup) forbids. Instances that do so are shut down. - -## Finishing (always) - -1. Download every result: model weights, adapters, checkpoints, logs, metrics. Destroying an instance erases its disk, and CloudGPU has no persistent storage. -2. Call `stop_instance`. -3. Tell the user what ran, where the results are on their computer, and the final cost from `stop_instance`. - -If anything goes wrong mid-way, do not leave the instance running. Download whatever exists, stop the instance, then explain what happened. - -## Only need a model, not a GPU? - -The same API key works for CloudGPU's OpenAI-compatible model API at `https://cloudgpu.app/v1`. Call `list_models` to see the models. For inference on a hosted model this is usually quicker and cheaper than renting a GPU. diff --git a/mcp-server/src/api.js b/mcp-server/src/api.js deleted file mode 100644 index 0e081a4..0000000 --- a/mcp-server/src/api.js +++ /dev/null @@ -1,99 +0,0 @@ -// CloudGPU REST client. Talks only to the public API (https://cloudgpu.app/v1/...), -// with the user's own API key. Nothing here knows or needs anything that is not public. - -export class ApiError extends Error { - constructor(status, code, message) { - super(message); - this.status = status; - this.code = code; - } -} - -export class CloudGpuApi { - constructor({ apiKey, baseUrl = "https://cloudgpu.app", fetchImpl = globalThis.fetch } = {}) { - this.apiKey = apiKey; - this.baseUrl = baseUrl.replace(/\/+$/, ""); - this.fetch = fetchImpl; - } - - async request(method, path, body) { - if (!this.apiKey) { - throw new ApiError( - 401, - "missing_api_key", - "CLOUDGPU_API_KEY is not set. Create a key at https://cloudgpu.app/api and add it to this MCP server's env.", - ); - } - let lastErr; - // Retry only on network errors and 502/503/504; never on 4xx (a create must not run twice). - const attempts = method === "GET" ? 3 : 1; - for (let i = 0; i < attempts; i++) { - try { - const res = await this.fetch(this.baseUrl + path, { - method, - headers: { - Authorization: `Bearer ${this.apiKey}`, - "Content-Type": "application/json", - "User-Agent": "cloudgpu-mcp/0.1", - }, - body: body === undefined ? undefined : JSON.stringify(body), - }); - const text = await res.text(); - let json; - try { - json = text ? JSON.parse(text) : {}; - } catch { - json = null; - } - if (!res.ok) { - const e = json && json.error ? json.error : {}; - const err = new ApiError(res.status, e.code || `http_${res.status}`, e.message || `HTTP ${res.status}`); - if (method === "GET" && res.status >= 502 && res.status <= 504 && i < attempts - 1) { - lastErr = err; - await sleep(1000 * (i + 1)); - continue; - } - throw err; - } - if (json === null) { - throw new ApiError(res.status, "bad_response", "The server returned something that is not JSON."); - } - return json; - } catch (err) { - if (err instanceof ApiError) throw err; - lastErr = new ApiError(0, "network_error", `Could not reach ${this.baseUrl}: ${err.message}`); - if (i < attempts - 1) await sleep(1000 * (i + 1)); - } - } - throw lastErr; - } - - account() { - return this.request("GET", "/v1/gpu/account"); - } - offers() { - return this.request("GET", "/v1/gpu/offers").then((r) => r.data || []); - } - templates() { - return this.request("GET", "/v1/gpu/templates").then((r) => r.data || []); - } - instances() { - return this.request("GET", "/v1/gpu/instances").then((r) => r.data || []); - } - instance(id) { - return this.request("GET", `/v1/gpu/instances/${encodeURIComponent(id)}`); - } - create(body) { - return this.request("POST", "/v1/gpu/instances", body); - } - destroy(id) { - return this.request("DELETE", `/v1/gpu/instances/${encodeURIComponent(id)}`); - } - models() { - return this.request("GET", "/v1/models").then((r) => r.data || []); - } -} - -export function sleep(ms) { - return new Promise((r) => setTimeout(r, ms)); -} diff --git a/mcp-server/src/guards.js b/mcp-server/src/guards.js deleted file mode 100644 index 589937d..0000000 --- a/mcp-server/src/guards.js +++ /dev/null @@ -1,118 +0,0 @@ -// Guardrails that run on this machine, before anything reaches the API or the instance. -// The hard limits (auto-shutdown on time, budget and idle GPU) are enforced by CloudGPU's servers; -// these catch mistakes early and keep secrets out of the model's context. -import os from "node:os"; -import path from "node:path"; -import crypto from "node:crypto"; - -// ── Commands that would break the instance ─────────────────────────────────── -// -// Every CloudGPU instance runs a small platform monitoring agent, and the platform checks on it -// over SSH. Changing the root password, rewriting the SSH config or killing the agent locks that -// check out, and the platform then shuts the instance down. These patterns stop an assistant from -// doing that by accident (for example while "hardening" SSH or "cleaning up" processes). -const BLOCKED = [ - { re: /\b(passwd|chpasswd)\b/, why: "changes a login password" }, - { re: /\busermod\b[^\n]*\s-p\b/, why: "changes a login password" }, - { re: /sshd_config|\/etc\/ssh\//, why: "edits the SSH server configuration" }, - { re: /\b(systemctl|service)\s+(stop|disable|mask|restart)\s+(ssh|sshd)\b/, why: "stops the SSH server" }, - { re: /cgpu-(watchdog|agent)/, why: "touches the platform monitoring agent" }, - { re: /\bkill\s+(-9\s+|-KILL\s+|-s\s+KILL\s+)?-1\b/, why: "kills every process on the machine" }, - { re: /\bpkill\s+(-9\s+)?(-f\s+)?(bash|sh|sshd)\b/, why: "kills the shells the platform relies on" }, - { re: /\bkillall\s+(-9\s+)?(bash|sh|sshd)\b/, why: "kills the shells the platform relies on" }, - { re: /\b(iptables|nft|ufw)\b/, why: "changes the firewall" }, -]; - -export function checkCommand(command) { - for (const b of BLOCKED) { - if (b.re.test(command)) { - return ( - `Refused: this command ${b.why}. CloudGPU instances must stay reachable for the platform's ` + - `monitoring, otherwise the instance is shut down. Do the task another way.` - ); - } - } - return null; -} - -// ── Local files that should not be shipped to a rented machine by default ───── -const SENSITIVE = [ - /(^|\/)\.ssh(\/|$)/, - /(^|\/)\.aws(\/|$)/, - /(^|\/)\.gnupg(\/|$)/, - /(^|\/)\.config\/gcloud(\/|$)/, - /(^|\/)\.kube(\/|$)/, - /(^|\/)\.docker\/config\.json$/, - /(^|\/)\.netrc$/, - /(^|\/)\.npmrc$/, - /(^|\/)\.pypirc$/, - /(^|\/)\.env(\..*)?$/, - /\.(pem|key|p12|pfx)$/, - /(^|\/)id_(rsa|ed25519|ecdsa|dsa)(\.pub)?$/, -]; - -export function sensitiveReason(localPath) { - const abs = path.resolve(expandHome(localPath)).replace(/\\/g, "/"); - if (abs === os.homedir().replace(/\\/g, "/")) return "it is your whole home directory"; - for (const re of SENSITIVE) if (re.test(abs)) return "it looks like credentials or a secrets file"; - return null; -} - -export function expandHome(p) { - if (!p) return p; - return p === "~" ? os.homedir() : p.startsWith("~/") ? path.join(os.homedir(), p.slice(2)) : p; -} - -// ── Redaction ───────────────────────────────────────────────────────────── -/** Remove secrets (API key, SSH password, SSH host) from any text going back to the model. */ -export function redact(text, secrets) { - if (text == null) return text; - let out = String(text); - for (const s of secrets) { - if (s && String(s).length >= 4) out = out.split(String(s)).join("[redacted]"); - } - out = out.replace(/\bsk-[A-Za-z0-9_-]{16,}/g, "sk-[redacted]"); - return out; -} - -/** Instance object as the model sees it: no SSH host, user or password. */ -export function publicInstance(inst) { - if (!inst) return inst; - const { ssh, ...rest } = inst; - return { ...rest, ssh_ready: !!(ssh && ssh.host && inst.status === "running") }; -} - -// ── Quotes ──────────────────────────────────────────────────────────────── -// -// create_instance only accepts a quote_id from estimate_cost, so the assistant always has the -// real hourly price, the estimate and the balance in hand (and shows them) before renting. -export class Quotes { - constructor(ttlMs = 15 * 60 * 1000) { - this.ttlMs = ttlMs; - this.map = new Map(); - } - put(q) { - const id = "q_" + crypto.randomBytes(6).toString("hex"); - this.map.set(id, { ...q, id, at: Date.now() }); - return id; - } - take(id) { - const q = this.map.get(id); - if (!q) return { error: "Unknown quote_id. Call estimate_cost first and show the quote to the user." }; - if (Date.now() - q.at > this.ttlMs) { - this.map.delete(id); - return { error: "This quote expired (quotes last 15 minutes). Call estimate_cost again; prices are live." }; - } - this.map.delete(id); - return { quote: q }; - } -} - -export function round2(n) { - return Math.round(n * 100) / 100; -} - -/** Shell-quote one argument for bash. */ -export function shq(s) { - return `'${String(s).replace(/'/g, `'\\''`)}'`; -} diff --git a/mcp-server/src/index.js b/mcp-server/src/index.js deleted file mode 100644 index b3d4052..0000000 --- a/mcp-server/src/index.js +++ /dev/null @@ -1,571 +0,0 @@ -#!/usr/bin/env node -// CloudGPU MCP server (stdio). Lets an AI coding assistant rent a GPU on cloudgpu.app, run a job, -// fetch the results and shut the GPU down. -// -// Env: -// CLOUDGPU_API_KEY required; create one at https://cloudgpu.app/api -// CLOUDGPU_MAX_SPEND_USD optional; highest budget the assistant may set for one instance (default 50) -// CLOUDGPU_MAX_HOURS optional; longest run the assistant may set for one instance (default 24) -// CLOUDGPU_READ_ONLY optional; "1" registers only the tools that look things up -// CLOUDGPU_BASE_URL optional; default https://cloudgpu.app -import fs from "node:fs"; -import path from "node:path"; -import { fileURLToPath } from "node:url"; -import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; -import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; -import { z } from "zod"; -import { CloudGpuApi, ApiError } from "./api.js"; -import { SshPool, exec, upload, download, writeFile } from "./ssh.js"; -import { - checkCommand, - sensitiveReason, - expandHome, - redact, - publicInstance, - Quotes, - round2, - shq, -} from "./guards.js"; - -const VERSION = "0.1.0"; -const HERE = path.dirname(fileURLToPath(import.meta.url)); -const RULES = fs.readFileSync(path.join(HERE, "..", "rules", "cloudgpu.md"), "utf8"); - -const cfg = { - apiKey: (process.env.CLOUDGPU_API_KEY || "").trim(), - baseUrl: process.env.CLOUDGPU_BASE_URL || "https://cloudgpu.app", - maxSpend: num(process.env.CLOUDGPU_MAX_SPEND_USD, 50), - maxHours: num(process.env.CLOUDGPU_MAX_HOURS, 24), - readOnly: /^(1|true|yes)$/i.test(process.env.CLOUDGPU_READ_ONLY || ""), -}; - -function num(v, d) { - const n = Number(v); - return Number.isFinite(n) && n > 0 ? n : d; -} - -const api = new CloudGpuApi({ apiKey: cfg.apiKey, baseUrl: cfg.baseUrl }); -const pool = new SshPool(); -const quotes = new Quotes(); -// Instances this session touched: did we run anything, did we download anything. -const session = new Map(); - -const INSTRUCTIONS = `CloudGPU (cloudgpu.app) rents GPUs billed per minute from a prepaid balance. -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. -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. -The same API key also works for the OpenAI-compatible model API at ${cfg.baseUrl}/v1 (see list_models).`; - -const server = new McpServer({ name: "cloudgpu", version: VERSION }, { instructions: INSTRUCTIONS }); - -// ── helpers ────────────────────────────────────────────────────────────── - -function ok(obj) { - const text = typeof obj === "string" ? obj : JSON.stringify(obj, null, 2); - return { content: [{ type: "text", text: redact(text, [cfg.apiKey]) }] }; -} - -function fail(msg) { - return { content: [{ type: "text", text: redact(msg, [cfg.apiKey]) }], isError: true }; -} - -function wrap(fn) { - return async (args) => { - try { - return await fn(args || {}); - } catch (err) { - if (err instanceof ApiError) { - let hint = ""; - if (err.status === 401) hint = " Check CLOUDGPU_API_KEY (create one at https://cloudgpu.app/api)."; - if (err.status === 402) hint = " Top up at https://cloudgpu.app/billing."; - return fail(`CloudGPU API error ${err.status} ${err.code}: ${err.message}${hint}`); - } - return fail(`Error: ${err && err.message ? err.message : String(err)}`); - } - }; -} - -function track(id) { - if (!session.has(id)) session.set(id, { ran: false, downloaded: false }); - return session.get(id); -} - -/** Running instance + SSH client; throws a readable error otherwise. */ -async function connectTo(id) { - const inst = await api.instance(id); - if (inst.status !== "running") { - throw new Error( - `Instance ${id} is ${inst.status}` + - (inst.status === "creating" - ? "; wait for it with get_status (usually about 2 minutes)." - : inst.failure_reason - ? `: ${inst.failure_reason}` - : inst.limits && inst.limits.stopped_by - ? ` (stopped by its ${inst.limits.stopped_by} limit).` - : "."), - ); - } - if (!inst.ssh || !inst.ssh.host) throw new Error(`Instance ${id} has no SSH access yet; try get_status again shortly.`); - const client = await pool.get(id, inst.ssh); - const secrets = [cfg.apiKey, inst.ssh.password, inst.ssh.host]; - return { inst, client, secrets }; -} - -const JOBS = ".cloudgpu/jobs"; -// bash -i so conda / venv set up in ~/.bashrc are active, the same as an interactive login. -const NOISE = /^bash: (cannot set terminal process group|no job control in this shell).*\n?/gm; - -function cleanOut(s, secrets) { - return redact((s || "").replace(NOISE, ""), secrets); -} - -// ── account and catalogue ──────────────────────────────────────────────── - -server.registerTool( - "get_account", - { - title: "CloudGPU account", - description: "Balance in USD, how many instances this account may run at once, and how many are running now.", - inputSchema: {}, - annotations: { readOnlyHint: true, openWorldHint: true }, - }, - wrap(async () => ok(await api.account())), -); - -server.registerTool( - "list_gpus", - { - title: "List GPUs", - description: - "GPU models you can rent now, with VRAM, live price per GPU-hour in USD and availability (ok / low / none). Prices are live; never assume them.", - inputSchema: { - min_vram_gb: z.number().optional().describe("Only GPUs with at least this much VRAM per card"), - gpu_model: z.string().optional().describe("Filter by name, e.g. 4090, A100, H20"), - }, - annotations: { readOnlyHint: true, openWorldHint: true }, - }, - wrap(async ({ min_vram_gb, gpu_model }) => { - let rows = await api.offers(); - if (min_vram_gb) rows = rows.filter((r) => (r.vram_gb || 0) >= min_vram_gb); - if (gpu_model) { - const q = gpu_model.toLowerCase().replace(/\s+/g, ""); - rows = rows.filter((r) => String(r.gpu_model).toLowerCase().replace(/\s+/g, "").includes(q)); - } - return ok({ - gpus: rows.map((r) => ({ - gpu_model: r.gpu_model, - vram_gb: r.vram_gb, - usd_per_gpu_hour: r.hourly_usd, - available: r.available, - min_gpu_count: r.min_gpu_count, - })), - note: "Billed per minute. 'available' is live and can change before you rent.", - }); - }), -); - -server.registerTool( - "list_templates", - { - title: "List templates", - description: - "Ready-made instance images (e.g. JupyterLab, Ollama, ComfyUI, LLaMA-Factory) with the GPU each recommends. Templates with has_api_endpoint get a public HTTPS api_url.", - inputSchema: {}, - annotations: { readOnlyHint: true, openWorldHint: true }, - }, - wrap(async () => ok({ templates: await api.templates() })), -); - -server.registerTool( - "estimate_cost", - { - title: "Quote a rental", - description: - "Live price and estimated cost for a GPU, plus your balance after it. Returns a quote_id that create_instance needs. Show the quote to the user and get an explicit yes before renting.", - inputSchema: { - gpu_model: z.string().describe("GPU model exactly as list_gpus returns it"), - gpu_count: z.number().int().min(1).max(8).default(1), - hours: z.number().positive().describe("Expected run time in hours"), - template: z.string().optional().describe("Template id from list_templates; omit for a plain GPU with Python and CUDA"), - }, - annotations: { readOnlyHint: true, openWorldHint: true }, - }, - wrap(async ({ gpu_model, gpu_count = 1, hours, template }) => { - const [offers, account] = await Promise.all([api.offers(), api.account().catch(() => null)]); - const offer = offers.find((o) => String(o.gpu_model).toLowerCase() === gpu_model.toLowerCase()); - if (!offer) { - return fail(`No GPU named "${gpu_model}". Available: ${offers.map((o) => o.gpu_model).join(", ")}`); - } - if (gpu_count < (offer.min_gpu_count || 1)) { - return fail(`${offer.gpu_model} is rented in groups of at least ${offer.min_gpu_count} GPUs.`); - } - const hourly = round2(Number(offer.hourly_usd) * gpu_count); - const estimate = round2(hourly * hours); - const balance = account ? Number(account.balance_usd) : null; - const warnings = []; - if (offer.available === "none") warnings.push("This GPU is out of stock right now; renting will likely fail. Pick another."); - if (offer.available === "low") warnings.push("Only a few of these are free; renting may fail."); - if (balance != null && balance < estimate * 1.1) { - warnings.push( - `Balance $${balance} does not cover the estimate plus a 10% buffer. When the balance runs out the instance is destroyed and its disk erased. Top up at https://cloudgpu.app/billing.`, - ); - } - const quote_id = quotes.put({ gpu_model: offer.gpu_model, gpu_count, template, hourly, hours, estimate }); - return ok({ - quote_id, - gpu_model: offer.gpu_model, - gpu_count, - template: template || null, - usd_per_hour: hourly, - hours, - estimated_cost_usd: estimate, - balance_usd: balance, - balance_after_usd: balance == null ? null : round2(balance - estimate), - suggested_max_spend_usd: round2(Math.min(cfg.maxSpend, Math.max(1, estimate * 1.25))), - warnings, - next: "Show this quote to the user. Only after they say yes, call create_instance with this quote_id.", - }); - }), -); - -server.registerTool( - "list_models", - { - title: "List hosted models", - description: - "Models on CloudGPU's OpenAI-compatible API (same key, same balance). Use them from code with base_url " + - `${cfg.baseUrl}/v1 instead of renting a GPU when you only need inference.`, - inputSchema: {}, - annotations: { readOnlyHint: true, openWorldHint: true }, - }, - wrap(async () => { - const models = await api.models(); - return ok({ - base_url: `${cfg.baseUrl}/v1`, - auth: "Authorization: Bearer ", - models: models.map((m) => m.id), - pricing: `${cfg.baseUrl}/pricing`, - }); - }), -); - -// ── instances (read) ───────────────────────────────────────────────────── - -server.registerTool( - "get_status", - { - title: "Instance status", - description: - "Status (creating / running / stopped / failed), minutes run, cost so far, whether SSH is ready, the public api_url if the template has one, and the auto-shutdown limits.", - inputSchema: { instance_id: z.string() }, - annotations: { readOnlyHint: true, openWorldHint: true }, - }, - wrap(async ({ instance_id }) => ok(publicInstance(await api.instance(instance_id)))), -); - -server.registerTool( - "list_instances", - { - title: "List instances", - description: "Instances on this account: running, starting, and those stopped in the last 7 days, with cost.", - inputSchema: {}, - annotations: { readOnlyHint: true, openWorldHint: true }, - }, - wrap(async () => ok({ instances: (await api.instances()).map(publicInstance) })), -); - -// ── instances (act) ────────────────────────────────────────────────────── - -if (!cfg.readOnly) { - server.registerTool( - "create_instance", - { - title: "Rent a GPU", - description: - "Rents the GPU from a quote. Costs money. Requires a quote_id from estimate_cost that the user has approved. " + - "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. " + - "idle_minutes destroys it after the GPU sits idle that long (installing packages and downloading data count as idle, so allow for setup).", - inputSchema: { - quote_id: z.string(), - user_confirmed: z.boolean().describe("true only if the user explicitly approved this quote in the conversation"), - max_spend_usd: z.number().positive().describe(`Budget for this instance in USD (at most ${cfg.maxSpend})`), - max_hours: z.number().positive().describe(`Hard time limit in hours (at most ${cfg.maxHours})`), - idle_minutes: z - .number() - .int() - .min(0) - .max(1440) - .default(60) - .describe("Destroy after the GPU has been idle this long; 0 turns it off; otherwise at least 10"), - }, - annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true }, - }, - wrap(async ({ quote_id, user_confirmed, max_spend_usd, max_hours, idle_minutes = 60 }) => { - if (user_confirmed !== true) { - return fail("Not rented: show the quote to the user and wait for an explicit yes, then call again with user_confirmed=true."); - } - if (max_spend_usd > cfg.maxSpend) { - return fail( - `max_spend_usd ${max_spend_usd} is above this server's cap of ${cfg.maxSpend} (CLOUDGPU_MAX_SPEND_USD). Ask the user to raise the cap in the MCP config if they want more.`, - ); - } - if (max_hours > cfg.maxHours) { - return fail(`max_hours ${max_hours} is above this server's cap of ${cfg.maxHours} (CLOUDGPU_MAX_HOURS).`); - } - if (idle_minutes > 0 && idle_minutes < 10) return fail("idle_minutes must be 0 (off) or at least 10."); - const { quote, error } = quotes.take(quote_id); - if (error) return fail(error); - const account = await api.account(); - const balance = Number(account.balance_usd); - const needed = round2(Math.min(max_spend_usd, quote.estimate) * 1.1); - if (balance < needed) { - return fail( - `Not rented: balance $${balance} is below $${needed} (the estimate or budget plus 10%). If the balance runs out the instance is destroyed and its disk erased. Top up at https://cloudgpu.app/billing.`, - ); - } - const body = { - gpu_model: quote.gpu_model, - gpu_count: quote.gpu_count, - max_minutes: Math.ceil(max_hours * 60), - max_spend_usd, - idle_minutes, - }; - if (quote.template) body.template = quote.template; - const inst = await api.create(body); - track(inst.id); - return ok({ - ...publicInstance(inst), - next: "Poll get_status every 30-60 seconds until status is running (usually about 2 minutes; templates and multi-GPU machines can take longer). Then upload and run_command.", - }); - }), - ); - - server.registerTool( - "run_command", - { - title: "Run a command on the instance", - description: - "Runs a bash command on the instance as root, in an interactive-style shell so conda/venv from ~/.bashrc are active. " + - "Foreground returns the exit code and the last 20k characters of output. For anything longer than a few minutes (training, big downloads) use background=true, then tail_logs.", - inputSchema: { - instance_id: z.string(), - command: z.string().describe("bash command or script"), - background: z.boolean().default(false), - timeout_sec: z.number().int().min(5).max(3600).default(600).describe("Foreground only"), - workdir: z.string().default("~").describe("Directory to run in"), - }, - annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: true }, - }, - wrap(async ({ instance_id, command, background = false, timeout_sec = 600, workdir = "~" }) => { - const blocked = checkCommand(command); - if (blocked) return fail(blocked); - const { client, secrets } = await connectTo(instance_id); - track(instance_id).ran = true; - const job = "j" + Date.now().toString(36); - const cd = workdir === "~" ? "cd ~" : workdir.startsWith("~/") ? `cd ~/${shq(workdir.slice(2))}` : `cd ${shq(workdir)}`; - await writeFile(client, `${JOBS}/${job}.sh`, `${cd} || exit 97\n${command}\n`); - if (background) { - const r = await exec( - client, - `cd ~ && setsid nohup bash -c 'bash -i ${JOBS}/${job}.sh > ${JOBS}/${job}.log 2>&1 < /dev/null; echo $? > ${JOBS}/${job}.exit' > /dev/null 2>&1 < /dev/null & echo started`, - { timeoutSec: 30 }, - ); - if (!/started/.test(r.stdout)) return fail(`Could not start the job: ${cleanOut(r.stderr, secrets)}`); - return ok({ - job_id: job, - log: `~/${JOBS}/${job}.log`, - next: "Check progress with tail_logs (job_id). The job keeps running if this assistant disconnects; the instance's limits still apply.", - }); - } - const r = await exec(client, `cd ~ && timeout ${timeout_sec} bash -i ${JOBS}/${job}.sh 2>&1 < /dev/null`, { - timeoutSec: timeout_sec + 15, - }); - const out = cleanOut(r.stdout + (r.stderr ? "\n" + r.stderr : ""), secrets); - return ok({ - exit_code: r.timedOut || r.code === 124 ? null : r.code, - timed_out: r.timedOut || r.code === 124, - output: out, - ...(r.timedOut || r.code === 124 ? { hint: "Timed out. Re-run long work with background=true." } : {}), - }); - }), - ); - - server.registerTool( - "upload", - { - title: "Upload to the instance", - description: - "Copies a local file or directory (this computer) to the instance over SFTP. node_modules, .git and __pycache__ are skipped. Credentials files (.ssh, .env, keys) are refused unless allow_sensitive is true and the user asked for it.", - inputSchema: { - instance_id: z.string(), - local_path: z.string(), - remote_path: z.string().describe("Destination on the instance, e.g. /root/project or /root/data/"), - allow_sensitive: z.boolean().default(false), - }, - annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true }, - }, - wrap(async ({ instance_id, local_path, remote_path, allow_sensitive = false }) => { - const local = path.resolve(expandHome(local_path)); - if (!fs.existsSync(local)) return fail(`No such local path: ${local}`); - const why = sensitiveReason(local); - if (why && !allow_sensitive) { - return fail(`Refused to upload ${local}: ${why}. If the user explicitly wants it on the instance, call again with allow_sensitive=true.`); - } - const { client } = await connectTo(instance_id); - const remote = remote_path.startsWith("~/") ? remote_path.slice(2) : remote_path; - const r = await upload(client, local, remote); - return ok({ uploaded_files: r.files, bytes: r.bytes, remote_path }); - }), - ); - - server.registerTool( - "download", - { - title: "Download from the instance", - description: - "Copies a file or directory from the instance to this computer. Do this for every result before stop_instance: destroying an instance erases its disk.", - inputSchema: { - instance_id: z.string(), - remote_path: z.string(), - local_path: z.string().describe("Local destination file or directory, e.g. ./outputs/"), - }, - annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true }, - }, - wrap(async ({ instance_id, remote_path, local_path }) => { - const { client } = await connectTo(instance_id); - const remote = remote_path.startsWith("~/") ? remote_path.slice(2) : remote_path; - const r = await download(client, remote, path.resolve(expandHome(local_path))); - track(instance_id).downloaded = true; - return ok({ - files: r.files.slice(0, 200), - file_count: r.files.length, - bytes: r.bytes, - }); - }), - ); - - server.registerTool( - "tail_logs", - { - title: "Job logs and GPU use", - description: - "Last lines of a background job's log (job_id) or any log file (path), whether the job is still running and its exit code, plus current GPU utilisation and memory.", - inputSchema: { - instance_id: z.string(), - job_id: z.string().optional(), - path: z.string().optional(), - lines: z.number().int().min(1).max(2000).default(100), - }, - annotations: { readOnlyHint: true, openWorldHint: true }, - }, - wrap(async ({ instance_id, job_id, path: logPath, lines = 100 }) => { - if (!job_id && !logPath) return fail("Give job_id (from run_command background=true) or path."); - if (job_id && !/^[a-z0-9]+$/i.test(job_id)) return fail("Bad job_id."); - const { client, secrets } = await connectTo(instance_id); - const file = job_id ? `${JOBS}/${job_id}.log` : logPath.startsWith("~/") ? logPath.slice(2) : logPath; - const exitFile = job_id ? `${JOBS}/${job_id}.exit` : "/nonexistent"; - const r = await exec( - client, - `cd ~; echo '<&1; echo 'LOG>>'; ` + - `if [ -f ${shq(exitFile)} ]; then echo "EXIT=$(cat ${shq(exitFile)})"; fi; ` + - `nvidia-smi --query-gpu=index,utilization.gpu,memory.used,memory.total --format=csv,noheader,nounits 2>/dev/null | sed 's/^/GPU=/'`, - { timeoutSec: 60 }, - ); - const s = r.stdout; - const log = s.includes("<>")) : s; - const exitM = s.match(/EXIT=(\d+)/); - const gpus = [...s.matchAll(/GPU=(\d+), (\d+), (\d+), (\d+)/g)].map((m) => ({ - gpu: Number(m[1]), - utilization_pct: Number(m[2]), - memory_used_mb: Number(m[3]), - memory_total_mb: Number(m[4]), - })); - return ok({ - log: cleanOut(log, secrets), - ...(job_id ? { running: !exitM, exit_code: exitM ? Number(exitM[1]) : null } : {}), - gpus, - }); - }), - ); - - server.registerTool( - "stop_instance", - { - title: "Destroy an instance", - description: - "Destroys the instance and stops billing. Its disk is erased. If commands were run on it in this session and nothing was downloaded, this refuses unless force=true (only after the user confirms the results are not needed).", - inputSchema: { - instance_id: z.string(), - force: z.boolean().default(false), - }, - annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: true }, - }, - wrap(async ({ instance_id, force = false }) => { - const s = session.get(instance_id); - if (s && s.ran && !s.downloaded && !force) { - return fail( - "Not stopped: nothing has been downloaded from this instance yet, and stopping erases its disk. Download the results first, or ask the user and call again with force=true.", - ); - } - pool.close(instance_id); - try { - const inst = await api.destroy(instance_id); - session.delete(instance_id); - return ok({ ...publicInstance(inst), note: "Destroyed. Billing has stopped." }); - } catch (err) { - if (err instanceof ApiError && err.code === "cannot_destroy") { - // 已经停了(限额到线、余额用完、开出来没 GPU 被平台退款):告诉助手结果,而不是报错 - const inst = await api.instance(instance_id).catch(() => null); - if (inst && inst.status !== "running") { - session.delete(instance_id); - return ok({ ...publicInstance(inst), note: "Already stopped; nothing more to do. Billing has stopped." }); - } - } - if (err instanceof ApiError && err.code === "instance_provisioning") { - return fail("The instance is still starting and cannot be destroyed yet. Wait for get_status to show running (or failed; failed instances are not charged), then call stop_instance again."); - } - throw err; - } - }), - ); -} - -// ── rules for the assistant ────────────────────────────────────────────── - -server.registerResource( - "rules", - "cloudgpu://rules", - { title: "CloudGPU agent rules", description: "How to rent, run and shut down safely", mimeType: "text/markdown" }, - async (uri) => ({ contents: [{ uri: uri.href, mimeType: "text/markdown", text: RULES }] }), -); - -server.registerPrompt( - "train_on_cloudgpu", - { - title: "Run a job on a CloudGPU GPU", - description: "Rent a GPU, run a training or fine-tuning job, bring the results back and shut down", - argsSchema: { task: z.string().describe("What to run, e.g. 'LoRA fine-tune Qwen2.5-7B on data/train.jsonl'") }, - }, - ({ task }) => ({ - messages: [{ role: "user", content: { type: "text", text: `${RULES}\n\n---\n\nTask: ${task}` } }], - }), -); - -// ── start ──────────────────────────────────────────────────────────────── - -if (process.argv.includes("--version")) { - console.log(VERSION); - process.exit(0); -} - -const transport = new StdioServerTransport(); -await server.connect(transport); -const bye = () => { - pool.closeAll(); - process.exit(0); -}; -process.on("SIGINT", bye); -process.on("SIGTERM", bye); -process.stdin.on("close", bye); -if (!cfg.apiKey) { - console.error("cloudgpu-mcp: CLOUDGPU_API_KEY is not set; tools will return an error until it is. Create a key at https://cloudgpu.app/api"); -} diff --git a/mcp-server/src/ssh.js b/mcp-server/src/ssh.js deleted file mode 100644 index 6a3e441..0000000 --- a/mcp-server/src/ssh.js +++ /dev/null @@ -1,233 +0,0 @@ -// SSH to a rented instance: run commands, upload, download. -// -// The SSH password comes from the API and stays inside this process. It is never put in a tool -// result, so it never reaches the model's context or the chat log. -import { Client } from "ssh2"; -import fs from "node:fs"; -import path from "node:path"; -import { sleep } from "./api.js"; - -const MAX_OUTPUT = 20000; // characters of command output returned to the model - -export class SshPool { - constructor() { - this.conns = new Map(); // instanceId -> { client, key } - } - - async get(instanceId, ssh) { - const key = `${ssh.host}:${ssh.port}:${ssh.user}`; - const cur = this.conns.get(instanceId); - if (cur && cur.key === key && cur.ready) return cur.client; - if (cur) this.close(instanceId); - // Some instance gateways drop several connections opened back to back, so retry with backoff. - let lastErr; - for (let i = 0; i < 4; i++) { - try { - const client = await connect(ssh); - const entry = { client, key, ready: true }; - client.on("close", () => { - entry.ready = false; - }); - client.on("error", () => { - entry.ready = false; - }); - this.conns.set(instanceId, entry); - return client; - } catch (err) { - lastErr = err; - await sleep(2000 * (i + 1)); - } - } - throw new Error(`SSH connection failed: ${lastErr && lastErr.message}`); - } - - close(instanceId) { - const cur = this.conns.get(instanceId); - if (cur) { - try { - cur.client.end(); - } catch { - /* already closed */ - } - this.conns.delete(instanceId); - } - } - - closeAll() { - for (const id of [...this.conns.keys()]) this.close(id); - } -} - -function connect(ssh) { - return new Promise((resolve, reject) => { - const c = new Client(); - const timer = setTimeout(() => { - c.end(); - reject(new Error("timed out")); - }, 25000); - c.on("ready", () => { - clearTimeout(timer); - resolve(c); - }); - c.on("error", (e) => { - clearTimeout(timer); - reject(e); - }); - c.connect({ - host: ssh.host, - port: ssh.port || 22, - username: ssh.user || "root", - password: ssh.password, - readyTimeout: 20000, - keepaliveInterval: 15000, - keepaliveCountMax: 4, - tryKeyboard: true, - }); - c.on("keyboard-interactive", (_n, _i, _l, prompts, finish) => finish(prompts.map(() => ssh.password))); - }); -} - -/** Run a command; resolves { code, stdout, stderr } (both truncated to the tail). */ -export function exec(client, command, { timeoutSec = 600 } = {}) { - return new Promise((resolve, reject) => { - client.exec(command, (err, stream) => { - if (err) return reject(err); - let out = ""; - let errOut = ""; - let done = false; - const timer = setTimeout(() => { - if (done) return; - done = true; - try { - stream.close(); - } catch { - /* ignore */ - } - resolve({ code: null, timedOut: true, stdout: tail(out), stderr: tail(errOut) }); - }, timeoutSec * 1000); - stream.on("data", (d) => { - out = keepTail(out + d.toString("utf8")); - }); - stream.stderr.on("data", (d) => { - errOut = keepTail(errOut + d.toString("utf8")); - }); - stream.on("close", (code) => { - if (done) return; - done = true; - clearTimeout(timer); - resolve({ code, timedOut: false, stdout: tail(out), stderr: tail(errOut) }); - }); - }); - }); -} - -function keepTail(s) { - return s.length > MAX_OUTPUT * 2 ? s.slice(-MAX_OUTPUT * 2) : s; -} - -function tail(s) { - return s.length > MAX_OUTPUT ? "…(earlier output cut)…\n" + s.slice(-MAX_OUTPUT) : s; -} - -function sftpOf(client) { - return new Promise((resolve, reject) => client.sftp((err, sftp) => (err ? reject(err) : resolve(sftp)))); -} - -const p = (fn) => - new Promise((resolve, reject) => fn((err, v) => (err ? reject(err) : resolve(v)))); - -async function mkdirp(sftp, dir) { - const parts = dir.split("/").filter(Boolean); - let cur = dir.startsWith("/") ? "" : "."; - for (const part of parts) { - cur = `${cur}/${part}`; - try { - await p((cb) => sftp.stat(cur, cb)); - } catch { - await p((cb) => sftp.mkdir(cur, cb)).catch(() => {}); - } - } -} - -/** Upload a local file or directory. Returns { files, bytes }. */ -export async function upload(client, localPath, remotePath) { - const sftp = await sftpOf(client); - try { - const st = fs.statSync(localPath); - let files = 0; - let bytes = 0; - const put = async (src, dst) => { - await mkdirp(sftp, path.posix.dirname(dst)); - await p((cb) => sftp.fastPut(src, dst, cb)); - files += 1; - bytes += fs.statSync(src).size; - }; - if (st.isDirectory()) { - const walk = async (dir, rel) => { - for (const ent of fs.readdirSync(dir, { withFileTypes: true })) { - if (ent.name === "node_modules" || ent.name === ".git" || ent.name === "__pycache__") continue; - const src = path.join(dir, ent.name); - const dst = path.posix.join(remotePath, rel, ent.name); - if (ent.isDirectory()) await walk(src, path.posix.join(rel, ent.name)); - else if (ent.isFile()) await put(src, dst); - } - }; - await mkdirp(sftp, remotePath); - await walk(localPath, ""); - } else { - await put(localPath, remotePath.endsWith("/") ? path.posix.join(remotePath, path.basename(localPath)) : remotePath); - } - return { files, bytes }; - } finally { - sftp.end(); - } -} - -/** Download a remote file or directory. Returns { files: [{path, bytes}], bytes }. */ -export async function download(client, remotePath, localPath) { - const sftp = await sftpOf(client); - try { - const st = await p((cb) => sftp.stat(remotePath, cb)); - const files = []; - let bytes = 0; - const get = async (src, dst, size) => { - fs.mkdirSync(path.dirname(dst), { recursive: true }); - await p((cb) => sftp.fastGet(src, dst, cb)); - files.push({ path: dst, bytes: size }); - bytes += size; - }; - if (st.isDirectory()) { - const walk = async (dir, rel) => { - const list = await p((cb) => sftp.readdir(dir, cb)); - for (const ent of list) { - const src = path.posix.join(dir, ent.filename); - const dst = path.join(localPath, rel, ent.filename); - if (ent.attrs.isDirectory()) await walk(src, path.join(rel, ent.filename)); - else if (ent.attrs.isFile()) await get(src, dst, ent.attrs.size); - } - }; - fs.mkdirSync(localPath, { recursive: true }); - await walk(remotePath, ""); - } else { - let dst = localPath; - if (fs.existsSync(localPath) && fs.statSync(localPath).isDirectory()) { - dst = path.join(localPath, path.posix.basename(remotePath)); - } - await get(remotePath, dst, st.size); - } - return { files, bytes }; - } finally { - sftp.end(); - } -} - -/** Write a small text file on the instance. */ -export async function writeFile(client, remotePath, content) { - const sftp = await sftpOf(client); - try { - await mkdirp(sftp, path.posix.dirname(remotePath)); - await p((cb) => sftp.writeFile(remotePath, content, { mode: 0o700 }, cb)); - } finally { - sftp.end(); - } -} diff --git a/mcp-server/test/guards.test.js b/mcp-server/test/guards.test.js deleted file mode 100644 index 2f208d0..0000000 --- a/mcp-server/test/guards.test.js +++ /dev/null @@ -1,36 +0,0 @@ -import test from "node:test"; -import assert from "node:assert/strict"; -import { checkCommand, sensitiveReason, redact, publicInstance, Quotes } from "../src/guards.js"; - -test("blocks commands that would lock the platform out", () => { - for (const c of ["passwd root", "echo 'root:x' | chpasswd", "sed -i 's/yes/no/' /etc/ssh/sshd_config", - "systemctl stop sshd", "pkill -f cgpu-watchdog", "kill -9 -1", "iptables -F", "pkill -9 bash"]) { - assert.ok(checkCommand(c), c); - } - for (const c of ["python train.py", "pip install torch", "nvidia-smi", "kill 1234", "pkill -f train.py", "ls ~/.ssh"]) { - assert.equal(checkCommand(c), null, c); - } -}); - -test("refuses credential uploads by default", () => { - assert.ok(sensitiveReason("~/.ssh/id_ed25519")); - assert.ok(sensitiveReason("./.env")); - assert.ok(sensitiveReason("~")); - assert.equal(sensitiveReason("./data/train.jsonl"), null); -}); - -test("redacts secrets and hides ssh details", () => { - assert.equal(redact("pw hunter22 at 1.2.3.4 key sk-abcdefghijklmnopqrstu", ["hunter22", "1.2.3.4"]), - "pw [redacted] at [redacted] key sk-[redacted]"); - const p = publicInstance({ id: "1", status: "running", ssh: { host: "1.2.3.4", port: 22, user: "root", password: "x" } }); - assert.equal(p.ssh, undefined); - assert.equal(p.ssh_ready, true); - assert.ok(!JSON.stringify(p).includes("1.2.3.4")); -}); - -test("quotes are single use and expire", () => { - const q = new Quotes(50); - const id = q.put({ gpu_model: "RTX 4090" }); - assert.ok(q.take(id).quote); - assert.ok(q.take(id).error); -});