@mcpjam/cli 3.9.0 → 3.10.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 +233 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command, CommanderError } from 'commander';
|
|
3
|
-
import { realpathSync,
|
|
3
|
+
import { realpathSync, mkdirSync, writeFileSync, readFileSync, existsSync, statSync, closeSync, renameSync, openSync } from 'fs';
|
|
4
4
|
import { pathToFileURL, fileURLToPath } 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
10
|
import os, { homedir } from 'os';
|
|
@@ -19,7 +19,7 @@ import { WebSocket } from 'ws';
|
|
|
19
19
|
|
|
20
20
|
// package.json
|
|
21
21
|
var package_default = {
|
|
22
|
-
version: "3.
|
|
22
|
+
version: "3.10.0"};
|
|
23
23
|
|
|
24
24
|
// src/lib/output.ts
|
|
25
25
|
var DEFAULT_OUTPUT_FORMAT = "json";
|
|
@@ -3382,6 +3382,91 @@ function registerAuthCommands(program) {
|
|
|
3382
3382
|
}
|
|
3383
3383
|
});
|
|
3384
3384
|
}
|
|
3385
|
+
|
|
3386
|
+
// src/lib/eval-screenshots.ts
|
|
3387
|
+
function asRecord(value) {
|
|
3388
|
+
return typeof value === "object" && value !== null ? value : null;
|
|
3389
|
+
}
|
|
3390
|
+
function asString(value) {
|
|
3391
|
+
return typeof value === "string" ? value : void 0;
|
|
3392
|
+
}
|
|
3393
|
+
function extractRenderedScreenshots(result) {
|
|
3394
|
+
const root = asRecord(result);
|
|
3395
|
+
if (!root) return [];
|
|
3396
|
+
const trace = asRecord(root.trace) ?? root;
|
|
3397
|
+
const observations = trace.widgetRenderObservations;
|
|
3398
|
+
if (!Array.isArray(observations)) return [];
|
|
3399
|
+
const screenshots = [];
|
|
3400
|
+
for (const entry of observations) {
|
|
3401
|
+
const obs = asRecord(entry);
|
|
3402
|
+
if (!obs) continue;
|
|
3403
|
+
const status = asString(obs.status);
|
|
3404
|
+
const screenshotUrl = asString(obs.screenshotUrl);
|
|
3405
|
+
if (status !== "rendered" || !screenshotUrl) continue;
|
|
3406
|
+
screenshots.push({
|
|
3407
|
+
status,
|
|
3408
|
+
screenshotUrl,
|
|
3409
|
+
toolName: asString(obs.toolName),
|
|
3410
|
+
toolCallId: asString(obs.toolCallId),
|
|
3411
|
+
promptIndex: typeof obs.promptIndex === "number" ? obs.promptIndex : void 0
|
|
3412
|
+
});
|
|
3413
|
+
}
|
|
3414
|
+
return screenshots;
|
|
3415
|
+
}
|
|
3416
|
+
function screenshotFilename(shot, index) {
|
|
3417
|
+
const tool = (shot.toolName ?? "widget").replace(/[^a-zA-Z0-9_-]+/g, "-");
|
|
3418
|
+
const suffix = shot.toolCallId ? shot.toolCallId.replace(/[^a-zA-Z0-9_-]+/g, "-") : String(index + 1);
|
|
3419
|
+
return `${tool}-${suffix}.png`;
|
|
3420
|
+
}
|
|
3421
|
+
|
|
3422
|
+
// src/lib/terminal-image.ts
|
|
3423
|
+
var ESC = "\x1B";
|
|
3424
|
+
var BEL = "\x07";
|
|
3425
|
+
function detectInlineImageProtocol(env = process.env, isTTY = process.stdout.isTTY) {
|
|
3426
|
+
if (!isTTY) return null;
|
|
3427
|
+
const termProgram = env.TERM_PROGRAM ?? "";
|
|
3428
|
+
const term = env.TERM ?? "";
|
|
3429
|
+
if (term === "xterm-kitty" || env.KITTY_WINDOW_ID !== void 0 || termProgram === "ghostty" || env.GHOSTTY_RESOURCES_DIR !== void 0) {
|
|
3430
|
+
return "kitty";
|
|
3431
|
+
}
|
|
3432
|
+
if (termProgram === "iTerm.app" || termProgram === "WezTerm" || termProgram === "WarpTerminal" || env.LC_TERMINAL === "iTerm2") {
|
|
3433
|
+
return "iterm";
|
|
3434
|
+
}
|
|
3435
|
+
return null;
|
|
3436
|
+
}
|
|
3437
|
+
function toBase64(data) {
|
|
3438
|
+
return Buffer.from(data).toString("base64");
|
|
3439
|
+
}
|
|
3440
|
+
function encodeIterm(data) {
|
|
3441
|
+
const payload = toBase64(data);
|
|
3442
|
+
const args = ["inline=1", `size=${data.byteLength}`, "preserveAspectRatio=1"].join(
|
|
3443
|
+
";"
|
|
3444
|
+
);
|
|
3445
|
+
return `${ESC}]1337;File=${args}:${payload}${BEL}
|
|
3446
|
+
`;
|
|
3447
|
+
}
|
|
3448
|
+
function encodeKitty(data) {
|
|
3449
|
+
const payload = toBase64(data);
|
|
3450
|
+
const CHUNK = 4096;
|
|
3451
|
+
const chunks = [];
|
|
3452
|
+
for (let offset = 0; offset < payload.length; offset += CHUNK) {
|
|
3453
|
+
chunks.push(payload.slice(offset, offset + CHUNK));
|
|
3454
|
+
}
|
|
3455
|
+
if (chunks.length === 0) chunks.push("");
|
|
3456
|
+
let out = "";
|
|
3457
|
+
chunks.forEach((chunk, index) => {
|
|
3458
|
+
const more = index < chunks.length - 1 ? 1 : 0;
|
|
3459
|
+
const control = index === 0 ? `a=T,f=100,m=${more}` : `m=${more}`;
|
|
3460
|
+
out += `${ESC}_G${control};${chunk}${ESC}\\`;
|
|
3461
|
+
});
|
|
3462
|
+
return `${out}
|
|
3463
|
+
`;
|
|
3464
|
+
}
|
|
3465
|
+
function encodeInlineImage(data, protocol) {
|
|
3466
|
+
return protocol === "kitty" ? encodeKitty(data) : encodeIterm(data);
|
|
3467
|
+
}
|
|
3468
|
+
|
|
3469
|
+
// src/commands/eval.ts
|
|
3385
3470
|
function addPlatformOptions(command) {
|
|
3386
3471
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
3387
3472
|
"--api-url <url>",
|
|
@@ -3556,6 +3641,43 @@ function buildCaseInput(options, opts) {
|
|
|
3556
3641
|
if (options.title !== void 0) input.title = options.title;
|
|
3557
3642
|
return input;
|
|
3558
3643
|
}
|
|
3644
|
+
async function fetchScreenshotBytes(url, timeoutMs) {
|
|
3645
|
+
const controller = new AbortController();
|
|
3646
|
+
const handle = setTimeout(() => controller.abort(), timeoutMs);
|
|
3647
|
+
handle.unref?.();
|
|
3648
|
+
try {
|
|
3649
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
3650
|
+
if (!response.ok) {
|
|
3651
|
+
throw operationalError(
|
|
3652
|
+
`Failed to download screenshot (HTTP ${response.status}).`,
|
|
3653
|
+
{ url }
|
|
3654
|
+
);
|
|
3655
|
+
}
|
|
3656
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
3657
|
+
} catch (error) {
|
|
3658
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
3659
|
+
throw operationalError(
|
|
3660
|
+
`Timed out downloading screenshot after ${timeoutMs}ms.`,
|
|
3661
|
+
{ url }
|
|
3662
|
+
);
|
|
3663
|
+
}
|
|
3664
|
+
throw error;
|
|
3665
|
+
} finally {
|
|
3666
|
+
clearTimeout(handle);
|
|
3667
|
+
}
|
|
3668
|
+
}
|
|
3669
|
+
function resolveScreenshotPath(out, shot, index, total) {
|
|
3670
|
+
const looksLikeDir = out.endsWith("/") || existsSync(out) && statSync(out).isDirectory();
|
|
3671
|
+
if (looksLikeDir) {
|
|
3672
|
+
return join(out, screenshotFilename(shot, index));
|
|
3673
|
+
}
|
|
3674
|
+
if (total > 1) {
|
|
3675
|
+
throw usageError(
|
|
3676
|
+
"--out must be a directory when the iteration rendered multiple screenshots."
|
|
3677
|
+
);
|
|
3678
|
+
}
|
|
3679
|
+
return out;
|
|
3680
|
+
}
|
|
3559
3681
|
function registerEvalCommands(program) {
|
|
3560
3682
|
const evals = program.command("eval").description("Author and run eval suites in your hosted MCPJam projects");
|
|
3561
3683
|
addPlatformOptions(
|
|
@@ -3692,6 +3814,114 @@ function registerEvalCommands(program) {
|
|
|
3692
3814
|
);
|
|
3693
3815
|
}
|
|
3694
3816
|
);
|
|
3817
|
+
addPlatformOptions(
|
|
3818
|
+
evals.command("screenshot").description(
|
|
3819
|
+
"Show the widget screenshot(s) an eval iteration rendered \u2014 inline when the terminal supports it, otherwise the image URL"
|
|
3820
|
+
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
3821
|
+
"--iteration <id>",
|
|
3822
|
+
"Iteration ID (from `eval iterations`)"
|
|
3823
|
+
).requiredOption(
|
|
3824
|
+
"--project <id-or-name>",
|
|
3825
|
+
"Project the run belongs to (name or ID)"
|
|
3826
|
+
).option(
|
|
3827
|
+
"--out <path>",
|
|
3828
|
+
"Save the PNG(s) to a file or directory instead of rendering inline"
|
|
3829
|
+
).option("--index <n>", "Show only the Nth screenshot (1-based)")
|
|
3830
|
+
).action(
|
|
3831
|
+
async (options, command) => {
|
|
3832
|
+
const globalOptions = getGlobalOptions(command);
|
|
3833
|
+
const index = options.index !== void 0 ? parsePositiveInteger(options.index, "--index") : void 0;
|
|
3834
|
+
const result = await runPlatformCommand(
|
|
3835
|
+
options,
|
|
3836
|
+
globalOptions.timeout,
|
|
3837
|
+
({ client, signal }) => getEvalIterationTraceOperation.execute(
|
|
3838
|
+
{
|
|
3839
|
+
project: options.project,
|
|
3840
|
+
runId: options.run,
|
|
3841
|
+
iterationId: options.iteration
|
|
3842
|
+
},
|
|
3843
|
+
{ client, signal }
|
|
3844
|
+
)
|
|
3845
|
+
);
|
|
3846
|
+
let shots = extractRenderedScreenshots(result);
|
|
3847
|
+
if (index !== void 0) {
|
|
3848
|
+
if (index > shots.length) {
|
|
3849
|
+
throw usageError(
|
|
3850
|
+
`--index ${index} is out of range; this iteration rendered ${shots.length} screenshot(s).`
|
|
3851
|
+
);
|
|
3852
|
+
}
|
|
3853
|
+
shots = [shots[index - 1]];
|
|
3854
|
+
}
|
|
3855
|
+
const base = {
|
|
3856
|
+
project: result.project,
|
|
3857
|
+
runId: result.runId,
|
|
3858
|
+
iterationId: result.iterationId
|
|
3859
|
+
};
|
|
3860
|
+
const isJson = globalOptions.format === "json";
|
|
3861
|
+
if (options.out !== void 0) {
|
|
3862
|
+
const saved = [];
|
|
3863
|
+
for (let i = 0; i < shots.length; i += 1) {
|
|
3864
|
+
const shot = shots[i];
|
|
3865
|
+
const bytes = await fetchScreenshotBytes(
|
|
3866
|
+
shot.screenshotUrl,
|
|
3867
|
+
globalOptions.timeout
|
|
3868
|
+
);
|
|
3869
|
+
const path6 = resolveScreenshotPath(
|
|
3870
|
+
options.out,
|
|
3871
|
+
shot,
|
|
3872
|
+
i,
|
|
3873
|
+
shots.length
|
|
3874
|
+
);
|
|
3875
|
+
mkdirSync(dirname(path6), { recursive: true });
|
|
3876
|
+
writeFileSync(path6, bytes);
|
|
3877
|
+
saved.push({ ...shot, savedTo: path6 });
|
|
3878
|
+
}
|
|
3879
|
+
if (isJson) {
|
|
3880
|
+
writeResult({ ...base, items: saved });
|
|
3881
|
+
return;
|
|
3882
|
+
}
|
|
3883
|
+
if (saved.length === 0) {
|
|
3884
|
+
process.stdout.write(
|
|
3885
|
+
"No rendered widget screenshots for this iteration.\n"
|
|
3886
|
+
);
|
|
3887
|
+
return;
|
|
3888
|
+
}
|
|
3889
|
+
for (const shot of saved) {
|
|
3890
|
+
process.stdout.write(
|
|
3891
|
+
`Saved ${shot.toolName ?? "widget"} \u2192 ${shot.savedTo}
|
|
3892
|
+
`
|
|
3893
|
+
);
|
|
3894
|
+
}
|
|
3895
|
+
return;
|
|
3896
|
+
}
|
|
3897
|
+
if (isJson) {
|
|
3898
|
+
writeResult({ ...base, items: shots });
|
|
3899
|
+
return;
|
|
3900
|
+
}
|
|
3901
|
+
if (shots.length === 0) {
|
|
3902
|
+
process.stdout.write(
|
|
3903
|
+
"No rendered widget screenshots for this iteration.\n"
|
|
3904
|
+
);
|
|
3905
|
+
return;
|
|
3906
|
+
}
|
|
3907
|
+
const protocol = detectInlineImageProtocol();
|
|
3908
|
+
for (const shot of shots) {
|
|
3909
|
+
const caption = `${shot.toolName ?? "widget"} \xB7 ${shot.status}`;
|
|
3910
|
+
if (protocol) {
|
|
3911
|
+
const bytes = await fetchScreenshotBytes(
|
|
3912
|
+
shot.screenshotUrl,
|
|
3913
|
+
globalOptions.timeout
|
|
3914
|
+
);
|
|
3915
|
+
process.stdout.write(`${caption}
|
|
3916
|
+
`);
|
|
3917
|
+
process.stdout.write(encodeInlineImage(bytes, protocol));
|
|
3918
|
+
} else {
|
|
3919
|
+
process.stdout.write(`${caption} ${shot.screenshotUrl}
|
|
3920
|
+
`);
|
|
3921
|
+
}
|
|
3922
|
+
}
|
|
3923
|
+
}
|
|
3924
|
+
);
|
|
3695
3925
|
addPlatformOptions(
|
|
3696
3926
|
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
3927
|
).action(
|