@mcpjam/cli 3.7.0 → 3.8.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 +541 -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 { 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.8.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,177 @@ 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(`Request timed out after ${timeoutMs}ms`, "TIMEOUT", {
|
|
3396
|
+
status: 0
|
|
3397
|
+
})
|
|
3398
|
+
);
|
|
3399
|
+
}, timeoutMs);
|
|
3400
|
+
timeoutHandle.unref?.();
|
|
3401
|
+
try {
|
|
3402
|
+
const { client } = buildPlatformClient({ ...options, timeoutMs });
|
|
3403
|
+
return await execute({ client, signal: controller.signal });
|
|
3404
|
+
} catch (error) {
|
|
3405
|
+
if (controller.signal.aborted && controller.signal.reason instanceof PlatformApiError) {
|
|
3406
|
+
throw toCliError(controller.signal.reason);
|
|
3407
|
+
}
|
|
3408
|
+
throw toCliError(error);
|
|
3409
|
+
} finally {
|
|
3410
|
+
clearTimeout(timeoutHandle);
|
|
3411
|
+
}
|
|
3412
|
+
}
|
|
3413
|
+
function readFileOrStdin(value, label) {
|
|
3414
|
+
try {
|
|
3415
|
+
return value === "-" ? readFileSync(0, "utf8") : readFileSync(value, "utf8");
|
|
3416
|
+
} catch (error) {
|
|
3417
|
+
throw usageError(`Failed to read ${label} "${value}".`, {
|
|
3418
|
+
source: error instanceof Error ? error.message : String(error)
|
|
3419
|
+
});
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
function loadSuiteDefinition(options) {
|
|
3423
|
+
if (options.file !== void 0 && options.json !== void 0) {
|
|
3424
|
+
throw usageError("Provide either --file or --json, not both.");
|
|
3425
|
+
}
|
|
3426
|
+
let base = {};
|
|
3427
|
+
if (options.file !== void 0) {
|
|
3428
|
+
const text = readFileOrStdin(options.file, "--file");
|
|
3429
|
+
if (text.trim() === "") {
|
|
3430
|
+
throw usageError("--file input is empty.");
|
|
3431
|
+
}
|
|
3432
|
+
try {
|
|
3433
|
+
base = JSON.parse(text);
|
|
3434
|
+
} catch (error) {
|
|
3435
|
+
throw usageError("--file must contain valid JSON.", {
|
|
3436
|
+
source: error instanceof Error ? error.message : String(error)
|
|
3437
|
+
});
|
|
3438
|
+
}
|
|
3439
|
+
} else if (options.json !== void 0) {
|
|
3440
|
+
base = new JsonInputContext().parseJsonInputRecord(options.json, "--json");
|
|
3441
|
+
}
|
|
3442
|
+
if (base === void 0 || base === null) {
|
|
3443
|
+
base = {};
|
|
3444
|
+
}
|
|
3445
|
+
if (typeof base !== "object" || Array.isArray(base)) {
|
|
3446
|
+
throw usageError("Suite definition must be a JSON object.");
|
|
3447
|
+
}
|
|
3448
|
+
const merged = {
|
|
3449
|
+
...base,
|
|
3450
|
+
...options.project !== void 0 ? { project: options.project } : {},
|
|
3451
|
+
...options.name !== void 0 ? { name: options.name } : {},
|
|
3452
|
+
...options.model !== void 0 ? { model: options.model } : {},
|
|
3453
|
+
...options.provider !== void 0 ? { provider: options.provider } : {},
|
|
3454
|
+
...options.server !== void 0 ? { servers: options.server } : {}
|
|
3455
|
+
};
|
|
3456
|
+
const parsed = createEvalSuiteOperation.inputSchema.safeParse(merged);
|
|
3457
|
+
if (!parsed.success) {
|
|
3458
|
+
const detail = parsed.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
|
|
3459
|
+
throw usageError(`Invalid suite definition: ${detail}`);
|
|
3460
|
+
}
|
|
3461
|
+
return parsed.data;
|
|
3462
|
+
}
|
|
3463
|
+
function registerEvalCommands(program) {
|
|
3464
|
+
const evals = program.command("eval").description("Author and run eval suites in your hosted MCPJam projects");
|
|
3465
|
+
addPlatformOptions(
|
|
3466
|
+
evals.command("create").description(
|
|
3467
|
+
"Create a runnable eval suite from authored test cases (does not run it)"
|
|
3468
|
+
).option(
|
|
3469
|
+
"--project <id-or-name>",
|
|
3470
|
+
"Project name or ID (defaults to the most recently updated project)"
|
|
3471
|
+
).option(
|
|
3472
|
+
"--file <path>",
|
|
3473
|
+
"Path to a suite definition JSON file (or - for stdin)"
|
|
3474
|
+
).option(
|
|
3475
|
+
"--json <json>",
|
|
3476
|
+
"Inline suite definition JSON (or @file, or - for stdin)"
|
|
3477
|
+
).option("--name <name>", "Suite name (overrides the file)").option("--model <model>", "Suite-level default model (overrides the file)").option(
|
|
3478
|
+
"--provider <provider>",
|
|
3479
|
+
"Suite-level default provider (overrides the file; needed for bare/custom model ids)"
|
|
3480
|
+
).option(
|
|
3481
|
+
"--server <name...>",
|
|
3482
|
+
"Project HTTP server names or IDs (overrides the file)"
|
|
3483
|
+
)
|
|
3484
|
+
).action(async (options, command) => {
|
|
3485
|
+
const globalOptions = getGlobalOptions(command);
|
|
3486
|
+
const input = loadSuiteDefinition(options);
|
|
3487
|
+
const result = await runPlatformCommand(
|
|
3488
|
+
options,
|
|
3489
|
+
globalOptions.timeout,
|
|
3490
|
+
({ client, signal }) => createEvalSuiteOperation.execute(input, { client, signal })
|
|
3491
|
+
);
|
|
3492
|
+
writeResult(result, globalOptions.format);
|
|
3493
|
+
});
|
|
3494
|
+
addPlatformOptions(
|
|
3495
|
+
evals.command("list").description("List the eval suites saved in a project").option(
|
|
3496
|
+
"--project <id-or-name>",
|
|
3497
|
+
"Project name or ID (defaults to the most recently updated project)"
|
|
3498
|
+
)
|
|
3499
|
+
).action(
|
|
3500
|
+
async (options, command) => {
|
|
3501
|
+
const globalOptions = getGlobalOptions(command);
|
|
3502
|
+
const result = await runPlatformCommand(
|
|
3503
|
+
options,
|
|
3504
|
+
globalOptions.timeout,
|
|
3505
|
+
({ client, signal }) => listEvalSuitesOperation.execute(
|
|
3506
|
+
{ project: options.project },
|
|
3507
|
+
{ client, signal }
|
|
3508
|
+
)
|
|
3509
|
+
);
|
|
3510
|
+
writeResult(result, globalOptions.format);
|
|
3511
|
+
}
|
|
3512
|
+
);
|
|
3513
|
+
addPlatformOptions(
|
|
3514
|
+
evals.command("run").description("Start an eval run of an existing suite (asynchronous)").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option(
|
|
3515
|
+
"--project <id-or-name>",
|
|
3516
|
+
"Project name or ID (defaults to the most recently updated project)"
|
|
3517
|
+
).option(
|
|
3518
|
+
"--server <name...>",
|
|
3519
|
+
"Override the suite's saved server selection (HTTP servers only)"
|
|
3520
|
+
)
|
|
3521
|
+
).action(
|
|
3522
|
+
async (options, command) => {
|
|
3523
|
+
const globalOptions = getGlobalOptions(command);
|
|
3524
|
+
const result = await runPlatformCommand(
|
|
3525
|
+
options,
|
|
3526
|
+
globalOptions.timeout,
|
|
3527
|
+
({ client, signal }) => runEvalSuiteOperation.execute(
|
|
3528
|
+
{
|
|
3529
|
+
project: options.project,
|
|
3530
|
+
suite: options.suite,
|
|
3531
|
+
...options.server ? { servers: options.server } : {}
|
|
3532
|
+
},
|
|
3533
|
+
{ client, signal }
|
|
3534
|
+
)
|
|
3535
|
+
);
|
|
3536
|
+
writeResult(result, globalOptions.format);
|
|
3537
|
+
}
|
|
3538
|
+
);
|
|
3539
|
+
addPlatformOptions(
|
|
3540
|
+
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")
|
|
3541
|
+
).action(
|
|
3542
|
+
async (options, command) => {
|
|
3543
|
+
const globalOptions = getGlobalOptions(command);
|
|
3544
|
+
const result = await runPlatformCommand(
|
|
3545
|
+
options,
|
|
3546
|
+
globalOptions.timeout,
|
|
3547
|
+
({ client, signal }) => getEvalRunOperation.execute(
|
|
3548
|
+
{ project: options.project, runId: options.run },
|
|
3549
|
+
{ client, signal }
|
|
3550
|
+
)
|
|
3551
|
+
);
|
|
3552
|
+
writeResult(result, globalOptions.format);
|
|
3553
|
+
}
|
|
3554
|
+
);
|
|
3555
|
+
}
|
|
3026
3556
|
|
|
3027
3557
|
// src/lib/server-doctor.ts
|
|
3028
3558
|
function summarizeServerDoctorTarget(target, config) {
|
|
@@ -3774,13 +4304,13 @@ function statusGlyph(status) {
|
|
|
3774
4304
|
}
|
|
3775
4305
|
|
|
3776
4306
|
// src/commands/projects.ts
|
|
3777
|
-
function
|
|
4307
|
+
function addPlatformOptions2(command) {
|
|
3778
4308
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
3779
4309
|
"--api-url <url>",
|
|
3780
4310
|
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
3781
4311
|
);
|
|
3782
4312
|
}
|
|
3783
|
-
async function
|
|
4313
|
+
async function runPlatformCommand2(options, timeoutMs, execute) {
|
|
3784
4314
|
const controller = new AbortController();
|
|
3785
4315
|
const timeoutHandle = setTimeout(() => {
|
|
3786
4316
|
controller.abort(
|
|
@@ -3808,11 +4338,11 @@ async function runPlatformCommand(options, timeoutMs, execute) {
|
|
|
3808
4338
|
}
|
|
3809
4339
|
function registerProjectsCommands(program) {
|
|
3810
4340
|
const projects = program.command("projects").description("Operate the MCP servers saved in your hosted MCPJam projects");
|
|
3811
|
-
|
|
4341
|
+
addPlatformOptions2(
|
|
3812
4342
|
projects.command("list").description("List the projects you can access")
|
|
3813
4343
|
).action(async (options, command) => {
|
|
3814
4344
|
const globalOptions = getGlobalOptions(command);
|
|
3815
|
-
const result = await
|
|
4345
|
+
const result = await runPlatformCommand2(
|
|
3816
4346
|
options,
|
|
3817
4347
|
globalOptions.timeout,
|
|
3818
4348
|
({ client, signal }) => listProjectsOperation.execute({}, { client, signal })
|
|
@@ -3824,14 +4354,14 @@ function registerProjectsCommands(program) {
|
|
|
3824
4354
|
writeResult(result, globalOptions.format);
|
|
3825
4355
|
}
|
|
3826
4356
|
});
|
|
3827
|
-
|
|
4357
|
+
addPlatformOptions2(
|
|
3828
4358
|
projects.command("servers").description("List the servers saved in a project").option(
|
|
3829
4359
|
"--project <id-or-name>",
|
|
3830
4360
|
"Project name or ID (defaults to the most recently updated project)"
|
|
3831
4361
|
)
|
|
3832
4362
|
).action(async (options, command) => {
|
|
3833
4363
|
const globalOptions = getGlobalOptions(command);
|
|
3834
|
-
const result = await
|
|
4364
|
+
const result = await runPlatformCommand2(
|
|
3835
4365
|
options,
|
|
3836
4366
|
globalOptions.timeout,
|
|
3837
4367
|
({ client, signal }) => listProjectServersOperation.execute(
|
|
@@ -3846,7 +4376,7 @@ function registerProjectsCommands(program) {
|
|
|
3846
4376
|
writeResult(result, globalOptions.format);
|
|
3847
4377
|
}
|
|
3848
4378
|
});
|
|
3849
|
-
|
|
4379
|
+
addPlatformOptions2(
|
|
3850
4380
|
projects.command("status").description(
|
|
3851
4381
|
"Health-check every server in a project (hosted doctor per server)"
|
|
3852
4382
|
).option(
|
|
@@ -3855,7 +4385,7 @@ function registerProjectsCommands(program) {
|
|
|
3855
4385
|
)
|
|
3856
4386
|
).action(async (options, command) => {
|
|
3857
4387
|
const globalOptions = getGlobalOptions(command);
|
|
3858
|
-
const payload = await
|
|
4388
|
+
const payload = await runPlatformCommand2(
|
|
3859
4389
|
options,
|
|
3860
4390
|
globalOptions.timeout,
|
|
3861
4391
|
({ client, signal }) => showServersOperation.execute(
|
|
@@ -7739,6 +8269,7 @@ async function main(argv = process.argv, dependencies = {}) {
|
|
|
7739
8269
|
registerProtocolCommands(program);
|
|
7740
8270
|
registerAuthCommands(program);
|
|
7741
8271
|
registerProjectsCommands(program);
|
|
8272
|
+
registerEvalCommands(program);
|
|
7742
8273
|
registerTunnelCommands(program);
|
|
7743
8274
|
registerInspectorCommands(program);
|
|
7744
8275
|
registerMcpCommands(program);
|