@mcpjam/cli 3.7.0 → 3.9.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 +840 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import path2, { join, dirname, basename } from 'path';
|
|
|
8
8
|
import { randomUUID } from 'crypto';
|
|
9
9
|
import { spawn } from 'child_process';
|
|
10
10
|
import os, { homedir } from 'os';
|
|
11
|
-
import { createTunnelOperation, DEFAULT_PLATFORM_API_BASE_URL, PlatformApiClient, isPlatformApiError, PlatformApiError, listProjectsOperation, listProjectServersOperation, showServersOperation } from '@mcpjam/sdk/platform';
|
|
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
12
|
import { StdioServerTransport, McpServer } from '@modelcontextprotocol/server';
|
|
13
13
|
import { z } from 'zod';
|
|
14
14
|
import { PostHog } from 'posthog-node';
|
|
@@ -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.9.0"};
|
|
23
23
|
|
|
24
24
|
// src/lib/output.ts
|
|
25
25
|
var DEFAULT_OUTPUT_FORMAT = "json";
|
|
@@ -2377,6 +2377,224 @@ function buildWidgetRenderOutput(response, options = {}) {
|
|
|
2377
2377
|
};
|
|
2378
2378
|
}
|
|
2379
2379
|
|
|
2380
|
+
// src/lib/widget-session.ts
|
|
2381
|
+
var BROWSER_ACTIONS = /* @__PURE__ */ new Set([
|
|
2382
|
+
"screenshot",
|
|
2383
|
+
"left_click",
|
|
2384
|
+
"double_click",
|
|
2385
|
+
"right_click",
|
|
2386
|
+
"mouse_move",
|
|
2387
|
+
"type",
|
|
2388
|
+
"key",
|
|
2389
|
+
"scroll",
|
|
2390
|
+
"wait"
|
|
2391
|
+
]);
|
|
2392
|
+
var SCROLL_DIRECTIONS = /* @__PURE__ */ new Set([
|
|
2393
|
+
"up",
|
|
2394
|
+
"down",
|
|
2395
|
+
"left",
|
|
2396
|
+
"right"
|
|
2397
|
+
]);
|
|
2398
|
+
async function runWidgetSessionStart(options, deps = {}) {
|
|
2399
|
+
const client = deps.client ?? new InspectorApiClient({ baseUrl: options.baseUrl });
|
|
2400
|
+
await client.ensureBackend({
|
|
2401
|
+
startIfNeeded: options.startIfNeeded ?? true,
|
|
2402
|
+
timeoutMs: options.timeoutMs
|
|
2403
|
+
});
|
|
2404
|
+
await client.connectServer(options.serverName, options.config, {
|
|
2405
|
+
timeoutMs: options.timeoutMs
|
|
2406
|
+
});
|
|
2407
|
+
const response = await client.request("/api/mcp/widget-session", {
|
|
2408
|
+
method: "POST",
|
|
2409
|
+
body: {
|
|
2410
|
+
serverId: options.serverName,
|
|
2411
|
+
toolName: options.toolName,
|
|
2412
|
+
parameters: options.parameters,
|
|
2413
|
+
...options.injectOpenAiCompat ? { injectOpenAiCompat: true } : {},
|
|
2414
|
+
...options.viewport ? { viewport: options.viewport } : {}
|
|
2415
|
+
},
|
|
2416
|
+
// The first render may install Chromium — wait generously.
|
|
2417
|
+
timeoutMs: resolveRenderRequestTimeoutMs(options.timeoutMs)
|
|
2418
|
+
});
|
|
2419
|
+
return normalizeStartResponse(response);
|
|
2420
|
+
}
|
|
2421
|
+
async function runWidgetSessionAction(options, deps = {}) {
|
|
2422
|
+
const client = deps.client ?? new InspectorApiClient({ baseUrl: options.baseUrl });
|
|
2423
|
+
await client.ensureBackend({ startIfNeeded: false, timeoutMs: options.timeoutMs });
|
|
2424
|
+
const response = await client.request(
|
|
2425
|
+
`/api/mcp/widget-session/${encodeURIComponent(options.sessionId)}/action`,
|
|
2426
|
+
{
|
|
2427
|
+
method: "POST",
|
|
2428
|
+
body: { action: options.action },
|
|
2429
|
+
timeoutMs: options.timeoutMs
|
|
2430
|
+
}
|
|
2431
|
+
);
|
|
2432
|
+
return normalizeActionResponse(response, options.action);
|
|
2433
|
+
}
|
|
2434
|
+
async function runWidgetSessionClose(options, deps = {}) {
|
|
2435
|
+
const client = deps.client ?? new InspectorApiClient({ baseUrl: options.baseUrl });
|
|
2436
|
+
await client.ensureBackend({ startIfNeeded: false, timeoutMs: options.timeoutMs });
|
|
2437
|
+
const response = await client.request(
|
|
2438
|
+
`/api/mcp/widget-session/${encodeURIComponent(options.sessionId)}`,
|
|
2439
|
+
{ method: "DELETE", timeoutMs: options.timeoutMs }
|
|
2440
|
+
);
|
|
2441
|
+
const closed = Boolean(
|
|
2442
|
+
response && typeof response === "object" ? response.closed : false
|
|
2443
|
+
);
|
|
2444
|
+
return { closed };
|
|
2445
|
+
}
|
|
2446
|
+
function parseBrowserActionSpec(options) {
|
|
2447
|
+
const action = options.action?.trim();
|
|
2448
|
+
if (!action) {
|
|
2449
|
+
throw usageError("--action is required. Use --action <type>.");
|
|
2450
|
+
}
|
|
2451
|
+
if (!BROWSER_ACTIONS.has(action)) {
|
|
2452
|
+
throw usageError(
|
|
2453
|
+
`Invalid action "${action}". Use one of: ${[...BROWSER_ACTIONS].join(", ")}.`
|
|
2454
|
+
);
|
|
2455
|
+
}
|
|
2456
|
+
const spec = {
|
|
2457
|
+
action
|
|
2458
|
+
};
|
|
2459
|
+
if (options.coordinate !== void 0) {
|
|
2460
|
+
spec.coordinate = parseCoordinate(options.coordinate);
|
|
2461
|
+
}
|
|
2462
|
+
if (options.text !== void 0) {
|
|
2463
|
+
spec.text = options.text;
|
|
2464
|
+
}
|
|
2465
|
+
if (options.scrollDirection !== void 0) {
|
|
2466
|
+
const dir = options.scrollDirection.trim();
|
|
2467
|
+
if (!SCROLL_DIRECTIONS.has(dir)) {
|
|
2468
|
+
throw usageError(
|
|
2469
|
+
`Invalid --scroll-direction "${options.scrollDirection}". Use up, down, left, or right.`
|
|
2470
|
+
);
|
|
2471
|
+
}
|
|
2472
|
+
spec.scrollDirection = dir;
|
|
2473
|
+
}
|
|
2474
|
+
if (options.scrollAmount !== void 0) {
|
|
2475
|
+
const scrollAmount = parseFiniteNumber(
|
|
2476
|
+
options.scrollAmount,
|
|
2477
|
+
"--scroll-amount"
|
|
2478
|
+
);
|
|
2479
|
+
if (scrollAmount <= 0) {
|
|
2480
|
+
throw usageError("--scroll-amount must be greater than 0.");
|
|
2481
|
+
}
|
|
2482
|
+
spec.scrollAmount = scrollAmount;
|
|
2483
|
+
}
|
|
2484
|
+
if (options.duration !== void 0) {
|
|
2485
|
+
const duration = parseFiniteNumber(options.duration, "--duration");
|
|
2486
|
+
if (duration < 0) {
|
|
2487
|
+
throw usageError("--duration must be greater than or equal to 0.");
|
|
2488
|
+
}
|
|
2489
|
+
spec.duration = duration;
|
|
2490
|
+
}
|
|
2491
|
+
return spec;
|
|
2492
|
+
}
|
|
2493
|
+
function parseCoordinate(value) {
|
|
2494
|
+
const match = /^\s*(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)\s*$/.exec(value);
|
|
2495
|
+
if (!match) {
|
|
2496
|
+
throw usageError(`Invalid --coordinate "${value}". Use "x,y", e.g. 640,400.`);
|
|
2497
|
+
}
|
|
2498
|
+
return [Number(match[1]), Number(match[2])];
|
|
2499
|
+
}
|
|
2500
|
+
function parseFiniteNumber(value, flag) {
|
|
2501
|
+
const parsed = Number(value);
|
|
2502
|
+
if (!Number.isFinite(parsed)) {
|
|
2503
|
+
throw usageError(`Invalid ${flag} "${value}". Expected a number.`);
|
|
2504
|
+
}
|
|
2505
|
+
return parsed;
|
|
2506
|
+
}
|
|
2507
|
+
function normalizeStartResponse(value) {
|
|
2508
|
+
if (!value || typeof value !== "object") {
|
|
2509
|
+
throw operationalError("Inspector widget-session response was invalid.", value);
|
|
2510
|
+
}
|
|
2511
|
+
const r = value;
|
|
2512
|
+
if (typeof r.status !== "string") {
|
|
2513
|
+
throw operationalError(
|
|
2514
|
+
"Inspector widget-session response was missing a status.",
|
|
2515
|
+
value
|
|
2516
|
+
);
|
|
2517
|
+
}
|
|
2518
|
+
if (r.status === "rendered" && typeof r.sessionId !== "string") {
|
|
2519
|
+
throw operationalError(
|
|
2520
|
+
"Inspector widget-session response was rendered but missing a sessionId.",
|
|
2521
|
+
value
|
|
2522
|
+
);
|
|
2523
|
+
}
|
|
2524
|
+
return {
|
|
2525
|
+
status: r.status,
|
|
2526
|
+
...typeof r.sessionId === "string" ? { sessionId: r.sessionId } : {},
|
|
2527
|
+
...typeof r.mountedWidgetId === "string" ? { mountedWidgetId: r.mountedWidgetId } : {},
|
|
2528
|
+
...isViewport(r.viewport) ? { viewport: r.viewport } : {},
|
|
2529
|
+
...typeof r.expiresAt === "number" ? { expiresAt: r.expiresAt } : {},
|
|
2530
|
+
...typeof r.idleTimeoutMs === "number" ? { idleTimeoutMs: r.idleTimeoutMs } : {},
|
|
2531
|
+
...typeof r.resourceUri === "string" ? { resourceUri: r.resourceUri } : {},
|
|
2532
|
+
...typeof r.bridgeInitialized === "boolean" ? { bridgeInitialized: r.bridgeInitialized } : {},
|
|
2533
|
+
...typeof r.screenshotBase64 === "string" ? { screenshotBase64: r.screenshotBase64 } : {},
|
|
2534
|
+
...Array.isArray(r.consoleErrors) ? { consoleErrors: r.consoleErrors.map(String) } : {},
|
|
2535
|
+
...Array.isArray(r.blockedRequests) ? { blockedRequests: r.blockedRequests.map(String) } : {},
|
|
2536
|
+
...typeof r.elapsedMs === "number" ? { elapsedMs: r.elapsedMs } : {},
|
|
2537
|
+
...typeof r.hint === "string" ? { hint: r.hint } : {}
|
|
2538
|
+
};
|
|
2539
|
+
}
|
|
2540
|
+
function normalizeActionResponse(value, fallbackAction) {
|
|
2541
|
+
if (!value || typeof value !== "object") {
|
|
2542
|
+
throw operationalError(
|
|
2543
|
+
"Inspector widget-session action response was invalid.",
|
|
2544
|
+
value
|
|
2545
|
+
);
|
|
2546
|
+
}
|
|
2547
|
+
const r = value;
|
|
2548
|
+
return {
|
|
2549
|
+
action: r.action ?? fallbackAction,
|
|
2550
|
+
widgetToolCalls: Array.isArray(r.widgetToolCalls) ? r.widgetToolCalls : [],
|
|
2551
|
+
...typeof r.screenshotBase64 === "string" ? { screenshotBase64: r.screenshotBase64 } : {},
|
|
2552
|
+
...typeof r.note === "string" ? { note: r.note } : {},
|
|
2553
|
+
...typeof r.elapsedMs === "number" ? { elapsedMs: r.elapsedMs } : {},
|
|
2554
|
+
...typeof r.expiresAt === "number" ? { expiresAt: r.expiresAt } : {}
|
|
2555
|
+
};
|
|
2556
|
+
}
|
|
2557
|
+
function isViewport(value) {
|
|
2558
|
+
return !!value && typeof value === "object" && typeof value.width === "number" && typeof value.height === "number";
|
|
2559
|
+
}
|
|
2560
|
+
function buildWidgetSessionStartOutput(response, options = {}) {
|
|
2561
|
+
const screenshotCaptured = typeof response.screenshotBase64 === "string" && response.screenshotBase64.length > 0;
|
|
2562
|
+
return {
|
|
2563
|
+
status: response.status,
|
|
2564
|
+
...response.sessionId ? { sessionId: response.sessionId } : {},
|
|
2565
|
+
...response.mountedWidgetId ? { mountedWidgetId: response.mountedWidgetId } : {},
|
|
2566
|
+
...response.viewport ? { viewport: response.viewport } : {},
|
|
2567
|
+
...response.expiresAt !== void 0 ? { expiresAt: response.expiresAt } : {},
|
|
2568
|
+
...response.idleTimeoutMs !== void 0 ? { idleTimeoutMs: response.idleTimeoutMs } : {},
|
|
2569
|
+
...options.toolName ? { toolName: options.toolName } : {},
|
|
2570
|
+
...options.serverName ? { serverName: options.serverName } : {},
|
|
2571
|
+
observation: {
|
|
2572
|
+
...response.consoleErrors ? { consoleErrors: response.consoleErrors } : {},
|
|
2573
|
+
...response.blockedRequests ? { blockedRequests: response.blockedRequests } : {},
|
|
2574
|
+
...response.resourceUri ? { resourceUri: response.resourceUri } : {},
|
|
2575
|
+
...response.bridgeInitialized !== void 0 ? { bridgeInitialized: response.bridgeInitialized } : {},
|
|
2576
|
+
...response.elapsedMs !== void 0 ? { elapsedMs: response.elapsedMs } : {}
|
|
2577
|
+
},
|
|
2578
|
+
screenshotCaptured,
|
|
2579
|
+
...options.screenshotPath ? { screenshotPath: options.screenshotPath } : {},
|
|
2580
|
+
...options.includeBase64 && screenshotCaptured ? { screenshotBase64: response.screenshotBase64 } : {},
|
|
2581
|
+
...response.hint ? { hint: response.hint } : {}
|
|
2582
|
+
};
|
|
2583
|
+
}
|
|
2584
|
+
function buildWidgetSessionActionOutput(response, options = {}) {
|
|
2585
|
+
const screenshotCaptured = typeof response.screenshotBase64 === "string" && response.screenshotBase64.length > 0;
|
|
2586
|
+
return {
|
|
2587
|
+
action: response.action,
|
|
2588
|
+
widgetToolCalls: response.widgetToolCalls,
|
|
2589
|
+
...response.note ? { note: response.note } : {},
|
|
2590
|
+
...response.elapsedMs !== void 0 ? { elapsedMs: response.elapsedMs } : {},
|
|
2591
|
+
...response.expiresAt !== void 0 ? { expiresAt: response.expiresAt } : {},
|
|
2592
|
+
screenshotCaptured,
|
|
2593
|
+
...options.screenshotPath ? { screenshotPath: options.screenshotPath } : {},
|
|
2594
|
+
...options.includeBase64 && screenshotCaptured ? { screenshotBase64: response.screenshotBase64 } : {}
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
|
|
2380
2598
|
// src/commands/apps.ts
|
|
2381
2599
|
var APPS_CHECK_IDS_BY_CATEGORY = {
|
|
2382
2600
|
tools: [
|
|
@@ -2391,6 +2609,12 @@ var APPS_CHECK_IDS_BY_CATEGORY = {
|
|
|
2391
2609
|
"ui-resource-meta-valid"
|
|
2392
2610
|
]
|
|
2393
2611
|
};
|
|
2612
|
+
async function writeScreenshotIfRequested(base64, screenshotOut) {
|
|
2613
|
+
if (!screenshotOut || !base64) {
|
|
2614
|
+
return void 0;
|
|
2615
|
+
}
|
|
2616
|
+
return writeBinaryArtifact(screenshotOut, Buffer.from(base64, "base64"));
|
|
2617
|
+
}
|
|
2394
2618
|
function getConformanceGlobals(command, reporter) {
|
|
2395
2619
|
const globalOptions = command.optsWithGlobals();
|
|
2396
2620
|
return {
|
|
@@ -2535,6 +2759,141 @@ function registerAppsCommands(program) {
|
|
|
2535
2759
|
setProcessExitCode(1);
|
|
2536
2760
|
}
|
|
2537
2761
|
});
|
|
2762
|
+
const session = apps.command("session").description(
|
|
2763
|
+
"Interactive headless widget sessions (start, action, close) via the local Inspector"
|
|
2764
|
+
);
|
|
2765
|
+
addSharedServerOptions(
|
|
2766
|
+
session.command("start").description("Render a widget and keep it mounted for stepping").option("--tool-name <tool>", "Tool name").option("--name <tool>", "Alias for --tool-name").option(
|
|
2767
|
+
"--tool-args <json>",
|
|
2768
|
+
"Tool parameter object as JSON, @path, or - for stdin"
|
|
2769
|
+
).option("--params <json>", "Alias for --tool-args").option("--tool-args-stdin", "Read tool parameter JSON from stdin").option(
|
|
2770
|
+
"--screenshot-out <path>",
|
|
2771
|
+
"Write the first-frame screenshot to a file (PNG)"
|
|
2772
|
+
).option(
|
|
2773
|
+
"--screenshot-base64",
|
|
2774
|
+
"Include the screenshot inline as base64 in the JSON output"
|
|
2775
|
+
).option("--viewport <WxH>", "Headless viewport size, e.g. 1280x800").option(
|
|
2776
|
+
"--protocol <protocol>",
|
|
2777
|
+
'Render protocol: "mcp-apps" (default) or "openai-sdk"'
|
|
2778
|
+
).option("--server-name <name>", "Server name inside Inspector").option("--inspector-url <url>", "Local Inspector base URL").option(
|
|
2779
|
+
"--require-render",
|
|
2780
|
+
"Exit non-zero unless the widget renders (status !== rendered)"
|
|
2781
|
+
)
|
|
2782
|
+
).action(async (options, command) => {
|
|
2783
|
+
const globalOptions = getGlobalOptions(command);
|
|
2784
|
+
const config = parseServerConfig({
|
|
2785
|
+
...options,
|
|
2786
|
+
timeout: globalOptions.timeout
|
|
2787
|
+
});
|
|
2788
|
+
const toolName = resolveAliasedStringOption(
|
|
2789
|
+
options,
|
|
2790
|
+
[
|
|
2791
|
+
{ key: "toolName", flag: "--tool-name" },
|
|
2792
|
+
{ key: "name", flag: "--name" }
|
|
2793
|
+
],
|
|
2794
|
+
"Tool name",
|
|
2795
|
+
{ required: true }
|
|
2796
|
+
);
|
|
2797
|
+
const resolvedParamsInput = resolveAliasedStringOption(
|
|
2798
|
+
options,
|
|
2799
|
+
[
|
|
2800
|
+
{ key: "toolArgs", flag: "--tool-args" },
|
|
2801
|
+
{ key: "params", flag: "--params" }
|
|
2802
|
+
],
|
|
2803
|
+
"Tool parameters"
|
|
2804
|
+
);
|
|
2805
|
+
if (options.toolArgsStdin && resolvedParamsInput !== void 0) {
|
|
2806
|
+
throw usageError(
|
|
2807
|
+
"--tool-args-stdin cannot be used together with --tool-args or --params."
|
|
2808
|
+
);
|
|
2809
|
+
}
|
|
2810
|
+
const paramsInput = options.toolArgsStdin ? "-" : resolvedParamsInput;
|
|
2811
|
+
const parameters = parseJsonRecord(paramsInput, "Tool parameters") ?? {};
|
|
2812
|
+
const viewport = parseWidgetRenderViewport(options.viewport);
|
|
2813
|
+
const injectOpenAiCompat = resolveWidgetRenderInjectOpenAiCompat(
|
|
2814
|
+
options.protocol
|
|
2815
|
+
);
|
|
2816
|
+
const serverName = typeof options.serverName === "string" && options.serverName.trim() ? options.serverName.trim() : buildInspectorServerName(options);
|
|
2817
|
+
const response = await runWidgetSessionStart({
|
|
2818
|
+
baseUrl: options.inspectorUrl,
|
|
2819
|
+
config,
|
|
2820
|
+
serverName,
|
|
2821
|
+
toolName,
|
|
2822
|
+
parameters,
|
|
2823
|
+
injectOpenAiCompat,
|
|
2824
|
+
viewport,
|
|
2825
|
+
startIfNeeded: true,
|
|
2826
|
+
timeoutMs: globalOptions.timeout
|
|
2827
|
+
});
|
|
2828
|
+
const screenshotPath = await writeScreenshotIfRequested(
|
|
2829
|
+
response.screenshotBase64,
|
|
2830
|
+
options.screenshotOut
|
|
2831
|
+
);
|
|
2832
|
+
writeResult(
|
|
2833
|
+
buildWidgetSessionStartOutput(response, {
|
|
2834
|
+
screenshotPath,
|
|
2835
|
+
includeBase64: options.screenshotBase64 === true,
|
|
2836
|
+
toolName,
|
|
2837
|
+
serverName
|
|
2838
|
+
}),
|
|
2839
|
+
globalOptions.format
|
|
2840
|
+
);
|
|
2841
|
+
if (response.status !== "rendered" && options.requireRender) {
|
|
2842
|
+
setProcessExitCode(1);
|
|
2843
|
+
}
|
|
2844
|
+
});
|
|
2845
|
+
session.command("action").description("Drive a Computer-Use action on a session's mounted widget").requiredOption("--session <id>", "Session id from `apps session start`").requiredOption(
|
|
2846
|
+
"--action <type>",
|
|
2847
|
+
"Action: left_click, double_click, right_click, mouse_move, type, key, scroll, wait, screenshot"
|
|
2848
|
+
).option("--coordinate <x,y>", 'Click/move target, e.g. "640,400"').option("--text <text>", "Text for type / key for press").option(
|
|
2849
|
+
"--scroll-direction <dir>",
|
|
2850
|
+
"Scroll direction: up, down, left, or right"
|
|
2851
|
+
).option("--scroll-amount <n>", "Scroll amount (wheel notches)").option("--duration <ms>", "Wait duration in milliseconds").option(
|
|
2852
|
+
"--screenshot-out <path>",
|
|
2853
|
+
"Write the post-action screenshot to a file (PNG)"
|
|
2854
|
+
).option(
|
|
2855
|
+
"--screenshot-base64",
|
|
2856
|
+
"Include the screenshot inline as base64 in the JSON output"
|
|
2857
|
+
).option("--inspector-url <url>", "Local Inspector base URL").action(async (options, command) => {
|
|
2858
|
+
const globalOptions = getGlobalOptions(command);
|
|
2859
|
+
const sessionId = options.session?.trim();
|
|
2860
|
+
if (!sessionId) {
|
|
2861
|
+
throw usageError("--session is required.");
|
|
2862
|
+
}
|
|
2863
|
+
const action = parseBrowserActionSpec(options);
|
|
2864
|
+
const response = await runWidgetSessionAction({
|
|
2865
|
+
baseUrl: options.inspectorUrl,
|
|
2866
|
+
sessionId,
|
|
2867
|
+
action,
|
|
2868
|
+
timeoutMs: globalOptions.timeout
|
|
2869
|
+
});
|
|
2870
|
+
const screenshotPath = await writeScreenshotIfRequested(
|
|
2871
|
+
response.screenshotBase64,
|
|
2872
|
+
options.screenshotOut
|
|
2873
|
+
);
|
|
2874
|
+
writeResult(
|
|
2875
|
+
buildWidgetSessionActionOutput(response, {
|
|
2876
|
+
screenshotPath,
|
|
2877
|
+
includeBase64: options.screenshotBase64 === true
|
|
2878
|
+
}),
|
|
2879
|
+
globalOptions.format
|
|
2880
|
+
);
|
|
2881
|
+
});
|
|
2882
|
+
session.command("close").description("Close a widget session and dispose its browser").requiredOption("--session <id>", "Session id from `apps session start`").option("--inspector-url <url>", "Local Inspector base URL").action(
|
|
2883
|
+
async (options, command) => {
|
|
2884
|
+
const globalOptions = getGlobalOptions(command);
|
|
2885
|
+
const sessionId = options.session?.trim();
|
|
2886
|
+
if (!sessionId) {
|
|
2887
|
+
throw usageError("--session is required.");
|
|
2888
|
+
}
|
|
2889
|
+
const response = await runWidgetSessionClose({
|
|
2890
|
+
baseUrl: options.inspectorUrl,
|
|
2891
|
+
sessionId,
|
|
2892
|
+
timeoutMs: globalOptions.timeout
|
|
2893
|
+
});
|
|
2894
|
+
writeResult({ closed: response.closed }, globalOptions.format);
|
|
2895
|
+
}
|
|
2896
|
+
);
|
|
2538
2897
|
apps.command("conformance-suite").description("Run MCP Apps conformance runs from a JSON config file").requiredOption("--config <path>", "Path to JSON config file").option(
|
|
2539
2898
|
"--reporter <reporter>",
|
|
2540
2899
|
"Structured reporter output: json-summary or junit-xml"
|
|
@@ -3023,6 +3382,476 @@ function registerAuthCommands(program) {
|
|
|
3023
3382
|
}
|
|
3024
3383
|
});
|
|
3025
3384
|
}
|
|
3385
|
+
function addPlatformOptions(command) {
|
|
3386
|
+
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
3387
|
+
"--api-url <url>",
|
|
3388
|
+
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
3389
|
+
);
|
|
3390
|
+
}
|
|
3391
|
+
async function runPlatformCommand(options, timeoutMs, execute) {
|
|
3392
|
+
const controller = new AbortController();
|
|
3393
|
+
const timeoutHandle = setTimeout(() => {
|
|
3394
|
+
controller.abort(
|
|
3395
|
+
new PlatformApiError(
|
|
3396
|
+
`Request timed out after ${timeoutMs}ms`,
|
|
3397
|
+
"TIMEOUT",
|
|
3398
|
+
{
|
|
3399
|
+
status: 0
|
|
3400
|
+
}
|
|
3401
|
+
)
|
|
3402
|
+
);
|
|
3403
|
+
}, timeoutMs);
|
|
3404
|
+
timeoutHandle.unref?.();
|
|
3405
|
+
try {
|
|
3406
|
+
const { client } = buildPlatformClient({ ...options, timeoutMs });
|
|
3407
|
+
return await execute({ client, signal: controller.signal });
|
|
3408
|
+
} catch (error) {
|
|
3409
|
+
if (controller.signal.aborted && controller.signal.reason instanceof PlatformApiError) {
|
|
3410
|
+
throw toCliError(controller.signal.reason);
|
|
3411
|
+
}
|
|
3412
|
+
throw toCliError(error);
|
|
3413
|
+
} finally {
|
|
3414
|
+
clearTimeout(timeoutHandle);
|
|
3415
|
+
}
|
|
3416
|
+
}
|
|
3417
|
+
function readFileOrStdin(value, label) {
|
|
3418
|
+
try {
|
|
3419
|
+
return value === "-" ? readFileSync(0, "utf8") : readFileSync(value, "utf8");
|
|
3420
|
+
} catch (error) {
|
|
3421
|
+
throw usageError(`Failed to read ${label} "${value}".`, {
|
|
3422
|
+
source: error instanceof Error ? error.message : String(error)
|
|
3423
|
+
});
|
|
3424
|
+
}
|
|
3425
|
+
}
|
|
3426
|
+
function loadSuiteDefinition(options) {
|
|
3427
|
+
if (options.file !== void 0 && options.json !== void 0) {
|
|
3428
|
+
throw usageError("Provide either --file or --json, not both.");
|
|
3429
|
+
}
|
|
3430
|
+
let base = {};
|
|
3431
|
+
if (options.file !== void 0) {
|
|
3432
|
+
const text = readFileOrStdin(options.file, "--file");
|
|
3433
|
+
if (text.trim() === "") {
|
|
3434
|
+
throw usageError("--file input is empty.");
|
|
3435
|
+
}
|
|
3436
|
+
try {
|
|
3437
|
+
base = JSON.parse(text);
|
|
3438
|
+
} catch (error) {
|
|
3439
|
+
throw usageError("--file must contain valid JSON.", {
|
|
3440
|
+
source: error instanceof Error ? error.message : String(error)
|
|
3441
|
+
});
|
|
3442
|
+
}
|
|
3443
|
+
} else if (options.json !== void 0) {
|
|
3444
|
+
base = new JsonInputContext().parseJsonInputRecord(options.json, "--json");
|
|
3445
|
+
}
|
|
3446
|
+
if (base === void 0 || base === null) {
|
|
3447
|
+
base = {};
|
|
3448
|
+
}
|
|
3449
|
+
if (typeof base !== "object" || Array.isArray(base)) {
|
|
3450
|
+
throw usageError("Suite definition must be a JSON object.");
|
|
3451
|
+
}
|
|
3452
|
+
const merged = {
|
|
3453
|
+
...base,
|
|
3454
|
+
...options.project !== void 0 ? { project: options.project } : {},
|
|
3455
|
+
...options.name !== void 0 ? { name: options.name } : {},
|
|
3456
|
+
...options.model !== void 0 ? { model: options.model } : {},
|
|
3457
|
+
...options.provider !== void 0 ? { provider: options.provider } : {},
|
|
3458
|
+
...options.server !== void 0 ? { servers: options.server } : {}
|
|
3459
|
+
};
|
|
3460
|
+
const parsed = createEvalSuiteOperation.inputSchema.safeParse(merged);
|
|
3461
|
+
if (!parsed.success) {
|
|
3462
|
+
const detail = parsed.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
|
|
3463
|
+
throw usageError(`Invalid suite definition: ${detail}`);
|
|
3464
|
+
}
|
|
3465
|
+
return parsed.data;
|
|
3466
|
+
}
|
|
3467
|
+
function loadBodyObject(options) {
|
|
3468
|
+
if (options.file !== void 0 && options.json !== void 0) {
|
|
3469
|
+
throw usageError("Provide either --file or --json, not both.");
|
|
3470
|
+
}
|
|
3471
|
+
let base = {};
|
|
3472
|
+
if (options.file !== void 0) {
|
|
3473
|
+
const text = readFileOrStdin(options.file, "--file");
|
|
3474
|
+
if (text.trim() === "") throw usageError("--file input is empty.");
|
|
3475
|
+
try {
|
|
3476
|
+
base = JSON.parse(text);
|
|
3477
|
+
} catch (error) {
|
|
3478
|
+
throw usageError("--file must contain valid JSON.", {
|
|
3479
|
+
source: error instanceof Error ? error.message : String(error)
|
|
3480
|
+
});
|
|
3481
|
+
}
|
|
3482
|
+
} else if (options.json !== void 0) {
|
|
3483
|
+
base = new JsonInputContext().parseJsonInputRecord(options.json, "--json");
|
|
3484
|
+
}
|
|
3485
|
+
if (base === void 0 || base === null) base = {};
|
|
3486
|
+
if (typeof base !== "object" || Array.isArray(base)) {
|
|
3487
|
+
throw usageError("Body must be a JSON object.");
|
|
3488
|
+
}
|
|
3489
|
+
return base;
|
|
3490
|
+
}
|
|
3491
|
+
function validateOpInput(op, raw) {
|
|
3492
|
+
const parsed = op.inputSchema.safeParse(raw);
|
|
3493
|
+
if (!parsed.success) {
|
|
3494
|
+
const detail = parsed.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
|
|
3495
|
+
throw usageError(`Invalid input: ${detail}`);
|
|
3496
|
+
}
|
|
3497
|
+
return parsed.data;
|
|
3498
|
+
}
|
|
3499
|
+
async function executeOp(op, input, options, command) {
|
|
3500
|
+
const globalOptions = getGlobalOptions(command);
|
|
3501
|
+
const result = await runPlatformCommand(
|
|
3502
|
+
options,
|
|
3503
|
+
globalOptions.timeout,
|
|
3504
|
+
({ client, signal }) => op.execute(input, { client, signal })
|
|
3505
|
+
);
|
|
3506
|
+
writeResult(result, globalOptions.format);
|
|
3507
|
+
}
|
|
3508
|
+
function buildSuiteUpdateInput(options) {
|
|
3509
|
+
const input = { ...loadBodyObject(options) };
|
|
3510
|
+
input.suite = options.suite;
|
|
3511
|
+
if (options.project !== void 0) input.project = options.project;
|
|
3512
|
+
if (options.name !== void 0) input.name = options.name;
|
|
3513
|
+
if (options.description !== void 0)
|
|
3514
|
+
input.description = options.description;
|
|
3515
|
+
if (options.server !== void 0)
|
|
3516
|
+
input.environment = {
|
|
3517
|
+
...input.environment ?? {},
|
|
3518
|
+
servers: options.server
|
|
3519
|
+
};
|
|
3520
|
+
if (options.host !== void 0)
|
|
3521
|
+
input.hosts = options.host.map((host) => ({ host }));
|
|
3522
|
+
const exec = { ...input.executionConfig ?? {} };
|
|
3523
|
+
if (options.model !== void 0) exec.model = options.model;
|
|
3524
|
+
if (options.systemPrompt !== void 0)
|
|
3525
|
+
exec.systemPrompt = options.systemPrompt;
|
|
3526
|
+
if (options.temperature !== void 0)
|
|
3527
|
+
exec.temperature = Number(options.temperature);
|
|
3528
|
+
if (Object.keys(exec).length > 0) input.executionConfig = exec;
|
|
3529
|
+
const settings = { ...input.settings ?? {} };
|
|
3530
|
+
if (options.minAccuracy !== void 0)
|
|
3531
|
+
settings.minimumAccuracy = Number(options.minAccuracy);
|
|
3532
|
+
const mo = { ...settings.matchOptions ?? {} };
|
|
3533
|
+
if (options.toolCallOrder !== void 0)
|
|
3534
|
+
mo.toolCallOrder = options.toolCallOrder;
|
|
3535
|
+
if (options.arguments !== void 0) mo.arguments = options.arguments;
|
|
3536
|
+
if (options.extraToolCalls !== void 0)
|
|
3537
|
+
mo.extraToolCalls = options.extraToolCalls === "unlimited" ? "unlimited" : Number(options.extraToolCalls);
|
|
3538
|
+
if (Object.keys(mo).length > 0) settings.matchOptions = mo;
|
|
3539
|
+
const judge = { ...settings.judge ?? {} };
|
|
3540
|
+
if (options.judge !== void 0) {
|
|
3541
|
+
if (options.judge !== "on" && options.judge !== "off") {
|
|
3542
|
+
throw usageError('--judge must be "on" or "off".');
|
|
3543
|
+
}
|
|
3544
|
+
judge.enabled = options.judge === "on";
|
|
3545
|
+
}
|
|
3546
|
+
if (options.judgeModel !== void 0) judge.model = options.judgeModel;
|
|
3547
|
+
if (Object.keys(judge).length > 0) settings.judge = judge;
|
|
3548
|
+
if (Object.keys(settings).length > 0) input.settings = settings;
|
|
3549
|
+
return input;
|
|
3550
|
+
}
|
|
3551
|
+
function buildCaseInput(options, opts) {
|
|
3552
|
+
const input = { ...loadBodyObject(options) };
|
|
3553
|
+
if (options.project !== void 0) input.project = options.project;
|
|
3554
|
+
input.suite = options.suite;
|
|
3555
|
+
if (opts.requireCase) input.case = options.case;
|
|
3556
|
+
if (options.title !== void 0) input.title = options.title;
|
|
3557
|
+
return input;
|
|
3558
|
+
}
|
|
3559
|
+
function registerEvalCommands(program) {
|
|
3560
|
+
const evals = program.command("eval").description("Author and run eval suites in your hosted MCPJam projects");
|
|
3561
|
+
addPlatformOptions(
|
|
3562
|
+
evals.command("create").description(
|
|
3563
|
+
"Create a runnable eval suite from authored test cases (does not run it)"
|
|
3564
|
+
).option(
|
|
3565
|
+
"--project <id-or-name>",
|
|
3566
|
+
"Project name or ID (defaults to the most recently updated project)"
|
|
3567
|
+
).option(
|
|
3568
|
+
"--file <path>",
|
|
3569
|
+
"Path to a suite definition JSON file (or - for stdin)"
|
|
3570
|
+
).option(
|
|
3571
|
+
"--json <json>",
|
|
3572
|
+
"Inline suite definition JSON (or @file, or - for stdin)"
|
|
3573
|
+
).option("--name <name>", "Suite name (overrides the file)").option(
|
|
3574
|
+
"--model <model>",
|
|
3575
|
+
"Suite-level default model (overrides the file)"
|
|
3576
|
+
).option(
|
|
3577
|
+
"--provider <provider>",
|
|
3578
|
+
"Suite-level default provider (overrides the file; needed for bare/custom model ids)"
|
|
3579
|
+
).option(
|
|
3580
|
+
"--server <name...>",
|
|
3581
|
+
"Project HTTP server names or IDs (overrides the file)"
|
|
3582
|
+
)
|
|
3583
|
+
).action(async (options, command) => {
|
|
3584
|
+
const globalOptions = getGlobalOptions(command);
|
|
3585
|
+
const input = loadSuiteDefinition(options);
|
|
3586
|
+
const result = await runPlatformCommand(
|
|
3587
|
+
options,
|
|
3588
|
+
globalOptions.timeout,
|
|
3589
|
+
({ client, signal }) => createEvalSuiteOperation.execute(input, { client, signal })
|
|
3590
|
+
);
|
|
3591
|
+
writeResult(result, globalOptions.format);
|
|
3592
|
+
});
|
|
3593
|
+
addPlatformOptions(
|
|
3594
|
+
evals.command("list").description("List the eval suites saved in a project").option(
|
|
3595
|
+
"--project <id-or-name>",
|
|
3596
|
+
"Project name or ID (defaults to the most recently updated project)"
|
|
3597
|
+
)
|
|
3598
|
+
).action(async (options, command) => {
|
|
3599
|
+
const globalOptions = getGlobalOptions(command);
|
|
3600
|
+
const result = await runPlatformCommand(
|
|
3601
|
+
options,
|
|
3602
|
+
globalOptions.timeout,
|
|
3603
|
+
({ client, signal }) => listEvalSuitesOperation.execute(
|
|
3604
|
+
{ project: options.project },
|
|
3605
|
+
{ client, signal }
|
|
3606
|
+
)
|
|
3607
|
+
);
|
|
3608
|
+
writeResult(result, globalOptions.format);
|
|
3609
|
+
});
|
|
3610
|
+
addPlatformOptions(
|
|
3611
|
+
evals.command("run").description("Start an eval run of an existing suite (asynchronous)").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option(
|
|
3612
|
+
"--project <id-or-name>",
|
|
3613
|
+
"Project name or ID (defaults to the most recently updated project)"
|
|
3614
|
+
).option(
|
|
3615
|
+
"--server <name...>",
|
|
3616
|
+
"Override the suite's saved server selection (HTTP servers only)"
|
|
3617
|
+
)
|
|
3618
|
+
).action(
|
|
3619
|
+
async (options, command) => {
|
|
3620
|
+
const globalOptions = getGlobalOptions(command);
|
|
3621
|
+
const result = await runPlatformCommand(
|
|
3622
|
+
options,
|
|
3623
|
+
globalOptions.timeout,
|
|
3624
|
+
({ client, signal }) => runEvalSuiteOperation.execute(
|
|
3625
|
+
{
|
|
3626
|
+
project: options.project,
|
|
3627
|
+
suite: options.suite,
|
|
3628
|
+
...options.server ? { servers: options.server } : {}
|
|
3629
|
+
},
|
|
3630
|
+
{ client, signal }
|
|
3631
|
+
)
|
|
3632
|
+
);
|
|
3633
|
+
writeResult(result, globalOptions.format);
|
|
3634
|
+
}
|
|
3635
|
+
);
|
|
3636
|
+
addPlatformOptions(
|
|
3637
|
+
evals.command("status").description("Get the status and summary of an eval run").requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption("--project <id-or-name>", "Project name or ID")
|
|
3638
|
+
).action(
|
|
3639
|
+
async (options, command) => {
|
|
3640
|
+
const globalOptions = getGlobalOptions(command);
|
|
3641
|
+
const result = await runPlatformCommand(
|
|
3642
|
+
options,
|
|
3643
|
+
globalOptions.timeout,
|
|
3644
|
+
({ client, signal }) => getEvalRunOperation.execute(
|
|
3645
|
+
{ project: options.project, runId: options.run },
|
|
3646
|
+
{ client, signal }
|
|
3647
|
+
)
|
|
3648
|
+
);
|
|
3649
|
+
writeResult(result, globalOptions.format);
|
|
3650
|
+
}
|
|
3651
|
+
);
|
|
3652
|
+
const PROJECT_OPT = "Project name or ID (defaults to most recently updated)";
|
|
3653
|
+
addPlatformOptions(
|
|
3654
|
+
evals.command("iterations").description(
|
|
3655
|
+
"List per-iteration results for an eval run (pass/fail, tool calls, tokens, latency)"
|
|
3656
|
+
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
3657
|
+
"--project <id-or-name>",
|
|
3658
|
+
"Project the run belongs to (name or ID)"
|
|
3659
|
+
).option("--cursor <cursor>", "Pagination cursor from a previous response").option("--limit <n>", "Max iterations per page (1\u2013200)")
|
|
3660
|
+
).action(
|
|
3661
|
+
async (options, command) => {
|
|
3662
|
+
const input = validateOpInput(listEvalRunIterationsOperation, {
|
|
3663
|
+
project: options.project,
|
|
3664
|
+
runId: options.run,
|
|
3665
|
+
...options.cursor !== void 0 ? { cursor: options.cursor } : {},
|
|
3666
|
+
...options.limit !== void 0 ? { limit: Number(options.limit) } : {}
|
|
3667
|
+
});
|
|
3668
|
+
await executeOp(listEvalRunIterationsOperation, input, options, command);
|
|
3669
|
+
}
|
|
3670
|
+
);
|
|
3671
|
+
addPlatformOptions(
|
|
3672
|
+
evals.command("trace").description(
|
|
3673
|
+
"Fetch the full trace for one eval iteration (large: full message history + spans)"
|
|
3674
|
+
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
3675
|
+
"--iteration <id>",
|
|
3676
|
+
"Iteration ID (from `eval iterations`)"
|
|
3677
|
+
).requiredOption(
|
|
3678
|
+
"--project <id-or-name>",
|
|
3679
|
+
"Project the run belongs to (name or ID)"
|
|
3680
|
+
)
|
|
3681
|
+
).action(
|
|
3682
|
+
async (options, command) => {
|
|
3683
|
+
await executeOp(
|
|
3684
|
+
getEvalIterationTraceOperation,
|
|
3685
|
+
{
|
|
3686
|
+
project: options.project,
|
|
3687
|
+
runId: options.run,
|
|
3688
|
+
iterationId: options.iteration
|
|
3689
|
+
},
|
|
3690
|
+
options,
|
|
3691
|
+
command
|
|
3692
|
+
);
|
|
3693
|
+
}
|
|
3694
|
+
);
|
|
3695
|
+
addPlatformOptions(
|
|
3696
|
+
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
|
+
).action(
|
|
3698
|
+
async (options, command) => {
|
|
3699
|
+
await executeOp(
|
|
3700
|
+
getEvalSuiteOperation,
|
|
3701
|
+
{ project: options.project, suite: options.suite },
|
|
3702
|
+
options,
|
|
3703
|
+
command
|
|
3704
|
+
);
|
|
3705
|
+
}
|
|
3706
|
+
);
|
|
3707
|
+
addPlatformOptions(
|
|
3708
|
+
evals.command("update").description(
|
|
3709
|
+
"Edit an eval suite's settings (only the flags you pass change)"
|
|
3710
|
+
).requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT).option("--file <path>", "Suite-update JSON body (or - for stdin)").option("--json <json>", "Inline suite-update JSON (or @file, or -)").option("--name <name>", "Rename the suite").option("--description <text>", "Suite description").option(
|
|
3711
|
+
"--server <name...>",
|
|
3712
|
+
"Replace the suite's server selection (project server names)"
|
|
3713
|
+
).option("--host <name...>", "Replace host attachments (by name/ID)").option("--model <id>", "Execution model id").option("--system-prompt <text>", "Execution system prompt").option("--temperature <n>", "Execution temperature").option("--min-accuracy <pct>", "Minimum accuracy, 0\u2013100").option("--tool-call-order <any|in-order|exact>", "Tool call order").option("--arguments <ignore|partial|exact>", "Argument matching").option("--extra-tool-calls <unlimited|N>", "Allowed extra tool calls").option("--judge <on|off>", "Enable/disable LLM-as-judge grading").option("--judge-model <id>", "Judge model id")
|
|
3714
|
+
).action(async (options, command) => {
|
|
3715
|
+
const input = validateOpInput(
|
|
3716
|
+
updateEvalSuiteOperation,
|
|
3717
|
+
buildSuiteUpdateInput(options)
|
|
3718
|
+
);
|
|
3719
|
+
await executeOp(updateEvalSuiteOperation, input, options, command);
|
|
3720
|
+
});
|
|
3721
|
+
addPlatformOptions(
|
|
3722
|
+
evals.command("delete").description("Permanently delete an eval suite (and its cases and runs)").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT)
|
|
3723
|
+
).action(
|
|
3724
|
+
async (options, command) => {
|
|
3725
|
+
await executeOp(
|
|
3726
|
+
deleteEvalSuiteOperation,
|
|
3727
|
+
{ project: options.project, suite: options.suite },
|
|
3728
|
+
options,
|
|
3729
|
+
command
|
|
3730
|
+
);
|
|
3731
|
+
}
|
|
3732
|
+
);
|
|
3733
|
+
addPlatformOptions(
|
|
3734
|
+
evals.command("schedule").description("Enable or disable scheduled runs for a suite").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT).option("--enable", "Enable scheduled runs").option("--disable", "Disable scheduled runs").option("--interval <minutes>", "Run interval in minutes (5\u201310080)")
|
|
3735
|
+
).action(
|
|
3736
|
+
async (options, command) => {
|
|
3737
|
+
if (options.enable && options.disable) {
|
|
3738
|
+
throw usageError("Pass either --enable or --disable, not both.");
|
|
3739
|
+
}
|
|
3740
|
+
if (!options.enable && !options.disable) {
|
|
3741
|
+
throw usageError("Pass --enable or --disable.");
|
|
3742
|
+
}
|
|
3743
|
+
const input = validateOpInput(setEvalSuiteScheduleOperation, {
|
|
3744
|
+
project: options.project,
|
|
3745
|
+
suite: options.suite,
|
|
3746
|
+
enabled: Boolean(options.enable),
|
|
3747
|
+
...options.interval !== void 0 ? { intervalMinutes: Number(options.interval) } : {}
|
|
3748
|
+
});
|
|
3749
|
+
await executeOp(setEvalSuiteScheduleOperation, input, options, command);
|
|
3750
|
+
}
|
|
3751
|
+
);
|
|
3752
|
+
const cases = evals.command("cases").description("List, author, and edit an eval suite's test cases");
|
|
3753
|
+
addPlatformOptions(
|
|
3754
|
+
cases.command("list").description("List a suite's test cases").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT)
|
|
3755
|
+
).action(
|
|
3756
|
+
async (options, command) => {
|
|
3757
|
+
await executeOp(
|
|
3758
|
+
listEvalCasesOperation,
|
|
3759
|
+
{ project: options.project, suite: options.suite },
|
|
3760
|
+
options,
|
|
3761
|
+
command
|
|
3762
|
+
);
|
|
3763
|
+
}
|
|
3764
|
+
);
|
|
3765
|
+
addPlatformOptions(
|
|
3766
|
+
cases.command("get").description("Show one test case").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)
|
|
3767
|
+
).action(
|
|
3768
|
+
async (options, command) => {
|
|
3769
|
+
await executeOp(
|
|
3770
|
+
getEvalCaseOperation,
|
|
3771
|
+
{ project: options.project, suite: options.suite, case: options.case },
|
|
3772
|
+
options,
|
|
3773
|
+
command
|
|
3774
|
+
);
|
|
3775
|
+
}
|
|
3776
|
+
);
|
|
3777
|
+
addPlatformOptions(
|
|
3778
|
+
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)")
|
|
3779
|
+
).action(async (options, command) => {
|
|
3780
|
+
const input = validateOpInput(
|
|
3781
|
+
createEvalCaseOperation,
|
|
3782
|
+
buildCaseInput(options, { requireCase: false })
|
|
3783
|
+
);
|
|
3784
|
+
await executeOp(createEvalCaseOperation, input, options, command);
|
|
3785
|
+
});
|
|
3786
|
+
addPlatformOptions(
|
|
3787
|
+
cases.command("update").description("Edit a test case (definition via --file/--json)").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("--file <path>", "Case JSON body (or - for stdin)").option("--json <json>", "Inline case JSON (or @file, or -)").option("--title <title>", "Rename the case")
|
|
3788
|
+
).action(async (options, command) => {
|
|
3789
|
+
const input = validateOpInput(
|
|
3790
|
+
updateEvalCaseOperation,
|
|
3791
|
+
buildCaseInput(options, { requireCase: true })
|
|
3792
|
+
);
|
|
3793
|
+
await executeOp(updateEvalCaseOperation, input, options, command);
|
|
3794
|
+
});
|
|
3795
|
+
addPlatformOptions(
|
|
3796
|
+
cases.command("delete").description("Permanently delete a test case").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)
|
|
3797
|
+
).action(
|
|
3798
|
+
async (options, command) => {
|
|
3799
|
+
await executeOp(
|
|
3800
|
+
deleteEvalCaseOperation,
|
|
3801
|
+
{ project: options.project, suite: options.suite, case: options.case },
|
|
3802
|
+
options,
|
|
3803
|
+
command
|
|
3804
|
+
);
|
|
3805
|
+
}
|
|
3806
|
+
);
|
|
3807
|
+
addPlatformOptions(
|
|
3808
|
+
cases.command("generate").description(
|
|
3809
|
+
"AI-generate test cases from the suite's tools (spends credits)"
|
|
3810
|
+
).requiredOption("--suite <id-or-name>", "Eval suite name or ID").option("--project <id-or-name>", PROJECT_OPT).option("--mode <normal|negative>", "Generation mode (default normal)").option(
|
|
3811
|
+
"--server <name...>",
|
|
3812
|
+
"Servers to discover tools from (default: suite's)"
|
|
3813
|
+
).option(
|
|
3814
|
+
"--case-model <id...>",
|
|
3815
|
+
"Execution model(s) for the generated cases"
|
|
3816
|
+
).option("--simple <n>", "How many easy, single-tool cases").option("--multi-tool <n>", "How many medium, 2+ tool cases").option("--multi-turn <n>", "How many multi-turn follow-up cases").option("--complex <n>", "How many hard / cross-server cases").option("--negative <n>", "How many negative (no-tool) cases").option(
|
|
3817
|
+
"--vary-user-styles",
|
|
3818
|
+
"Vary query phrasing across a realistic range of user styles"
|
|
3819
|
+
)
|
|
3820
|
+
).action(
|
|
3821
|
+
async (options, command) => {
|
|
3822
|
+
const caseMix = {};
|
|
3823
|
+
for (const key of [
|
|
3824
|
+
"simple",
|
|
3825
|
+
"multiTool",
|
|
3826
|
+
"multiTurn",
|
|
3827
|
+
"complex",
|
|
3828
|
+
"negative"
|
|
3829
|
+
]) {
|
|
3830
|
+
const raw = options[key];
|
|
3831
|
+
if (raw !== void 0) {
|
|
3832
|
+
const parsed = Number(raw);
|
|
3833
|
+
if (!Number.isInteger(parsed)) {
|
|
3834
|
+
const flag = key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
3835
|
+
throw usageError(
|
|
3836
|
+
`--${flag} requires an integer value, got "${raw}".`
|
|
3837
|
+
);
|
|
3838
|
+
}
|
|
3839
|
+
caseMix[key] = parsed;
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3842
|
+
const input = validateOpInput(generateEvalCasesOperation, {
|
|
3843
|
+
project: options.project,
|
|
3844
|
+
suite: options.suite,
|
|
3845
|
+
...options.mode ? { mode: options.mode } : {},
|
|
3846
|
+
...options.server ? { servers: options.server } : {},
|
|
3847
|
+
...options.caseModel ? { caseModels: options.caseModel.map((model) => ({ model })) } : {},
|
|
3848
|
+
...Object.keys(caseMix).length > 0 ? { caseMix } : {},
|
|
3849
|
+
...options.varyUserStyles ? { varyUserStyles: true } : {}
|
|
3850
|
+
});
|
|
3851
|
+
await executeOp(generateEvalCasesOperation, input, options, command);
|
|
3852
|
+
}
|
|
3853
|
+
);
|
|
3854
|
+
}
|
|
3026
3855
|
|
|
3027
3856
|
// src/lib/server-doctor.ts
|
|
3028
3857
|
function summarizeServerDoctorTarget(target, config) {
|
|
@@ -3774,13 +4603,13 @@ function statusGlyph(status) {
|
|
|
3774
4603
|
}
|
|
3775
4604
|
|
|
3776
4605
|
// src/commands/projects.ts
|
|
3777
|
-
function
|
|
4606
|
+
function addPlatformOptions2(command) {
|
|
3778
4607
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
3779
4608
|
"--api-url <url>",
|
|
3780
4609
|
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
3781
4610
|
);
|
|
3782
4611
|
}
|
|
3783
|
-
async function
|
|
4612
|
+
async function runPlatformCommand2(options, timeoutMs, execute) {
|
|
3784
4613
|
const controller = new AbortController();
|
|
3785
4614
|
const timeoutHandle = setTimeout(() => {
|
|
3786
4615
|
controller.abort(
|
|
@@ -3808,11 +4637,11 @@ async function runPlatformCommand(options, timeoutMs, execute) {
|
|
|
3808
4637
|
}
|
|
3809
4638
|
function registerProjectsCommands(program) {
|
|
3810
4639
|
const projects = program.command("projects").description("Operate the MCP servers saved in your hosted MCPJam projects");
|
|
3811
|
-
|
|
4640
|
+
addPlatformOptions2(
|
|
3812
4641
|
projects.command("list").description("List the projects you can access")
|
|
3813
4642
|
).action(async (options, command) => {
|
|
3814
4643
|
const globalOptions = getGlobalOptions(command);
|
|
3815
|
-
const result = await
|
|
4644
|
+
const result = await runPlatformCommand2(
|
|
3816
4645
|
options,
|
|
3817
4646
|
globalOptions.timeout,
|
|
3818
4647
|
({ client, signal }) => listProjectsOperation.execute({}, { client, signal })
|
|
@@ -3824,14 +4653,14 @@ function registerProjectsCommands(program) {
|
|
|
3824
4653
|
writeResult(result, globalOptions.format);
|
|
3825
4654
|
}
|
|
3826
4655
|
});
|
|
3827
|
-
|
|
4656
|
+
addPlatformOptions2(
|
|
3828
4657
|
projects.command("servers").description("List the servers saved in a project").option(
|
|
3829
4658
|
"--project <id-or-name>",
|
|
3830
4659
|
"Project name or ID (defaults to the most recently updated project)"
|
|
3831
4660
|
)
|
|
3832
4661
|
).action(async (options, command) => {
|
|
3833
4662
|
const globalOptions = getGlobalOptions(command);
|
|
3834
|
-
const result = await
|
|
4663
|
+
const result = await runPlatformCommand2(
|
|
3835
4664
|
options,
|
|
3836
4665
|
globalOptions.timeout,
|
|
3837
4666
|
({ client, signal }) => listProjectServersOperation.execute(
|
|
@@ -3846,7 +4675,7 @@ function registerProjectsCommands(program) {
|
|
|
3846
4675
|
writeResult(result, globalOptions.format);
|
|
3847
4676
|
}
|
|
3848
4677
|
});
|
|
3849
|
-
|
|
4678
|
+
addPlatformOptions2(
|
|
3850
4679
|
projects.command("status").description(
|
|
3851
4680
|
"Health-check every server in a project (hosted doctor per server)"
|
|
3852
4681
|
).option(
|
|
@@ -3855,7 +4684,7 @@ function registerProjectsCommands(program) {
|
|
|
3855
4684
|
)
|
|
3856
4685
|
).action(async (options, command) => {
|
|
3857
4686
|
const globalOptions = getGlobalOptions(command);
|
|
3858
|
-
const payload = await
|
|
4687
|
+
const payload = await runPlatformCommand2(
|
|
3859
4688
|
options,
|
|
3860
4689
|
globalOptions.timeout,
|
|
3861
4690
|
({ client, signal }) => showServersOperation.execute(
|
|
@@ -7739,6 +8568,7 @@ async function main(argv = process.argv, dependencies = {}) {
|
|
|
7739
8568
|
registerProtocolCommands(program);
|
|
7740
8569
|
registerAuthCommands(program);
|
|
7741
8570
|
registerProjectsCommands(program);
|
|
8571
|
+
registerEvalCommands(program);
|
|
7742
8572
|
registerTunnelCommands(program);
|
|
7743
8573
|
registerInspectorCommands(program);
|
|
7744
8574
|
registerMcpCommands(program);
|