@mcpjam/cli 3.15.2 → 3.16.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 +2477 -244
- 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, toConformanceReport, renderConformanceReportJUnitXml, renderConformanceReportJson, formatOAuthConformanceHuman, formatOAuthConformanceSuiteHuman, fetchOAuthMetadata, executeOAuthProxy, executeDebugOAuthProxy, normalizeRegistrationStrategy, normalizeXaaClientAuth, normalizeIdentityAssertionFormat, IDENTITY_ASSERTION_FORMATS, XAA_CONFIDENTIAL_CIMD_ORIGIN, getLocalConfidentialCimdProvider, isKnownProtocolVersion, 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.16.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`);
|
|
@@ -3472,16 +3482,545 @@ async function assertToolVisibleToHost(manager, serverId, toolName, host) {
|
|
|
3472
3482
|
`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
3483
|
);
|
|
3474
3484
|
}
|
|
3485
|
+
var MrtrCollectAbortError = class extends Error {
|
|
3486
|
+
constructor(message = "MRTR input collection was aborted.") {
|
|
3487
|
+
super(message);
|
|
3488
|
+
this.name = "AbortError";
|
|
3489
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
3490
|
+
}
|
|
3491
|
+
};
|
|
3492
|
+
function sanitizeTerminalText(value) {
|
|
3493
|
+
return value.replace(/[\u0000-\u0008\u000A-\u001F\u007F-\u009F]/g, " ");
|
|
3494
|
+
}
|
|
3495
|
+
function resolveNonInteractive(args) {
|
|
3496
|
+
if (args.yes) return true;
|
|
3497
|
+
const env = args.env ?? process.env;
|
|
3498
|
+
if (env.CI || env.MCPJAM_NON_INTERACTIVE) return true;
|
|
3499
|
+
return args.stdinIsTTY !== true;
|
|
3500
|
+
}
|
|
3501
|
+
var INTERACTIVE_ELICITATION_CAPABILITY = {
|
|
3502
|
+
form: {},
|
|
3503
|
+
url: {}
|
|
3504
|
+
};
|
|
3505
|
+
function buildMrtrBeforeConnect(options) {
|
|
3506
|
+
if (!options.interactive) return void 0;
|
|
3507
|
+
const nonInteractive = resolveNonInteractive({
|
|
3508
|
+
yes: options.yes,
|
|
3509
|
+
stdinIsTTY: Boolean(process.stdin.isTTY)
|
|
3510
|
+
});
|
|
3511
|
+
const collectorOptions = { nonInteractive };
|
|
3512
|
+
const collector = createStdinMrtrCollector(collectorOptions);
|
|
3513
|
+
const handler = createStdinElicitationHandler(collectorOptions);
|
|
3514
|
+
return (manager, serverId) => {
|
|
3515
|
+
manager.setMrtrInputCollector(serverId, collector);
|
|
3516
|
+
manager.setElicitationHandler(serverId, handler);
|
|
3517
|
+
};
|
|
3518
|
+
}
|
|
3519
|
+
function parseElicitationFields(requestedSchema) {
|
|
3520
|
+
if (!isRecord(requestedSchema)) return [];
|
|
3521
|
+
const properties = requestedSchema.properties;
|
|
3522
|
+
if (!isRecord(properties)) return [];
|
|
3523
|
+
const required = new Set(
|
|
3524
|
+
Array.isArray(requestedSchema.required) ? requestedSchema.required.filter((v) => typeof v === "string") : []
|
|
3525
|
+
);
|
|
3526
|
+
const fields = [];
|
|
3527
|
+
for (const key of Object.keys(properties)) {
|
|
3528
|
+
const prop = properties[key];
|
|
3529
|
+
if (!isRecord(prop)) {
|
|
3530
|
+
fields.push({ key, type: "string", required: required.has(key) });
|
|
3531
|
+
continue;
|
|
3532
|
+
}
|
|
3533
|
+
const title = typeof prop.title === "string" ? prop.title : void 0;
|
|
3534
|
+
const description = typeof prop.description === "string" ? prop.description : void 0;
|
|
3535
|
+
const scalarEnum = extractEnum(prop);
|
|
3536
|
+
if (scalarEnum) {
|
|
3537
|
+
fields.push({
|
|
3538
|
+
key,
|
|
3539
|
+
type: "enum",
|
|
3540
|
+
required: required.has(key),
|
|
3541
|
+
title,
|
|
3542
|
+
description,
|
|
3543
|
+
enumValues: scalarEnum.values,
|
|
3544
|
+
...scalarEnum.names ? { enumNames: scalarEnum.names } : {}
|
|
3545
|
+
});
|
|
3546
|
+
continue;
|
|
3547
|
+
}
|
|
3548
|
+
if (prop.type === "array") {
|
|
3549
|
+
const items = isRecord(prop.items) ? prop.items : void 0;
|
|
3550
|
+
const itemEnum = items ? extractEnum(items) : void 0;
|
|
3551
|
+
const itemRawType = items && typeof items.type === "string" ? items.type : "string";
|
|
3552
|
+
const itemType = itemRawType === "number" ? "number" : itemRawType === "integer" ? "integer" : itemRawType === "boolean" ? "boolean" : "string";
|
|
3553
|
+
fields.push({
|
|
3554
|
+
key,
|
|
3555
|
+
type: "array",
|
|
3556
|
+
required: required.has(key),
|
|
3557
|
+
title,
|
|
3558
|
+
description,
|
|
3559
|
+
...itemEnum ? { enumValues: itemEnum.values } : {},
|
|
3560
|
+
...itemEnum?.names ? { enumNames: itemEnum.names } : {},
|
|
3561
|
+
...itemEnum ? {} : { itemType },
|
|
3562
|
+
...required.has(key) && !isPositiveInteger(prop.minItems) ? { allowEmpty: true } : {},
|
|
3563
|
+
...withConstraints(prop)
|
|
3564
|
+
});
|
|
3565
|
+
continue;
|
|
3566
|
+
}
|
|
3567
|
+
const rawType = typeof prop.type === "string" ? prop.type : "string";
|
|
3568
|
+
const type = rawType === "number" ? "number" : rawType === "integer" ? "integer" : rawType === "boolean" ? "boolean" : "string";
|
|
3569
|
+
fields.push({
|
|
3570
|
+
key,
|
|
3571
|
+
type,
|
|
3572
|
+
required: required.has(key),
|
|
3573
|
+
title,
|
|
3574
|
+
description,
|
|
3575
|
+
...type === "string" && required.has(key) && !isPositiveInteger(prop.minLength) ? { allowEmpty: true } : {},
|
|
3576
|
+
...withConstraints(prop)
|
|
3577
|
+
});
|
|
3578
|
+
}
|
|
3579
|
+
return fields;
|
|
3580
|
+
}
|
|
3581
|
+
function withConstraints(prop) {
|
|
3582
|
+
const constraints = {};
|
|
3583
|
+
for (const key of [
|
|
3584
|
+
"minLength",
|
|
3585
|
+
"maxLength",
|
|
3586
|
+
"minimum",
|
|
3587
|
+
"maximum",
|
|
3588
|
+
"minItems",
|
|
3589
|
+
"maxItems"
|
|
3590
|
+
]) {
|
|
3591
|
+
const value = prop[key];
|
|
3592
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
3593
|
+
constraints[key] = value;
|
|
3594
|
+
}
|
|
3595
|
+
}
|
|
3596
|
+
if (typeof prop.pattern === "string" && prop.pattern !== "") {
|
|
3597
|
+
constraints.pattern = prop.pattern;
|
|
3598
|
+
}
|
|
3599
|
+
if (typeof prop.format === "string" && prop.format !== "") {
|
|
3600
|
+
constraints.format = prop.format;
|
|
3601
|
+
}
|
|
3602
|
+
return Object.keys(constraints).length > 0 ? { constraints } : {};
|
|
3603
|
+
}
|
|
3604
|
+
function isPositiveInteger(value) {
|
|
3605
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0;
|
|
3606
|
+
}
|
|
3607
|
+
function satisfiesStringFormat(value, format) {
|
|
3608
|
+
switch (format) {
|
|
3609
|
+
case "email": {
|
|
3610
|
+
const parts = value.split("@");
|
|
3611
|
+
if (parts.length !== 2) return false;
|
|
3612
|
+
const [local, domain] = parts;
|
|
3613
|
+
if (local.length === 0 || domain.length === 0) return false;
|
|
3614
|
+
if (/\s/.test(value)) return false;
|
|
3615
|
+
return domain.includes(".") && !domain.startsWith(".") && !domain.endsWith(".");
|
|
3616
|
+
}
|
|
3617
|
+
case "uri": {
|
|
3618
|
+
try {
|
|
3619
|
+
new URL(value);
|
|
3620
|
+
return true;
|
|
3621
|
+
} catch {
|
|
3622
|
+
return false;
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
case "date": {
|
|
3626
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
3627
|
+
if (!match) return false;
|
|
3628
|
+
const [, y, m, d] = match;
|
|
3629
|
+
const date = /* @__PURE__ */ new Date(`${y}-${m}-${d}T00:00:00Z`);
|
|
3630
|
+
return !Number.isNaN(date.getTime()) && date.getUTCFullYear() === Number(y) && date.getUTCMonth() + 1 === Number(m) && date.getUTCDate() === Number(d);
|
|
3631
|
+
}
|
|
3632
|
+
case "date-time": {
|
|
3633
|
+
if (!/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(\.\d+)?([Zz]|[+-]\d{2}:\d{2})$/.test(value)) {
|
|
3634
|
+
return false;
|
|
3635
|
+
}
|
|
3636
|
+
return !Number.isNaN(new Date(value).getTime());
|
|
3637
|
+
}
|
|
3638
|
+
default:
|
|
3639
|
+
return true;
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
function isScreenedPattern(pattern) {
|
|
3643
|
+
if (pattern.length > 200) return false;
|
|
3644
|
+
if (/\\\d/.test(pattern)) return false;
|
|
3645
|
+
if (/\([^()]*[+*][^()]*\)\s*[+*{]/.test(pattern)) return false;
|
|
3646
|
+
if (/\)\s*[+*]\s*[+*]/.test(pattern)) return false;
|
|
3647
|
+
return true;
|
|
3648
|
+
}
|
|
3649
|
+
function assertSatisfiesConstraints(value, field) {
|
|
3650
|
+
const c = field.constraints;
|
|
3651
|
+
if (!c) return;
|
|
3652
|
+
const name = sanitizeTerminalText(field.title ?? field.key);
|
|
3653
|
+
if (typeof value === "string") {
|
|
3654
|
+
const length = Array.from(value).length;
|
|
3655
|
+
if (c.minLength !== void 0 && length < c.minLength) {
|
|
3656
|
+
throw new Error(`"${name}" must be at least ${c.minLength} character(s).`);
|
|
3657
|
+
}
|
|
3658
|
+
if (c.maxLength !== void 0 && length > c.maxLength) {
|
|
3659
|
+
throw new Error(`"${name}" must be at most ${c.maxLength} character(s).`);
|
|
3660
|
+
}
|
|
3661
|
+
if (c.format !== void 0 && !satisfiesStringFormat(value, c.format)) {
|
|
3662
|
+
throw new Error(
|
|
3663
|
+
`"${name}" must be a valid ${sanitizeTerminalText(c.format)}.`
|
|
3664
|
+
);
|
|
3665
|
+
}
|
|
3666
|
+
if (c.pattern !== void 0 && isScreenedPattern(c.pattern)) {
|
|
3667
|
+
let re;
|
|
3668
|
+
try {
|
|
3669
|
+
re = new RegExp(c.pattern);
|
|
3670
|
+
} catch {
|
|
3671
|
+
re = void 0;
|
|
3672
|
+
}
|
|
3673
|
+
if (re && !re.test(value)) {
|
|
3674
|
+
throw new Error(
|
|
3675
|
+
`"${name}" must match ${sanitizeTerminalText(c.pattern)}.`
|
|
3676
|
+
);
|
|
3677
|
+
}
|
|
3678
|
+
}
|
|
3679
|
+
return;
|
|
3680
|
+
}
|
|
3681
|
+
if (typeof value === "number") {
|
|
3682
|
+
if (c.minimum !== void 0 && value < c.minimum) {
|
|
3683
|
+
throw new Error(`"${name}" must be >= ${c.minimum}.`);
|
|
3684
|
+
}
|
|
3685
|
+
if (c.maximum !== void 0 && value > c.maximum) {
|
|
3686
|
+
throw new Error(`"${name}" must be <= ${c.maximum}.`);
|
|
3687
|
+
}
|
|
3688
|
+
return;
|
|
3689
|
+
}
|
|
3690
|
+
if (Array.isArray(value)) {
|
|
3691
|
+
if (c.minItems !== void 0 && value.length < c.minItems) {
|
|
3692
|
+
throw new Error(`"${name}" needs at least ${c.minItems} item(s).`);
|
|
3693
|
+
}
|
|
3694
|
+
if (c.maxItems !== void 0 && value.length > c.maxItems) {
|
|
3695
|
+
throw new Error(`"${name}" takes at most ${c.maxItems} item(s).`);
|
|
3696
|
+
}
|
|
3697
|
+
}
|
|
3698
|
+
}
|
|
3699
|
+
function extractEnum(node) {
|
|
3700
|
+
if (Array.isArray(node.enum) && node.enum.length > 0) {
|
|
3701
|
+
const values2 = node.enum.map((v) => String(v));
|
|
3702
|
+
const names2 = Array.isArray(node.enumNames) ? node.enumNames.map((v) => String(v)) : void 0;
|
|
3703
|
+
return names2 ? { values: values2, names: names2 } : { values: values2 };
|
|
3704
|
+
}
|
|
3705
|
+
const branches = Array.isArray(node.oneOf) ? node.oneOf : Array.isArray(node.anyOf) ? node.anyOf : void 0;
|
|
3706
|
+
if (!branches || branches.length === 0) return void 0;
|
|
3707
|
+
const values = [];
|
|
3708
|
+
const names = [];
|
|
3709
|
+
let anyName = false;
|
|
3710
|
+
for (const branch of branches) {
|
|
3711
|
+
if (!isRecord(branch)) return void 0;
|
|
3712
|
+
let value;
|
|
3713
|
+
if ("const" in branch) {
|
|
3714
|
+
value = branch.const;
|
|
3715
|
+
} else if (Array.isArray(branch.enum) && branch.enum.length === 1) {
|
|
3716
|
+
value = branch.enum[0];
|
|
3717
|
+
} else {
|
|
3718
|
+
return void 0;
|
|
3719
|
+
}
|
|
3720
|
+
values.push(String(value));
|
|
3721
|
+
const label = typeof branch.title === "string" ? branch.title : typeof branch.description === "string" ? branch.description : String(value);
|
|
3722
|
+
if (typeof branch.title === "string" || typeof branch.description === "string") {
|
|
3723
|
+
anyName = true;
|
|
3724
|
+
}
|
|
3725
|
+
names.push(label);
|
|
3726
|
+
}
|
|
3727
|
+
return anyName ? { values, names } : { values };
|
|
3728
|
+
}
|
|
3729
|
+
function coerceFieldValue(raw, field) {
|
|
3730
|
+
const coerced = coerceFieldValueRaw(raw, field);
|
|
3731
|
+
if ("value" in coerced) assertSatisfiesConstraints(coerced.value, field);
|
|
3732
|
+
return coerced;
|
|
3733
|
+
}
|
|
3734
|
+
function coerceFieldValueRaw(raw, field) {
|
|
3735
|
+
const trimmed = raw.trim();
|
|
3736
|
+
if (trimmed === "") {
|
|
3737
|
+
if (field.required) {
|
|
3738
|
+
if (field.allowEmpty && field.type === "string") return { value: "" };
|
|
3739
|
+
if (!(field.allowEmpty && field.type === "array")) {
|
|
3740
|
+
throw new Error(`"${sanitizeTerminalText(field.key)}" is required.`);
|
|
3741
|
+
}
|
|
3742
|
+
} else {
|
|
3743
|
+
return { skip: true };
|
|
3744
|
+
}
|
|
3745
|
+
}
|
|
3746
|
+
switch (field.type) {
|
|
3747
|
+
case "string":
|
|
3748
|
+
return { value: raw };
|
|
3749
|
+
case "number": {
|
|
3750
|
+
const n = Number(trimmed);
|
|
3751
|
+
if (!Number.isFinite(n)) throw new Error(`"${trimmed}" is not a number.`);
|
|
3752
|
+
return { value: n };
|
|
3753
|
+
}
|
|
3754
|
+
case "integer": {
|
|
3755
|
+
const n = Number(trimmed);
|
|
3756
|
+
if (!Number.isInteger(n)) throw new Error(`"${trimmed}" is not an integer.`);
|
|
3757
|
+
return { value: n };
|
|
3758
|
+
}
|
|
3759
|
+
case "boolean": {
|
|
3760
|
+
const lowered = trimmed.toLowerCase();
|
|
3761
|
+
if (["y", "yes", "true", "1"].includes(lowered)) return { value: true };
|
|
3762
|
+
if (["n", "no", "false", "0"].includes(lowered)) return { value: false };
|
|
3763
|
+
throw new Error(`Enter yes/no for "${sanitizeTerminalText(field.key)}".`);
|
|
3764
|
+
}
|
|
3765
|
+
case "enum": {
|
|
3766
|
+
const values = field.enumValues ?? [];
|
|
3767
|
+
if (values.includes(trimmed)) return { value: trimmed };
|
|
3768
|
+
const idx = Number(trimmed);
|
|
3769
|
+
if (Number.isInteger(idx) && idx >= 1 && idx <= values.length) {
|
|
3770
|
+
return { value: values[idx - 1] };
|
|
3771
|
+
}
|
|
3772
|
+
throw new Error(
|
|
3773
|
+
`Choose one of: ${sanitizeTerminalText(values.join(", "))} (or its number).`
|
|
3774
|
+
);
|
|
3775
|
+
}
|
|
3776
|
+
case "array": {
|
|
3777
|
+
const parts = trimmed.split(",").map((p) => p.trim()).filter((p) => p !== "");
|
|
3778
|
+
if (parts.length === 0) {
|
|
3779
|
+
if (!field.required) return { skip: true };
|
|
3780
|
+
if (field.allowEmpty) return { value: [] };
|
|
3781
|
+
throw new Error(`"${sanitizeTerminalText(field.key)}" is required.`);
|
|
3782
|
+
}
|
|
3783
|
+
const values = field.enumValues;
|
|
3784
|
+
if (values && values.length > 0) {
|
|
3785
|
+
const selected = parts.map((part) => {
|
|
3786
|
+
if (values.includes(part)) return part;
|
|
3787
|
+
const idx = Number(part);
|
|
3788
|
+
if (Number.isInteger(idx) && idx >= 1 && idx <= values.length) {
|
|
3789
|
+
return values[idx - 1];
|
|
3790
|
+
}
|
|
3791
|
+
throw new Error(
|
|
3792
|
+
`Choose from: ${sanitizeTerminalText(values.join(", "))} (comma-separated values or numbers).`
|
|
3793
|
+
);
|
|
3794
|
+
});
|
|
3795
|
+
return { value: selected };
|
|
3796
|
+
}
|
|
3797
|
+
const itemType = field.itemType ?? "string";
|
|
3798
|
+
const coerced = parts.map((part) => {
|
|
3799
|
+
const one = coerceFieldValueRaw(part, {
|
|
3800
|
+
key: field.key,
|
|
3801
|
+
type: itemType,
|
|
3802
|
+
required: true
|
|
3803
|
+
});
|
|
3804
|
+
return one.value;
|
|
3805
|
+
});
|
|
3806
|
+
return { value: coerced };
|
|
3807
|
+
}
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3810
|
+
function createStdinElicitationHandler(options = {}) {
|
|
3811
|
+
const collector = createStdinMrtrCollector(options);
|
|
3812
|
+
return async (params) => {
|
|
3813
|
+
const responses = await collector({
|
|
3814
|
+
state: {},
|
|
3815
|
+
inputRequests: {
|
|
3816
|
+
[INBOUND_ELICITATION_KEY]: { method: "elicitation/create", params }
|
|
3817
|
+
}
|
|
3818
|
+
});
|
|
3819
|
+
return responses[INBOUND_ELICITATION_KEY];
|
|
3820
|
+
};
|
|
3821
|
+
}
|
|
3822
|
+
var INBOUND_ELICITATION_KEY = "elicitation";
|
|
3823
|
+
function createStdinMrtrCollector(options = {}) {
|
|
3824
|
+
const write = options.write ?? ((text) => void process.stderr.write(text));
|
|
3825
|
+
const rawAttempts = options.maxFieldAttempts;
|
|
3826
|
+
const maxFieldAttempts = typeof rawAttempts === "number" && Number.isInteger(rawAttempts) && rawAttempts >= 1 ? rawAttempts : 3;
|
|
3827
|
+
return async ({ inputRequests, signal }) => {
|
|
3828
|
+
const activeSignal = signal ?? options.signal;
|
|
3829
|
+
throwIfAborted(activeSignal);
|
|
3830
|
+
const keys = Object.keys(inputRequests);
|
|
3831
|
+
const responses = /* @__PURE__ */ Object.create(null);
|
|
3832
|
+
if (options.nonInteractive) {
|
|
3833
|
+
write(
|
|
3834
|
+
`Non-interactive mode: declining ${keys.length} embedded input request(s). Re-run in a TTY (without --yes) to answer interactively.
|
|
3835
|
+
`
|
|
3836
|
+
);
|
|
3837
|
+
for (const key of keys) responses[key] = { action: "decline" };
|
|
3838
|
+
return responses;
|
|
3839
|
+
}
|
|
3840
|
+
const ownReader = options.reader === void 0;
|
|
3841
|
+
const reader = options.reader ?? createReadlineReader();
|
|
3842
|
+
try {
|
|
3843
|
+
let cancelled = false;
|
|
3844
|
+
for (const key of keys) {
|
|
3845
|
+
if (cancelled) {
|
|
3846
|
+
responses[key] = { action: "cancel" };
|
|
3847
|
+
continue;
|
|
3848
|
+
}
|
|
3849
|
+
responses[key] = await collectOne(
|
|
3850
|
+
key,
|
|
3851
|
+
inputRequests[key],
|
|
3852
|
+
{ reader, write, maxFieldAttempts, signal: activeSignal }
|
|
3853
|
+
);
|
|
3854
|
+
if (responses[key].action === "cancel") {
|
|
3855
|
+
cancelled = true;
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
return responses;
|
|
3859
|
+
} finally {
|
|
3860
|
+
if (ownReader) closeReadlineReader(reader);
|
|
3861
|
+
}
|
|
3862
|
+
};
|
|
3863
|
+
}
|
|
3864
|
+
async function collectOne(key, request, ctx) {
|
|
3865
|
+
const params = request.params ?? {};
|
|
3866
|
+
const message = typeof params.message === "string" ? params.message : void 0;
|
|
3867
|
+
const mode = params.mode === "url" ? "url" : "form";
|
|
3868
|
+
ctx.write("\n");
|
|
3869
|
+
ctx.write(
|
|
3870
|
+
message ? `${sanitizeTerminalText(message)}
|
|
3871
|
+
` : `Input requested ("${sanitizeTerminalText(key)}"):
|
|
3872
|
+
`
|
|
3873
|
+
);
|
|
3874
|
+
if (mode === "url") {
|
|
3875
|
+
const url = typeof params.url === "string" ? params.url : "(no URL provided)";
|
|
3876
|
+
ctx.write(
|
|
3877
|
+
`Open this URL to continue, then confirm below:
|
|
3878
|
+
${sanitizeTerminalText(url)}
|
|
3879
|
+
`
|
|
3880
|
+
);
|
|
3881
|
+
const action2 = await askAction(ctx.reader, ctx.write, ctx.signal, {
|
|
3882
|
+
acceptLabel: "approve"
|
|
3883
|
+
});
|
|
3884
|
+
return { action: action2 };
|
|
3885
|
+
}
|
|
3886
|
+
const action = await askAction(ctx.reader, ctx.write, ctx.signal, {
|
|
3887
|
+
acceptLabel: "accept"
|
|
3888
|
+
});
|
|
3889
|
+
if (action !== "accept") {
|
|
3890
|
+
return { action };
|
|
3891
|
+
}
|
|
3892
|
+
const fields = parseElicitationFields(params.requestedSchema);
|
|
3893
|
+
const content = /* @__PURE__ */ Object.create(null);
|
|
3894
|
+
for (const field of fields) {
|
|
3895
|
+
const label = sanitizeTerminalText(field.title ?? field.key);
|
|
3896
|
+
if (field.description)
|
|
3897
|
+
ctx.write(` ${sanitizeTerminalText(field.description)}
|
|
3898
|
+
`);
|
|
3899
|
+
if (field.type === "enum" || field.type === "array") {
|
|
3900
|
+
const values = field.enumValues ?? [];
|
|
3901
|
+
values.forEach((value, index) => {
|
|
3902
|
+
const name = field.enumNames?.[index];
|
|
3903
|
+
ctx.write(
|
|
3904
|
+
` ${index + 1}) ${sanitizeTerminalText(value)}${name ? ` \u2014 ${sanitizeTerminalText(name)}` : ""}
|
|
3905
|
+
`
|
|
3906
|
+
);
|
|
3907
|
+
});
|
|
3908
|
+
if (field.type === "array") {
|
|
3909
|
+
ctx.write(` (comma-separated for multiple)
|
|
3910
|
+
`);
|
|
3911
|
+
}
|
|
3912
|
+
}
|
|
3913
|
+
const suffix = !field.required ? " (optional, blank to skip)" : field.allowEmpty ? field.type === "array" ? " (required, blank for none)" : " (required, blank for empty)" : "";
|
|
3914
|
+
let coerced;
|
|
3915
|
+
for (let attempt = 1; attempt <= ctx.maxFieldAttempts; attempt += 1) {
|
|
3916
|
+
throwIfAborted(ctx.signal);
|
|
3917
|
+
const raw = await ctx.reader.question(
|
|
3918
|
+
`${label} [${field.type}]${suffix}: `,
|
|
3919
|
+
{ signal: ctx.signal }
|
|
3920
|
+
);
|
|
3921
|
+
try {
|
|
3922
|
+
coerced = coerceFieldValue(raw, field);
|
|
3923
|
+
break;
|
|
3924
|
+
} catch (error) {
|
|
3925
|
+
ctx.write(` ${error.message}
|
|
3926
|
+
`);
|
|
3927
|
+
if (attempt === ctx.maxFieldAttempts) {
|
|
3928
|
+
ctx.write(
|
|
3929
|
+
` Giving up on "${sanitizeTerminalText(field.key)}" after ${ctx.maxFieldAttempts} attempts; declining this request.
|
|
3930
|
+
`
|
|
3931
|
+
);
|
|
3932
|
+
return { action: "decline" };
|
|
3933
|
+
}
|
|
3934
|
+
}
|
|
3935
|
+
}
|
|
3936
|
+
if (coerced && "value" in coerced) {
|
|
3937
|
+
content[field.key] = coerced.value;
|
|
3938
|
+
}
|
|
3939
|
+
}
|
|
3940
|
+
return { action: "accept", content };
|
|
3941
|
+
}
|
|
3942
|
+
async function askAction(reader, write, signal, opts) {
|
|
3943
|
+
for (; ; ) {
|
|
3944
|
+
throwIfAborted(signal);
|
|
3945
|
+
const raw = (await reader.question(
|
|
3946
|
+
`[a]${opts.acceptLabel.slice(1)} / [d]ecline / [c]ancel: `,
|
|
3947
|
+
{ signal }
|
|
3948
|
+
)).trim().toLowerCase();
|
|
3949
|
+
if (raw === "a" || raw === opts.acceptLabel) return "accept";
|
|
3950
|
+
if (raw === "d" || raw === "decline") return "decline";
|
|
3951
|
+
if (raw === "c" || raw === "cancel") return "cancel";
|
|
3952
|
+
write(` Please answer a, d, or c.
|
|
3953
|
+
`);
|
|
3954
|
+
}
|
|
3955
|
+
}
|
|
3956
|
+
function throwIfAborted(signal) {
|
|
3957
|
+
if (signal?.aborted) {
|
|
3958
|
+
throw new MrtrCollectAbortError();
|
|
3959
|
+
}
|
|
3960
|
+
}
|
|
3961
|
+
function isRecord(value) {
|
|
3962
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
3963
|
+
}
|
|
3964
|
+
function createReadlineReader() {
|
|
3965
|
+
const rl = readline.createInterface({
|
|
3966
|
+
input: process.stdin,
|
|
3967
|
+
// Prompts to stderr so stdout stays a clean machine-readable result.
|
|
3968
|
+
output: process.stderr
|
|
3969
|
+
});
|
|
3970
|
+
return {
|
|
3971
|
+
question: async (prompt, options) => {
|
|
3972
|
+
try {
|
|
3973
|
+
return await (options?.signal ? rl.question(prompt, { signal: options.signal }) : rl.question(prompt));
|
|
3974
|
+
} catch (error) {
|
|
3975
|
+
if (options?.signal?.aborted || error?.name === "AbortError") {
|
|
3976
|
+
throw new MrtrCollectAbortError();
|
|
3977
|
+
}
|
|
3978
|
+
throw error;
|
|
3979
|
+
}
|
|
3980
|
+
},
|
|
3981
|
+
close: () => rl.close()
|
|
3982
|
+
};
|
|
3983
|
+
}
|
|
3984
|
+
function closeReadlineReader(reader) {
|
|
3985
|
+
reader.close?.();
|
|
3986
|
+
}
|
|
3475
3987
|
|
|
3476
3988
|
// src/lib/ephemeral.ts
|
|
3989
|
+
function applyInteractiveElicitationCapability(config) {
|
|
3990
|
+
const exact = config.clientCapabilities;
|
|
3991
|
+
if (exact) {
|
|
3992
|
+
if (exact.elicitation == null) {
|
|
3993
|
+
throw usageError(
|
|
3994
|
+
'--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.'
|
|
3995
|
+
);
|
|
3996
|
+
}
|
|
3997
|
+
return config;
|
|
3998
|
+
}
|
|
3999
|
+
const capabilities = config.capabilities ?? {};
|
|
4000
|
+
return {
|
|
4001
|
+
...config,
|
|
4002
|
+
capabilities: {
|
|
4003
|
+
...capabilities,
|
|
4004
|
+
elicitation: {
|
|
4005
|
+
...INTERACTIVE_ELICITATION_CAPABILITY,
|
|
4006
|
+
...isRecord2(capabilities.elicitation) ? capabilities.elicitation : {}
|
|
4007
|
+
}
|
|
4008
|
+
}
|
|
4009
|
+
};
|
|
4010
|
+
}
|
|
4011
|
+
function isRecord2(value) {
|
|
4012
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
4013
|
+
}
|
|
3477
4014
|
async function withEphemeralManager(config, fn, options) {
|
|
3478
|
-
const
|
|
4015
|
+
const hostConfig = options?.host ? applyHostToConfig(config, options.host) : config;
|
|
4016
|
+
const resolvedConfig = options?.interactiveElicitation ? applyInteractiveElicitationCapability(hostConfig) : hostConfig;
|
|
3479
4017
|
return withEphemeralClient(resolvedConfig, fn, {
|
|
3480
4018
|
serverId: "__cli__",
|
|
3481
4019
|
clientName: "mcpjam",
|
|
3482
4020
|
timeout: options?.timeout ?? 3e4,
|
|
3483
4021
|
rpcLogger: options?.rpcLogger,
|
|
3484
|
-
retryPolicy: options?.retryPolicy
|
|
4022
|
+
retryPolicy: options?.retryPolicy,
|
|
4023
|
+
beforeConnect: options?.beforeConnect
|
|
3485
4024
|
});
|
|
3486
4025
|
}
|
|
3487
4026
|
|
|
@@ -3607,9 +4146,13 @@ async function runPlatformCommand(options, timeoutMs, execute) {
|
|
|
3607
4146
|
const controller = new AbortController();
|
|
3608
4147
|
const timeoutHandle = setTimeout(() => {
|
|
3609
4148
|
controller.abort(
|
|
3610
|
-
new PlatformApiError(
|
|
3611
|
-
|
|
3612
|
-
|
|
4149
|
+
new PlatformApiError(
|
|
4150
|
+
`Request timed out after ${timeoutMs}ms`,
|
|
4151
|
+
"TIMEOUT",
|
|
4152
|
+
{
|
|
4153
|
+
status: 0
|
|
4154
|
+
}
|
|
4155
|
+
)
|
|
3613
4156
|
);
|
|
3614
4157
|
}, timeoutMs);
|
|
3615
4158
|
timeoutHandle.unref?.();
|
|
@@ -3625,7 +4168,7 @@ async function runPlatformCommand(options, timeoutMs, execute) {
|
|
|
3625
4168
|
clearTimeout(timeoutHandle);
|
|
3626
4169
|
}
|
|
3627
4170
|
}
|
|
3628
|
-
function
|
|
4171
|
+
function loadBlueprintText(file) {
|
|
3629
4172
|
let text;
|
|
3630
4173
|
try {
|
|
3631
4174
|
text = file === "-" ? readFileSync(0, "utf8") : readFileSync(file, "utf8");
|
|
@@ -3645,12 +4188,12 @@ function validateInput(op, raw) {
|
|
|
3645
4188
|
}
|
|
3646
4189
|
return parsed.data;
|
|
3647
4190
|
}
|
|
3648
|
-
function
|
|
3649
|
-
const env = program.command("
|
|
3650
|
-
"List, build, and manage custom Computer
|
|
4191
|
+
function registerImagesCommands(program) {
|
|
4192
|
+
const env = program.command("images").description(
|
|
4193
|
+
"List, build, and manage custom Computer sandbox images (blueprints) in your hosted MCPJam projects"
|
|
3651
4194
|
);
|
|
3652
4195
|
addPlatformOptions(
|
|
3653
|
-
env.command("list").description("List the
|
|
4196
|
+
env.command("list").description("List the sandbox images in a project").option(
|
|
3654
4197
|
"--project <id-or-name>",
|
|
3655
4198
|
"Project name or ID (defaults to the most recently updated project)"
|
|
3656
4199
|
)
|
|
@@ -3659,7 +4202,7 @@ function registerEnvironmentsCommands(program) {
|
|
|
3659
4202
|
const result = await runPlatformCommand(
|
|
3660
4203
|
options,
|
|
3661
4204
|
globalOptions.timeout,
|
|
3662
|
-
({ client, signal }) =>
|
|
4205
|
+
({ client, signal }) => listImagesOperation.execute(
|
|
3663
4206
|
{ project: options.project },
|
|
3664
4207
|
{ client, signal }
|
|
3665
4208
|
)
|
|
@@ -3667,15 +4210,17 @@ function registerEnvironmentsCommands(program) {
|
|
|
3667
4210
|
writeResult(result, globalOptions.format);
|
|
3668
4211
|
});
|
|
3669
4212
|
addPlatformOptions(
|
|
3670
|
-
env.command("get").description(
|
|
4213
|
+
env.command("get").description(
|
|
4214
|
+
"Show one sandbox image's blueprint and latest build status"
|
|
4215
|
+
).requiredOption("--image <id-or-name>", "Sandbox image name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
3671
4216
|
).action(
|
|
3672
4217
|
async (options, command) => {
|
|
3673
4218
|
const globalOptions = getGlobalOptions(command);
|
|
3674
4219
|
const result = await runPlatformCommand(
|
|
3675
4220
|
options,
|
|
3676
4221
|
globalOptions.timeout,
|
|
3677
|
-
({ client, signal }) =>
|
|
3678
|
-
{ project: options.project,
|
|
4222
|
+
({ client, signal }) => getImageOperation.execute(
|
|
4223
|
+
{ project: options.project, image: options.image },
|
|
3679
4224
|
{ client, signal }
|
|
3680
4225
|
)
|
|
3681
4226
|
);
|
|
@@ -3683,57 +4228,84 @@ function registerEnvironmentsCommands(program) {
|
|
|
3683
4228
|
}
|
|
3684
4229
|
);
|
|
3685
4230
|
addPlatformOptions(
|
|
3686
|
-
env.command("create").description(
|
|
4231
|
+
env.command("create").description(
|
|
4232
|
+
"Create a sandbox image from a blueprint YAML file (--file, or - for stdin)"
|
|
4233
|
+
).requiredOption("--name <name>", "Display name for the new sandbox image").requiredOption(
|
|
3687
4234
|
"--file <path>",
|
|
3688
|
-
"
|
|
4235
|
+
"Blueprint YAML path, or - to read it from stdin"
|
|
3689
4236
|
).option("--project <id-or-name>", "Project name or ID")
|
|
3690
4237
|
).action(
|
|
3691
4238
|
async (options, command) => {
|
|
3692
4239
|
const globalOptions = getGlobalOptions(command);
|
|
3693
|
-
const
|
|
3694
|
-
const input = validateInput(
|
|
4240
|
+
const blueprint = loadBlueprintText(options.file);
|
|
4241
|
+
const input = validateInput(createImageOperation, {
|
|
3695
4242
|
project: options.project,
|
|
3696
4243
|
name: options.name,
|
|
3697
|
-
|
|
4244
|
+
blueprint
|
|
3698
4245
|
});
|
|
3699
4246
|
const result = await runPlatformCommand(
|
|
3700
4247
|
options,
|
|
3701
4248
|
globalOptions.timeout,
|
|
3702
|
-
({ client, signal }) =>
|
|
4249
|
+
({ client, signal }) => createImageOperation.execute(input, { client, signal })
|
|
3703
4250
|
);
|
|
3704
4251
|
writeResult(result, globalOptions.format);
|
|
3705
4252
|
}
|
|
3706
4253
|
);
|
|
3707
4254
|
addPlatformOptions(
|
|
3708
|
-
env.command("
|
|
4255
|
+
env.command("validate").description(
|
|
4256
|
+
"Lint a blueprint YAML file without saving it (--file, or - for stdin)"
|
|
4257
|
+
).requiredOption(
|
|
4258
|
+
"--file <path>",
|
|
4259
|
+
"Blueprint YAML path, or - to read it from stdin"
|
|
4260
|
+
).option("--project <id-or-name>", "Project name or ID")
|
|
3709
4261
|
).action(
|
|
3710
4262
|
async (options, command) => {
|
|
3711
4263
|
const globalOptions = getGlobalOptions(command);
|
|
3712
|
-
const
|
|
3713
|
-
const input = validateInput(
|
|
4264
|
+
const blueprint = loadBlueprintText(options.file);
|
|
4265
|
+
const input = validateInput(validateImageBlueprintOperation, {
|
|
3714
4266
|
project: options.project,
|
|
3715
|
-
|
|
4267
|
+
blueprint
|
|
4268
|
+
});
|
|
4269
|
+
const result = await runPlatformCommand(
|
|
4270
|
+
options,
|
|
4271
|
+
globalOptions.timeout,
|
|
4272
|
+
({ client, signal }) => validateImageBlueprintOperation.execute(input, { client, signal })
|
|
4273
|
+
);
|
|
4274
|
+
writeResult(result, globalOptions.format);
|
|
4275
|
+
}
|
|
4276
|
+
);
|
|
4277
|
+
addPlatformOptions(
|
|
4278
|
+
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)")
|
|
4279
|
+
).action(
|
|
4280
|
+
async (options, command) => {
|
|
4281
|
+
const globalOptions = getGlobalOptions(command);
|
|
4282
|
+
const blueprint = options.file !== void 0 ? loadBlueprintText(options.file) : void 0;
|
|
4283
|
+
const input = validateInput(updateImageOperation, {
|
|
4284
|
+
project: options.project,
|
|
4285
|
+
image: options.image,
|
|
3716
4286
|
...options.name !== void 0 ? { name: options.name } : {},
|
|
3717
|
-
...
|
|
4287
|
+
...blueprint !== void 0 ? { blueprint } : {}
|
|
3718
4288
|
});
|
|
3719
4289
|
const result = await runPlatformCommand(
|
|
3720
4290
|
options,
|
|
3721
4291
|
globalOptions.timeout,
|
|
3722
|
-
({ client, signal }) =>
|
|
4292
|
+
({ client, signal }) => updateImageOperation.execute(input, { client, signal })
|
|
3723
4293
|
);
|
|
3724
4294
|
writeResult(result, globalOptions.format);
|
|
3725
4295
|
}
|
|
3726
4296
|
);
|
|
3727
4297
|
addPlatformOptions(
|
|
3728
|
-
env.command("build").description(
|
|
4298
|
+
env.command("build").description(
|
|
4299
|
+
"Build the sandbox image (async \u2014 poll `images logs` for status)"
|
|
4300
|
+
).requiredOption("--image <id-or-name>", "Sandbox image name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
3729
4301
|
).action(
|
|
3730
4302
|
async (options, command) => {
|
|
3731
4303
|
const globalOptions = getGlobalOptions(command);
|
|
3732
4304
|
const result = await runPlatformCommand(
|
|
3733
4305
|
options,
|
|
3734
4306
|
globalOptions.timeout,
|
|
3735
|
-
({ client, signal }) =>
|
|
3736
|
-
{ project: options.project,
|
|
4307
|
+
({ client, signal }) => buildImageOperation.execute(
|
|
4308
|
+
{ project: options.project, image: options.image },
|
|
3737
4309
|
{ client, signal }
|
|
3738
4310
|
)
|
|
3739
4311
|
);
|
|
@@ -3741,15 +4313,17 @@ function registerEnvironmentsCommands(program) {
|
|
|
3741
4313
|
}
|
|
3742
4314
|
);
|
|
3743
4315
|
addPlatformOptions(
|
|
3744
|
-
env.command("logs").description(
|
|
4316
|
+
env.command("logs").description(
|
|
4317
|
+
"Show a sandbox image's builds (newest first) with their log preview"
|
|
4318
|
+
).requiredOption("--image <id-or-name>", "Sandbox image name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
3745
4319
|
).action(
|
|
3746
4320
|
async (options, command) => {
|
|
3747
4321
|
const globalOptions = getGlobalOptions(command);
|
|
3748
4322
|
const result = await runPlatformCommand(
|
|
3749
4323
|
options,
|
|
3750
4324
|
globalOptions.timeout,
|
|
3751
|
-
({ client, signal }) =>
|
|
3752
|
-
{ project: options.project,
|
|
4325
|
+
({ client, signal }) => listImageBuildsOperation.execute(
|
|
4326
|
+
{ project: options.project, image: options.image },
|
|
3753
4327
|
{ client, signal }
|
|
3754
4328
|
)
|
|
3755
4329
|
);
|
|
@@ -3758,16 +4332,16 @@ function registerEnvironmentsCommands(program) {
|
|
|
3758
4332
|
);
|
|
3759
4333
|
addPlatformOptions(
|
|
3760
4334
|
env.command("use").description(
|
|
3761
|
-
"Boot your computer from this
|
|
3762
|
-
).requiredOption("--
|
|
4335
|
+
"Boot your computer from this sandbox image (rebuilds it \u2014 installed files are wiped)"
|
|
4336
|
+
).requiredOption("--image <id-or-name>", "Sandbox image name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
3763
4337
|
).action(
|
|
3764
4338
|
async (options, command) => {
|
|
3765
4339
|
const globalOptions = getGlobalOptions(command);
|
|
3766
4340
|
const result = await runPlatformCommand(
|
|
3767
4341
|
options,
|
|
3768
4342
|
globalOptions.timeout,
|
|
3769
|
-
({ client, signal }) =>
|
|
3770
|
-
{ project: options.project,
|
|
4343
|
+
({ client, signal }) => useImageOperation.execute(
|
|
4344
|
+
{ project: options.project, image: options.image },
|
|
3771
4345
|
{ client, signal }
|
|
3772
4346
|
)
|
|
3773
4347
|
);
|
|
@@ -3775,7 +4349,9 @@ function registerEnvironmentsCommands(program) {
|
|
|
3775
4349
|
}
|
|
3776
4350
|
);
|
|
3777
4351
|
addPlatformOptions(
|
|
3778
|
-
env.command("reset").description(
|
|
4352
|
+
env.command("reset").description(
|
|
4353
|
+
"Reset your computer to its current image (wipes mutable state)"
|
|
4354
|
+
).option("--project <id-or-name>", "Project name or ID")
|
|
3779
4355
|
).action(async (options, command) => {
|
|
3780
4356
|
const globalOptions = getGlobalOptions(command);
|
|
3781
4357
|
const result = await runPlatformCommand(
|
|
@@ -3789,15 +4365,17 @@ function registerEnvironmentsCommands(program) {
|
|
|
3789
4365
|
writeResult(result, globalOptions.format);
|
|
3790
4366
|
});
|
|
3791
4367
|
addPlatformOptions(
|
|
3792
|
-
env.command("promote").description(
|
|
4368
|
+
env.command("promote").description(
|
|
4369
|
+
"Share a personal-draft sandbox image with the whole project (admin only)"
|
|
4370
|
+
).requiredOption("--image <id-or-name>", "Sandbox image name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
3793
4371
|
).action(
|
|
3794
4372
|
async (options, command) => {
|
|
3795
4373
|
const globalOptions = getGlobalOptions(command);
|
|
3796
4374
|
const result = await runPlatformCommand(
|
|
3797
4375
|
options,
|
|
3798
4376
|
globalOptions.timeout,
|
|
3799
|
-
({ client, signal }) =>
|
|
3800
|
-
{ project: options.project,
|
|
4377
|
+
({ client, signal }) => promoteImageOperation.execute(
|
|
4378
|
+
{ project: options.project, image: options.image },
|
|
3801
4379
|
{ client, signal }
|
|
3802
4380
|
)
|
|
3803
4381
|
);
|
|
@@ -3805,15 +4383,15 @@ function registerEnvironmentsCommands(program) {
|
|
|
3805
4383
|
}
|
|
3806
4384
|
);
|
|
3807
4385
|
addPlatformOptions(
|
|
3808
|
-
env.command("delete").description("Permanently delete
|
|
4386
|
+
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
4387
|
).action(
|
|
3810
4388
|
async (options, command) => {
|
|
3811
4389
|
const globalOptions = getGlobalOptions(command);
|
|
3812
4390
|
const result = await runPlatformCommand(
|
|
3813
4391
|
options,
|
|
3814
4392
|
globalOptions.timeout,
|
|
3815
|
-
({ client, signal }) =>
|
|
3816
|
-
{ project: options.project,
|
|
4393
|
+
({ client, signal }) => deleteImageOperation.execute(
|
|
4394
|
+
{ project: options.project, image: options.image },
|
|
3817
4395
|
{ client, signal }
|
|
3818
4396
|
)
|
|
3819
4397
|
);
|
|
@@ -3821,34 +4399,291 @@ function registerEnvironmentsCommands(program) {
|
|
|
3821
4399
|
}
|
|
3822
4400
|
);
|
|
3823
4401
|
}
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
function asString(value) {
|
|
3830
|
-
return typeof value === "string" ? value : void 0;
|
|
4402
|
+
function addPlatformOptions2(command) {
|
|
4403
|
+
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
4404
|
+
"--api-url <url>",
|
|
4405
|
+
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
4406
|
+
);
|
|
3831
4407
|
}
|
|
3832
|
-
function
|
|
3833
|
-
const
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
4408
|
+
async function runPlatformCommand2(options, timeoutMs, execute) {
|
|
4409
|
+
const controller = new AbortController();
|
|
4410
|
+
const timeoutHandle = setTimeout(() => {
|
|
4411
|
+
controller.abort(
|
|
4412
|
+
new PlatformApiError(
|
|
4413
|
+
`Request timed out after ${timeoutMs}ms`,
|
|
4414
|
+
"TIMEOUT",
|
|
4415
|
+
{
|
|
4416
|
+
status: 0
|
|
4417
|
+
}
|
|
4418
|
+
)
|
|
4419
|
+
);
|
|
4420
|
+
}, timeoutMs);
|
|
4421
|
+
timeoutHandle.unref?.();
|
|
4422
|
+
try {
|
|
4423
|
+
const { client } = buildPlatformClient({ ...options, timeoutMs });
|
|
4424
|
+
return await execute({ client, signal: controller.signal });
|
|
4425
|
+
} catch (error) {
|
|
4426
|
+
if (controller.signal.aborted && controller.signal.reason instanceof PlatformApiError) {
|
|
4427
|
+
throw toCliError(controller.signal.reason);
|
|
4428
|
+
}
|
|
4429
|
+
throw toCliError(error);
|
|
4430
|
+
} finally {
|
|
4431
|
+
clearTimeout(timeoutHandle);
|
|
4432
|
+
}
|
|
4433
|
+
}
|
|
4434
|
+
function validateInput2(op, raw) {
|
|
4435
|
+
const parsed = op.inputSchema.safeParse(raw);
|
|
4436
|
+
if (!parsed.success) {
|
|
4437
|
+
const detail = parsed.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
|
|
4438
|
+
throw usageError(`Invalid input: ${detail}`);
|
|
4439
|
+
}
|
|
4440
|
+
return parsed.data;
|
|
4441
|
+
}
|
|
4442
|
+
function loadJsonObject(options) {
|
|
4443
|
+
if (options.file !== void 0 && options.json !== void 0) {
|
|
4444
|
+
throw usageError("Provide either --file or --json, not both.");
|
|
4445
|
+
}
|
|
4446
|
+
let base;
|
|
4447
|
+
if (options.file !== void 0) {
|
|
4448
|
+
let text;
|
|
4449
|
+
try {
|
|
4450
|
+
text = options.file === "-" ? readFileSync(0, "utf8") : readFileSync(options.file, "utf8");
|
|
4451
|
+
} catch (error) {
|
|
4452
|
+
throw usageError(`Failed to read --file "${options.file}".`, {
|
|
4453
|
+
source: error instanceof Error ? error.message : String(error)
|
|
4454
|
+
});
|
|
4455
|
+
}
|
|
4456
|
+
if (text.trim() === "") throw usageError("--file input is empty.");
|
|
4457
|
+
try {
|
|
4458
|
+
base = JSON.parse(text);
|
|
4459
|
+
} catch (error) {
|
|
4460
|
+
throw usageError("--file must contain valid JSON.", {
|
|
4461
|
+
source: error instanceof Error ? error.message : String(error)
|
|
4462
|
+
});
|
|
4463
|
+
}
|
|
4464
|
+
} else if (options.json !== void 0) {
|
|
4465
|
+
base = new JsonInputContext().parseJsonInputRecord(options.json, "--json");
|
|
4466
|
+
} else {
|
|
4467
|
+
return void 0;
|
|
4468
|
+
}
|
|
4469
|
+
if (typeof base !== "object" || base === null || Array.isArray(base)) {
|
|
4470
|
+
throw usageError("Environment input must be a JSON object.");
|
|
4471
|
+
}
|
|
4472
|
+
return base;
|
|
4473
|
+
}
|
|
4474
|
+
function parseRevision(raw) {
|
|
4475
|
+
const value = Number(raw);
|
|
4476
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
4477
|
+
throw usageError(
|
|
4478
|
+
"--expected-revision must be a non-negative integer (read it from `mcpjam environments get`)."
|
|
4479
|
+
);
|
|
4480
|
+
}
|
|
4481
|
+
return value;
|
|
4482
|
+
}
|
|
4483
|
+
function registerEnvironmentsCommands(program) {
|
|
4484
|
+
const environments = program.command("environments").description(
|
|
4485
|
+
"List, create, and manage the project environments (host + servers + pinned skills/plugins) in your hosted MCPJam projects"
|
|
4486
|
+
);
|
|
4487
|
+
addPlatformOptions2(
|
|
4488
|
+
environments.command("list").description("List the project environments in a project").option(
|
|
4489
|
+
"--project <id-or-name>",
|
|
4490
|
+
"Project name or ID (defaults to the most recently updated project)"
|
|
4491
|
+
).option(
|
|
4492
|
+
"--include-archived",
|
|
4493
|
+
"Include archived environments (needed to find one to restore)"
|
|
4494
|
+
)
|
|
4495
|
+
).action(
|
|
4496
|
+
async (options, command) => {
|
|
4497
|
+
const globalOptions = getGlobalOptions(command);
|
|
4498
|
+
const result = await runPlatformCommand2(
|
|
4499
|
+
options,
|
|
4500
|
+
globalOptions.timeout,
|
|
4501
|
+
({ client, signal }) => listEnvironmentsOperation.execute(
|
|
4502
|
+
{
|
|
4503
|
+
project: options.project,
|
|
4504
|
+
...options.includeArchived ? { includeArchived: true } : {}
|
|
4505
|
+
},
|
|
4506
|
+
{ client, signal }
|
|
4507
|
+
)
|
|
4508
|
+
);
|
|
4509
|
+
writeResult(result, globalOptions.format);
|
|
4510
|
+
}
|
|
4511
|
+
);
|
|
4512
|
+
addPlatformOptions2(
|
|
4513
|
+
environments.command("get").description(
|
|
4514
|
+
"Show one environment's settings and its current revision (pass that revision to update/archive/restore)"
|
|
4515
|
+
).requiredOption("--environment <id-or-name>", "Environment name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
4516
|
+
).action(
|
|
4517
|
+
async (options, command) => {
|
|
4518
|
+
const globalOptions = getGlobalOptions(command);
|
|
4519
|
+
const result = await runPlatformCommand2(
|
|
4520
|
+
options,
|
|
4521
|
+
globalOptions.timeout,
|
|
4522
|
+
({ client, signal }) => getEnvironmentOperation.execute(
|
|
4523
|
+
{ project: options.project, environment: options.environment },
|
|
4524
|
+
{ client, signal }
|
|
4525
|
+
)
|
|
4526
|
+
);
|
|
4527
|
+
writeResult(result, globalOptions.format);
|
|
4528
|
+
}
|
|
4529
|
+
);
|
|
4530
|
+
addPlatformOptions2(
|
|
4531
|
+
environments.command("resolve").description(
|
|
4532
|
+
"Preview what an environment resolves to right now: host config, closed server set, and pinned plugin versions"
|
|
4533
|
+
).requiredOption("--environment <id-or-name>", "Environment name or ID").option("--project <id-or-name>", "Project name or ID")
|
|
4534
|
+
).action(
|
|
4535
|
+
async (options, command) => {
|
|
4536
|
+
const globalOptions = getGlobalOptions(command);
|
|
4537
|
+
const result = await runPlatformCommand2(
|
|
4538
|
+
options,
|
|
4539
|
+
globalOptions.timeout,
|
|
4540
|
+
({ client, signal }) => resolveEnvironmentOperation.execute(
|
|
4541
|
+
{ project: options.project, environment: options.environment },
|
|
4542
|
+
{ client, signal }
|
|
4543
|
+
)
|
|
4544
|
+
);
|
|
4545
|
+
writeResult(result, globalOptions.format);
|
|
4546
|
+
}
|
|
4547
|
+
);
|
|
4548
|
+
addPlatformOptions2(
|
|
4549
|
+
environments.command("create").description(
|
|
4550
|
+
"Create a project environment (requires project admin). Body fields may be supplied via --file/--json"
|
|
4551
|
+
).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(
|
|
4552
|
+
"--file <path>",
|
|
4553
|
+
"Environment JSON file with any of name/hostId/description/serverAttachmentId/skillSelection/pluginVersionIds (or - for stdin)"
|
|
4554
|
+
).option("--json <json>", "Inline environment JSON (or @file, or -)")
|
|
4555
|
+
).action(
|
|
4556
|
+
async (options, command) => {
|
|
4557
|
+
const globalOptions = getGlobalOptions(command);
|
|
4558
|
+
const body = loadJsonObject(options) ?? {};
|
|
4559
|
+
const input = validateInput2(createEnvironmentOperation, {
|
|
4560
|
+
...body,
|
|
4561
|
+
...options.project !== void 0 ? { project: options.project } : {},
|
|
4562
|
+
...options.name !== void 0 ? { name: options.name } : {},
|
|
4563
|
+
...options.hostId !== void 0 ? { hostId: options.hostId } : {},
|
|
4564
|
+
...options.description !== void 0 ? { description: options.description } : {}
|
|
4565
|
+
});
|
|
4566
|
+
const result = await runPlatformCommand2(
|
|
4567
|
+
options,
|
|
4568
|
+
globalOptions.timeout,
|
|
4569
|
+
({ client, signal }) => createEnvironmentOperation.execute(input, { client, signal })
|
|
4570
|
+
);
|
|
4571
|
+
writeResult(result, globalOptions.format);
|
|
4572
|
+
}
|
|
4573
|
+
);
|
|
4574
|
+
addPlatformOptions2(
|
|
4575
|
+
environments.command("update").description(
|
|
4576
|
+
"Edit an environment. Only the fields you pass change; use --file/--json with a null value to clear serverAttachmentId, skillSelection, or pluginVersionIds"
|
|
4577
|
+
).requiredOption("--environment <id-or-name>", "Environment name or ID").requiredOption(
|
|
4578
|
+
"--expected-revision <n>",
|
|
4579
|
+
"The revision you last read (from `environments get`); a stale value is rejected instead of overwriting a concurrent edit"
|
|
4580
|
+
).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(
|
|
4581
|
+
"--description <text>",
|
|
4582
|
+
"New description (empty string clears it)"
|
|
4583
|
+
).option(
|
|
4584
|
+
"--file <path>",
|
|
4585
|
+
"Environment JSON file with the fields to change (or - for stdin)"
|
|
4586
|
+
).option("--json <json>", "Inline environment JSON (or @file, or -)")
|
|
4587
|
+
).action(
|
|
4588
|
+
async (options, command) => {
|
|
4589
|
+
const globalOptions = getGlobalOptions(command);
|
|
4590
|
+
const body = loadJsonObject(options) ?? {};
|
|
4591
|
+
const input = validateInput2(updateEnvironmentOperation, {
|
|
4592
|
+
...body,
|
|
4593
|
+
...options.project !== void 0 ? { project: options.project } : {},
|
|
4594
|
+
environment: options.environment,
|
|
4595
|
+
expectedRevision: parseRevision(options.expectedRevision),
|
|
4596
|
+
...options.name !== void 0 ? { name: options.name } : {},
|
|
4597
|
+
...options.hostId !== void 0 ? { hostId: options.hostId } : {},
|
|
4598
|
+
...options.description !== void 0 ? { description: options.description } : {}
|
|
4599
|
+
});
|
|
4600
|
+
const result = await runPlatformCommand2(
|
|
4601
|
+
options,
|
|
4602
|
+
globalOptions.timeout,
|
|
4603
|
+
({ client, signal }) => updateEnvironmentOperation.execute(input, { client, signal })
|
|
4604
|
+
);
|
|
4605
|
+
writeResult(result, globalOptions.format);
|
|
4606
|
+
}
|
|
4607
|
+
);
|
|
4608
|
+
addPlatformOptions2(
|
|
4609
|
+
environments.command("archive").description(
|
|
4610
|
+
"Archive an environment (reversible; frees its name for a new one)"
|
|
4611
|
+
).requiredOption("--environment <id-or-name>", "Environment name or ID").requiredOption(
|
|
4612
|
+
"--expected-revision <n>",
|
|
4613
|
+
"The revision you last read (from `environments get`)"
|
|
4614
|
+
).option("--project <id-or-name>", "Project name or ID")
|
|
4615
|
+
).action(
|
|
4616
|
+
async (options, command) => {
|
|
4617
|
+
const globalOptions = getGlobalOptions(command);
|
|
4618
|
+
const result = await runPlatformCommand2(
|
|
4619
|
+
options,
|
|
4620
|
+
globalOptions.timeout,
|
|
4621
|
+
({ client, signal }) => archiveEnvironmentOperation.execute(
|
|
4622
|
+
{
|
|
4623
|
+
project: options.project,
|
|
4624
|
+
environment: options.environment,
|
|
4625
|
+
expectedRevision: parseRevision(options.expectedRevision)
|
|
4626
|
+
},
|
|
4627
|
+
{ client, signal }
|
|
4628
|
+
)
|
|
4629
|
+
);
|
|
4630
|
+
writeResult(result, globalOptions.format);
|
|
4631
|
+
}
|
|
4632
|
+
);
|
|
4633
|
+
addPlatformOptions2(
|
|
4634
|
+
environments.command("restore").description(
|
|
4635
|
+
"Restore an archived environment. Plugin pins whose version no longer exists are dropped \u2014 check the returned pluginVersionIds"
|
|
4636
|
+
).requiredOption("--environment <id-or-name>", "Environment name or ID").requiredOption(
|
|
4637
|
+
"--expected-revision <n>",
|
|
4638
|
+
"The revision you last read (from `environments get --include-archived` via list)"
|
|
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 }) => restoreEnvironmentOperation.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
|
+
}
|
|
4659
|
+
|
|
4660
|
+
// src/lib/eval-screenshots.ts
|
|
4661
|
+
function asRecord(value) {
|
|
4662
|
+
return typeof value === "object" && value !== null ? value : null;
|
|
4663
|
+
}
|
|
4664
|
+
function asString(value) {
|
|
4665
|
+
return typeof value === "string" ? value : void 0;
|
|
4666
|
+
}
|
|
4667
|
+
function extractRenderedScreenshots(result) {
|
|
4668
|
+
const root = asRecord(result);
|
|
4669
|
+
if (!root) return [];
|
|
4670
|
+
const trace = asRecord(root.trace) ?? root;
|
|
4671
|
+
const screenshots = [];
|
|
4672
|
+
const observations = trace.widgetRenderObservations;
|
|
4673
|
+
if (Array.isArray(observations)) {
|
|
4674
|
+
for (const entry of observations) {
|
|
4675
|
+
const obs = asRecord(entry);
|
|
4676
|
+
if (!obs) continue;
|
|
4677
|
+
const status = asString(obs.status);
|
|
4678
|
+
const screenshotUrl = asString(obs.screenshotUrl);
|
|
4679
|
+
if (status !== "rendered" || !screenshotUrl) continue;
|
|
4680
|
+
screenshots.push({
|
|
4681
|
+
status,
|
|
4682
|
+
screenshotUrl,
|
|
4683
|
+
toolName: asString(obs.toolName),
|
|
4684
|
+
toolCallId: asString(obs.toolCallId),
|
|
4685
|
+
promptIndex: typeof obs.promptIndex === "number" ? obs.promptIndex : void 0
|
|
4686
|
+
});
|
|
3852
4687
|
}
|
|
3853
4688
|
}
|
|
3854
4689
|
const interactions = trace.browserInteractionSteps;
|
|
@@ -3932,13 +4767,13 @@ function encodeInlineImage(data, protocol) {
|
|
|
3932
4767
|
}
|
|
3933
4768
|
|
|
3934
4769
|
// src/commands/eval.ts
|
|
3935
|
-
function
|
|
4770
|
+
function addPlatformOptions3(command) {
|
|
3936
4771
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
3937
4772
|
"--api-url <url>",
|
|
3938
4773
|
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
3939
4774
|
);
|
|
3940
4775
|
}
|
|
3941
|
-
async function
|
|
4776
|
+
async function runPlatformCommand3(options, timeoutMs, execute) {
|
|
3942
4777
|
const controller = new AbortController();
|
|
3943
4778
|
const timeoutHandle = setTimeout(() => {
|
|
3944
4779
|
controller.abort(
|
|
@@ -4048,7 +4883,7 @@ function validateOpInput(op, raw) {
|
|
|
4048
4883
|
}
|
|
4049
4884
|
async function executeOp(op, input, options, command) {
|
|
4050
4885
|
const globalOptions = getGlobalOptions(command);
|
|
4051
|
-
const result = await
|
|
4886
|
+
const result = await runPlatformCommand3(
|
|
4052
4887
|
options,
|
|
4053
4888
|
globalOptions.timeout,
|
|
4054
4889
|
({ client, signal }) => op.execute(input, { client, signal })
|
|
@@ -4148,7 +4983,7 @@ function resolveScreenshotPath(out, shot, index, total) {
|
|
|
4148
4983
|
}
|
|
4149
4984
|
function registerEvalCommands(program) {
|
|
4150
4985
|
const evals = program.command("eval").description("Author and run eval suites in your hosted MCPJam projects");
|
|
4151
|
-
|
|
4986
|
+
addPlatformOptions3(
|
|
4152
4987
|
evals.command("create").description(
|
|
4153
4988
|
"Create a runnable eval suite from authored test cases (does not run it)"
|
|
4154
4989
|
).option(
|
|
@@ -4173,21 +5008,21 @@ function registerEvalCommands(program) {
|
|
|
4173
5008
|
).action(async (options, command) => {
|
|
4174
5009
|
const globalOptions = getGlobalOptions(command);
|
|
4175
5010
|
const input = loadSuiteDefinition(options);
|
|
4176
|
-
const result = await
|
|
5011
|
+
const result = await runPlatformCommand3(
|
|
4177
5012
|
options,
|
|
4178
5013
|
globalOptions.timeout,
|
|
4179
5014
|
({ client, signal }) => createEvalSuiteOperation.execute(input, { client, signal })
|
|
4180
5015
|
);
|
|
4181
5016
|
writeResult(result, globalOptions.format);
|
|
4182
5017
|
});
|
|
4183
|
-
|
|
5018
|
+
addPlatformOptions3(
|
|
4184
5019
|
evals.command("list").description("List the eval suites saved in a project").option(
|
|
4185
5020
|
"--project <id-or-name>",
|
|
4186
5021
|
"Project name or ID (defaults to the most recently updated project)"
|
|
4187
5022
|
)
|
|
4188
5023
|
).action(async (options, command) => {
|
|
4189
5024
|
const globalOptions = getGlobalOptions(command);
|
|
4190
|
-
const result = await
|
|
5025
|
+
const result = await runPlatformCommand3(
|
|
4191
5026
|
options,
|
|
4192
5027
|
globalOptions.timeout,
|
|
4193
5028
|
({ client, signal }) => listEvalSuitesOperation.execute(
|
|
@@ -4197,7 +5032,7 @@ function registerEvalCommands(program) {
|
|
|
4197
5032
|
);
|
|
4198
5033
|
writeResult(result, globalOptions.format);
|
|
4199
5034
|
});
|
|
4200
|
-
|
|
5035
|
+
addPlatformOptions3(
|
|
4201
5036
|
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
5037
|
"--project <id-or-name>",
|
|
4203
5038
|
"Project name or ID (defaults to the most recently updated project)"
|
|
@@ -4208,7 +5043,7 @@ function registerEvalCommands(program) {
|
|
|
4208
5043
|
).action(
|
|
4209
5044
|
async (options, command) => {
|
|
4210
5045
|
const globalOptions = getGlobalOptions(command);
|
|
4211
|
-
const result = await
|
|
5046
|
+
const result = await runPlatformCommand3(
|
|
4212
5047
|
options,
|
|
4213
5048
|
globalOptions.timeout,
|
|
4214
5049
|
({ client, signal }) => runEvalSuiteOperation.execute(
|
|
@@ -4223,12 +5058,12 @@ function registerEvalCommands(program) {
|
|
|
4223
5058
|
writeResult(result, globalOptions.format);
|
|
4224
5059
|
}
|
|
4225
5060
|
);
|
|
4226
|
-
|
|
5061
|
+
addPlatformOptions3(
|
|
4227
5062
|
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
5063
|
).action(
|
|
4229
5064
|
async (options, command) => {
|
|
4230
5065
|
const globalOptions = getGlobalOptions(command);
|
|
4231
|
-
const result = await
|
|
5066
|
+
const result = await runPlatformCommand3(
|
|
4232
5067
|
options,
|
|
4233
5068
|
globalOptions.timeout,
|
|
4234
5069
|
({ client, signal }) => getEvalRunOperation.execute(
|
|
@@ -4239,7 +5074,7 @@ function registerEvalCommands(program) {
|
|
|
4239
5074
|
writeResult(result, globalOptions.format);
|
|
4240
5075
|
}
|
|
4241
5076
|
);
|
|
4242
|
-
|
|
5077
|
+
addPlatformOptions3(
|
|
4243
5078
|
evals.command("cancel").description(
|
|
4244
5079
|
"Cancel an in-flight eval run (no-op if already cancelled; errors if it already finished)"
|
|
4245
5080
|
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption("--project <id-or-name>", "Project name or ID")
|
|
@@ -4254,7 +5089,7 @@ function registerEvalCommands(program) {
|
|
|
4254
5089
|
}
|
|
4255
5090
|
);
|
|
4256
5091
|
const PROJECT_OPT = "Project name or ID (defaults to most recently updated)";
|
|
4257
|
-
|
|
5092
|
+
addPlatformOptions3(
|
|
4258
5093
|
evals.command("iterations").description(
|
|
4259
5094
|
"List per-iteration results for an eval run (pass/fail, tool calls, tokens, latency)"
|
|
4260
5095
|
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
@@ -4272,7 +5107,7 @@ function registerEvalCommands(program) {
|
|
|
4272
5107
|
await executeOp(listEvalRunIterationsOperation, input, options, command);
|
|
4273
5108
|
}
|
|
4274
5109
|
);
|
|
4275
|
-
|
|
5110
|
+
addPlatformOptions3(
|
|
4276
5111
|
evals.command("trace").description(
|
|
4277
5112
|
"Fetch the full trace for one eval iteration (large: full message history + spans)"
|
|
4278
5113
|
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
@@ -4296,7 +5131,7 @@ function registerEvalCommands(program) {
|
|
|
4296
5131
|
);
|
|
4297
5132
|
}
|
|
4298
5133
|
);
|
|
4299
|
-
|
|
5134
|
+
addPlatformOptions3(
|
|
4300
5135
|
evals.command("steps").description(
|
|
4301
5136
|
"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
5137
|
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
@@ -4320,7 +5155,7 @@ function registerEvalCommands(program) {
|
|
|
4320
5155
|
);
|
|
4321
5156
|
}
|
|
4322
5157
|
);
|
|
4323
|
-
|
|
5158
|
+
addPlatformOptions3(
|
|
4324
5159
|
evals.command("screenshot").description(
|
|
4325
5160
|
"Show the widget screenshot(s) an eval iteration rendered \u2014 inline when the terminal supports it, otherwise the image URL"
|
|
4326
5161
|
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
@@ -4337,7 +5172,7 @@ function registerEvalCommands(program) {
|
|
|
4337
5172
|
async (options, command) => {
|
|
4338
5173
|
const globalOptions = getGlobalOptions(command);
|
|
4339
5174
|
const index = options.index !== void 0 ? parsePositiveInteger(options.index, "--index") : void 0;
|
|
4340
|
-
const result = await
|
|
5175
|
+
const result = await runPlatformCommand3(
|
|
4341
5176
|
options,
|
|
4342
5177
|
globalOptions.timeout,
|
|
4343
5178
|
({ client, signal }) => getEvalIterationTraceOperation.execute(
|
|
@@ -4428,7 +5263,7 @@ function registerEvalCommands(program) {
|
|
|
4428
5263
|
}
|
|
4429
5264
|
}
|
|
4430
5265
|
);
|
|
4431
|
-
|
|
5266
|
+
addPlatformOptions3(
|
|
4432
5267
|
evals.command("video").description(
|
|
4433
5268
|
"Get the Playwright replay video (.webm) an eval iteration recorded \u2014 prints the URL, or downloads it with --out"
|
|
4434
5269
|
).requiredOption("--run <id>", "Eval run ID (from `eval run`)").requiredOption(
|
|
@@ -4441,7 +5276,7 @@ function registerEvalCommands(program) {
|
|
|
4441
5276
|
).action(
|
|
4442
5277
|
async (options, command) => {
|
|
4443
5278
|
const globalOptions = getGlobalOptions(command);
|
|
4444
|
-
const result = await
|
|
5279
|
+
const result = await runPlatformCommand3(
|
|
4445
5280
|
options,
|
|
4446
5281
|
globalOptions.timeout,
|
|
4447
5282
|
({ client, signal }) => getEvalIterationTraceOperation.execute(
|
|
@@ -4492,7 +5327,7 @@ function registerEvalCommands(program) {
|
|
|
4492
5327
|
`);
|
|
4493
5328
|
}
|
|
4494
5329
|
);
|
|
4495
|
-
|
|
5330
|
+
addPlatformOptions3(
|
|
4496
5331
|
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
5332
|
).action(
|
|
4498
5333
|
async (options, command) => {
|
|
@@ -4504,7 +5339,7 @@ function registerEvalCommands(program) {
|
|
|
4504
5339
|
);
|
|
4505
5340
|
}
|
|
4506
5341
|
);
|
|
4507
|
-
|
|
5342
|
+
addPlatformOptions3(
|
|
4508
5343
|
evals.command("update").description(
|
|
4509
5344
|
"Edit an eval suite's settings (only the flags you pass change)"
|
|
4510
5345
|
).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 +5353,7 @@ function registerEvalCommands(program) {
|
|
|
4518
5353
|
);
|
|
4519
5354
|
await executeOp(updateEvalSuiteOperation, input, options, command);
|
|
4520
5355
|
});
|
|
4521
|
-
|
|
5356
|
+
addPlatformOptions3(
|
|
4522
5357
|
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
5358
|
).action(
|
|
4524
5359
|
async (options, command) => {
|
|
@@ -4530,7 +5365,7 @@ function registerEvalCommands(program) {
|
|
|
4530
5365
|
);
|
|
4531
5366
|
}
|
|
4532
5367
|
);
|
|
4533
|
-
|
|
5368
|
+
addPlatformOptions3(
|
|
4534
5369
|
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
5370
|
).action(
|
|
4536
5371
|
async (options, command) => {
|
|
@@ -4550,7 +5385,7 @@ function registerEvalCommands(program) {
|
|
|
4550
5385
|
}
|
|
4551
5386
|
);
|
|
4552
5387
|
const cases = evals.command("cases").description("List, author, and edit an eval suite's test cases");
|
|
4553
|
-
|
|
5388
|
+
addPlatformOptions3(
|
|
4554
5389
|
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
5390
|
).action(
|
|
4556
5391
|
async (options, command) => {
|
|
@@ -4562,7 +5397,7 @@ function registerEvalCommands(program) {
|
|
|
4562
5397
|
);
|
|
4563
5398
|
}
|
|
4564
5399
|
);
|
|
4565
|
-
|
|
5400
|
+
addPlatformOptions3(
|
|
4566
5401
|
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
5402
|
).action(
|
|
4568
5403
|
async (options, command) => {
|
|
@@ -4574,7 +5409,7 @@ function registerEvalCommands(program) {
|
|
|
4574
5409
|
);
|
|
4575
5410
|
}
|
|
4576
5411
|
);
|
|
4577
|
-
|
|
5412
|
+
addPlatformOptions3(
|
|
4578
5413
|
cases.command("run").description(
|
|
4579
5414
|
"Run a single case as a persisted, fully-queryable run (inspect it with `eval iterations` / `eval steps` like any run)"
|
|
4580
5415
|
).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 +5431,7 @@ function registerEvalCommands(program) {
|
|
|
4596
5431
|
);
|
|
4597
5432
|
}
|
|
4598
5433
|
);
|
|
4599
|
-
|
|
5434
|
+
addPlatformOptions3(
|
|
4600
5435
|
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
5436
|
).action(async (options, command) => {
|
|
4602
5437
|
const input = validateOpInput(
|
|
@@ -4605,7 +5440,7 @@ function registerEvalCommands(program) {
|
|
|
4605
5440
|
);
|
|
4606
5441
|
await executeOp(createEvalCaseOperation, input, options, command);
|
|
4607
5442
|
});
|
|
4608
|
-
|
|
5443
|
+
addPlatformOptions3(
|
|
4609
5444
|
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
5445
|
).action(async (options, command) => {
|
|
4611
5446
|
const input = validateOpInput(
|
|
@@ -4614,7 +5449,7 @@ function registerEvalCommands(program) {
|
|
|
4614
5449
|
);
|
|
4615
5450
|
await executeOp(updateEvalCaseOperation, input, options, command);
|
|
4616
5451
|
});
|
|
4617
|
-
|
|
5452
|
+
addPlatformOptions3(
|
|
4618
5453
|
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
5454
|
).action(
|
|
4620
5455
|
async (options, command) => {
|
|
@@ -4626,7 +5461,7 @@ function registerEvalCommands(program) {
|
|
|
4626
5461
|
);
|
|
4627
5462
|
}
|
|
4628
5463
|
);
|
|
4629
|
-
|
|
5464
|
+
addPlatformOptions3(
|
|
4630
5465
|
cases.command("generate").description(
|
|
4631
5466
|
"AI-generate test cases from the suite's tools (spends credits)"
|
|
4632
5467
|
).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 +5510,13 @@ function registerEvalCommands(program) {
|
|
|
4675
5510
|
);
|
|
4676
5511
|
}
|
|
4677
5512
|
var HOST_TEMPLATES = HOST_TEMPLATES$1.map(({ id, label }) => ({ id, label }));
|
|
4678
|
-
function
|
|
5513
|
+
function addPlatformOptions4(command) {
|
|
4679
5514
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
4680
5515
|
"--api-url <url>",
|
|
4681
5516
|
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
4682
5517
|
);
|
|
4683
5518
|
}
|
|
4684
|
-
async function
|
|
5519
|
+
async function runPlatformCommand4(options, timeoutMs, execute) {
|
|
4685
5520
|
const controller = new AbortController();
|
|
4686
5521
|
const timeoutHandle = setTimeout(() => {
|
|
4687
5522
|
controller.abort(
|
|
@@ -4741,26 +5576,26 @@ function registerHostsCommands(program) {
|
|
|
4741
5576
|
const globalOptions = getGlobalOptions(command);
|
|
4742
5577
|
writeResult({ items: HOST_TEMPLATES }, globalOptions.format);
|
|
4743
5578
|
});
|
|
4744
|
-
|
|
5579
|
+
addPlatformOptions4(
|
|
4745
5580
|
hosts.command("list").description("List the hosts saved in a project").option(
|
|
4746
5581
|
"--project <id-or-name>",
|
|
4747
5582
|
"Project name or ID (defaults to the most recently updated project)"
|
|
4748
5583
|
)
|
|
4749
5584
|
).action(async (options, command) => {
|
|
4750
5585
|
const globalOptions = getGlobalOptions(command);
|
|
4751
|
-
const result = await
|
|
5586
|
+
const result = await runPlatformCommand4(
|
|
4752
5587
|
options,
|
|
4753
5588
|
globalOptions.timeout,
|
|
4754
5589
|
({ client, signal }) => listHostsOperation.execute({ project: options.project }, { client, signal })
|
|
4755
5590
|
);
|
|
4756
5591
|
writeResult(result, globalOptions.format);
|
|
4757
5592
|
});
|
|
4758
|
-
|
|
5593
|
+
addPlatformOptions4(
|
|
4759
5594
|
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
5595
|
).action(
|
|
4761
5596
|
async (options, command) => {
|
|
4762
5597
|
const globalOptions = getGlobalOptions(command);
|
|
4763
|
-
const result = await
|
|
5598
|
+
const result = await runPlatformCommand4(
|
|
4764
5599
|
options,
|
|
4765
5600
|
globalOptions.timeout,
|
|
4766
5601
|
({ client, signal }) => getHostOperation.execute(
|
|
@@ -4771,7 +5606,7 @@ function registerHostsCommands(program) {
|
|
|
4771
5606
|
writeResult(result, globalOptions.format);
|
|
4772
5607
|
}
|
|
4773
5608
|
);
|
|
4774
|
-
|
|
5609
|
+
addPlatformOptions4(
|
|
4775
5610
|
hosts.command("create").description(
|
|
4776
5611
|
"Create a host from a built-in template (--template) or a full host config (--file/--json)"
|
|
4777
5612
|
).requiredOption("--name <name>", "Display name for the new host").option("--project <id-or-name>", "Project name or ID").option(
|
|
@@ -4785,14 +5620,14 @@ function registerHostsCommands(program) {
|
|
|
4785
5620
|
async (options, command) => {
|
|
4786
5621
|
const globalOptions = getGlobalOptions(command);
|
|
4787
5622
|
const config = loadConfigObject(options);
|
|
4788
|
-
const input =
|
|
5623
|
+
const input = validateInput3(createHostOperation, {
|
|
4789
5624
|
project: options.project,
|
|
4790
5625
|
name: options.name,
|
|
4791
5626
|
...options.template !== void 0 ? { template: options.template } : {},
|
|
4792
5627
|
...options.theme !== void 0 ? { theme: options.theme } : {},
|
|
4793
5628
|
...config !== void 0 ? { config } : {}
|
|
4794
5629
|
});
|
|
4795
|
-
const result = await
|
|
5630
|
+
const result = await runPlatformCommand4(
|
|
4796
5631
|
options,
|
|
4797
5632
|
globalOptions.timeout,
|
|
4798
5633
|
({ client, signal }) => createHostOperation.execute(input, { client, signal })
|
|
@@ -4800,19 +5635,19 @@ function registerHostsCommands(program) {
|
|
|
4800
5635
|
writeResult(result, globalOptions.format);
|
|
4801
5636
|
}
|
|
4802
5637
|
);
|
|
4803
|
-
|
|
5638
|
+
addPlatformOptions4(
|
|
4804
5639
|
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
5640
|
).action(
|
|
4806
5641
|
async (options, command) => {
|
|
4807
5642
|
const globalOptions = getGlobalOptions(command);
|
|
4808
5643
|
const config = loadConfigObject(options);
|
|
4809
|
-
const input =
|
|
5644
|
+
const input = validateInput3(updateHostOperation, {
|
|
4810
5645
|
project: options.project,
|
|
4811
5646
|
host: options.host,
|
|
4812
5647
|
...options.name !== void 0 ? { name: options.name } : {},
|
|
4813
5648
|
...config !== void 0 ? { config } : {}
|
|
4814
5649
|
});
|
|
4815
|
-
const result = await
|
|
5650
|
+
const result = await runPlatformCommand4(
|
|
4816
5651
|
options,
|
|
4817
5652
|
globalOptions.timeout,
|
|
4818
5653
|
({ client, signal }) => updateHostOperation.execute(input, { client, signal })
|
|
@@ -4820,12 +5655,12 @@ function registerHostsCommands(program) {
|
|
|
4820
5655
|
writeResult(result, globalOptions.format);
|
|
4821
5656
|
}
|
|
4822
5657
|
);
|
|
4823
|
-
|
|
5658
|
+
addPlatformOptions4(
|
|
4824
5659
|
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
5660
|
).action(
|
|
4826
5661
|
async (options, command) => {
|
|
4827
5662
|
const globalOptions = getGlobalOptions(command);
|
|
4828
|
-
const result = await
|
|
5663
|
+
const result = await runPlatformCommand4(
|
|
4829
5664
|
options,
|
|
4830
5665
|
globalOptions.timeout,
|
|
4831
5666
|
({ client, signal }) => deleteHostOperation.execute(
|
|
@@ -4840,7 +5675,7 @@ function registerHostsCommands(program) {
|
|
|
4840
5675
|
}
|
|
4841
5676
|
);
|
|
4842
5677
|
}
|
|
4843
|
-
function
|
|
5678
|
+
function validateInput3(op, raw) {
|
|
4844
5679
|
const parsed = op.inputSchema.safeParse(raw);
|
|
4845
5680
|
if (!parsed.success) {
|
|
4846
5681
|
const detail = parsed.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ");
|
|
@@ -5599,13 +6434,13 @@ function statusGlyph(status) {
|
|
|
5599
6434
|
}
|
|
5600
6435
|
|
|
5601
6436
|
// src/commands/projects.ts
|
|
5602
|
-
function
|
|
6437
|
+
function addPlatformOptions5(command) {
|
|
5603
6438
|
return command.option("--api-key <key>", "MCPJam sk_ API key (overrides MCPJAM_API_KEY)").option(
|
|
5604
6439
|
"--api-url <url>",
|
|
5605
6440
|
"MCPJam API base URL (defaults to https://app.mcpjam.com/api/v1)"
|
|
5606
6441
|
);
|
|
5607
6442
|
}
|
|
5608
|
-
async function
|
|
6443
|
+
async function runPlatformCommand5(options, timeoutMs, execute) {
|
|
5609
6444
|
const controller = new AbortController();
|
|
5610
6445
|
const timeoutHandle = setTimeout(() => {
|
|
5611
6446
|
controller.abort(
|
|
@@ -5633,11 +6468,11 @@ async function runPlatformCommand4(options, timeoutMs, execute) {
|
|
|
5633
6468
|
}
|
|
5634
6469
|
function registerProjectsCommands(program) {
|
|
5635
6470
|
const projects = program.command("projects").description("Operate the MCP servers saved in your hosted MCPJam projects");
|
|
5636
|
-
|
|
6471
|
+
addPlatformOptions5(
|
|
5637
6472
|
projects.command("list").description("List the projects you can access")
|
|
5638
6473
|
).action(async (options, command) => {
|
|
5639
6474
|
const globalOptions = getGlobalOptions(command);
|
|
5640
|
-
const result = await
|
|
6475
|
+
const result = await runPlatformCommand5(
|
|
5641
6476
|
options,
|
|
5642
6477
|
globalOptions.timeout,
|
|
5643
6478
|
({ client, signal }) => listProjectsOperation.execute({}, { client, signal })
|
|
@@ -5649,14 +6484,14 @@ function registerProjectsCommands(program) {
|
|
|
5649
6484
|
writeResult(result, globalOptions.format);
|
|
5650
6485
|
}
|
|
5651
6486
|
});
|
|
5652
|
-
|
|
6487
|
+
addPlatformOptions5(
|
|
5653
6488
|
projects.command("servers").description("List the servers saved in a project").option(
|
|
5654
6489
|
"--project <id-or-name>",
|
|
5655
6490
|
"Project name or ID (defaults to the most recently updated project)"
|
|
5656
6491
|
)
|
|
5657
6492
|
).action(async (options, command) => {
|
|
5658
6493
|
const globalOptions = getGlobalOptions(command);
|
|
5659
|
-
const result = await
|
|
6494
|
+
const result = await runPlatformCommand5(
|
|
5660
6495
|
options,
|
|
5661
6496
|
globalOptions.timeout,
|
|
5662
6497
|
({ client, signal }) => listProjectServersOperation.execute(
|
|
@@ -5671,7 +6506,7 @@ function registerProjectsCommands(program) {
|
|
|
5671
6506
|
writeResult(result, globalOptions.format);
|
|
5672
6507
|
}
|
|
5673
6508
|
});
|
|
5674
|
-
|
|
6509
|
+
addPlatformOptions5(
|
|
5675
6510
|
projects.command("status").description(
|
|
5676
6511
|
"Health-check every server in a project (hosted doctor per server)"
|
|
5677
6512
|
).option(
|
|
@@ -5680,7 +6515,7 @@ function registerProjectsCommands(program) {
|
|
|
5680
6515
|
)
|
|
5681
6516
|
).action(async (options, command) => {
|
|
5682
6517
|
const globalOptions = getGlobalOptions(command);
|
|
5683
|
-
const payload = await
|
|
6518
|
+
const payload = await runPlatformCommand5(
|
|
5684
6519
|
options,
|
|
5685
6520
|
globalOptions.timeout,
|
|
5686
6521
|
({ client, signal }) => showServersOperation.execute(
|
|
@@ -5721,6 +6556,9 @@ function registerProtocolCommands(program) {
|
|
|
5721
6556
|
"Specific check ID to run. Repeat for multiple. Default: all.",
|
|
5722
6557
|
(value, previous = []) => [...previous, value],
|
|
5723
6558
|
[]
|
|
6559
|
+
).option(
|
|
6560
|
+
"--protocol-version <version>",
|
|
6561
|
+
"Pin the MCP protocol version to conform against. Default: legacy (2025-era) behavior."
|
|
5724
6562
|
).option(
|
|
5725
6563
|
"--reporter <reporter>",
|
|
5726
6564
|
"Structured reporter output: json-summary or junit-xml"
|
|
@@ -5796,13 +6634,20 @@ function buildConfig(options) {
|
|
|
5796
6634
|
`Unknown check id${invalidCheckIds.length === 1 ? "" : "s"}: ${invalidCheckIds.join(", ")}`
|
|
5797
6635
|
);
|
|
5798
6636
|
}
|
|
6637
|
+
const protocolVersion = options.protocolVersion?.trim();
|
|
6638
|
+
if (options.protocolVersion !== void 0 && (!protocolVersion || !isKnownProtocolVersion(protocolVersion))) {
|
|
6639
|
+
throw usageError(
|
|
6640
|
+
`Unknown protocol version: ${protocolVersion ?? ""}. Known: ${MCP_PROTOCOL_VERSIONS.join(", ")}`
|
|
6641
|
+
);
|
|
6642
|
+
}
|
|
5799
6643
|
return {
|
|
5800
6644
|
serverUrl,
|
|
5801
6645
|
accessToken,
|
|
5802
6646
|
customHeaders,
|
|
5803
6647
|
checkTimeout: options.checkTimeout ?? 15e3,
|
|
5804
6648
|
...categories && categories.length > 0 ? { categories } : {},
|
|
5805
|
-
...checkIds && checkIds.length > 0 ? { checkIds } : {}
|
|
6649
|
+
...checkIds && checkIds.length > 0 ? { checkIds } : {},
|
|
6650
|
+
...protocolVersion ? { protocolVersion } : {}
|
|
5806
6651
|
};
|
|
5807
6652
|
}
|
|
5808
6653
|
function parseOAuthOutputFormat(value) {
|
|
@@ -5913,7 +6758,7 @@ function registerOAuthCommands(program) {
|
|
|
5913
6758
|
const oauth = program.command("oauth").description("Run MCP OAuth login, proxy, and conformance flows");
|
|
5914
6759
|
oauth.command("login").description("Run an OAuth login flow against an HTTP MCP server").requiredOption("--url <url>", "MCP server URL").option(
|
|
5915
6760
|
"--protocol-version <version>",
|
|
5916
|
-
"OAuth protocol override: 2025-03-26, 2025-06-18,
|
|
6761
|
+
"OAuth protocol override: 2025-03-26, 2025-06-18, 2025-11-25, or 2026-07-28"
|
|
5917
6762
|
).option(
|
|
5918
6763
|
"--registration <strategy>",
|
|
5919
6764
|
"Registration override: dcr, preregistered, or cimd"
|
|
@@ -6036,7 +6881,7 @@ function registerOAuthCommands(program) {
|
|
|
6036
6881
|
});
|
|
6037
6882
|
oauth.command("conformance").description("Run OAuth conformance against an HTTP MCP server").requiredOption("--url <url>", "MCP server URL").requiredOption(
|
|
6038
6883
|
"--protocol-version <version>",
|
|
6039
|
-
"OAuth protocol version: 2025-03-26, 2025-06-18,
|
|
6884
|
+
"OAuth protocol version: 2025-03-26, 2025-06-18, 2025-11-25, or 2026-07-28"
|
|
6040
6885
|
).requiredOption(
|
|
6041
6886
|
"--registration <strategy>",
|
|
6042
6887
|
"Registration strategy: dcr, preregistered, or cimd"
|
|
@@ -6212,7 +7057,7 @@ function buildOAuthConformanceConfig(options, defaults) {
|
|
|
6212
7057
|
"--print-url only applies to --auth-mode interactive. Headless and client_credentials modes do not open a browser."
|
|
6213
7058
|
);
|
|
6214
7059
|
}
|
|
6215
|
-
if (protocolVersion
|
|
7060
|
+
if (!CIMD_PROTOCOL_VERSIONS.has(protocolVersion) && registrationStrategy === "cimd") {
|
|
6216
7061
|
throw usageError(
|
|
6217
7062
|
`CIMD registration is not supported for protocol version ${protocolVersion}.`
|
|
6218
7063
|
);
|
|
@@ -6295,7 +7140,7 @@ function buildOAuthLoginConfig(options, defaults) {
|
|
|
6295
7140
|
"--print-url only applies to --auth-mode interactive. Headless and client_credentials modes do not open a browser."
|
|
6296
7141
|
);
|
|
6297
7142
|
}
|
|
6298
|
-
if (protocolVersion !== void 0 && registrationStrategy === "cimd" && protocolVersion
|
|
7143
|
+
if (protocolVersion !== void 0 && registrationStrategy === "cimd" && !CIMD_PROTOCOL_VERSIONS.has(protocolVersion)) {
|
|
6299
7144
|
throw usageError(
|
|
6300
7145
|
`CIMD registration is not supported for protocol version ${protocolVersion}.`
|
|
6301
7146
|
);
|
|
@@ -6388,10 +7233,12 @@ function summarizeOAuthLoginCommandInput(options) {
|
|
|
6388
7233
|
};
|
|
6389
7234
|
}
|
|
6390
7235
|
function buildOAuthLoginSnapshotConfig(config, result) {
|
|
7236
|
+
const snapshotProtocolVersion = result?.protocolVersion ?? config.protocolVersion;
|
|
6391
7237
|
const baseConfig = {
|
|
6392
7238
|
url: config.serverUrl,
|
|
6393
7239
|
...config.customHeaders ? { requestInit: { headers: config.customHeaders } } : {},
|
|
6394
|
-
timeout: config.stepTimeout ?? 3e4
|
|
7240
|
+
timeout: config.stepTimeout ?? 3e4,
|
|
7241
|
+
...snapshotProtocolVersion === "2026-07-28" ? { mcpProtocolVersion: "2026-07-28" } : {}
|
|
6395
7242
|
};
|
|
6396
7243
|
if (!result) {
|
|
6397
7244
|
return baseConfig;
|
|
@@ -6885,6 +7732,12 @@ function registerPromptCommands(program) {
|
|
|
6885
7732
|
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
7733
|
"--prompt-args <json>",
|
|
6887
7734
|
"Prompt arguments as JSON, @path, or - for stdin"
|
|
7735
|
+
).option(
|
|
7736
|
+
"--interactive",
|
|
7737
|
+
"Drive the modern input_required (multi-round-trip) loop: render embedded elicitations to the terminal and collect responses from stdin"
|
|
7738
|
+
).option(
|
|
7739
|
+
"--yes",
|
|
7740
|
+
"With --interactive, run non-interactively: decline every embedded input request instead of prompting"
|
|
6888
7741
|
)
|
|
6889
7742
|
)
|
|
6890
7743
|
)
|
|
@@ -6907,6 +7760,11 @@ function registerPromptCommands(program) {
|
|
|
6907
7760
|
...options,
|
|
6908
7761
|
timeout: globalOptions.timeout
|
|
6909
7762
|
});
|
|
7763
|
+
if (options.interactive && options.promptArgs === "-") {
|
|
7764
|
+
throw usageError(
|
|
7765
|
+
"--interactive cannot be used together with --prompt-args -: interactive answers are read from stdin too. Pass the arguments as JSON or @path."
|
|
7766
|
+
);
|
|
7767
|
+
}
|
|
6910
7768
|
const promptArguments = parsePromptArguments(options.promptArgs);
|
|
6911
7769
|
const result = await withEphemeralManager(
|
|
6912
7770
|
config,
|
|
@@ -6919,7 +7777,9 @@ function registerPromptCommands(program) {
|
|
|
6919
7777
|
timeout: globalOptions.timeout,
|
|
6920
7778
|
rpcLogger: collector?.rpcLogger,
|
|
6921
7779
|
retryPolicy,
|
|
6922
|
-
host: host?.connection
|
|
7780
|
+
host: host?.connection,
|
|
7781
|
+
beforeConnect: buildMrtrBeforeConnect(options),
|
|
7782
|
+
interactiveElicitation: options.interactive === true
|
|
6923
7783
|
}
|
|
6924
7784
|
);
|
|
6925
7785
|
writeResult(
|
|
@@ -6964,7 +7824,13 @@ function registerResourcesCommands(program) {
|
|
|
6964
7824
|
addHostOption(
|
|
6965
7825
|
addRetryOptions(
|
|
6966
7826
|
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")
|
|
7827
|
+
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(
|
|
7828
|
+
"--interactive",
|
|
7829
|
+
"Drive the modern input_required (multi-round-trip) loop: render embedded elicitations to the terminal and collect responses from stdin"
|
|
7830
|
+
).option(
|
|
7831
|
+
"--yes",
|
|
7832
|
+
"With --interactive, run non-interactively: decline every embedded input request instead of prompting"
|
|
7833
|
+
)
|
|
6968
7834
|
)
|
|
6969
7835
|
)
|
|
6970
7836
|
).action(async (options, command) => {
|
|
@@ -6993,7 +7859,9 @@ function registerResourcesCommands(program) {
|
|
|
6993
7859
|
timeout: globalOptions.timeout,
|
|
6994
7860
|
rpcLogger: collector?.rpcLogger,
|
|
6995
7861
|
retryPolicy,
|
|
6996
|
-
host: host?.connection
|
|
7862
|
+
host: host?.connection,
|
|
7863
|
+
beforeConnect: buildMrtrBeforeConnect(options),
|
|
7864
|
+
interactiveElicitation: options.interactive === true
|
|
6997
7865
|
}
|
|
6998
7866
|
);
|
|
6999
7867
|
writeResult(
|
|
@@ -7572,6 +8440,420 @@ function createServerDiffResult(left, right, failOn) {
|
|
|
7572
8440
|
throw error;
|
|
7573
8441
|
}
|
|
7574
8442
|
}
|
|
8443
|
+
|
|
8444
|
+
// src/lib/subscriptions-session.ts
|
|
8445
|
+
var SUBSCRIPTION_OUTCOME_EXIT_CODES = {
|
|
8446
|
+
graceful: 0,
|
|
8447
|
+
cancelled: 0,
|
|
8448
|
+
remote: 1,
|
|
8449
|
+
error: 1
|
|
8450
|
+
};
|
|
8451
|
+
function relistenDelayMs(policy, attempt) {
|
|
8452
|
+
return Math.min(
|
|
8453
|
+
policy.maxDelayMs,
|
|
8454
|
+
policy.initialDelayMs * policy.factor ** (attempt - 1)
|
|
8455
|
+
);
|
|
8456
|
+
}
|
|
8457
|
+
function describeFilter(filter) {
|
|
8458
|
+
const parts = [];
|
|
8459
|
+
if (filter.toolsListChanged) parts.push("tools/list_changed");
|
|
8460
|
+
if (filter.promptsListChanged) parts.push("prompts/list_changed");
|
|
8461
|
+
if (filter.resourcesListChanged) parts.push("resources/list_changed");
|
|
8462
|
+
for (const uri of filter.resourceSubscriptions ?? []) {
|
|
8463
|
+
parts.push(`resource:${uri}`);
|
|
8464
|
+
}
|
|
8465
|
+
return parts.length > 0 ? parts.join(", ") : "(empty)";
|
|
8466
|
+
}
|
|
8467
|
+
function hasAnyInterest(desired) {
|
|
8468
|
+
return Boolean(
|
|
8469
|
+
desired.toolsListChanged || desired.promptsListChanged || desired.resourcesListChanged || (desired.resourceUris?.length ?? 0) > 0
|
|
8470
|
+
);
|
|
8471
|
+
}
|
|
8472
|
+
var SubscriptionListenSession = class {
|
|
8473
|
+
constructor(options, deps) {
|
|
8474
|
+
this.options = options;
|
|
8475
|
+
this.deps = deps;
|
|
8476
|
+
this.now = deps.now ?? (() => Date.now());
|
|
8477
|
+
this.setTimer = deps.setTimer ?? ((fn, ms) => {
|
|
8478
|
+
const handle = setTimeout(fn, ms);
|
|
8479
|
+
handle.unref?.();
|
|
8480
|
+
return { cancel: () => clearTimeout(handle) };
|
|
8481
|
+
});
|
|
8482
|
+
this.completion = new Promise((resolve) => {
|
|
8483
|
+
this.resolveCompletion = resolve;
|
|
8484
|
+
});
|
|
8485
|
+
this.coordinator = deps.createCoordinator({
|
|
8486
|
+
onStreamChange: (stream) => this.onStreamChange(stream),
|
|
8487
|
+
onNotification: (event) => this.onNotification(event),
|
|
8488
|
+
onRejectedNotification: (event) => this.onRejectedNotification(event)
|
|
8489
|
+
});
|
|
8490
|
+
}
|
|
8491
|
+
coordinator;
|
|
8492
|
+
now;
|
|
8493
|
+
setTimer;
|
|
8494
|
+
timers = [];
|
|
8495
|
+
settled = false;
|
|
8496
|
+
/**
|
|
8497
|
+
* Set the moment a local abort is requested, before the (async) cancel
|
|
8498
|
+
* round-trip completes: notifications that land during the teardown belong
|
|
8499
|
+
* to a stream we have already decided to stop, so counting them would let a
|
|
8500
|
+
* chatty server overshoot `--max-notifications`.
|
|
8501
|
+
*/
|
|
8502
|
+
stopping = false;
|
|
8503
|
+
stopReason;
|
|
8504
|
+
notifications = 0;
|
|
8505
|
+
rejectedNotifications = 0;
|
|
8506
|
+
relistenAttempts = 0;
|
|
8507
|
+
seenStreams = /* @__PURE__ */ new Set();
|
|
8508
|
+
acknowledged = /* @__PURE__ */ new Set();
|
|
8509
|
+
closed = /* @__PURE__ */ new Set();
|
|
8510
|
+
resolveCompletion;
|
|
8511
|
+
completion;
|
|
8512
|
+
/** Opens the stream and resolves when it reaches a terminal outcome. */
|
|
8513
|
+
async run() {
|
|
8514
|
+
this.deps.status(
|
|
8515
|
+
`Opening subscription: ${describeFilter({
|
|
8516
|
+
toolsListChanged: this.options.desired.toolsListChanged,
|
|
8517
|
+
promptsListChanged: this.options.desired.promptsListChanged,
|
|
8518
|
+
resourcesListChanged: this.options.desired.resourcesListChanged,
|
|
8519
|
+
resourceSubscriptions: [...this.options.desired.resourceUris ?? []]
|
|
8520
|
+
})}`
|
|
8521
|
+
);
|
|
8522
|
+
if (this.options.durationMs !== void 0) {
|
|
8523
|
+
this.timers.push(
|
|
8524
|
+
this.setTimer(() => {
|
|
8525
|
+
void this.stop("duration");
|
|
8526
|
+
}, this.options.durationMs)
|
|
8527
|
+
);
|
|
8528
|
+
}
|
|
8529
|
+
try {
|
|
8530
|
+
await this.coordinator.setDesiredInterests(this.options.desired);
|
|
8531
|
+
} catch (error) {
|
|
8532
|
+
this.finish(
|
|
8533
|
+
"error",
|
|
8534
|
+
error instanceof Error ? error.message : String(error)
|
|
8535
|
+
);
|
|
8536
|
+
}
|
|
8537
|
+
const result = await this.completion;
|
|
8538
|
+
for (const timer of this.timers) timer.cancel();
|
|
8539
|
+
await this.safeDispose();
|
|
8540
|
+
return result;
|
|
8541
|
+
}
|
|
8542
|
+
/** Local abort (signal, duration cap, notification cap). Idempotent. */
|
|
8543
|
+
async stop(reason) {
|
|
8544
|
+
if (this.settled || this.stopping) return;
|
|
8545
|
+
this.stopping = true;
|
|
8546
|
+
this.stopReason ??= reason;
|
|
8547
|
+
this.deps.status(`Cancelling subscription (${reason})...`);
|
|
8548
|
+
try {
|
|
8549
|
+
await this.coordinator.cancel();
|
|
8550
|
+
} catch (error) {
|
|
8551
|
+
this.deps.status(
|
|
8552
|
+
`Cancel failed: ${error instanceof Error ? error.message : String(error)}`
|
|
8553
|
+
);
|
|
8554
|
+
}
|
|
8555
|
+
this.finish("cancelled");
|
|
8556
|
+
}
|
|
8557
|
+
onStreamChange(stream) {
|
|
8558
|
+
if (this.settled) return;
|
|
8559
|
+
if (!this.seenStreams.has(stream.localId)) {
|
|
8560
|
+
this.seenStreams.add(stream.localId);
|
|
8561
|
+
if (stream.reconnectAttempt > 0) {
|
|
8562
|
+
this.relistenAttempts = Math.max(
|
|
8563
|
+
this.relistenAttempts,
|
|
8564
|
+
stream.reconnectAttempt
|
|
8565
|
+
);
|
|
8566
|
+
}
|
|
8567
|
+
this.deps.emit({
|
|
8568
|
+
type: "subscription.opened",
|
|
8569
|
+
localSubscriptionId: stream.localId,
|
|
8570
|
+
...stream.mcpSubscriptionId ? { subscriptionId: stream.mcpSubscriptionId } : {},
|
|
8571
|
+
era: stream.era,
|
|
8572
|
+
requestedFilter: stream.requestedFilter,
|
|
8573
|
+
rejectedInterests: stream.rejectedInterests,
|
|
8574
|
+
relistenAttempt: stream.reconnectAttempt,
|
|
8575
|
+
at: stream.openedAt
|
|
8576
|
+
});
|
|
8577
|
+
this.deps.status(
|
|
8578
|
+
stream.reconnectAttempt > 0 ? `Re-listening (attempt ${stream.reconnectAttempt}): ${describeFilter(stream.requestedFilter)}` : `Requested: ${describeFilter(stream.requestedFilter)}`
|
|
8579
|
+
);
|
|
8580
|
+
}
|
|
8581
|
+
if (stream.acknowledgedFilter && !this.acknowledged.has(stream.localId)) {
|
|
8582
|
+
this.acknowledged.add(stream.localId);
|
|
8583
|
+
this.deps.emit({
|
|
8584
|
+
type: "subscription.acknowledged",
|
|
8585
|
+
localSubscriptionId: stream.localId,
|
|
8586
|
+
...stream.mcpSubscriptionId ? { subscriptionId: stream.mcpSubscriptionId } : {},
|
|
8587
|
+
requestedFilter: stream.requestedFilter,
|
|
8588
|
+
acknowledgedFilter: stream.acknowledgedFilter,
|
|
8589
|
+
rejectedInterests: stream.rejectedInterests,
|
|
8590
|
+
at: stream.acknowledgedAt ?? this.now()
|
|
8591
|
+
});
|
|
8592
|
+
this.deps.status(
|
|
8593
|
+
`Acknowledged: ${describeFilter(stream.acknowledgedFilter)}`
|
|
8594
|
+
);
|
|
8595
|
+
}
|
|
8596
|
+
if (stream.status === "opening" || stream.status === "active" || this.closed.has(stream.localId)) {
|
|
8597
|
+
return;
|
|
8598
|
+
}
|
|
8599
|
+
this.closed.add(stream.localId);
|
|
8600
|
+
this.onStreamClosed(stream);
|
|
8601
|
+
}
|
|
8602
|
+
onStreamClosed(stream) {
|
|
8603
|
+
const outcome = stream.status === "graceful-closed" ? "graceful" : stream.status === "remote-closed" ? "remote" : stream.status === "cancelled" ? "cancelled" : "error";
|
|
8604
|
+
this.deps.emit({
|
|
8605
|
+
type: "subscription.closed",
|
|
8606
|
+
localSubscriptionId: stream.localId,
|
|
8607
|
+
...stream.mcpSubscriptionId ? { subscriptionId: stream.mcpSubscriptionId } : {},
|
|
8608
|
+
outcome,
|
|
8609
|
+
...stream.closeReason ? { closeReason: stream.closeReason } : {},
|
|
8610
|
+
...stream.error ? { error: stream.error } : {},
|
|
8611
|
+
relistenAttempt: stream.reconnectAttempt,
|
|
8612
|
+
at: stream.closedAt ?? this.now()
|
|
8613
|
+
});
|
|
8614
|
+
if (outcome === "remote") {
|
|
8615
|
+
const attempt = stream.reconnectAttempt + 1;
|
|
8616
|
+
if (attempt <= this.options.reconnect.maxAttempts) {
|
|
8617
|
+
const delayMs = relistenDelayMs(this.options.reconnect, attempt);
|
|
8618
|
+
this.relistenAttempts = Math.max(this.relistenAttempts, attempt);
|
|
8619
|
+
this.deps.emit({
|
|
8620
|
+
type: "subscription.relisten",
|
|
8621
|
+
localSubscriptionId: stream.localId,
|
|
8622
|
+
attempt,
|
|
8623
|
+
maxAttempts: this.options.reconnect.maxAttempts,
|
|
8624
|
+
delayMs,
|
|
8625
|
+
at: this.now()
|
|
8626
|
+
});
|
|
8627
|
+
this.deps.status(
|
|
8628
|
+
`Stream lost; re-listening in ${delayMs}ms (attempt ${attempt}/${this.options.reconnect.maxAttempts})`
|
|
8629
|
+
);
|
|
8630
|
+
return;
|
|
8631
|
+
}
|
|
8632
|
+
this.deps.status(
|
|
8633
|
+
this.options.reconnect.maxAttempts > 0 ? "Stream lost remotely; re-listen attempts exhausted." : "Stream lost remotely."
|
|
8634
|
+
);
|
|
8635
|
+
this.finish("remote");
|
|
8636
|
+
return;
|
|
8637
|
+
}
|
|
8638
|
+
if (outcome === "graceful") {
|
|
8639
|
+
this.deps.status("Server completed the subscription.");
|
|
8640
|
+
}
|
|
8641
|
+
this.finish(outcome, stream.error);
|
|
8642
|
+
}
|
|
8643
|
+
onNotification(event) {
|
|
8644
|
+
if (this.settled || this.stopping) return;
|
|
8645
|
+
this.notifications += 1;
|
|
8646
|
+
this.deps.emit({
|
|
8647
|
+
type: "notification",
|
|
8648
|
+
localSubscriptionId: event.localSubscriptionId,
|
|
8649
|
+
...event.subscriptionId ? { subscriptionId: event.subscriptionId } : {},
|
|
8650
|
+
method: event.method,
|
|
8651
|
+
kind: event.kind,
|
|
8652
|
+
...event.uri ? { uri: event.uri } : {},
|
|
8653
|
+
...event.params ? { params: event.params } : {},
|
|
8654
|
+
at: event.at
|
|
8655
|
+
});
|
|
8656
|
+
if (this.options.maxNotifications !== void 0 && this.notifications >= this.options.maxNotifications) {
|
|
8657
|
+
void this.stop("max-notifications");
|
|
8658
|
+
}
|
|
8659
|
+
}
|
|
8660
|
+
onRejectedNotification(event) {
|
|
8661
|
+
if (this.settled || this.stopping) return;
|
|
8662
|
+
this.rejectedNotifications += 1;
|
|
8663
|
+
this.deps.emit({
|
|
8664
|
+
type: "notification.rejected",
|
|
8665
|
+
...event.localSubscriptionId ? { localSubscriptionId: event.localSubscriptionId } : {},
|
|
8666
|
+
...event.subscriptionId ? { subscriptionId: event.subscriptionId } : {},
|
|
8667
|
+
method: event.method,
|
|
8668
|
+
reason: event.reason,
|
|
8669
|
+
at: event.at
|
|
8670
|
+
});
|
|
8671
|
+
}
|
|
8672
|
+
finish(outcome, error) {
|
|
8673
|
+
if (this.settled) return;
|
|
8674
|
+
this.settled = true;
|
|
8675
|
+
const result = {
|
|
8676
|
+
outcome,
|
|
8677
|
+
...outcome === "cancelled" && this.stopReason ? { stopReason: this.stopReason } : {},
|
|
8678
|
+
exitCode: SUBSCRIPTION_OUTCOME_EXIT_CODES[outcome],
|
|
8679
|
+
...error ? { error } : {},
|
|
8680
|
+
notifications: this.notifications,
|
|
8681
|
+
rejectedNotifications: this.rejectedNotifications,
|
|
8682
|
+
relistenAttempts: this.relistenAttempts,
|
|
8683
|
+
streams: this.seenStreams.size
|
|
8684
|
+
};
|
|
8685
|
+
this.deps.emit({ type: "summary", ...result, at: this.now() });
|
|
8686
|
+
this.resolveCompletion(result);
|
|
8687
|
+
}
|
|
8688
|
+
async safeDispose() {
|
|
8689
|
+
try {
|
|
8690
|
+
await this.coordinator.dispose();
|
|
8691
|
+
} catch {
|
|
8692
|
+
}
|
|
8693
|
+
}
|
|
8694
|
+
};
|
|
8695
|
+
|
|
8696
|
+
// src/commands/subscriptions.ts
|
|
8697
|
+
function buildDesiredInterests(options) {
|
|
8698
|
+
const all = options.listChanged === true;
|
|
8699
|
+
return {
|
|
8700
|
+
toolsListChanged: all || options.toolsListChanged === true,
|
|
8701
|
+
promptsListChanged: all || options.promptsListChanged === true,
|
|
8702
|
+
resourcesListChanged: all || options.resourcesListChanged === true,
|
|
8703
|
+
resourceUris: [...new Set(options.resourceUri ?? [])]
|
|
8704
|
+
};
|
|
8705
|
+
}
|
|
8706
|
+
function parseRelistenPolicy(options) {
|
|
8707
|
+
const maxAttempts = options.relisten ?? 0;
|
|
8708
|
+
if (maxAttempts === 0) {
|
|
8709
|
+
if (options.relistenDelayMs !== void 0 || options.relistenMaxDelayMs !== void 0) {
|
|
8710
|
+
throw usageError(
|
|
8711
|
+
"--relisten-delay-ms/--relisten-max-delay-ms require --relisten with a positive attempt count."
|
|
8712
|
+
);
|
|
8713
|
+
}
|
|
8714
|
+
return { ...DEFAULT_SUBSCRIPTION_RECONNECT_POLICY, maxAttempts: 0 };
|
|
8715
|
+
}
|
|
8716
|
+
const initialDelayMs = options.relistenDelayMs ?? DEFAULT_SUBSCRIPTION_RECONNECT_POLICY.initialDelayMs;
|
|
8717
|
+
const maxDelayMs = Math.max(
|
|
8718
|
+
initialDelayMs,
|
|
8719
|
+
options.relistenMaxDelayMs ?? DEFAULT_SUBSCRIPTION_RECONNECT_POLICY.maxDelayMs
|
|
8720
|
+
);
|
|
8721
|
+
return {
|
|
8722
|
+
...DEFAULT_SUBSCRIPTION_RECONNECT_POLICY,
|
|
8723
|
+
maxAttempts,
|
|
8724
|
+
initialDelayMs,
|
|
8725
|
+
maxDelayMs
|
|
8726
|
+
};
|
|
8727
|
+
}
|
|
8728
|
+
function listenResultError(result) {
|
|
8729
|
+
if (result.exitCode === 0) return void 0;
|
|
8730
|
+
return result.outcome === "remote" ? cliError(
|
|
8731
|
+
"SUBSCRIPTION_REMOTE_CLOSED",
|
|
8732
|
+
"The subscription stream was lost remotely (no completion result from the server).",
|
|
8733
|
+
result.exitCode,
|
|
8734
|
+
{ notifications: result.notifications, relistenAttempts: result.relistenAttempts }
|
|
8735
|
+
) : cliError(
|
|
8736
|
+
"SUBSCRIPTION_FAILED",
|
|
8737
|
+
result.error ?? "The subscription stream failed to open.",
|
|
8738
|
+
result.exitCode
|
|
8739
|
+
);
|
|
8740
|
+
}
|
|
8741
|
+
function registerSubscriptionsCommands(program) {
|
|
8742
|
+
const subscriptions = program.command("subscriptions").description(
|
|
8743
|
+
"Open a long-lived MCP subscription and stream its notifications (2026-07-28 subscriptions/listen, with a legacy fallback)"
|
|
8744
|
+
);
|
|
8745
|
+
addHostOption(
|
|
8746
|
+
addRetryOptions(
|
|
8747
|
+
addSharedServerOptions(
|
|
8748
|
+
subscriptions.command("listen").description(
|
|
8749
|
+
"Open a subscription, print the acknowledgement, and stream notifications as NDJSON on stdout until the stream closes or Ctrl-C"
|
|
8750
|
+
).option("--tools-list-changed", "Subscribe to tools/list_changed").option("--prompts-list-changed", "Subscribe to prompts/list_changed").option(
|
|
8751
|
+
"--resources-list-changed",
|
|
8752
|
+
"Subscribe to resources/list_changed"
|
|
8753
|
+
).option(
|
|
8754
|
+
"--list-changed",
|
|
8755
|
+
"Subscribe to all three list_changed notifications"
|
|
8756
|
+
).option(
|
|
8757
|
+
"--resource-uri <uri...>",
|
|
8758
|
+
"Watch a resource URI for resources/updated. Pass multiple values or repeat the flag."
|
|
8759
|
+
).option(
|
|
8760
|
+
"--relisten <count>",
|
|
8761
|
+
"After an unexpected remote loss, re-listen up to this many times with exponential backoff (0 disables)",
|
|
8762
|
+
(value) => parseNonNegativeInteger(value, "Relisten count")
|
|
8763
|
+
).option(
|
|
8764
|
+
"--relisten-delay-ms <ms>",
|
|
8765
|
+
"Initial re-listen backoff delay in milliseconds",
|
|
8766
|
+
(value) => parsePositiveInteger(value, "Relisten delay")
|
|
8767
|
+
).option(
|
|
8768
|
+
"--relisten-max-delay-ms <ms>",
|
|
8769
|
+
"Maximum re-listen backoff delay in milliseconds",
|
|
8770
|
+
(value) => parsePositiveInteger(value, "Relisten max delay")
|
|
8771
|
+
).option(
|
|
8772
|
+
"--max-notifications <count>",
|
|
8773
|
+
"Stop after this many delivered notifications",
|
|
8774
|
+
(value) => parsePositiveInteger(value, "Max notifications")
|
|
8775
|
+
).option(
|
|
8776
|
+
"--duration-ms <ms>",
|
|
8777
|
+
"Stop after this many milliseconds",
|
|
8778
|
+
(value) => parsePositiveInteger(value, "Duration")
|
|
8779
|
+
)
|
|
8780
|
+
)
|
|
8781
|
+
)
|
|
8782
|
+
).action(async (options, command) => {
|
|
8783
|
+
const globalOptions = getGlobalOptions(command);
|
|
8784
|
+
const desired = buildDesiredInterests(options);
|
|
8785
|
+
if (!hasAnyInterest(desired)) {
|
|
8786
|
+
throw usageError(
|
|
8787
|
+
"Select at least one subscription interest: --tools-list-changed, --prompts-list-changed, --resources-list-changed, --list-changed, or --resource-uri."
|
|
8788
|
+
);
|
|
8789
|
+
}
|
|
8790
|
+
const reconnect = parseRelistenPolicy(options);
|
|
8791
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
8792
|
+
const host = resolveHostFromOptions(options);
|
|
8793
|
+
const target = describeTarget(options);
|
|
8794
|
+
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
8795
|
+
const config = parseServerConfig({
|
|
8796
|
+
...options,
|
|
8797
|
+
timeout: globalOptions.timeout
|
|
8798
|
+
});
|
|
8799
|
+
const emit = (event) => {
|
|
8800
|
+
process.stdout.write(`${JSON.stringify(event)}
|
|
8801
|
+
`);
|
|
8802
|
+
};
|
|
8803
|
+
const status = (message) => {
|
|
8804
|
+
if (globalOptions.quiet) return;
|
|
8805
|
+
process.stderr.write(`${message}
|
|
8806
|
+
`);
|
|
8807
|
+
};
|
|
8808
|
+
const result = await withEphemeralManager(
|
|
8809
|
+
config,
|
|
8810
|
+
async (manager, serverId) => {
|
|
8811
|
+
const client = manager.getManagedClient(serverId);
|
|
8812
|
+
if (!client) {
|
|
8813
|
+
throw operationalError(
|
|
8814
|
+
`MCP server "${serverId}" is not connected; cannot open a subscription.`
|
|
8815
|
+
);
|
|
8816
|
+
}
|
|
8817
|
+
const session = new SubscriptionListenSession(
|
|
8818
|
+
{
|
|
8819
|
+
desired,
|
|
8820
|
+
reconnect,
|
|
8821
|
+
...options.maxNotifications !== void 0 ? { maxNotifications: options.maxNotifications } : {},
|
|
8822
|
+
...options.durationMs !== void 0 ? { durationMs: options.durationMs } : {}
|
|
8823
|
+
},
|
|
8824
|
+
{
|
|
8825
|
+
createCoordinator: (handlers) => new SubscriptionCoordinator({
|
|
8826
|
+
client,
|
|
8827
|
+
reconnect,
|
|
8828
|
+
...handlers
|
|
8829
|
+
}),
|
|
8830
|
+
emit,
|
|
8831
|
+
status
|
|
8832
|
+
}
|
|
8833
|
+
);
|
|
8834
|
+
const onSignal = () => {
|
|
8835
|
+
void session.stop("signal");
|
|
8836
|
+
};
|
|
8837
|
+
process.on("SIGINT", onSignal);
|
|
8838
|
+
process.on("SIGTERM", onSignal);
|
|
8839
|
+
try {
|
|
8840
|
+
return await session.run();
|
|
8841
|
+
} finally {
|
|
8842
|
+
process.removeListener("SIGINT", onSignal);
|
|
8843
|
+
process.removeListener("SIGTERM", onSignal);
|
|
8844
|
+
}
|
|
8845
|
+
},
|
|
8846
|
+
{
|
|
8847
|
+
timeout: globalOptions.timeout,
|
|
8848
|
+
rpcLogger: collector?.rpcLogger,
|
|
8849
|
+
retryPolicy,
|
|
8850
|
+
host: host?.connection
|
|
8851
|
+
}
|
|
8852
|
+
);
|
|
8853
|
+
const error = listenResultError(result);
|
|
8854
|
+
if (error) throw error;
|
|
8855
|
+
});
|
|
8856
|
+
}
|
|
7575
8857
|
var DEFAULT_UPDATE_PACKAGE_NAME = "@mcpjam/cli";
|
|
7576
8858
|
var UPDATE_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
7577
8859
|
var UPDATE_CACHE_FILE = "update-check.json";
|
|
@@ -8200,112 +9482,1000 @@ function writeTelemetryStatus(status, format) {
|
|
|
8200
9482
|
format
|
|
8201
9483
|
);
|
|
8202
9484
|
}
|
|
8203
|
-
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
|
|
8210
|
-
|
|
8211
|
-
|
|
8212
|
-
|
|
8213
|
-
|
|
8214
|
-
|
|
8215
|
-
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
config,
|
|
8223
|
-
async (manager, serverId) => {
|
|
8224
|
-
const listed = await listToolsWithMetadata(manager, {
|
|
8225
|
-
serverId,
|
|
8226
|
-
cursor: options.cursor,
|
|
8227
|
-
modelId: options.modelId
|
|
8228
|
-
});
|
|
8229
|
-
if (!host) return listed;
|
|
8230
|
-
const { tools: visibleTools, toolsDroppedVisibility } = applyHostVisibility(
|
|
8231
|
-
listed.tools,
|
|
8232
|
-
manager,
|
|
8233
|
-
serverId,
|
|
8234
|
-
host.policy
|
|
8235
|
-
);
|
|
8236
|
-
const visibleNames = new Set(
|
|
8237
|
-
visibleTools.map((tool) => String(tool.name))
|
|
8238
|
-
);
|
|
8239
|
-
return {
|
|
8240
|
-
...listed,
|
|
8241
|
-
tools: visibleTools,
|
|
8242
|
-
toolsMetadata: Object.fromEntries(
|
|
8243
|
-
Object.entries(listed.toolsMetadata).filter(
|
|
8244
|
-
([name]) => visibleNames.has(name)
|
|
8245
|
-
)
|
|
8246
|
-
),
|
|
8247
|
-
...listed.tokenCount === void 0 ? {} : { tokenCount: estimateTokensFromChars(JSON.stringify(visibleTools)) },
|
|
8248
|
-
host: host.id,
|
|
8249
|
-
toolsDroppedVisibility
|
|
8250
|
-
};
|
|
8251
|
-
},
|
|
8252
|
-
{
|
|
8253
|
-
timeout: globalOptions.timeout,
|
|
8254
|
-
rpcLogger: collector?.rpcLogger,
|
|
8255
|
-
retryPolicy,
|
|
8256
|
-
host: host?.connection
|
|
8257
|
-
}
|
|
9485
|
+
var MODEL_IMMEDIATE_RESPONSE_META_KEY = "io.modelcontextprotocol/model-immediate-response";
|
|
9486
|
+
var RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
|
|
9487
|
+
var ASSERTABLE_TASKS_WIRES = ["legacy", "extension"];
|
|
9488
|
+
function parseTasksWireOption(value) {
|
|
9489
|
+
if (ASSERTABLE_TASKS_WIRES.includes(value)) {
|
|
9490
|
+
return value;
|
|
9491
|
+
}
|
|
9492
|
+
throw usageError(
|
|
9493
|
+
`Invalid wire "${value}". Use "legacy" or "extension".`
|
|
9494
|
+
);
|
|
9495
|
+
}
|
|
9496
|
+
function resolveTasksSupportOrThrow(manager, serverId, requiredWire) {
|
|
9497
|
+
const support = manager.getTasksSupport(serverId);
|
|
9498
|
+
if (support.wire === "none") {
|
|
9499
|
+
throw cliError(
|
|
9500
|
+
"TASKS_UNSUPPORTED",
|
|
9501
|
+
"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.",
|
|
9502
|
+
1,
|
|
9503
|
+
{ wire: support.wire }
|
|
8258
9504
|
);
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
9505
|
+
}
|
|
9506
|
+
if (requiredWire && support.wire !== requiredWire) {
|
|
9507
|
+
throw cliError(
|
|
9508
|
+
"TASKS_WIRE_MISMATCH",
|
|
9509
|
+
`--wire ${requiredWire} was asserted, but this connection resolved to the ${support.wire} wire.`,
|
|
9510
|
+
1,
|
|
9511
|
+
{ requestedWire: requiredWire, wire: support.wire }
|
|
9512
|
+
);
|
|
9513
|
+
}
|
|
9514
|
+
return support;
|
|
9515
|
+
}
|
|
9516
|
+
var CAPABILITY_LABELS = {
|
|
9517
|
+
list: "tasks/list",
|
|
9518
|
+
cancel: "tasks/cancel",
|
|
9519
|
+
update: "tasks/update",
|
|
9520
|
+
toolCalls: "task-augmented tools/call"
|
|
9521
|
+
};
|
|
9522
|
+
function assertWireCapability(support, capability, hint) {
|
|
9523
|
+
if (support[capability]) return;
|
|
9524
|
+
throw cliError(
|
|
9525
|
+
"TASKS_UNSUPPORTED",
|
|
9526
|
+
`${CAPABILITY_LABELS[capability]} is not available on the ${support.wire} wire. ${hint}`,
|
|
9527
|
+
1,
|
|
9528
|
+
{ wire: support.wire, capability }
|
|
9529
|
+
);
|
|
9530
|
+
}
|
|
9531
|
+
function taskUnknownError(taskId) {
|
|
9532
|
+
return cliError(
|
|
9533
|
+
"TASK_UNKNOWN_OR_EXPIRED",
|
|
9534
|
+
`The server does not know task "${taskId}". It was never created, or its TTL elapsed and the server dropped it.`,
|
|
9535
|
+
1,
|
|
9536
|
+
{ taskId }
|
|
9537
|
+
);
|
|
9538
|
+
}
|
|
9539
|
+
async function getTaskForWire(manager, serverId, taskId, support) {
|
|
9540
|
+
try {
|
|
9541
|
+
const task = support.wire === "extension" ? await manager.getTaskExt(serverId, taskId) : await manager.getTask(serverId, taskId);
|
|
9542
|
+
return { wire: support.wire, task };
|
|
9543
|
+
} catch (error) {
|
|
9544
|
+
if (isUnknownTaskError(error)) throw taskUnknownError(taskId);
|
|
9545
|
+
throw error;
|
|
9546
|
+
}
|
|
9547
|
+
}
|
|
9548
|
+
function asRecord2(value) {
|
|
9549
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
9550
|
+
}
|
|
9551
|
+
function modelImmediateResponseOf(result) {
|
|
9552
|
+
return asRecord2(asRecord2(result)?._meta)?.[MODEL_IMMEDIATE_RESPONSE_META_KEY];
|
|
9553
|
+
}
|
|
9554
|
+
function detectCreatedTask(wire, result) {
|
|
9555
|
+
if (wire === "none") return null;
|
|
9556
|
+
const body = asRecord2(result);
|
|
9557
|
+
if (!body) return null;
|
|
9558
|
+
const task = wire === "extension" ? body : asRecord2(body.task);
|
|
9559
|
+
if (!task) return null;
|
|
9560
|
+
if (wire === "extension") {
|
|
9561
|
+
if (task.resultType !== "task") return null;
|
|
9562
|
+
} else if (typeof task.status !== "string" || !LEGACY_TASK_STATUSES.has(task.status)) {
|
|
9563
|
+
return null;
|
|
9564
|
+
}
|
|
9565
|
+
const taskId = task.taskId;
|
|
9566
|
+
if (typeof taskId !== "string" || taskId.length === 0) return null;
|
|
9567
|
+
return {
|
|
9568
|
+
status: "task_created",
|
|
9569
|
+
wire,
|
|
9570
|
+
task,
|
|
9571
|
+
...withModelImmediateResponse(result)
|
|
9572
|
+
};
|
|
9573
|
+
}
|
|
9574
|
+
function withModelImmediateResponse(result) {
|
|
9575
|
+
const value = modelImmediateResponseOf(result);
|
|
9576
|
+
return value === void 0 ? {} : { modelImmediateResponse: value };
|
|
9577
|
+
}
|
|
9578
|
+
function taskWatchExitCode(outcome) {
|
|
9579
|
+
switch (outcome) {
|
|
9580
|
+
case "completed":
|
|
9581
|
+
return 0;
|
|
9582
|
+
case "input-required":
|
|
9583
|
+
return 6;
|
|
9584
|
+
case "timeout":
|
|
9585
|
+
return 7;
|
|
9586
|
+
case "aborted":
|
|
9587
|
+
return 130;
|
|
9588
|
+
case "failed":
|
|
9589
|
+
case "cancelled":
|
|
9590
|
+
case "expired":
|
|
9591
|
+
case "unreachable":
|
|
9592
|
+
return 1;
|
|
9593
|
+
}
|
|
9594
|
+
}
|
|
9595
|
+
function describeError(error) {
|
|
9596
|
+
if (error === void 0 || error === null) return void 0;
|
|
9597
|
+
if (error instanceof Error) return { message: error.message };
|
|
9598
|
+
if (typeof error === "string") return { message: error };
|
|
9599
|
+
try {
|
|
9600
|
+
return { message: JSON.stringify(error) ?? String(error) };
|
|
9601
|
+
} catch {
|
|
9602
|
+
return { message: String(error) };
|
|
9603
|
+
}
|
|
9604
|
+
}
|
|
9605
|
+
async function driveTaskWatch(args) {
|
|
9606
|
+
const { manager, serverId, support, taskId } = args;
|
|
9607
|
+
if (support.wire === "none") {
|
|
9608
|
+
throw cliError(
|
|
9609
|
+
"TASKS_UNSUPPORTED",
|
|
9610
|
+
"Cannot watch a task on a server with no tasks wire.",
|
|
9611
|
+
1
|
|
8262
9612
|
);
|
|
9613
|
+
}
|
|
9614
|
+
const identity = {
|
|
9615
|
+
serverId,
|
|
9616
|
+
wire: support.wire,
|
|
9617
|
+
taskId
|
|
9618
|
+
};
|
|
9619
|
+
const engine = new TaskLifecycleEngine();
|
|
9620
|
+
if (args.tuning?.pollIntervalMs !== void 0) {
|
|
9621
|
+
engine.setUserMinimumIntervalMs(args.tuning.pollIntervalMs);
|
|
9622
|
+
}
|
|
9623
|
+
const extension = support.wire === "extension";
|
|
9624
|
+
const result = await driveTaskToTerminal({
|
|
9625
|
+
identity,
|
|
9626
|
+
engine,
|
|
9627
|
+
getTask: async () => extension ? extensionTaskToObservation(await manager.getTaskExt(serverId, taskId)) : legacyTaskToObservation(
|
|
9628
|
+
await manager.getTask(serverId, taskId)
|
|
9629
|
+
),
|
|
9630
|
+
// Extension results are inline on `tasks/get`; the legacy wire has no
|
|
9631
|
+
// payload at all without this second call, and the driver reports a
|
|
9632
|
+
// completed-but-empty watch as an error rather than inventing one.
|
|
9633
|
+
...extension ? {} : {
|
|
9634
|
+
getResult: async () => await manager.getTaskResult(serverId, taskId)
|
|
9635
|
+
},
|
|
9636
|
+
// Extension only, and not an omission: `tasks/update` does not exist on
|
|
9637
|
+
// 2025-11-25, which is why `TasksSupport.update` is hard-`false` for that
|
|
9638
|
+
// wire. A legacy task's input arrives out of band as an `elicitation/create`
|
|
9639
|
+
// stamped with `relatedTaskId` and its `Task` carries no `inputRequests`, so
|
|
9640
|
+
// the poll loop has nothing to answer and nothing to answer it with. The
|
|
9641
|
+
// driver reports `input_required` there deliberately rather than re-reading
|
|
9642
|
+
// an unchanging status until the deadline — a deterministic exit 6 beats a
|
|
9643
|
+
// timeout that looks like a hang.
|
|
9644
|
+
...extension ? {
|
|
9645
|
+
updateTask: async (_identity, inputResponses) => {
|
|
9646
|
+
await manager.updateTask(serverId, taskId, inputResponses);
|
|
9647
|
+
}
|
|
9648
|
+
} : {},
|
|
9649
|
+
...args.input ? { input: args.input } : {},
|
|
9650
|
+
...args.tuning?.durationMs !== void 0 ? { timeoutMs: args.tuning.durationMs } : {},
|
|
9651
|
+
...args.tuning?.maxInputRounds !== void 0 ? { maxInputRounds: args.tuning.maxInputRounds } : {},
|
|
9652
|
+
...args.tuning?.maxConsecutiveErrors !== void 0 ? { maxConsecutiveErrors: args.tuning.maxConsecutiveErrors } : {},
|
|
9653
|
+
...args.signal ? { signal: args.signal } : {},
|
|
9654
|
+
...args.onState ? { onState: args.onState } : {}
|
|
8263
9655
|
});
|
|
8264
|
-
|
|
8265
|
-
|
|
8266
|
-
|
|
8267
|
-
|
|
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
|
-
|
|
9656
|
+
const lastError = describeError(result.lastError);
|
|
9657
|
+
return {
|
|
9658
|
+
outcome: abortedDuringResultFetch({
|
|
9659
|
+
aborted: args.signal?.aborted === true,
|
|
9660
|
+
outcome: result.outcome,
|
|
9661
|
+
hasLastError: result.lastError !== void 0,
|
|
9662
|
+
hasResult: result.task?.result !== void 0
|
|
9663
|
+
}) ? "aborted" : result.outcome,
|
|
9664
|
+
wire: support.wire,
|
|
9665
|
+
taskId,
|
|
9666
|
+
...result.task ? { task: result.task } : {},
|
|
9667
|
+
...result.unansweredInput?.length ? { unansweredInput: result.unansweredInput } : {},
|
|
9668
|
+
...lastError ? { lastError } : {}
|
|
9669
|
+
};
|
|
9670
|
+
}
|
|
9671
|
+
function abortedDuringResultFetch(args) {
|
|
9672
|
+
return args.aborted && args.outcome === "completed" && args.hasLastError && !args.hasResult;
|
|
9673
|
+
}
|
|
9674
|
+
function buildTaskInputDriverOptions(args) {
|
|
9675
|
+
if (args.interactive !== true) return void 0;
|
|
9676
|
+
const nonInteractive = resolveNonInteractive({
|
|
9677
|
+
yes: args.yes,
|
|
9678
|
+
stdinIsTTY: args.stdinIsTTY ?? Boolean(process.stdin.isTTY),
|
|
9679
|
+
...args.env ? { env: args.env } : {}
|
|
9680
|
+
});
|
|
9681
|
+
const resolved = applyInteractiveElicitationCapability(args.config);
|
|
9682
|
+
const declaredCapabilities = resolved.clientCapabilities ?? resolved.capabilities;
|
|
9683
|
+
const handlers = {
|
|
9684
|
+
// Built per invocation rather than once, so each call can be given ITS
|
|
9685
|
+
// context's `signal`. A terminal prompt is the one place a watch can block
|
|
9686
|
+
// indefinitely, and without the signal reaching `readline` a Ctrl-C during
|
|
9687
|
+
// the prompt would leave the drive stuck instead of producing the
|
|
9688
|
+
// documented `aborted` outcome.
|
|
9689
|
+
//
|
|
9690
|
+
// The cast is the seam between two descriptions of the same
|
|
9691
|
+
// `elicitation/create` params: the task input driver hands over an opaque
|
|
9692
|
+
// record because it has already validated the request shape and the
|
|
9693
|
+
// declared mode before dispatching, while the standalone handler is typed
|
|
9694
|
+
// against the narrowed union.
|
|
9695
|
+
elicitation: (params, ctx) => createStdinElicitationHandler({
|
|
9696
|
+
nonInteractive,
|
|
9697
|
+
...ctx?.signal ? { signal: ctx.signal } : {},
|
|
9698
|
+
...args.collectorOptions
|
|
9699
|
+
})(params)
|
|
9700
|
+
};
|
|
9701
|
+
const declaration = canDeclareTasksExtension(
|
|
9702
|
+
declaredCapabilities,
|
|
9703
|
+
handlers
|
|
9704
|
+
);
|
|
9705
|
+
if (!declaration.ok) {
|
|
9706
|
+
throw usageError(
|
|
9707
|
+
`--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\`.`,
|
|
9708
|
+
{ missing: declaration.missing }
|
|
9709
|
+
);
|
|
9710
|
+
}
|
|
9711
|
+
return {
|
|
9712
|
+
declaredCapabilities,
|
|
9713
|
+
handlers,
|
|
9714
|
+
// The same strict, dialect-aware self-validation the standalone MRTR path
|
|
9715
|
+
// applies (the manager's `mrtrElicitationContentValidator` is built from
|
|
9716
|
+
// this same factory). Without it, an accepted answer that violates the
|
|
9717
|
+
// request's `requestedSchema` would be submitted via `tasks/update` here
|
|
9718
|
+
// while the interactive path refuses the identical answer.
|
|
9719
|
+
validateElicitationContent: createStrictElicitationContentValidator()
|
|
9720
|
+
};
|
|
9721
|
+
}
|
|
9722
|
+
|
|
9723
|
+
// src/commands/tasks.ts
|
|
9724
|
+
var TASKS_CHECK_IDS_BY_CATEGORY = {
|
|
9725
|
+
dispatch: ["tasks-wire-resolvable", "tasks-declaration-hygiene"],
|
|
9726
|
+
creation: [
|
|
9727
|
+
"tasks-result-type-discipline",
|
|
9728
|
+
"tasks-undeclared-creation-refused"
|
|
9729
|
+
],
|
|
9730
|
+
lifecycle: [
|
|
9731
|
+
"tasks-ttl-shape",
|
|
9732
|
+
"tasks-inline-result",
|
|
9733
|
+
"tasks-mcp-name-routing",
|
|
9734
|
+
"tasks-undeclared-capability-rejected"
|
|
9735
|
+
]
|
|
9736
|
+
};
|
|
9737
|
+
function tasksConformanceExitCode(result) {
|
|
9738
|
+
if (result.outcome === "incomplete") return 3;
|
|
9739
|
+
if (result.outcome === "failed") return 1;
|
|
9740
|
+
return result.passed ? 0 : 1;
|
|
9741
|
+
}
|
|
9742
|
+
function collectInvalidEntries3(values, allowed) {
|
|
9743
|
+
return (values ?? []).filter((value) => !allowed.includes(value));
|
|
9744
|
+
}
|
|
9745
|
+
function buildTasksConformanceConfig(options) {
|
|
9746
|
+
const serverConfig = parseServerConfig(options);
|
|
9747
|
+
const categories = options.category?.filter(Boolean);
|
|
9748
|
+
const invalidCategories = collectInvalidEntries3(
|
|
9749
|
+
categories,
|
|
9750
|
+
MCP_TASKS_CHECK_CATEGORIES
|
|
9751
|
+
);
|
|
9752
|
+
if (invalidCategories.length > 0) {
|
|
9753
|
+
throw usageError(
|
|
9754
|
+
invalidCategories.length === 1 ? `Unknown category: ${invalidCategories[0]}` : `Unknown categories: ${invalidCategories.join(", ")}`
|
|
9755
|
+
);
|
|
9756
|
+
}
|
|
9757
|
+
const checkIds = options.checkId?.filter(Boolean);
|
|
9758
|
+
const invalidCheckIds = collectInvalidEntries3(checkIds, MCP_TASKS_CHECK_IDS);
|
|
9759
|
+
if (invalidCheckIds.length > 0) {
|
|
9760
|
+
throw usageError(
|
|
9761
|
+
`Unknown check id${invalidCheckIds.length === 1 ? "" : "s"}: ${invalidCheckIds.join(", ")}`
|
|
9762
|
+
);
|
|
9763
|
+
}
|
|
9764
|
+
const resolvedCheckIds = checkIds && checkIds.length > 0 ? checkIds : categories && categories.length > 0 ? Array.from(
|
|
9765
|
+
new Set(
|
|
9766
|
+
categories.flatMap(
|
|
9767
|
+
(category) => TASKS_CHECK_IDS_BY_CATEGORY[category]
|
|
9768
|
+
)
|
|
9769
|
+
)
|
|
9770
|
+
) : void 0;
|
|
9771
|
+
return {
|
|
9772
|
+
...serverConfig,
|
|
9773
|
+
...resolvedCheckIds && resolvedCheckIds.length > 0 ? { checkIds: resolvedCheckIds } : {},
|
|
9774
|
+
...options.toolName ? { toolName: options.toolName } : {},
|
|
9775
|
+
...options.toolArgs ? { toolArguments: parseJsonRecord(options.toolArgs, "--tool-args") } : {},
|
|
9776
|
+
...options.pollTimeout ? { pollTimeoutMs: options.pollTimeout } : {}
|
|
9777
|
+
};
|
|
9778
|
+
}
|
|
9779
|
+
function requireTaskId(options) {
|
|
9780
|
+
if (!options.taskId) {
|
|
9781
|
+
throw usageError("--task-id is required.");
|
|
9782
|
+
}
|
|
9783
|
+
return options.taskId;
|
|
9784
|
+
}
|
|
9785
|
+
async function runTaskVerb(options, command, fn, verbOptions = {}) {
|
|
9786
|
+
const globalOptions = getGlobalOptions(command);
|
|
9787
|
+
const taskId = verbOptions.requiresTaskId === false ? "" : requireTaskId(options);
|
|
9788
|
+
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: describeTarget(options) }) : void 0;
|
|
9789
|
+
const note = (message) => {
|
|
9790
|
+
if (!globalOptions.quiet) process.stderr.write(`${message}
|
|
9791
|
+
`);
|
|
9792
|
+
};
|
|
9793
|
+
const config = parseServerConfig({ ...options, timeout: globalOptions.timeout });
|
|
9794
|
+
const result = await withEphemeralManager(
|
|
9795
|
+
config,
|
|
9796
|
+
async (manager, serverId) => {
|
|
9797
|
+
const support = resolveTasksSupportOrThrow(manager, serverId, options.wire);
|
|
9798
|
+
return fn({ manager, serverId, support, taskId, globalOptions, note });
|
|
9799
|
+
},
|
|
9800
|
+
{ timeout: globalOptions.timeout, rpcLogger: collector?.rpcLogger }
|
|
9801
|
+
);
|
|
9802
|
+
writeResult(
|
|
9803
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
9804
|
+
globalOptions.format
|
|
9805
|
+
);
|
|
9806
|
+
}
|
|
9807
|
+
function addTaskIdOption(command) {
|
|
9808
|
+
return command.option("--task-id <id>", "The task to act on");
|
|
9809
|
+
}
|
|
9810
|
+
function addWireOption(command) {
|
|
9811
|
+
return command.option(
|
|
9812
|
+
"--wire <wire>",
|
|
9813
|
+
"Assert the connection resolves to this tasks wire: legacy or extension",
|
|
9814
|
+
parseTasksWireOption
|
|
9815
|
+
);
|
|
9816
|
+
}
|
|
9817
|
+
function registerTaskVerbs(tasks) {
|
|
9818
|
+
addSharedServerOptions(
|
|
9819
|
+
tasks.command("capabilities").description(
|
|
9820
|
+
"Report the tasks wire this connection resolves to and which task verbs it carries. Always exits 0 \u2014 branch on `.wire`."
|
|
9821
|
+
)
|
|
9822
|
+
).action(async (options, command) => {
|
|
9823
|
+
const globalOptions = getGlobalOptions(command);
|
|
9824
|
+
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: describeTarget(options) }) : void 0;
|
|
9825
|
+
const config = parseServerConfig({
|
|
9826
|
+
...options,
|
|
9827
|
+
timeout: globalOptions.timeout
|
|
9828
|
+
});
|
|
9829
|
+
const support = await withEphemeralManager(
|
|
9830
|
+
config,
|
|
9831
|
+
async (manager, serverId) => manager.getTasksSupport(serverId),
|
|
9832
|
+
{ timeout: globalOptions.timeout, rpcLogger: collector?.rpcLogger }
|
|
9833
|
+
);
|
|
9834
|
+
writeResult(
|
|
9835
|
+
withRpcLogsIfRequested(support, collector, globalOptions),
|
|
9836
|
+
globalOptions.format
|
|
9837
|
+
);
|
|
9838
|
+
});
|
|
9839
|
+
addSharedServerOptions(
|
|
9840
|
+
addWireOption(
|
|
9841
|
+
tasks.command("list").description("List tasks the server is tracking (legacy wire only)").option("--cursor <cursor>", "Pagination cursor")
|
|
9842
|
+
)
|
|
9843
|
+
).action(
|
|
9844
|
+
(options, command) => runTaskVerb(
|
|
9845
|
+
options,
|
|
9846
|
+
command,
|
|
9847
|
+
async ({ manager, serverId, support, note }) => {
|
|
9848
|
+
if (support.wire === "extension") {
|
|
9849
|
+
note(
|
|
9850
|
+
"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."
|
|
9851
|
+
);
|
|
9852
|
+
} else {
|
|
9853
|
+
assertWireCapability(
|
|
9854
|
+
support,
|
|
9855
|
+
"list",
|
|
9856
|
+
"The server did not declare `capabilities.tasks.list`."
|
|
9857
|
+
);
|
|
9858
|
+
}
|
|
9859
|
+
const result = await manager.listTasks(serverId, options.cursor);
|
|
9860
|
+
return { ...result, wire: support.wire };
|
|
9861
|
+
},
|
|
9862
|
+
{ requiresTaskId: false }
|
|
9863
|
+
)
|
|
9864
|
+
);
|
|
9865
|
+
addSharedServerOptions(
|
|
9866
|
+
addWireOption(
|
|
9867
|
+
addTaskIdOption(
|
|
9868
|
+
tasks.command("get").description("Read one task's current state")
|
|
9869
|
+
)
|
|
9870
|
+
)
|
|
9871
|
+
).action(
|
|
9872
|
+
(options, command) => runTaskVerb(
|
|
9873
|
+
options,
|
|
9874
|
+
command,
|
|
9875
|
+
({ manager, serverId, support, taskId }) => getTaskForWire(manager, serverId, taskId, support)
|
|
9876
|
+
)
|
|
9877
|
+
);
|
|
9878
|
+
addSharedServerOptions(
|
|
9879
|
+
addWireOption(
|
|
9880
|
+
addTaskIdOption(
|
|
9881
|
+
tasks.command("result").description(
|
|
9882
|
+
"Read a completed task's result (legacy wire only \u2014 extension results are inline on `tasks get`)"
|
|
9883
|
+
)
|
|
9884
|
+
)
|
|
9885
|
+
)
|
|
9886
|
+
).action(
|
|
9887
|
+
(options, command) => runTaskVerb(options, command, async ({ manager, serverId, support, taskId }) => {
|
|
9888
|
+
try {
|
|
9889
|
+
const result = await manager.getTaskResult(serverId, taskId);
|
|
9890
|
+
if (result && typeof result === "object") {
|
|
9891
|
+
const meta = result._meta ?? {};
|
|
9892
|
+
result._meta = { ...meta, [RELATED_TASK_META_KEY]: { taskId } };
|
|
9893
|
+
}
|
|
9894
|
+
return result;
|
|
9895
|
+
} catch (error) {
|
|
9896
|
+
if (isUnknownTaskError(error)) throw taskUnknownError(taskId);
|
|
9897
|
+
if (isMCPTasksWireError(error)) {
|
|
9898
|
+
throw cliError(
|
|
9899
|
+
"TASKS_UNSUPPORTED",
|
|
9900
|
+
"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.",
|
|
9901
|
+
1,
|
|
9902
|
+
{ wire: support.wire }
|
|
9903
|
+
);
|
|
9904
|
+
}
|
|
9905
|
+
throw error;
|
|
9906
|
+
}
|
|
9907
|
+
})
|
|
9908
|
+
);
|
|
9909
|
+
addSharedServerOptions(
|
|
9910
|
+
addWireOption(
|
|
9911
|
+
addTaskIdOption(
|
|
9912
|
+
tasks.command("cancel").description("Request cancellation of a task")
|
|
9913
|
+
)
|
|
9914
|
+
)
|
|
9915
|
+
).action(
|
|
9916
|
+
(options, command) => runTaskVerb(
|
|
9917
|
+
options,
|
|
9918
|
+
command,
|
|
9919
|
+
async ({ manager, serverId, support, taskId, note }) => {
|
|
9920
|
+
assertWireCapability(
|
|
9921
|
+
support,
|
|
9922
|
+
"cancel",
|
|
9923
|
+
"The server did not declare `capabilities.tasks.cancel`."
|
|
9924
|
+
);
|
|
9925
|
+
try {
|
|
9926
|
+
if (support.wire === "extension") {
|
|
9927
|
+
await manager.cancelTaskExt(serverId, taskId);
|
|
9928
|
+
note(
|
|
9929
|
+
"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`."
|
|
9930
|
+
);
|
|
9931
|
+
return { wire: support.wire, task: null, cooperative: true };
|
|
9932
|
+
}
|
|
9933
|
+
const task = await manager.cancelTask(serverId, taskId);
|
|
9934
|
+
return { wire: support.wire, task };
|
|
9935
|
+
} catch (error) {
|
|
9936
|
+
if (isUnknownTaskError(error)) throw taskUnknownError(taskId);
|
|
9937
|
+
throw error;
|
|
9938
|
+
}
|
|
9939
|
+
}
|
|
9940
|
+
)
|
|
9941
|
+
);
|
|
9942
|
+
addSharedServerOptions(
|
|
9943
|
+
addWireOption(
|
|
9944
|
+
addTaskIdOption(
|
|
9945
|
+
tasks.command("update").description(
|
|
9946
|
+
"Answer a task's `input_required` requests (extension wire only)"
|
|
9947
|
+
).option(
|
|
9948
|
+
"--input-responses <json>",
|
|
9949
|
+
"Responses keyed by input key, as a JSON object, @path, or - for stdin"
|
|
9950
|
+
)
|
|
9951
|
+
)
|
|
9952
|
+
)
|
|
9953
|
+
).action(
|
|
9954
|
+
(options, command) => runTaskVerb(
|
|
9955
|
+
options,
|
|
9956
|
+
command,
|
|
9957
|
+
async ({ manager, serverId, support, taskId, note }) => {
|
|
9958
|
+
assertWireCapability(
|
|
9959
|
+
support,
|
|
9960
|
+
"update",
|
|
9961
|
+
"tasks/update is part of the io.modelcontextprotocol/tasks extension; the 2025-11-25 wire answers task input out of band via elicitation instead."
|
|
9962
|
+
);
|
|
9963
|
+
if (!options.inputResponses) {
|
|
9964
|
+
throw usageError("--input-responses is required for `tasks update`.");
|
|
9965
|
+
}
|
|
9966
|
+
const responses = parseJsonRecord(
|
|
9967
|
+
options.inputResponses,
|
|
9968
|
+
"--input-responses"
|
|
9969
|
+
);
|
|
9970
|
+
if (!responses) {
|
|
9971
|
+
throw usageError("--input-responses must be a JSON object.");
|
|
9972
|
+
}
|
|
9973
|
+
try {
|
|
9974
|
+
const ack = await manager.updateTask(
|
|
9975
|
+
serverId,
|
|
9976
|
+
taskId,
|
|
9977
|
+
responses
|
|
9978
|
+
);
|
|
9979
|
+
note(
|
|
9980
|
+
"Responses accepted. The ack is empty by design \u2014 the task's status does not move until a later `mcpjam tasks get`."
|
|
9981
|
+
);
|
|
9982
|
+
return { wire: support.wire, ack };
|
|
9983
|
+
} catch (error) {
|
|
9984
|
+
if (!isUnknownTaskError(error)) throw error;
|
|
9985
|
+
let provenUnknown = false;
|
|
9986
|
+
try {
|
|
9987
|
+
await manager.getTaskExt(serverId, taskId);
|
|
9988
|
+
} catch (confirmation) {
|
|
9989
|
+
provenUnknown = isUnknownTaskError(confirmation);
|
|
9990
|
+
}
|
|
9991
|
+
throw provenUnknown ? taskUnknownError(taskId) : error;
|
|
9992
|
+
}
|
|
9993
|
+
}
|
|
9994
|
+
)
|
|
9995
|
+
);
|
|
9996
|
+
}
|
|
9997
|
+
function addTaskWatchTuningOptions(command) {
|
|
9998
|
+
return command.option(
|
|
9999
|
+
"--duration-ms <ms>",
|
|
10000
|
+
"How long to keep watching before giving up",
|
|
10001
|
+
(value) => parsePositiveInteger(value, "Duration")
|
|
10002
|
+
).option(
|
|
10003
|
+
"--poll-interval-ms <ms>",
|
|
10004
|
+
"Your minimum interval between polls. The server's pollIntervalMs, any Retry-After, and error backoff still apply as floors on top of it.",
|
|
10005
|
+
(value) => parsePositiveInteger(value, "Poll interval")
|
|
10006
|
+
).option(
|
|
10007
|
+
"--max-input-rounds <n>",
|
|
10008
|
+
"Give up after this many input_required rounds",
|
|
10009
|
+
(value) => parsePositiveInteger(value, "Max input rounds")
|
|
10010
|
+
).option(
|
|
10011
|
+
"--max-consecutive-errors <n>",
|
|
10012
|
+
"Give up after this many consecutive failed reads",
|
|
10013
|
+
(value) => parsePositiveInteger(value, "Max consecutive errors")
|
|
10014
|
+
);
|
|
10015
|
+
}
|
|
10016
|
+
function addWatchInteractivityOptions(command) {
|
|
10017
|
+
return command.option("--interactive", "Answer the task's input requests from the terminal").option("--yes", "Never prompt; a task that needs input exits 6");
|
|
10018
|
+
}
|
|
10019
|
+
function taskWatchTuningFrom(options) {
|
|
10020
|
+
return {
|
|
10021
|
+
...options.durationMs !== void 0 ? { durationMs: options.durationMs } : {},
|
|
10022
|
+
...options.pollIntervalMs !== void 0 ? { pollIntervalMs: options.pollIntervalMs } : {},
|
|
10023
|
+
...options.maxInputRounds !== void 0 ? { maxInputRounds: options.maxInputRounds } : {},
|
|
10024
|
+
...options.maxConsecutiveErrors !== void 0 ? { maxConsecutiveErrors: options.maxConsecutiveErrors } : {}
|
|
10025
|
+
};
|
|
10026
|
+
}
|
|
10027
|
+
async function withWatchSignals(fn) {
|
|
10028
|
+
const controller = new AbortController();
|
|
10029
|
+
const onSignal = () => controller.abort();
|
|
10030
|
+
process.on("SIGINT", onSignal);
|
|
10031
|
+
process.on("SIGTERM", onSignal);
|
|
10032
|
+
try {
|
|
10033
|
+
return await fn(controller.signal);
|
|
10034
|
+
} finally {
|
|
10035
|
+
process.removeListener("SIGINT", onSignal);
|
|
10036
|
+
process.removeListener("SIGTERM", onSignal);
|
|
10037
|
+
}
|
|
10038
|
+
}
|
|
10039
|
+
function watchStateReporter(globalOptions) {
|
|
10040
|
+
if (globalOptions.quiet) return void 0;
|
|
10041
|
+
let last;
|
|
10042
|
+
return (snapshot) => {
|
|
10043
|
+
if (snapshot.status === last) return;
|
|
10044
|
+
last = snapshot.status;
|
|
10045
|
+
const detail = snapshot.statusMessage ? ` \u2014 ${sanitizeTerminalText(snapshot.statusMessage)}` : "";
|
|
10046
|
+
process.stderr.write(
|
|
10047
|
+
`task: ${sanitizeTerminalText(snapshot.status)}${detail}
|
|
10048
|
+
`
|
|
10049
|
+
);
|
|
10050
|
+
};
|
|
10051
|
+
}
|
|
10052
|
+
function registerTaskWatch(tasks) {
|
|
10053
|
+
addSharedServerOptions(
|
|
10054
|
+
addWatchInteractivityOptions(
|
|
10055
|
+
addTaskWatchTuningOptions(
|
|
10056
|
+
addWireOption(
|
|
10057
|
+
addTaskIdOption(
|
|
10058
|
+
tasks.command("watch").description(
|
|
10059
|
+
"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."
|
|
10060
|
+
)
|
|
10061
|
+
)
|
|
10062
|
+
)
|
|
10063
|
+
)
|
|
10064
|
+
)
|
|
10065
|
+
).action(async (options, command) => {
|
|
10066
|
+
const globalOptions = getGlobalOptions(command);
|
|
10067
|
+
const taskId = requireTaskId(options);
|
|
10068
|
+
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: describeTarget(options) }) : void 0;
|
|
10069
|
+
const config = parseServerConfig({
|
|
10070
|
+
...options,
|
|
10071
|
+
timeout: globalOptions.timeout
|
|
10072
|
+
});
|
|
10073
|
+
const input = buildTaskInputDriverOptions({
|
|
10074
|
+
config,
|
|
10075
|
+
interactive: options.interactive,
|
|
10076
|
+
yes: options.yes
|
|
10077
|
+
});
|
|
10078
|
+
const onState = watchStateReporter(globalOptions);
|
|
10079
|
+
const envelope = await withEphemeralManager(
|
|
10080
|
+
config,
|
|
10081
|
+
async (manager, serverId) => {
|
|
10082
|
+
const support = resolveTasksSupportOrThrow(
|
|
10083
|
+
manager,
|
|
10084
|
+
serverId,
|
|
10085
|
+
options.wire
|
|
10086
|
+
);
|
|
10087
|
+
return withWatchSignals(
|
|
10088
|
+
(signal) => driveTaskWatch({
|
|
10089
|
+
manager,
|
|
10090
|
+
serverId,
|
|
10091
|
+
support,
|
|
10092
|
+
taskId,
|
|
10093
|
+
tuning: taskWatchTuningFrom(options),
|
|
10094
|
+
...input ? { input } : {},
|
|
10095
|
+
signal,
|
|
10096
|
+
...onState ? { onState } : {}
|
|
10097
|
+
})
|
|
10098
|
+
);
|
|
10099
|
+
},
|
|
10100
|
+
{
|
|
10101
|
+
timeout: globalOptions.timeout,
|
|
10102
|
+
rpcLogger: collector?.rpcLogger,
|
|
10103
|
+
// On the legacy wire a task's `input_required` surfaces as an
|
|
10104
|
+
// out-of-band `elicitation/create` stamped with the task id, not as
|
|
10105
|
+
// data on `tasks/get`. Registering the terminal handler is the only
|
|
10106
|
+
// way a single invocation can answer it.
|
|
10107
|
+
...options.interactive ? {
|
|
10108
|
+
beforeConnect: buildMrtrBeforeConnect(options),
|
|
10109
|
+
interactiveElicitation: true
|
|
10110
|
+
} : {}
|
|
10111
|
+
}
|
|
10112
|
+
);
|
|
10113
|
+
writeResult(
|
|
10114
|
+
withRpcLogsIfRequested(envelope, collector, globalOptions),
|
|
10115
|
+
globalOptions.format
|
|
10116
|
+
);
|
|
10117
|
+
const exitCode = taskWatchExitCode(envelope.outcome);
|
|
10118
|
+
if (exitCode !== 0) setProcessExitCode(exitCode);
|
|
10119
|
+
});
|
|
10120
|
+
}
|
|
10121
|
+
function registerTasksCommands(program) {
|
|
10122
|
+
const tasks = program.command("tasks").description(
|
|
10123
|
+
"Create, inspect and drive MCP Tasks (legacy 2025-11-25 and SEP-2663), and validate a server's tasks wire behavior"
|
|
10124
|
+
);
|
|
10125
|
+
registerTaskVerbs(tasks);
|
|
10126
|
+
registerTaskWatch(tasks);
|
|
10127
|
+
addSharedServerOptions(
|
|
10128
|
+
tasks.command("conformance").description("Run MCP Tasks conformance checks").option(
|
|
10129
|
+
"--category <category>",
|
|
10130
|
+
"Check category to run. Repeat for multiple. Default: all.",
|
|
10131
|
+
(value, previous = []) => [...previous, value],
|
|
10132
|
+
[]
|
|
10133
|
+
).option(
|
|
10134
|
+
"--check-id <id>",
|
|
10135
|
+
"Specific check ID to run. Repeat for multiple. Default: all.",
|
|
10136
|
+
(value, previous = []) => [...previous, value],
|
|
10137
|
+
[]
|
|
10138
|
+
).option(
|
|
10139
|
+
"--tool-name <tool>",
|
|
10140
|
+
"Tool used to provoke a task. Required for servers whose tools carry no task metadata (the extension wire)."
|
|
10141
|
+
).option("--tool-args <json>", "Tool arguments as a JSON object").option(
|
|
10142
|
+
"--poll-timeout <ms>",
|
|
10143
|
+
"How long to poll a created task for a terminal status",
|
|
10144
|
+
(value) => parsePositiveInteger(value, "Poll timeout"),
|
|
10145
|
+
3e4
|
|
10146
|
+
).option(
|
|
10147
|
+
"--reporter <reporter>",
|
|
10148
|
+
"Structured reporter output: json-summary or junit-xml"
|
|
10149
|
+
)
|
|
10150
|
+
).action(async (options, command) => {
|
|
10151
|
+
const reporter = parseReporterFormat(
|
|
10152
|
+
options.reporter
|
|
10153
|
+
);
|
|
10154
|
+
const globalOptions = command.optsWithGlobals();
|
|
10155
|
+
const format = resolveConformanceOutputFormatForCli(
|
|
10156
|
+
globalOptions.format,
|
|
10157
|
+
process.stdout.isTTY,
|
|
10158
|
+
reporter
|
|
10159
|
+
);
|
|
10160
|
+
const target = describeTarget(options);
|
|
10161
|
+
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
10162
|
+
const config = {
|
|
10163
|
+
...buildTasksConformanceConfig({
|
|
10164
|
+
...options,
|
|
10165
|
+
timeout: globalOptions.timeout ?? 3e4
|
|
10166
|
+
}),
|
|
10167
|
+
...collector ? { rpcLogger: collector.rpcLogger } : {}
|
|
10168
|
+
};
|
|
10169
|
+
const result = await new MCPTasksConformanceTest(config).run();
|
|
10170
|
+
const outputResult = reporter ? result : withRpcLogsIfRequested(result, collector, {
|
|
10171
|
+
format,
|
|
10172
|
+
rpc: globalOptions.rpc ?? false
|
|
10173
|
+
});
|
|
10174
|
+
const output = renderConformanceForCli(outputResult, reporter, format);
|
|
10175
|
+
process.stdout.write(output.endsWith("\n") ? output : `${output}
|
|
10176
|
+
`);
|
|
10177
|
+
const incompleteReason = result.incompleteReason;
|
|
10178
|
+
if (incompleteReason && !globalOptions.quiet) {
|
|
10179
|
+
process.stderr.write(`Run incomplete: ${incompleteReason}
|
|
10180
|
+
`);
|
|
10181
|
+
}
|
|
10182
|
+
const exitCode = tasksConformanceExitCode(result);
|
|
10183
|
+
if (exitCode !== 0) {
|
|
10184
|
+
setProcessExitCode(exitCode);
|
|
10185
|
+
}
|
|
10186
|
+
});
|
|
10187
|
+
}
|
|
10188
|
+
async function runTaskAugmentedToolCall(args) {
|
|
10189
|
+
const {
|
|
10190
|
+
options,
|
|
10191
|
+
globalOptions,
|
|
10192
|
+
config,
|
|
10193
|
+
host,
|
|
10194
|
+
toolName,
|
|
10195
|
+
params,
|
|
10196
|
+
collector,
|
|
10197
|
+
targetSummary,
|
|
10198
|
+
snapshotCollector
|
|
10199
|
+
} = args;
|
|
10200
|
+
const writeArtifact = (outcome) => writeCommandDebugArtifact({
|
|
10201
|
+
outputPath: options.debugOut,
|
|
10202
|
+
format: globalOptions.format,
|
|
10203
|
+
quiet: globalOptions.quiet,
|
|
10204
|
+
commandName: "tools call",
|
|
10205
|
+
commandInput: { toolName, params },
|
|
10206
|
+
target: targetSummary,
|
|
10207
|
+
outcome,
|
|
10208
|
+
snapshot: options.debugOut ? {
|
|
10209
|
+
input: {
|
|
10210
|
+
config,
|
|
10211
|
+
target: targetSummary,
|
|
10212
|
+
timeout: globalOptions.timeout
|
|
10213
|
+
},
|
|
10214
|
+
collector: snapshotCollector
|
|
10215
|
+
} : void 0,
|
|
10216
|
+
collectors: [collector]
|
|
10217
|
+
});
|
|
10218
|
+
const input = buildTaskInputDriverOptions({
|
|
10219
|
+
config: host ? applyHostToConfig(config, host.connection) : config,
|
|
10220
|
+
interactive: options.interactive,
|
|
10221
|
+
yes: options.yes
|
|
10222
|
+
});
|
|
10223
|
+
const onState = options.taskWatch ? watchStateReporter(globalOptions) : void 0;
|
|
10224
|
+
const note = (message) => {
|
|
10225
|
+
if (!globalOptions.quiet) process.stderr.write(`${message}
|
|
10226
|
+
`);
|
|
10227
|
+
};
|
|
10228
|
+
const run = () => withEphemeralManager(
|
|
10229
|
+
config,
|
|
10230
|
+
async (manager, serverId) => {
|
|
10231
|
+
if (host) {
|
|
10232
|
+
await assertToolVisibleToHost(manager, serverId, toolName, host);
|
|
10233
|
+
}
|
|
10234
|
+
const support = resolveTasksSupportOrThrow(manager, serverId, options.wire);
|
|
10235
|
+
assertWireCapability(
|
|
10236
|
+
support,
|
|
10237
|
+
"toolCalls",
|
|
10238
|
+
"The server did not declare `capabilities.tasks.requests` for `tools/call`, so it cannot turn this call into a task."
|
|
10239
|
+
);
|
|
10240
|
+
if (options.taskTtl !== void 0 && support.wire !== "legacy") {
|
|
10241
|
+
throw usageError(
|
|
10242
|
+
"--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."
|
|
10243
|
+
);
|
|
10244
|
+
}
|
|
10245
|
+
return withWatchSignals(async (signal) => {
|
|
10246
|
+
let result;
|
|
10247
|
+
try {
|
|
10248
|
+
result = support.wire === "legacy" ? await manager.executeTool(
|
|
10249
|
+
serverId,
|
|
10250
|
+
toolName,
|
|
10251
|
+
params,
|
|
10252
|
+
{ signal },
|
|
10253
|
+
options.taskTtl !== void 0 ? { ttl: options.taskTtl } : {}
|
|
10254
|
+
) : await manager.executeTool(serverId, toolName, params, {
|
|
10255
|
+
allowTaskResult: true,
|
|
10256
|
+
request: { signal }
|
|
10257
|
+
});
|
|
10258
|
+
} catch (error) {
|
|
10259
|
+
if (!signal.aborted) throw error;
|
|
10260
|
+
return {
|
|
10261
|
+
aborted: { wire: support.wire, phase: "create" },
|
|
10262
|
+
created: null,
|
|
10263
|
+
result: null
|
|
10264
|
+
};
|
|
10265
|
+
}
|
|
10266
|
+
const created = detectCreatedTask(support.wire, result);
|
|
10267
|
+
if (!created) {
|
|
10268
|
+
if (support.wire === "legacy") {
|
|
10269
|
+
throw cliError(
|
|
10270
|
+
"TASK_MALFORMED",
|
|
10271
|
+
`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\`.`,
|
|
10272
|
+
1,
|
|
10273
|
+
{ wire: support.wire, result }
|
|
10274
|
+
);
|
|
10275
|
+
}
|
|
10276
|
+
note(
|
|
10277
|
+
`No task materialized: the server answered ${toolName} synchronously. Returning the tool result as-is.`
|
|
10278
|
+
);
|
|
10279
|
+
return { aborted: null, created: null, result };
|
|
10280
|
+
}
|
|
10281
|
+
if (!options.taskWatch) {
|
|
10282
|
+
return { aborted: null, created, result: null };
|
|
10283
|
+
}
|
|
10284
|
+
const taskId = created.task.taskId;
|
|
10285
|
+
const watch = await driveTaskWatch({
|
|
10286
|
+
manager,
|
|
10287
|
+
serverId,
|
|
10288
|
+
support,
|
|
10289
|
+
taskId,
|
|
10290
|
+
tuning: taskWatchTuningFrom(options),
|
|
10291
|
+
...input ? { input } : {},
|
|
10292
|
+
signal,
|
|
10293
|
+
...onState ? { onState } : {}
|
|
10294
|
+
});
|
|
10295
|
+
return { aborted: null, created, watch, result: null };
|
|
10296
|
+
});
|
|
10297
|
+
},
|
|
10298
|
+
{
|
|
10299
|
+
timeout: globalOptions.timeout,
|
|
10300
|
+
rpcLogger: collector?.rpcLogger,
|
|
10301
|
+
host: host?.connection,
|
|
10302
|
+
...options.interactive ? {
|
|
10303
|
+
beforeConnect: buildMrtrBeforeConnect(options),
|
|
10304
|
+
interactiveElicitation: true
|
|
10305
|
+
} : {}
|
|
10306
|
+
}
|
|
10307
|
+
);
|
|
10308
|
+
let envelope;
|
|
10309
|
+
try {
|
|
10310
|
+
envelope = await run();
|
|
10311
|
+
} catch (error) {
|
|
10312
|
+
await writeArtifact({ status: "error", error });
|
|
10313
|
+
throw error;
|
|
10314
|
+
}
|
|
10315
|
+
const payload = envelope.aborted ? { status: "aborted", ...envelope.aborted } : envelope.created ? envelope.watch ? { created: envelope.created, watch: envelope.watch } : envelope.created : envelope.result;
|
|
10316
|
+
const syncToolResultError = !envelope.aborted && !envelope.created && isCallToolResultError(envelope.result);
|
|
10317
|
+
const exitCode = envelope.aborted ? 130 : envelope.watch ? taskWatchExitCode(envelope.watch.outcome) : syncToolResultError ? 1 : 0;
|
|
10318
|
+
await writeArtifact(
|
|
10319
|
+
exitCode === 0 ? { status: "success", result: payload } : envelope.aborted ? {
|
|
10320
|
+
status: "error",
|
|
10321
|
+
result: payload,
|
|
10322
|
+
error: {
|
|
10323
|
+
code: "task_aborted",
|
|
10324
|
+
message: `Interrupted during task ${envelope.aborted.phase}.`
|
|
10325
|
+
}
|
|
10326
|
+
} : syncToolResultError ? {
|
|
10327
|
+
// Same code the plain path stamps for `isError: true`: the task
|
|
10328
|
+
// machinery was a bystander here, so the artifact must not
|
|
10329
|
+
// suggest a task outcome that never existed.
|
|
10330
|
+
status: "error",
|
|
10331
|
+
result: payload,
|
|
10332
|
+
error: {
|
|
10333
|
+
code: "tool_result_error",
|
|
10334
|
+
message: "Tool returned an error result."
|
|
10335
|
+
}
|
|
10336
|
+
} : {
|
|
10337
|
+
status: "error",
|
|
10338
|
+
result: payload,
|
|
10339
|
+
error: {
|
|
10340
|
+
code: `task_${envelope.watch?.outcome ?? "unknown"}`,
|
|
10341
|
+
message: `Task watch ended with outcome "${envelope.watch?.outcome}".`
|
|
10342
|
+
}
|
|
10343
|
+
}
|
|
10344
|
+
);
|
|
10345
|
+
writeResult(
|
|
10346
|
+
withRpcLogsIfRequested(payload, collector, globalOptions),
|
|
10347
|
+
globalOptions.format
|
|
10348
|
+
);
|
|
10349
|
+
if (exitCode !== 0) setProcessExitCode(exitCode);
|
|
10350
|
+
}
|
|
10351
|
+
function registerToolsCommands(program) {
|
|
10352
|
+
const tools = program.command("tools").description("List and invoke MCP server tools");
|
|
10353
|
+
addHostOption(
|
|
10354
|
+
addRetryOptions(
|
|
10355
|
+
addSharedServerOptions(
|
|
10356
|
+
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")
|
|
10357
|
+
)
|
|
10358
|
+
)
|
|
10359
|
+
).action(async (options, command) => {
|
|
10360
|
+
const globalOptions = getGlobalOptions(command);
|
|
10361
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
10362
|
+
const host = resolveHostFromOptions(options);
|
|
10363
|
+
const target = describeTarget(options);
|
|
10364
|
+
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
10365
|
+
const config = parseServerConfig({
|
|
10366
|
+
...options,
|
|
10367
|
+
timeout: globalOptions.timeout
|
|
10368
|
+
});
|
|
10369
|
+
const result = await withEphemeralManager(
|
|
10370
|
+
config,
|
|
10371
|
+
async (manager, serverId) => {
|
|
10372
|
+
const listed = await listToolsWithMetadata(manager, {
|
|
10373
|
+
serverId,
|
|
10374
|
+
cursor: options.cursor,
|
|
10375
|
+
modelId: options.modelId
|
|
10376
|
+
});
|
|
10377
|
+
if (!host) return listed;
|
|
10378
|
+
const { tools: visibleTools, toolsDroppedVisibility } = applyHostVisibility(
|
|
10379
|
+
listed.tools,
|
|
10380
|
+
manager,
|
|
10381
|
+
serverId,
|
|
10382
|
+
host.policy
|
|
10383
|
+
);
|
|
10384
|
+
const visibleNames = new Set(
|
|
10385
|
+
visibleTools.map((tool) => String(tool.name))
|
|
10386
|
+
);
|
|
10387
|
+
return {
|
|
10388
|
+
...listed,
|
|
10389
|
+
tools: visibleTools,
|
|
10390
|
+
toolsMetadata: Object.fromEntries(
|
|
10391
|
+
Object.entries(listed.toolsMetadata).filter(
|
|
10392
|
+
([name]) => visibleNames.has(name)
|
|
10393
|
+
)
|
|
10394
|
+
),
|
|
10395
|
+
...listed.tokenCount === void 0 ? {} : { tokenCount: estimateTokensFromChars(JSON.stringify(visibleTools)) },
|
|
10396
|
+
host: host.id,
|
|
10397
|
+
toolsDroppedVisibility
|
|
10398
|
+
};
|
|
10399
|
+
},
|
|
10400
|
+
{
|
|
10401
|
+
timeout: globalOptions.timeout,
|
|
10402
|
+
rpcLogger: collector?.rpcLogger,
|
|
10403
|
+
retryPolicy,
|
|
10404
|
+
host: host?.connection
|
|
10405
|
+
}
|
|
10406
|
+
);
|
|
10407
|
+
writeResult(
|
|
10408
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
10409
|
+
globalOptions.format
|
|
10410
|
+
);
|
|
10411
|
+
});
|
|
10412
|
+
addHostOption(
|
|
10413
|
+
addSharedServerOptions(
|
|
10414
|
+
addTaskWatchTuningOptions(
|
|
10415
|
+
tools.command("call").description("Call an MCP tool").option("--tool-name <tool>", "Tool name").option("--name <tool>", "Alias for --tool-name").option(
|
|
10416
|
+
"--interactive",
|
|
10417
|
+
"Drive the modern input_required (multi-round-trip) loop: render embedded elicitations to the terminal and collect responses from stdin"
|
|
10418
|
+
).option(
|
|
10419
|
+
"--yes",
|
|
10420
|
+
"With --interactive, run non-interactively: decline every embedded input request instead of prompting"
|
|
10421
|
+
).option(
|
|
10422
|
+
"--tool-args <json>",
|
|
10423
|
+
"Tool parameter object as JSON, @path, or - for stdin"
|
|
10424
|
+
).option("--params <json>", "Alias for --tool-args").option("--tool-args-stdin", "Read tool parameter JSON from stdin").option(
|
|
10425
|
+
"--validate-response",
|
|
10426
|
+
"Validate the MCP tool-call envelope returned by the server"
|
|
10427
|
+
).option(
|
|
10428
|
+
"--expect-success",
|
|
10429
|
+
"Evaluate the tool-call outcome policy against isError"
|
|
10430
|
+
).option(
|
|
10431
|
+
"--reporter <reporter>",
|
|
10432
|
+
"Structured reporter output: json-summary or junit-xml"
|
|
10433
|
+
).option(
|
|
10434
|
+
"--debug-out <path>",
|
|
10435
|
+
"Write a structured debug artifact to a file"
|
|
10436
|
+
).option(
|
|
10437
|
+
"--ui",
|
|
10438
|
+
"Render the tool result in Inspector Playground; opens a browser by default in a TTY"
|
|
10439
|
+
).option(
|
|
10440
|
+
"--require-render",
|
|
10441
|
+
"Treat skipped Inspector renders as errors (with --ui)"
|
|
10442
|
+
).option(
|
|
10443
|
+
"--open",
|
|
10444
|
+
"Open Inspector in the system browser before rendering (default with --ui in a TTY)"
|
|
10445
|
+
).option(
|
|
10446
|
+
"--no-open",
|
|
10447
|
+
"Start/use Inspector without opening a system browser"
|
|
10448
|
+
).option(
|
|
10449
|
+
"--attach-only",
|
|
10450
|
+
"Require an already-running Inspector browser client; do not start or open Inspector"
|
|
10451
|
+
).option("--inspector-url <url>", "Local Inspector base URL (with --ui)").option(
|
|
10452
|
+
"--frontend-url <url>",
|
|
10453
|
+
"Inspector frontend URL (with --ui; overrides health-advertised frontend and skips discovery)"
|
|
10454
|
+
).option(
|
|
10455
|
+
"--server-name <name>",
|
|
10456
|
+
"Server name inside Inspector (with --ui)"
|
|
10457
|
+
).option(
|
|
10458
|
+
"--protocol <protocol>",
|
|
10459
|
+
'Render protocol: "mcp-apps" or "openai-sdk" (with --ui)'
|
|
10460
|
+
).option(
|
|
10461
|
+
"--device <device>",
|
|
10462
|
+
'Render device: "mobile", "tablet", "desktop", or "custom" (with --ui)'
|
|
10463
|
+
).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(
|
|
10464
|
+
"--task",
|
|
10465
|
+
"Invite the server to answer with a task instead of a result. Uses whichever tasks wire the connection resolves to."
|
|
10466
|
+
).option(
|
|
10467
|
+
"--task-ttl <ms>",
|
|
10468
|
+
"Requested task TTL (2025-11-25 wire only; the extension server owns its TTL). Requires --task.",
|
|
10469
|
+
(value) => parsePositiveInteger(value, "Task TTL")
|
|
10470
|
+
).option(
|
|
10471
|
+
"--task-watch",
|
|
10472
|
+
"After creating the task, poll it to a terminal status in the same connection. Requires --task."
|
|
10473
|
+
).option(
|
|
10474
|
+
"--wire <wire>",
|
|
10475
|
+
"Assert the connection resolves to this tasks wire: legacy or extension (with --task)",
|
|
10476
|
+
parseTasksWireOption
|
|
10477
|
+
)
|
|
10478
|
+
)
|
|
8309
10479
|
)
|
|
8310
10480
|
).action(async (options, command) => {
|
|
8311
10481
|
const globalOptions = getGlobalOptions(command);
|
|
@@ -8341,6 +10511,11 @@ function registerToolsCommands(program) {
|
|
|
8341
10511
|
);
|
|
8342
10512
|
}
|
|
8343
10513
|
const paramsInput = options.toolArgsStdin ? "-" : resolvedParamsInput;
|
|
10514
|
+
if (options.interactive && paramsInput === "-") {
|
|
10515
|
+
throw usageError(
|
|
10516
|
+
"--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."
|
|
10517
|
+
);
|
|
10518
|
+
}
|
|
8344
10519
|
const params = parseJsonRecord(paramsInput, "Tool parameters") ?? {};
|
|
8345
10520
|
const targetSummary = summarizeServerDoctorTarget(target, config);
|
|
8346
10521
|
const shouldValidateResponse = options.validateResponse === true;
|
|
@@ -8359,6 +10534,59 @@ function registerToolsCommands(program) {
|
|
|
8359
10534
|
"--reporter requires --validate-response and/or --expect-success."
|
|
8360
10535
|
);
|
|
8361
10536
|
}
|
|
10537
|
+
const watchTuningFlags = [
|
|
10538
|
+
["--duration-ms", options.durationMs],
|
|
10539
|
+
["--poll-interval-ms", options.pollIntervalMs],
|
|
10540
|
+
["--max-input-rounds", options.maxInputRounds],
|
|
10541
|
+
["--max-consecutive-errors", options.maxConsecutiveErrors]
|
|
10542
|
+
];
|
|
10543
|
+
if (!options.task) {
|
|
10544
|
+
if (options.taskTtl !== void 0) {
|
|
10545
|
+
throw usageError("--task-ttl requires --task.");
|
|
10546
|
+
}
|
|
10547
|
+
if (options.taskWatch) throw usageError("--task-watch requires --task.");
|
|
10548
|
+
if (options.wire !== void 0) {
|
|
10549
|
+
throw usageError("--wire requires --task.");
|
|
10550
|
+
}
|
|
10551
|
+
for (const [flag, value] of watchTuningFlags) {
|
|
10552
|
+
if (value !== void 0) {
|
|
10553
|
+
throw usageError(`${flag} requires --task --task-watch.`);
|
|
10554
|
+
}
|
|
10555
|
+
}
|
|
10556
|
+
} else {
|
|
10557
|
+
if (!options.taskWatch) {
|
|
10558
|
+
for (const [flag, value] of watchTuningFlags) {
|
|
10559
|
+
if (value !== void 0) {
|
|
10560
|
+
throw usageError(
|
|
10561
|
+
`${flag} tunes the watch loop, so it requires --task-watch.`
|
|
10562
|
+
);
|
|
10563
|
+
}
|
|
10564
|
+
}
|
|
10565
|
+
}
|
|
10566
|
+
if (options.ui) {
|
|
10567
|
+
throw usageError("--task cannot be used together with --ui.");
|
|
10568
|
+
}
|
|
10569
|
+
if (reporter) {
|
|
10570
|
+
throw usageError("--task cannot be used together with --reporter.");
|
|
10571
|
+
}
|
|
10572
|
+
if (shouldValidateResponse || shouldExpectSuccess) {
|
|
10573
|
+
throw usageError(
|
|
10574
|
+
"--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."
|
|
10575
|
+
);
|
|
10576
|
+
}
|
|
10577
|
+
await runTaskAugmentedToolCall({
|
|
10578
|
+
options,
|
|
10579
|
+
globalOptions,
|
|
10580
|
+
config,
|
|
10581
|
+
host,
|
|
10582
|
+
toolName,
|
|
10583
|
+
params,
|
|
10584
|
+
collector: primaryCollector,
|
|
10585
|
+
targetSummary,
|
|
10586
|
+
snapshotCollector
|
|
10587
|
+
});
|
|
10588
|
+
return;
|
|
10589
|
+
}
|
|
8362
10590
|
const renderContext = options.ui ? {
|
|
8363
10591
|
protocol: parseRenderProtocol(options.protocol),
|
|
8364
10592
|
deviceType: parseRenderDevice(options.device),
|
|
@@ -8380,7 +10608,9 @@ function registerToolsCommands(program) {
|
|
|
8380
10608
|
{
|
|
8381
10609
|
timeout: globalOptions.timeout,
|
|
8382
10610
|
rpcLogger: primaryCollector?.rpcLogger,
|
|
8383
|
-
host: host?.connection
|
|
10611
|
+
host: host?.connection,
|
|
10612
|
+
beforeConnect: buildMrtrBeforeConnect(options),
|
|
10613
|
+
interactiveElicitation: options.interactive === true
|
|
8384
10614
|
}
|
|
8385
10615
|
);
|
|
8386
10616
|
} catch (error) {
|
|
@@ -8742,7 +10972,7 @@ function buildCompactInspectorRender(uiResult, options = {}) {
|
|
|
8742
10972
|
hasCommandError = true;
|
|
8743
10973
|
}
|
|
8744
10974
|
}
|
|
8745
|
-
const topLevelError = options.skipped ? options.issue ? { warning: options.issue } : uiResult.status === "error" &&
|
|
10975
|
+
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
10976
|
return {
|
|
8747
10977
|
status: options.skipped ? "skipped" : hasCommandError || uiResult.status === "error" ? "error" : "rendered",
|
|
8748
10978
|
remediation: options.remediation ?? "none",
|
|
@@ -8771,18 +11001,18 @@ function parseInspectorFrontendUrl(value) {
|
|
|
8771
11001
|
return frontendUrl;
|
|
8772
11002
|
}
|
|
8773
11003
|
function compactInspectorCommandResponse(value) {
|
|
8774
|
-
if (!
|
|
11004
|
+
if (!isRecord3(value) || !isCompactInspectorCommandStatus(value.status)) {
|
|
8775
11005
|
return void 0;
|
|
8776
11006
|
}
|
|
8777
11007
|
return {
|
|
8778
11008
|
status: value.status,
|
|
8779
|
-
...value.status === "error" &&
|
|
11009
|
+
...value.status === "error" && isRecord3(value.error) ? { error: value.error } : {}
|
|
8780
11010
|
};
|
|
8781
11011
|
}
|
|
8782
11012
|
function isCompactInspectorCommandStatus(value) {
|
|
8783
11013
|
return value === "success" || value === "error";
|
|
8784
11014
|
}
|
|
8785
|
-
function
|
|
11015
|
+
function isRecord3(value) {
|
|
8786
11016
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
8787
11017
|
}
|
|
8788
11018
|
function tunnelPathPrefix(serverId) {
|
|
@@ -9904,9 +12134,11 @@ async function main(argv = process.argv, dependencies = {}) {
|
|
|
9904
12134
|
registerServerCommands(program);
|
|
9905
12135
|
registerToolsCommands(program);
|
|
9906
12136
|
registerResourcesCommands(program);
|
|
12137
|
+
registerSubscriptionsCommands(program);
|
|
9907
12138
|
registerCompatCommands(program);
|
|
9908
12139
|
registerPromptCommands(program);
|
|
9909
12140
|
registerAppsCommands(program);
|
|
12141
|
+
registerTasksCommands(program);
|
|
9910
12142
|
registerOAuthCommands(program);
|
|
9911
12143
|
registerXaaCommands(program);
|
|
9912
12144
|
registerProtocolCommands(program);
|
|
@@ -9915,6 +12147,7 @@ async function main(argv = process.argv, dependencies = {}) {
|
|
|
9915
12147
|
registerEvalCommands(program);
|
|
9916
12148
|
registerHostsCommands(program);
|
|
9917
12149
|
registerEnvironmentsCommands(program);
|
|
12150
|
+
registerImagesCommands(program);
|
|
9918
12151
|
registerTunnelCommands(program);
|
|
9919
12152
|
registerInspectorCommands(program);
|
|
9920
12153
|
registerMcpCommands(program);
|