@mcpjam/cli 3.9.0 → 3.10.1
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/dist/index.js +431 -20
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command, CommanderError } from 'commander';
|
|
3
|
-
import { realpathSync,
|
|
4
|
-
import { pathToFileURL
|
|
3
|
+
import { realpathSync, mkdirSync, writeFileSync, readFileSync, existsSync, statSync, closeSync, renameSync, openSync } from 'fs';
|
|
4
|
+
import { pathToFileURL } from 'url';
|
|
5
5
|
import { probeMcpServer, redactSensitiveValue, runServerDoctor, collectServerSnapshot, serializeStableServerSnapshot, serializeServerSnapshot, buildServerDiffReport, validateToolCallResult, isCallToolResultError, buildToolCallValidationReport, listResources, readResource, listPrompts, getPrompt, MCPAppsConformanceTest, MCPAppsConformanceSuite, runOAuthLogin, OAuthConformanceTest, OAuthConformanceSuite, MCPConformanceTest, MCPConformanceSuite, withEphemeralClient, diffServerSnapshots, ServerSnapshotFormatError, renderStructuredRunJUnitXml, renderStructuredRunJson, toConformanceReport, renderConformanceReportJUnitXml, renderConformanceReportJson, formatOAuthConformanceHuman, formatOAuthConformanceSuiteHuman, fetchOAuthMetadata, executeOAuthProxy, executeDebugOAuthProxy, generateRandomString, generateCodeChallenge, createInteractiveAuthorizationSession, openUrlInBrowser, MCPClientManager, MCP_APPS_CHECK_CATEGORIES, MCP_APPS_CHECK_IDS, OAuthProxyError, MCP_CHECK_CATEGORIES, MCP_CHECK_IDS } from '@mcpjam/sdk';
|
|
6
6
|
import { mkdir, writeFile, readFile, chmod, rename, rm } from 'fs/promises';
|
|
7
|
-
import path2, {
|
|
7
|
+
import path2, { dirname, join, basename } from 'path';
|
|
8
8
|
import { randomUUID } from 'crypto';
|
|
9
9
|
import { spawn } from 'child_process';
|
|
10
|
+
import { createRequire } from 'module';
|
|
10
11
|
import os, { homedir } from 'os';
|
|
11
|
-
import { listEvalRunIterationsOperation, getEvalIterationTraceOperation, getEvalSuiteOperation, updateEvalSuiteOperation, deleteEvalSuiteOperation, setEvalSuiteScheduleOperation, listEvalCasesOperation, getEvalCaseOperation, createEvalCaseOperation, updateEvalCaseOperation, deleteEvalCaseOperation, generateEvalCasesOperation, createTunnelOperation, DEFAULT_PLATFORM_API_BASE_URL, PlatformApiClient, isPlatformApiError, PlatformApiError, listProjectsOperation, listProjectServersOperation, showServersOperation, createEvalSuiteOperation, listEvalSuitesOperation, runEvalSuiteOperation, getEvalRunOperation } from '@mcpjam/sdk/platform';
|
|
12
|
+
import { listEvalRunIterationsOperation, getEvalIterationTraceOperation, getEvalSuiteOperation, updateEvalSuiteOperation, deleteEvalSuiteOperation, setEvalSuiteScheduleOperation, listEvalCasesOperation, getEvalCaseOperation, createEvalCaseOperation, updateEvalCaseOperation, deleteEvalCaseOperation, generateEvalCasesOperation, createHostOperation, updateHostOperation, createTunnelOperation, DEFAULT_PLATFORM_API_BASE_URL, PlatformApiClient, isPlatformApiError, PlatformApiError, listProjectsOperation, listProjectServersOperation, showServersOperation, createEvalSuiteOperation, listEvalSuitesOperation, runEvalSuiteOperation, getEvalRunOperation, listHostsOperation, getHostOperation, deleteHostOperation } from '@mcpjam/sdk/platform';
|
|
13
|
+
import { HOST_TEMPLATES as HOST_TEMPLATES$1 } from '@mcpjam/sdk/host-config/templates';
|
|
12
14
|
import { StdioServerTransport, McpServer } from '@modelcontextprotocol/server';
|
|
13
15
|
import { z } from 'zod';
|
|
14
16
|
import { PostHog } from 'posthog-node';
|
|
@@ -19,7 +21,7 @@ import { WebSocket } from 'ws';
|
|
|
19
21
|
|
|
20
22
|
// package.json
|
|
21
23
|
var package_default = {
|
|
22
|
-
version: "3.
|
|
24
|
+
version: "3.10.1"};
|
|
23
25
|
|
|
24
26
|
// src/lib/output.ts
|
|
25
27
|
var DEFAULT_OUTPUT_FORMAT = "json";
|
|
@@ -1112,6 +1114,7 @@ function normalizeOptionalAuthValue(value) {
|
|
|
1112
1114
|
const trimmed = value?.trim();
|
|
1113
1115
|
return trimmed ? trimmed : void 0;
|
|
1114
1116
|
}
|
|
1117
|
+
var require2 = createRequire(import.meta.url);
|
|
1115
1118
|
var FALLBACK_INSPECTOR_BASE_URL = "http://127.0.0.1:6274";
|
|
1116
1119
|
var DEFAULT_START_TIMEOUT_MS = 3e4;
|
|
1117
1120
|
var DEFAULT_COMMAND_TIMEOUT_MS = 3e4;
|
|
@@ -1597,9 +1600,12 @@ async function fetchFreshInspectorSessionToken(normalizedBaseUrl) {
|
|
|
1597
1600
|
return body.token;
|
|
1598
1601
|
}
|
|
1599
1602
|
function getInspectorStartScriptPath() {
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
+
try {
|
|
1604
|
+
const packageJsonPath = require2.resolve("@mcpjam/inspector/package.json");
|
|
1605
|
+
return path2.resolve(path2.dirname(packageJsonPath), "bin/start.js");
|
|
1606
|
+
} catch {
|
|
1607
|
+
return void 0;
|
|
1608
|
+
}
|
|
1603
1609
|
}
|
|
1604
1610
|
async function getInspectorHealth(baseUrl, timeoutMs = HEALTH_FETCH_TIMEOUT_MS) {
|
|
1605
1611
|
try {
|
|
@@ -1802,15 +1808,15 @@ async function startInspector(baseUrl, timeoutMs) {
|
|
|
1802
1808
|
const parsedUrl = new URL(baseUrl);
|
|
1803
1809
|
const port = parsedUrl.port || "6274";
|
|
1804
1810
|
const startScriptPath = getInspectorStartScriptPath();
|
|
1805
|
-
const
|
|
1806
|
-
const args =
|
|
1807
|
-
const executable =
|
|
1811
|
+
const localStartScriptPath = startScriptPath && existsSync(startScriptPath) ? startScriptPath : void 0;
|
|
1812
|
+
const args = localStartScriptPath ? [localStartScriptPath, "--port", port, "--no-open"] : ["-y", "@mcpjam/inspector@latest", "--port", port, "--no-open"];
|
|
1813
|
+
const executable = localStartScriptPath ? process.execPath : getNpxExecutable();
|
|
1808
1814
|
const logPath = getInspectorStartupLogPath();
|
|
1809
1815
|
const logFd = openStartupLogFile(logPath);
|
|
1810
1816
|
let child;
|
|
1811
1817
|
try {
|
|
1812
1818
|
child = spawn(executable, args, {
|
|
1813
|
-
cwd:
|
|
1819
|
+
cwd: localStartScriptPath ? path2.dirname(localStartScriptPath) : process.cwd(),
|
|
1814
1820
|
detached: true,
|
|
1815
1821
|
stdio: ["ignore", logFd, logFd],
|
|
1816
1822
|
env: {
|
|
@@ -3382,6 +3388,91 @@ function registerAuthCommands(program) {
|
|
|
3382
3388
|
}
|
|
3383
3389
|
});
|
|
3384
3390
|
}
|
|
3391
|
+
|
|
3392
|
+
// src/lib/eval-screenshots.ts
|
|
3393
|
+
function asRecord(value) {
|
|
3394
|
+
return typeof value === "object" && value !== null ? value : null;
|
|
3395
|
+
}
|
|
3396
|
+
function asString(value) {
|
|
3397
|
+
return typeof value === "string" ? value : void 0;
|
|
3398
|
+
}
|
|
3399
|
+
function extractRenderedScreenshots(result) {
|
|
3400
|
+
const root = asRecord(result);
|
|
3401
|
+
if (!root) return [];
|
|
3402
|
+
const trace = asRecord(root.trace) ?? root;
|
|
3403
|
+
const observations = trace.widgetRenderObservations;
|
|
3404
|
+
if (!Array.isArray(observations)) return [];
|
|
3405
|
+
const screenshots = [];
|
|
3406
|
+
for (const entry of observations) {
|
|
3407
|
+
const obs = asRecord(entry);
|
|
3408
|
+
if (!obs) continue;
|
|
3409
|
+
const status = asString(obs.status);
|
|
3410
|
+
const screenshotUrl = asString(obs.screenshotUrl);
|
|
3411
|
+
if (status !== "rendered" || !screenshotUrl) continue;
|
|
3412
|
+
screenshots.push({
|
|
3413
|
+
status,
|
|
3414
|
+
screenshotUrl,
|
|
3415
|
+
toolName: asString(obs.toolName),
|
|
3416
|
+
toolCallId: asString(obs.toolCallId),
|
|
3417
|
+
promptIndex: typeof obs.promptIndex === "number" ? obs.promptIndex : void 0
|
|
3418
|
+
});
|
|
3419
|
+
}
|
|
3420
|
+
return screenshots;
|
|
3421
|
+
}
|
|
3422
|
+
function screenshotFilename(shot, index) {
|
|
3423
|
+
const tool = (shot.toolName ?? "widget").replace(/[^a-zA-Z0-9_-]+/g, "-");
|
|
3424
|
+
const suffix = shot.toolCallId ? shot.toolCallId.replace(/[^a-zA-Z0-9_-]+/g, "-") : String(index + 1);
|
|
3425
|
+
return `${tool}-${suffix}.png`;
|
|
3426
|
+
}
|
|
3427
|
+
|
|
3428
|
+
// src/lib/terminal-image.ts
|
|
3429
|
+
var ESC = "\x1B";
|
|
3430
|
+
var BEL = "\x07";
|
|
3431
|
+
function detectInlineImageProtocol(env = process.env, isTTY = process.stdout.isTTY) {
|
|
3432
|
+
if (!isTTY) return null;
|
|
3433
|
+
const termProgram = env.TERM_PROGRAM ?? "";
|
|
3434
|
+
const term = env.TERM ?? "";
|
|
3435
|
+
if (term === "xterm-kitty" || env.KITTY_WINDOW_ID !== void 0 || termProgram === "ghostty" || env.GHOSTTY_RESOURCES_DIR !== void 0) {
|
|
3436
|
+
return "kitty";
|
|
3437
|
+
}
|
|
3438
|
+
if (termProgram === "iTerm.app" || termProgram === "WezTerm" || termProgram === "WarpTerminal" || env.LC_TERMINAL === "iTerm2") {
|
|
3439
|
+
return "iterm";
|
|
3440
|
+
}
|
|
3441
|
+
return null;
|
|
3442
|
+
}
|
|
3443
|
+
function toBase64(data) {
|
|
3444
|
+
return Buffer.from(data).toString("base64");
|
|
3445
|
+
}
|
|
3446
|
+
function encodeIterm(data) {
|
|
3447
|
+
const payload = toBase64(data);
|
|
3448
|
+
const args = ["inline=1", `size=${data.byteLength}`, "preserveAspectRatio=1"].join(
|
|
3449
|
+
";"
|
|
3450
|
+
);
|
|
3451
|
+
return `${ESC}]1337;File=${args}:${payload}${BEL}
|
|
3452
|
+
`;
|
|
3453
|
+
}
|
|
3454
|
+
function encodeKitty(data) {
|
|
3455
|
+
const payload = toBase64(data);
|
|
3456
|
+
const CHUNK = 4096;
|
|
3457
|
+
const chunks = [];
|
|
3458
|
+
for (let offset = 0; offset < payload.length; offset += CHUNK) {
|
|
3459
|
+
chunks.push(payload.slice(offset, offset + CHUNK));
|
|
3460
|
+
}
|
|
3461
|
+
if (chunks.length === 0) chunks.push("");
|
|
3462
|
+
let out = "";
|
|
3463
|
+
chunks.forEach((chunk, index) => {
|
|
3464
|
+
const more = index < chunks.length - 1 ? 1 : 0;
|
|
3465
|
+
const control = index === 0 ? `a=T,f=100,m=${more}` : `m=${more}`;
|
|
3466
|
+
out += `${ESC}_G${control};${chunk}${ESC}\\`;
|
|
3467
|
+
});
|
|
3468
|
+
return `${out}
|
|
3469
|
+
`;
|
|
3470
|
+
}
|
|
3471
|
+
function encodeInlineImage(data, protocol) {
|
|
3472
|
+
return protocol === "kitty" ? encodeKitty(data) : encodeIterm(data);
|
|
3473
|
+
}
|
|
3474
|
+
|
|
3475
|
+
// src/commands/eval.ts
|
|
3385
3476
|
function addPlatformOptions(command) {
|
|
3386
3477
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
3387
3478
|
"--api-url <url>",
|
|
@@ -3556,6 +3647,43 @@ function buildCaseInput(options, opts) {
|
|
|
3556
3647
|
if (options.title !== void 0) input.title = options.title;
|
|
3557
3648
|
return input;
|
|
3558
3649
|
}
|
|
3650
|
+
async function fetchScreenshotBytes(url, timeoutMs) {
|
|
3651
|
+
const controller = new AbortController();
|
|
3652
|
+
const handle = setTimeout(() => controller.abort(), timeoutMs);
|
|
3653
|
+
handle.unref?.();
|
|
3654
|
+
try {
|
|
3655
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
3656
|
+
if (!response.ok) {
|
|
3657
|
+
throw operationalError(
|
|
3658
|
+
`Failed to download screenshot (HTTP ${response.status}).`,
|
|
3659
|
+
{ url }
|
|
3660
|
+
);
|
|
3661
|
+
}
|
|
3662
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
3663
|
+
} catch (error) {
|
|
3664
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
3665
|
+
throw operationalError(
|
|
3666
|
+
`Timed out downloading screenshot after ${timeoutMs}ms.`,
|
|
3667
|
+
{ url }
|
|
3668
|
+
);
|
|
3669
|
+
}
|
|
3670
|
+
throw error;
|
|
3671
|
+
} finally {
|
|
3672
|
+
clearTimeout(handle);
|
|
3673
|
+
}
|
|
3674
|
+
}
|
|
3675
|
+
function resolveScreenshotPath(out, shot, index, total) {
|
|
3676
|
+
const looksLikeDir = out.endsWith("/") || existsSync(out) && statSync(out).isDirectory();
|
|
3677
|
+
if (looksLikeDir) {
|
|
3678
|
+
return join(out, screenshotFilename(shot, index));
|
|
3679
|
+
}
|
|
3680
|
+
if (total > 1) {
|
|
3681
|
+
throw usageError(
|
|
3682
|
+
"--out must be a directory when the iteration rendered multiple screenshots."
|
|
3683
|
+
);
|
|
3684
|
+
}
|
|
3685
|
+
return out;
|
|
3686
|
+
}
|
|
3559
3687
|
function registerEvalCommands(program) {
|
|
3560
3688
|
const evals = program.command("eval").description("Author and run eval suites in your hosted MCPJam projects");
|
|
3561
3689
|
addPlatformOptions(
|
|
@@ -3692,6 +3820,114 @@ function registerEvalCommands(program) {
|
|
|
3692
3820
|
);
|
|
3693
3821
|
}
|
|
3694
3822
|
);
|
|
3823
|
+
addPlatformOptions(
|
|
3824
|
+
evals.command("screenshot").description(
|
|
3825
|
+
"Show the widget screenshot(s) an eval iteration rendered \u2014 inline when the terminal supports it, otherwise the image URL"
|
|
3826
|
+
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
3827
|
+
"--iteration <id>",
|
|
3828
|
+
"Iteration ID (from `eval iterations`)"
|
|
3829
|
+
).requiredOption(
|
|
3830
|
+
"--project <id-or-name>",
|
|
3831
|
+
"Project the run belongs to (name or ID)"
|
|
3832
|
+
).option(
|
|
3833
|
+
"--out <path>",
|
|
3834
|
+
"Save the PNG(s) to a file or directory instead of rendering inline"
|
|
3835
|
+
).option("--index <n>", "Show only the Nth screenshot (1-based)")
|
|
3836
|
+
).action(
|
|
3837
|
+
async (options, command) => {
|
|
3838
|
+
const globalOptions = getGlobalOptions(command);
|
|
3839
|
+
const index = options.index !== void 0 ? parsePositiveInteger(options.index, "--index") : void 0;
|
|
3840
|
+
const result = await runPlatformCommand(
|
|
3841
|
+
options,
|
|
3842
|
+
globalOptions.timeout,
|
|
3843
|
+
({ client, signal }) => getEvalIterationTraceOperation.execute(
|
|
3844
|
+
{
|
|
3845
|
+
project: options.project,
|
|
3846
|
+
runId: options.run,
|
|
3847
|
+
iterationId: options.iteration
|
|
3848
|
+
},
|
|
3849
|
+
{ client, signal }
|
|
3850
|
+
)
|
|
3851
|
+
);
|
|
3852
|
+
let shots = extractRenderedScreenshots(result);
|
|
3853
|
+
if (index !== void 0) {
|
|
3854
|
+
if (index > shots.length) {
|
|
3855
|
+
throw usageError(
|
|
3856
|
+
`--index ${index} is out of range; this iteration rendered ${shots.length} screenshot(s).`
|
|
3857
|
+
);
|
|
3858
|
+
}
|
|
3859
|
+
shots = [shots[index - 1]];
|
|
3860
|
+
}
|
|
3861
|
+
const base = {
|
|
3862
|
+
project: result.project,
|
|
3863
|
+
runId: result.runId,
|
|
3864
|
+
iterationId: result.iterationId
|
|
3865
|
+
};
|
|
3866
|
+
const isJson = globalOptions.format === "json";
|
|
3867
|
+
if (options.out !== void 0) {
|
|
3868
|
+
const saved = [];
|
|
3869
|
+
for (let i = 0; i < shots.length; i += 1) {
|
|
3870
|
+
const shot = shots[i];
|
|
3871
|
+
const bytes = await fetchScreenshotBytes(
|
|
3872
|
+
shot.screenshotUrl,
|
|
3873
|
+
globalOptions.timeout
|
|
3874
|
+
);
|
|
3875
|
+
const path6 = resolveScreenshotPath(
|
|
3876
|
+
options.out,
|
|
3877
|
+
shot,
|
|
3878
|
+
i,
|
|
3879
|
+
shots.length
|
|
3880
|
+
);
|
|
3881
|
+
mkdirSync(dirname(path6), { recursive: true });
|
|
3882
|
+
writeFileSync(path6, bytes);
|
|
3883
|
+
saved.push({ ...shot, savedTo: path6 });
|
|
3884
|
+
}
|
|
3885
|
+
if (isJson) {
|
|
3886
|
+
writeResult({ ...base, items: saved });
|
|
3887
|
+
return;
|
|
3888
|
+
}
|
|
3889
|
+
if (saved.length === 0) {
|
|
3890
|
+
process.stdout.write(
|
|
3891
|
+
"No rendered widget screenshots for this iteration.\n"
|
|
3892
|
+
);
|
|
3893
|
+
return;
|
|
3894
|
+
}
|
|
3895
|
+
for (const shot of saved) {
|
|
3896
|
+
process.stdout.write(
|
|
3897
|
+
`Saved ${shot.toolName ?? "widget"} \u2192 ${shot.savedTo}
|
|
3898
|
+
`
|
|
3899
|
+
);
|
|
3900
|
+
}
|
|
3901
|
+
return;
|
|
3902
|
+
}
|
|
3903
|
+
if (isJson) {
|
|
3904
|
+
writeResult({ ...base, items: shots });
|
|
3905
|
+
return;
|
|
3906
|
+
}
|
|
3907
|
+
if (shots.length === 0) {
|
|
3908
|
+
process.stdout.write(
|
|
3909
|
+
"No rendered widget screenshots for this iteration.\n"
|
|
3910
|
+
);
|
|
3911
|
+
return;
|
|
3912
|
+
}
|
|
3913
|
+
const protocol = detectInlineImageProtocol();
|
|
3914
|
+
for (const shot of shots) {
|
|
3915
|
+
const caption = `${shot.toolName ?? "widget"} \xB7 ${shot.status}`;
|
|
3916
|
+
if (protocol) {
|
|
3917
|
+
const bytes = await fetchScreenshotBytes(
|
|
3918
|
+
shot.screenshotUrl,
|
|
3919
|
+
globalOptions.timeout
|
|
3920
|
+
);
|
|
3921
|
+
process.stdout.write(`${caption}
|
|
3922
|
+
`);
|
|
3923
|
+
process.stdout.write(encodeInlineImage(bytes, protocol));
|
|
3924
|
+
} else {
|
|
3925
|
+
process.stdout.write(`${caption} ${shot.screenshotUrl}
|
|
3926
|
+
`);
|
|
3927
|
+
}
|
|
3928
|
+
}
|
|
3929
|
+
}
|
|
3930
|
+
);
|
|
3695
3931
|
addPlatformOptions(
|
|
3696
3932
|
evals.command("get").description("Show an eval suite's full settings").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT)
|
|
3697
3933
|
).action(
|
|
@@ -3852,6 +4088,180 @@ function registerEvalCommands(program) {
|
|
|
3852
4088
|
}
|
|
3853
4089
|
);
|
|
3854
4090
|
}
|
|
4091
|
+
var HOST_TEMPLATES = HOST_TEMPLATES$1.map(({ id, label }) => ({ id, label }));
|
|
4092
|
+
function addPlatformOptions2(command) {
|
|
4093
|
+
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
4094
|
+
"--api-url <url>",
|
|
4095
|
+
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
4096
|
+
);
|
|
4097
|
+
}
|
|
4098
|
+
async function runPlatformCommand2(options, timeoutMs, execute) {
|
|
4099
|
+
const controller = new AbortController();
|
|
4100
|
+
const timeoutHandle = setTimeout(() => {
|
|
4101
|
+
controller.abort(
|
|
4102
|
+
new PlatformApiError(`Request timed out after ${timeoutMs}ms`, "TIMEOUT", {
|
|
4103
|
+
status: 0
|
|
4104
|
+
})
|
|
4105
|
+
);
|
|
4106
|
+
}, timeoutMs);
|
|
4107
|
+
timeoutHandle.unref?.();
|
|
4108
|
+
try {
|
|
4109
|
+
const { client } = buildPlatformClient({ ...options, timeoutMs });
|
|
4110
|
+
return await execute({ client, signal: controller.signal });
|
|
4111
|
+
} catch (error) {
|
|
4112
|
+
if (controller.signal.aborted && controller.signal.reason instanceof PlatformApiError) {
|
|
4113
|
+
throw toCliError(controller.signal.reason);
|
|
4114
|
+
}
|
|
4115
|
+
throw toCliError(error);
|
|
4116
|
+
} finally {
|
|
4117
|
+
clearTimeout(timeoutHandle);
|
|
4118
|
+
}
|
|
4119
|
+
}
|
|
4120
|
+
function loadConfigObject(options) {
|
|
4121
|
+
if (options.file !== void 0 && options.json !== void 0) {
|
|
4122
|
+
throw usageError("Provide either --file or --json, not both.");
|
|
4123
|
+
}
|
|
4124
|
+
let base;
|
|
4125
|
+
if (options.file !== void 0) {
|
|
4126
|
+
let text;
|
|
4127
|
+
try {
|
|
4128
|
+
text = options.file === "-" ? readFileSync(0, "utf8") : readFileSync(options.file, "utf8");
|
|
4129
|
+
} catch (error) {
|
|
4130
|
+
throw usageError(`Failed to read --file "${options.file}".`, {
|
|
4131
|
+
source: error instanceof Error ? error.message : String(error)
|
|
4132
|
+
});
|
|
4133
|
+
}
|
|
4134
|
+
if (text.trim() === "") throw usageError("--file input is empty.");
|
|
4135
|
+
try {
|
|
4136
|
+
base = JSON.parse(text);
|
|
4137
|
+
} catch (error) {
|
|
4138
|
+
throw usageError("--file must contain valid JSON.", {
|
|
4139
|
+
source: error instanceof Error ? error.message : String(error)
|
|
4140
|
+
});
|
|
4141
|
+
}
|
|
4142
|
+
} else if (options.json !== void 0) {
|
|
4143
|
+
base = new JsonInputContext().parseJsonInputRecord(options.json, "--json");
|
|
4144
|
+
} else {
|
|
4145
|
+
return void 0;
|
|
4146
|
+
}
|
|
4147
|
+
if (typeof base !== "object" || base === null || Array.isArray(base)) {
|
|
4148
|
+
throw usageError("Host config must be a JSON object.");
|
|
4149
|
+
}
|
|
4150
|
+
return base;
|
|
4151
|
+
}
|
|
4152
|
+
function registerHostsCommands(program) {
|
|
4153
|
+
const hosts = program.command("hosts").description("List, create, and manage the hosts in your hosted MCPJam projects");
|
|
4154
|
+
hosts.command("templates").description("List the built-in host templates usable with `hosts create --template`").action((_options, command) => {
|
|
4155
|
+
const globalOptions = getGlobalOptions(command);
|
|
4156
|
+
writeResult({ items: HOST_TEMPLATES }, globalOptions.format);
|
|
4157
|
+
});
|
|
4158
|
+
addPlatformOptions2(
|
|
4159
|
+
hosts.command("list").description("List the hosts saved in a project").option(
|
|
4160
|
+
"--project <id-or-name>",
|
|
4161
|
+
"Project name or ID (defaults to the most recently updated project)"
|
|
4162
|
+
)
|
|
4163
|
+
).action(async (options, command) => {
|
|
4164
|
+
const globalOptions = getGlobalOptions(command);
|
|
4165
|
+
const result = await runPlatformCommand2(
|
|
4166
|
+
options,
|
|
4167
|
+
globalOptions.timeout,
|
|
4168
|
+
({ client, signal }) => listHostsOperation.execute({ project: options.project }, { client, signal })
|
|
4169
|
+
);
|
|
4170
|
+
writeResult(result, globalOptions.format);
|
|
4171
|
+
});
|
|
4172
|
+
addPlatformOptions2(
|
|
4173
|
+
hosts.command("get").description("Show one host's full settings, including its host config").requiredOption("--host <id-or-name>", "Host name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
4174
|
+
).action(
|
|
4175
|
+
async (options, command) => {
|
|
4176
|
+
const globalOptions = getGlobalOptions(command);
|
|
4177
|
+
const result = await runPlatformCommand2(
|
|
4178
|
+
options,
|
|
4179
|
+
globalOptions.timeout,
|
|
4180
|
+
({ client, signal }) => getHostOperation.execute(
|
|
4181
|
+
{ project: options.project, host: options.host },
|
|
4182
|
+
{ client, signal }
|
|
4183
|
+
)
|
|
4184
|
+
);
|
|
4185
|
+
writeResult(result, globalOptions.format);
|
|
4186
|
+
}
|
|
4187
|
+
);
|
|
4188
|
+
addPlatformOptions2(
|
|
4189
|
+
hosts.command("create").description(
|
|
4190
|
+
"Create a host from a built-in template (--template) or a full host config (--file/--json)"
|
|
4191
|
+
).requiredOption("--name <name>", "Display name for the new host").option("--project <id-or-name>", "Project name or ID").option(
|
|
4192
|
+
"--template <id>",
|
|
4193
|
+
"Built-in template id (see `hosts templates`), e.g. claude, chatgpt, cursor"
|
|
4194
|
+
).option(
|
|
4195
|
+
"--theme <theme>",
|
|
4196
|
+
"Theme for the seeded config: light or dark (template only)"
|
|
4197
|
+
).option("--file <path>", "Host config v2 JSON file (or - for stdin)").option("--json <json>", "Inline host config v2 JSON (or @file, or -)")
|
|
4198
|
+
).action(
|
|
4199
|
+
async (options, command) => {
|
|
4200
|
+
const globalOptions = getGlobalOptions(command);
|
|
4201
|
+
const config = loadConfigObject(options);
|
|
4202
|
+
const input = validateInput(createHostOperation, {
|
|
4203
|
+
project: options.project,
|
|
4204
|
+
name: options.name,
|
|
4205
|
+
...options.template !== void 0 ? { template: options.template } : {},
|
|
4206
|
+
...options.theme !== void 0 ? { theme: options.theme } : {},
|
|
4207
|
+
...config !== void 0 ? { config } : {}
|
|
4208
|
+
});
|
|
4209
|
+
const result = await runPlatformCommand2(
|
|
4210
|
+
options,
|
|
4211
|
+
globalOptions.timeout,
|
|
4212
|
+
({ client, signal }) => createHostOperation.execute(input, { client, signal })
|
|
4213
|
+
);
|
|
4214
|
+
writeResult(result, globalOptions.format);
|
|
4215
|
+
}
|
|
4216
|
+
);
|
|
4217
|
+
addPlatformOptions2(
|
|
4218
|
+
hosts.command("update").description("Edit a host's name and/or its host config").requiredOption("--host <id-or-name>", "Host name or ID").option("--project <id-or-name>", "Project name or ID").option("--name <name>", "New display name").option("--file <path>", "Replacement host config v2 JSON (or - for stdin)").option("--json <json>", "Inline replacement host config v2 JSON (or @file, or -)")
|
|
4219
|
+
).action(
|
|
4220
|
+
async (options, command) => {
|
|
4221
|
+
const globalOptions = getGlobalOptions(command);
|
|
4222
|
+
const config = loadConfigObject(options);
|
|
4223
|
+
const input = validateInput(updateHostOperation, {
|
|
4224
|
+
project: options.project,
|
|
4225
|
+
host: options.host,
|
|
4226
|
+
...options.name !== void 0 ? { name: options.name } : {},
|
|
4227
|
+
...config !== void 0 ? { config } : {}
|
|
4228
|
+
});
|
|
4229
|
+
const result = await runPlatformCommand2(
|
|
4230
|
+
options,
|
|
4231
|
+
globalOptions.timeout,
|
|
4232
|
+
({ client, signal }) => updateHostOperation.execute(input, { client, signal })
|
|
4233
|
+
);
|
|
4234
|
+
writeResult(result, globalOptions.format);
|
|
4235
|
+
}
|
|
4236
|
+
);
|
|
4237
|
+
addPlatformOptions2(
|
|
4238
|
+
hosts.command("delete").description("Permanently delete a host from a project").requiredOption("--host <id-or-name>", "Host name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
4239
|
+
).action(
|
|
4240
|
+
async (options, command) => {
|
|
4241
|
+
const globalOptions = getGlobalOptions(command);
|
|
4242
|
+
const result = await runPlatformCommand2(
|
|
4243
|
+
options,
|
|
4244
|
+
globalOptions.timeout,
|
|
4245
|
+
({ client, signal }) => deleteHostOperation.execute(
|
|
4246
|
+
{
|
|
4247
|
+
project: options.project,
|
|
4248
|
+
host: options.host
|
|
4249
|
+
},
|
|
4250
|
+
{ client, signal }
|
|
4251
|
+
)
|
|
4252
|
+
);
|
|
4253
|
+
writeResult(result, globalOptions.format);
|
|
4254
|
+
}
|
|
4255
|
+
);
|
|
4256
|
+
}
|
|
4257
|
+
function validateInput(op, raw) {
|
|
4258
|
+
const parsed = op.inputSchema.safeParse(raw);
|
|
4259
|
+
if (!parsed.success) {
|
|
4260
|
+
const detail = parsed.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
|
|
4261
|
+
throw usageError(`Invalid input: ${detail}`);
|
|
4262
|
+
}
|
|
4263
|
+
return parsed.data;
|
|
4264
|
+
}
|
|
3855
4265
|
|
|
3856
4266
|
// src/lib/server-doctor.ts
|
|
3857
4267
|
function summarizeServerDoctorTarget(target, config) {
|
|
@@ -4603,13 +5013,13 @@ function statusGlyph(status) {
|
|
|
4603
5013
|
}
|
|
4604
5014
|
|
|
4605
5015
|
// src/commands/projects.ts
|
|
4606
|
-
function
|
|
5016
|
+
function addPlatformOptions3(command) {
|
|
4607
5017
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
4608
5018
|
"--api-url <url>",
|
|
4609
5019
|
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
4610
5020
|
);
|
|
4611
5021
|
}
|
|
4612
|
-
async function
|
|
5022
|
+
async function runPlatformCommand3(options, timeoutMs, execute) {
|
|
4613
5023
|
const controller = new AbortController();
|
|
4614
5024
|
const timeoutHandle = setTimeout(() => {
|
|
4615
5025
|
controller.abort(
|
|
@@ -4637,11 +5047,11 @@ async function runPlatformCommand2(options, timeoutMs, execute) {
|
|
|
4637
5047
|
}
|
|
4638
5048
|
function registerProjectsCommands(program) {
|
|
4639
5049
|
const projects = program.command("projects").description("Operate the MCP servers saved in your hosted MCPJam projects");
|
|
4640
|
-
|
|
5050
|
+
addPlatformOptions3(
|
|
4641
5051
|
projects.command("list").description("List the projects you can access")
|
|
4642
5052
|
).action(async (options, command) => {
|
|
4643
5053
|
const globalOptions = getGlobalOptions(command);
|
|
4644
|
-
const result = await
|
|
5054
|
+
const result = await runPlatformCommand3(
|
|
4645
5055
|
options,
|
|
4646
5056
|
globalOptions.timeout,
|
|
4647
5057
|
({ client, signal }) => listProjectsOperation.execute({}, { client, signal })
|
|
@@ -4653,14 +5063,14 @@ function registerProjectsCommands(program) {
|
|
|
4653
5063
|
writeResult(result, globalOptions.format);
|
|
4654
5064
|
}
|
|
4655
5065
|
});
|
|
4656
|
-
|
|
5066
|
+
addPlatformOptions3(
|
|
4657
5067
|
projects.command("servers").description("List the servers saved in a project").option(
|
|
4658
5068
|
"--project <id-or-name>",
|
|
4659
5069
|
"Project name or ID (defaults to the most recently updated project)"
|
|
4660
5070
|
)
|
|
4661
5071
|
).action(async (options, command) => {
|
|
4662
5072
|
const globalOptions = getGlobalOptions(command);
|
|
4663
|
-
const result = await
|
|
5073
|
+
const result = await runPlatformCommand3(
|
|
4664
5074
|
options,
|
|
4665
5075
|
globalOptions.timeout,
|
|
4666
5076
|
({ client, signal }) => listProjectServersOperation.execute(
|
|
@@ -4675,7 +5085,7 @@ function registerProjectsCommands(program) {
|
|
|
4675
5085
|
writeResult(result, globalOptions.format);
|
|
4676
5086
|
}
|
|
4677
5087
|
});
|
|
4678
|
-
|
|
5088
|
+
addPlatformOptions3(
|
|
4679
5089
|
projects.command("status").description(
|
|
4680
5090
|
"Health-check every server in a project (hosted doctor per server)"
|
|
4681
5091
|
).option(
|
|
@@ -4684,7 +5094,7 @@ function registerProjectsCommands(program) {
|
|
|
4684
5094
|
)
|
|
4685
5095
|
).action(async (options, command) => {
|
|
4686
5096
|
const globalOptions = getGlobalOptions(command);
|
|
4687
|
-
const payload = await
|
|
5097
|
+
const payload = await runPlatformCommand3(
|
|
4688
5098
|
options,
|
|
4689
5099
|
globalOptions.timeout,
|
|
4690
5100
|
({ client, signal }) => showServersOperation.execute(
|
|
@@ -8569,6 +8979,7 @@ async function main(argv = process.argv, dependencies = {}) {
|
|
|
8569
8979
|
registerAuthCommands(program);
|
|
8570
8980
|
registerProjectsCommands(program);
|
|
8571
8981
|
registerEvalCommands(program);
|
|
8982
|
+
registerHostsCommands(program);
|
|
8572
8983
|
registerTunnelCommands(program);
|
|
8573
8984
|
registerInspectorCommands(program);
|
|
8574
8985
|
registerMcpCommands(program);
|