@paraloncloud/mcp 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -3
- package/package.json +1 -1
- package/server.js +143 -13
package/README.md
CHANGED
|
@@ -72,7 +72,15 @@ Use a **dedicated key** for the agent, not your production key.
|
|
|
72
72
|
|
|
73
73
|
### 2. Add it to your MCP client
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
**Hosted (no install):** ParalonCloud runs this server at `https://paraloncloud.com/mcp` (Streamable HTTP). Send your key as `Authorization: Bearer YOUR_API_KEY`. In Claude Code:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
claude mcp add --transport http paraloncloud https://paraloncloud.com/mcp --header "Authorization: Bearer YOUR_API_KEY"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The hosted server keeps no session and no key: each request carries its key, and it is used only for that request's calls to the ParalonCloud API.
|
|
82
|
+
|
|
83
|
+
**Local (npm):** the client passes your key via the `PARALON_API_KEY` env var — you never edit the server.
|
|
76
84
|
|
|
77
85
|
**Claude Desktop** — `claude_desktop_config.json`:
|
|
78
86
|
|
|
@@ -159,8 +167,8 @@ changes nothing. Without a key it only starts the server and checks the tool lis
|
|
|
159
167
|
|
|
160
168
|
Releases are published from GitHub Actions with npm provenance, never from a laptop: bump the
|
|
161
169
|
version in `package.json`, `server.json` and `server.js`, commit, then push an annotated tag
|
|
162
|
-
`vX.Y.Z`. The `publish` workflow runs the check
|
|
163
|
-
was built from.
|
|
170
|
+
`vX.Y.Z`. The `publish` workflow runs the check, publishes to npm, then to the official MCP
|
|
171
|
+
registry. The npm page shows the commit it was built from.
|
|
164
172
|
|
|
165
173
|
## Run locally (dev)
|
|
166
174
|
|
|
@@ -168,6 +176,12 @@ was built from.
|
|
|
168
176
|
PARALON_API_KEY=prlc_your_key_here node server.js
|
|
169
177
|
```
|
|
170
178
|
|
|
179
|
+
Hosted mode (what runs at `paraloncloud.com/mcp`): set `MCP_HTTP_PORT`, and the server answers stateless Streamable HTTP on `/mcp` (POST only) with the key from each request's `Authorization` header; `PARALON_API_KEY` is ignored. `/health` answers `{"ok":true}`. It logs no keys and no request bodies.
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
MCP_HTTP_PORT=8095 PARALON_BASE_URL=https://paraloncloud.com/api/v1 node server.js
|
|
183
|
+
```
|
|
184
|
+
|
|
171
185
|
## Links
|
|
172
186
|
|
|
173
187
|
- Rental API docs: https://paraloncloud.com/docs/rental-api
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paraloncloud/mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"mcpName": "io.github.ParalonCloud/paralon-mcp",
|
|
5
5
|
"description": "ParalonCloud MCP server: rent GPUs, and as a GPU provider manage your own nodes, prices and earnings, from an AI agent.",
|
|
6
6
|
"license": "MIT",
|
package/server.js
CHANGED
|
@@ -27,14 +27,26 @@ import {
|
|
|
27
27
|
ListToolsRequestSchema,
|
|
28
28
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
29
29
|
import { randomUUID } from "node:crypto";
|
|
30
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
31
|
+
import http from "node:http";
|
|
30
32
|
|
|
31
33
|
const BASE_URL = (process.env.PARALON_BASE_URL || "https://paraloncloud.com/api/v1").replace(/\/$/, "");
|
|
32
34
|
const API_KEY = process.env.PARALON_API_KEY || "";
|
|
33
35
|
|
|
36
|
+
// Hosted mode (MCP_HTTP_PORT set): one process serves many users over
|
|
37
|
+
// Streamable HTTP, each request with its own key in the Authorization header.
|
|
38
|
+
// The key and the caller's address travel with the request through
|
|
39
|
+
// AsyncLocalStorage, so every API call below uses the caller's key, never
|
|
40
|
+
// another user's and never one from the environment.
|
|
41
|
+
const HTTP_PORT = process.env.MCP_HTTP_PORT ? Number(process.env.MCP_HTTP_PORT) : 0;
|
|
42
|
+
const requestContext = new AsyncLocalStorage();
|
|
43
|
+
|
|
34
44
|
// One thin REST helper. Returns { ok, status, data } — never throws on HTTP
|
|
35
45
|
// errors, so a tool can surface the API's own error message to the agent.
|
|
36
46
|
async function api(method, path, { body, headers } = {}) {
|
|
37
|
-
|
|
47
|
+
const ctx = requestContext.getStore();
|
|
48
|
+
const key = HTTP_PORT ? ctx?.key || "" : API_KEY;
|
|
49
|
+
if (!key) {
|
|
38
50
|
return {
|
|
39
51
|
ok: false,
|
|
40
52
|
status: 0,
|
|
@@ -49,7 +61,11 @@ async function api(method, path, { body, headers } = {}) {
|
|
|
49
61
|
const res = await fetch(`${BASE_URL}${path}`, {
|
|
50
62
|
method,
|
|
51
63
|
headers: {
|
|
52
|
-
Authorization: `Bearer ${
|
|
64
|
+
Authorization: `Bearer ${key}`,
|
|
65
|
+
// Hosted mode calls the API on the internal network: pass the
|
|
66
|
+
// caller's address so the API's per-IP guard (failed keys) counts
|
|
67
|
+
// each user, not this server.
|
|
68
|
+
...(ctx?.clientIP ? { "CF-Connecting-IP": ctx.clientIP } : {}),
|
|
53
69
|
...(body ? { "Content-Type": "application/json" } : {}),
|
|
54
70
|
...headers,
|
|
55
71
|
},
|
|
@@ -88,11 +104,6 @@ function reply(result, note) {
|
|
|
88
104
|
};
|
|
89
105
|
}
|
|
90
106
|
|
|
91
|
-
const server = new Server(
|
|
92
|
-
{ name: "paraloncloud", version: "1.6.1" },
|
|
93
|
-
{ capabilities: { tools: {} } }
|
|
94
|
-
);
|
|
95
|
-
|
|
96
107
|
const TOOLS = [
|
|
97
108
|
{
|
|
98
109
|
name: "list_gpus",
|
|
@@ -363,6 +374,52 @@ const TOOLS = [
|
|
|
363
374
|
},
|
|
364
375
|
];
|
|
365
376
|
|
|
377
|
+
// MCP tool annotations: a title, and whether a tool only reads, changes
|
|
378
|
+
// something, or undoes something (stops a GPU, deletes a key, takes a spot
|
|
379
|
+
// node back). Clients use them to decide what to confirm; Anthropic's
|
|
380
|
+
// connector directory requires them. None of these tools reach anything but
|
|
381
|
+
// the ParalonCloud API, so openWorldHint is false throughout.
|
|
382
|
+
const READ = { readOnlyHint: true, openWorldHint: false };
|
|
383
|
+
const WRITE = (idempotent) => ({ readOnlyHint: false, destructiveHint: false, idempotentHint: idempotent, openWorldHint: false });
|
|
384
|
+
const UNDO = { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false };
|
|
385
|
+
const ANNOTATIONS = {
|
|
386
|
+
list_gpus: { title: "List rentable GPUs", ...READ },
|
|
387
|
+
list_templates: { title: "List rental app templates", ...READ },
|
|
388
|
+
get_balance: { title: "Get credit balance", ...READ },
|
|
389
|
+
// Spends credits per minute; the price ceiling and the automatic
|
|
390
|
+
// idempotency key keep a repeat from starting a second GPU, but each call
|
|
391
|
+
// is a new rental, so it is not idempotent.
|
|
392
|
+
create_rental: { title: "Rent a GPU (spends credits)", ...WRITE(false) },
|
|
393
|
+
get_rental: { title: "Get a rental and its connection", ...READ },
|
|
394
|
+
list_rentals: { title: "List rentals", ...READ },
|
|
395
|
+
destroy_rental: { title: "Stop a rental (stops billing)", ...UNDO },
|
|
396
|
+
list_ssh_keys: { title: "List SSH keys", ...READ },
|
|
397
|
+
add_ssh_key: { title: "Add an SSH key", ...WRITE(false) },
|
|
398
|
+
delete_ssh_key: { title: "Delete an SSH key", ...UNDO },
|
|
399
|
+
list_my_nodes: { title: "List my GPU nodes", ...READ },
|
|
400
|
+
get_my_node: { title: "Get one of my nodes", ...READ },
|
|
401
|
+
add_node: { title: "Add a GPU node", ...WRITE(false) },
|
|
402
|
+
get_node_install_command: { title: "Get a node's install command", ...READ },
|
|
403
|
+
set_node_available: { title: "Put a node on or off the market", ...WRITE(true) },
|
|
404
|
+
set_node_price: { title: "Set a node's price", ...WRITE(true) },
|
|
405
|
+
update_node: { title: "Update a node", ...WRITE(true) },
|
|
406
|
+
reclaim_spot_node: { title: "Take a spot node back (stops its rental)", ...UNDO },
|
|
407
|
+
get_node_access: { title: "Get who can rent a node", ...READ },
|
|
408
|
+
// Replaces the whole list: entries left out lose access.
|
|
409
|
+
set_node_access: { title: "Set who can rent a node", readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false },
|
|
410
|
+
get_earnings: { title: "Get provider earnings", ...READ },
|
|
411
|
+
};
|
|
412
|
+
for (const t of TOOLS) {
|
|
413
|
+
if (!ANNOTATIONS[t.name]) throw new Error(`tool ${t.name} has no annotations`);
|
|
414
|
+
t.annotations = ANNOTATIONS[t.name];
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function createServer() {
|
|
418
|
+
const server = new Server(
|
|
419
|
+
{ name: "paraloncloud", version: "1.7.0" },
|
|
420
|
+
{ capabilities: { tools: {} } }
|
|
421
|
+
);
|
|
422
|
+
|
|
366
423
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
|
|
367
424
|
|
|
368
425
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
@@ -546,9 +603,82 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
546
603
|
}
|
|
547
604
|
});
|
|
548
605
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
606
|
+
return server;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
if (HTTP_PORT) {
|
|
610
|
+
await serveHTTP(HTTP_PORT);
|
|
611
|
+
} else {
|
|
612
|
+
const server = createServer();
|
|
613
|
+
const transport = new StdioServerTransport();
|
|
614
|
+
await server.connect(transport);
|
|
615
|
+
// Log to stderr only — stdout is the MCP protocol channel.
|
|
616
|
+
console.error(
|
|
617
|
+
`ParalonCloud MCP server running (base: ${BASE_URL}, key: ${API_KEY ? "set" : "MISSING — set PARALON_API_KEY"})`
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// Hosted mode: stateless Streamable HTTP. Every POST is a complete exchange
|
|
622
|
+
// with a fresh server and transport, so no session or key outlives it.
|
|
623
|
+
// Nothing is logged about a request but its method and status; never a key.
|
|
624
|
+
async function serveHTTP(port) {
|
|
625
|
+
const { StreamableHTTPServerTransport } = await import("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
626
|
+
const MAX_BODY = 1024 * 1024;
|
|
627
|
+
const json = (res, status, obj, extra = {}) => {
|
|
628
|
+
res.writeHead(status, { "Content-Type": "application/json", ...extra });
|
|
629
|
+
res.end(JSON.stringify(obj));
|
|
630
|
+
};
|
|
631
|
+
const rpcError = (res, status, message, extra) =>
|
|
632
|
+
json(res, status, { jsonrpc: "2.0", error: { code: -32000, message }, id: null }, extra);
|
|
633
|
+
|
|
634
|
+
const httpServer = http.createServer(async (req, res) => {
|
|
635
|
+
const path = (req.url || "/").split("?")[0].replace(/\/+$/, "") || "/";
|
|
636
|
+
if (path === "/health") return json(res, 200, { ok: true, version: "1.7.0" });
|
|
637
|
+
if (path !== "/mcp" && path !== "/") return json(res, 404, { error: "not_found" });
|
|
638
|
+
if (req.method !== "POST") {
|
|
639
|
+
// Stateless: no server-to-client stream and no session to end.
|
|
640
|
+
return rpcError(res, 405, "Method not allowed: this server is stateless, use POST.", { Allow: "POST" });
|
|
641
|
+
}
|
|
642
|
+
const auth = req.headers["authorization"] || "";
|
|
643
|
+
const key = auth.startsWith("Bearer ") ? auth.slice(7).trim() : "";
|
|
644
|
+
if (!key) {
|
|
645
|
+
return rpcError(
|
|
646
|
+
res,
|
|
647
|
+
401,
|
|
648
|
+
"Missing API key: send Authorization: Bearer <prlc_ key>. Create a key at https://paraloncloud.com/console (API keys).",
|
|
649
|
+
{ "WWW-Authenticate": 'Bearer realm="paraloncloud"' }
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
let size = 0;
|
|
653
|
+
const chunks = [];
|
|
654
|
+
for await (const c of req) {
|
|
655
|
+
size += c.length;
|
|
656
|
+
if (size > MAX_BODY) return rpcError(res, 413, "Request too large.");
|
|
657
|
+
chunks.push(c);
|
|
658
|
+
}
|
|
659
|
+
let body;
|
|
660
|
+
try {
|
|
661
|
+
body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
662
|
+
} catch {
|
|
663
|
+
return json(res, 400, { jsonrpc: "2.0", error: { code: -32700, message: "Parse error" }, id: null });
|
|
664
|
+
}
|
|
665
|
+
const clientIP = String(req.headers["cf-connecting-ip"] || req.headers["x-real-ip"] || "").split(",")[0].trim();
|
|
666
|
+
await requestContext.run({ key, clientIP }, async () => {
|
|
667
|
+
const server = createServer();
|
|
668
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined, enableJsonResponse: true });
|
|
669
|
+
res.on("close", () => {
|
|
670
|
+
transport.close();
|
|
671
|
+
server.close();
|
|
672
|
+
});
|
|
673
|
+
try {
|
|
674
|
+
await server.connect(transport);
|
|
675
|
+
await transport.handleRequest(req, res, body);
|
|
676
|
+
} catch (e) {
|
|
677
|
+
if (!res.headersSent) rpcError(res, 500, "Internal error.");
|
|
678
|
+
console.error(`mcp: ${req.method} failed: ${e && e.message}`);
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
});
|
|
682
|
+
httpServer.requestTimeout = 120000;
|
|
683
|
+
httpServer.listen(port, () => console.error(`ParalonCloud MCP server (HTTP) on :${port}, base ${BASE_URL}`));
|
|
684
|
+
}
|