@runpod/mcp-server 3.1.0 → 3.2.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/CHANGELOG.md +14 -0
- package/dist/{chunk-OM6RHPQC.mjs → chunk-WGK7D2YR.mjs} +370 -9
- package/dist/chunk-WGK7D2YR.mjs.map +1 -0
- package/dist/http.cjs +392 -17
- package/dist/http.cjs.map +1 -1
- package/dist/http.mjs +24 -10
- package/dist/http.mjs.map +1 -1
- package/dist/stdio.cjs +387 -16
- package/dist/stdio.cjs.map +1 -1
- package/dist/stdio.mjs +387 -16
- package/dist/stdio.mjs.map +1 -1
- package/dist/tools.cjs +369 -8
- package/dist/tools.cjs.map +1 -1
- package/dist/tools.d.cts +3 -0
- package/dist/tools.d.ts +3 -0
- package/dist/tools.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-OM6RHPQC.mjs.map +0 -1
package/dist/stdio.mjs
CHANGED
|
@@ -204,7 +204,7 @@ function restV1Base(env) {
|
|
|
204
204
|
return env.RUNPOD_REST_API_URL ?? "https://rest.runpod.io/v1";
|
|
205
205
|
}
|
|
206
206
|
function restV2Base(env) {
|
|
207
|
-
return env.RUNPOD_REST_V2_API_URL ?? "https://
|
|
207
|
+
return env.RUNPOD_REST_V2_API_URL ?? "https://api.runpod.io/v2";
|
|
208
208
|
}
|
|
209
209
|
function serverlessBase(env) {
|
|
210
210
|
return env.RUNPOD_SERVERLESS_API_URL ?? "https://api.runpod.ai/v2";
|
|
@@ -426,27 +426,176 @@ function resolveBackend(opts) {
|
|
|
426
426
|
|
|
427
427
|
// src/server.ts
|
|
428
428
|
var SERVER_NAME = "Runpod API Server";
|
|
429
|
-
var SERVER_VERSION = true ? "3.
|
|
429
|
+
var SERVER_VERSION = true ? "3.2.0" : "dev";
|
|
430
|
+
var SERVER_INSTRUCTIONS = `These tools cover common Runpod operations, but they are curated projections: the underlying APIs expose more fields and parameters than the tools surface.
|
|
431
|
+
|
|
432
|
+
When you need data or capability beyond these tools, consult the full API contracts directly. The REST v2 API lives at https://api.runpod.io/v2 \u2014 the same host these tools call \u2014 and is machine-readable at https://api.runpod.io/v2/openapi.json (fetch and search it to enumerate every path, parameter, and response schema). REST v1 at https://rest.runpod.io/v1 is deprecated; prefer v2. The REST version these tools are actually configured for is reported in the serverInfo.version string of the initialize response, e.g. "[RUNPOD_REST_VERSION=v2]". The GraphQL API at https://api.runpod.io/graphql may expose data the REST API does not yet cover; its schema is documented at https://graphql-spec.runpod.io/, and introspection is disabled in production, so use that reference rather than __schema queries. Both APIs take Bearer auth with a Runpod API key: use the key this client is already configured with \u2014 do not search the environment or filesystem for a credential.`;
|
|
430
433
|
function createServer(version = SERVER_VERSION) {
|
|
431
|
-
return new McpServer(
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
434
|
+
return new McpServer(
|
|
435
|
+
{
|
|
436
|
+
name: SERVER_NAME,
|
|
437
|
+
version: `${version} [${restVersionSummary(process.env)}]`
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
// Only advertise capabilities the server implements. It registers
|
|
441
|
+
// tools and no resources — advertising `resources` would invite
|
|
442
|
+
// `resources/list` calls that answer -32601.
|
|
443
|
+
capabilities: {
|
|
444
|
+
tools: {}
|
|
445
|
+
},
|
|
446
|
+
instructions: SERVER_INSTRUCTIONS
|
|
437
447
|
}
|
|
438
|
-
|
|
448
|
+
);
|
|
439
449
|
}
|
|
440
450
|
|
|
441
451
|
// src/tools/runtime.ts
|
|
442
452
|
import fetch from "node-fetch";
|
|
443
453
|
import { randomUUID } from "crypto";
|
|
444
454
|
|
|
455
|
+
// src/_shared/rate-limit.ts
|
|
456
|
+
var GENERIC_RATE_LIMIT_HINT = "rate limited \u2014 back off before retrying, and pace bulk operations";
|
|
457
|
+
var MAX_PLAUSIBLE_WAIT_S = 7 * 86400;
|
|
458
|
+
function remainingRequests(raw) {
|
|
459
|
+
const value = raw?.trim();
|
|
460
|
+
return value && /^\d+$/.test(value) ? Number(value) : null;
|
|
461
|
+
}
|
|
462
|
+
function waitSeconds(raw) {
|
|
463
|
+
const value = raw?.trim();
|
|
464
|
+
if (!value || !/^\d+$/.test(value)) return null;
|
|
465
|
+
const seconds = Number(value);
|
|
466
|
+
return seconds <= MAX_PLAUSIBLE_WAIT_S ? seconds : null;
|
|
467
|
+
}
|
|
468
|
+
var WINDOW_NAME_RE = /^(?:"([\x20-\x21\x23-\x5b\x5d-\x7e]{1,32})"|([A-Za-z*][A-Za-z0-9!#$%&'*+.^_`|~:/-]{0,31}))$/;
|
|
469
|
+
function windowName(raw) {
|
|
470
|
+
const match = WINDOW_NAME_RE.exec(raw.trim());
|
|
471
|
+
return match ? match[1] ?? match[2] : null;
|
|
472
|
+
}
|
|
473
|
+
var QUOTED_VALUE_RE = /^"(?:[\x20-\x21\x23-\x5b\x5d-\x7e]|\\["\\])*"$/;
|
|
474
|
+
var DISPLAY_VALUE_RE = /^%"(?:[\x20-\x21\x23-\x24\x26-\x5b\x5d-\x7e]|\\|%[0-9a-f]{2})*"$/;
|
|
475
|
+
function isWellFormedParam(param) {
|
|
476
|
+
const eq = param.indexOf("=");
|
|
477
|
+
const key = (eq === -1 ? param : param.slice(0, eq)).trim();
|
|
478
|
+
if (key.includes('"')) return false;
|
|
479
|
+
if (eq === -1) return true;
|
|
480
|
+
const value = param.slice(eq + 1).trim();
|
|
481
|
+
if (value.startsWith('"')) return QUOTED_VALUE_RE.test(value);
|
|
482
|
+
if (value.startsWith('%"')) return DISPLAY_VALUE_RE.test(value);
|
|
483
|
+
return !/[\s"]/.test(value);
|
|
484
|
+
}
|
|
485
|
+
function splitOutsideStrings(input, sep) {
|
|
486
|
+
const parts = [];
|
|
487
|
+
let current = "";
|
|
488
|
+
let inString = false;
|
|
489
|
+
let inDisplay = false;
|
|
490
|
+
let escaped = false;
|
|
491
|
+
let prev = "";
|
|
492
|
+
for (const ch of input) {
|
|
493
|
+
if (escaped) escaped = false;
|
|
494
|
+
else if (inString && !inDisplay && ch === "\\") escaped = true;
|
|
495
|
+
else if (ch === '"') {
|
|
496
|
+
if (!inString) inDisplay = prev === "%";
|
|
497
|
+
inString = !inString;
|
|
498
|
+
} else if (ch === sep && !inString) {
|
|
499
|
+
parts.push(current);
|
|
500
|
+
current = "";
|
|
501
|
+
prev = ch;
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
current += ch;
|
|
505
|
+
prev = ch;
|
|
506
|
+
}
|
|
507
|
+
parts.push(current);
|
|
508
|
+
return parts;
|
|
509
|
+
}
|
|
510
|
+
function readParams(params) {
|
|
511
|
+
const values = /* @__PURE__ */ new Map();
|
|
512
|
+
let unreadable = false;
|
|
513
|
+
let valuelessAt = -1;
|
|
514
|
+
for (const [index, param] of params.entries()) {
|
|
515
|
+
const eq = param.indexOf("=");
|
|
516
|
+
const key = (eq === -1 ? param : param.slice(0, eq)).trim().toLowerCase();
|
|
517
|
+
if (!key) continue;
|
|
518
|
+
if (eq === -1) {
|
|
519
|
+
if (key === "r") unreadable = true;
|
|
520
|
+
if (key === "t") values.delete("t");
|
|
521
|
+
valuelessAt = index;
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if ((key === "r" || key === "t") && (values.has(key) || valuelessAt !== -1 && index > valuelessAt)) {
|
|
525
|
+
unreadable = true;
|
|
526
|
+
}
|
|
527
|
+
values.set(key, param.slice(eq + 1));
|
|
528
|
+
}
|
|
529
|
+
return { values, unreadable };
|
|
530
|
+
}
|
|
531
|
+
function parseExhaustedWindows(header) {
|
|
532
|
+
if (!header) return { windows: [], dropped: false };
|
|
533
|
+
const windows = [];
|
|
534
|
+
let dropped = false;
|
|
535
|
+
for (const item of splitOutsideStrings(header, ",")) {
|
|
536
|
+
if (item.trim() === "") continue;
|
|
537
|
+
const [rawName, ...params] = splitOutsideStrings(item, ";");
|
|
538
|
+
if (!params.every(isWellFormedParam)) {
|
|
539
|
+
dropped = true;
|
|
540
|
+
continue;
|
|
541
|
+
}
|
|
542
|
+
const { values, unreadable } = readParams(params);
|
|
543
|
+
if (unreadable) {
|
|
544
|
+
dropped = true;
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
const remaining = remainingRequests(values.get("r"));
|
|
548
|
+
if (remaining === null) {
|
|
549
|
+
dropped = true;
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
if (remaining !== 0) continue;
|
|
553
|
+
windows.push({
|
|
554
|
+
window: windowName(rawName),
|
|
555
|
+
resetS: waitSeconds(values.get("t"))
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
return { windows, dropped };
|
|
559
|
+
}
|
|
560
|
+
function humanWait(seconds) {
|
|
561
|
+
if (seconds < 120) return `~${seconds}s`;
|
|
562
|
+
if (seconds < 3600)
|
|
563
|
+
return `~${Math.ceil(seconds / 60)} minutes (${seconds}s)`;
|
|
564
|
+
if (seconds < 2 * 86400) {
|
|
565
|
+
const hours = Math.ceil(seconds / 3600);
|
|
566
|
+
return `~${hours} hour${hours === 1 ? "" : "s"} (${seconds}s)`;
|
|
567
|
+
}
|
|
568
|
+
return `~${Math.ceil(seconds / 86400)} days (${seconds}s)`;
|
|
569
|
+
}
|
|
570
|
+
function rateLimitHint(rateLimitHeader, retryAfterHeader) {
|
|
571
|
+
const { windows, dropped } = parseExhaustedWindows(rateLimitHeader);
|
|
572
|
+
windows.sort((a, b) => (b.resetS ?? -1) - (a.resetS ?? -1));
|
|
573
|
+
const longestWindow = windows[0];
|
|
574
|
+
const waitCandidates = [
|
|
575
|
+
waitSeconds(retryAfterHeader),
|
|
576
|
+
longestWindow?.resetS
|
|
577
|
+
].filter((n) => typeof n === "number" && n > 0);
|
|
578
|
+
const waitS = waitCandidates.length ? Math.max(...waitCandidates) : null;
|
|
579
|
+
const retryAfterUnreadable = typeof retryAfterHeader === "string" && retryAfterHeader.trim() !== "" && waitSeconds(retryAfterHeader) === null;
|
|
580
|
+
if (!longestWindow && waitS === null) {
|
|
581
|
+
if (!retryAfterUnreadable) return GENERIC_RATE_LIMIT_HINT;
|
|
582
|
+
}
|
|
583
|
+
const namedClause = longestWindow?.window ? `the ${longestWindow.window} quota is exhausted` : "";
|
|
584
|
+
if (waitS === null) {
|
|
585
|
+
const cause = namedClause ? `${namedClause}, but the response gave no usable reset time` : "the response gave no usable reset time";
|
|
586
|
+
return `rate limited \u2014 ${cause}; back off substantially before retrying, and pace bulk operations`;
|
|
587
|
+
}
|
|
588
|
+
const hedge = dropped || retryAfterUnreadable || windows.some((w) => w.resetS === null) ? "at least " : "";
|
|
589
|
+
const wait = `wait ${hedge}${humanWait(waitS)} before retrying, and pace bulk operations`;
|
|
590
|
+
return `rate limited \u2014 ${namedClause ? `${namedClause}; ` : ""}${wait}`;
|
|
591
|
+
}
|
|
592
|
+
|
|
445
593
|
// src/_shared/http.ts
|
|
594
|
+
var EXPIRED_CREDENTIAL_HINT = "the Runpod API rejected the credential \u2014 the API key may be expired or revoked; re-authenticate or update RUNPOD_API_KEY";
|
|
446
595
|
var HttpError = class extends Error {
|
|
447
|
-
constructor(prefix, status, body) {
|
|
448
|
-
const
|
|
449
|
-
super(`${prefix}: ${status} - ${
|
|
596
|
+
constructor(prefix, status, body, hint) {
|
|
597
|
+
const shownBody = body.length > 2048 ? `${body.slice(0, 2048)}\u2026 [truncated ${body.length - 2048} chars]` : body;
|
|
598
|
+
super(`${prefix}: ${status} - ${shownBody}${hint ? ` (${hint})` : ""}`);
|
|
450
599
|
this.name = "HttpError";
|
|
451
600
|
this.status = status;
|
|
452
601
|
this.body = body;
|
|
@@ -481,7 +630,11 @@ function createHttpClient(deps) {
|
|
|
481
630
|
throw new HttpError(
|
|
482
631
|
deps.errorPrefix,
|
|
483
632
|
response.status,
|
|
484
|
-
await response.text()
|
|
633
|
+
await response.text(),
|
|
634
|
+
response.status === 429 ? rateLimitHint(
|
|
635
|
+
response.headers.get("ratelimit"),
|
|
636
|
+
response.headers.get("retry-after")
|
|
637
|
+
) : response.status === 401 ? EXPIRED_CREDENTIAL_HINT : void 0
|
|
485
638
|
);
|
|
486
639
|
}
|
|
487
640
|
return isJsonContentType(response.headers.get("content-type")) ? response.json() : { success: true, status: response.status };
|
|
@@ -540,7 +693,15 @@ async function readSseSnapshot(fetchImpl, url, headers, opts) {
|
|
|
540
693
|
throw new HttpError(
|
|
541
694
|
"Runpod API Error",
|
|
542
695
|
res.status,
|
|
543
|
-
await res.text().catch(() => "")
|
|
696
|
+
await res.text().catch(() => ""),
|
|
697
|
+
// This throw bypasses createHttpClient, so the status hints are built
|
|
698
|
+
// here too or these two tools alone return a bare 429/401. The 401
|
|
699
|
+
// hint applies: this request always carries Authorization (see the
|
|
700
|
+
// headers bound in runtime.ts streamSse).
|
|
701
|
+
res.status === 429 ? rateLimitHint(
|
|
702
|
+
res.headers.get("ratelimit"),
|
|
703
|
+
res.headers.get("retry-after")
|
|
704
|
+
) : res.status === 401 ? EXPIRED_CREDENTIAL_HINT : void 0
|
|
544
705
|
);
|
|
545
706
|
}
|
|
546
707
|
for await (const chunk of res.body ?? []) {
|
|
@@ -603,7 +764,7 @@ async function streamLogsReply(rt, tool, params) {
|
|
|
603
764
|
}
|
|
604
765
|
|
|
605
766
|
// src/tools/runtime.ts
|
|
606
|
-
var MCP_SERVER_VERSION = true ? "3.
|
|
767
|
+
var MCP_SERVER_VERSION = true ? "3.2.0" : "dev";
|
|
607
768
|
var SESSION_ID = randomUUID();
|
|
608
769
|
function trackingHeaders(server, ctx) {
|
|
609
770
|
const info = server.server.getClientVersion();
|
|
@@ -653,6 +814,36 @@ async function graphqlRequest(query, tracking, fetchImpl, url, options) {
|
|
|
653
814
|
...options?.variables ? { variables: options.variables } : {}
|
|
654
815
|
})
|
|
655
816
|
});
|
|
817
|
+
if (!response.ok) {
|
|
818
|
+
const bodyText = await response.text();
|
|
819
|
+
let gqlErrors;
|
|
820
|
+
try {
|
|
821
|
+
gqlErrors = JSON.parse(bodyText).errors;
|
|
822
|
+
} catch {
|
|
823
|
+
}
|
|
824
|
+
if (Array.isArray(gqlErrors) && gqlErrors.length > 0 && response.status !== 401 && response.status !== 429) {
|
|
825
|
+
throw new HttpError(
|
|
826
|
+
"Runpod GraphQL Error",
|
|
827
|
+
response.status,
|
|
828
|
+
gqlErrors.map((e) => String(e?.message ?? JSON.stringify(e))).join(", ")
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
throw new HttpError(
|
|
832
|
+
"Runpod GraphQL Error",
|
|
833
|
+
response.status,
|
|
834
|
+
bodyText,
|
|
835
|
+
response.status === 429 ? rateLimitHint(
|
|
836
|
+
response.headers.get("ratelimit"),
|
|
837
|
+
response.headers.get("retry-after")
|
|
838
|
+
) : (
|
|
839
|
+
// Only when this request actually carried the caller's API key: the
|
|
840
|
+
// public path sends no Authorization header, so a 401 from that
|
|
841
|
+
// host (WAF, misconfigured RUNPOD_PUBLIC_GRAPHQL_URL) says nothing
|
|
842
|
+
// about the credential — same rationale as observeUnauthorized.
|
|
843
|
+
response.status === 401 && options?.apiKey ? EXPIRED_CREDENTIAL_HINT : void 0
|
|
844
|
+
)
|
|
845
|
+
);
|
|
846
|
+
}
|
|
656
847
|
const result = await response.json();
|
|
657
848
|
if (result.errors && result.errors.length > 0) {
|
|
658
849
|
throw new Error(
|
|
@@ -1069,6 +1260,178 @@ function registerCatalogTools(server, rt) {
|
|
|
1069
1260
|
return jsonReply2(result);
|
|
1070
1261
|
}
|
|
1071
1262
|
);
|
|
1263
|
+
server.tool(
|
|
1264
|
+
"get-capacity",
|
|
1265
|
+
"GPU capacity across host CUDA versions, as a matrix. Use this to choose an endpoint's allowedCudaVersions/minCudaVersion (or diagnose/widen a capacity-starved one) and to distinguish capacity problems from compatibility problems. Default mode is one call returning, per GPU type, overall stock plus AVAILABLE/UNAVAILABLE per host-reported CUDA version. Pass cudaVersions to deep-probe instead: one stock lookup per listed version, returning graded stock (High/Medium/Low/Out) and the lowest on-demand price per version; a probe that fails transiently reports a per-version error instead of failing the call. Nothing is hidden by default \u2014 set includeUnavailable:false to drop GPUs with no stock on any listed version. Credential-free public catalog data; works on both v1 and v2 APIs. Stock is live, so page cursors can shift between calls. Note: the matrix reflects host-reported versions, but endpoint allowedCudaVersions only accepts values from the platform enum \u2014 check create-endpoint/update-endpoint for the accepted list.",
|
|
1266
|
+
{
|
|
1267
|
+
...listPaginationParams,
|
|
1268
|
+
cudaVersions: z3.array(z3.string().regex(/^\d{1,2}\.\d{1,2}$/)).min(1).max(12).optional().describe(
|
|
1269
|
+
'Deep-probe these host CUDA versions (e.g. ["12.8", "13.0"], max 12): one stock lookup per version returns graded stock and price. Omit for the single-call AVAILABLE/UNAVAILABLE matrix across all versions the fleet currently reports.'
|
|
1270
|
+
),
|
|
1271
|
+
includeUnavailable: z3.boolean().optional().describe(
|
|
1272
|
+
'Out-of-stock GPUs are included by default (explicit "Out" cells / all-UNAVAILABLE rows, sorted last). Set false to hide GPUs with no stock on any listed version.'
|
|
1273
|
+
),
|
|
1274
|
+
gpuTypeIds: z3.array(z3.string()).optional().describe(
|
|
1275
|
+
"Filter to GPU types matching any of these ids or display names (case-insensitive substring, e.g. ['NVIDIA GeForce RTX 4090'] or ['4090', 'H200'])."
|
|
1276
|
+
),
|
|
1277
|
+
gpuCount: z3.number().int().min(1).max(8).optional().describe("GPUs per worker/pod to check stock for (default 1)."),
|
|
1278
|
+
secureCloudOnly: z3.boolean().optional().describe("Restrict the stock lookup to Secure Cloud hosts.")
|
|
1279
|
+
},
|
|
1280
|
+
{ title: "Get GPU capacity by CUDA version", ...READ_ONLY },
|
|
1281
|
+
async (params) => {
|
|
1282
|
+
const gpuCount = Math.min(
|
|
1283
|
+
8,
|
|
1284
|
+
Math.max(1, Math.floor(Number(params.gpuCount)) || 1)
|
|
1285
|
+
);
|
|
1286
|
+
const secureArg = params.secureCloudOnly ? ", secureCloud: true" : "";
|
|
1287
|
+
const filterTerms = (params.gpuTypeIds ?? []).filter((t) => typeof t === "string" && t.trim().length > 0).map((t) => t.toLowerCase());
|
|
1288
|
+
const matchesFilter = (gpu) => {
|
|
1289
|
+
if (filterTerms.length === 0) return true;
|
|
1290
|
+
const id = gpu.id.toLowerCase();
|
|
1291
|
+
const name = gpu.displayName.toLowerCase();
|
|
1292
|
+
return filterTerms.some(
|
|
1293
|
+
(term) => id.includes(term) || name.includes(term)
|
|
1294
|
+
);
|
|
1295
|
+
};
|
|
1296
|
+
const stockPriority = {
|
|
1297
|
+
High: 3,
|
|
1298
|
+
Medium: 2,
|
|
1299
|
+
Low: 1
|
|
1300
|
+
};
|
|
1301
|
+
if (!params.cudaVersions?.length) {
|
|
1302
|
+
const data = await graphql(`
|
|
1303
|
+
query {
|
|
1304
|
+
gpuTypes {
|
|
1305
|
+
id
|
|
1306
|
+
displayName
|
|
1307
|
+
memoryInGb
|
|
1308
|
+
secureCloud
|
|
1309
|
+
communityCloud
|
|
1310
|
+
lowestPrice(input: { gpuCount: ${gpuCount}${secureArg} }) {
|
|
1311
|
+
stockStatus
|
|
1312
|
+
uninterruptablePrice
|
|
1313
|
+
gpuTypeCudaVersions {
|
|
1314
|
+
cudaVersion
|
|
1315
|
+
availability
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
`);
|
|
1321
|
+
let rows2 = data.gpuTypes.filter((gpu) => gpu.id !== "unknown" && matchesFilter(gpu)).map((gpu) => {
|
|
1322
|
+
const cuda = {};
|
|
1323
|
+
for (const c of gpu.lowestPrice?.gpuTypeCudaVersions ?? []) {
|
|
1324
|
+
cuda[c.cudaVersion] = c.availability;
|
|
1325
|
+
}
|
|
1326
|
+
return {
|
|
1327
|
+
id: gpu.id,
|
|
1328
|
+
displayName: gpu.displayName,
|
|
1329
|
+
memoryGb: gpu.memoryInGb,
|
|
1330
|
+
secureCloud: gpu.secureCloud,
|
|
1331
|
+
communityCloud: gpu.communityCloud,
|
|
1332
|
+
stockStatus: gpu.lowestPrice?.stockStatus || "unavailable",
|
|
1333
|
+
pricePerHr: gpu.lowestPrice?.uninterruptablePrice ?? null,
|
|
1334
|
+
cudaVersions: cuda
|
|
1335
|
+
};
|
|
1336
|
+
});
|
|
1337
|
+
const availableCount = (r) => Object.values(r.cudaVersions).filter((a) => a === "AVAILABLE").length;
|
|
1338
|
+
if (params.includeUnavailable === false)
|
|
1339
|
+
rows2 = rows2.filter((r) => availableCount(r) > 0);
|
|
1340
|
+
rows2.sort((a, b) => {
|
|
1341
|
+
const diff = availableCount(b) - availableCount(a);
|
|
1342
|
+
if (diff !== 0) return diff;
|
|
1343
|
+
const stockDiff = (stockPriority[b.stockStatus] || 0) - (stockPriority[a.stockStatus] || 0);
|
|
1344
|
+
if (stockDiff !== 0) return stockDiff;
|
|
1345
|
+
return b.memoryGb - a.memoryGb;
|
|
1346
|
+
});
|
|
1347
|
+
return capListResult(rows2, {
|
|
1348
|
+
limit: params.limit,
|
|
1349
|
+
cursor: params.cursor
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
const versions = [...new Set(params.cudaVersions)].slice(0, 12);
|
|
1353
|
+
const invalid = versions.filter((v) => !/^\d{1,2}\.\d{1,2}$/.test(v));
|
|
1354
|
+
if (invalid.length > 0) {
|
|
1355
|
+
return jsonReply2({
|
|
1356
|
+
error: `Invalid CUDA version format: ${invalid.join(", ")}. Use "major.minor" strings like "12.8".`,
|
|
1357
|
+
status: 400
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
const perVersion = await Promise.allSettled(
|
|
1361
|
+
versions.map(
|
|
1362
|
+
(v) => graphql(`
|
|
1363
|
+
query {
|
|
1364
|
+
gpuTypes {
|
|
1365
|
+
id
|
|
1366
|
+
displayName
|
|
1367
|
+
memoryInGb
|
|
1368
|
+
secureCloud
|
|
1369
|
+
communityCloud
|
|
1370
|
+
lowestPrice(input: { gpuCount: ${gpuCount}, allowedCudaVersions: ["${v}"]${secureArg} }) {
|
|
1371
|
+
stockStatus
|
|
1372
|
+
uninterruptablePrice
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
`)
|
|
1377
|
+
)
|
|
1378
|
+
);
|
|
1379
|
+
const probeErrors = {};
|
|
1380
|
+
const byId = /* @__PURE__ */ new Map();
|
|
1381
|
+
versions.forEach((v, i) => {
|
|
1382
|
+
const settled = perVersion[i];
|
|
1383
|
+
if (settled.status === "rejected") {
|
|
1384
|
+
probeErrors[v] = settled.reason instanceof Error ? settled.reason.message : String(settled.reason);
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
for (const gpu of settled.value.gpuTypes) {
|
|
1388
|
+
if (gpu.id === "unknown" || !matchesFilter(gpu)) continue;
|
|
1389
|
+
let row = byId.get(gpu.id);
|
|
1390
|
+
if (!row) {
|
|
1391
|
+
row = {
|
|
1392
|
+
id: gpu.id,
|
|
1393
|
+
displayName: gpu.displayName,
|
|
1394
|
+
memoryGb: gpu.memoryInGb,
|
|
1395
|
+
secureCloud: gpu.secureCloud,
|
|
1396
|
+
communityCloud: gpu.communityCloud,
|
|
1397
|
+
cudaVersions: {}
|
|
1398
|
+
};
|
|
1399
|
+
byId.set(gpu.id, row);
|
|
1400
|
+
}
|
|
1401
|
+
const stock = gpu.lowestPrice?.stockStatus;
|
|
1402
|
+
row.cudaVersions[v] = !stock || stock === "Out" ? { stock: "Out", pricePerHr: null } : {
|
|
1403
|
+
stock,
|
|
1404
|
+
pricePerHr: gpu.lowestPrice?.uninterruptablePrice ?? null
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1408
|
+
let rows = [...byId.values()];
|
|
1409
|
+
const inStockCount = (r) => Object.values(r.cudaVersions).filter((c) => c.stock !== "Out").length;
|
|
1410
|
+
if (params.includeUnavailable === false)
|
|
1411
|
+
rows = rows.filter((r) => inStockCount(r) > 0);
|
|
1412
|
+
rows.sort((a, b) => {
|
|
1413
|
+
const diff = inStockCount(b) - inStockCount(a);
|
|
1414
|
+
if (diff !== 0) return diff;
|
|
1415
|
+
const best = (r) => Math.max(
|
|
1416
|
+
0,
|
|
1417
|
+
...Object.values(r.cudaVersions).map(
|
|
1418
|
+
(c) => stockPriority[c.stock] || 0
|
|
1419
|
+
)
|
|
1420
|
+
);
|
|
1421
|
+
const bestDiff = best(b) - best(a);
|
|
1422
|
+
if (bestDiff !== 0) return bestDiff;
|
|
1423
|
+
return b.memoryGb - a.memoryGb;
|
|
1424
|
+
});
|
|
1425
|
+
return capListResult(
|
|
1426
|
+
rows,
|
|
1427
|
+
{ limit: params.limit, cursor: params.cursor },
|
|
1428
|
+
{
|
|
1429
|
+
probedCudaVersions: versions,
|
|
1430
|
+
...Object.keys(probeErrors).length > 0 ? { probeErrors } : {}
|
|
1431
|
+
}
|
|
1432
|
+
);
|
|
1433
|
+
}
|
|
1434
|
+
);
|
|
1072
1435
|
server.tool(
|
|
1073
1436
|
"get-data-center",
|
|
1074
1437
|
"Get details for a single data center by id. v2-only \u2014 returns a 501 notice on the v1 API (use list-data-centers there).",
|
|
@@ -1753,7 +2116,9 @@ function registerPodTools(server, rt) {
|
|
|
1753
2116
|
"create-pod",
|
|
1754
2117
|
'Create a new GPU/CPU pod on Runpod. Pass gpuTypeIds for a GPU pod, or computeType:"CPU" for a CPU pod (CPU pods are served by the v1 API for now). Pass either imageName or templateId (templateId deploys from an existing template \u2014 its name, image, start command, ports, env, disk, volume, and registry credential are used as defaults, and any field you also pass explicitly replaces the template value for that field, e.g. passing env replaces the whole env set rather than merging; pass containerRegistryAuthId to override or supply a private-image credential, or an empty string to deploy with none). If the user specifies neither an image nor a template, recommend the "Runpod Pytorch 2.8.0" image (runpod/pytorch:1.0.2-cu1281-torch280-ubuntu2404) as the default \u2014 it has the most up-to-date CUDA and PyTorch versions.',
|
|
1755
2118
|
{
|
|
1756
|
-
name: z7.string().optional().describe(
|
|
2119
|
+
name: z7.string().optional().describe(
|
|
2120
|
+
"Name for the pod. Required on v2 unless deploying from a templateId (the template supplies its name as the default)."
|
|
2121
|
+
),
|
|
1757
2122
|
imageName: z7.string().optional().describe("Docker image to use. Optional when templateId is provided."),
|
|
1758
2123
|
templateId: z7.string().optional().describe(
|
|
1759
2124
|
"Deploy from an existing template (see list-templates / get-template). The template supplies name, image, start command, ports, env, disk, volume, and registry credential as defaults; any field you also pass replaces the template value for that field (whole-field, not a merge). Override the registry credential with containerRegistryAuthId. Requires the v2 REST API. Still pass gpuTypeIds or computeType to choose the compute \u2014 a template does not pin the pod compute."
|
|
@@ -1812,6 +2177,12 @@ function registerPodTools(server, rt) {
|
|
|
1812
2177
|
status: 400
|
|
1813
2178
|
});
|
|
1814
2179
|
}
|
|
2180
|
+
if (!wantsCpu && !params.name && !params.templateId) {
|
|
2181
|
+
return jsonReply2({
|
|
2182
|
+
error: "Provide a name for the pod (deploying from a templateId inherits the template name).",
|
|
2183
|
+
status: 400
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
1815
2186
|
if (wantsCpu) {
|
|
1816
2187
|
if (params.templateId) {
|
|
1817
2188
|
return jsonReply2({
|