@mcpjam/cli 3.10.0 → 3.11.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/dist/index.js +370 -36
- 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
3
|
import { realpathSync, mkdirSync, writeFileSync, readFileSync, existsSync, statSync, closeSync, renameSync, openSync } from 'fs';
|
|
4
|
-
import { pathToFileURL
|
|
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
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 { cancelEvalRunOperation, listEvalRunIterationsOperation, getEvalIterationTraceOperation, getEvalRunStepsOperation, getEvalSuiteOperation, updateEvalSuiteOperation, deleteEvalSuiteOperation, setEvalSuiteScheduleOperation, listEvalCasesOperation, getEvalCaseOperation, runEvalCaseOperation, 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.11.0"};
|
|
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: {
|
|
@@ -3394,25 +3400,51 @@ function extractRenderedScreenshots(result) {
|
|
|
3394
3400
|
const root = asRecord(result);
|
|
3395
3401
|
if (!root) return [];
|
|
3396
3402
|
const trace = asRecord(root.trace) ?? root;
|
|
3397
|
-
const observations = trace.widgetRenderObservations;
|
|
3398
|
-
if (!Array.isArray(observations)) return [];
|
|
3399
3403
|
const screenshots = [];
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
status
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3404
|
+
const observations = trace.widgetRenderObservations;
|
|
3405
|
+
if (Array.isArray(observations)) {
|
|
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
|
+
}
|
|
3421
|
+
const interactions = trace.browserInteractionSteps;
|
|
3422
|
+
if (Array.isArray(interactions)) {
|
|
3423
|
+
for (const entry of interactions) {
|
|
3424
|
+
const step = asRecord(entry);
|
|
3425
|
+
if (!step) continue;
|
|
3426
|
+
const screenshotUrl = asString(step.screenshotUrl);
|
|
3427
|
+
if (!screenshotUrl) continue;
|
|
3428
|
+
const assertion = asRecord(step.assertion);
|
|
3429
|
+
const status = assertion ? assertion.passed === true ? "assert:passed" : "assert:failed" : asString(step.action) ?? "interaction";
|
|
3430
|
+
const label = asString(step.locatorLabel) ?? asString(step.action) ?? "interaction";
|
|
3431
|
+
screenshots.push({
|
|
3432
|
+
status,
|
|
3433
|
+
screenshotUrl,
|
|
3434
|
+
toolName: label,
|
|
3435
|
+
toolCallId: asString(step.toolCallId),
|
|
3436
|
+
promptIndex: typeof step.promptIndex === "number" ? step.promptIndex : void 0
|
|
3437
|
+
});
|
|
3438
|
+
}
|
|
3413
3439
|
}
|
|
3414
3440
|
return screenshots;
|
|
3415
3441
|
}
|
|
3442
|
+
function extractIterationVideoUrl(result) {
|
|
3443
|
+
const root = asRecord(result);
|
|
3444
|
+
if (!root) return void 0;
|
|
3445
|
+
const trace = asRecord(root.trace) ?? root;
|
|
3446
|
+
return asString(trace.videoUrl);
|
|
3447
|
+
}
|
|
3416
3448
|
function screenshotFilename(shot, index) {
|
|
3417
3449
|
const tool = (shot.toolName ?? "widget").replace(/[^a-zA-Z0-9_-]+/g, "-");
|
|
3418
3450
|
const suffix = shot.toolCallId ? shot.toolCallId.replace(/[^a-zA-Z0-9_-]+/g, "-") : String(index + 1);
|
|
@@ -3641,7 +3673,7 @@ function buildCaseInput(options, opts) {
|
|
|
3641
3673
|
if (options.title !== void 0) input.title = options.title;
|
|
3642
3674
|
return input;
|
|
3643
3675
|
}
|
|
3644
|
-
async function
|
|
3676
|
+
async function fetchArtifactBytes(url, timeoutMs, kind = "screenshot") {
|
|
3645
3677
|
const controller = new AbortController();
|
|
3646
3678
|
const handle = setTimeout(() => controller.abort(), timeoutMs);
|
|
3647
3679
|
handle.unref?.();
|
|
@@ -3649,7 +3681,7 @@ async function fetchScreenshotBytes(url, timeoutMs) {
|
|
|
3649
3681
|
const response = await fetch(url, { signal: controller.signal });
|
|
3650
3682
|
if (!response.ok) {
|
|
3651
3683
|
throw operationalError(
|
|
3652
|
-
`Failed to download
|
|
3684
|
+
`Failed to download ${kind} (HTTP ${response.status}).`,
|
|
3653
3685
|
{ url }
|
|
3654
3686
|
);
|
|
3655
3687
|
}
|
|
@@ -3657,7 +3689,7 @@ async function fetchScreenshotBytes(url, timeoutMs) {
|
|
|
3657
3689
|
} catch (error) {
|
|
3658
3690
|
if (error instanceof Error && error.name === "AbortError") {
|
|
3659
3691
|
throw operationalError(
|
|
3660
|
-
`Timed out downloading
|
|
3692
|
+
`Timed out downloading ${kind} after ${timeoutMs}ms.`,
|
|
3661
3693
|
{ url }
|
|
3662
3694
|
);
|
|
3663
3695
|
}
|
|
@@ -3666,6 +3698,9 @@ async function fetchScreenshotBytes(url, timeoutMs) {
|
|
|
3666
3698
|
clearTimeout(handle);
|
|
3667
3699
|
}
|
|
3668
3700
|
}
|
|
3701
|
+
function fetchScreenshotBytes(url, timeoutMs) {
|
|
3702
|
+
return fetchArtifactBytes(url, timeoutMs, "screenshot");
|
|
3703
|
+
}
|
|
3669
3704
|
function resolveScreenshotPath(out, shot, index, total) {
|
|
3670
3705
|
const looksLikeDir = out.endsWith("/") || existsSync(out) && statSync(out).isDirectory();
|
|
3671
3706
|
if (looksLikeDir) {
|
|
@@ -3771,6 +3806,20 @@ function registerEvalCommands(program) {
|
|
|
3771
3806
|
writeResult(result, globalOptions.format);
|
|
3772
3807
|
}
|
|
3773
3808
|
);
|
|
3809
|
+
addPlatformOptions(
|
|
3810
|
+
evals.command("cancel").description(
|
|
3811
|
+
"Cancel an in-flight eval run (no-op if already cancelled; errors if it already finished)"
|
|
3812
|
+
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption("--project <id-or-name>", "Project name or ID")
|
|
3813
|
+
).action(
|
|
3814
|
+
async (options, command) => {
|
|
3815
|
+
await executeOp(
|
|
3816
|
+
cancelEvalRunOperation,
|
|
3817
|
+
{ project: options.project, runId: options.run },
|
|
3818
|
+
options,
|
|
3819
|
+
command
|
|
3820
|
+
);
|
|
3821
|
+
}
|
|
3822
|
+
);
|
|
3774
3823
|
const PROJECT_OPT = "Project name or ID (defaults to most recently updated)";
|
|
3775
3824
|
addPlatformOptions(
|
|
3776
3825
|
evals.command("iterations").description(
|
|
@@ -3814,6 +3863,30 @@ function registerEvalCommands(program) {
|
|
|
3814
3863
|
);
|
|
3815
3864
|
}
|
|
3816
3865
|
);
|
|
3866
|
+
addPlatformOptions(
|
|
3867
|
+
evals.command("steps").description(
|
|
3868
|
+
"Per-authored-step results for one eval iteration: status (ok/fail/skipped/pending), reason, and evidence (screenshot/video URLs). The fastest way to see WHICH step failed and why."
|
|
3869
|
+
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
3870
|
+
"--iteration <id>",
|
|
3871
|
+
"Iteration ID (from `eval iterations`)"
|
|
3872
|
+
).requiredOption(
|
|
3873
|
+
"--project <id-or-name>",
|
|
3874
|
+
"Project the run belongs to (name or ID)"
|
|
3875
|
+
)
|
|
3876
|
+
).action(
|
|
3877
|
+
async (options, command) => {
|
|
3878
|
+
await executeOp(
|
|
3879
|
+
getEvalRunStepsOperation,
|
|
3880
|
+
{
|
|
3881
|
+
project: options.project,
|
|
3882
|
+
runId: options.run,
|
|
3883
|
+
iterationId: options.iteration
|
|
3884
|
+
},
|
|
3885
|
+
options,
|
|
3886
|
+
command
|
|
3887
|
+
);
|
|
3888
|
+
}
|
|
3889
|
+
);
|
|
3817
3890
|
addPlatformOptions(
|
|
3818
3891
|
evals.command("screenshot").description(
|
|
3819
3892
|
"Show the widget screenshot(s) an eval iteration rendered \u2014 inline when the terminal supports it, otherwise the image URL"
|
|
@@ -3922,6 +3995,70 @@ function registerEvalCommands(program) {
|
|
|
3922
3995
|
}
|
|
3923
3996
|
}
|
|
3924
3997
|
);
|
|
3998
|
+
addPlatformOptions(
|
|
3999
|
+
evals.command("video").description(
|
|
4000
|
+
"Get the Playwright replay video (.webm) an eval iteration recorded \u2014 prints the URL, or downloads it with --out"
|
|
4001
|
+
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
4002
|
+
"--iteration <id>",
|
|
4003
|
+
"Iteration ID (from `eval iterations`)"
|
|
4004
|
+
).requiredOption(
|
|
4005
|
+
"--project <id-or-name>",
|
|
4006
|
+
"Project the run belongs to (name or ID)"
|
|
4007
|
+
).option("--out <path>", "Download the .webm to this file instead of printing the URL")
|
|
4008
|
+
).action(
|
|
4009
|
+
async (options, command) => {
|
|
4010
|
+
const globalOptions = getGlobalOptions(command);
|
|
4011
|
+
const result = await runPlatformCommand(
|
|
4012
|
+
options,
|
|
4013
|
+
globalOptions.timeout,
|
|
4014
|
+
({ client, signal }) => getEvalIterationTraceOperation.execute(
|
|
4015
|
+
{
|
|
4016
|
+
project: options.project,
|
|
4017
|
+
runId: options.run,
|
|
4018
|
+
iterationId: options.iteration
|
|
4019
|
+
},
|
|
4020
|
+
{ client, signal }
|
|
4021
|
+
)
|
|
4022
|
+
);
|
|
4023
|
+
const videoUrl = extractIterationVideoUrl(result);
|
|
4024
|
+
const base = {
|
|
4025
|
+
project: result.project,
|
|
4026
|
+
runId: result.runId,
|
|
4027
|
+
iterationId: result.iterationId
|
|
4028
|
+
};
|
|
4029
|
+
const isJson = globalOptions.format === "json";
|
|
4030
|
+
if (!videoUrl) {
|
|
4031
|
+
if (isJson) {
|
|
4032
|
+
writeResult({ ...base, videoUrl: null });
|
|
4033
|
+
return;
|
|
4034
|
+
}
|
|
4035
|
+
process.stdout.write("No replay video for this iteration.\n");
|
|
4036
|
+
return;
|
|
4037
|
+
}
|
|
4038
|
+
if (options.out !== void 0) {
|
|
4039
|
+
const bytes = await fetchArtifactBytes(
|
|
4040
|
+
videoUrl,
|
|
4041
|
+
globalOptions.timeout,
|
|
4042
|
+
"video"
|
|
4043
|
+
);
|
|
4044
|
+
mkdirSync(dirname(options.out), { recursive: true });
|
|
4045
|
+
writeFileSync(options.out, bytes);
|
|
4046
|
+
if (isJson) {
|
|
4047
|
+
writeResult({ ...base, videoUrl, savedTo: options.out });
|
|
4048
|
+
return;
|
|
4049
|
+
}
|
|
4050
|
+
process.stdout.write(`Saved replay video \u2192 ${options.out}
|
|
4051
|
+
`);
|
|
4052
|
+
return;
|
|
4053
|
+
}
|
|
4054
|
+
if (isJson) {
|
|
4055
|
+
writeResult({ ...base, videoUrl });
|
|
4056
|
+
return;
|
|
4057
|
+
}
|
|
4058
|
+
process.stdout.write(`${videoUrl}
|
|
4059
|
+
`);
|
|
4060
|
+
}
|
|
4061
|
+
);
|
|
3925
4062
|
addPlatformOptions(
|
|
3926
4063
|
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)
|
|
3927
4064
|
).action(
|
|
@@ -4004,6 +4141,28 @@ function registerEvalCommands(program) {
|
|
|
4004
4141
|
);
|
|
4005
4142
|
}
|
|
4006
4143
|
);
|
|
4144
|
+
addPlatformOptions(
|
|
4145
|
+
cases.command("run").description(
|
|
4146
|
+
"Run a single case as a persisted, fully-queryable run (inspect it with `eval iterations` / `eval steps` like any run)"
|
|
4147
|
+
).requiredOption("--suite <id-or-name>", "Eval suite name or ID").requiredOption("--case <id-or-title>", "Eval case title or ID").option("--project <id-or-name>", PROJECT_OPT).option(
|
|
4148
|
+
"--server <id-or-name...>",
|
|
4149
|
+
"Override the suite's saved servers for this run"
|
|
4150
|
+
)
|
|
4151
|
+
).action(
|
|
4152
|
+
async (options, command) => {
|
|
4153
|
+
await executeOp(
|
|
4154
|
+
runEvalCaseOperation,
|
|
4155
|
+
{
|
|
4156
|
+
project: options.project,
|
|
4157
|
+
suite: options.suite,
|
|
4158
|
+
case: options.case,
|
|
4159
|
+
...options.server?.length ? { servers: options.server } : {}
|
|
4160
|
+
},
|
|
4161
|
+
options,
|
|
4162
|
+
command
|
|
4163
|
+
);
|
|
4164
|
+
}
|
|
4165
|
+
);
|
|
4007
4166
|
addPlatformOptions(
|
|
4008
4167
|
cases.command("create").description("Add a test case to a suite (definition via --file/--json)").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT).option("--file <path>", "Case JSON body (or - for stdin)").option("--json <json>", "Inline case JSON (or @file, or -)").option("--title <title>", "Case title (overrides the body)")
|
|
4009
4168
|
).action(async (options, command) => {
|
|
@@ -4082,6 +4241,180 @@ function registerEvalCommands(program) {
|
|
|
4082
4241
|
}
|
|
4083
4242
|
);
|
|
4084
4243
|
}
|
|
4244
|
+
var HOST_TEMPLATES = HOST_TEMPLATES$1.map(({ id, label }) => ({ id, label }));
|
|
4245
|
+
function addPlatformOptions2(command) {
|
|
4246
|
+
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
4247
|
+
"--api-url <url>",
|
|
4248
|
+
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
4249
|
+
);
|
|
4250
|
+
}
|
|
4251
|
+
async function runPlatformCommand2(options, timeoutMs, execute) {
|
|
4252
|
+
const controller = new AbortController();
|
|
4253
|
+
const timeoutHandle = setTimeout(() => {
|
|
4254
|
+
controller.abort(
|
|
4255
|
+
new PlatformApiError(`Request timed out after ${timeoutMs}ms`, "TIMEOUT", {
|
|
4256
|
+
status: 0
|
|
4257
|
+
})
|
|
4258
|
+
);
|
|
4259
|
+
}, timeoutMs);
|
|
4260
|
+
timeoutHandle.unref?.();
|
|
4261
|
+
try {
|
|
4262
|
+
const { client } = buildPlatformClient({ ...options, timeoutMs });
|
|
4263
|
+
return await execute({ client, signal: controller.signal });
|
|
4264
|
+
} catch (error) {
|
|
4265
|
+
if (controller.signal.aborted && controller.signal.reason instanceof PlatformApiError) {
|
|
4266
|
+
throw toCliError(controller.signal.reason);
|
|
4267
|
+
}
|
|
4268
|
+
throw toCliError(error);
|
|
4269
|
+
} finally {
|
|
4270
|
+
clearTimeout(timeoutHandle);
|
|
4271
|
+
}
|
|
4272
|
+
}
|
|
4273
|
+
function loadConfigObject(options) {
|
|
4274
|
+
if (options.file !== void 0 && options.json !== void 0) {
|
|
4275
|
+
throw usageError("Provide either --file or --json, not both.");
|
|
4276
|
+
}
|
|
4277
|
+
let base;
|
|
4278
|
+
if (options.file !== void 0) {
|
|
4279
|
+
let text;
|
|
4280
|
+
try {
|
|
4281
|
+
text = options.file === "-" ? readFileSync(0, "utf8") : readFileSync(options.file, "utf8");
|
|
4282
|
+
} catch (error) {
|
|
4283
|
+
throw usageError(`Failed to read --file "${options.file}".`, {
|
|
4284
|
+
source: error instanceof Error ? error.message : String(error)
|
|
4285
|
+
});
|
|
4286
|
+
}
|
|
4287
|
+
if (text.trim() === "") throw usageError("--file input is empty.");
|
|
4288
|
+
try {
|
|
4289
|
+
base = JSON.parse(text);
|
|
4290
|
+
} catch (error) {
|
|
4291
|
+
throw usageError("--file must contain valid JSON.", {
|
|
4292
|
+
source: error instanceof Error ? error.message : String(error)
|
|
4293
|
+
});
|
|
4294
|
+
}
|
|
4295
|
+
} else if (options.json !== void 0) {
|
|
4296
|
+
base = new JsonInputContext().parseJsonInputRecord(options.json, "--json");
|
|
4297
|
+
} else {
|
|
4298
|
+
return void 0;
|
|
4299
|
+
}
|
|
4300
|
+
if (typeof base !== "object" || base === null || Array.isArray(base)) {
|
|
4301
|
+
throw usageError("Host config must be a JSON object.");
|
|
4302
|
+
}
|
|
4303
|
+
return base;
|
|
4304
|
+
}
|
|
4305
|
+
function registerHostsCommands(program) {
|
|
4306
|
+
const hosts = program.command("hosts").description("List, create, and manage the hosts in your hosted MCPJam projects");
|
|
4307
|
+
hosts.command("templates").description("List the built-in host templates usable with `hosts create --template`").action((_options, command) => {
|
|
4308
|
+
const globalOptions = getGlobalOptions(command);
|
|
4309
|
+
writeResult({ items: HOST_TEMPLATES }, globalOptions.format);
|
|
4310
|
+
});
|
|
4311
|
+
addPlatformOptions2(
|
|
4312
|
+
hosts.command("list").description("List the hosts saved in a project").option(
|
|
4313
|
+
"--project <id-or-name>",
|
|
4314
|
+
"Project name or ID (defaults to the most recently updated project)"
|
|
4315
|
+
)
|
|
4316
|
+
).action(async (options, command) => {
|
|
4317
|
+
const globalOptions = getGlobalOptions(command);
|
|
4318
|
+
const result = await runPlatformCommand2(
|
|
4319
|
+
options,
|
|
4320
|
+
globalOptions.timeout,
|
|
4321
|
+
({ client, signal }) => listHostsOperation.execute({ project: options.project }, { client, signal })
|
|
4322
|
+
);
|
|
4323
|
+
writeResult(result, globalOptions.format);
|
|
4324
|
+
});
|
|
4325
|
+
addPlatformOptions2(
|
|
4326
|
+
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")
|
|
4327
|
+
).action(
|
|
4328
|
+
async (options, command) => {
|
|
4329
|
+
const globalOptions = getGlobalOptions(command);
|
|
4330
|
+
const result = await runPlatformCommand2(
|
|
4331
|
+
options,
|
|
4332
|
+
globalOptions.timeout,
|
|
4333
|
+
({ client, signal }) => getHostOperation.execute(
|
|
4334
|
+
{ project: options.project, host: options.host },
|
|
4335
|
+
{ client, signal }
|
|
4336
|
+
)
|
|
4337
|
+
);
|
|
4338
|
+
writeResult(result, globalOptions.format);
|
|
4339
|
+
}
|
|
4340
|
+
);
|
|
4341
|
+
addPlatformOptions2(
|
|
4342
|
+
hosts.command("create").description(
|
|
4343
|
+
"Create a host from a built-in template (--template) or a full host config (--file/--json)"
|
|
4344
|
+
).requiredOption("--name <name>", "Display name for the new host").option("--project <id-or-name>", "Project name or ID").option(
|
|
4345
|
+
"--template <id>",
|
|
4346
|
+
"Built-in template id (see `hosts templates`), e.g. claude, chatgpt, cursor"
|
|
4347
|
+
).option(
|
|
4348
|
+
"--theme <theme>",
|
|
4349
|
+
"Theme for the seeded config: light or dark (template only)"
|
|
4350
|
+
).option("--file <path>", "Host config v2 JSON file (or - for stdin)").option("--json <json>", "Inline host config v2 JSON (or @file, or -)")
|
|
4351
|
+
).action(
|
|
4352
|
+
async (options, command) => {
|
|
4353
|
+
const globalOptions = getGlobalOptions(command);
|
|
4354
|
+
const config = loadConfigObject(options);
|
|
4355
|
+
const input = validateInput(createHostOperation, {
|
|
4356
|
+
project: options.project,
|
|
4357
|
+
name: options.name,
|
|
4358
|
+
...options.template !== void 0 ? { template: options.template } : {},
|
|
4359
|
+
...options.theme !== void 0 ? { theme: options.theme } : {},
|
|
4360
|
+
...config !== void 0 ? { config } : {}
|
|
4361
|
+
});
|
|
4362
|
+
const result = await runPlatformCommand2(
|
|
4363
|
+
options,
|
|
4364
|
+
globalOptions.timeout,
|
|
4365
|
+
({ client, signal }) => createHostOperation.execute(input, { client, signal })
|
|
4366
|
+
);
|
|
4367
|
+
writeResult(result, globalOptions.format);
|
|
4368
|
+
}
|
|
4369
|
+
);
|
|
4370
|
+
addPlatformOptions2(
|
|
4371
|
+
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 -)")
|
|
4372
|
+
).action(
|
|
4373
|
+
async (options, command) => {
|
|
4374
|
+
const globalOptions = getGlobalOptions(command);
|
|
4375
|
+
const config = loadConfigObject(options);
|
|
4376
|
+
const input = validateInput(updateHostOperation, {
|
|
4377
|
+
project: options.project,
|
|
4378
|
+
host: options.host,
|
|
4379
|
+
...options.name !== void 0 ? { name: options.name } : {},
|
|
4380
|
+
...config !== void 0 ? { config } : {}
|
|
4381
|
+
});
|
|
4382
|
+
const result = await runPlatformCommand2(
|
|
4383
|
+
options,
|
|
4384
|
+
globalOptions.timeout,
|
|
4385
|
+
({ client, signal }) => updateHostOperation.execute(input, { client, signal })
|
|
4386
|
+
);
|
|
4387
|
+
writeResult(result, globalOptions.format);
|
|
4388
|
+
}
|
|
4389
|
+
);
|
|
4390
|
+
addPlatformOptions2(
|
|
4391
|
+
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")
|
|
4392
|
+
).action(
|
|
4393
|
+
async (options, command) => {
|
|
4394
|
+
const globalOptions = getGlobalOptions(command);
|
|
4395
|
+
const result = await runPlatformCommand2(
|
|
4396
|
+
options,
|
|
4397
|
+
globalOptions.timeout,
|
|
4398
|
+
({ client, signal }) => deleteHostOperation.execute(
|
|
4399
|
+
{
|
|
4400
|
+
project: options.project,
|
|
4401
|
+
host: options.host
|
|
4402
|
+
},
|
|
4403
|
+
{ client, signal }
|
|
4404
|
+
)
|
|
4405
|
+
);
|
|
4406
|
+
writeResult(result, globalOptions.format);
|
|
4407
|
+
}
|
|
4408
|
+
);
|
|
4409
|
+
}
|
|
4410
|
+
function validateInput(op, raw) {
|
|
4411
|
+
const parsed = op.inputSchema.safeParse(raw);
|
|
4412
|
+
if (!parsed.success) {
|
|
4413
|
+
const detail = parsed.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
|
|
4414
|
+
throw usageError(`Invalid input: ${detail}`);
|
|
4415
|
+
}
|
|
4416
|
+
return parsed.data;
|
|
4417
|
+
}
|
|
4085
4418
|
|
|
4086
4419
|
// src/lib/server-doctor.ts
|
|
4087
4420
|
function summarizeServerDoctorTarget(target, config) {
|
|
@@ -4833,13 +5166,13 @@ function statusGlyph(status) {
|
|
|
4833
5166
|
}
|
|
4834
5167
|
|
|
4835
5168
|
// src/commands/projects.ts
|
|
4836
|
-
function
|
|
5169
|
+
function addPlatformOptions3(command) {
|
|
4837
5170
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
4838
5171
|
"--api-url <url>",
|
|
4839
5172
|
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
4840
5173
|
);
|
|
4841
5174
|
}
|
|
4842
|
-
async function
|
|
5175
|
+
async function runPlatformCommand3(options, timeoutMs, execute) {
|
|
4843
5176
|
const controller = new AbortController();
|
|
4844
5177
|
const timeoutHandle = setTimeout(() => {
|
|
4845
5178
|
controller.abort(
|
|
@@ -4867,11 +5200,11 @@ async function runPlatformCommand2(options, timeoutMs, execute) {
|
|
|
4867
5200
|
}
|
|
4868
5201
|
function registerProjectsCommands(program) {
|
|
4869
5202
|
const projects = program.command("projects").description("Operate the MCP servers saved in your hosted MCPJam projects");
|
|
4870
|
-
|
|
5203
|
+
addPlatformOptions3(
|
|
4871
5204
|
projects.command("list").description("List the projects you can access")
|
|
4872
5205
|
).action(async (options, command) => {
|
|
4873
5206
|
const globalOptions = getGlobalOptions(command);
|
|
4874
|
-
const result = await
|
|
5207
|
+
const result = await runPlatformCommand3(
|
|
4875
5208
|
options,
|
|
4876
5209
|
globalOptions.timeout,
|
|
4877
5210
|
({ client, signal }) => listProjectsOperation.execute({}, { client, signal })
|
|
@@ -4883,14 +5216,14 @@ function registerProjectsCommands(program) {
|
|
|
4883
5216
|
writeResult(result, globalOptions.format);
|
|
4884
5217
|
}
|
|
4885
5218
|
});
|
|
4886
|
-
|
|
5219
|
+
addPlatformOptions3(
|
|
4887
5220
|
projects.command("servers").description("List the servers saved in a project").option(
|
|
4888
5221
|
"--project <id-or-name>",
|
|
4889
5222
|
"Project name or ID (defaults to the most recently updated project)"
|
|
4890
5223
|
)
|
|
4891
5224
|
).action(async (options, command) => {
|
|
4892
5225
|
const globalOptions = getGlobalOptions(command);
|
|
4893
|
-
const result = await
|
|
5226
|
+
const result = await runPlatformCommand3(
|
|
4894
5227
|
options,
|
|
4895
5228
|
globalOptions.timeout,
|
|
4896
5229
|
({ client, signal }) => listProjectServersOperation.execute(
|
|
@@ -4905,7 +5238,7 @@ function registerProjectsCommands(program) {
|
|
|
4905
5238
|
writeResult(result, globalOptions.format);
|
|
4906
5239
|
}
|
|
4907
5240
|
});
|
|
4908
|
-
|
|
5241
|
+
addPlatformOptions3(
|
|
4909
5242
|
projects.command("status").description(
|
|
4910
5243
|
"Health-check every server in a project (hosted doctor per server)"
|
|
4911
5244
|
).option(
|
|
@@ -4914,7 +5247,7 @@ function registerProjectsCommands(program) {
|
|
|
4914
5247
|
)
|
|
4915
5248
|
).action(async (options, command) => {
|
|
4916
5249
|
const globalOptions = getGlobalOptions(command);
|
|
4917
|
-
const payload = await
|
|
5250
|
+
const payload = await runPlatformCommand3(
|
|
4918
5251
|
options,
|
|
4919
5252
|
globalOptions.timeout,
|
|
4920
5253
|
({ client, signal }) => showServersOperation.execute(
|
|
@@ -8799,6 +9132,7 @@ async function main(argv = process.argv, dependencies = {}) {
|
|
|
8799
9132
|
registerAuthCommands(program);
|
|
8800
9133
|
registerProjectsCommands(program);
|
|
8801
9134
|
registerEvalCommands(program);
|
|
9135
|
+
registerHostsCommands(program);
|
|
8802
9136
|
registerTunnelCommands(program);
|
|
8803
9137
|
registerInspectorCommands(program);
|
|
8804
9138
|
registerMcpCommands(program);
|