@mcpjam/cli 3.15.2 → 3.17.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 +2442 -184
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
import { Command, CommanderError } from 'commander';
|
|
3
3
|
import { realpathSync, mkdirSync, writeFileSync, readFileSync, existsSync, statSync, closeSync, renameSync, openSync } from 'fs';
|
|
4
4
|
import { pathToFileURL } from 'url';
|
|
5
|
-
import { probeMcpServer, redactSensitiveValue, runServerDoctor, collectServerSnapshot, serializeStableServerSnapshot, serializeServerSnapshot, buildServerDiffReport, validateToolCallResult, isCallToolResultError, buildToolCallValidationReport, listResources, readResource, listTools, listPrompts, getPrompt, MCPAppsConformanceTest, MCPAppsConformanceSuite, runOAuthLogin, OAuthConformanceTest, OAuthConformanceSuite, runXaaFlow, MCPConformanceTest, MCPConformanceSuite, withEphemeralClient, diffServerSnapshots, ServerSnapshotFormatError, renderStructuredRunJUnitXml, renderStructuredRunJson, toConformanceReport, renderConformanceReportJUnitXml, renderConformanceReportJson, formatOAuthConformanceHuman, formatOAuthConformanceSuiteHuman, fetchOAuthMetadata, executeOAuthProxy, executeDebugOAuthProxy, normalizeRegistrationStrategy, normalizeXaaClientAuth, normalizeIdentityAssertionFormat, IDENTITY_ASSERTION_FORMATS, XAA_CONFIDENTIAL_CIMD_ORIGIN, getLocalConfidentialCimdProvider, generateRandomString, generateCodeChallenge, createInteractiveAuthorizationSession, openUrlInBrowser, MCPClientManager, MCP_APPS_CHECK_CATEGORIES, MCP_APPS_CHECK_IDS, OAuthProxyError, isLoopbackHost, MCP_CHECK_CATEGORIES, MCP_CHECK_IDS } from '@mcpjam/sdk';
|
|
5
|
+
import { probeMcpServer, redactSensitiveValue, runServerDoctor, collectServerSnapshot, serializeStableServerSnapshot, serializeServerSnapshot, buildServerDiffReport, validateToolCallResult, isCallToolResultError, buildToolCallValidationReport, listResources, readResource, SubscriptionCoordinator, listTools, listPrompts, getPrompt, MCPAppsConformanceTest, MCPAppsConformanceSuite, MCPTasksConformanceTest, runOAuthLogin, OAuthConformanceTest, OAuthConformanceSuite, runXaaFlow, MCPConformanceTest, MCPConformanceSuite, withEphemeralClient, diffServerSnapshots, ServerSnapshotFormatError, renderStructuredRunJUnitXml, renderStructuredRunJson, DEFAULT_SUBSCRIPTION_RECONNECT_POLICY, isKnownProtocolVersion, toConformanceReport, renderConformanceReportJUnitXml, renderConformanceReportJson, formatOAuthConformanceHuman, formatOAuthConformanceSuiteHuman, fetchOAuthMetadata, executeOAuthProxy, executeDebugOAuthProxy, normalizeRegistrationStrategy, normalizeXaaClientAuth, normalizeIdentityAssertionFormat, IDENTITY_ASSERTION_FORMATS, XAA_CONFIDENTIAL_CIMD_ORIGIN, getLocalConfidentialCimdProvider, MCP_PROTOCOL_VERSIONS, generateRandomString, generateCodeChallenge, createInteractiveAuthorizationSession, openUrlInBrowser, MCPClientManager, canDeclareTasksExtension, createStrictElicitationContentValidator, MCP_APPS_CHECK_CATEGORIES, MCP_APPS_CHECK_IDS, MCP_TASKS_CHECK_CATEGORIES, MCP_TASKS_CHECK_IDS, OAuthProxyError, isLoopbackHost, MCP_CHECK_CATEGORIES, MCP_CHECK_IDS, TaskLifecycleEngine, driveTaskToTerminal, extensionTaskToObservation, legacyTaskToObservation, isUnknownTaskError, isMCPTasksWireError, LEGACY_TASK_STATUSES } from '@mcpjam/sdk';
|
|
6
6
|
import { mkdir, writeFile, readFile, chmod, rename, rm } from 'fs/promises';
|
|
7
7
|
import path2, { dirname, join, basename } from 'path';
|
|
8
8
|
import { randomUUID } from 'crypto';
|
|
9
9
|
import { spawn } from 'child_process';
|
|
10
10
|
import { createRequire } from 'module';
|
|
11
11
|
import os, { homedir } from 'os';
|
|
12
|
-
import { cancelEvalRunOperation, listEvalRunIterationsOperation, getEvalIterationTraceOperation, getEvalRunStepsOperation, getEvalSuiteOperation, updateEvalSuiteOperation, deleteEvalSuiteOperation, setEvalSuiteScheduleOperation, listEvalCasesOperation, getEvalCaseOperation, runEvalCaseOperation, createEvalCaseOperation, updateEvalCaseOperation, deleteEvalCaseOperation, generateEvalCasesOperation, createHostOperation, updateHostOperation, createEnvironmentOperation, updateEnvironmentOperation, createTunnelOperation, DEFAULT_PLATFORM_API_BASE_URL, PlatformApiClient, isPlatformApiError, PlatformApiError, listProjectsOperation, listProjectServersOperation, showServersOperation, createEvalSuiteOperation, listEvalSuitesOperation, runEvalSuiteOperation, getEvalRunOperation, listHostsOperation, getHostOperation, deleteHostOperation, listEnvironmentsOperation, getEnvironmentOperation,
|
|
12
|
+
import { cancelEvalRunOperation, listEvalRunIterationsOperation, getEvalIterationTraceOperation, getEvalRunStepsOperation, getEvalSuiteOperation, updateEvalSuiteOperation, deleteEvalSuiteOperation, setEvalSuiteScheduleOperation, listEvalCasesOperation, getEvalCaseOperation, runEvalCaseOperation, createEvalCaseOperation, updateEvalCaseOperation, deleteEvalCaseOperation, generateEvalCasesOperation, createHostOperation, updateHostOperation, createEnvironmentOperation, updateEnvironmentOperation, createImageOperation, validateImageBlueprintOperation, updateImageOperation, createTunnelOperation, DEFAULT_PLATFORM_API_BASE_URL, PlatformApiClient, isPlatformApiError, PlatformApiError, listProjectsOperation, listProjectServersOperation, showServersOperation, createEvalSuiteOperation, listEvalSuitesOperation, runEvalSuiteOperation, getEvalRunOperation, listHostsOperation, getHostOperation, deleteHostOperation, listEnvironmentsOperation, getEnvironmentOperation, resolveEnvironmentOperation, archiveEnvironmentOperation, restoreEnvironmentOperation, listImagesOperation, getImageOperation, buildImageOperation, listImageBuildsOperation, useImageOperation, resetComputerOperation, promoteImageOperation, deleteImageOperation } from '@mcpjam/sdk/platform';
|
|
13
13
|
import { buildHostProfilesFromCatalog, buildMarketHostProfiles, scanWidgetUsage, evaluateMarketHosts, fetchHostCompatCatalog } from '@mcpjam/sdk/host-compat';
|
|
14
14
|
import { HOST_TEMPLATES as HOST_TEMPLATES$1, HOST_TEMPLATE_IDS, seedHostTemplate } from '@mcpjam/sdk/host-config/templates';
|
|
15
15
|
import { applyVisibilityPolicyAndCountSignals, isAppOnlyTool, extractHostExecutionPolicy, hostConnectionProfile } from '@mcpjam/sdk/host-config/internal';
|
|
16
|
+
import * as readline from 'readline/promises';
|
|
16
17
|
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
17
18
|
import { McpServer } from '@modelcontextprotocol/server';
|
|
18
19
|
import { z } from 'zod';
|
|
@@ -24,7 +25,7 @@ import { WebSocket } from 'ws';
|
|
|
24
25
|
|
|
25
26
|
// package.json
|
|
26
27
|
var package_default = {
|
|
27
|
-
version: "3.
|
|
28
|
+
version: "3.17.0"};
|
|
28
29
|
|
|
29
30
|
// src/lib/output.ts
|
|
30
31
|
var DEFAULT_OUTPUT_FORMAT = "json";
|
|
@@ -141,8 +142,10 @@ function setProcessExitCode(code) {
|
|
|
141
142
|
var VALID_PROTOCOL_VERSIONS = /* @__PURE__ */ new Set([
|
|
142
143
|
"2025-03-26",
|
|
143
144
|
"2025-06-18",
|
|
144
|
-
"2025-11-25"
|
|
145
|
+
"2025-11-25",
|
|
146
|
+
"2026-07-28"
|
|
145
147
|
]);
|
|
148
|
+
var CIMD_PROTOCOL_VERSIONS = /* @__PURE__ */ new Set(["2025-11-25", "2026-07-28"]);
|
|
146
149
|
var VALID_REGISTRATION_STRATEGIES = /* @__PURE__ */ new Set([
|
|
147
150
|
"cimd",
|
|
148
151
|
"dcr",
|
|
@@ -245,6 +248,13 @@ function validateProtocolRun(run, label) {
|
|
|
245
248
|
validateOptionalString(run.label, `${label}.label`);
|
|
246
249
|
validateEnumArray(run.categories, MCP_CHECK_CATEGORIES, `${label}.categories`);
|
|
247
250
|
validateEnumArray(run.checkIds, MCP_CHECK_IDS, `${label}.checkIds`);
|
|
251
|
+
if (run.protocolVersion !== void 0) {
|
|
252
|
+
if (typeof run.protocolVersion !== "string" || !isKnownProtocolVersion(run.protocolVersion)) {
|
|
253
|
+
throw usageError(
|
|
254
|
+
`Invalid ${label}.protocolVersion "${String(run.protocolVersion)}". Known: ${MCP_PROTOCOL_VERSIONS.join(", ")}`
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
248
258
|
}
|
|
249
259
|
function validateOAuthFlow(flow, defaults, index) {
|
|
250
260
|
validateOptionalString(flow.label, `flows[${index}].label`);
|
|
@@ -2663,6 +2673,9 @@ function registerAppsCommands(program) {
|
|
|
2663
2673
|
).option(
|
|
2664
2674
|
"--reporter <reporter>",
|
|
2665
2675
|
"Structured reporter output: json-summary or junit-xml"
|
|
2676
|
+
).option(
|
|
2677
|
+
"--protocol-version <version>",
|
|
2678
|
+
"Pin the MCP protocol version for the conformance connection (e.g. 2026-07-28). HTTP targets only."
|
|
2666
2679
|
)
|
|
2667
2680
|
).action(async (options, command) => {
|
|
2668
2681
|
const reporter = parseReporterFormat(options.reporter);
|
|
@@ -2968,8 +2981,22 @@ function buildAppsConformanceConfig(options) {
|
|
|
2968
2981
|
)
|
|
2969
2982
|
)
|
|
2970
2983
|
) : void 0;
|
|
2984
|
+
const trimmedProtocolVersion = options.protocolVersion?.trim();
|
|
2985
|
+
let mcpProtocolVersion;
|
|
2986
|
+
if (trimmedProtocolVersion) {
|
|
2987
|
+
if (!isKnownProtocolVersion(trimmedProtocolVersion)) {
|
|
2988
|
+
throw usageError(`Unknown --protocol-version: ${trimmedProtocolVersion}`);
|
|
2989
|
+
}
|
|
2990
|
+
if (!("url" in serverConfig) || !serverConfig.url) {
|
|
2991
|
+
throw usageError(
|
|
2992
|
+
"--protocol-version can only be used with an HTTP target (--url)."
|
|
2993
|
+
);
|
|
2994
|
+
}
|
|
2995
|
+
mcpProtocolVersion = trimmedProtocolVersion;
|
|
2996
|
+
}
|
|
2971
2997
|
return {
|
|
2972
2998
|
...serverConfig,
|
|
2999
|
+
...mcpProtocolVersion ? { mcpProtocolVersion } : {},
|
|
2973
3000
|
...resolvedCheckIds && resolvedCheckIds.length > 0 ? { checkIds: resolvedCheckIds } : {}
|
|
2974
3001
|
};
|
|
2975
3002
|
}
|
|
@@ -3472,16 +3499,545 @@ async function assertToolVisibleToHost(manager, serverId, toolName, host) {
|
|
|
3472
3499
|
`Could not verify "${toolName}" is visible to host "${host.id}" \u2014 the server's tool list is too long to page through. Omit --host to call it as an operator.`
|
|
3473
3500
|
);
|
|
3474
3501
|
}
|
|
3502
|
+
var MrtrCollectAbortError = class extends Error {
|
|
3503
|
+
constructor(message = "MRTR input collection was aborted.") {
|
|
3504
|
+
super(message);
|
|
3505
|
+
this.name = "AbortError";
|
|
3506
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
3507
|
+
}
|
|
3508
|
+
};
|
|
3509
|
+
function sanitizeTerminalText(value) {
|
|
3510
|
+
return value.replace(/[\u0000-\u0008\u000A-\u001F\u007F-\u009F]/g, " ");
|
|
3511
|
+
}
|
|
3512
|
+
function resolveNonInteractive(args) {
|
|
3513
|
+
if (args.yes) return true;
|
|
3514
|
+
const env = args.env ?? process.env;
|
|
3515
|
+
if (env.CI || env.MCPJAM_NON_INTERACTIVE) return true;
|
|
3516
|
+
return args.stdinIsTTY !== true;
|
|
3517
|
+
}
|
|
3518
|
+
var INTERACTIVE_ELICITATION_CAPABILITY = {
|
|
3519
|
+
form: {},
|
|
3520
|
+
url: {}
|
|
3521
|
+
};
|
|
3522
|
+
function buildMrtrBeforeConnect(options) {
|
|
3523
|
+
if (!options.interactive) return void 0;
|
|
3524
|
+
const nonInteractive = resolveNonInteractive({
|
|
3525
|
+
yes: options.yes,
|
|
3526
|
+
stdinIsTTY: Boolean(process.stdin.isTTY)
|
|
3527
|
+
});
|
|
3528
|
+
const collectorOptions = { nonInteractive };
|
|
3529
|
+
const collector = createStdinMrtrCollector(collectorOptions);
|
|
3530
|
+
const handler = createStdinElicitationHandler(collectorOptions);
|
|
3531
|
+
return (manager, serverId) => {
|
|
3532
|
+
manager.setMrtrInputCollector(serverId, collector);
|
|
3533
|
+
manager.setElicitationHandler(serverId, handler);
|
|
3534
|
+
};
|
|
3535
|
+
}
|
|
3536
|
+
function parseElicitationFields(requestedSchema) {
|
|
3537
|
+
if (!isRecord(requestedSchema)) return [];
|
|
3538
|
+
const properties = requestedSchema.properties;
|
|
3539
|
+
if (!isRecord(properties)) return [];
|
|
3540
|
+
const required = new Set(
|
|
3541
|
+
Array.isArray(requestedSchema.required) ? requestedSchema.required.filter((v) => typeof v === "string") : []
|
|
3542
|
+
);
|
|
3543
|
+
const fields = [];
|
|
3544
|
+
for (const key of Object.keys(properties)) {
|
|
3545
|
+
const prop = properties[key];
|
|
3546
|
+
if (!isRecord(prop)) {
|
|
3547
|
+
fields.push({ key, type: "string", required: required.has(key) });
|
|
3548
|
+
continue;
|
|
3549
|
+
}
|
|
3550
|
+
const title = typeof prop.title === "string" ? prop.title : void 0;
|
|
3551
|
+
const description = typeof prop.description === "string" ? prop.description : void 0;
|
|
3552
|
+
const scalarEnum = extractEnum(prop);
|
|
3553
|
+
if (scalarEnum) {
|
|
3554
|
+
fields.push({
|
|
3555
|
+
key,
|
|
3556
|
+
type: "enum",
|
|
3557
|
+
required: required.has(key),
|
|
3558
|
+
title,
|
|
3559
|
+
description,
|
|
3560
|
+
enumValues: scalarEnum.values,
|
|
3561
|
+
...scalarEnum.names ? { enumNames: scalarEnum.names } : {}
|
|
3562
|
+
});
|
|
3563
|
+
continue;
|
|
3564
|
+
}
|
|
3565
|
+
if (prop.type === "array") {
|
|
3566
|
+
const items = isRecord(prop.items) ? prop.items : void 0;
|
|
3567
|
+
const itemEnum = items ? extractEnum(items) : void 0;
|
|
3568
|
+
const itemRawType = items && typeof items.type === "string" ? items.type : "string";
|
|
3569
|
+
const itemType = itemRawType === "number" ? "number" : itemRawType === "integer" ? "integer" : itemRawType === "boolean" ? "boolean" : "string";
|
|
3570
|
+
fields.push({
|
|
3571
|
+
key,
|
|
3572
|
+
type: "array",
|
|
3573
|
+
required: required.has(key),
|
|
3574
|
+
title,
|
|
3575
|
+
description,
|
|
3576
|
+
...itemEnum ? { enumValues: itemEnum.values } : {},
|
|
3577
|
+
...itemEnum?.names ? { enumNames: itemEnum.names } : {},
|
|
3578
|
+
...itemEnum ? {} : { itemType },
|
|
3579
|
+
...required.has(key) && !isPositiveInteger(prop.minItems) ? { allowEmpty: true } : {},
|
|
3580
|
+
...withConstraints(prop)
|
|
3581
|
+
});
|
|
3582
|
+
continue;
|
|
3583
|
+
}
|
|
3584
|
+
const rawType = typeof prop.type === "string" ? prop.type : "string";
|
|
3585
|
+
const type = rawType === "number" ? "number" : rawType === "integer" ? "integer" : rawType === "boolean" ? "boolean" : "string";
|
|
3586
|
+
fields.push({
|
|
3587
|
+
key,
|
|
3588
|
+
type,
|
|
3589
|
+
required: required.has(key),
|
|
3590
|
+
title,
|
|
3591
|
+
description,
|
|
3592
|
+
...type === "string" && required.has(key) && !isPositiveInteger(prop.minLength) ? { allowEmpty: true } : {},
|
|
3593
|
+
...withConstraints(prop)
|
|
3594
|
+
});
|
|
3595
|
+
}
|
|
3596
|
+
return fields;
|
|
3597
|
+
}
|
|
3598
|
+
function withConstraints(prop) {
|
|
3599
|
+
const constraints = {};
|
|
3600
|
+
for (const key of [
|
|
3601
|
+
"minLength",
|
|
3602
|
+
"maxLength",
|
|
3603
|
+
"minimum",
|
|
3604
|
+
"maximum",
|
|
3605
|
+
"minItems",
|
|
3606
|
+
"maxItems"
|
|
3607
|
+
]) {
|
|
3608
|
+
const value = prop[key];
|
|
3609
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
3610
|
+
constraints[key] = value;
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
if (typeof prop.pattern === "string" && prop.pattern !== "") {
|
|
3614
|
+
constraints.pattern = prop.pattern;
|
|
3615
|
+
}
|
|
3616
|
+
if (typeof prop.format === "string" && prop.format !== "") {
|
|
3617
|
+
constraints.format = prop.format;
|
|
3618
|
+
}
|
|
3619
|
+
return Object.keys(constraints).length > 0 ? { constraints } : {};
|
|
3620
|
+
}
|
|
3621
|
+
function isPositiveInteger(value) {
|
|
3622
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
3623
|
+
}
|
|
3624
|
+
function satisfiesStringFormat(value, format) {
|
|
3625
|
+
switch (format) {
|
|
3626
|
+
case "email": {
|
|
3627
|
+
const parts = value.split("@");
|
|
3628
|
+
if (parts.length !== 2) return false;
|
|
3629
|
+
const [local, domain] = parts;
|
|
3630
|
+
if (local.length === 0 || domain.length === 0) return false;
|
|
3631
|
+
if (/\s/.test(value)) return false;
|
|
3632
|
+
return domain.includes(".") && !domain.startsWith(".") && !domain.endsWith(".");
|
|
3633
|
+
}
|
|
3634
|
+
case "uri": {
|
|
3635
|
+
try {
|
|
3636
|
+
new URL(value);
|
|
3637
|
+
return true;
|
|
3638
|
+
} catch {
|
|
3639
|
+
return false;
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
case "date": {
|
|
3643
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
3644
|
+
if (!match) return false;
|
|
3645
|
+
const [, y, m, d] = match;
|
|
3646
|
+
const date = /* @__PURE__ */ new Date(`${y}-${m}-${d}T00:00:00Z`);
|
|
3647
|
+
return !Number.isNaN(date.getTime()) && date.getUTCFullYear() === Number(y) && date.getUTCMonth() + 1 === Number(m) && date.getUTCDate() === Number(d);
|
|
3648
|
+
}
|
|
3649
|
+
case "date-time": {
|
|
3650
|
+
if (!/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(\.\d+)?([Zz]|[+-]\d{2}:\d{2})$/.test(value)) {
|
|
3651
|
+
return false;
|
|
3652
|
+
}
|
|
3653
|
+
return !Number.isNaN(new Date(value).getTime());
|
|
3654
|
+
}
|
|
3655
|
+
default:
|
|
3656
|
+
return true;
|
|
3657
|
+
}
|
|
3658
|
+
}
|
|
3659
|
+
function isScreenedPattern(pattern) {
|
|
3660
|
+
if (pattern.length > 200) return false;
|
|
3661
|
+
if (/\\\d/.test(pattern)) return false;
|
|
3662
|
+
if (/\([^()]*[+*][^()]*\)\s*[+*{]/.test(pattern)) return false;
|
|
3663
|
+
if (/\)\s*[+*]\s*[+*]/.test(pattern)) return false;
|
|
3664
|
+
return true;
|
|
3665
|
+
}
|
|
3666
|
+
function assertSatisfiesConstraints(value, field) {
|
|
3667
|
+
const c = field.constraints;
|
|
3668
|
+
if (!c) return;
|
|
3669
|
+
const name = sanitizeTerminalText(field.title ?? field.key);
|
|
3670
|
+
if (typeof value === "string") {
|
|
3671
|
+
const length = Array.from(value).length;
|
|
3672
|
+
if (c.minLength !== void 0 && length < c.minLength) {
|
|
3673
|
+
throw new Error(`"${name}" must be at least ${c.minLength} character(s).`);
|
|
3674
|
+
}
|
|
3675
|
+
if (c.maxLength !== void 0 && length > c.maxLength) {
|
|
3676
|
+
throw new Error(`"${name}" must be at most ${c.maxLength} character(s).`);
|
|
3677
|
+
}
|
|
3678
|
+
if (c.format !== void 0 && !satisfiesStringFormat(value, c.format)) {
|
|
3679
|
+
throw new Error(
|
|
3680
|
+
`"${name}" must be a valid ${sanitizeTerminalText(c.format)}.`
|
|
3681
|
+
);
|
|
3682
|
+
}
|
|
3683
|
+
if (c.pattern !== void 0 && isScreenedPattern(c.pattern)) {
|
|
3684
|
+
let re;
|
|
3685
|
+
try {
|
|
3686
|
+
re = new RegExp(c.pattern);
|
|
3687
|
+
} catch {
|
|
3688
|
+
re = void 0;
|
|
3689
|
+
}
|
|
3690
|
+
if (re && !re.test(value)) {
|
|
3691
|
+
throw new Error(
|
|
3692
|
+
`"${name}" must match ${sanitizeTerminalText(c.pattern)}.`
|
|
3693
|
+
);
|
|
3694
|
+
}
|
|
3695
|
+
}
|
|
3696
|
+
return;
|
|
3697
|
+
}
|
|
3698
|
+
if (typeof value === "number") {
|
|
3699
|
+
if (c.minimum !== void 0 && value < c.minimum) {
|
|
3700
|
+
throw new Error(`"${name}" must be >= ${c.minimum}.`);
|
|
3701
|
+
}
|
|
3702
|
+
if (c.maximum !== void 0 && value > c.maximum) {
|
|
3703
|
+
throw new Error(`"${name}" must be <= ${c.maximum}.`);
|
|
3704
|
+
}
|
|
3705
|
+
return;
|
|
3706
|
+
}
|
|
3707
|
+
if (Array.isArray(value)) {
|
|
3708
|
+
if (c.minItems !== void 0 && value.length < c.minItems) {
|
|
3709
|
+
throw new Error(`"${name}" needs at least ${c.minItems} item(s).`);
|
|
3710
|
+
}
|
|
3711
|
+
if (c.maxItems !== void 0 && value.length > c.maxItems) {
|
|
3712
|
+
throw new Error(`"${name}" takes at most ${c.maxItems} item(s).`);
|
|
3713
|
+
}
|
|
3714
|
+
}
|
|
3715
|
+
}
|
|
3716
|
+
function extractEnum(node) {
|
|
3717
|
+
if (Array.isArray(node.enum) && node.enum.length > 0) {
|
|
3718
|
+
const values2 = node.enum.map((v) => String(v));
|
|
3719
|
+
const names2 = Array.isArray(node.enumNames) ? node.enumNames.map((v) => String(v)) : void 0;
|
|
3720
|
+
return names2 ? { values: values2, names: names2 } : { values: values2 };
|
|
3721
|
+
}
|
|
3722
|
+
const branches = Array.isArray(node.oneOf) ? node.oneOf : Array.isArray(node.anyOf) ? node.anyOf : void 0;
|
|
3723
|
+
if (!branches || branches.length === 0) return void 0;
|
|
3724
|
+
const values = [];
|
|
3725
|
+
const names = [];
|
|
3726
|
+
let anyName = false;
|
|
3727
|
+
for (const branch of branches) {
|
|
3728
|
+
if (!isRecord(branch)) return void 0;
|
|
3729
|
+
let value;
|
|
3730
|
+
if ("const" in branch) {
|
|
3731
|
+
value = branch.const;
|
|
3732
|
+
} else if (Array.isArray(branch.enum) && branch.enum.length === 1) {
|
|
3733
|
+
value = branch.enum[0];
|
|
3734
|
+
} else {
|
|
3735
|
+
return void 0;
|
|
3736
|
+
}
|
|
3737
|
+
values.push(String(value));
|
|
3738
|
+
const label = typeof branch.title === "string" ? branch.title : typeof branch.description === "string" ? branch.description : String(value);
|
|
3739
|
+
if (typeof branch.title === "string" || typeof branch.description === "string") {
|
|
3740
|
+
anyName = true;
|
|
3741
|
+
}
|
|
3742
|
+
names.push(label);
|
|
3743
|
+
}
|
|
3744
|
+
return anyName ? { values, names } : { values };
|
|
3745
|
+
}
|
|
3746
|
+
function coerceFieldValue(raw, field) {
|
|
3747
|
+
const coerced = coerceFieldValueRaw(raw, field);
|
|
3748
|
+
if ("value" in coerced) assertSatisfiesConstraints(coerced.value, field);
|
|
3749
|
+
return coerced;
|
|
3750
|
+
}
|
|
3751
|
+
function coerceFieldValueRaw(raw, field) {
|
|
3752
|
+
const trimmed = raw.trim();
|
|
3753
|
+
if (trimmed === "") {
|
|
3754
|
+
if (field.required) {
|
|
3755
|
+
if (field.allowEmpty && field.type === "string") return { value: "" };
|
|
3756
|
+
if (!(field.allowEmpty && field.type === "array")) {
|
|
3757
|
+
throw new Error(`"${sanitizeTerminalText(field.key)}" is required.`);
|
|
3758
|
+
}
|
|
3759
|
+
} else {
|
|
3760
|
+
return { skip: true };
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3763
|
+
switch (field.type) {
|
|
3764
|
+
case "string":
|
|
3765
|
+
return { value: raw };
|
|
3766
|
+
case "number": {
|
|
3767
|
+
const n = Number(trimmed);
|
|
3768
|
+
if (!Number.isFinite(n)) throw new Error(`"${trimmed}" is not a number.`);
|
|
3769
|
+
return { value: n };
|
|
3770
|
+
}
|
|
3771
|
+
case "integer": {
|
|
3772
|
+
const n = Number(trimmed);
|
|
3773
|
+
if (!Number.isInteger(n)) throw new Error(`"${trimmed}" is not an integer.`);
|
|
3774
|
+
return { value: n };
|
|
3775
|
+
}
|
|
3776
|
+
case "boolean": {
|
|
3777
|
+
const lowered = trimmed.toLowerCase();
|
|
3778
|
+
if (["y", "yes", "true", "1"].includes(lowered)) return { value: true };
|
|
3779
|
+
if (["n", "no", "false", "0"].includes(lowered)) return { value: false };
|
|
3780
|
+
throw new Error(`Enter yes/no for "${sanitizeTerminalText(field.key)}".`);
|
|
3781
|
+
}
|
|
3782
|
+
case "enum": {
|
|
3783
|
+
const values = field.enumValues ?? [];
|
|
3784
|
+
if (values.includes(trimmed)) return { value: trimmed };
|
|
3785
|
+
const idx = Number(trimmed);
|
|
3786
|
+
if (Number.isInteger(idx) && idx >= 1 && idx <= values.length) {
|
|
3787
|
+
return { value: values[idx - 1] };
|
|
3788
|
+
}
|
|
3789
|
+
throw new Error(
|
|
3790
|
+
`Choose one of: ${sanitizeTerminalText(values.join(", "))} (or its number).`
|
|
3791
|
+
);
|
|
3792
|
+
}
|
|
3793
|
+
case "array": {
|
|
3794
|
+
const parts = trimmed.split(",").map((p) => p.trim()).filter((p) => p !== "");
|
|
3795
|
+
if (parts.length === 0) {
|
|
3796
|
+
if (!field.required) return { skip: true };
|
|
3797
|
+
if (field.allowEmpty) return { value: [] };
|
|
3798
|
+
throw new Error(`"${sanitizeTerminalText(field.key)}" is required.`);
|
|
3799
|
+
}
|
|
3800
|
+
const values = field.enumValues;
|
|
3801
|
+
if (values && values.length > 0) {
|
|
3802
|
+
const selected = parts.map((part) => {
|
|
3803
|
+
if (values.includes(part)) return part;
|
|
3804
|
+
const idx = Number(part);
|
|
3805
|
+
if (Number.isInteger(idx) && idx >= 1 && idx <= values.length) {
|
|
3806
|
+
return values[idx - 1];
|
|
3807
|
+
}
|
|
3808
|
+
throw new Error(
|
|
3809
|
+
`Choose from: ${sanitizeTerminalText(values.join(", "))} (comma-separated values or numbers).`
|
|
3810
|
+
);
|
|
3811
|
+
});
|
|
3812
|
+
return { value: selected };
|
|
3813
|
+
}
|
|
3814
|
+
const itemType = field.itemType ?? "string";
|
|
3815
|
+
const coerced = parts.map((part) => {
|
|
3816
|
+
const one = coerceFieldValueRaw(part, {
|
|
3817
|
+
key: field.key,
|
|
3818
|
+
type: itemType,
|
|
3819
|
+
required: true
|
|
3820
|
+
});
|
|
3821
|
+
return one.value;
|
|
3822
|
+
});
|
|
3823
|
+
return { value: coerced };
|
|
3824
|
+
}
|
|
3825
|
+
}
|
|
3826
|
+
}
|
|
3827
|
+
function createStdinElicitationHandler(options = {}) {
|
|
3828
|
+
const collector = createStdinMrtrCollector(options);
|
|
3829
|
+
return async (params) => {
|
|
3830
|
+
const responses = await collector({
|
|
3831
|
+
state: {},
|
|
3832
|
+
inputRequests: {
|
|
3833
|
+
[INBOUND_ELICITATION_KEY]: { method: "elicitation/create", params }
|
|
3834
|
+
}
|
|
3835
|
+
});
|
|
3836
|
+
return responses[INBOUND_ELICITATION_KEY];
|
|
3837
|
+
};
|
|
3838
|
+
}
|
|
3839
|
+
var INBOUND_ELICITATION_KEY = "elicitation";
|
|
3840
|
+
function createStdinMrtrCollector(options = {}) {
|
|
3841
|
+
const write = options.write ?? ((text) => void process.stderr.write(text));
|
|
3842
|
+
const rawAttempts = options.maxFieldAttempts;
|
|
3843
|
+
const maxFieldAttempts = typeof rawAttempts === "number" && Number.isInteger(rawAttempts) && rawAttempts >= 1 ? rawAttempts : 3;
|
|
3844
|
+
return async ({ inputRequests, signal }) => {
|
|
3845
|
+
const activeSignal = signal ?? options.signal;
|
|
3846
|
+
throwIfAborted(activeSignal);
|
|
3847
|
+
const keys = Object.keys(inputRequests);
|
|
3848
|
+
const responses = /* @__PURE__ */ Object.create(null);
|
|
3849
|
+
if (options.nonInteractive) {
|
|
3850
|
+
write(
|
|
3851
|
+
`Non-interactive mode: declining ${keys.length} embedded input request(s). Re-run in a TTY (without --yes) to answer interactively.
|
|
3852
|
+
`
|
|
3853
|
+
);
|
|
3854
|
+
for (const key of keys) responses[key] = { action: "decline" };
|
|
3855
|
+
return responses;
|
|
3856
|
+
}
|
|
3857
|
+
const ownReader = options.reader === void 0;
|
|
3858
|
+
const reader = options.reader ?? createReadlineReader();
|
|
3859
|
+
try {
|
|
3860
|
+
let cancelled = false;
|
|
3861
|
+
for (const key of keys) {
|
|
3862
|
+
if (cancelled) {
|
|
3863
|
+
responses[key] = { action: "cancel" };
|
|
3864
|
+
continue;
|
|
3865
|
+
}
|
|
3866
|
+
responses[key] = await collectOne(
|
|
3867
|
+
key,
|
|
3868
|
+
inputRequests[key],
|
|
3869
|
+
{ reader, write, maxFieldAttempts, signal: activeSignal }
|
|
3870
|
+
);
|
|
3871
|
+
if (responses[key].action === "cancel") {
|
|
3872
|
+
cancelled = true;
|
|
3873
|
+
}
|
|
3874
|
+
}
|
|
3875
|
+
return responses;
|
|
3876
|
+
} finally {
|
|
3877
|
+
if (ownReader) closeReadlineReader(reader);
|
|
3878
|
+
}
|
|
3879
|
+
};
|
|
3880
|
+
}
|
|
3881
|
+
async function collectOne(key, request, ctx) {
|
|
3882
|
+
const params = request.params ?? {};
|
|
3883
|
+
const message = typeof params.message === "string" ? params.message : void 0;
|
|
3884
|
+
const mode = params.mode === "url" ? "url" : "form";
|
|
3885
|
+
ctx.write("\n");
|
|
3886
|
+
ctx.write(
|
|
3887
|
+
message ? `${sanitizeTerminalText(message)}
|
|
3888
|
+
` : `Input requested ("${sanitizeTerminalText(key)}"):
|
|
3889
|
+
`
|
|
3890
|
+
);
|
|
3891
|
+
if (mode === "url") {
|
|
3892
|
+
const url = typeof params.url === "string" ? params.url : "(no URL provided)";
|
|
3893
|
+
ctx.write(
|
|
3894
|
+
`Open this URL to continue, then confirm below:
|
|
3895
|
+
${sanitizeTerminalText(url)}
|
|
3896
|
+
`
|
|
3897
|
+
);
|
|
3898
|
+
const action2 = await askAction(ctx.reader, ctx.write, ctx.signal, {
|
|
3899
|
+
acceptLabel: "approve"
|
|
3900
|
+
});
|
|
3901
|
+
return { action: action2 };
|
|
3902
|
+
}
|
|
3903
|
+
const action = await askAction(ctx.reader, ctx.write, ctx.signal, {
|
|
3904
|
+
acceptLabel: "accept"
|
|
3905
|
+
});
|
|
3906
|
+
if (action !== "accept") {
|
|
3907
|
+
return { action };
|
|
3908
|
+
}
|
|
3909
|
+
const fields = parseElicitationFields(params.requestedSchema);
|
|
3910
|
+
const content = /* @__PURE__ */ Object.create(null);
|
|
3911
|
+
for (const field of fields) {
|
|
3912
|
+
const label = sanitizeTerminalText(field.title ?? field.key);
|
|
3913
|
+
if (field.description)
|
|
3914
|
+
ctx.write(` ${sanitizeTerminalText(field.description)}
|
|
3915
|
+
`);
|
|
3916
|
+
if (field.type === "enum" || field.type === "array") {
|
|
3917
|
+
const values = field.enumValues ?? [];
|
|
3918
|
+
values.forEach((value, index) => {
|
|
3919
|
+
const name = field.enumNames?.[index];
|
|
3920
|
+
ctx.write(
|
|
3921
|
+
` ${index + 1}) ${sanitizeTerminalText(value)}${name ? ` \u2014 ${sanitizeTerminalText(name)}` : ""}
|
|
3922
|
+
`
|
|
3923
|
+
);
|
|
3924
|
+
});
|
|
3925
|
+
if (field.type === "array") {
|
|
3926
|
+
ctx.write(` (comma-separated for multiple)
|
|
3927
|
+
`);
|
|
3928
|
+
}
|
|
3929
|
+
}
|
|
3930
|
+
const suffix = !field.required ? " (optional, blank to skip)" : field.allowEmpty ? field.type === "array" ? " (required, blank for none)" : " (required, blank for empty)" : "";
|
|
3931
|
+
let coerced;
|
|
3932
|
+
for (let attempt = 1; attempt <= ctx.maxFieldAttempts; attempt += 1) {
|
|
3933
|
+
throwIfAborted(ctx.signal);
|
|
3934
|
+
const raw = await ctx.reader.question(
|
|
3935
|
+
`${label} [${field.type}]${suffix}: `,
|
|
3936
|
+
{ signal: ctx.signal }
|
|
3937
|
+
);
|
|
3938
|
+
try {
|
|
3939
|
+
coerced = coerceFieldValue(raw, field);
|
|
3940
|
+
break;
|
|
3941
|
+
} catch (error) {
|
|
3942
|
+
ctx.write(` ${error.message}
|
|
3943
|
+
`);
|
|
3944
|
+
if (attempt === ctx.maxFieldAttempts) {
|
|
3945
|
+
ctx.write(
|
|
3946
|
+
` Giving up on "${sanitizeTerminalText(field.key)}" after ${ctx.maxFieldAttempts} attempts; declining this request.
|
|
3947
|
+
`
|
|
3948
|
+
);
|
|
3949
|
+
return { action: "decline" };
|
|
3950
|
+
}
|
|
3951
|
+
}
|
|
3952
|
+
}
|
|
3953
|
+
if (coerced && "value" in coerced) {
|
|
3954
|
+
content[field.key] = coerced.value;
|
|
3955
|
+
}
|
|
3956
|
+
}
|
|
3957
|
+
return { action: "accept", content };
|
|
3958
|
+
}
|
|
3959
|
+
async function askAction(reader, write, signal, opts) {
|
|
3960
|
+
for (; ; ) {
|
|
3961
|
+
throwIfAborted(signal);
|
|
3962
|
+
const raw = (await reader.question(
|
|
3963
|
+
`[a]${opts.acceptLabel.slice(1)} / [d]ecline / [c]ancel: `,
|
|
3964
|
+
{ signal }
|
|
3965
|
+
)).trim().toLowerCase();
|
|
3966
|
+
if (raw === "a" || raw === opts.acceptLabel) return "accept";
|
|
3967
|
+
if (raw === "d" || raw === "decline") return "decline";
|
|
3968
|
+
if (raw === "c" || raw === "cancel") return "cancel";
|
|
3969
|
+
write(` Please answer a, d, or c.
|
|
3970
|
+
`);
|
|
3971
|
+
}
|
|
3972
|
+
}
|
|
3973
|
+
function throwIfAborted(signal) {
|
|
3974
|
+
if (signal?.aborted) {
|
|
3975
|
+
throw new MrtrCollectAbortError();
|
|
3976
|
+
}
|
|
3977
|
+
}
|
|
3978
|
+
function isRecord(value) {
|
|
3979
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
3980
|
+
}
|
|
3981
|
+
function createReadlineReader() {
|
|
3982
|
+
const rl = readline.createInterface({
|
|
3983
|
+
input: process.stdin,
|
|
3984
|
+
// Prompts to stderr so stdout stays a clean machine-readable result.
|
|
3985
|
+
output: process.stderr
|
|
3986
|
+
});
|
|
3987
|
+
return {
|
|
3988
|
+
question: async (prompt, options) => {
|
|
3989
|
+
try {
|
|
3990
|
+
return await (options?.signal ? rl.question(prompt, { signal: options.signal }) : rl.question(prompt));
|
|
3991
|
+
} catch (error) {
|
|
3992
|
+
if (options?.signal?.aborted || error?.name === "AbortError") {
|
|
3993
|
+
throw new MrtrCollectAbortError();
|
|
3994
|
+
}
|
|
3995
|
+
throw error;
|
|
3996
|
+
}
|
|
3997
|
+
},
|
|
3998
|
+
close: () => rl.close()
|
|
3999
|
+
};
|
|
4000
|
+
}
|
|
4001
|
+
function closeReadlineReader(reader) {
|
|
4002
|
+
reader.close?.();
|
|
4003
|
+
}
|
|
3475
4004
|
|
|
3476
4005
|
// src/lib/ephemeral.ts
|
|
4006
|
+
function applyInteractiveElicitationCapability(config) {
|
|
4007
|
+
const exact = config.clientCapabilities;
|
|
4008
|
+
if (exact) {
|
|
4009
|
+
if (exact.elicitation == null) {
|
|
4010
|
+
throw usageError(
|
|
4011
|
+
'--interactive requires the advertised client capabilities to include `elicitation`, but --client-capabilities/--host pinned an exact set without it. Add `"elicitation": { "form": {}, "url": {} }` to the capabilities, or drop --interactive.'
|
|
4012
|
+
);
|
|
4013
|
+
}
|
|
4014
|
+
return config;
|
|
4015
|
+
}
|
|
4016
|
+
const capabilities = config.capabilities ?? {};
|
|
4017
|
+
return {
|
|
4018
|
+
...config,
|
|
4019
|
+
capabilities: {
|
|
4020
|
+
...capabilities,
|
|
4021
|
+
elicitation: {
|
|
4022
|
+
...INTERACTIVE_ELICITATION_CAPABILITY,
|
|
4023
|
+
...isRecord2(capabilities.elicitation) ? capabilities.elicitation : {}
|
|
4024
|
+
}
|
|
4025
|
+
}
|
|
4026
|
+
};
|
|
4027
|
+
}
|
|
4028
|
+
function isRecord2(value) {
|
|
4029
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
4030
|
+
}
|
|
3477
4031
|
async function withEphemeralManager(config, fn, options) {
|
|
3478
|
-
const
|
|
4032
|
+
const hostConfig = options?.host ? applyHostToConfig(config, options.host) : config;
|
|
4033
|
+
const resolvedConfig = options?.interactiveElicitation ? applyInteractiveElicitationCapability(hostConfig) : hostConfig;
|
|
3479
4034
|
return withEphemeralClient(resolvedConfig, fn, {
|
|
3480
4035
|
serverId: "__cli__",
|
|
3481
4036
|
clientName: "mcpjam",
|
|
3482
4037
|
timeout: options?.timeout ?? 3e4,
|
|
3483
4038
|
rpcLogger: options?.rpcLogger,
|
|
3484
|
-
retryPolicy: options?.retryPolicy
|
|
4039
|
+
retryPolicy: options?.retryPolicy,
|
|
4040
|
+
beforeConnect: options?.beforeConnect
|
|
3485
4041
|
});
|
|
3486
4042
|
}
|
|
3487
4043
|
|
|
@@ -3607,9 +4163,13 @@ async function runPlatformCommand(options, timeoutMs, execute) {
|
|
|
3607
4163
|
const controller = new AbortController();
|
|
3608
4164
|
const timeoutHandle = setTimeout(() => {
|
|
3609
4165
|
controller.abort(
|
|
3610
|
-
new PlatformApiError(
|
|
3611
|
-
|
|
3612
|
-
|
|
4166
|
+
new PlatformApiError(
|
|
4167
|
+
`Request timed out after ${timeoutMs}ms`,
|
|
4168
|
+
"TIMEOUT",
|
|
4169
|
+
{
|
|
4170
|
+
status: 0
|
|
4171
|
+
}
|
|
4172
|
+
)
|
|
3613
4173
|
);
|
|
3614
4174
|
}, timeoutMs);
|
|
3615
4175
|
timeoutHandle.unref?.();
|
|
@@ -3625,7 +4185,7 @@ async function runPlatformCommand(options, timeoutMs, execute) {
|
|
|
3625
4185
|
clearTimeout(timeoutHandle);
|
|
3626
4186
|
}
|
|
3627
4187
|
}
|
|
3628
|
-
function
|
|
4188
|
+
function loadBlueprintText(file) {
|
|
3629
4189
|
let text;
|
|
3630
4190
|
try {
|
|
3631
4191
|
text = file === "-" ? readFileSync(0, "utf8") : readFileSync(file, "utf8");
|
|
@@ -3645,12 +4205,12 @@ function validateInput(op, raw) {
|
|
|
3645
4205
|
}
|
|
3646
4206
|
return parsed.data;
|
|
3647
4207
|
}
|
|
3648
|
-
function
|
|
3649
|
-
const env = program.command("
|
|
3650
|
-
"List, build, and manage custom Computer
|
|
4208
|
+
function registerImagesCommands(program) {
|
|
4209
|
+
const env = program.command("images").description(
|
|
4210
|
+
"List, build, and manage custom Computer sandbox images (blueprints) in your hosted MCPJam projects"
|
|
3651
4211
|
);
|
|
3652
4212
|
addPlatformOptions(
|
|
3653
|
-
env.command("list").description("List the
|
|
4213
|
+
env.command("list").description("List the sandbox images in a project").option(
|
|
3654
4214
|
"--project <id-or-name>",
|
|
3655
4215
|
"Project name or ID (defaults to the most recently updated project)"
|
|
3656
4216
|
)
|
|
@@ -3659,7 +4219,7 @@ function registerEnvironmentsCommands(program) {
|
|
|
3659
4219
|
const result = await runPlatformCommand(
|
|
3660
4220
|
options,
|
|
3661
4221
|
globalOptions.timeout,
|
|
3662
|
-
({ client, signal }) =>
|
|
4222
|
+
({ client, signal }) => listImagesOperation.execute(
|
|
3663
4223
|
{ project: options.project },
|
|
3664
4224
|
{ client, signal }
|
|
3665
4225
|
)
|
|
@@ -3667,15 +4227,17 @@ function registerEnvironmentsCommands(program) {
|
|
|
3667
4227
|
writeResult(result, globalOptions.format);
|
|
3668
4228
|
});
|
|
3669
4229
|
addPlatformOptions(
|
|
3670
|
-
env.command("get").description(
|
|
4230
|
+
env.command("get").description(
|
|
4231
|
+
"Show one sandbox image's blueprint and latest build status"
|
|
4232
|
+
).requiredOption("--image <id-or-name>", "Sandbox image name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
3671
4233
|
).action(
|
|
3672
4234
|
async (options, command) => {
|
|
3673
4235
|
const globalOptions = getGlobalOptions(command);
|
|
3674
4236
|
const result = await runPlatformCommand(
|
|
3675
4237
|
options,
|
|
3676
4238
|
globalOptions.timeout,
|
|
3677
|
-
({ client, signal }) =>
|
|
3678
|
-
{ project: options.project,
|
|
4239
|
+
({ client, signal }) => getImageOperation.execute(
|
|
4240
|
+
{ project: options.project, image: options.image },
|
|
3679
4241
|
{ client, signal }
|
|
3680
4242
|
)
|
|
3681
4243
|
);
|
|
@@ -3683,57 +4245,84 @@ function registerEnvironmentsCommands(program) {
|
|
|
3683
4245
|
}
|
|
3684
4246
|
);
|
|
3685
4247
|
addPlatformOptions(
|
|
3686
|
-
env.command("create").description(
|
|
4248
|
+
env.command("create").description(
|
|
4249
|
+
"Create a sandbox image from a blueprint YAML file (--file, or - for stdin)"
|
|
4250
|
+
).requiredOption("--name <name>", "Display name for the new sandbox image").requiredOption(
|
|
3687
4251
|
"--file <path>",
|
|
3688
|
-
"
|
|
4252
|
+
"Blueprint YAML path, or - to read it from stdin"
|
|
3689
4253
|
).option("--project <id-or-name>", "Project name or ID")
|
|
3690
4254
|
).action(
|
|
3691
4255
|
async (options, command) => {
|
|
3692
4256
|
const globalOptions = getGlobalOptions(command);
|
|
3693
|
-
const
|
|
3694
|
-
const input = validateInput(
|
|
4257
|
+
const blueprint = loadBlueprintText(options.file);
|
|
4258
|
+
const input = validateInput(createImageOperation, {
|
|
3695
4259
|
project: options.project,
|
|
3696
4260
|
name: options.name,
|
|
3697
|
-
|
|
4261
|
+
blueprint
|
|
3698
4262
|
});
|
|
3699
4263
|
const result = await runPlatformCommand(
|
|
3700
4264
|
options,
|
|
3701
4265
|
globalOptions.timeout,
|
|
3702
|
-
({ client, signal }) =>
|
|
4266
|
+
({ client, signal }) => createImageOperation.execute(input, { client, signal })
|
|
3703
4267
|
);
|
|
3704
4268
|
writeResult(result, globalOptions.format);
|
|
3705
4269
|
}
|
|
3706
4270
|
);
|
|
3707
4271
|
addPlatformOptions(
|
|
3708
|
-
env.command("
|
|
4272
|
+
env.command("validate").description(
|
|
4273
|
+
"Lint a blueprint YAML file without saving it (--file, or - for stdin)"
|
|
4274
|
+
).requiredOption(
|
|
4275
|
+
"--file <path>",
|
|
4276
|
+
"Blueprint YAML path, or - to read it from stdin"
|
|
4277
|
+
).option("--project <id-or-name>", "Project name or ID")
|
|
3709
4278
|
).action(
|
|
3710
4279
|
async (options, command) => {
|
|
3711
4280
|
const globalOptions = getGlobalOptions(command);
|
|
3712
|
-
const
|
|
3713
|
-
const input = validateInput(
|
|
4281
|
+
const blueprint = loadBlueprintText(options.file);
|
|
4282
|
+
const input = validateInput(validateImageBlueprintOperation, {
|
|
3714
4283
|
project: options.project,
|
|
3715
|
-
|
|
4284
|
+
blueprint
|
|
4285
|
+
});
|
|
4286
|
+
const result = await runPlatformCommand(
|
|
4287
|
+
options,
|
|
4288
|
+
globalOptions.timeout,
|
|
4289
|
+
({ client, signal }) => validateImageBlueprintOperation.execute(input, { client, signal })
|
|
4290
|
+
);
|
|
4291
|
+
writeResult(result, globalOptions.format);
|
|
4292
|
+
}
|
|
4293
|
+
);
|
|
4294
|
+
addPlatformOptions(
|
|
4295
|
+
env.command("edit").description("Edit a sandbox image's name and/or blueprint").requiredOption("--image <id-or-name>", "Sandbox image name or ID").option("--project <id-or-name>", "Project name or ID").option("--name <name>", "New display name").option("--file <path>", "Replacement blueprint YAML path (or - for stdin)")
|
|
4296
|
+
).action(
|
|
4297
|
+
async (options, command) => {
|
|
4298
|
+
const globalOptions = getGlobalOptions(command);
|
|
4299
|
+
const blueprint = options.file !== void 0 ? loadBlueprintText(options.file) : void 0;
|
|
4300
|
+
const input = validateInput(updateImageOperation, {
|
|
4301
|
+
project: options.project,
|
|
4302
|
+
image: options.image,
|
|
3716
4303
|
...options.name !== void 0 ? { name: options.name } : {},
|
|
3717
|
-
...
|
|
4304
|
+
...blueprint !== void 0 ? { blueprint } : {}
|
|
3718
4305
|
});
|
|
3719
4306
|
const result = await runPlatformCommand(
|
|
3720
4307
|
options,
|
|
3721
4308
|
globalOptions.timeout,
|
|
3722
|
-
({ client, signal }) =>
|
|
4309
|
+
({ client, signal }) => updateImageOperation.execute(input, { client, signal })
|
|
3723
4310
|
);
|
|
3724
4311
|
writeResult(result, globalOptions.format);
|
|
3725
4312
|
}
|
|
3726
4313
|
);
|
|
3727
4314
|
addPlatformOptions(
|
|
3728
|
-
env.command("build").description(
|
|
4315
|
+
env.command("build").description(
|
|
4316
|
+
"Build the sandbox image (async \u2014 poll `images logs` for status)"
|
|
4317
|
+
).requiredOption("--image <id-or-name>", "Sandbox image name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
3729
4318
|
).action(
|
|
3730
4319
|
async (options, command) => {
|
|
3731
4320
|
const globalOptions = getGlobalOptions(command);
|
|
3732
4321
|
const result = await runPlatformCommand(
|
|
3733
4322
|
options,
|
|
3734
4323
|
globalOptions.timeout,
|
|
3735
|
-
({ client, signal }) =>
|
|
3736
|
-
{ project: options.project,
|
|
4324
|
+
({ client, signal }) => buildImageOperation.execute(
|
|
4325
|
+
{ project: options.project, image: options.image },
|
|
3737
4326
|
{ client, signal }
|
|
3738
4327
|
)
|
|
3739
4328
|
);
|
|
@@ -3741,15 +4330,17 @@ function registerEnvironmentsCommands(program) {
|
|
|
3741
4330
|
}
|
|
3742
4331
|
);
|
|
3743
4332
|
addPlatformOptions(
|
|
3744
|
-
env.command("logs").description(
|
|
4333
|
+
env.command("logs").description(
|
|
4334
|
+
"Show a sandbox image's builds (newest first) with their log preview"
|
|
4335
|
+
).requiredOption("--image <id-or-name>", "Sandbox image name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
3745
4336
|
).action(
|
|
3746
4337
|
async (options, command) => {
|
|
3747
4338
|
const globalOptions = getGlobalOptions(command);
|
|
3748
4339
|
const result = await runPlatformCommand(
|
|
3749
4340
|
options,
|
|
3750
4341
|
globalOptions.timeout,
|
|
3751
|
-
({ client, signal }) =>
|
|
3752
|
-
{ project: options.project,
|
|
4342
|
+
({ client, signal }) => listImageBuildsOperation.execute(
|
|
4343
|
+
{ project: options.project, image: options.image },
|
|
3753
4344
|
{ client, signal }
|
|
3754
4345
|
)
|
|
3755
4346
|
);
|
|
@@ -3758,16 +4349,16 @@ function registerEnvironmentsCommands(program) {
|
|
|
3758
4349
|
);
|
|
3759
4350
|
addPlatformOptions(
|
|
3760
4351
|
env.command("use").description(
|
|
3761
|
-
"Boot your computer from this
|
|
3762
|
-
).requiredOption("--
|
|
4352
|
+
"Boot your computer from this sandbox image (rebuilds it \u2014 installed files are wiped)"
|
|
4353
|
+
).requiredOption("--image <id-or-name>", "Sandbox image name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
3763
4354
|
).action(
|
|
3764
4355
|
async (options, command) => {
|
|
3765
4356
|
const globalOptions = getGlobalOptions(command);
|
|
3766
4357
|
const result = await runPlatformCommand(
|
|
3767
4358
|
options,
|
|
3768
4359
|
globalOptions.timeout,
|
|
3769
|
-
({ client, signal }) =>
|
|
3770
|
-
{ project: options.project,
|
|
4360
|
+
({ client, signal }) => useImageOperation.execute(
|
|
4361
|
+
{ project: options.project, image: options.image },
|
|
3771
4362
|
{ client, signal }
|
|
3772
4363
|
)
|
|
3773
4364
|
);
|
|
@@ -3775,7 +4366,9 @@ function registerEnvironmentsCommands(program) {
|
|
|
3775
4366
|
}
|
|
3776
4367
|
);
|
|
3777
4368
|
addPlatformOptions(
|
|
3778
|
-
env.command("reset").description(
|
|
4369
|
+
env.command("reset").description(
|
|
4370
|
+
"Reset your computer to its current image (wipes mutable state)"
|
|
4371
|
+
).option("--project <id-or-name>", "Project name or ID")
|
|
3779
4372
|
).action(async (options, command) => {
|
|
3780
4373
|
const globalOptions = getGlobalOptions(command);
|
|
3781
4374
|
const result = await runPlatformCommand(
|
|
@@ -3789,15 +4382,17 @@ function registerEnvironmentsCommands(program) {
|
|
|
3789
4382
|
writeResult(result, globalOptions.format);
|
|
3790
4383
|
});
|
|
3791
4384
|
addPlatformOptions(
|
|
3792
|
-
env.command("promote").description(
|
|
4385
|
+
env.command("promote").description(
|
|
4386
|
+
"Share a personal-draft sandbox image with the whole project (admin only)"
|
|
4387
|
+
).requiredOption("--image <id-or-name>", "Sandbox image name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
3793
4388
|
).action(
|
|
3794
4389
|
async (options, command) => {
|
|
3795
4390
|
const globalOptions = getGlobalOptions(command);
|
|
3796
4391
|
const result = await runPlatformCommand(
|
|
3797
4392
|
options,
|
|
3798
4393
|
globalOptions.timeout,
|
|
3799
|
-
({ client, signal }) =>
|
|
3800
|
-
{ project: options.project,
|
|
4394
|
+
({ client, signal }) => promoteImageOperation.execute(
|
|
4395
|
+
{ project: options.project, image: options.image },
|
|
3801
4396
|
{ client, signal }
|
|
3802
4397
|
)
|
|
3803
4398
|
);
|
|
@@ -3805,15 +4400,15 @@ function registerEnvironmentsCommands(program) {
|
|
|
3805
4400
|
}
|
|
3806
4401
|
);
|
|
3807
4402
|
addPlatformOptions(
|
|
3808
|
-
env.command("delete").description("Permanently delete
|
|
4403
|
+
env.command("delete").description("Permanently delete a sandbox image from a project").requiredOption("--image <id-or-name>", "Sandbox image name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
3809
4404
|
).action(
|
|
3810
4405
|
async (options, command) => {
|
|
3811
4406
|
const globalOptions = getGlobalOptions(command);
|
|
3812
4407
|
const result = await runPlatformCommand(
|
|
3813
4408
|
options,
|
|
3814
4409
|
globalOptions.timeout,
|
|
3815
|
-
({ client, signal }) =>
|
|
3816
|
-
{ project: options.project,
|
|
4410
|
+
({ client, signal }) => deleteImageOperation.execute(
|
|
4411
|
+
{ project: options.project, image: options.image },
|
|
3817
4412
|
{ client, signal }
|
|
3818
4413
|
)
|
|
3819
4414
|
);
|
|
@@ -3821,26 +4416,291 @@ function registerEnvironmentsCommands(program) {
|
|
|
3821
4416
|
}
|
|
3822
4417
|
);
|
|
3823
4418
|
}
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
4419
|
+
function addPlatformOptions2(command) {
|
|
4420
|
+
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
4421
|
+
"--api-url <url>",
|
|
4422
|
+
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
4423
|
+
);
|
|
3828
4424
|
}
|
|
3829
|
-
function
|
|
3830
|
-
|
|
4425
|
+
async function runPlatformCommand2(options, timeoutMs, execute) {
|
|
4426
|
+
const controller = new AbortController();
|
|
4427
|
+
const timeoutHandle = setTimeout(() => {
|
|
4428
|
+
controller.abort(
|
|
4429
|
+
new PlatformApiError(
|
|
4430
|
+
`Request timed out after ${timeoutMs}ms`,
|
|
4431
|
+
"TIMEOUT",
|
|
4432
|
+
{
|
|
4433
|
+
status: 0
|
|
4434
|
+
}
|
|
4435
|
+
)
|
|
4436
|
+
);
|
|
4437
|
+
}, timeoutMs);
|
|
4438
|
+
timeoutHandle.unref?.();
|
|
4439
|
+
try {
|
|
4440
|
+
const { client } = buildPlatformClient({ ...options, timeoutMs });
|
|
4441
|
+
return await execute({ client, signal: controller.signal });
|
|
4442
|
+
} catch (error) {
|
|
4443
|
+
if (controller.signal.aborted && controller.signal.reason instanceof PlatformApiError) {
|
|
4444
|
+
throw toCliError(controller.signal.reason);
|
|
4445
|
+
}
|
|
4446
|
+
throw toCliError(error);
|
|
4447
|
+
} finally {
|
|
4448
|
+
clearTimeout(timeoutHandle);
|
|
4449
|
+
}
|
|
3831
4450
|
}
|
|
3832
|
-
function
|
|
3833
|
-
const
|
|
3834
|
-
if (!
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
4451
|
+
function validateInput2(op, raw) {
|
|
4452
|
+
const parsed = op.inputSchema.safeParse(raw);
|
|
4453
|
+
if (!parsed.success) {
|
|
4454
|
+
const detail = parsed.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
|
|
4455
|
+
throw usageError(`Invalid input: ${detail}`);
|
|
4456
|
+
}
|
|
4457
|
+
return parsed.data;
|
|
4458
|
+
}
|
|
4459
|
+
function loadJsonObject(options) {
|
|
4460
|
+
if (options.file !== void 0 && options.json !== void 0) {
|
|
4461
|
+
throw usageError("Provide either --file or --json, not both.");
|
|
4462
|
+
}
|
|
4463
|
+
let base;
|
|
4464
|
+
if (options.file !== void 0) {
|
|
4465
|
+
let text;
|
|
4466
|
+
try {
|
|
4467
|
+
text = options.file === "-" ? readFileSync(0, "utf8") : readFileSync(options.file, "utf8");
|
|
4468
|
+
} catch (error) {
|
|
4469
|
+
throw usageError(`Failed to read --file "${options.file}".`, {
|
|
4470
|
+
source: error instanceof Error ? error.message : String(error)
|
|
4471
|
+
});
|
|
4472
|
+
}
|
|
4473
|
+
if (text.trim() === "") throw usageError("--file input is empty.");
|
|
4474
|
+
try {
|
|
4475
|
+
base = JSON.parse(text);
|
|
4476
|
+
} catch (error) {
|
|
4477
|
+
throw usageError("--file must contain valid JSON.", {
|
|
4478
|
+
source: error instanceof Error ? error.message : String(error)
|
|
4479
|
+
});
|
|
4480
|
+
}
|
|
4481
|
+
} else if (options.json !== void 0) {
|
|
4482
|
+
base = new JsonInputContext().parseJsonInputRecord(options.json, "--json");
|
|
4483
|
+
} else {
|
|
4484
|
+
return void 0;
|
|
4485
|
+
}
|
|
4486
|
+
if (typeof base !== "object" || base === null || Array.isArray(base)) {
|
|
4487
|
+
throw usageError("Environment input must be a JSON object.");
|
|
4488
|
+
}
|
|
4489
|
+
return base;
|
|
4490
|
+
}
|
|
4491
|
+
function parseRevision(raw) {
|
|
4492
|
+
const value = Number(raw);
|
|
4493
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
4494
|
+
throw usageError(
|
|
4495
|
+
"--expected-revision must be a non-negative integer (read it from `mcpjam environments get`)."
|
|
4496
|
+
);
|
|
4497
|
+
}
|
|
4498
|
+
return value;
|
|
4499
|
+
}
|
|
4500
|
+
function registerEnvironmentsCommands(program) {
|
|
4501
|
+
const environments = program.command("environments").description(
|
|
4502
|
+
"List, create, and manage the project environments (host + servers + pinned skills/plugins) in your hosted MCPJam projects"
|
|
4503
|
+
);
|
|
4504
|
+
addPlatformOptions2(
|
|
4505
|
+
environments.command("list").description("List the project environments in a project").option(
|
|
4506
|
+
"--project <id-or-name>",
|
|
4507
|
+
"Project name or ID (defaults to the most recently updated project)"
|
|
4508
|
+
).option(
|
|
4509
|
+
"--include-archived",
|
|
4510
|
+
"Include archived environments (needed to find one to restore)"
|
|
4511
|
+
)
|
|
4512
|
+
).action(
|
|
4513
|
+
async (options, command) => {
|
|
4514
|
+
const globalOptions = getGlobalOptions(command);
|
|
4515
|
+
const result = await runPlatformCommand2(
|
|
4516
|
+
options,
|
|
4517
|
+
globalOptions.timeout,
|
|
4518
|
+
({ client, signal }) => listEnvironmentsOperation.execute(
|
|
4519
|
+
{
|
|
4520
|
+
project: options.project,
|
|
4521
|
+
...options.includeArchived ? { includeArchived: true } : {}
|
|
4522
|
+
},
|
|
4523
|
+
{ client, signal }
|
|
4524
|
+
)
|
|
4525
|
+
);
|
|
4526
|
+
writeResult(result, globalOptions.format);
|
|
4527
|
+
}
|
|
4528
|
+
);
|
|
4529
|
+
addPlatformOptions2(
|
|
4530
|
+
environments.command("get").description(
|
|
4531
|
+
"Show one environment's settings and its current revision (pass that revision to update/archive/restore)"
|
|
4532
|
+
).requiredOption("--environment <id-or-name>", "Environment name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
4533
|
+
).action(
|
|
4534
|
+
async (options, command) => {
|
|
4535
|
+
const globalOptions = getGlobalOptions(command);
|
|
4536
|
+
const result = await runPlatformCommand2(
|
|
4537
|
+
options,
|
|
4538
|
+
globalOptions.timeout,
|
|
4539
|
+
({ client, signal }) => getEnvironmentOperation.execute(
|
|
4540
|
+
{ project: options.project, environment: options.environment },
|
|
4541
|
+
{ client, signal }
|
|
4542
|
+
)
|
|
4543
|
+
);
|
|
4544
|
+
writeResult(result, globalOptions.format);
|
|
4545
|
+
}
|
|
4546
|
+
);
|
|
4547
|
+
addPlatformOptions2(
|
|
4548
|
+
environments.command("resolve").description(
|
|
4549
|
+
"Preview what an environment resolves to right now: host config, closed server set, and pinned plugin versions"
|
|
4550
|
+
).requiredOption("--environment <id-or-name>", "Environment name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
4551
|
+
).action(
|
|
4552
|
+
async (options, command) => {
|
|
4553
|
+
const globalOptions = getGlobalOptions(command);
|
|
4554
|
+
const result = await runPlatformCommand2(
|
|
4555
|
+
options,
|
|
4556
|
+
globalOptions.timeout,
|
|
4557
|
+
({ client, signal }) => resolveEnvironmentOperation.execute(
|
|
4558
|
+
{ project: options.project, environment: options.environment },
|
|
4559
|
+
{ client, signal }
|
|
4560
|
+
)
|
|
4561
|
+
);
|
|
4562
|
+
writeResult(result, globalOptions.format);
|
|
4563
|
+
}
|
|
4564
|
+
);
|
|
4565
|
+
addPlatformOptions2(
|
|
4566
|
+
environments.command("create").description(
|
|
4567
|
+
"Create a project environment (requires project admin). Body fields may be supplied via --file/--json"
|
|
4568
|
+
).option("--project <id-or-name>", "Project name or ID").option("--name <name>", "Display name for the new environment").option("--host-id <id>", "ID of the host this environment runs against").option("--description <text>", "Optional description").option(
|
|
4569
|
+
"--sandbox-image <id>",
|
|
4570
|
+
"Project-shared sandbox image (see `mcpjam images`) to pin: eval runs boot a fresh sandbox from it"
|
|
4571
|
+
).option(
|
|
4572
|
+
"--file <path>",
|
|
4573
|
+
"Environment JSON file with any of name/hostId/description/serverAttachmentId/skillSelection/pluginVersionIds/sandboxImageId (or - for stdin)"
|
|
4574
|
+
).option("--json <json>", "Inline environment JSON (or @file, or -)")
|
|
4575
|
+
).action(
|
|
4576
|
+
async (options, command) => {
|
|
4577
|
+
const globalOptions = getGlobalOptions(command);
|
|
4578
|
+
const body = loadJsonObject(options) ?? {};
|
|
4579
|
+
const input = validateInput2(createEnvironmentOperation, {
|
|
4580
|
+
...body,
|
|
4581
|
+
...options.project !== void 0 ? { project: options.project } : {},
|
|
4582
|
+
...options.name !== void 0 ? { name: options.name } : {},
|
|
4583
|
+
...options.hostId !== void 0 ? { hostId: options.hostId } : {},
|
|
4584
|
+
...options.description !== void 0 ? { description: options.description } : {},
|
|
4585
|
+
...options.sandboxImage !== void 0 ? { sandboxImageId: options.sandboxImage } : {}
|
|
4586
|
+
});
|
|
4587
|
+
const result = await runPlatformCommand2(
|
|
4588
|
+
options,
|
|
4589
|
+
globalOptions.timeout,
|
|
4590
|
+
({ client, signal }) => createEnvironmentOperation.execute(input, { client, signal })
|
|
4591
|
+
);
|
|
4592
|
+
writeResult(result, globalOptions.format);
|
|
4593
|
+
}
|
|
4594
|
+
);
|
|
4595
|
+
addPlatformOptions2(
|
|
4596
|
+
environments.command("update").description(
|
|
4597
|
+
"Edit an environment. Only the fields you pass change; use --file/--json with a null value to clear serverAttachmentId, skillSelection, pluginVersionIds, or sandboxImageId"
|
|
4598
|
+
).requiredOption("--environment <id-or-name>", "Environment name or ID").requiredOption(
|
|
4599
|
+
"--expected-revision <n>",
|
|
4600
|
+
"The revision you last read (from `environments get`); a stale value is rejected instead of overwriting a concurrent edit"
|
|
4601
|
+
).option("--project <id-or-name>", "Project name or ID").option("--name <name>", "New display name").option("--host-id <id>", "New host for this environment").option(
|
|
4602
|
+
"--description <text>",
|
|
4603
|
+
"New description (empty string clears it)"
|
|
4604
|
+
).option(
|
|
4605
|
+
"--sandbox-image <id>",
|
|
4606
|
+
`New sandbox-image pin (clear via --json '{"sandboxImageId": null}')`
|
|
4607
|
+
).option(
|
|
4608
|
+
"--file <path>",
|
|
4609
|
+
"Environment JSON file with the fields to change (or - for stdin)"
|
|
4610
|
+
).option("--json <json>", "Inline environment JSON (or @file, or -)")
|
|
4611
|
+
).action(
|
|
4612
|
+
async (options, command) => {
|
|
4613
|
+
const globalOptions = getGlobalOptions(command);
|
|
4614
|
+
const body = loadJsonObject(options) ?? {};
|
|
4615
|
+
const input = validateInput2(updateEnvironmentOperation, {
|
|
4616
|
+
...body,
|
|
4617
|
+
...options.project !== void 0 ? { project: options.project } : {},
|
|
4618
|
+
environment: options.environment,
|
|
4619
|
+
expectedRevision: parseRevision(options.expectedRevision),
|
|
4620
|
+
...options.name !== void 0 ? { name: options.name } : {},
|
|
4621
|
+
...options.hostId !== void 0 ? { hostId: options.hostId } : {},
|
|
4622
|
+
...options.description !== void 0 ? { description: options.description } : {},
|
|
4623
|
+
...options.sandboxImage !== void 0 ? { sandboxImageId: options.sandboxImage } : {}
|
|
4624
|
+
});
|
|
4625
|
+
const result = await runPlatformCommand2(
|
|
4626
|
+
options,
|
|
4627
|
+
globalOptions.timeout,
|
|
4628
|
+
({ client, signal }) => updateEnvironmentOperation.execute(input, { client, signal })
|
|
4629
|
+
);
|
|
4630
|
+
writeResult(result, globalOptions.format);
|
|
4631
|
+
}
|
|
4632
|
+
);
|
|
4633
|
+
addPlatformOptions2(
|
|
4634
|
+
environments.command("archive").description(
|
|
4635
|
+
"Archive an environment (reversible; frees its name for a new one)"
|
|
4636
|
+
).requiredOption("--environment <id-or-name>", "Environment name or ID").requiredOption(
|
|
4637
|
+
"--expected-revision <n>",
|
|
4638
|
+
"The revision you last read (from `environments get`)"
|
|
4639
|
+
).option("--project <id-or-name>", "Project name or ID")
|
|
4640
|
+
).action(
|
|
4641
|
+
async (options, command) => {
|
|
4642
|
+
const globalOptions = getGlobalOptions(command);
|
|
4643
|
+
const result = await runPlatformCommand2(
|
|
4644
|
+
options,
|
|
4645
|
+
globalOptions.timeout,
|
|
4646
|
+
({ client, signal }) => archiveEnvironmentOperation.execute(
|
|
4647
|
+
{
|
|
4648
|
+
project: options.project,
|
|
4649
|
+
environment: options.environment,
|
|
4650
|
+
expectedRevision: parseRevision(options.expectedRevision)
|
|
4651
|
+
},
|
|
4652
|
+
{ client, signal }
|
|
4653
|
+
)
|
|
4654
|
+
);
|
|
4655
|
+
writeResult(result, globalOptions.format);
|
|
4656
|
+
}
|
|
4657
|
+
);
|
|
4658
|
+
addPlatformOptions2(
|
|
4659
|
+
environments.command("restore").description(
|
|
4660
|
+
"Restore an archived environment. Plugin pins whose version no longer exists are dropped \u2014 check the returned pluginVersionIds"
|
|
4661
|
+
).requiredOption("--environment <id-or-name>", "Environment name or ID").requiredOption(
|
|
4662
|
+
"--expected-revision <n>",
|
|
4663
|
+
"The revision you last read (from `environments get --include-archived` via list)"
|
|
4664
|
+
).option("--project <id-or-name>", "Project name or ID")
|
|
4665
|
+
).action(
|
|
4666
|
+
async (options, command) => {
|
|
4667
|
+
const globalOptions = getGlobalOptions(command);
|
|
4668
|
+
const result = await runPlatformCommand2(
|
|
4669
|
+
options,
|
|
4670
|
+
globalOptions.timeout,
|
|
4671
|
+
({ client, signal }) => restoreEnvironmentOperation.execute(
|
|
4672
|
+
{
|
|
4673
|
+
project: options.project,
|
|
4674
|
+
environment: options.environment,
|
|
4675
|
+
expectedRevision: parseRevision(options.expectedRevision)
|
|
4676
|
+
},
|
|
4677
|
+
{ client, signal }
|
|
4678
|
+
)
|
|
4679
|
+
);
|
|
4680
|
+
writeResult(result, globalOptions.format);
|
|
4681
|
+
}
|
|
4682
|
+
);
|
|
4683
|
+
}
|
|
4684
|
+
|
|
4685
|
+
// src/lib/eval-screenshots.ts
|
|
4686
|
+
function asRecord(value) {
|
|
4687
|
+
return typeof value === "object" && value !== null ? value : null;
|
|
4688
|
+
}
|
|
4689
|
+
function asString(value) {
|
|
4690
|
+
return typeof value === "string" ? value : void 0;
|
|
4691
|
+
}
|
|
4692
|
+
function extractRenderedScreenshots(result) {
|
|
4693
|
+
const root = asRecord(result);
|
|
4694
|
+
if (!root) return [];
|
|
4695
|
+
const trace = asRecord(root.trace) ?? root;
|
|
4696
|
+
const screenshots = [];
|
|
4697
|
+
const observations = trace.widgetRenderObservations;
|
|
4698
|
+
if (Array.isArray(observations)) {
|
|
4699
|
+
for (const entry of observations) {
|
|
4700
|
+
const obs = asRecord(entry);
|
|
4701
|
+
if (!obs) continue;
|
|
4702
|
+
const status = asString(obs.status);
|
|
4703
|
+
const screenshotUrl = asString(obs.screenshotUrl);
|
|
3844
4704
|
if (status !== "rendered" || !screenshotUrl) continue;
|
|
3845
4705
|
screenshots.push({
|
|
3846
4706
|
status,
|
|
@@ -3932,13 +4792,13 @@ function encodeInlineImage(data, protocol) {
|
|
|
3932
4792
|
}
|
|
3933
4793
|
|
|
3934
4794
|
// src/commands/eval.ts
|
|
3935
|
-
function
|
|
4795
|
+
function addPlatformOptions3(command) {
|
|
3936
4796
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
3937
4797
|
"--api-url <url>",
|
|
3938
4798
|
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
3939
4799
|
);
|
|
3940
4800
|
}
|
|
3941
|
-
async function
|
|
4801
|
+
async function runPlatformCommand3(options, timeoutMs, execute) {
|
|
3942
4802
|
const controller = new AbortController();
|
|
3943
4803
|
const timeoutHandle = setTimeout(() => {
|
|
3944
4804
|
controller.abort(
|
|
@@ -4048,7 +4908,7 @@ function validateOpInput(op, raw) {
|
|
|
4048
4908
|
}
|
|
4049
4909
|
async function executeOp(op, input, options, command) {
|
|
4050
4910
|
const globalOptions = getGlobalOptions(command);
|
|
4051
|
-
const result = await
|
|
4911
|
+
const result = await runPlatformCommand3(
|
|
4052
4912
|
options,
|
|
4053
4913
|
globalOptions.timeout,
|
|
4054
4914
|
({ client, signal }) => op.execute(input, { client, signal })
|
|
@@ -4148,7 +5008,7 @@ function resolveScreenshotPath(out, shot, index, total) {
|
|
|
4148
5008
|
}
|
|
4149
5009
|
function registerEvalCommands(program) {
|
|
4150
5010
|
const evals = program.command("eval").description("Author and run eval suites in your hosted MCPJam projects");
|
|
4151
|
-
|
|
5011
|
+
addPlatformOptions3(
|
|
4152
5012
|
evals.command("create").description(
|
|
4153
5013
|
"Create a runnable eval suite from authored test cases (does not run it)"
|
|
4154
5014
|
).option(
|
|
@@ -4173,21 +5033,21 @@ function registerEvalCommands(program) {
|
|
|
4173
5033
|
).action(async (options, command) => {
|
|
4174
5034
|
const globalOptions = getGlobalOptions(command);
|
|
4175
5035
|
const input = loadSuiteDefinition(options);
|
|
4176
|
-
const result = await
|
|
5036
|
+
const result = await runPlatformCommand3(
|
|
4177
5037
|
options,
|
|
4178
5038
|
globalOptions.timeout,
|
|
4179
5039
|
({ client, signal }) => createEvalSuiteOperation.execute(input, { client, signal })
|
|
4180
5040
|
);
|
|
4181
5041
|
writeResult(result, globalOptions.format);
|
|
4182
5042
|
});
|
|
4183
|
-
|
|
5043
|
+
addPlatformOptions3(
|
|
4184
5044
|
evals.command("list").description("List the eval suites saved in a project").option(
|
|
4185
5045
|
"--project <id-or-name>",
|
|
4186
5046
|
"Project name or ID (defaults to the most recently updated project)"
|
|
4187
5047
|
)
|
|
4188
5048
|
).action(async (options, command) => {
|
|
4189
5049
|
const globalOptions = getGlobalOptions(command);
|
|
4190
|
-
const result = await
|
|
5050
|
+
const result = await runPlatformCommand3(
|
|
4191
5051
|
options,
|
|
4192
5052
|
globalOptions.timeout,
|
|
4193
5053
|
({ client, signal }) => listEvalSuitesOperation.execute(
|
|
@@ -4197,7 +5057,7 @@ function registerEvalCommands(program) {
|
|
|
4197
5057
|
);
|
|
4198
5058
|
writeResult(result, globalOptions.format);
|
|
4199
5059
|
});
|
|
4200
|
-
|
|
5060
|
+
addPlatformOptions3(
|
|
4201
5061
|
evals.command("run").description("Start an eval run of an existing suite (asynchronous)").requiredOption("--suite <id-or-name>", "Eval suite name or ID").option(
|
|
4202
5062
|
"--project <id-or-name>",
|
|
4203
5063
|
"Project name or ID (defaults to the most recently updated project)"
|
|
@@ -4208,7 +5068,7 @@ function registerEvalCommands(program) {
|
|
|
4208
5068
|
).action(
|
|
4209
5069
|
async (options, command) => {
|
|
4210
5070
|
const globalOptions = getGlobalOptions(command);
|
|
4211
|
-
const result = await
|
|
5071
|
+
const result = await runPlatformCommand3(
|
|
4212
5072
|
options,
|
|
4213
5073
|
globalOptions.timeout,
|
|
4214
5074
|
({ client, signal }) => runEvalSuiteOperation.execute(
|
|
@@ -4223,12 +5083,12 @@ function registerEvalCommands(program) {
|
|
|
4223
5083
|
writeResult(result, globalOptions.format);
|
|
4224
5084
|
}
|
|
4225
5085
|
);
|
|
4226
|
-
|
|
5086
|
+
addPlatformOptions3(
|
|
4227
5087
|
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")
|
|
4228
5088
|
).action(
|
|
4229
5089
|
async (options, command) => {
|
|
4230
5090
|
const globalOptions = getGlobalOptions(command);
|
|
4231
|
-
const result = await
|
|
5091
|
+
const result = await runPlatformCommand3(
|
|
4232
5092
|
options,
|
|
4233
5093
|
globalOptions.timeout,
|
|
4234
5094
|
({ client, signal }) => getEvalRunOperation.execute(
|
|
@@ -4239,7 +5099,7 @@ function registerEvalCommands(program) {
|
|
|
4239
5099
|
writeResult(result, globalOptions.format);
|
|
4240
5100
|
}
|
|
4241
5101
|
);
|
|
4242
|
-
|
|
5102
|
+
addPlatformOptions3(
|
|
4243
5103
|
evals.command("cancel").description(
|
|
4244
5104
|
"Cancel an in-flight eval run (no-op if already cancelled; errors if it already finished)"
|
|
4245
5105
|
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption("--project <id-or-name>", "Project name or ID")
|
|
@@ -4254,7 +5114,7 @@ function registerEvalCommands(program) {
|
|
|
4254
5114
|
}
|
|
4255
5115
|
);
|
|
4256
5116
|
const PROJECT_OPT = "Project name or ID (defaults to most recently updated)";
|
|
4257
|
-
|
|
5117
|
+
addPlatformOptions3(
|
|
4258
5118
|
evals.command("iterations").description(
|
|
4259
5119
|
"List per-iteration results for an eval run (pass/fail, tool calls, tokens, latency)"
|
|
4260
5120
|
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
@@ -4272,7 +5132,7 @@ function registerEvalCommands(program) {
|
|
|
4272
5132
|
await executeOp(listEvalRunIterationsOperation, input, options, command);
|
|
4273
5133
|
}
|
|
4274
5134
|
);
|
|
4275
|
-
|
|
5135
|
+
addPlatformOptions3(
|
|
4276
5136
|
evals.command("trace").description(
|
|
4277
5137
|
"Fetch the full trace for one eval iteration (large: full message history + spans)"
|
|
4278
5138
|
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
@@ -4296,7 +5156,7 @@ function registerEvalCommands(program) {
|
|
|
4296
5156
|
);
|
|
4297
5157
|
}
|
|
4298
5158
|
);
|
|
4299
|
-
|
|
5159
|
+
addPlatformOptions3(
|
|
4300
5160
|
evals.command("steps").description(
|
|
4301
5161
|
"Per-authored-step results for one eval iteration: status (ok/fail/skipped/pending), reason, and evidence (screenshot/video URLs). The fastest way to see WHICH step failed and why."
|
|
4302
5162
|
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
@@ -4320,7 +5180,7 @@ function registerEvalCommands(program) {
|
|
|
4320
5180
|
);
|
|
4321
5181
|
}
|
|
4322
5182
|
);
|
|
4323
|
-
|
|
5183
|
+
addPlatformOptions3(
|
|
4324
5184
|
evals.command("screenshot").description(
|
|
4325
5185
|
"Show the widget screenshot(s) an eval iteration rendered \u2014 inline when the terminal supports it, otherwise the image URL"
|
|
4326
5186
|
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
@@ -4337,7 +5197,7 @@ function registerEvalCommands(program) {
|
|
|
4337
5197
|
async (options, command) => {
|
|
4338
5198
|
const globalOptions = getGlobalOptions(command);
|
|
4339
5199
|
const index = options.index !== void 0 ? parsePositiveInteger(options.index, "--index") : void 0;
|
|
4340
|
-
const result = await
|
|
5200
|
+
const result = await runPlatformCommand3(
|
|
4341
5201
|
options,
|
|
4342
5202
|
globalOptions.timeout,
|
|
4343
5203
|
({ client, signal }) => getEvalIterationTraceOperation.execute(
|
|
@@ -4428,7 +5288,7 @@ function registerEvalCommands(program) {
|
|
|
4428
5288
|
}
|
|
4429
5289
|
}
|
|
4430
5290
|
);
|
|
4431
|
-
|
|
5291
|
+
addPlatformOptions3(
|
|
4432
5292
|
evals.command("video").description(
|
|
4433
5293
|
"Get the Playwright replay video (.webm) an eval iteration recorded \u2014 prints the URL, or downloads it with --out"
|
|
4434
5294
|
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
@@ -4441,7 +5301,7 @@ function registerEvalCommands(program) {
|
|
|
4441
5301
|
).action(
|
|
4442
5302
|
async (options, command) => {
|
|
4443
5303
|
const globalOptions = getGlobalOptions(command);
|
|
4444
|
-
const result = await
|
|
5304
|
+
const result = await runPlatformCommand3(
|
|
4445
5305
|
options,
|
|
4446
5306
|
globalOptions.timeout,
|
|
4447
5307
|
({ client, signal }) => getEvalIterationTraceOperation.execute(
|
|
@@ -4492,7 +5352,7 @@ function registerEvalCommands(program) {
|
|
|
4492
5352
|
`);
|
|
4493
5353
|
}
|
|
4494
5354
|
);
|
|
4495
|
-
|
|
5355
|
+
addPlatformOptions3(
|
|
4496
5356
|
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)
|
|
4497
5357
|
).action(
|
|
4498
5358
|
async (options, command) => {
|
|
@@ -4504,7 +5364,7 @@ function registerEvalCommands(program) {
|
|
|
4504
5364
|
);
|
|
4505
5365
|
}
|
|
4506
5366
|
);
|
|
4507
|
-
|
|
5367
|
+
addPlatformOptions3(
|
|
4508
5368
|
evals.command("update").description(
|
|
4509
5369
|
"Edit an eval suite's settings (only the flags you pass change)"
|
|
4510
5370
|
).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(
|
|
@@ -4518,7 +5378,7 @@ function registerEvalCommands(program) {
|
|
|
4518
5378
|
);
|
|
4519
5379
|
await executeOp(updateEvalSuiteOperation, input, options, command);
|
|
4520
5380
|
});
|
|
4521
|
-
|
|
5381
|
+
addPlatformOptions3(
|
|
4522
5382
|
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)
|
|
4523
5383
|
).action(
|
|
4524
5384
|
async (options, command) => {
|
|
@@ -4530,7 +5390,7 @@ function registerEvalCommands(program) {
|
|
|
4530
5390
|
);
|
|
4531
5391
|
}
|
|
4532
5392
|
);
|
|
4533
|
-
|
|
5393
|
+
addPlatformOptions3(
|
|
4534
5394
|
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)")
|
|
4535
5395
|
).action(
|
|
4536
5396
|
async (options, command) => {
|
|
@@ -4550,7 +5410,7 @@ function registerEvalCommands(program) {
|
|
|
4550
5410
|
}
|
|
4551
5411
|
);
|
|
4552
5412
|
const cases = evals.command("cases").description("List, author, and edit an eval suite's test cases");
|
|
4553
|
-
|
|
5413
|
+
addPlatformOptions3(
|
|
4554
5414
|
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)
|
|
4555
5415
|
).action(
|
|
4556
5416
|
async (options, command) => {
|
|
@@ -4562,7 +5422,7 @@ function registerEvalCommands(program) {
|
|
|
4562
5422
|
);
|
|
4563
5423
|
}
|
|
4564
5424
|
);
|
|
4565
|
-
|
|
5425
|
+
addPlatformOptions3(
|
|
4566
5426
|
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)
|
|
4567
5427
|
).action(
|
|
4568
5428
|
async (options, command) => {
|
|
@@ -4574,7 +5434,7 @@ function registerEvalCommands(program) {
|
|
|
4574
5434
|
);
|
|
4575
5435
|
}
|
|
4576
5436
|
);
|
|
4577
|
-
|
|
5437
|
+
addPlatformOptions3(
|
|
4578
5438
|
cases.command("run").description(
|
|
4579
5439
|
"Run a single case as a persisted, fully-queryable run (inspect it with `eval iterations` / `eval steps` like any run)"
|
|
4580
5440
|
).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(
|
|
@@ -4596,7 +5456,7 @@ function registerEvalCommands(program) {
|
|
|
4596
5456
|
);
|
|
4597
5457
|
}
|
|
4598
5458
|
);
|
|
4599
|
-
|
|
5459
|
+
addPlatformOptions3(
|
|
4600
5460
|
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)")
|
|
4601
5461
|
).action(async (options, command) => {
|
|
4602
5462
|
const input = validateOpInput(
|
|
@@ -4605,7 +5465,7 @@ function registerEvalCommands(program) {
|
|
|
4605
5465
|
);
|
|
4606
5466
|
await executeOp(createEvalCaseOperation, input, options, command);
|
|
4607
5467
|
});
|
|
4608
|
-
|
|
5468
|
+
addPlatformOptions3(
|
|
4609
5469
|
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")
|
|
4610
5470
|
).action(async (options, command) => {
|
|
4611
5471
|
const input = validateOpInput(
|
|
@@ -4614,7 +5474,7 @@ function registerEvalCommands(program) {
|
|
|
4614
5474
|
);
|
|
4615
5475
|
await executeOp(updateEvalCaseOperation, input, options, command);
|
|
4616
5476
|
});
|
|
4617
|
-
|
|
5477
|
+
addPlatformOptions3(
|
|
4618
5478
|
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)
|
|
4619
5479
|
).action(
|
|
4620
5480
|
async (options, command) => {
|
|
@@ -4626,7 +5486,7 @@ function registerEvalCommands(program) {
|
|
|
4626
5486
|
);
|
|
4627
5487
|
}
|
|
4628
5488
|
);
|
|
4629
|
-
|
|
5489
|
+
addPlatformOptions3(
|
|
4630
5490
|
cases.command("generate").description(
|
|
4631
5491
|
"AI-generate test cases from the suite's tools (spends credits)"
|
|
4632
5492
|
).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(
|
|
@@ -4675,13 +5535,13 @@ function registerEvalCommands(program) {
|
|
|
4675
5535
|
);
|
|
4676
5536
|
}
|
|
4677
5537
|
var HOST_TEMPLATES = HOST_TEMPLATES$1.map(({ id, label }) => ({ id, label }));
|
|
4678
|
-
function
|
|
5538
|
+
function addPlatformOptions4(command) {
|
|
4679
5539
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
4680
5540
|
"--api-url <url>",
|
|
4681
5541
|
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
4682
5542
|
);
|
|
4683
5543
|
}
|
|
4684
|
-
async function
|
|
5544
|
+
async function runPlatformCommand4(options, timeoutMs, execute) {
|
|
4685
5545
|
const controller = new AbortController();
|
|
4686
5546
|
const timeoutHandle = setTimeout(() => {
|
|
4687
5547
|
controller.abort(
|
|
@@ -4741,26 +5601,26 @@ function registerHostsCommands(program) {
|
|
|
4741
5601
|
const globalOptions = getGlobalOptions(command);
|
|
4742
5602
|
writeResult({ items: HOST_TEMPLATES }, globalOptions.format);
|
|
4743
5603
|
});
|
|
4744
|
-
|
|
5604
|
+
addPlatformOptions4(
|
|
4745
5605
|
hosts.command("list").description("List the hosts saved in a project").option(
|
|
4746
5606
|
"--project <id-or-name>",
|
|
4747
5607
|
"Project name or ID (defaults to the most recently updated project)"
|
|
4748
5608
|
)
|
|
4749
5609
|
).action(async (options, command) => {
|
|
4750
5610
|
const globalOptions = getGlobalOptions(command);
|
|
4751
|
-
const result = await
|
|
5611
|
+
const result = await runPlatformCommand4(
|
|
4752
5612
|
options,
|
|
4753
5613
|
globalOptions.timeout,
|
|
4754
5614
|
({ client, signal }) => listHostsOperation.execute({ project: options.project }, { client, signal })
|
|
4755
5615
|
);
|
|
4756
5616
|
writeResult(result, globalOptions.format);
|
|
4757
5617
|
});
|
|
4758
|
-
|
|
5618
|
+
addPlatformOptions4(
|
|
4759
5619
|
hosts.command("get").description("Show one host's full settings, including its host config").requiredOption("--host <id-or-name>", "Host name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
4760
5620
|
).action(
|
|
4761
5621
|
async (options, command) => {
|
|
4762
5622
|
const globalOptions = getGlobalOptions(command);
|
|
4763
|
-
const result = await
|
|
5623
|
+
const result = await runPlatformCommand4(
|
|
4764
5624
|
options,
|
|
4765
5625
|
globalOptions.timeout,
|
|
4766
5626
|
({ client, signal }) => getHostOperation.execute(
|
|
@@ -4771,7 +5631,7 @@ function registerHostsCommands(program) {
|
|
|
4771
5631
|
writeResult(result, globalOptions.format);
|
|
4772
5632
|
}
|
|
4773
5633
|
);
|
|
4774
|
-
|
|
5634
|
+
addPlatformOptions4(
|
|
4775
5635
|
hosts.command("create").description(
|
|
4776
5636
|
"Create a host from a built-in template (--template) or a full host config (--file/--json)"
|
|
4777
5637
|
).requiredOption("--name <name>", "Display name for the new host").option("--project <id-or-name>", "Project name or ID").option(
|
|
@@ -4785,14 +5645,14 @@ function registerHostsCommands(program) {
|
|
|
4785
5645
|
async (options, command) => {
|
|
4786
5646
|
const globalOptions = getGlobalOptions(command);
|
|
4787
5647
|
const config = loadConfigObject(options);
|
|
4788
|
-
const input =
|
|
5648
|
+
const input = validateInput3(createHostOperation, {
|
|
4789
5649
|
project: options.project,
|
|
4790
5650
|
name: options.name,
|
|
4791
5651
|
...options.template !== void 0 ? { template: options.template } : {},
|
|
4792
5652
|
...options.theme !== void 0 ? { theme: options.theme } : {},
|
|
4793
5653
|
...config !== void 0 ? { config } : {}
|
|
4794
5654
|
});
|
|
4795
|
-
const result = await
|
|
5655
|
+
const result = await runPlatformCommand4(
|
|
4796
5656
|
options,
|
|
4797
5657
|
globalOptions.timeout,
|
|
4798
5658
|
({ client, signal }) => createHostOperation.execute(input, { client, signal })
|
|
@@ -4800,19 +5660,19 @@ function registerHostsCommands(program) {
|
|
|
4800
5660
|
writeResult(result, globalOptions.format);
|
|
4801
5661
|
}
|
|
4802
5662
|
);
|
|
4803
|
-
|
|
5663
|
+
addPlatformOptions4(
|
|
4804
5664
|
hosts.command("update").description("Edit a host's name and/or its host config").requiredOption("--host <id-or-name>", "Host name or ID").option("--project <id-or-name>", "Project name or ID").option("--name <name>", "New display name").option("--file <path>", "Replacement host config v2 JSON (or - for stdin)").option("--json <json>", "Inline replacement host config v2 JSON (or @file, or -)")
|
|
4805
5665
|
).action(
|
|
4806
5666
|
async (options, command) => {
|
|
4807
5667
|
const globalOptions = getGlobalOptions(command);
|
|
4808
5668
|
const config = loadConfigObject(options);
|
|
4809
|
-
const input =
|
|
5669
|
+
const input = validateInput3(updateHostOperation, {
|
|
4810
5670
|
project: options.project,
|
|
4811
5671
|
host: options.host,
|
|
4812
5672
|
...options.name !== void 0 ? { name: options.name } : {},
|
|
4813
5673
|
...config !== void 0 ? { config } : {}
|
|
4814
5674
|
});
|
|
4815
|
-
const result = await
|
|
5675
|
+
const result = await runPlatformCommand4(
|
|
4816
5676
|
options,
|
|
4817
5677
|
globalOptions.timeout,
|
|
4818
5678
|
({ client, signal }) => updateHostOperation.execute(input, { client, signal })
|
|
@@ -4820,12 +5680,12 @@ function registerHostsCommands(program) {
|
|
|
4820
5680
|
writeResult(result, globalOptions.format);
|
|
4821
5681
|
}
|
|
4822
5682
|
);
|
|
4823
|
-
|
|
5683
|
+
addPlatformOptions4(
|
|
4824
5684
|
hosts.command("delete").description("Permanently delete a host from a project").requiredOption("--host <id-or-name>", "Host name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
4825
5685
|
).action(
|
|
4826
5686
|
async (options, command) => {
|
|
4827
5687
|
const globalOptions = getGlobalOptions(command);
|
|
4828
|
-
const result = await
|
|
5688
|
+
const result = await runPlatformCommand4(
|
|
4829
5689
|
options,
|
|
4830
5690
|
globalOptions.timeout,
|
|
4831
5691
|
({ client, signal }) => deleteHostOperation.execute(
|
|
@@ -4840,7 +5700,7 @@ function registerHostsCommands(program) {
|
|
|
4840
5700
|
}
|
|
4841
5701
|
);
|
|
4842
5702
|
}
|
|
4843
|
-
function
|
|
5703
|
+
function validateInput3(op, raw) {
|
|
4844
5704
|
const parsed = op.inputSchema.safeParse(raw);
|
|
4845
5705
|
if (!parsed.success) {
|
|
4846
5706
|
const detail = parsed.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
|
|
@@ -5599,13 +6459,13 @@ function statusGlyph(status) {
|
|
|
5599
6459
|
}
|
|
5600
6460
|
|
|
5601
6461
|
// src/commands/projects.ts
|
|
5602
|
-
function
|
|
6462
|
+
function addPlatformOptions5(command) {
|
|
5603
6463
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
5604
6464
|
"--api-url <url>",
|
|
5605
6465
|
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
5606
6466
|
);
|
|
5607
6467
|
}
|
|
5608
|
-
async function
|
|
6468
|
+
async function runPlatformCommand5(options, timeoutMs, execute) {
|
|
5609
6469
|
const controller = new AbortController();
|
|
5610
6470
|
const timeoutHandle = setTimeout(() => {
|
|
5611
6471
|
controller.abort(
|
|
@@ -5633,11 +6493,11 @@ async function runPlatformCommand4(options, timeoutMs, execute) {
|
|
|
5633
6493
|
}
|
|
5634
6494
|
function registerProjectsCommands(program) {
|
|
5635
6495
|
const projects = program.command("projects").description("Operate the MCP servers saved in your hosted MCPJam projects");
|
|
5636
|
-
|
|
6496
|
+
addPlatformOptions5(
|
|
5637
6497
|
projects.command("list").description("List the projects you can access")
|
|
5638
6498
|
).action(async (options, command) => {
|
|
5639
6499
|
const globalOptions = getGlobalOptions(command);
|
|
5640
|
-
const result = await
|
|
6500
|
+
const result = await runPlatformCommand5(
|
|
5641
6501
|
options,
|
|
5642
6502
|
globalOptions.timeout,
|
|
5643
6503
|
({ client, signal }) => listProjectsOperation.execute({}, { client, signal })
|
|
@@ -5649,14 +6509,14 @@ function registerProjectsCommands(program) {
|
|
|
5649
6509
|
writeResult(result, globalOptions.format);
|
|
5650
6510
|
}
|
|
5651
6511
|
});
|
|
5652
|
-
|
|
6512
|
+
addPlatformOptions5(
|
|
5653
6513
|
projects.command("servers").description("List the servers saved in a project").option(
|
|
5654
6514
|
"--project <id-or-name>",
|
|
5655
6515
|
"Project name or ID (defaults to the most recently updated project)"
|
|
5656
6516
|
)
|
|
5657
6517
|
).action(async (options, command) => {
|
|
5658
6518
|
const globalOptions = getGlobalOptions(command);
|
|
5659
|
-
const result = await
|
|
6519
|
+
const result = await runPlatformCommand5(
|
|
5660
6520
|
options,
|
|
5661
6521
|
globalOptions.timeout,
|
|
5662
6522
|
({ client, signal }) => listProjectServersOperation.execute(
|
|
@@ -5671,7 +6531,7 @@ function registerProjectsCommands(program) {
|
|
|
5671
6531
|
writeResult(result, globalOptions.format);
|
|
5672
6532
|
}
|
|
5673
6533
|
});
|
|
5674
|
-
|
|
6534
|
+
addPlatformOptions5(
|
|
5675
6535
|
projects.command("status").description(
|
|
5676
6536
|
"Health-check every server in a project (hosted doctor per server)"
|
|
5677
6537
|
).option(
|
|
@@ -5680,7 +6540,7 @@ function registerProjectsCommands(program) {
|
|
|
5680
6540
|
)
|
|
5681
6541
|
).action(async (options, command) => {
|
|
5682
6542
|
const globalOptions = getGlobalOptions(command);
|
|
5683
|
-
const payload = await
|
|
6543
|
+
const payload = await runPlatformCommand5(
|
|
5684
6544
|
options,
|
|
5685
6545
|
globalOptions.timeout,
|
|
5686
6546
|
({ client, signal }) => showServersOperation.execute(
|
|
@@ -5721,6 +6581,9 @@ function registerProtocolCommands(program) {
|
|
|
5721
6581
|
"Specific check ID to run. Repeat for multiple. Default: all.",
|
|
5722
6582
|
(value, previous = []) => [...previous, value],
|
|
5723
6583
|
[]
|
|
6584
|
+
).option(
|
|
6585
|
+
"--protocol-version <version>",
|
|
6586
|
+
"Pin the MCP protocol version to conform against. Default: legacy (2025-era) behavior."
|
|
5724
6587
|
).option(
|
|
5725
6588
|
"--reporter <reporter>",
|
|
5726
6589
|
"Structured reporter output: json-summary or junit-xml"
|
|
@@ -5796,13 +6659,20 @@ function buildConfig(options) {
|
|
|
5796
6659
|
`Unknown check id${invalidCheckIds.length === 1 ? "" : "s"}: ${invalidCheckIds.join(", ")}`
|
|
5797
6660
|
);
|
|
5798
6661
|
}
|
|
6662
|
+
const protocolVersion = options.protocolVersion?.trim();
|
|
6663
|
+
if (options.protocolVersion !== void 0 && (!protocolVersion || !isKnownProtocolVersion(protocolVersion))) {
|
|
6664
|
+
throw usageError(
|
|
6665
|
+
`Unknown protocol version: ${protocolVersion ?? ""}. Known: ${MCP_PROTOCOL_VERSIONS.join(", ")}`
|
|
6666
|
+
);
|
|
6667
|
+
}
|
|
5799
6668
|
return {
|
|
5800
6669
|
serverUrl,
|
|
5801
6670
|
accessToken,
|
|
5802
6671
|
customHeaders,
|
|
5803
6672
|
checkTimeout: options.checkTimeout ?? 15e3,
|
|
5804
6673
|
...categories && categories.length > 0 ? { categories } : {},
|
|
5805
|
-
...checkIds && checkIds.length > 0 ? { checkIds } : {}
|
|
6674
|
+
...checkIds && checkIds.length > 0 ? { checkIds } : {},
|
|
6675
|
+
...protocolVersion ? { protocolVersion } : {}
|
|
5806
6676
|
};
|
|
5807
6677
|
}
|
|
5808
6678
|
function parseOAuthOutputFormat(value) {
|
|
@@ -5913,7 +6783,7 @@ function registerOAuthCommands(program) {
|
|
|
5913
6783
|
const oauth = program.command("oauth").description("Run MCP OAuth login, proxy, and conformance flows");
|
|
5914
6784
|
oauth.command("login").description("Run an OAuth login flow against an HTTP MCP server").requiredOption("--url <url>", "MCP server URL").option(
|
|
5915
6785
|
"--protocol-version <version>",
|
|
5916
|
-
"OAuth protocol override: 2025-03-26, 2025-06-18,
|
|
6786
|
+
"OAuth protocol override: 2025-03-26, 2025-06-18, 2025-11-25, or 2026-07-28"
|
|
5917
6787
|
).option(
|
|
5918
6788
|
"--registration <strategy>",
|
|
5919
6789
|
"Registration override: dcr, preregistered, or cimd"
|
|
@@ -6036,7 +6906,7 @@ function registerOAuthCommands(program) {
|
|
|
6036
6906
|
});
|
|
6037
6907
|
oauth.command("conformance").description("Run OAuth conformance against an HTTP MCP server").requiredOption("--url <url>", "MCP server URL").requiredOption(
|
|
6038
6908
|
"--protocol-version <version>",
|
|
6039
|
-
"OAuth protocol version: 2025-03-26, 2025-06-18,
|
|
6909
|
+
"OAuth protocol version: 2025-03-26, 2025-06-18, 2025-11-25, or 2026-07-28"
|
|
6040
6910
|
).requiredOption(
|
|
6041
6911
|
"--registration <strategy>",
|
|
6042
6912
|
"Registration strategy: dcr, preregistered, or cimd"
|
|
@@ -6212,7 +7082,7 @@ function buildOAuthConformanceConfig(options, defaults) {
|
|
|
6212
7082
|
"--print-url only applies to --auth-mode interactive. Headless and client_credentials modes do not open a browser."
|
|
6213
7083
|
);
|
|
6214
7084
|
}
|
|
6215
|
-
if (protocolVersion
|
|
7085
|
+
if (!CIMD_PROTOCOL_VERSIONS.has(protocolVersion) && registrationStrategy === "cimd") {
|
|
6216
7086
|
throw usageError(
|
|
6217
7087
|
`CIMD registration is not supported for protocol version ${protocolVersion}.`
|
|
6218
7088
|
);
|
|
@@ -6295,7 +7165,7 @@ function buildOAuthLoginConfig(options, defaults) {
|
|
|
6295
7165
|
"--print-url only applies to --auth-mode interactive. Headless and client_credentials modes do not open a browser."
|
|
6296
7166
|
);
|
|
6297
7167
|
}
|
|
6298
|
-
if (protocolVersion !== void 0 && registrationStrategy === "cimd" && protocolVersion
|
|
7168
|
+
if (protocolVersion !== void 0 && registrationStrategy === "cimd" && !CIMD_PROTOCOL_VERSIONS.has(protocolVersion)) {
|
|
6299
7169
|
throw usageError(
|
|
6300
7170
|
`CIMD registration is not supported for protocol version ${protocolVersion}.`
|
|
6301
7171
|
);
|
|
@@ -6388,10 +7258,12 @@ function summarizeOAuthLoginCommandInput(options) {
|
|
|
6388
7258
|
};
|
|
6389
7259
|
}
|
|
6390
7260
|
function buildOAuthLoginSnapshotConfig(config, result) {
|
|
7261
|
+
const snapshotProtocolVersion = result?.protocolVersion ?? config.protocolVersion;
|
|
6391
7262
|
const baseConfig = {
|
|
6392
7263
|
url: config.serverUrl,
|
|
6393
7264
|
...config.customHeaders ? { requestInit: { headers: config.customHeaders } } : {},
|
|
6394
|
-
timeout: config.stepTimeout ?? 3e4
|
|
7265
|
+
timeout: config.stepTimeout ?? 3e4,
|
|
7266
|
+
...snapshotProtocolVersion === "2026-07-28" ? { mcpProtocolVersion: "2026-07-28" } : {}
|
|
6395
7267
|
};
|
|
6396
7268
|
if (!result) {
|
|
6397
7269
|
return baseConfig;
|
|
@@ -6885,6 +7757,12 @@ function registerPromptCommands(program) {
|
|
|
6885
7757
|
prompts.command("get").description("Get a named prompt from an MCP server").option("--prompt-name <prompt>", "Prompt name").option("--name <prompt>", "Alias for --prompt-name").option(
|
|
6886
7758
|
"--prompt-args <json>",
|
|
6887
7759
|
"Prompt arguments as JSON, @path, or - for stdin"
|
|
7760
|
+
).option(
|
|
7761
|
+
"--interactive",
|
|
7762
|
+
"Drive the modern input_required (multi-round-trip) loop: render embedded elicitations to the terminal and collect responses from stdin"
|
|
7763
|
+
).option(
|
|
7764
|
+
"--yes",
|
|
7765
|
+
"With --interactive, run non-interactively: decline every embedded input request instead of prompting"
|
|
6888
7766
|
)
|
|
6889
7767
|
)
|
|
6890
7768
|
)
|
|
@@ -6907,6 +7785,11 @@ function registerPromptCommands(program) {
|
|
|
6907
7785
|
...options,
|
|
6908
7786
|
timeout: globalOptions.timeout
|
|
6909
7787
|
});
|
|
7788
|
+
if (options.interactive && options.promptArgs === "-") {
|
|
7789
|
+
throw usageError(
|
|
7790
|
+
"--interactive cannot be used together with --prompt-args -: interactive answers are read from stdin too. Pass the arguments as JSON or @path."
|
|
7791
|
+
);
|
|
7792
|
+
}
|
|
6910
7793
|
const promptArguments = parsePromptArguments(options.promptArgs);
|
|
6911
7794
|
const result = await withEphemeralManager(
|
|
6912
7795
|
config,
|
|
@@ -6919,7 +7802,9 @@ function registerPromptCommands(program) {
|
|
|
6919
7802
|
timeout: globalOptions.timeout,
|
|
6920
7803
|
rpcLogger: collector?.rpcLogger,
|
|
6921
7804
|
retryPolicy,
|
|
6922
|
-
host: host?.connection
|
|
7805
|
+
host: host?.connection,
|
|
7806
|
+
beforeConnect: buildMrtrBeforeConnect(options),
|
|
7807
|
+
interactiveElicitation: options.interactive === true
|
|
6923
7808
|
}
|
|
6924
7809
|
);
|
|
6925
7810
|
writeResult(
|
|
@@ -6964,7 +7849,13 @@ function registerResourcesCommands(program) {
|
|
|
6964
7849
|
addHostOption(
|
|
6965
7850
|
addRetryOptions(
|
|
6966
7851
|
addSharedServerOptions(
|
|
6967
|
-
resources.command("read").description("Read a resource from an MCP server").option("--resource-uri <uri>", "Resource URI").option("--uri <uri>", "Alias for --resource-uri")
|
|
7852
|
+
resources.command("read").description("Read a resource from an MCP server").option("--resource-uri <uri>", "Resource URI").option("--uri <uri>", "Alias for --resource-uri").option(
|
|
7853
|
+
"--interactive",
|
|
7854
|
+
"Drive the modern input_required (multi-round-trip) loop: render embedded elicitations to the terminal and collect responses from stdin"
|
|
7855
|
+
).option(
|
|
7856
|
+
"--yes",
|
|
7857
|
+
"With --interactive, run non-interactively: decline every embedded input request instead of prompting"
|
|
7858
|
+
)
|
|
6968
7859
|
)
|
|
6969
7860
|
)
|
|
6970
7861
|
).action(async (options, command) => {
|
|
@@ -6993,7 +7884,9 @@ function registerResourcesCommands(program) {
|
|
|
6993
7884
|
timeout: globalOptions.timeout,
|
|
6994
7885
|
rpcLogger: collector?.rpcLogger,
|
|
6995
7886
|
retryPolicy,
|
|
6996
|
-
host: host?.connection
|
|
7887
|
+
host: host?.connection,
|
|
7888
|
+
beforeConnect: buildMrtrBeforeConnect(options),
|
|
7889
|
+
interactiveElicitation: options.interactive === true
|
|
6997
7890
|
}
|
|
6998
7891
|
);
|
|
6999
7892
|
writeResult(
|
|
@@ -7572,6 +8465,420 @@ function createServerDiffResult(left, right, failOn) {
|
|
|
7572
8465
|
throw error;
|
|
7573
8466
|
}
|
|
7574
8467
|
}
|
|
8468
|
+
|
|
8469
|
+
// src/lib/subscriptions-session.ts
|
|
8470
|
+
var SUBSCRIPTION_OUTCOME_EXIT_CODES = {
|
|
8471
|
+
graceful: 0,
|
|
8472
|
+
cancelled: 0,
|
|
8473
|
+
remote: 1,
|
|
8474
|
+
error: 1
|
|
8475
|
+
};
|
|
8476
|
+
function relistenDelayMs(policy, attempt) {
|
|
8477
|
+
return Math.min(
|
|
8478
|
+
policy.maxDelayMs,
|
|
8479
|
+
policy.initialDelayMs * policy.factor ** (attempt - 1)
|
|
8480
|
+
);
|
|
8481
|
+
}
|
|
8482
|
+
function describeFilter(filter) {
|
|
8483
|
+
const parts = [];
|
|
8484
|
+
if (filter.toolsListChanged) parts.push("tools/list_changed");
|
|
8485
|
+
if (filter.promptsListChanged) parts.push("prompts/list_changed");
|
|
8486
|
+
if (filter.resourcesListChanged) parts.push("resources/list_changed");
|
|
8487
|
+
for (const uri of filter.resourceSubscriptions ?? []) {
|
|
8488
|
+
parts.push(`resource:${uri}`);
|
|
8489
|
+
}
|
|
8490
|
+
return parts.length > 0 ? parts.join(", ") : "(empty)";
|
|
8491
|
+
}
|
|
8492
|
+
function hasAnyInterest(desired) {
|
|
8493
|
+
return Boolean(
|
|
8494
|
+
desired.toolsListChanged || desired.promptsListChanged || desired.resourcesListChanged || (desired.resourceUris?.length ?? 0) > 0
|
|
8495
|
+
);
|
|
8496
|
+
}
|
|
8497
|
+
var SubscriptionListenSession = class {
|
|
8498
|
+
constructor(options, deps) {
|
|
8499
|
+
this.options = options;
|
|
8500
|
+
this.deps = deps;
|
|
8501
|
+
this.now = deps.now ?? (() => Date.now());
|
|
8502
|
+
this.setTimer = deps.setTimer ?? ((fn, ms) => {
|
|
8503
|
+
const handle = setTimeout(fn, ms);
|
|
8504
|
+
handle.unref?.();
|
|
8505
|
+
return { cancel: () => clearTimeout(handle) };
|
|
8506
|
+
});
|
|
8507
|
+
this.completion = new Promise((resolve) => {
|
|
8508
|
+
this.resolveCompletion = resolve;
|
|
8509
|
+
});
|
|
8510
|
+
this.coordinator = deps.createCoordinator({
|
|
8511
|
+
onStreamChange: (stream) => this.onStreamChange(stream),
|
|
8512
|
+
onNotification: (event) => this.onNotification(event),
|
|
8513
|
+
onRejectedNotification: (event) => this.onRejectedNotification(event)
|
|
8514
|
+
});
|
|
8515
|
+
}
|
|
8516
|
+
coordinator;
|
|
8517
|
+
now;
|
|
8518
|
+
setTimer;
|
|
8519
|
+
timers = [];
|
|
8520
|
+
settled = false;
|
|
8521
|
+
/**
|
|
8522
|
+
* Set the moment a local abort is requested, before the (async) cancel
|
|
8523
|
+
* round-trip completes: notifications that land during the teardown belong
|
|
8524
|
+
* to a stream we have already decided to stop, so counting them would let a
|
|
8525
|
+
* chatty server overshoot `--max-notifications`.
|
|
8526
|
+
*/
|
|
8527
|
+
stopping = false;
|
|
8528
|
+
stopReason;
|
|
8529
|
+
notifications = 0;
|
|
8530
|
+
rejectedNotifications = 0;
|
|
8531
|
+
relistenAttempts = 0;
|
|
8532
|
+
seenStreams = /* @__PURE__ */ new Set();
|
|
8533
|
+
acknowledged = /* @__PURE__ */ new Set();
|
|
8534
|
+
closed = /* @__PURE__ */ new Set();
|
|
8535
|
+
resolveCompletion;
|
|
8536
|
+
completion;
|
|
8537
|
+
/** Opens the stream and resolves when it reaches a terminal outcome. */
|
|
8538
|
+
async run() {
|
|
8539
|
+
this.deps.status(
|
|
8540
|
+
`Opening subscription: ${describeFilter({
|
|
8541
|
+
toolsListChanged: this.options.desired.toolsListChanged,
|
|
8542
|
+
promptsListChanged: this.options.desired.promptsListChanged,
|
|
8543
|
+
resourcesListChanged: this.options.desired.resourcesListChanged,
|
|
8544
|
+
resourceSubscriptions: [...this.options.desired.resourceUris ?? []]
|
|
8545
|
+
})}`
|
|
8546
|
+
);
|
|
8547
|
+
if (this.options.durationMs !== void 0) {
|
|
8548
|
+
this.timers.push(
|
|
8549
|
+
this.setTimer(() => {
|
|
8550
|
+
void this.stop("duration");
|
|
8551
|
+
}, this.options.durationMs)
|
|
8552
|
+
);
|
|
8553
|
+
}
|
|
8554
|
+
try {
|
|
8555
|
+
await this.coordinator.setDesiredInterests(this.options.desired);
|
|
8556
|
+
} catch (error) {
|
|
8557
|
+
this.finish(
|
|
8558
|
+
"error",
|
|
8559
|
+
error instanceof Error ? error.message : String(error)
|
|
8560
|
+
);
|
|
8561
|
+
}
|
|
8562
|
+
const result = await this.completion;
|
|
8563
|
+
for (const timer of this.timers) timer.cancel();
|
|
8564
|
+
await this.safeDispose();
|
|
8565
|
+
return result;
|
|
8566
|
+
}
|
|
8567
|
+
/** Local abort (signal, duration cap, notification cap). Idempotent. */
|
|
8568
|
+
async stop(reason) {
|
|
8569
|
+
if (this.settled || this.stopping) return;
|
|
8570
|
+
this.stopping = true;
|
|
8571
|
+
this.stopReason ??= reason;
|
|
8572
|
+
this.deps.status(`Cancelling subscription (${reason})...`);
|
|
8573
|
+
try {
|
|
8574
|
+
await this.coordinator.cancel();
|
|
8575
|
+
} catch (error) {
|
|
8576
|
+
this.deps.status(
|
|
8577
|
+
`Cancel failed: ${error instanceof Error ? error.message : String(error)}`
|
|
8578
|
+
);
|
|
8579
|
+
}
|
|
8580
|
+
this.finish("cancelled");
|
|
8581
|
+
}
|
|
8582
|
+
onStreamChange(stream) {
|
|
8583
|
+
if (this.settled) return;
|
|
8584
|
+
if (!this.seenStreams.has(stream.localId)) {
|
|
8585
|
+
this.seenStreams.add(stream.localId);
|
|
8586
|
+
if (stream.reconnectAttempt > 0) {
|
|
8587
|
+
this.relistenAttempts = Math.max(
|
|
8588
|
+
this.relistenAttempts,
|
|
8589
|
+
stream.reconnectAttempt
|
|
8590
|
+
);
|
|
8591
|
+
}
|
|
8592
|
+
this.deps.emit({
|
|
8593
|
+
type: "subscription.opened",
|
|
8594
|
+
localSubscriptionId: stream.localId,
|
|
8595
|
+
...stream.mcpSubscriptionId ? { subscriptionId: stream.mcpSubscriptionId } : {},
|
|
8596
|
+
era: stream.era,
|
|
8597
|
+
requestedFilter: stream.requestedFilter,
|
|
8598
|
+
rejectedInterests: stream.rejectedInterests,
|
|
8599
|
+
relistenAttempt: stream.reconnectAttempt,
|
|
8600
|
+
at: stream.openedAt
|
|
8601
|
+
});
|
|
8602
|
+
this.deps.status(
|
|
8603
|
+
stream.reconnectAttempt > 0 ? `Re-listening (attempt ${stream.reconnectAttempt}): ${describeFilter(stream.requestedFilter)}` : `Requested: ${describeFilter(stream.requestedFilter)}`
|
|
8604
|
+
);
|
|
8605
|
+
}
|
|
8606
|
+
if (stream.acknowledgedFilter && !this.acknowledged.has(stream.localId)) {
|
|
8607
|
+
this.acknowledged.add(stream.localId);
|
|
8608
|
+
this.deps.emit({
|
|
8609
|
+
type: "subscription.acknowledged",
|
|
8610
|
+
localSubscriptionId: stream.localId,
|
|
8611
|
+
...stream.mcpSubscriptionId ? { subscriptionId: stream.mcpSubscriptionId } : {},
|
|
8612
|
+
requestedFilter: stream.requestedFilter,
|
|
8613
|
+
acknowledgedFilter: stream.acknowledgedFilter,
|
|
8614
|
+
rejectedInterests: stream.rejectedInterests,
|
|
8615
|
+
at: stream.acknowledgedAt ?? this.now()
|
|
8616
|
+
});
|
|
8617
|
+
this.deps.status(
|
|
8618
|
+
`Acknowledged: ${describeFilter(stream.acknowledgedFilter)}`
|
|
8619
|
+
);
|
|
8620
|
+
}
|
|
8621
|
+
if (stream.status === "opening" || stream.status === "active" || this.closed.has(stream.localId)) {
|
|
8622
|
+
return;
|
|
8623
|
+
}
|
|
8624
|
+
this.closed.add(stream.localId);
|
|
8625
|
+
this.onStreamClosed(stream);
|
|
8626
|
+
}
|
|
8627
|
+
onStreamClosed(stream) {
|
|
8628
|
+
const outcome = stream.status === "graceful-closed" ? "graceful" : stream.status === "remote-closed" ? "remote" : stream.status === "cancelled" ? "cancelled" : "error";
|
|
8629
|
+
this.deps.emit({
|
|
8630
|
+
type: "subscription.closed",
|
|
8631
|
+
localSubscriptionId: stream.localId,
|
|
8632
|
+
...stream.mcpSubscriptionId ? { subscriptionId: stream.mcpSubscriptionId } : {},
|
|
8633
|
+
outcome,
|
|
8634
|
+
...stream.closeReason ? { closeReason: stream.closeReason } : {},
|
|
8635
|
+
...stream.error ? { error: stream.error } : {},
|
|
8636
|
+
relistenAttempt: stream.reconnectAttempt,
|
|
8637
|
+
at: stream.closedAt ?? this.now()
|
|
8638
|
+
});
|
|
8639
|
+
if (outcome === "remote") {
|
|
8640
|
+
const attempt = stream.reconnectAttempt + 1;
|
|
8641
|
+
if (attempt <= this.options.reconnect.maxAttempts) {
|
|
8642
|
+
const delayMs = relistenDelayMs(this.options.reconnect, attempt);
|
|
8643
|
+
this.relistenAttempts = Math.max(this.relistenAttempts, attempt);
|
|
8644
|
+
this.deps.emit({
|
|
8645
|
+
type: "subscription.relisten",
|
|
8646
|
+
localSubscriptionId: stream.localId,
|
|
8647
|
+
attempt,
|
|
8648
|
+
maxAttempts: this.options.reconnect.maxAttempts,
|
|
8649
|
+
delayMs,
|
|
8650
|
+
at: this.now()
|
|
8651
|
+
});
|
|
8652
|
+
this.deps.status(
|
|
8653
|
+
`Stream lost; re-listening in ${delayMs}ms (attempt ${attempt}/${this.options.reconnect.maxAttempts})`
|
|
8654
|
+
);
|
|
8655
|
+
return;
|
|
8656
|
+
}
|
|
8657
|
+
this.deps.status(
|
|
8658
|
+
this.options.reconnect.maxAttempts > 0 ? "Stream lost remotely; re-listen attempts exhausted." : "Stream lost remotely."
|
|
8659
|
+
);
|
|
8660
|
+
this.finish("remote");
|
|
8661
|
+
return;
|
|
8662
|
+
}
|
|
8663
|
+
if (outcome === "graceful") {
|
|
8664
|
+
this.deps.status("Server completed the subscription.");
|
|
8665
|
+
}
|
|
8666
|
+
this.finish(outcome, stream.error);
|
|
8667
|
+
}
|
|
8668
|
+
onNotification(event) {
|
|
8669
|
+
if (this.settled || this.stopping) return;
|
|
8670
|
+
this.notifications += 1;
|
|
8671
|
+
this.deps.emit({
|
|
8672
|
+
type: "notification",
|
|
8673
|
+
localSubscriptionId: event.localSubscriptionId,
|
|
8674
|
+
...event.subscriptionId ? { subscriptionId: event.subscriptionId } : {},
|
|
8675
|
+
method: event.method,
|
|
8676
|
+
kind: event.kind,
|
|
8677
|
+
...event.uri ? { uri: event.uri } : {},
|
|
8678
|
+
...event.params ? { params: event.params } : {},
|
|
8679
|
+
at: event.at
|
|
8680
|
+
});
|
|
8681
|
+
if (this.options.maxNotifications !== void 0 && this.notifications >= this.options.maxNotifications) {
|
|
8682
|
+
void this.stop("max-notifications");
|
|
8683
|
+
}
|
|
8684
|
+
}
|
|
8685
|
+
onRejectedNotification(event) {
|
|
8686
|
+
if (this.settled || this.stopping) return;
|
|
8687
|
+
this.rejectedNotifications += 1;
|
|
8688
|
+
this.deps.emit({
|
|
8689
|
+
type: "notification.rejected",
|
|
8690
|
+
...event.localSubscriptionId ? { localSubscriptionId: event.localSubscriptionId } : {},
|
|
8691
|
+
...event.subscriptionId ? { subscriptionId: event.subscriptionId } : {},
|
|
8692
|
+
method: event.method,
|
|
8693
|
+
reason: event.reason,
|
|
8694
|
+
at: event.at
|
|
8695
|
+
});
|
|
8696
|
+
}
|
|
8697
|
+
finish(outcome, error) {
|
|
8698
|
+
if (this.settled) return;
|
|
8699
|
+
this.settled = true;
|
|
8700
|
+
const result = {
|
|
8701
|
+
outcome,
|
|
8702
|
+
...outcome === "cancelled" && this.stopReason ? { stopReason: this.stopReason } : {},
|
|
8703
|
+
exitCode: SUBSCRIPTION_OUTCOME_EXIT_CODES[outcome],
|
|
8704
|
+
...error ? { error } : {},
|
|
8705
|
+
notifications: this.notifications,
|
|
8706
|
+
rejectedNotifications: this.rejectedNotifications,
|
|
8707
|
+
relistenAttempts: this.relistenAttempts,
|
|
8708
|
+
streams: this.seenStreams.size
|
|
8709
|
+
};
|
|
8710
|
+
this.deps.emit({ type: "summary", ...result, at: this.now() });
|
|
8711
|
+
this.resolveCompletion(result);
|
|
8712
|
+
}
|
|
8713
|
+
async safeDispose() {
|
|
8714
|
+
try {
|
|
8715
|
+
await this.coordinator.dispose();
|
|
8716
|
+
} catch {
|
|
8717
|
+
}
|
|
8718
|
+
}
|
|
8719
|
+
};
|
|
8720
|
+
|
|
8721
|
+
// src/commands/subscriptions.ts
|
|
8722
|
+
function buildDesiredInterests(options) {
|
|
8723
|
+
const all = options.listChanged === true;
|
|
8724
|
+
return {
|
|
8725
|
+
toolsListChanged: all || options.toolsListChanged === true,
|
|
8726
|
+
promptsListChanged: all || options.promptsListChanged === true,
|
|
8727
|
+
resourcesListChanged: all || options.resourcesListChanged === true,
|
|
8728
|
+
resourceUris: [...new Set(options.resourceUri ?? [])]
|
|
8729
|
+
};
|
|
8730
|
+
}
|
|
8731
|
+
function parseRelistenPolicy(options) {
|
|
8732
|
+
const maxAttempts = options.relisten ?? 0;
|
|
8733
|
+
if (maxAttempts === 0) {
|
|
8734
|
+
if (options.relistenDelayMs !== void 0 || options.relistenMaxDelayMs !== void 0) {
|
|
8735
|
+
throw usageError(
|
|
8736
|
+
"--relisten-delay-ms/--relisten-max-delay-ms require --relisten with a positive attempt count."
|
|
8737
|
+
);
|
|
8738
|
+
}
|
|
8739
|
+
return { ...DEFAULT_SUBSCRIPTION_RECONNECT_POLICY, maxAttempts: 0 };
|
|
8740
|
+
}
|
|
8741
|
+
const initialDelayMs = options.relistenDelayMs ?? DEFAULT_SUBSCRIPTION_RECONNECT_POLICY.initialDelayMs;
|
|
8742
|
+
const maxDelayMs = Math.max(
|
|
8743
|
+
initialDelayMs,
|
|
8744
|
+
options.relistenMaxDelayMs ?? DEFAULT_SUBSCRIPTION_RECONNECT_POLICY.maxDelayMs
|
|
8745
|
+
);
|
|
8746
|
+
return {
|
|
8747
|
+
...DEFAULT_SUBSCRIPTION_RECONNECT_POLICY,
|
|
8748
|
+
maxAttempts,
|
|
8749
|
+
initialDelayMs,
|
|
8750
|
+
maxDelayMs
|
|
8751
|
+
};
|
|
8752
|
+
}
|
|
8753
|
+
function listenResultError(result) {
|
|
8754
|
+
if (result.exitCode === 0) return void 0;
|
|
8755
|
+
return result.outcome === "remote" ? cliError(
|
|
8756
|
+
"SUBSCRIPTION_REMOTE_CLOSED",
|
|
8757
|
+
"The subscription stream was lost remotely (no completion result from the server).",
|
|
8758
|
+
result.exitCode,
|
|
8759
|
+
{ notifications: result.notifications, relistenAttempts: result.relistenAttempts }
|
|
8760
|
+
) : cliError(
|
|
8761
|
+
"SUBSCRIPTION_FAILED",
|
|
8762
|
+
result.error ?? "The subscription stream failed to open.",
|
|
8763
|
+
result.exitCode
|
|
8764
|
+
);
|
|
8765
|
+
}
|
|
8766
|
+
function registerSubscriptionsCommands(program) {
|
|
8767
|
+
const subscriptions = program.command("subscriptions").description(
|
|
8768
|
+
"Open a long-lived MCP subscription and stream its notifications (2026-07-28 subscriptions/listen, with a legacy fallback)"
|
|
8769
|
+
);
|
|
8770
|
+
addHostOption(
|
|
8771
|
+
addRetryOptions(
|
|
8772
|
+
addSharedServerOptions(
|
|
8773
|
+
subscriptions.command("listen").description(
|
|
8774
|
+
"Open a subscription, print the acknowledgement, and stream notifications as NDJSON on stdout until the stream closes or Ctrl-C"
|
|
8775
|
+
).option("--tools-list-changed", "Subscribe to tools/list_changed").option("--prompts-list-changed", "Subscribe to prompts/list_changed").option(
|
|
8776
|
+
"--resources-list-changed",
|
|
8777
|
+
"Subscribe to resources/list_changed"
|
|
8778
|
+
).option(
|
|
8779
|
+
"--list-changed",
|
|
8780
|
+
"Subscribe to all three list_changed notifications"
|
|
8781
|
+
).option(
|
|
8782
|
+
"--resource-uri <uri...>",
|
|
8783
|
+
"Watch a resource URI for resources/updated. Pass multiple values or repeat the flag."
|
|
8784
|
+
).option(
|
|
8785
|
+
"--relisten <count>",
|
|
8786
|
+
"After an unexpected remote loss, re-listen up to this many times with exponential backoff (0 disables)",
|
|
8787
|
+
(value) => parseNonNegativeInteger(value, "Relisten count")
|
|
8788
|
+
).option(
|
|
8789
|
+
"--relisten-delay-ms <ms>",
|
|
8790
|
+
"Initial re-listen backoff delay in milliseconds",
|
|
8791
|
+
(value) => parsePositiveInteger(value, "Relisten delay")
|
|
8792
|
+
).option(
|
|
8793
|
+
"--relisten-max-delay-ms <ms>",
|
|
8794
|
+
"Maximum re-listen backoff delay in milliseconds",
|
|
8795
|
+
(value) => parsePositiveInteger(value, "Relisten max delay")
|
|
8796
|
+
).option(
|
|
8797
|
+
"--max-notifications <count>",
|
|
8798
|
+
"Stop after this many delivered notifications",
|
|
8799
|
+
(value) => parsePositiveInteger(value, "Max notifications")
|
|
8800
|
+
).option(
|
|
8801
|
+
"--duration-ms <ms>",
|
|
8802
|
+
"Stop after this many milliseconds",
|
|
8803
|
+
(value) => parsePositiveInteger(value, "Duration")
|
|
8804
|
+
)
|
|
8805
|
+
)
|
|
8806
|
+
)
|
|
8807
|
+
).action(async (options, command) => {
|
|
8808
|
+
const globalOptions = getGlobalOptions(command);
|
|
8809
|
+
const desired = buildDesiredInterests(options);
|
|
8810
|
+
if (!hasAnyInterest(desired)) {
|
|
8811
|
+
throw usageError(
|
|
8812
|
+
"Select at least one subscription interest: --tools-list-changed, --prompts-list-changed, --resources-list-changed, --list-changed, or --resource-uri."
|
|
8813
|
+
);
|
|
8814
|
+
}
|
|
8815
|
+
const reconnect = parseRelistenPolicy(options);
|
|
8816
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
8817
|
+
const host = resolveHostFromOptions(options);
|
|
8818
|
+
const target = describeTarget(options);
|
|
8819
|
+
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
8820
|
+
const config = parseServerConfig({
|
|
8821
|
+
...options,
|
|
8822
|
+
timeout: globalOptions.timeout
|
|
8823
|
+
});
|
|
8824
|
+
const emit = (event) => {
|
|
8825
|
+
process.stdout.write(`${JSON.stringify(event)}
|
|
8826
|
+
`);
|
|
8827
|
+
};
|
|
8828
|
+
const status = (message) => {
|
|
8829
|
+
if (globalOptions.quiet) return;
|
|
8830
|
+
process.stderr.write(`${message}
|
|
8831
|
+
`);
|
|
8832
|
+
};
|
|
8833
|
+
const result = await withEphemeralManager(
|
|
8834
|
+
config,
|
|
8835
|
+
async (manager, serverId) => {
|
|
8836
|
+
const client = manager.getManagedClient(serverId);
|
|
8837
|
+
if (!client) {
|
|
8838
|
+
throw operationalError(
|
|
8839
|
+
`MCP server "${serverId}" is not connected; cannot open a subscription.`
|
|
8840
|
+
);
|
|
8841
|
+
}
|
|
8842
|
+
const session = new SubscriptionListenSession(
|
|
8843
|
+
{
|
|
8844
|
+
desired,
|
|
8845
|
+
reconnect,
|
|
8846
|
+
...options.maxNotifications !== void 0 ? { maxNotifications: options.maxNotifications } : {},
|
|
8847
|
+
...options.durationMs !== void 0 ? { durationMs: options.durationMs } : {}
|
|
8848
|
+
},
|
|
8849
|
+
{
|
|
8850
|
+
createCoordinator: (handlers) => new SubscriptionCoordinator({
|
|
8851
|
+
client,
|
|
8852
|
+
reconnect,
|
|
8853
|
+
...handlers
|
|
8854
|
+
}),
|
|
8855
|
+
emit,
|
|
8856
|
+
status
|
|
8857
|
+
}
|
|
8858
|
+
);
|
|
8859
|
+
const onSignal = () => {
|
|
8860
|
+
void session.stop("signal");
|
|
8861
|
+
};
|
|
8862
|
+
process.on("SIGINT", onSignal);
|
|
8863
|
+
process.on("SIGTERM", onSignal);
|
|
8864
|
+
try {
|
|
8865
|
+
return await session.run();
|
|
8866
|
+
} finally {
|
|
8867
|
+
process.removeListener("SIGINT", onSignal);
|
|
8868
|
+
process.removeListener("SIGTERM", onSignal);
|
|
8869
|
+
}
|
|
8870
|
+
},
|
|
8871
|
+
{
|
|
8872
|
+
timeout: globalOptions.timeout,
|
|
8873
|
+
rpcLogger: collector?.rpcLogger,
|
|
8874
|
+
retryPolicy,
|
|
8875
|
+
host: host?.connection
|
|
8876
|
+
}
|
|
8877
|
+
);
|
|
8878
|
+
const error = listenResultError(result);
|
|
8879
|
+
if (error) throw error;
|
|
8880
|
+
});
|
|
8881
|
+
}
|
|
7575
8882
|
var DEFAULT_UPDATE_PACKAGE_NAME = "@mcpjam/cli";
|
|
7576
8883
|
var UPDATE_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
7577
8884
|
var UPDATE_CACHE_FILE = "update-check.json";
|
|
@@ -8200,19 +9507,885 @@ function writeTelemetryStatus(status, format) {
|
|
|
8200
9507
|
format
|
|
8201
9508
|
);
|
|
8202
9509
|
}
|
|
8203
|
-
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
9510
|
+
var MODEL_IMMEDIATE_RESPONSE_META_KEY = "io.modelcontextprotocol/model-immediate-response";
|
|
9511
|
+
var RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
9512
|
+
var ASSERTABLE_TASKS_WIRES = ["legacy", "extension"];
|
|
9513
|
+
function parseTasksWireOption(value) {
|
|
9514
|
+
if (ASSERTABLE_TASKS_WIRES.includes(value)) {
|
|
9515
|
+
return value;
|
|
9516
|
+
}
|
|
9517
|
+
throw usageError(
|
|
9518
|
+
`Invalid wire "${value}". Use "legacy" or "extension".`
|
|
9519
|
+
);
|
|
9520
|
+
}
|
|
9521
|
+
function resolveTasksSupportOrThrow(manager, serverId, requiredWire) {
|
|
9522
|
+
const support = manager.getTasksSupport(serverId);
|
|
9523
|
+
if (support.wire === "none") {
|
|
9524
|
+
throw cliError(
|
|
9525
|
+
"TASKS_UNSUPPORTED",
|
|
9526
|
+
"This server does not support MCP Tasks on either wire: it neither declares `capabilities.tasks` on 2025-11-25 nor the `io.modelcontextprotocol/tasks` extension on 2026-07-28.",
|
|
9527
|
+
1,
|
|
9528
|
+
{ wire: support.wire }
|
|
9529
|
+
);
|
|
9530
|
+
}
|
|
9531
|
+
if (requiredWire && support.wire !== requiredWire) {
|
|
9532
|
+
throw cliError(
|
|
9533
|
+
"TASKS_WIRE_MISMATCH",
|
|
9534
|
+
`--wire ${requiredWire} was asserted, but this connection resolved to the ${support.wire} wire.`,
|
|
9535
|
+
1,
|
|
9536
|
+
{ requestedWire: requiredWire, wire: support.wire }
|
|
9537
|
+
);
|
|
9538
|
+
}
|
|
9539
|
+
return support;
|
|
9540
|
+
}
|
|
9541
|
+
var CAPABILITY_LABELS = {
|
|
9542
|
+
list: "tasks/list",
|
|
9543
|
+
cancel: "tasks/cancel",
|
|
9544
|
+
update: "tasks/update",
|
|
9545
|
+
toolCalls: "task-augmented tools/call"
|
|
9546
|
+
};
|
|
9547
|
+
function assertWireCapability(support, capability, hint) {
|
|
9548
|
+
if (support[capability]) return;
|
|
9549
|
+
throw cliError(
|
|
9550
|
+
"TASKS_UNSUPPORTED",
|
|
9551
|
+
`${CAPABILITY_LABELS[capability]} is not available on the ${support.wire} wire. ${hint}`,
|
|
9552
|
+
1,
|
|
9553
|
+
{ wire: support.wire, capability }
|
|
9554
|
+
);
|
|
9555
|
+
}
|
|
9556
|
+
function taskUnknownError(taskId) {
|
|
9557
|
+
return cliError(
|
|
9558
|
+
"TASK_UNKNOWN_OR_EXPIRED",
|
|
9559
|
+
`The server does not know task "${taskId}". It was never created, or its TTL elapsed and the server dropped it.`,
|
|
9560
|
+
1,
|
|
9561
|
+
{ taskId }
|
|
9562
|
+
);
|
|
9563
|
+
}
|
|
9564
|
+
async function getTaskForWire(manager, serverId, taskId, support) {
|
|
9565
|
+
try {
|
|
9566
|
+
const task = support.wire === "extension" ? await manager.getTaskExt(serverId, taskId) : await manager.getTask(serverId, taskId);
|
|
9567
|
+
return { wire: support.wire, task };
|
|
9568
|
+
} catch (error) {
|
|
9569
|
+
if (isUnknownTaskError(error)) throw taskUnknownError(taskId);
|
|
9570
|
+
throw error;
|
|
9571
|
+
}
|
|
9572
|
+
}
|
|
9573
|
+
function asRecord2(value) {
|
|
9574
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
9575
|
+
}
|
|
9576
|
+
function modelImmediateResponseOf(result) {
|
|
9577
|
+
return asRecord2(asRecord2(result)?._meta)?.[MODEL_IMMEDIATE_RESPONSE_META_KEY];
|
|
9578
|
+
}
|
|
9579
|
+
function detectCreatedTask(wire, result) {
|
|
9580
|
+
if (wire === "none") return null;
|
|
9581
|
+
const body = asRecord2(result);
|
|
9582
|
+
if (!body) return null;
|
|
9583
|
+
const task = wire === "extension" ? body : asRecord2(body.task);
|
|
9584
|
+
if (!task) return null;
|
|
9585
|
+
if (wire === "extension") {
|
|
9586
|
+
if (task.resultType !== "task") return null;
|
|
9587
|
+
} else if (typeof task.status !== "string" || !LEGACY_TASK_STATUSES.has(task.status)) {
|
|
9588
|
+
return null;
|
|
9589
|
+
}
|
|
9590
|
+
const taskId = task.taskId;
|
|
9591
|
+
if (typeof taskId !== "string" || taskId.length === 0) return null;
|
|
9592
|
+
return {
|
|
9593
|
+
status: "task_created",
|
|
9594
|
+
wire,
|
|
9595
|
+
task,
|
|
9596
|
+
...withModelImmediateResponse(result)
|
|
9597
|
+
};
|
|
9598
|
+
}
|
|
9599
|
+
function withModelImmediateResponse(result) {
|
|
9600
|
+
const value = modelImmediateResponseOf(result);
|
|
9601
|
+
return value === void 0 ? {} : { modelImmediateResponse: value };
|
|
9602
|
+
}
|
|
9603
|
+
function taskWatchExitCode(outcome) {
|
|
9604
|
+
switch (outcome) {
|
|
9605
|
+
case "completed":
|
|
9606
|
+
return 0;
|
|
9607
|
+
case "input-required":
|
|
9608
|
+
return 6;
|
|
9609
|
+
case "timeout":
|
|
9610
|
+
return 7;
|
|
9611
|
+
case "aborted":
|
|
9612
|
+
return 130;
|
|
9613
|
+
case "failed":
|
|
9614
|
+
case "cancelled":
|
|
9615
|
+
case "expired":
|
|
9616
|
+
case "unreachable":
|
|
9617
|
+
return 1;
|
|
9618
|
+
}
|
|
9619
|
+
}
|
|
9620
|
+
function describeError(error) {
|
|
9621
|
+
if (error === void 0 || error === null) return void 0;
|
|
9622
|
+
if (error instanceof Error) return { message: error.message };
|
|
9623
|
+
if (typeof error === "string") return { message: error };
|
|
9624
|
+
try {
|
|
9625
|
+
return { message: JSON.stringify(error) ?? String(error) };
|
|
9626
|
+
} catch {
|
|
9627
|
+
return { message: String(error) };
|
|
9628
|
+
}
|
|
9629
|
+
}
|
|
9630
|
+
async function driveTaskWatch(args) {
|
|
9631
|
+
const { manager, serverId, support, taskId } = args;
|
|
9632
|
+
if (support.wire === "none") {
|
|
9633
|
+
throw cliError(
|
|
9634
|
+
"TASKS_UNSUPPORTED",
|
|
9635
|
+
"Cannot watch a task on a server with no tasks wire.",
|
|
9636
|
+
1
|
|
9637
|
+
);
|
|
9638
|
+
}
|
|
9639
|
+
const identity = {
|
|
9640
|
+
serverId,
|
|
9641
|
+
wire: support.wire,
|
|
9642
|
+
taskId
|
|
9643
|
+
};
|
|
9644
|
+
const engine = new TaskLifecycleEngine();
|
|
9645
|
+
if (args.tuning?.pollIntervalMs !== void 0) {
|
|
9646
|
+
engine.setUserMinimumIntervalMs(args.tuning.pollIntervalMs);
|
|
9647
|
+
}
|
|
9648
|
+
const extension = support.wire === "extension";
|
|
9649
|
+
const result = await driveTaskToTerminal({
|
|
9650
|
+
identity,
|
|
9651
|
+
engine,
|
|
9652
|
+
getTask: async () => extension ? extensionTaskToObservation(await manager.getTaskExt(serverId, taskId)) : legacyTaskToObservation(
|
|
9653
|
+
await manager.getTask(serverId, taskId)
|
|
9654
|
+
),
|
|
9655
|
+
// Extension results are inline on `tasks/get`; the legacy wire has no
|
|
9656
|
+
// payload at all without this second call, and the driver reports a
|
|
9657
|
+
// completed-but-empty watch as an error rather than inventing one.
|
|
9658
|
+
...extension ? {} : {
|
|
9659
|
+
getResult: async () => await manager.getTaskResult(serverId, taskId)
|
|
9660
|
+
},
|
|
9661
|
+
// Extension only, and not an omission: `tasks/update` does not exist on
|
|
9662
|
+
// 2025-11-25, which is why `TasksSupport.update` is hard-`false` for that
|
|
9663
|
+
// wire. A legacy task's input arrives out of band as an `elicitation/create`
|
|
9664
|
+
// stamped with `relatedTaskId` and its `Task` carries no `inputRequests`, so
|
|
9665
|
+
// the poll loop has nothing to answer and nothing to answer it with. The
|
|
9666
|
+
// driver reports `input_required` there deliberately rather than re-reading
|
|
9667
|
+
// an unchanging status until the deadline — a deterministic exit 6 beats a
|
|
9668
|
+
// timeout that looks like a hang.
|
|
9669
|
+
...extension ? {
|
|
9670
|
+
updateTask: async (_identity, inputResponses) => {
|
|
9671
|
+
await manager.updateTask(serverId, taskId, inputResponses);
|
|
9672
|
+
}
|
|
9673
|
+
} : {},
|
|
9674
|
+
...args.input ? { input: args.input } : {},
|
|
9675
|
+
...args.tuning?.durationMs !== void 0 ? { timeoutMs: args.tuning.durationMs } : {},
|
|
9676
|
+
...args.tuning?.maxInputRounds !== void 0 ? { maxInputRounds: args.tuning.maxInputRounds } : {},
|
|
9677
|
+
...args.tuning?.maxConsecutiveErrors !== void 0 ? { maxConsecutiveErrors: args.tuning.maxConsecutiveErrors } : {},
|
|
9678
|
+
...args.signal ? { signal: args.signal } : {},
|
|
9679
|
+
...args.onState ? { onState: args.onState } : {}
|
|
9680
|
+
});
|
|
9681
|
+
const lastError = describeError(result.lastError);
|
|
9682
|
+
return {
|
|
9683
|
+
outcome: abortedDuringResultFetch({
|
|
9684
|
+
aborted: args.signal?.aborted === true,
|
|
9685
|
+
outcome: result.outcome,
|
|
9686
|
+
hasLastError: result.lastError !== void 0,
|
|
9687
|
+
hasResult: result.task?.result !== void 0
|
|
9688
|
+
}) ? "aborted" : result.outcome,
|
|
9689
|
+
wire: support.wire,
|
|
9690
|
+
taskId,
|
|
9691
|
+
...result.task ? { task: result.task } : {},
|
|
9692
|
+
...result.unansweredInput?.length ? { unansweredInput: result.unansweredInput } : {},
|
|
9693
|
+
...lastError ? { lastError } : {}
|
|
9694
|
+
};
|
|
9695
|
+
}
|
|
9696
|
+
function abortedDuringResultFetch(args) {
|
|
9697
|
+
return args.aborted && args.outcome === "completed" && args.hasLastError && !args.hasResult;
|
|
9698
|
+
}
|
|
9699
|
+
function buildTaskInputDriverOptions(args) {
|
|
9700
|
+
if (args.interactive !== true) return void 0;
|
|
9701
|
+
const nonInteractive = resolveNonInteractive({
|
|
9702
|
+
yes: args.yes,
|
|
9703
|
+
stdinIsTTY: args.stdinIsTTY ?? Boolean(process.stdin.isTTY),
|
|
9704
|
+
...args.env ? { env: args.env } : {}
|
|
9705
|
+
});
|
|
9706
|
+
const resolved = applyInteractiveElicitationCapability(args.config);
|
|
9707
|
+
const declaredCapabilities = resolved.clientCapabilities ?? resolved.capabilities;
|
|
9708
|
+
const handlers = {
|
|
9709
|
+
// Built per invocation rather than once, so each call can be given ITS
|
|
9710
|
+
// context's `signal`. A terminal prompt is the one place a watch can block
|
|
9711
|
+
// indefinitely, and without the signal reaching `readline` a Ctrl-C during
|
|
9712
|
+
// the prompt would leave the drive stuck instead of producing the
|
|
9713
|
+
// documented `aborted` outcome.
|
|
9714
|
+
//
|
|
9715
|
+
// The cast is the seam between two descriptions of the same
|
|
9716
|
+
// `elicitation/create` params: the task input driver hands over an opaque
|
|
9717
|
+
// record because it has already validated the request shape and the
|
|
9718
|
+
// declared mode before dispatching, while the standalone handler is typed
|
|
9719
|
+
// against the narrowed union.
|
|
9720
|
+
elicitation: (params, ctx) => createStdinElicitationHandler({
|
|
9721
|
+
nonInteractive,
|
|
9722
|
+
...ctx?.signal ? { signal: ctx.signal } : {},
|
|
9723
|
+
...args.collectorOptions
|
|
9724
|
+
})(params)
|
|
9725
|
+
};
|
|
9726
|
+
const declaration = canDeclareTasksExtension(
|
|
9727
|
+
declaredCapabilities,
|
|
9728
|
+
handlers
|
|
9729
|
+
);
|
|
9730
|
+
if (!declaration.ok) {
|
|
9731
|
+
throw usageError(
|
|
9732
|
+
`--interactive cannot answer a task's embedded input on this connection: it advertises ${declaration.missing.join(", ")} with no handler behind it, so a task requesting one would never be answered. Drop the capability from --client-capabilities/--host, or drop --interactive and answer with \`mcpjam tasks update\`.`,
|
|
9733
|
+
{ missing: declaration.missing }
|
|
9734
|
+
);
|
|
9735
|
+
}
|
|
9736
|
+
return {
|
|
9737
|
+
declaredCapabilities,
|
|
9738
|
+
handlers,
|
|
9739
|
+
// The same strict, dialect-aware self-validation the standalone MRTR path
|
|
9740
|
+
// applies (the manager's `mrtrElicitationContentValidator` is built from
|
|
9741
|
+
// this same factory). Without it, an accepted answer that violates the
|
|
9742
|
+
// request's `requestedSchema` would be submitted via `tasks/update` here
|
|
9743
|
+
// while the interactive path refuses the identical answer.
|
|
9744
|
+
validateElicitationContent: createStrictElicitationContentValidator()
|
|
9745
|
+
};
|
|
9746
|
+
}
|
|
9747
|
+
|
|
9748
|
+
// src/commands/tasks.ts
|
|
9749
|
+
var TASKS_CHECK_IDS_BY_CATEGORY = {
|
|
9750
|
+
dispatch: ["tasks-wire-resolvable", "tasks-declaration-hygiene"],
|
|
9751
|
+
creation: [
|
|
9752
|
+
"tasks-result-type-discipline",
|
|
9753
|
+
"tasks-undeclared-creation-refused"
|
|
9754
|
+
],
|
|
9755
|
+
lifecycle: [
|
|
9756
|
+
"tasks-ttl-shape",
|
|
9757
|
+
"tasks-inline-result",
|
|
9758
|
+
"tasks-mcp-name-routing",
|
|
9759
|
+
"tasks-undeclared-capability-rejected"
|
|
9760
|
+
]
|
|
9761
|
+
};
|
|
9762
|
+
function tasksConformanceExitCode(result) {
|
|
9763
|
+
if (result.outcome === "incomplete") return 3;
|
|
9764
|
+
if (result.outcome === "failed") return 1;
|
|
9765
|
+
return result.passed ? 0 : 1;
|
|
9766
|
+
}
|
|
9767
|
+
function collectInvalidEntries3(values, allowed) {
|
|
9768
|
+
return (values ?? []).filter((value) => !allowed.includes(value));
|
|
9769
|
+
}
|
|
9770
|
+
function buildTasksConformanceConfig(options) {
|
|
9771
|
+
const serverConfig = parseServerConfig(options);
|
|
9772
|
+
const categories = options.category?.filter(Boolean);
|
|
9773
|
+
const invalidCategories = collectInvalidEntries3(
|
|
9774
|
+
categories,
|
|
9775
|
+
MCP_TASKS_CHECK_CATEGORIES
|
|
9776
|
+
);
|
|
9777
|
+
if (invalidCategories.length > 0) {
|
|
9778
|
+
throw usageError(
|
|
9779
|
+
invalidCategories.length === 1 ? `Unknown category: ${invalidCategories[0]}` : `Unknown categories: ${invalidCategories.join(", ")}`
|
|
9780
|
+
);
|
|
9781
|
+
}
|
|
9782
|
+
const checkIds = options.checkId?.filter(Boolean);
|
|
9783
|
+
const invalidCheckIds = collectInvalidEntries3(checkIds, MCP_TASKS_CHECK_IDS);
|
|
9784
|
+
if (invalidCheckIds.length > 0) {
|
|
9785
|
+
throw usageError(
|
|
9786
|
+
`Unknown check id${invalidCheckIds.length === 1 ? "" : "s"}: ${invalidCheckIds.join(", ")}`
|
|
9787
|
+
);
|
|
9788
|
+
}
|
|
9789
|
+
const resolvedCheckIds = checkIds && checkIds.length > 0 ? checkIds : categories && categories.length > 0 ? Array.from(
|
|
9790
|
+
new Set(
|
|
9791
|
+
categories.flatMap(
|
|
9792
|
+
(category) => TASKS_CHECK_IDS_BY_CATEGORY[category]
|
|
8209
9793
|
)
|
|
8210
9794
|
)
|
|
9795
|
+
) : void 0;
|
|
9796
|
+
return {
|
|
9797
|
+
...serverConfig,
|
|
9798
|
+
...resolvedCheckIds && resolvedCheckIds.length > 0 ? { checkIds: resolvedCheckIds } : {},
|
|
9799
|
+
...options.toolName ? { toolName: options.toolName } : {},
|
|
9800
|
+
...options.toolArgs ? { toolArguments: parseJsonRecord(options.toolArgs, "--tool-args") } : {},
|
|
9801
|
+
...options.pollTimeout ? { pollTimeoutMs: options.pollTimeout } : {}
|
|
9802
|
+
};
|
|
9803
|
+
}
|
|
9804
|
+
function requireTaskId(options) {
|
|
9805
|
+
if (!options.taskId) {
|
|
9806
|
+
throw usageError("--task-id is required.");
|
|
9807
|
+
}
|
|
9808
|
+
return options.taskId;
|
|
9809
|
+
}
|
|
9810
|
+
async function runTaskVerb(options, command, fn, verbOptions = {}) {
|
|
9811
|
+
const globalOptions = getGlobalOptions(command);
|
|
9812
|
+
const taskId = verbOptions.requiresTaskId === false ? "" : requireTaskId(options);
|
|
9813
|
+
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: describeTarget(options) }) : void 0;
|
|
9814
|
+
const note = (message) => {
|
|
9815
|
+
if (!globalOptions.quiet) process.stderr.write(`${message}
|
|
9816
|
+
`);
|
|
9817
|
+
};
|
|
9818
|
+
const config = parseServerConfig({ ...options, timeout: globalOptions.timeout });
|
|
9819
|
+
const result = await withEphemeralManager(
|
|
9820
|
+
config,
|
|
9821
|
+
async (manager, serverId) => {
|
|
9822
|
+
const support = resolveTasksSupportOrThrow(manager, serverId, options.wire);
|
|
9823
|
+
return fn({ manager, serverId, support, taskId, globalOptions, note });
|
|
9824
|
+
},
|
|
9825
|
+
{ timeout: globalOptions.timeout, rpcLogger: collector?.rpcLogger }
|
|
9826
|
+
);
|
|
9827
|
+
writeResult(
|
|
9828
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
9829
|
+
globalOptions.format
|
|
9830
|
+
);
|
|
9831
|
+
}
|
|
9832
|
+
function addTaskIdOption(command) {
|
|
9833
|
+
return command.option("--task-id <id>", "The task to act on");
|
|
9834
|
+
}
|
|
9835
|
+
function addWireOption(command) {
|
|
9836
|
+
return command.option(
|
|
9837
|
+
"--wire <wire>",
|
|
9838
|
+
"Assert the connection resolves to this tasks wire: legacy or extension",
|
|
9839
|
+
parseTasksWireOption
|
|
9840
|
+
);
|
|
9841
|
+
}
|
|
9842
|
+
function registerTaskVerbs(tasks) {
|
|
9843
|
+
addSharedServerOptions(
|
|
9844
|
+
tasks.command("capabilities").description(
|
|
9845
|
+
"Report the tasks wire this connection resolves to and which task verbs it carries. Always exits 0 \u2014 branch on `.wire`."
|
|
9846
|
+
)
|
|
8211
9847
|
).action(async (options, command) => {
|
|
8212
9848
|
const globalOptions = getGlobalOptions(command);
|
|
8213
|
-
const
|
|
8214
|
-
const
|
|
8215
|
-
|
|
9849
|
+
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: describeTarget(options) }) : void 0;
|
|
9850
|
+
const config = parseServerConfig({
|
|
9851
|
+
...options,
|
|
9852
|
+
timeout: globalOptions.timeout
|
|
9853
|
+
});
|
|
9854
|
+
const support = await withEphemeralManager(
|
|
9855
|
+
config,
|
|
9856
|
+
async (manager, serverId) => manager.getTasksSupport(serverId),
|
|
9857
|
+
{ timeout: globalOptions.timeout, rpcLogger: collector?.rpcLogger }
|
|
9858
|
+
);
|
|
9859
|
+
writeResult(
|
|
9860
|
+
withRpcLogsIfRequested(support, collector, globalOptions),
|
|
9861
|
+
globalOptions.format
|
|
9862
|
+
);
|
|
9863
|
+
});
|
|
9864
|
+
addSharedServerOptions(
|
|
9865
|
+
addWireOption(
|
|
9866
|
+
tasks.command("list").description("List tasks the server is tracking (legacy wire only)").option("--cursor <cursor>", "Pagination cursor")
|
|
9867
|
+
)
|
|
9868
|
+
).action(
|
|
9869
|
+
(options, command) => runTaskVerb(
|
|
9870
|
+
options,
|
|
9871
|
+
command,
|
|
9872
|
+
async ({ manager, serverId, support, note }) => {
|
|
9873
|
+
if (support.wire === "extension") {
|
|
9874
|
+
note(
|
|
9875
|
+
"Note: SEP-2663 removed tasks/list \u2014 a server cannot enumerate tasks for you on the extension wire, so this is always empty. Track task ids from `tools call --task` instead."
|
|
9876
|
+
);
|
|
9877
|
+
} else {
|
|
9878
|
+
assertWireCapability(
|
|
9879
|
+
support,
|
|
9880
|
+
"list",
|
|
9881
|
+
"The server did not declare `capabilities.tasks.list`."
|
|
9882
|
+
);
|
|
9883
|
+
}
|
|
9884
|
+
const result = await manager.listTasks(serverId, options.cursor);
|
|
9885
|
+
return { ...result, wire: support.wire };
|
|
9886
|
+
},
|
|
9887
|
+
{ requiresTaskId: false }
|
|
9888
|
+
)
|
|
9889
|
+
);
|
|
9890
|
+
addSharedServerOptions(
|
|
9891
|
+
addWireOption(
|
|
9892
|
+
addTaskIdOption(
|
|
9893
|
+
tasks.command("get").description("Read one task's current state")
|
|
9894
|
+
)
|
|
9895
|
+
)
|
|
9896
|
+
).action(
|
|
9897
|
+
(options, command) => runTaskVerb(
|
|
9898
|
+
options,
|
|
9899
|
+
command,
|
|
9900
|
+
({ manager, serverId, support, taskId }) => getTaskForWire(manager, serverId, taskId, support)
|
|
9901
|
+
)
|
|
9902
|
+
);
|
|
9903
|
+
addSharedServerOptions(
|
|
9904
|
+
addWireOption(
|
|
9905
|
+
addTaskIdOption(
|
|
9906
|
+
tasks.command("result").description(
|
|
9907
|
+
"Read a completed task's result (legacy wire only \u2014 extension results are inline on `tasks get`)"
|
|
9908
|
+
)
|
|
9909
|
+
)
|
|
9910
|
+
)
|
|
9911
|
+
).action(
|
|
9912
|
+
(options, command) => runTaskVerb(options, command, async ({ manager, serverId, support, taskId }) => {
|
|
9913
|
+
try {
|
|
9914
|
+
const result = await manager.getTaskResult(serverId, taskId);
|
|
9915
|
+
if (result && typeof result === "object") {
|
|
9916
|
+
const meta = result._meta ?? {};
|
|
9917
|
+
result._meta = { ...meta, [RELATED_TASK_META_KEY]: { taskId } };
|
|
9918
|
+
}
|
|
9919
|
+
return result;
|
|
9920
|
+
} catch (error) {
|
|
9921
|
+
if (isUnknownTaskError(error)) throw taskUnknownError(taskId);
|
|
9922
|
+
if (isMCPTasksWireError(error)) {
|
|
9923
|
+
throw cliError(
|
|
9924
|
+
"TASKS_UNSUPPORTED",
|
|
9925
|
+
"tasks/result exists only on the 2025-11-25 wire. This server resolved to the extension wire, where a completed task carries its result inline \u2014 use `mcpjam tasks get` instead.",
|
|
9926
|
+
1,
|
|
9927
|
+
{ wire: support.wire }
|
|
9928
|
+
);
|
|
9929
|
+
}
|
|
9930
|
+
throw error;
|
|
9931
|
+
}
|
|
9932
|
+
})
|
|
9933
|
+
);
|
|
9934
|
+
addSharedServerOptions(
|
|
9935
|
+
addWireOption(
|
|
9936
|
+
addTaskIdOption(
|
|
9937
|
+
tasks.command("cancel").description("Request cancellation of a task")
|
|
9938
|
+
)
|
|
9939
|
+
)
|
|
9940
|
+
).action(
|
|
9941
|
+
(options, command) => runTaskVerb(
|
|
9942
|
+
options,
|
|
9943
|
+
command,
|
|
9944
|
+
async ({ manager, serverId, support, taskId, note }) => {
|
|
9945
|
+
assertWireCapability(
|
|
9946
|
+
support,
|
|
9947
|
+
"cancel",
|
|
9948
|
+
"The server did not declare `capabilities.tasks.cancel`."
|
|
9949
|
+
);
|
|
9950
|
+
try {
|
|
9951
|
+
if (support.wire === "extension") {
|
|
9952
|
+
await manager.cancelTaskExt(serverId, taskId);
|
|
9953
|
+
note(
|
|
9954
|
+
"Cancellation requested. SEP-2663 cancellation is cooperative and the ack is empty: the task may still be running, and may still reach `completed`. Re-poll with `mcpjam tasks get`."
|
|
9955
|
+
);
|
|
9956
|
+
return { wire: support.wire, task: null, cooperative: true };
|
|
9957
|
+
}
|
|
9958
|
+
const task = await manager.cancelTask(serverId, taskId);
|
|
9959
|
+
return { wire: support.wire, task };
|
|
9960
|
+
} catch (error) {
|
|
9961
|
+
if (isUnknownTaskError(error)) throw taskUnknownError(taskId);
|
|
9962
|
+
throw error;
|
|
9963
|
+
}
|
|
9964
|
+
}
|
|
9965
|
+
)
|
|
9966
|
+
);
|
|
9967
|
+
addSharedServerOptions(
|
|
9968
|
+
addWireOption(
|
|
9969
|
+
addTaskIdOption(
|
|
9970
|
+
tasks.command("update").description(
|
|
9971
|
+
"Answer a task's `input_required` requests (extension wire only)"
|
|
9972
|
+
).option(
|
|
9973
|
+
"--input-responses <json>",
|
|
9974
|
+
"Responses keyed by input key, as a JSON object, @path, or - for stdin"
|
|
9975
|
+
)
|
|
9976
|
+
)
|
|
9977
|
+
)
|
|
9978
|
+
).action(
|
|
9979
|
+
(options, command) => runTaskVerb(
|
|
9980
|
+
options,
|
|
9981
|
+
command,
|
|
9982
|
+
async ({ manager, serverId, support, taskId, note }) => {
|
|
9983
|
+
assertWireCapability(
|
|
9984
|
+
support,
|
|
9985
|
+
"update",
|
|
9986
|
+
"tasks/update is part of the io.modelcontextprotocol/tasks extension; the 2025-11-25 wire answers task input out of band via elicitation instead."
|
|
9987
|
+
);
|
|
9988
|
+
if (!options.inputResponses) {
|
|
9989
|
+
throw usageError("--input-responses is required for `tasks update`.");
|
|
9990
|
+
}
|
|
9991
|
+
const responses = parseJsonRecord(
|
|
9992
|
+
options.inputResponses,
|
|
9993
|
+
"--input-responses"
|
|
9994
|
+
);
|
|
9995
|
+
if (!responses) {
|
|
9996
|
+
throw usageError("--input-responses must be a JSON object.");
|
|
9997
|
+
}
|
|
9998
|
+
try {
|
|
9999
|
+
const ack = await manager.updateTask(
|
|
10000
|
+
serverId,
|
|
10001
|
+
taskId,
|
|
10002
|
+
responses
|
|
10003
|
+
);
|
|
10004
|
+
note(
|
|
10005
|
+
"Responses accepted. The ack is empty by design \u2014 the task's status does not move until a later `mcpjam tasks get`."
|
|
10006
|
+
);
|
|
10007
|
+
return { wire: support.wire, ack };
|
|
10008
|
+
} catch (error) {
|
|
10009
|
+
if (!isUnknownTaskError(error)) throw error;
|
|
10010
|
+
let provenUnknown = false;
|
|
10011
|
+
try {
|
|
10012
|
+
await manager.getTaskExt(serverId, taskId);
|
|
10013
|
+
} catch (confirmation) {
|
|
10014
|
+
provenUnknown = isUnknownTaskError(confirmation);
|
|
10015
|
+
}
|
|
10016
|
+
throw provenUnknown ? taskUnknownError(taskId) : error;
|
|
10017
|
+
}
|
|
10018
|
+
}
|
|
10019
|
+
)
|
|
10020
|
+
);
|
|
10021
|
+
}
|
|
10022
|
+
function addTaskWatchTuningOptions(command) {
|
|
10023
|
+
return command.option(
|
|
10024
|
+
"--duration-ms <ms>",
|
|
10025
|
+
"How long to keep watching before giving up",
|
|
10026
|
+
(value) => parsePositiveInteger(value, "Duration")
|
|
10027
|
+
).option(
|
|
10028
|
+
"--poll-interval-ms <ms>",
|
|
10029
|
+
"Your minimum interval between polls. The server's pollIntervalMs, any Retry-After, and error backoff still apply as floors on top of it.",
|
|
10030
|
+
(value) => parsePositiveInteger(value, "Poll interval")
|
|
10031
|
+
).option(
|
|
10032
|
+
"--max-input-rounds <n>",
|
|
10033
|
+
"Give up after this many input_required rounds",
|
|
10034
|
+
(value) => parsePositiveInteger(value, "Max input rounds")
|
|
10035
|
+
).option(
|
|
10036
|
+
"--max-consecutive-errors <n>",
|
|
10037
|
+
"Give up after this many consecutive failed reads",
|
|
10038
|
+
(value) => parsePositiveInteger(value, "Max consecutive errors")
|
|
10039
|
+
);
|
|
10040
|
+
}
|
|
10041
|
+
function addWatchInteractivityOptions(command) {
|
|
10042
|
+
return command.option("--interactive", "Answer the task's input requests from the terminal").option("--yes", "Never prompt; a task that needs input exits 6");
|
|
10043
|
+
}
|
|
10044
|
+
function taskWatchTuningFrom(options) {
|
|
10045
|
+
return {
|
|
10046
|
+
...options.durationMs !== void 0 ? { durationMs: options.durationMs } : {},
|
|
10047
|
+
...options.pollIntervalMs !== void 0 ? { pollIntervalMs: options.pollIntervalMs } : {},
|
|
10048
|
+
...options.maxInputRounds !== void 0 ? { maxInputRounds: options.maxInputRounds } : {},
|
|
10049
|
+
...options.maxConsecutiveErrors !== void 0 ? { maxConsecutiveErrors: options.maxConsecutiveErrors } : {}
|
|
10050
|
+
};
|
|
10051
|
+
}
|
|
10052
|
+
async function withWatchSignals(fn) {
|
|
10053
|
+
const controller = new AbortController();
|
|
10054
|
+
const onSignal = () => controller.abort();
|
|
10055
|
+
process.on("SIGINT", onSignal);
|
|
10056
|
+
process.on("SIGTERM", onSignal);
|
|
10057
|
+
try {
|
|
10058
|
+
return await fn(controller.signal);
|
|
10059
|
+
} finally {
|
|
10060
|
+
process.removeListener("SIGINT", onSignal);
|
|
10061
|
+
process.removeListener("SIGTERM", onSignal);
|
|
10062
|
+
}
|
|
10063
|
+
}
|
|
10064
|
+
function watchStateReporter(globalOptions) {
|
|
10065
|
+
if (globalOptions.quiet) return void 0;
|
|
10066
|
+
let last;
|
|
10067
|
+
return (snapshot) => {
|
|
10068
|
+
if (snapshot.status === last) return;
|
|
10069
|
+
last = snapshot.status;
|
|
10070
|
+
const detail = snapshot.statusMessage ? ` \u2014 ${sanitizeTerminalText(snapshot.statusMessage)}` : "";
|
|
10071
|
+
process.stderr.write(
|
|
10072
|
+
`task: ${sanitizeTerminalText(snapshot.status)}${detail}
|
|
10073
|
+
`
|
|
10074
|
+
);
|
|
10075
|
+
};
|
|
10076
|
+
}
|
|
10077
|
+
function registerTaskWatch(tasks) {
|
|
10078
|
+
addSharedServerOptions(
|
|
10079
|
+
addWatchInteractivityOptions(
|
|
10080
|
+
addTaskWatchTuningOptions(
|
|
10081
|
+
addWireOption(
|
|
10082
|
+
addTaskIdOption(
|
|
10083
|
+
tasks.command("watch").description(
|
|
10084
|
+
"Poll a task until it reaches a terminal status. Exit codes: 0 completed (including a tool-level isError result), 6 input_required, 7 timed out, 130 interrupted, 1 otherwise. The host tasks policy is not consulted \u2014 this is a debugging affordance, like the Inspector's Tools tab."
|
|
10085
|
+
)
|
|
10086
|
+
)
|
|
10087
|
+
)
|
|
10088
|
+
)
|
|
10089
|
+
)
|
|
10090
|
+
).action(async (options, command) => {
|
|
10091
|
+
const globalOptions = getGlobalOptions(command);
|
|
10092
|
+
const taskId = requireTaskId(options);
|
|
10093
|
+
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: describeTarget(options) }) : void 0;
|
|
10094
|
+
const config = parseServerConfig({
|
|
10095
|
+
...options,
|
|
10096
|
+
timeout: globalOptions.timeout
|
|
10097
|
+
});
|
|
10098
|
+
const input = buildTaskInputDriverOptions({
|
|
10099
|
+
config,
|
|
10100
|
+
interactive: options.interactive,
|
|
10101
|
+
yes: options.yes
|
|
10102
|
+
});
|
|
10103
|
+
const onState = watchStateReporter(globalOptions);
|
|
10104
|
+
const envelope = await withEphemeralManager(
|
|
10105
|
+
config,
|
|
10106
|
+
async (manager, serverId) => {
|
|
10107
|
+
const support = resolveTasksSupportOrThrow(
|
|
10108
|
+
manager,
|
|
10109
|
+
serverId,
|
|
10110
|
+
options.wire
|
|
10111
|
+
);
|
|
10112
|
+
return withWatchSignals(
|
|
10113
|
+
(signal) => driveTaskWatch({
|
|
10114
|
+
manager,
|
|
10115
|
+
serverId,
|
|
10116
|
+
support,
|
|
10117
|
+
taskId,
|
|
10118
|
+
tuning: taskWatchTuningFrom(options),
|
|
10119
|
+
...input ? { input } : {},
|
|
10120
|
+
signal,
|
|
10121
|
+
...onState ? { onState } : {}
|
|
10122
|
+
})
|
|
10123
|
+
);
|
|
10124
|
+
},
|
|
10125
|
+
{
|
|
10126
|
+
timeout: globalOptions.timeout,
|
|
10127
|
+
rpcLogger: collector?.rpcLogger,
|
|
10128
|
+
// On the legacy wire a task's `input_required` surfaces as an
|
|
10129
|
+
// out-of-band `elicitation/create` stamped with the task id, not as
|
|
10130
|
+
// data on `tasks/get`. Registering the terminal handler is the only
|
|
10131
|
+
// way a single invocation can answer it.
|
|
10132
|
+
...options.interactive ? {
|
|
10133
|
+
beforeConnect: buildMrtrBeforeConnect(options),
|
|
10134
|
+
interactiveElicitation: true
|
|
10135
|
+
} : {}
|
|
10136
|
+
}
|
|
10137
|
+
);
|
|
10138
|
+
writeResult(
|
|
10139
|
+
withRpcLogsIfRequested(envelope, collector, globalOptions),
|
|
10140
|
+
globalOptions.format
|
|
10141
|
+
);
|
|
10142
|
+
const exitCode = taskWatchExitCode(envelope.outcome);
|
|
10143
|
+
if (exitCode !== 0) setProcessExitCode(exitCode);
|
|
10144
|
+
});
|
|
10145
|
+
}
|
|
10146
|
+
function registerTasksCommands(program) {
|
|
10147
|
+
const tasks = program.command("tasks").description(
|
|
10148
|
+
"Create, inspect and drive MCP Tasks (legacy 2025-11-25 and SEP-2663), and validate a server's tasks wire behavior"
|
|
10149
|
+
);
|
|
10150
|
+
registerTaskVerbs(tasks);
|
|
10151
|
+
registerTaskWatch(tasks);
|
|
10152
|
+
addSharedServerOptions(
|
|
10153
|
+
tasks.command("conformance").description("Run MCP Tasks conformance checks").option(
|
|
10154
|
+
"--category <category>",
|
|
10155
|
+
"Check category to run. Repeat for multiple. Default: all.",
|
|
10156
|
+
(value, previous = []) => [...previous, value],
|
|
10157
|
+
[]
|
|
10158
|
+
).option(
|
|
10159
|
+
"--check-id <id>",
|
|
10160
|
+
"Specific check ID to run. Repeat for multiple. Default: all.",
|
|
10161
|
+
(value, previous = []) => [...previous, value],
|
|
10162
|
+
[]
|
|
10163
|
+
).option(
|
|
10164
|
+
"--tool-name <tool>",
|
|
10165
|
+
"Tool used to provoke a task. Required for servers whose tools carry no task metadata (the extension wire)."
|
|
10166
|
+
).option("--tool-args <json>", "Tool arguments as a JSON object").option(
|
|
10167
|
+
"--poll-timeout <ms>",
|
|
10168
|
+
"How long to poll a created task for a terminal status",
|
|
10169
|
+
(value) => parsePositiveInteger(value, "Poll timeout"),
|
|
10170
|
+
3e4
|
|
10171
|
+
).option(
|
|
10172
|
+
"--reporter <reporter>",
|
|
10173
|
+
"Structured reporter output: json-summary or junit-xml"
|
|
10174
|
+
)
|
|
10175
|
+
).action(async (options, command) => {
|
|
10176
|
+
const reporter = parseReporterFormat(
|
|
10177
|
+
options.reporter
|
|
10178
|
+
);
|
|
10179
|
+
const globalOptions = command.optsWithGlobals();
|
|
10180
|
+
const format = resolveConformanceOutputFormatForCli(
|
|
10181
|
+
globalOptions.format,
|
|
10182
|
+
process.stdout.isTTY,
|
|
10183
|
+
reporter
|
|
10184
|
+
);
|
|
10185
|
+
const target = describeTarget(options);
|
|
10186
|
+
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
10187
|
+
const config = {
|
|
10188
|
+
...buildTasksConformanceConfig({
|
|
10189
|
+
...options,
|
|
10190
|
+
timeout: globalOptions.timeout ?? 3e4
|
|
10191
|
+
}),
|
|
10192
|
+
...collector ? { rpcLogger: collector.rpcLogger } : {}
|
|
10193
|
+
};
|
|
10194
|
+
const result = await new MCPTasksConformanceTest(config).run();
|
|
10195
|
+
const outputResult = reporter ? result : withRpcLogsIfRequested(result, collector, {
|
|
10196
|
+
format,
|
|
10197
|
+
rpc: globalOptions.rpc ?? false
|
|
10198
|
+
});
|
|
10199
|
+
const output = renderConformanceForCli(outputResult, reporter, format);
|
|
10200
|
+
process.stdout.write(output.endsWith("\n") ? output : `${output}
|
|
10201
|
+
`);
|
|
10202
|
+
const incompleteReason = result.incompleteReason;
|
|
10203
|
+
if (incompleteReason && !globalOptions.quiet) {
|
|
10204
|
+
process.stderr.write(`Run incomplete: ${incompleteReason}
|
|
10205
|
+
`);
|
|
10206
|
+
}
|
|
10207
|
+
const exitCode = tasksConformanceExitCode(result);
|
|
10208
|
+
if (exitCode !== 0) {
|
|
10209
|
+
setProcessExitCode(exitCode);
|
|
10210
|
+
}
|
|
10211
|
+
});
|
|
10212
|
+
}
|
|
10213
|
+
async function runTaskAugmentedToolCall(args) {
|
|
10214
|
+
const {
|
|
10215
|
+
options,
|
|
10216
|
+
globalOptions,
|
|
10217
|
+
config,
|
|
10218
|
+
host,
|
|
10219
|
+
toolName,
|
|
10220
|
+
params,
|
|
10221
|
+
collector,
|
|
10222
|
+
targetSummary,
|
|
10223
|
+
snapshotCollector
|
|
10224
|
+
} = args;
|
|
10225
|
+
const writeArtifact = (outcome) => writeCommandDebugArtifact({
|
|
10226
|
+
outputPath: options.debugOut,
|
|
10227
|
+
format: globalOptions.format,
|
|
10228
|
+
quiet: globalOptions.quiet,
|
|
10229
|
+
commandName: "tools call",
|
|
10230
|
+
commandInput: { toolName, params },
|
|
10231
|
+
target: targetSummary,
|
|
10232
|
+
outcome,
|
|
10233
|
+
snapshot: options.debugOut ? {
|
|
10234
|
+
input: {
|
|
10235
|
+
config,
|
|
10236
|
+
target: targetSummary,
|
|
10237
|
+
timeout: globalOptions.timeout
|
|
10238
|
+
},
|
|
10239
|
+
collector: snapshotCollector
|
|
10240
|
+
} : void 0,
|
|
10241
|
+
collectors: [collector]
|
|
10242
|
+
});
|
|
10243
|
+
const input = buildTaskInputDriverOptions({
|
|
10244
|
+
config: host ? applyHostToConfig(config, host.connection) : config,
|
|
10245
|
+
interactive: options.interactive,
|
|
10246
|
+
yes: options.yes
|
|
10247
|
+
});
|
|
10248
|
+
const onState = options.taskWatch ? watchStateReporter(globalOptions) : void 0;
|
|
10249
|
+
const note = (message) => {
|
|
10250
|
+
if (!globalOptions.quiet) process.stderr.write(`${message}
|
|
10251
|
+
`);
|
|
10252
|
+
};
|
|
10253
|
+
const run = () => withEphemeralManager(
|
|
10254
|
+
config,
|
|
10255
|
+
async (manager, serverId) => {
|
|
10256
|
+
if (host) {
|
|
10257
|
+
await assertToolVisibleToHost(manager, serverId, toolName, host);
|
|
10258
|
+
}
|
|
10259
|
+
const support = resolveTasksSupportOrThrow(manager, serverId, options.wire);
|
|
10260
|
+
assertWireCapability(
|
|
10261
|
+
support,
|
|
10262
|
+
"toolCalls",
|
|
10263
|
+
"The server did not declare `capabilities.tasks.requests` for `tools/call`, so it cannot turn this call into a task."
|
|
10264
|
+
);
|
|
10265
|
+
if (options.taskTtl !== void 0 && support.wire !== "legacy") {
|
|
10266
|
+
throw usageError(
|
|
10267
|
+
"--task-ttl applies only to the 2025-11-25 tasks wire. This server resolved to the extension wire, where the server owns the TTL and a client cannot set one."
|
|
10268
|
+
);
|
|
10269
|
+
}
|
|
10270
|
+
return withWatchSignals(async (signal) => {
|
|
10271
|
+
let result;
|
|
10272
|
+
try {
|
|
10273
|
+
result = support.wire === "legacy" ? await manager.executeTool(
|
|
10274
|
+
serverId,
|
|
10275
|
+
toolName,
|
|
10276
|
+
params,
|
|
10277
|
+
{ signal },
|
|
10278
|
+
options.taskTtl !== void 0 ? { ttl: options.taskTtl } : {}
|
|
10279
|
+
) : await manager.executeTool(serverId, toolName, params, {
|
|
10280
|
+
allowTaskResult: true,
|
|
10281
|
+
request: { signal }
|
|
10282
|
+
});
|
|
10283
|
+
} catch (error) {
|
|
10284
|
+
if (!signal.aborted) throw error;
|
|
10285
|
+
return {
|
|
10286
|
+
aborted: { wire: support.wire, phase: "create" },
|
|
10287
|
+
created: null,
|
|
10288
|
+
result: null
|
|
10289
|
+
};
|
|
10290
|
+
}
|
|
10291
|
+
const created = detectCreatedTask(support.wire, result);
|
|
10292
|
+
if (!created) {
|
|
10293
|
+
if (support.wire === "legacy") {
|
|
10294
|
+
throw cliError(
|
|
10295
|
+
"TASK_MALFORMED",
|
|
10296
|
+
`Server returned a task-augmented result for ${toolName} that is not a usable task: the 2025-11-25 \`CreateTaskResult\` requires a \`taskId\` and a \`status\` of \`working\`, \`input_required\`, \`completed\`, \`failed\`, or \`cancelled\`.`,
|
|
10297
|
+
1,
|
|
10298
|
+
{ wire: support.wire, result }
|
|
10299
|
+
);
|
|
10300
|
+
}
|
|
10301
|
+
note(
|
|
10302
|
+
`No task materialized: the server answered ${toolName} synchronously. Returning the tool result as-is.`
|
|
10303
|
+
);
|
|
10304
|
+
return { aborted: null, created: null, result };
|
|
10305
|
+
}
|
|
10306
|
+
if (!options.taskWatch) {
|
|
10307
|
+
return { aborted: null, created, result: null };
|
|
10308
|
+
}
|
|
10309
|
+
const taskId = created.task.taskId;
|
|
10310
|
+
const watch = await driveTaskWatch({
|
|
10311
|
+
manager,
|
|
10312
|
+
serverId,
|
|
10313
|
+
support,
|
|
10314
|
+
taskId,
|
|
10315
|
+
tuning: taskWatchTuningFrom(options),
|
|
10316
|
+
...input ? { input } : {},
|
|
10317
|
+
signal,
|
|
10318
|
+
...onState ? { onState } : {}
|
|
10319
|
+
});
|
|
10320
|
+
return { aborted: null, created, watch, result: null };
|
|
10321
|
+
});
|
|
10322
|
+
},
|
|
10323
|
+
{
|
|
10324
|
+
timeout: globalOptions.timeout,
|
|
10325
|
+
rpcLogger: collector?.rpcLogger,
|
|
10326
|
+
host: host?.connection,
|
|
10327
|
+
...options.interactive ? {
|
|
10328
|
+
beforeConnect: buildMrtrBeforeConnect(options),
|
|
10329
|
+
interactiveElicitation: true
|
|
10330
|
+
} : {}
|
|
10331
|
+
}
|
|
10332
|
+
);
|
|
10333
|
+
let envelope;
|
|
10334
|
+
try {
|
|
10335
|
+
envelope = await run();
|
|
10336
|
+
} catch (error) {
|
|
10337
|
+
await writeArtifact({ status: "error", error });
|
|
10338
|
+
throw error;
|
|
10339
|
+
}
|
|
10340
|
+
const payload = envelope.aborted ? { status: "aborted", ...envelope.aborted } : envelope.created ? envelope.watch ? { created: envelope.created, watch: envelope.watch } : envelope.created : envelope.result;
|
|
10341
|
+
const syncToolResultError = !envelope.aborted && !envelope.created && isCallToolResultError(envelope.result);
|
|
10342
|
+
const exitCode = envelope.aborted ? 130 : envelope.watch ? taskWatchExitCode(envelope.watch.outcome) : syncToolResultError ? 1 : 0;
|
|
10343
|
+
await writeArtifact(
|
|
10344
|
+
exitCode === 0 ? { status: "success", result: payload } : envelope.aborted ? {
|
|
10345
|
+
status: "error",
|
|
10346
|
+
result: payload,
|
|
10347
|
+
error: {
|
|
10348
|
+
code: "task_aborted",
|
|
10349
|
+
message: `Interrupted during task ${envelope.aborted.phase}.`
|
|
10350
|
+
}
|
|
10351
|
+
} : syncToolResultError ? {
|
|
10352
|
+
// Same code the plain path stamps for `isError: true`: the task
|
|
10353
|
+
// machinery was a bystander here, so the artifact must not
|
|
10354
|
+
// suggest a task outcome that never existed.
|
|
10355
|
+
status: "error",
|
|
10356
|
+
result: payload,
|
|
10357
|
+
error: {
|
|
10358
|
+
code: "tool_result_error",
|
|
10359
|
+
message: "Tool returned an error result."
|
|
10360
|
+
}
|
|
10361
|
+
} : {
|
|
10362
|
+
status: "error",
|
|
10363
|
+
result: payload,
|
|
10364
|
+
error: {
|
|
10365
|
+
code: `task_${envelope.watch?.outcome ?? "unknown"}`,
|
|
10366
|
+
message: `Task watch ended with outcome "${envelope.watch?.outcome}".`
|
|
10367
|
+
}
|
|
10368
|
+
}
|
|
10369
|
+
);
|
|
10370
|
+
writeResult(
|
|
10371
|
+
withRpcLogsIfRequested(payload, collector, globalOptions),
|
|
10372
|
+
globalOptions.format
|
|
10373
|
+
);
|
|
10374
|
+
if (exitCode !== 0) setProcessExitCode(exitCode);
|
|
10375
|
+
}
|
|
10376
|
+
function registerToolsCommands(program) {
|
|
10377
|
+
const tools = program.command("tools").description("List and invoke MCP server tools");
|
|
10378
|
+
addHostOption(
|
|
10379
|
+
addRetryOptions(
|
|
10380
|
+
addSharedServerOptions(
|
|
10381
|
+
tools.command("list").description("List tools exposed by an MCP server").option("--cursor <cursor>", "Pagination cursor").option("--model-id <model>", "Model id used for token counting")
|
|
10382
|
+
)
|
|
10383
|
+
)
|
|
10384
|
+
).action(async (options, command) => {
|
|
10385
|
+
const globalOptions = getGlobalOptions(command);
|
|
10386
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
10387
|
+
const host = resolveHostFromOptions(options);
|
|
10388
|
+
const target = describeTarget(options);
|
|
8216
10389
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
8217
10390
|
const config = parseServerConfig({
|
|
8218
10391
|
...options,
|
|
@@ -8263,49 +10436,71 @@ function registerToolsCommands(program) {
|
|
|
8263
10436
|
});
|
|
8264
10437
|
addHostOption(
|
|
8265
10438
|
addSharedServerOptions(
|
|
8266
|
-
|
|
8267
|
-
"--tool-
|
|
8268
|
-
|
|
8269
|
-
|
|
8270
|
-
|
|
8271
|
-
|
|
8272
|
-
|
|
8273
|
-
|
|
8274
|
-
|
|
8275
|
-
|
|
8276
|
-
"--
|
|
8277
|
-
|
|
8278
|
-
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8287
|
-
|
|
8288
|
-
|
|
8289
|
-
|
|
8290
|
-
|
|
8291
|
-
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8298
|
-
|
|
8299
|
-
|
|
8300
|
-
|
|
8301
|
-
|
|
8302
|
-
|
|
8303
|
-
"--
|
|
8304
|
-
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
|
|
8308
|
-
|
|
10439
|
+
addTaskWatchTuningOptions(
|
|
10440
|
+
tools.command("call").description("Call an MCP tool").option("--tool-name <tool>", "Tool name").option("--name <tool>", "Alias for --tool-name").option(
|
|
10441
|
+
"--interactive",
|
|
10442
|
+
"Drive the modern input_required (multi-round-trip) loop: render embedded elicitations to the terminal and collect responses from stdin"
|
|
10443
|
+
).option(
|
|
10444
|
+
"--yes",
|
|
10445
|
+
"With --interactive, run non-interactively: decline every embedded input request instead of prompting"
|
|
10446
|
+
).option(
|
|
10447
|
+
"--tool-args <json>",
|
|
10448
|
+
"Tool parameter object as JSON, @path, or - for stdin"
|
|
10449
|
+
).option("--params <json>", "Alias for --tool-args").option("--tool-args-stdin", "Read tool parameter JSON from stdin").option(
|
|
10450
|
+
"--validate-response",
|
|
10451
|
+
"Validate the MCP tool-call envelope returned by the server"
|
|
10452
|
+
).option(
|
|
10453
|
+
"--expect-success",
|
|
10454
|
+
"Evaluate the tool-call outcome policy against isError"
|
|
10455
|
+
).option(
|
|
10456
|
+
"--reporter <reporter>",
|
|
10457
|
+
"Structured reporter output: json-summary or junit-xml"
|
|
10458
|
+
).option(
|
|
10459
|
+
"--debug-out <path>",
|
|
10460
|
+
"Write a structured debug artifact to a file"
|
|
10461
|
+
).option(
|
|
10462
|
+
"--ui",
|
|
10463
|
+
"Render the tool result in Inspector Playground; opens a browser by default in a TTY"
|
|
10464
|
+
).option(
|
|
10465
|
+
"--require-render",
|
|
10466
|
+
"Treat skipped Inspector renders as errors (with --ui)"
|
|
10467
|
+
).option(
|
|
10468
|
+
"--open",
|
|
10469
|
+
"Open Inspector in the system browser before rendering (default with --ui in a TTY)"
|
|
10470
|
+
).option(
|
|
10471
|
+
"--no-open",
|
|
10472
|
+
"Start/use Inspector without opening a system browser"
|
|
10473
|
+
).option(
|
|
10474
|
+
"--attach-only",
|
|
10475
|
+
"Require an already-running Inspector browser client; do not start or open Inspector"
|
|
10476
|
+
).option("--inspector-url <url>", "Local Inspector base URL (with --ui)").option(
|
|
10477
|
+
"--frontend-url <url>",
|
|
10478
|
+
"Inspector frontend URL (with --ui; overrides health-advertised frontend and skips discovery)"
|
|
10479
|
+
).option(
|
|
10480
|
+
"--server-name <name>",
|
|
10481
|
+
"Server name inside Inspector (with --ui)"
|
|
10482
|
+
).option(
|
|
10483
|
+
"--protocol <protocol>",
|
|
10484
|
+
'Render protocol: "mcp-apps" or "openai-sdk" (with --ui)'
|
|
10485
|
+
).option(
|
|
10486
|
+
"--device <device>",
|
|
10487
|
+
'Render device: "mobile", "tablet", "desktop", or "custom" (with --ui)'
|
|
10488
|
+
).option("--theme <theme>", 'Render theme: "light" or "dark" (with --ui)').option("--locale <locale>", "Render locale (with --ui)").option("--time-zone <iana>", "Render IANA timezone (with --ui)").option(
|
|
10489
|
+
"--task",
|
|
10490
|
+
"Invite the server to answer with a task instead of a result. Uses whichever tasks wire the connection resolves to."
|
|
10491
|
+
).option(
|
|
10492
|
+
"--task-ttl <ms>",
|
|
10493
|
+
"Requested task TTL (2025-11-25 wire only; the extension server owns its TTL). Requires --task.",
|
|
10494
|
+
(value) => parsePositiveInteger(value, "Task TTL")
|
|
10495
|
+
).option(
|
|
10496
|
+
"--task-watch",
|
|
10497
|
+
"After creating the task, poll it to a terminal status in the same connection. Requires --task."
|
|
10498
|
+
).option(
|
|
10499
|
+
"--wire <wire>",
|
|
10500
|
+
"Assert the connection resolves to this tasks wire: legacy or extension (with --task)",
|
|
10501
|
+
parseTasksWireOption
|
|
10502
|
+
)
|
|
10503
|
+
)
|
|
8309
10504
|
)
|
|
8310
10505
|
).action(async (options, command) => {
|
|
8311
10506
|
const globalOptions = getGlobalOptions(command);
|
|
@@ -8341,6 +10536,11 @@ function registerToolsCommands(program) {
|
|
|
8341
10536
|
);
|
|
8342
10537
|
}
|
|
8343
10538
|
const paramsInput = options.toolArgsStdin ? "-" : resolvedParamsInput;
|
|
10539
|
+
if (options.interactive && paramsInput === "-") {
|
|
10540
|
+
throw usageError(
|
|
10541
|
+
"--interactive cannot be used together with tool parameters read from stdin (--tool-args-stdin or --tool-args/--params -): interactive answers are read from stdin too. Pass the parameters as JSON or @path."
|
|
10542
|
+
);
|
|
10543
|
+
}
|
|
8344
10544
|
const params = parseJsonRecord(paramsInput, "Tool parameters") ?? {};
|
|
8345
10545
|
const targetSummary = summarizeServerDoctorTarget(target, config);
|
|
8346
10546
|
const shouldValidateResponse = options.validateResponse === true;
|
|
@@ -8359,6 +10559,59 @@ function registerToolsCommands(program) {
|
|
|
8359
10559
|
"--reporter requires --validate-response and/or --expect-success."
|
|
8360
10560
|
);
|
|
8361
10561
|
}
|
|
10562
|
+
const watchTuningFlags = [
|
|
10563
|
+
["--duration-ms", options.durationMs],
|
|
10564
|
+
["--poll-interval-ms", options.pollIntervalMs],
|
|
10565
|
+
["--max-input-rounds", options.maxInputRounds],
|
|
10566
|
+
["--max-consecutive-errors", options.maxConsecutiveErrors]
|
|
10567
|
+
];
|
|
10568
|
+
if (!options.task) {
|
|
10569
|
+
if (options.taskTtl !== void 0) {
|
|
10570
|
+
throw usageError("--task-ttl requires --task.");
|
|
10571
|
+
}
|
|
10572
|
+
if (options.taskWatch) throw usageError("--task-watch requires --task.");
|
|
10573
|
+
if (options.wire !== void 0) {
|
|
10574
|
+
throw usageError("--wire requires --task.");
|
|
10575
|
+
}
|
|
10576
|
+
for (const [flag, value] of watchTuningFlags) {
|
|
10577
|
+
if (value !== void 0) {
|
|
10578
|
+
throw usageError(`${flag} requires --task --task-watch.`);
|
|
10579
|
+
}
|
|
10580
|
+
}
|
|
10581
|
+
} else {
|
|
10582
|
+
if (!options.taskWatch) {
|
|
10583
|
+
for (const [flag, value] of watchTuningFlags) {
|
|
10584
|
+
if (value !== void 0) {
|
|
10585
|
+
throw usageError(
|
|
10586
|
+
`${flag} tunes the watch loop, so it requires --task-watch.`
|
|
10587
|
+
);
|
|
10588
|
+
}
|
|
10589
|
+
}
|
|
10590
|
+
}
|
|
10591
|
+
if (options.ui) {
|
|
10592
|
+
throw usageError("--task cannot be used together with --ui.");
|
|
10593
|
+
}
|
|
10594
|
+
if (reporter) {
|
|
10595
|
+
throw usageError("--task cannot be used together with --reporter.");
|
|
10596
|
+
}
|
|
10597
|
+
if (shouldValidateResponse || shouldExpectSuccess) {
|
|
10598
|
+
throw usageError(
|
|
10599
|
+
"--task cannot be used together with --validate-response or --expect-success: a task-creation envelope is not a tool result. Validate the result of `tasks watch` instead."
|
|
10600
|
+
);
|
|
10601
|
+
}
|
|
10602
|
+
await runTaskAugmentedToolCall({
|
|
10603
|
+
options,
|
|
10604
|
+
globalOptions,
|
|
10605
|
+
config,
|
|
10606
|
+
host,
|
|
10607
|
+
toolName,
|
|
10608
|
+
params,
|
|
10609
|
+
collector: primaryCollector,
|
|
10610
|
+
targetSummary,
|
|
10611
|
+
snapshotCollector
|
|
10612
|
+
});
|
|
10613
|
+
return;
|
|
10614
|
+
}
|
|
8362
10615
|
const renderContext = options.ui ? {
|
|
8363
10616
|
protocol: parseRenderProtocol(options.protocol),
|
|
8364
10617
|
deviceType: parseRenderDevice(options.device),
|
|
@@ -8380,7 +10633,9 @@ function registerToolsCommands(program) {
|
|
|
8380
10633
|
{
|
|
8381
10634
|
timeout: globalOptions.timeout,
|
|
8382
10635
|
rpcLogger: primaryCollector?.rpcLogger,
|
|
8383
|
-
host: host?.connection
|
|
10636
|
+
host: host?.connection,
|
|
10637
|
+
beforeConnect: buildMrtrBeforeConnect(options),
|
|
10638
|
+
interactiveElicitation: options.interactive === true
|
|
8384
10639
|
}
|
|
8385
10640
|
);
|
|
8386
10641
|
} catch (error) {
|
|
@@ -8742,7 +10997,7 @@ function buildCompactInspectorRender(uiResult, options = {}) {
|
|
|
8742
10997
|
hasCommandError = true;
|
|
8743
10998
|
}
|
|
8744
10999
|
}
|
|
8745
|
-
const topLevelError = options.skipped ? options.issue ? { warning: options.issue } : uiResult.status === "error" &&
|
|
11000
|
+
const topLevelError = options.skipped ? options.issue ? { warning: options.issue } : uiResult.status === "error" && isRecord3(uiResult.error) ? { warning: uiResult.error } : {} : options.issue ? { error: options.issue } : uiResult.status === "error" && isRecord3(uiResult.error) ? { error: uiResult.error } : {};
|
|
8746
11001
|
return {
|
|
8747
11002
|
status: options.skipped ? "skipped" : hasCommandError || uiResult.status === "error" ? "error" : "rendered",
|
|
8748
11003
|
remediation: options.remediation ?? "none",
|
|
@@ -8771,18 +11026,18 @@ function parseInspectorFrontendUrl(value) {
|
|
|
8771
11026
|
return frontendUrl;
|
|
8772
11027
|
}
|
|
8773
11028
|
function compactInspectorCommandResponse(value) {
|
|
8774
|
-
if (!
|
|
11029
|
+
if (!isRecord3(value) || !isCompactInspectorCommandStatus(value.status)) {
|
|
8775
11030
|
return void 0;
|
|
8776
11031
|
}
|
|
8777
11032
|
return {
|
|
8778
11033
|
status: value.status,
|
|
8779
|
-
...value.status === "error" &&
|
|
11034
|
+
...value.status === "error" && isRecord3(value.error) ? { error: value.error } : {}
|
|
8780
11035
|
};
|
|
8781
11036
|
}
|
|
8782
11037
|
function isCompactInspectorCommandStatus(value) {
|
|
8783
11038
|
return value === "success" || value === "error";
|
|
8784
11039
|
}
|
|
8785
|
-
function
|
|
11040
|
+
function isRecord3(value) {
|
|
8786
11041
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
8787
11042
|
}
|
|
8788
11043
|
function tunnelPathPrefix(serverId) {
|
|
@@ -9904,9 +12159,11 @@ async function main(argv = process.argv, dependencies = {}) {
|
|
|
9904
12159
|
registerServerCommands(program);
|
|
9905
12160
|
registerToolsCommands(program);
|
|
9906
12161
|
registerResourcesCommands(program);
|
|
12162
|
+
registerSubscriptionsCommands(program);
|
|
9907
12163
|
registerCompatCommands(program);
|
|
9908
12164
|
registerPromptCommands(program);
|
|
9909
12165
|
registerAppsCommands(program);
|
|
12166
|
+
registerTasksCommands(program);
|
|
9910
12167
|
registerOAuthCommands(program);
|
|
9911
12168
|
registerXaaCommands(program);
|
|
9912
12169
|
registerProtocolCommands(program);
|
|
@@ -9915,6 +12172,7 @@ async function main(argv = process.argv, dependencies = {}) {
|
|
|
9915
12172
|
registerEvalCommands(program);
|
|
9916
12173
|
registerHostsCommands(program);
|
|
9917
12174
|
registerEnvironmentsCommands(program);
|
|
12175
|
+
registerImagesCommands(program);
|
|
9918
12176
|
registerTunnelCommands(program);
|
|
9919
12177
|
registerInspectorCommands(program);
|
|
9920
12178
|
registerMcpCommands(program);
|