@mcpjam/cli 2.0.2 → 2.1.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/README.md +1 -1
- package/dist/index.js +592 -231
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
12
12
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
13
13
|
|
|
14
14
|
// package.json
|
|
15
|
-
var version = "2.0
|
|
15
|
+
var version = "2.1.0";
|
|
16
16
|
|
|
17
17
|
// src/lib/output.ts
|
|
18
18
|
var DEFAULT_OUTPUT_FORMAT = "json";
|
|
@@ -233,51 +233,16 @@ async function withEphemeralManager(config, fn, options) {
|
|
|
233
233
|
serverId: "__cli__",
|
|
234
234
|
clientName: "mcpjam",
|
|
235
235
|
timeout: options?.timeout ?? 3e4,
|
|
236
|
-
rpcLogger: options?.rpcLogger
|
|
236
|
+
rpcLogger: options?.rpcLogger,
|
|
237
|
+
retryPolicy: options?.retryPolicy
|
|
237
238
|
});
|
|
238
239
|
}
|
|
239
240
|
|
|
240
|
-
// src/lib/redaction.ts
|
|
241
|
-
function redactSensitiveValue(value) {
|
|
242
|
-
if (Array.isArray(value)) {
|
|
243
|
-
return value.map((entry) => redactSensitiveValue(entry));
|
|
244
|
-
}
|
|
245
|
-
if (!value || typeof value !== "object") {
|
|
246
|
-
return typeof value === "string" ? redactSensitiveString(value) : value;
|
|
247
|
-
}
|
|
248
|
-
return Object.fromEntries(
|
|
249
|
-
Object.entries(value).map(([key, entryValue]) => [
|
|
250
|
-
key,
|
|
251
|
-
shouldRedactKey(key) ? "[REDACTED]" : redactSensitiveValue(entryValue)
|
|
252
|
-
])
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
function redactSensitiveString(value) {
|
|
256
|
-
return value.replace(
|
|
257
|
-
/\b(authorization|proxy-authorization|cookie|set-cookie)\s*:\s*[^\r\n]*/giu,
|
|
258
|
-
(_match, headerName) => `${headerName}: [REDACTED]`
|
|
259
|
-
).replace(
|
|
260
|
-
/\bBearer\s+(?![A-Za-z_][A-Za-z0-9_-]*=)([A-Za-z0-9\-._~+/]+=*)/giu,
|
|
261
|
-
"Bearer [REDACTED]"
|
|
262
|
-
).replace(
|
|
263
|
-
/\b(access_token|refresh_token|client_secret|id_token|code|code_verifier|accessToken|refreshToken|clientSecret|idToken|codeVerifier)=([^&\s]+)/giu,
|
|
264
|
-
"$1=[REDACTED]"
|
|
265
|
-
).replace(
|
|
266
|
-
/(["']?(?:access_token|refresh_token|client_secret|id_token|code|code_verifier|accessToken|refreshToken|clientSecret|idToken|codeVerifier)["']?\s*:\s*["'])[^"']*(["'])/giu,
|
|
267
|
-
"$1[REDACTED]$2"
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
function shouldRedactKey(key) {
|
|
271
|
-
const normalized = key.toLowerCase().replace(/[^a-z0-9]/gu, "");
|
|
272
|
-
return normalized === "authorization" || normalized === "proxyauthorization" || normalized === "cookie" || normalized === "setcookie" || normalized === "accesstoken" || normalized === "refreshtoken" || normalized === "clientsecret" || normalized === "idtoken" || normalized === "apikey" || normalized === "xapikey";
|
|
273
|
-
}
|
|
274
|
-
|
|
275
241
|
// src/lib/rpc-logs.ts
|
|
276
242
|
var CliRpcLogCollector = class {
|
|
277
243
|
constructor(serverNamesById) {
|
|
278
244
|
this.serverNamesById = serverNamesById;
|
|
279
245
|
}
|
|
280
|
-
serverNamesById;
|
|
281
246
|
logs = [];
|
|
282
247
|
rpcLogger = ({ direction, message, serverId }) => {
|
|
283
248
|
this.logs.push({
|
|
@@ -313,7 +278,7 @@ function getCliRpcLogEvents(collectors) {
|
|
|
313
278
|
function redactCliRpcLogs(logs) {
|
|
314
279
|
return logs.map((event) => ({
|
|
315
280
|
...event,
|
|
316
|
-
message: redactSensitiveValue(event.message)
|
|
281
|
+
message: sdk.redactSensitiveValue(event.message)
|
|
317
282
|
}));
|
|
318
283
|
}
|
|
319
284
|
|
|
@@ -326,20 +291,21 @@ function withRpcLogsIfRequested(value, collector, options) {
|
|
|
326
291
|
}
|
|
327
292
|
|
|
328
293
|
// src/lib/server-config.ts
|
|
294
|
+
var DEFAULT_CLI_RETRY_POLICY = {
|
|
295
|
+
retries: 0,
|
|
296
|
+
retryDelayMs: 3e3
|
|
297
|
+
};
|
|
329
298
|
function collectString(value, previous = []) {
|
|
330
299
|
return [...previous, value];
|
|
331
300
|
}
|
|
332
301
|
function addSharedServerOptions(command) {
|
|
333
|
-
return command.option(
|
|
302
|
+
return command.option(
|
|
303
|
+
"--transport <transport>",
|
|
304
|
+
'Explicit transport type: "http" or "stdio"'
|
|
305
|
+
).option("--url <url>", "HTTP MCP server URL").option("--access-token <token>", "Bearer access token for HTTP servers").option(
|
|
334
306
|
"--oauth-access-token <token>",
|
|
335
307
|
"OAuth bearer access token for HTTP servers"
|
|
336
|
-
).option(
|
|
337
|
-
"--refresh-token <token>",
|
|
338
|
-
"OAuth refresh token for HTTP servers"
|
|
339
|
-
).option(
|
|
340
|
-
"--client-id <id>",
|
|
341
|
-
"OAuth client ID used with --refresh-token"
|
|
342
|
-
).option(
|
|
308
|
+
).option("--refresh-token <token>", "OAuth refresh token for HTTP servers").option("--client-id <id>", "OAuth client ID used with --refresh-token").option(
|
|
343
309
|
"--client-secret <secret>",
|
|
344
310
|
"OAuth client secret used with --refresh-token"
|
|
345
311
|
).option(
|
|
@@ -351,19 +317,24 @@ function addSharedServerOptions(command) {
|
|
|
351
317
|
"--client-capabilities <json>",
|
|
352
318
|
"Client capabilities advertised to the server as a JSON object"
|
|
353
319
|
).option("--command <command>", "Command for a stdio MCP server").option(
|
|
320
|
+
"--args <arg...>",
|
|
321
|
+
"Preferred stdio command arguments. Pass multiple values or repeat the flag."
|
|
322
|
+
).option(
|
|
354
323
|
"--command-args <arg>",
|
|
355
|
-
"
|
|
324
|
+
"Legacy stdio command argument. Repeat to pass multiple arguments.",
|
|
356
325
|
collectString
|
|
357
326
|
).option(
|
|
358
|
-
"--env <env
|
|
359
|
-
'Stdio environment assignment in "KEY=VALUE" format.
|
|
360
|
-
|
|
361
|
-
);
|
|
327
|
+
"-e, --env <env...>",
|
|
328
|
+
'Stdio environment assignment in "KEY=VALUE" format. Pass multiple values or repeat the flag.'
|
|
329
|
+
).option("--cwd <path>", "Working directory for the stdio MCP server process");
|
|
362
330
|
}
|
|
363
331
|
function getGlobalOptions(command) {
|
|
364
332
|
const options = command.optsWithGlobals();
|
|
365
333
|
return {
|
|
366
|
-
format: resolveOutputFormat(
|
|
334
|
+
format: resolveOutputFormat(
|
|
335
|
+
options.format,
|
|
336
|
+
process.stdout.isTTY
|
|
337
|
+
),
|
|
367
338
|
timeout: options.timeout ?? 3e4,
|
|
368
339
|
rpc: options.rpc ?? false
|
|
369
340
|
};
|
|
@@ -375,6 +346,37 @@ function parsePositiveInteger(value, label = "Value") {
|
|
|
375
346
|
}
|
|
376
347
|
return parsed;
|
|
377
348
|
}
|
|
349
|
+
function parseNonNegativeInteger(value, label = "Value") {
|
|
350
|
+
const parsed = Number(value);
|
|
351
|
+
if (!Number.isInteger(parsed) || parsed < 0) {
|
|
352
|
+
throw usageError(`${label} must be a non-negative integer.`);
|
|
353
|
+
}
|
|
354
|
+
return parsed;
|
|
355
|
+
}
|
|
356
|
+
function addRetryOptions(command) {
|
|
357
|
+
return command.option(
|
|
358
|
+
"--retries <count>",
|
|
359
|
+
"Retry transient failures this many times",
|
|
360
|
+
(value) => parseNonNegativeInteger(value, "Retries")
|
|
361
|
+
).option(
|
|
362
|
+
"--retry-delay-ms <ms>",
|
|
363
|
+
"Fixed delay between retries in milliseconds",
|
|
364
|
+
(value) => parseNonNegativeInteger(value, "Retry delay")
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
function parseRetryPolicy(options = {}) {
|
|
368
|
+
if (options.retries === void 0 && options.retryDelayMs === void 0) {
|
|
369
|
+
return void 0;
|
|
370
|
+
}
|
|
371
|
+
const retries = options.retries ?? DEFAULT_CLI_RETRY_POLICY.retries;
|
|
372
|
+
if (options.retryDelayMs !== void 0 && retries === 0) {
|
|
373
|
+
throw usageError("--retry-delay-ms requires --retries to be greater than 0.");
|
|
374
|
+
}
|
|
375
|
+
return {
|
|
376
|
+
retries,
|
|
377
|
+
retryDelayMs: options.retryDelayMs ?? DEFAULT_CLI_RETRY_POLICY.retryDelayMs
|
|
378
|
+
};
|
|
379
|
+
}
|
|
378
380
|
function parseHeadersOption(headers) {
|
|
379
381
|
if (!headers || headers.length === 0) {
|
|
380
382
|
return void 0;
|
|
@@ -430,7 +432,9 @@ function resolveAliasedStringOption(options, aliases, label, config) {
|
|
|
430
432
|
flag: alias.flag,
|
|
431
433
|
value: normalized
|
|
432
434
|
};
|
|
433
|
-
}).filter(
|
|
435
|
+
}).filter(
|
|
436
|
+
(entry) => entry !== void 0
|
|
437
|
+
);
|
|
434
438
|
const flagsText = aliases.map((alias) => alias.flag).join(" or ");
|
|
435
439
|
if (provided.length === 0) {
|
|
436
440
|
if (config?.required) {
|
|
@@ -449,16 +453,15 @@ function parseServerConfig(options) {
|
|
|
449
453
|
const command = options.command?.trim();
|
|
450
454
|
const hasUrl = Boolean(url);
|
|
451
455
|
const hasCommand = Boolean(command);
|
|
456
|
+
const transport = resolveTargetTransport(options, hasUrl, hasCommand);
|
|
457
|
+
const cwd = options.cwd?.trim();
|
|
452
458
|
const clientCapabilities = resolveClientCapabilities(
|
|
453
459
|
options.clientCapabilities
|
|
454
460
|
);
|
|
455
|
-
if (
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
if (hasUrl && url) {
|
|
459
|
-
if ((options.commandArgs?.length ?? 0) > 0 || (options.env?.length ?? 0) > 0) {
|
|
461
|
+
if (transport === "http" && url) {
|
|
462
|
+
if ((options.args?.length ?? 0) > 0 || (options.commandArgs?.length ?? 0) > 0 || (options.env?.length ?? 0) > 0 || cwd) {
|
|
460
463
|
throw usageError(
|
|
461
|
-
"--command-args and --
|
|
464
|
+
"--args, --command-args, --env, and --cwd can only be used together with --command."
|
|
462
465
|
);
|
|
463
466
|
}
|
|
464
467
|
try {
|
|
@@ -505,10 +508,11 @@ function parseServerConfig(options) {
|
|
|
505
508
|
}
|
|
506
509
|
return {
|
|
507
510
|
command,
|
|
508
|
-
args: parseCommandArgs(options.commandArgs),
|
|
511
|
+
args: parseCommandArgs(options.args, options.commandArgs),
|
|
509
512
|
env: parseEnvironmentOption(options.env),
|
|
513
|
+
...cwd ? { cwd } : {},
|
|
510
514
|
...clientCapabilities ? { clientCapabilities } : {},
|
|
511
|
-
stderr: "
|
|
515
|
+
stderr: "pipe",
|
|
512
516
|
timeout: options.timeout
|
|
513
517
|
};
|
|
514
518
|
}
|
|
@@ -537,11 +541,12 @@ function parseHeader(entry) {
|
|
|
537
541
|
}
|
|
538
542
|
return [key, value];
|
|
539
543
|
}
|
|
540
|
-
function parseCommandArgs(values) {
|
|
541
|
-
|
|
544
|
+
function parseCommandArgs(values, legacyValues) {
|
|
545
|
+
const combined = [...values ?? [], ...legacyValues ?? []];
|
|
546
|
+
if (combined.length === 0) {
|
|
542
547
|
return void 0;
|
|
543
548
|
}
|
|
544
|
-
return
|
|
549
|
+
return combined;
|
|
545
550
|
}
|
|
546
551
|
function parseEnvironmentOption(values) {
|
|
547
552
|
if (!values || values.length === 0) {
|
|
@@ -575,6 +580,42 @@ function resolveClientCapabilities(value) {
|
|
|
575
580
|
}
|
|
576
581
|
return parseUnknownRecord(value, "Client capabilities");
|
|
577
582
|
}
|
|
583
|
+
function resolveTargetTransport(options, hasUrl, hasCommand) {
|
|
584
|
+
const transport = resolveTransportOption(options.transport);
|
|
585
|
+
if (!transport) {
|
|
586
|
+
if (hasUrl === hasCommand) {
|
|
587
|
+
throw usageError("Specify exactly one target: either --url or --command.");
|
|
588
|
+
}
|
|
589
|
+
return hasUrl ? "http" : "stdio";
|
|
590
|
+
}
|
|
591
|
+
if (transport === "http") {
|
|
592
|
+
if (!hasUrl) {
|
|
593
|
+
throw usageError("--transport http requires --url.");
|
|
594
|
+
}
|
|
595
|
+
if (hasCommand) {
|
|
596
|
+
throw usageError("--command can only be used with --transport stdio.");
|
|
597
|
+
}
|
|
598
|
+
return transport;
|
|
599
|
+
}
|
|
600
|
+
if (!hasCommand) {
|
|
601
|
+
throw usageError("--transport stdio requires --command.");
|
|
602
|
+
}
|
|
603
|
+
if (hasUrl) {
|
|
604
|
+
throw usageError("--url can only be used with --transport http.");
|
|
605
|
+
}
|
|
606
|
+
return transport;
|
|
607
|
+
}
|
|
608
|
+
function resolveTransportOption(value) {
|
|
609
|
+
if (value === void 0) {
|
|
610
|
+
return void 0;
|
|
611
|
+
}
|
|
612
|
+
if (value === "http" || value === "stdio") {
|
|
613
|
+
return value;
|
|
614
|
+
}
|
|
615
|
+
throw usageError(
|
|
616
|
+
`Invalid transport "${value}". Use "http" or "stdio".`
|
|
617
|
+
);
|
|
618
|
+
}
|
|
578
619
|
function resolveHttpAccessToken(options) {
|
|
579
620
|
const accessToken = options.accessToken?.trim();
|
|
580
621
|
const oauthAccessToken = options.oauthAccessToken?.trim();
|
|
@@ -601,7 +642,9 @@ var APPS_CHECK_IDS_BY_CATEGORY = {
|
|
|
601
642
|
]
|
|
602
643
|
};
|
|
603
644
|
function registerAppsCommands(program) {
|
|
604
|
-
const apps = program.command("apps").description(
|
|
645
|
+
const apps = program.command("apps").description(
|
|
646
|
+
"MCP Apps utilities, widget extraction, and conformance checks"
|
|
647
|
+
);
|
|
605
648
|
addSharedServerOptions(
|
|
606
649
|
apps.command("conformance").description("Run MCP Apps server conformance checks").option(
|
|
607
650
|
"--category <category>",
|
|
@@ -634,13 +677,19 @@ function registerAppsCommands(program) {
|
|
|
634
677
|
setProcessExitCode(1);
|
|
635
678
|
}
|
|
636
679
|
});
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
"--
|
|
640
|
-
|
|
641
|
-
|
|
680
|
+
addRetryOptions(
|
|
681
|
+
addSharedServerOptions(
|
|
682
|
+
apps.command("mcp-widget").description("Fetch hosted-style MCP App widget content").option("--resource-uri <uri>", "Widget resource URI").option("--uri <uri>", "Alias for --resource-uri").requiredOption(
|
|
683
|
+
"--tool-id <id>",
|
|
684
|
+
"Tool call id used for runtime injection"
|
|
685
|
+
).requiredOption(
|
|
686
|
+
"--tool-name <name>",
|
|
687
|
+
"Tool name used for runtime injection"
|
|
688
|
+
).option("--tool-input <json>", "Tool input payload as JSON").option("--tool-output <json>", "Tool output payload as JSON").option("--theme <theme>", "Widget theme: light or dark").option("--csp-mode <mode>", "CSP mode: permissive or widget-declared").option("--template <uri>", "Optional ui:// template override").option("--view-mode <mode>", "Widget view mode").option("--view-params <json>", "Widget view params as JSON")
|
|
689
|
+
)
|
|
642
690
|
).action(async (options, command) => {
|
|
643
691
|
const globalOptions = getGlobalOptions(command);
|
|
692
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
644
693
|
const target = describeTarget(options);
|
|
645
694
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
646
695
|
const resourceUri = resolveAliasedStringOption(
|
|
@@ -672,21 +721,34 @@ function registerAppsCommands(program) {
|
|
|
672
721
|
}),
|
|
673
722
|
{
|
|
674
723
|
timeout: globalOptions.timeout,
|
|
675
|
-
rpcLogger: collector?.rpcLogger
|
|
724
|
+
rpcLogger: collector?.rpcLogger,
|
|
725
|
+
retryPolicy
|
|
676
726
|
}
|
|
677
727
|
);
|
|
678
|
-
writeResult(
|
|
728
|
+
writeResult(
|
|
729
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
730
|
+
globalOptions.format
|
|
731
|
+
);
|
|
679
732
|
});
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
"
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
733
|
+
addRetryOptions(
|
|
734
|
+
addSharedServerOptions(
|
|
735
|
+
apps.command("chatgpt-widget").description("Fetch hosted-style ChatGPT App widget content").option("--resource-uri <uri>", "Widget resource URI").option("--uri <uri>", "Alias for --resource-uri").requiredOption(
|
|
736
|
+
"--tool-id <id>",
|
|
737
|
+
"Tool call id used for runtime injection"
|
|
738
|
+
).requiredOption(
|
|
739
|
+
"--tool-name <name>",
|
|
740
|
+
"Tool name used for runtime injection"
|
|
741
|
+
).option("--tool-input <json>", "Tool input payload as JSON").option("--tool-output <json>", "Tool output payload as JSON").option(
|
|
742
|
+
"--tool-response-metadata <json>",
|
|
743
|
+
"Tool response metadata as a JSON object"
|
|
744
|
+
).option("--theme <theme>", "Widget theme: light or dark").option("--csp-mode <mode>", "CSP mode: permissive or widget-declared").option("--locale <locale>", "Locale override").option(
|
|
745
|
+
"--device-type <type>",
|
|
746
|
+
"Device type: mobile, tablet, or desktop"
|
|
747
|
+
)
|
|
748
|
+
)
|
|
688
749
|
).action(async (options, command) => {
|
|
689
750
|
const globalOptions = getGlobalOptions(command);
|
|
751
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
690
752
|
const target = describeTarget(options);
|
|
691
753
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
692
754
|
const resourceUri = resolveAliasedStringOption(
|
|
@@ -721,10 +783,14 @@ function registerAppsCommands(program) {
|
|
|
721
783
|
}),
|
|
722
784
|
{
|
|
723
785
|
timeout: globalOptions.timeout,
|
|
724
|
-
rpcLogger: collector?.rpcLogger
|
|
786
|
+
rpcLogger: collector?.rpcLogger,
|
|
787
|
+
retryPolicy
|
|
725
788
|
}
|
|
726
789
|
);
|
|
727
|
-
writeResult(
|
|
790
|
+
writeResult(
|
|
791
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
792
|
+
globalOptions.format
|
|
793
|
+
);
|
|
728
794
|
});
|
|
729
795
|
}
|
|
730
796
|
function parseJsonValue(value) {
|
|
@@ -1119,7 +1185,7 @@ function buildDebugArtifactEnvelope(options) {
|
|
|
1119
1185
|
if (rpcLogs.length > 0) {
|
|
1120
1186
|
payload._rpcLogs = rpcLogs;
|
|
1121
1187
|
}
|
|
1122
|
-
return redactSensitiveValue(payload);
|
|
1188
|
+
return sdk.redactSensitiveValue(payload);
|
|
1123
1189
|
}
|
|
1124
1190
|
function buildCommandArtifactError(code, message, details) {
|
|
1125
1191
|
return {
|
|
@@ -1130,7 +1196,7 @@ function buildCommandArtifactError(code, message, details) {
|
|
|
1130
1196
|
}
|
|
1131
1197
|
async function writeDebugArtifact(outputPath, payload) {
|
|
1132
1198
|
const resolvedPath = path__default.default.resolve(process.cwd(), outputPath);
|
|
1133
|
-
const redactedPayload = redactSensitiveValue(payload);
|
|
1199
|
+
const redactedPayload = sdk.redactSensitiveValue(payload);
|
|
1134
1200
|
try {
|
|
1135
1201
|
await promises.mkdir(path__default.default.dirname(resolvedPath), { recursive: true });
|
|
1136
1202
|
await promises.writeFile(
|
|
@@ -1735,10 +1801,13 @@ function statusToErrorCode(status) {
|
|
|
1735
1801
|
}
|
|
1736
1802
|
function registerPromptCommands(program) {
|
|
1737
1803
|
const prompts = program.command("prompts").description("List and fetch MCP prompts");
|
|
1738
|
-
|
|
1739
|
-
|
|
1804
|
+
addRetryOptions(
|
|
1805
|
+
addSharedServerOptions(
|
|
1806
|
+
prompts.command("list").description("List prompts exposed by an MCP server").option("--cursor <cursor>", "Pagination cursor")
|
|
1807
|
+
)
|
|
1740
1808
|
).action(async (options, command) => {
|
|
1741
1809
|
const globalOptions = getGlobalOptions(command);
|
|
1810
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
1742
1811
|
const target = describeTarget(options);
|
|
1743
1812
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
1744
1813
|
const config = parseServerConfig({
|
|
@@ -1750,15 +1819,22 @@ function registerPromptCommands(program) {
|
|
|
1750
1819
|
(manager, serverId) => sdk.listPrompts(manager, { serverId, cursor: options.cursor }),
|
|
1751
1820
|
{
|
|
1752
1821
|
timeout: globalOptions.timeout,
|
|
1753
|
-
rpcLogger: collector?.rpcLogger
|
|
1822
|
+
rpcLogger: collector?.rpcLogger,
|
|
1823
|
+
retryPolicy
|
|
1754
1824
|
}
|
|
1755
1825
|
);
|
|
1756
|
-
writeResult(
|
|
1826
|
+
writeResult(
|
|
1827
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
1828
|
+
globalOptions.format
|
|
1829
|
+
);
|
|
1757
1830
|
});
|
|
1758
|
-
|
|
1759
|
-
|
|
1831
|
+
addRetryOptions(
|
|
1832
|
+
addSharedServerOptions(
|
|
1833
|
+
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("--prompt-args <json>", "Prompt arguments as a JSON object")
|
|
1834
|
+
)
|
|
1760
1835
|
).action(async (options, command) => {
|
|
1761
1836
|
const globalOptions = getGlobalOptions(command);
|
|
1837
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
1762
1838
|
const target = describeTarget(options);
|
|
1763
1839
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
1764
1840
|
const promptName = resolveAliasedStringOption(
|
|
@@ -1784,18 +1860,25 @@ function registerPromptCommands(program) {
|
|
|
1784
1860
|
}),
|
|
1785
1861
|
{
|
|
1786
1862
|
timeout: globalOptions.timeout,
|
|
1787
|
-
rpcLogger: collector?.rpcLogger
|
|
1863
|
+
rpcLogger: collector?.rpcLogger,
|
|
1864
|
+
retryPolicy
|
|
1788
1865
|
}
|
|
1789
1866
|
);
|
|
1790
|
-
writeResult(
|
|
1867
|
+
writeResult(
|
|
1868
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
1869
|
+
globalOptions.format
|
|
1870
|
+
);
|
|
1791
1871
|
});
|
|
1792
1872
|
}
|
|
1793
1873
|
function registerResourcesCommands(program) {
|
|
1794
1874
|
const resources = program.command("resources").description("List and read MCP resources");
|
|
1795
|
-
|
|
1796
|
-
|
|
1875
|
+
addRetryOptions(
|
|
1876
|
+
addSharedServerOptions(
|
|
1877
|
+
resources.command("list").description("List resources exposed by an MCP server").option("--cursor <cursor>", "Pagination cursor")
|
|
1878
|
+
)
|
|
1797
1879
|
).action(async (options, command) => {
|
|
1798
1880
|
const globalOptions = getGlobalOptions(command);
|
|
1881
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
1799
1882
|
const target = describeTarget(options);
|
|
1800
1883
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
1801
1884
|
const config = parseServerConfig({
|
|
@@ -1807,15 +1890,22 @@ function registerResourcesCommands(program) {
|
|
|
1807
1890
|
(manager, serverId) => sdk.listResources(manager, { serverId, cursor: options.cursor }),
|
|
1808
1891
|
{
|
|
1809
1892
|
timeout: globalOptions.timeout,
|
|
1810
|
-
rpcLogger: collector?.rpcLogger
|
|
1893
|
+
rpcLogger: collector?.rpcLogger,
|
|
1894
|
+
retryPolicy
|
|
1811
1895
|
}
|
|
1812
1896
|
);
|
|
1813
|
-
writeResult(
|
|
1897
|
+
writeResult(
|
|
1898
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
1899
|
+
globalOptions.format
|
|
1900
|
+
);
|
|
1814
1901
|
});
|
|
1815
|
-
|
|
1816
|
-
|
|
1902
|
+
addRetryOptions(
|
|
1903
|
+
addSharedServerOptions(
|
|
1904
|
+
resources.command("read").description("Read a resource from an MCP server").option("--resource-uri <uri>", "Resource URI").option("--uri <uri>", "Alias for --resource-uri")
|
|
1905
|
+
)
|
|
1817
1906
|
).action(async (options, command) => {
|
|
1818
1907
|
const globalOptions = getGlobalOptions(command);
|
|
1908
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
1819
1909
|
const target = describeTarget(options);
|
|
1820
1910
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
1821
1911
|
const resourceUri = resolveAliasedStringOption(
|
|
@@ -1836,15 +1926,22 @@ function registerResourcesCommands(program) {
|
|
|
1836
1926
|
(manager, serverId) => sdk.readResource(manager, { serverId, uri: resourceUri }),
|
|
1837
1927
|
{
|
|
1838
1928
|
timeout: globalOptions.timeout,
|
|
1839
|
-
rpcLogger: collector?.rpcLogger
|
|
1929
|
+
rpcLogger: collector?.rpcLogger,
|
|
1930
|
+
retryPolicy
|
|
1840
1931
|
}
|
|
1841
1932
|
);
|
|
1842
|
-
writeResult(
|
|
1933
|
+
writeResult(
|
|
1934
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
1935
|
+
globalOptions.format
|
|
1936
|
+
);
|
|
1843
1937
|
});
|
|
1844
|
-
|
|
1845
|
-
|
|
1938
|
+
addRetryOptions(
|
|
1939
|
+
addSharedServerOptions(
|
|
1940
|
+
resources.command("templates").description("List resource templates exposed by an MCP server").option("--cursor <cursor>", "Pagination cursor")
|
|
1941
|
+
)
|
|
1846
1942
|
).action(async (options, command) => {
|
|
1847
1943
|
const globalOptions = getGlobalOptions(command);
|
|
1944
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
1848
1945
|
const target = describeTarget(options);
|
|
1849
1946
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
1850
1947
|
const config = parseServerConfig({
|
|
@@ -1859,102 +1956,87 @@ function registerResourcesCommands(program) {
|
|
|
1859
1956
|
),
|
|
1860
1957
|
{
|
|
1861
1958
|
timeout: globalOptions.timeout,
|
|
1862
|
-
rpcLogger: collector?.rpcLogger
|
|
1959
|
+
rpcLogger: collector?.rpcLogger,
|
|
1960
|
+
retryPolicy
|
|
1863
1961
|
}
|
|
1864
1962
|
);
|
|
1865
|
-
writeResult(
|
|
1963
|
+
writeResult(
|
|
1964
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
1965
|
+
globalOptions.format
|
|
1966
|
+
);
|
|
1866
1967
|
});
|
|
1867
1968
|
}
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1969
|
+
function parseReporterFormat(value) {
|
|
1970
|
+
if (value === void 0) {
|
|
1971
|
+
return void 0;
|
|
1972
|
+
}
|
|
1973
|
+
if (value === "json-summary" || value === "junit-xml") {
|
|
1974
|
+
return value;
|
|
1975
|
+
}
|
|
1976
|
+
throw usageError(
|
|
1977
|
+
`Invalid reporter "${value}". Use "json-summary" or "junit-xml".`
|
|
1874
1978
|
);
|
|
1875
|
-
const tools = result.tools ?? [];
|
|
1876
|
-
const toolsMetadata = manager.getAllToolsMetadata(params.serverId);
|
|
1877
|
-
const tokenCount = params.modelId ? estimateTokensFromChars(JSON.stringify(tools)) : void 0;
|
|
1878
|
-
return {
|
|
1879
|
-
tools,
|
|
1880
|
-
nextCursor: result.nextCursor,
|
|
1881
|
-
toolsMetadata,
|
|
1882
|
-
...tokenCount === void 0 ? {} : { tokenCount }
|
|
1883
|
-
};
|
|
1884
1979
|
}
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
resourceTemplates: []
|
|
1892
|
-
}))
|
|
1893
|
-
]);
|
|
1894
|
-
return {
|
|
1895
|
-
target,
|
|
1896
|
-
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1897
|
-
initInfo: manager.getInitializationInfo(serverId) ?? null,
|
|
1898
|
-
capabilities: manager.getServerCapabilities(serverId) ?? null,
|
|
1899
|
-
tools: (toolsResult.tools ?? []).map((tool) => ({
|
|
1900
|
-
name: tool.name,
|
|
1901
|
-
description: tool.description,
|
|
1902
|
-
inputSchema: tool.inputSchema,
|
|
1903
|
-
outputSchema: tool.outputSchema
|
|
1904
|
-
})),
|
|
1905
|
-
toolsMetadata: manager.getAllToolsMetadata(serverId),
|
|
1906
|
-
resources: (resourcesResult.resources ?? []).map((resource) => ({
|
|
1907
|
-
uri: resource.uri,
|
|
1908
|
-
name: resource.name,
|
|
1909
|
-
description: resource.description,
|
|
1910
|
-
mimeType: resource.mimeType
|
|
1911
|
-
})),
|
|
1912
|
-
resourceTemplates: (resourceTemplatesResult.resourceTemplates ?? []).map(
|
|
1913
|
-
(template) => ({
|
|
1914
|
-
uriTemplate: template.uriTemplate,
|
|
1915
|
-
name: template.name,
|
|
1916
|
-
description: template.description,
|
|
1917
|
-
mimeType: template.mimeType
|
|
1918
|
-
})
|
|
1919
|
-
),
|
|
1920
|
-
prompts: (promptsResult.prompts ?? []).map((prompt) => ({
|
|
1921
|
-
name: prompt.name,
|
|
1922
|
-
description: prompt.description,
|
|
1923
|
-
arguments: prompt.arguments
|
|
1924
|
-
}))
|
|
1925
|
-
};
|
|
1980
|
+
function writeReporterResult(reporter, report) {
|
|
1981
|
+
if (reporter === "junit-xml") {
|
|
1982
|
+
process.stdout.write(sdk.renderStructuredRunJUnitXml(report));
|
|
1983
|
+
return;
|
|
1984
|
+
}
|
|
1985
|
+
writeResult(sdk.renderStructuredRunJson(report), "json");
|
|
1926
1986
|
}
|
|
1927
|
-
function
|
|
1928
|
-
|
|
1987
|
+
async function writeJsonArtifact(outputPath, payload) {
|
|
1988
|
+
const resolvedPath = path__default.default.resolve(process.cwd(), outputPath);
|
|
1989
|
+
try {
|
|
1990
|
+
await promises.mkdir(path__default.default.dirname(resolvedPath), { recursive: true });
|
|
1991
|
+
await promises.writeFile(
|
|
1992
|
+
resolvedPath,
|
|
1993
|
+
`${JSON.stringify(payload, null, 2)}
|
|
1994
|
+
`,
|
|
1995
|
+
"utf8"
|
|
1996
|
+
);
|
|
1997
|
+
} catch (error) {
|
|
1998
|
+
throw operationalError(
|
|
1999
|
+
`Failed to write JSON artifact to "${resolvedPath}".`,
|
|
2000
|
+
{
|
|
2001
|
+
source: error instanceof Error ? error.message : String(error)
|
|
2002
|
+
}
|
|
2003
|
+
);
|
|
2004
|
+
}
|
|
2005
|
+
return resolvedPath;
|
|
1929
2006
|
}
|
|
1930
2007
|
|
|
1931
2008
|
// src/commands/server.ts
|
|
1932
2009
|
function registerServerCommands(program) {
|
|
1933
2010
|
const server = program.command("server").description("Inspect MCP server connectivity and capabilities");
|
|
1934
|
-
|
|
1935
|
-
"
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
(
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
2011
|
+
addRetryOptions(
|
|
2012
|
+
server.command("probe").description(
|
|
2013
|
+
"Probe an HTTP MCP server without using the full client connect flow"
|
|
2014
|
+
).requiredOption("--url <url>", "HTTP MCP server URL").option("--access-token <token>", "Bearer access token for HTTP servers").option(
|
|
2015
|
+
"--oauth-access-token <token>",
|
|
2016
|
+
"OAuth bearer access token for HTTP servers"
|
|
2017
|
+
).option(
|
|
2018
|
+
"--header <header>",
|
|
2019
|
+
'HTTP header in "Key: Value" format. Repeat to send multiple headers.',
|
|
2020
|
+
(value, previous = []) => [...previous, value],
|
|
2021
|
+
[]
|
|
2022
|
+
).option(
|
|
2023
|
+
"--client-capabilities <json>",
|
|
2024
|
+
"Client capabilities advertised in the initialize probe as a JSON object"
|
|
2025
|
+
).option(
|
|
2026
|
+
"--protocol-version <version>",
|
|
2027
|
+
"OAuth/MCP protocol version hint used for the initialize probe",
|
|
2028
|
+
"2025-11-25"
|
|
2029
|
+
).option(
|
|
2030
|
+
"--timeout <ms>",
|
|
2031
|
+
"Request timeout in milliseconds",
|
|
2032
|
+
(value) => parsePositiveInteger(value, "Timeout")
|
|
2033
|
+
).option(
|
|
2034
|
+
"--debug-out <path>",
|
|
2035
|
+
"Write a structured debug artifact to a file"
|
|
2036
|
+
)
|
|
1956
2037
|
).action(async (options, command) => {
|
|
1957
2038
|
const globalOptions = getGlobalOptions(command);
|
|
2039
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
1958
2040
|
const protocolVersion = options.protocolVersion;
|
|
1959
2041
|
const config = parseServerConfig({
|
|
1960
2042
|
...options,
|
|
@@ -1981,7 +2063,8 @@ function registerServerCommands(program) {
|
|
|
1981
2063
|
headers: parseHeadersOption(options.header),
|
|
1982
2064
|
accessToken: resolveHttpAccessToken(options),
|
|
1983
2065
|
clientCapabilities: "clientCapabilities" in config ? config.clientCapabilities : void 0,
|
|
1984
|
-
timeoutMs: options.timeout ?? globalOptions.timeout
|
|
2066
|
+
timeoutMs: options.timeout ?? globalOptions.timeout,
|
|
2067
|
+
retryPolicy
|
|
1985
2068
|
});
|
|
1986
2069
|
} catch (error) {
|
|
1987
2070
|
commandError = error;
|
|
@@ -2029,10 +2112,13 @@ function registerServerCommands(program) {
|
|
|
2029
2112
|
setProcessExitCode(1);
|
|
2030
2113
|
}
|
|
2031
2114
|
});
|
|
2032
|
-
|
|
2033
|
-
|
|
2115
|
+
addRetryOptions(
|
|
2116
|
+
addSharedServerOptions(
|
|
2117
|
+
server.command("doctor").description("Run a stateless diagnostic sweep against an MCP server").option("--out <path>", "Write the doctor JSON artifact to a file")
|
|
2118
|
+
)
|
|
2034
2119
|
).action(async (options, command) => {
|
|
2035
2120
|
const globalOptions = getGlobalOptions(command);
|
|
2121
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
2036
2122
|
const target = describeTarget(options);
|
|
2037
2123
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
2038
2124
|
const config = parseServerConfig({
|
|
@@ -2040,14 +2126,13 @@ function registerServerCommands(program) {
|
|
|
2040
2126
|
timeout: globalOptions.timeout
|
|
2041
2127
|
});
|
|
2042
2128
|
const doctorTarget = summarizeServerDoctorTarget(target, config);
|
|
2043
|
-
const result = await sdk.runServerDoctor(
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
);
|
|
2129
|
+
const result = await sdk.runServerDoctor({
|
|
2130
|
+
config,
|
|
2131
|
+
target: doctorTarget,
|
|
2132
|
+
timeout: globalOptions.timeout,
|
|
2133
|
+
rpcLogger: collector?.rpcLogger,
|
|
2134
|
+
retryPolicy
|
|
2135
|
+
});
|
|
2051
2136
|
const jsonPayload = globalOptions.rpc ? attachCliRpcLogs(result, collector) : result;
|
|
2052
2137
|
const artifactPath = options.out ? await writeDebugArtifact(options.out, jsonPayload) : void 0;
|
|
2053
2138
|
if (globalOptions.format === "human") {
|
|
@@ -2062,10 +2147,13 @@ function registerServerCommands(program) {
|
|
|
2062
2147
|
setProcessExitCode(1);
|
|
2063
2148
|
}
|
|
2064
2149
|
});
|
|
2065
|
-
|
|
2066
|
-
|
|
2150
|
+
addRetryOptions(
|
|
2151
|
+
addSharedServerOptions(
|
|
2152
|
+
server.command("info").description("Get initialization info for an MCP server")
|
|
2153
|
+
)
|
|
2067
2154
|
).action(async (options, command) => {
|
|
2068
2155
|
const globalOptions = getGlobalOptions(command);
|
|
2156
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
2069
2157
|
const target = describeTarget(options);
|
|
2070
2158
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
2071
2159
|
const config = parseServerConfig({
|
|
@@ -2085,18 +2173,22 @@ function registerServerCommands(program) {
|
|
|
2085
2173
|
},
|
|
2086
2174
|
{
|
|
2087
2175
|
timeout: globalOptions.timeout,
|
|
2088
|
-
rpcLogger: collector?.rpcLogger
|
|
2176
|
+
rpcLogger: collector?.rpcLogger,
|
|
2177
|
+
retryPolicy
|
|
2089
2178
|
}
|
|
2090
2179
|
);
|
|
2091
|
-
writeResult(
|
|
2180
|
+
writeResult(
|
|
2181
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
2182
|
+
globalOptions.format
|
|
2183
|
+
);
|
|
2092
2184
|
});
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
).action(async (options, command) => {
|
|
2185
|
+
addRetryOptions(
|
|
2186
|
+
addSharedServerOptions(
|
|
2187
|
+
server.command("validate").description("Connect to a server and verify the debugger surface works")
|
|
2188
|
+
)
|
|
2189
|
+
).option("--debug-out <path>", "Write a structured debug artifact to a file").action(async (options, command) => {
|
|
2099
2190
|
const globalOptions = getGlobalOptions(command);
|
|
2191
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
2100
2192
|
const target = describeTarget(options);
|
|
2101
2193
|
const primaryCollector = globalOptions.rpc || options.debugOut ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
2102
2194
|
const snapshotCollector = options.debugOut ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
@@ -2121,7 +2213,8 @@ function registerServerCommands(program) {
|
|
|
2121
2213
|
},
|
|
2122
2214
|
{
|
|
2123
2215
|
timeout: globalOptions.timeout,
|
|
2124
|
-
rpcLogger: primaryCollector?.rpcLogger
|
|
2216
|
+
rpcLogger: primaryCollector?.rpcLogger,
|
|
2217
|
+
retryPolicy
|
|
2125
2218
|
}
|
|
2126
2219
|
);
|
|
2127
2220
|
} catch (error) {
|
|
@@ -2158,10 +2251,13 @@ function registerServerCommands(program) {
|
|
|
2158
2251
|
globalOptions.format
|
|
2159
2252
|
);
|
|
2160
2253
|
});
|
|
2161
|
-
|
|
2162
|
-
|
|
2254
|
+
addRetryOptions(
|
|
2255
|
+
addSharedServerOptions(
|
|
2256
|
+
server.command("ping").description("Ping an MCP server")
|
|
2257
|
+
)
|
|
2163
2258
|
).action(async (options, command) => {
|
|
2164
2259
|
const globalOptions = getGlobalOptions(command);
|
|
2260
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
2165
2261
|
const target = describeTarget(options);
|
|
2166
2262
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
2167
2263
|
const config = parseServerConfig({
|
|
@@ -2177,15 +2273,22 @@ function registerServerCommands(program) {
|
|
|
2177
2273
|
}),
|
|
2178
2274
|
{
|
|
2179
2275
|
timeout: globalOptions.timeout,
|
|
2180
|
-
rpcLogger: collector?.rpcLogger
|
|
2276
|
+
rpcLogger: collector?.rpcLogger,
|
|
2277
|
+
retryPolicy
|
|
2181
2278
|
}
|
|
2182
2279
|
);
|
|
2183
|
-
writeResult(
|
|
2280
|
+
writeResult(
|
|
2281
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
2282
|
+
globalOptions.format
|
|
2283
|
+
);
|
|
2184
2284
|
});
|
|
2185
|
-
|
|
2186
|
-
|
|
2285
|
+
addRetryOptions(
|
|
2286
|
+
addSharedServerOptions(
|
|
2287
|
+
server.command("capabilities").description("Get resolved server capabilities")
|
|
2288
|
+
)
|
|
2187
2289
|
).action(async (options, command) => {
|
|
2188
2290
|
const globalOptions = getGlobalOptions(command);
|
|
2291
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
2189
2292
|
const target = describeTarget(options);
|
|
2190
2293
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
2191
2294
|
const config = parseServerConfig({
|
|
@@ -2200,38 +2303,252 @@ function registerServerCommands(program) {
|
|
|
2200
2303
|
}),
|
|
2201
2304
|
{
|
|
2202
2305
|
timeout: globalOptions.timeout,
|
|
2203
|
-
rpcLogger: collector?.rpcLogger
|
|
2306
|
+
rpcLogger: collector?.rpcLogger,
|
|
2307
|
+
retryPolicy
|
|
2204
2308
|
}
|
|
2205
2309
|
);
|
|
2206
|
-
writeResult(
|
|
2310
|
+
writeResult(
|
|
2311
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
2312
|
+
globalOptions.format
|
|
2313
|
+
);
|
|
2207
2314
|
});
|
|
2208
|
-
|
|
2209
|
-
|
|
2315
|
+
addRetryOptions(
|
|
2316
|
+
addSharedServerOptions(
|
|
2317
|
+
server.command("export").description(
|
|
2318
|
+
"Export server tools, resources, prompts, and capabilities"
|
|
2319
|
+
).option(
|
|
2320
|
+
"--stable",
|
|
2321
|
+
"Emit the deterministic versioned snapshot format for baselines"
|
|
2322
|
+
)
|
|
2323
|
+
)
|
|
2210
2324
|
).action(async (options, command) => {
|
|
2211
2325
|
const globalOptions = getGlobalOptions(command);
|
|
2326
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
2212
2327
|
const target = describeTarget(options);
|
|
2213
2328
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
2214
2329
|
const config = parseServerConfig({
|
|
2215
2330
|
...options,
|
|
2216
2331
|
timeout: globalOptions.timeout
|
|
2217
2332
|
});
|
|
2218
|
-
const
|
|
2333
|
+
const snapshot = await sdk.collectServerSnapshot({
|
|
2219
2334
|
config,
|
|
2220
|
-
|
|
2221
|
-
|
|
2335
|
+
target,
|
|
2336
|
+
timeout: globalOptions.timeout,
|
|
2337
|
+
rpcLogger: collector?.rpcLogger,
|
|
2338
|
+
retryPolicy,
|
|
2339
|
+
clientName: "mcpjam",
|
|
2340
|
+
serverId: "__cli__"
|
|
2341
|
+
});
|
|
2342
|
+
const result = options.stable ? sdk.serializeStableServerSnapshot(snapshot) : sdk.serializeServerSnapshot(snapshot, { mode: "raw" });
|
|
2343
|
+
writeResult(
|
|
2344
|
+
options.stable ? result : withRpcLogsIfRequested(result, collector, globalOptions),
|
|
2345
|
+
globalOptions.format
|
|
2346
|
+
);
|
|
2347
|
+
});
|
|
2348
|
+
addRetryOptions(
|
|
2349
|
+
addSharedServerOptions(
|
|
2350
|
+
server.command("diff").description(
|
|
2351
|
+
"Compare a server snapshot baseline against a live or file snapshot"
|
|
2352
|
+
).option(
|
|
2353
|
+
"--baseline <path>",
|
|
2354
|
+
"Compare a baseline file to a live server target"
|
|
2355
|
+
).option(
|
|
2356
|
+
"--left <path>",
|
|
2357
|
+
"Left snapshot file for file-vs-file comparison"
|
|
2358
|
+
).option(
|
|
2359
|
+
"--right <path>",
|
|
2360
|
+
"Right snapshot file for file-vs-file comparison"
|
|
2361
|
+
).option(
|
|
2362
|
+
"--fail-on <policy>",
|
|
2363
|
+
"Diff failure policy: breaking, any, or none"
|
|
2364
|
+
).option(
|
|
2365
|
+
"--reporter <reporter>",
|
|
2366
|
+
"Structured reporter output: json-summary or junit-xml"
|
|
2367
|
+
).option("--out <path>", "Write the raw diff JSON artifact to a file")
|
|
2368
|
+
)
|
|
2369
|
+
).action(async (options, command) => {
|
|
2370
|
+
const globalOptions = getGlobalOptions(command);
|
|
2371
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
2372
|
+
const reporter = parseReporterFormat(
|
|
2373
|
+
options.reporter
|
|
2374
|
+
);
|
|
2375
|
+
const mode = resolveServerDiffMode(options);
|
|
2376
|
+
let rawDiff;
|
|
2377
|
+
let collector;
|
|
2378
|
+
if (mode.kind === "baseline-live") {
|
|
2379
|
+
const target = describeTarget(options);
|
|
2380
|
+
collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
2381
|
+
const config = parseServerConfig({
|
|
2382
|
+
...options,
|
|
2383
|
+
timeout: globalOptions.timeout
|
|
2384
|
+
});
|
|
2385
|
+
const baselineSnapshot = await readSnapshotFile(mode.baselinePath);
|
|
2386
|
+
const currentSnapshot = await sdk.collectServerSnapshot({
|
|
2387
|
+
config,
|
|
2388
|
+
target,
|
|
2222
2389
|
timeout: globalOptions.timeout,
|
|
2223
|
-
rpcLogger: collector?.rpcLogger
|
|
2390
|
+
rpcLogger: collector?.rpcLogger,
|
|
2391
|
+
retryPolicy,
|
|
2392
|
+
clientName: "mcpjam",
|
|
2393
|
+
serverId: "__cli__"
|
|
2394
|
+
});
|
|
2395
|
+
rawDiff = createServerDiffResult(
|
|
2396
|
+
baselineSnapshot,
|
|
2397
|
+
currentSnapshot,
|
|
2398
|
+
parseDiffFailOn(options.failOn)
|
|
2399
|
+
);
|
|
2400
|
+
} else {
|
|
2401
|
+
if (hasServerTargetOptions(options)) {
|
|
2402
|
+
throw usageError(
|
|
2403
|
+
"Do not pass live target options together with --left/--right file comparison."
|
|
2404
|
+
);
|
|
2224
2405
|
}
|
|
2225
|
-
|
|
2226
|
-
|
|
2406
|
+
const [leftSnapshot, rightSnapshot] = await Promise.all([
|
|
2407
|
+
readSnapshotFile(mode.leftPath),
|
|
2408
|
+
readSnapshotFile(mode.rightPath)
|
|
2409
|
+
]);
|
|
2410
|
+
rawDiff = createServerDiffResult(
|
|
2411
|
+
leftSnapshot,
|
|
2412
|
+
rightSnapshot,
|
|
2413
|
+
parseDiffFailOn(options.failOn)
|
|
2414
|
+
);
|
|
2415
|
+
}
|
|
2416
|
+
if (options.out) {
|
|
2417
|
+
await writeJsonArtifact(options.out, rawDiff);
|
|
2418
|
+
}
|
|
2419
|
+
if (reporter) {
|
|
2420
|
+
writeReporterResult(
|
|
2421
|
+
reporter,
|
|
2422
|
+
sdk.buildServerDiffReport(rawDiff, {
|
|
2423
|
+
metadata: mode.kind === "baseline-live" ? {
|
|
2424
|
+
comparisonMode: mode.kind,
|
|
2425
|
+
baselinePath: mode.baselinePath
|
|
2426
|
+
} : {
|
|
2427
|
+
comparisonMode: mode.kind,
|
|
2428
|
+
leftPath: mode.leftPath,
|
|
2429
|
+
rightPath: mode.rightPath
|
|
2430
|
+
}
|
|
2431
|
+
})
|
|
2432
|
+
);
|
|
2433
|
+
} else {
|
|
2434
|
+
writeResult(
|
|
2435
|
+
withRpcLogsIfRequested(rawDiff, collector, globalOptions),
|
|
2436
|
+
globalOptions.format
|
|
2437
|
+
);
|
|
2438
|
+
}
|
|
2439
|
+
if (!rawDiff.passed) {
|
|
2440
|
+
setProcessExitCode(1);
|
|
2441
|
+
}
|
|
2227
2442
|
});
|
|
2228
2443
|
}
|
|
2444
|
+
function hasServerTargetOptions(options) {
|
|
2445
|
+
return typeof options.url === "string" || typeof options.command === "string";
|
|
2446
|
+
}
|
|
2447
|
+
function resolveServerDiffMode(options) {
|
|
2448
|
+
const baselinePath = toOptionalString(options.baseline);
|
|
2449
|
+
const leftPath = toOptionalString(options.left);
|
|
2450
|
+
const rightPath = toOptionalString(options.right);
|
|
2451
|
+
if (baselinePath && (leftPath || rightPath)) {
|
|
2452
|
+
throw usageError(
|
|
2453
|
+
"Specify either --baseline with a live target or --left/--right for file comparison."
|
|
2454
|
+
);
|
|
2455
|
+
}
|
|
2456
|
+
if (baselinePath) {
|
|
2457
|
+
return {
|
|
2458
|
+
kind: "baseline-live",
|
|
2459
|
+
baselinePath
|
|
2460
|
+
};
|
|
2461
|
+
}
|
|
2462
|
+
if (leftPath && rightPath) {
|
|
2463
|
+
return {
|
|
2464
|
+
kind: "file-file",
|
|
2465
|
+
leftPath,
|
|
2466
|
+
rightPath
|
|
2467
|
+
};
|
|
2468
|
+
}
|
|
2469
|
+
if (leftPath || rightPath) {
|
|
2470
|
+
throw usageError(
|
|
2471
|
+
"Both --left and --right are required for file comparison."
|
|
2472
|
+
);
|
|
2473
|
+
}
|
|
2474
|
+
throw usageError(
|
|
2475
|
+
"Specify either --baseline with a live target or --left/--right for file comparison."
|
|
2476
|
+
);
|
|
2477
|
+
}
|
|
2478
|
+
function parseDiffFailOn(value) {
|
|
2479
|
+
if (value === void 0) {
|
|
2480
|
+
return void 0;
|
|
2481
|
+
}
|
|
2482
|
+
if (value === "breaking" || value === "any" || value === "none") {
|
|
2483
|
+
return value;
|
|
2484
|
+
}
|
|
2485
|
+
throw usageError(
|
|
2486
|
+
`Invalid fail-on policy "${value}". Use "breaking", "any", or "none".`
|
|
2487
|
+
);
|
|
2488
|
+
}
|
|
2489
|
+
async function readSnapshotFile(filePath) {
|
|
2490
|
+
let contents;
|
|
2491
|
+
try {
|
|
2492
|
+
contents = await promises.readFile(filePath, "utf8");
|
|
2493
|
+
} catch (error) {
|
|
2494
|
+
throw operationalError(`Failed to read snapshot file "${filePath}".`, {
|
|
2495
|
+
source: error instanceof Error ? error.message : String(error)
|
|
2496
|
+
});
|
|
2497
|
+
}
|
|
2498
|
+
try {
|
|
2499
|
+
return JSON.parse(contents);
|
|
2500
|
+
} catch (error) {
|
|
2501
|
+
throw usageError(`Snapshot file "${filePath}" must contain valid JSON.`, {
|
|
2502
|
+
source: error instanceof Error ? error.message : String(error)
|
|
2503
|
+
});
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
function toOptionalString(value) {
|
|
2507
|
+
if (typeof value !== "string") {
|
|
2508
|
+
return void 0;
|
|
2509
|
+
}
|
|
2510
|
+
const normalized = value.trim();
|
|
2511
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
2512
|
+
}
|
|
2513
|
+
function createServerDiffResult(left, right, failOn) {
|
|
2514
|
+
try {
|
|
2515
|
+
return sdk.diffServerSnapshots(left, right, { failOn });
|
|
2516
|
+
} catch (error) {
|
|
2517
|
+
if (error instanceof sdk.ServerSnapshotFormatError) {
|
|
2518
|
+
throw usageError(error.message);
|
|
2519
|
+
}
|
|
2520
|
+
throw error;
|
|
2521
|
+
}
|
|
2522
|
+
}
|
|
2523
|
+
async function listToolsWithMetadata(manager, params) {
|
|
2524
|
+
const result = await manager.listTools(
|
|
2525
|
+
params.serverId,
|
|
2526
|
+
params.cursor ? { cursor: params.cursor } : void 0
|
|
2527
|
+
);
|
|
2528
|
+
const tools = result.tools ?? [];
|
|
2529
|
+
const toolsMetadata = manager.getAllToolsMetadata(params.serverId);
|
|
2530
|
+
const tokenCount = params.modelId ? estimateTokensFromChars(JSON.stringify(tools)) : void 0;
|
|
2531
|
+
return {
|
|
2532
|
+
tools,
|
|
2533
|
+
nextCursor: result.nextCursor,
|
|
2534
|
+
toolsMetadata,
|
|
2535
|
+
...tokenCount === void 0 ? {} : { tokenCount }
|
|
2536
|
+
};
|
|
2537
|
+
}
|
|
2538
|
+
function estimateTokensFromChars(text) {
|
|
2539
|
+
return Math.ceil(text.length / 4);
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
// src/commands/tools.ts
|
|
2229
2543
|
function registerToolsCommands(program) {
|
|
2230
2544
|
const tools = program.command("tools").description("List and invoke MCP server tools");
|
|
2231
|
-
|
|
2232
|
-
|
|
2545
|
+
addRetryOptions(
|
|
2546
|
+
addSharedServerOptions(
|
|
2547
|
+
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")
|
|
2548
|
+
)
|
|
2233
2549
|
).action(async (options, command) => {
|
|
2234
2550
|
const globalOptions = getGlobalOptions(command);
|
|
2551
|
+
const retryPolicy = parseRetryPolicy(options);
|
|
2235
2552
|
const target = describeTarget(options);
|
|
2236
2553
|
const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
|
|
2237
2554
|
const config = parseServerConfig({
|
|
@@ -2247,13 +2564,26 @@ function registerToolsCommands(program) {
|
|
|
2247
2564
|
}),
|
|
2248
2565
|
{
|
|
2249
2566
|
timeout: globalOptions.timeout,
|
|
2250
|
-
rpcLogger: collector?.rpcLogger
|
|
2567
|
+
rpcLogger: collector?.rpcLogger,
|
|
2568
|
+
retryPolicy
|
|
2251
2569
|
}
|
|
2252
2570
|
);
|
|
2253
|
-
writeResult(
|
|
2571
|
+
writeResult(
|
|
2572
|
+
withRpcLogsIfRequested(result, collector, globalOptions),
|
|
2573
|
+
globalOptions.format
|
|
2574
|
+
);
|
|
2254
2575
|
});
|
|
2255
2576
|
addSharedServerOptions(
|
|
2256
2577
|
tools.command("call").description("Call an MCP tool").option("--tool-name <tool>", "Tool name").option("--name <tool>", "Alias for --tool-name").option("--tool-args <json>", "Tool parameter object as JSON").option("--params <json>", "Alias for --tool-args").option(
|
|
2578
|
+
"--validate-response",
|
|
2579
|
+
"Validate the MCP tool-call envelope returned by the server"
|
|
2580
|
+
).option(
|
|
2581
|
+
"--expect-success",
|
|
2582
|
+
"Evaluate the tool-call outcome policy against isError"
|
|
2583
|
+
).option(
|
|
2584
|
+
"--reporter <reporter>",
|
|
2585
|
+
"Structured reporter output: json-summary or junit-xml"
|
|
2586
|
+
).option(
|
|
2257
2587
|
"--debug-out <path>",
|
|
2258
2588
|
"Write a structured debug artifact to a file"
|
|
2259
2589
|
)
|
|
@@ -2266,6 +2596,9 @@ function registerToolsCommands(program) {
|
|
|
2266
2596
|
...options,
|
|
2267
2597
|
timeout: globalOptions.timeout
|
|
2268
2598
|
});
|
|
2599
|
+
const reporter = parseReporterFormat(
|
|
2600
|
+
options.reporter
|
|
2601
|
+
);
|
|
2269
2602
|
const toolName = resolveAliasedStringOption(
|
|
2270
2603
|
options,
|
|
2271
2604
|
[
|
|
@@ -2285,8 +2618,16 @@ function registerToolsCommands(program) {
|
|
|
2285
2618
|
);
|
|
2286
2619
|
const params = parseJsonRecord(paramsInput, "Tool parameters") ?? {};
|
|
2287
2620
|
const targetSummary = summarizeServerDoctorTarget(target, config);
|
|
2621
|
+
const shouldValidateResponse = options.validateResponse === true;
|
|
2622
|
+
const shouldExpectSuccess = options.expectSuccess === true;
|
|
2623
|
+
if (reporter && !shouldValidateResponse && !shouldExpectSuccess) {
|
|
2624
|
+
throw usageError(
|
|
2625
|
+
"--reporter requires --validate-response and/or --expect-success."
|
|
2626
|
+
);
|
|
2627
|
+
}
|
|
2288
2628
|
let result;
|
|
2289
2629
|
let commandError;
|
|
2630
|
+
const startedAt = Date.now();
|
|
2290
2631
|
try {
|
|
2291
2632
|
result = await withEphemeralManager(
|
|
2292
2633
|
config,
|
|
@@ -2328,10 +2669,30 @@ function registerToolsCommands(program) {
|
|
|
2328
2669
|
if (commandError) {
|
|
2329
2670
|
throw commandError;
|
|
2330
2671
|
}
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
);
|
|
2672
|
+
const validationResult = shouldValidateResponse || shouldExpectSuccess ? sdk.validateToolCallResult(result, {
|
|
2673
|
+
envelope: shouldValidateResponse,
|
|
2674
|
+
outcome: shouldExpectSuccess ? { failOnIsError: true } : void 0
|
|
2675
|
+
}) : void 0;
|
|
2676
|
+
if (reporter) {
|
|
2677
|
+
writeReporterResult(
|
|
2678
|
+
reporter,
|
|
2679
|
+
sdk.buildToolCallValidationReport(validationResult, {
|
|
2680
|
+
durationMs: Date.now() - startedAt,
|
|
2681
|
+
rawResult: result,
|
|
2682
|
+
metadata: {
|
|
2683
|
+
toolName
|
|
2684
|
+
}
|
|
2685
|
+
})
|
|
2686
|
+
);
|
|
2687
|
+
} else {
|
|
2688
|
+
writeResult(
|
|
2689
|
+
withRpcLogsIfRequested(result, primaryCollector, globalOptions),
|
|
2690
|
+
globalOptions.format
|
|
2691
|
+
);
|
|
2692
|
+
}
|
|
2693
|
+
if (validationResult && !validationResult.passed) {
|
|
2694
|
+
setProcessExitCode(1);
|
|
2695
|
+
}
|
|
2335
2696
|
if (sdk.isCallToolResultError(result)) {
|
|
2336
2697
|
setProcessExitCode(1);
|
|
2337
2698
|
}
|