@mcpjam/cli 6.3.0 → 6.3.2
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 +311 -97
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -34,7 +34,90 @@ import { selectPluginMcpServerMap, detectPluginMcpTransport } from '@mcpjam/sdk/
|
|
|
34
34
|
|
|
35
35
|
// package.json
|
|
36
36
|
var package_default = {
|
|
37
|
-
version: "6.3.
|
|
37
|
+
version: "6.3.2"};
|
|
38
|
+
|
|
39
|
+
// src/lib/command-outcome.ts
|
|
40
|
+
var UNKNOWN_COMMAND = "(unknown)";
|
|
41
|
+
var recorded;
|
|
42
|
+
function recordCommandOutcome(outcome, errorCode) {
|
|
43
|
+
if (recorded?.outcome === "interrupted") {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
recorded = errorCode === void 0 ? { outcome } : { outcome, errorCode };
|
|
47
|
+
}
|
|
48
|
+
function resetCommandOutcome() {
|
|
49
|
+
recorded = void 0;
|
|
50
|
+
}
|
|
51
|
+
function resolveCommandOutcome(exitCode, thrownErrorCode) {
|
|
52
|
+
if (recorded?.outcome === "interrupted") {
|
|
53
|
+
return { outcome: "interrupted" };
|
|
54
|
+
}
|
|
55
|
+
if (thrownErrorCode !== void 0) {
|
|
56
|
+
return {
|
|
57
|
+
outcome: thrownErrorCode === "USAGE_ERROR" ? "usage_error" : "error",
|
|
58
|
+
errorCode: thrownErrorCode
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (exitCode === 0) {
|
|
62
|
+
return { outcome: "ok" };
|
|
63
|
+
}
|
|
64
|
+
if (recorded?.outcome === "check_failed") {
|
|
65
|
+
return { outcome: "check_failed" };
|
|
66
|
+
}
|
|
67
|
+
const errorCode = recorded?.errorCode ?? "UNKNOWN_ERROR";
|
|
68
|
+
return {
|
|
69
|
+
outcome: errorCode === "USAGE_ERROR" ? "usage_error" : "error",
|
|
70
|
+
errorCode
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function resolveRegisteredCommandPath(program, argv) {
|
|
74
|
+
const path14 = [];
|
|
75
|
+
let current = program;
|
|
76
|
+
const tokens = argv.slice(2);
|
|
77
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
78
|
+
const token = tokens[index];
|
|
79
|
+
if (token === "--") {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
if (token.startsWith("-")) {
|
|
83
|
+
const next2 = tokens[index + 1];
|
|
84
|
+
const value = separateOptionValue(current, token);
|
|
85
|
+
if (next2 !== void 0 && (value === "required" || value === "optional" && !next2.startsWith("-"))) {
|
|
86
|
+
index += 1;
|
|
87
|
+
}
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const next = current.commands.find(
|
|
91
|
+
(command) => command.name() === token || command.aliases().includes(token)
|
|
92
|
+
);
|
|
93
|
+
if (!next) {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
path14.push(next.name());
|
|
97
|
+
current = next;
|
|
98
|
+
}
|
|
99
|
+
return path14;
|
|
100
|
+
}
|
|
101
|
+
function separateOptionValue(command, token) {
|
|
102
|
+
if (token.includes("=") || /^-[^-]./.test(token)) {
|
|
103
|
+
return "none";
|
|
104
|
+
}
|
|
105
|
+
for (let cursor = command; cursor; cursor = cursor.parent) {
|
|
106
|
+
const option = cursor.options.find(
|
|
107
|
+
(candidate) => candidate.long === token || candidate.short === token
|
|
108
|
+
);
|
|
109
|
+
if (option) {
|
|
110
|
+
return option.required ? "required" : option.optional ? "optional" : "none";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return "none";
|
|
114
|
+
}
|
|
115
|
+
function argvOptsOutOfTelemetry(argv) {
|
|
116
|
+
const end = argv.indexOf("--");
|
|
117
|
+
return (end === -1 ? argv : argv.slice(0, end)).includes("--no-telemetry");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/lib/output.ts
|
|
38
121
|
var DEFAULT_OUTPUT_FORMAT = "json";
|
|
39
122
|
var CliError = class extends Error {
|
|
40
123
|
code;
|
|
@@ -234,6 +317,9 @@ function parseLooseOutputFormat(value) {
|
|
|
234
317
|
}
|
|
235
318
|
function setProcessExitCode(code) {
|
|
236
319
|
process.exitCode = code;
|
|
320
|
+
if (code !== 0) {
|
|
321
|
+
recordCommandOutcome("check_failed");
|
|
322
|
+
}
|
|
237
323
|
}
|
|
238
324
|
|
|
239
325
|
// src/lib/credentials-file.ts
|
|
@@ -2934,8 +3020,11 @@ var POSTHOG_HOST = "https://us.i.posthog.com";
|
|
|
2934
3020
|
var TELEMETRY_STATE_FILE = "telemetry.json";
|
|
2935
3021
|
var TELEMETRY_EVENT_NAME = "cli_command";
|
|
2936
3022
|
var CONFORMANCE_EVENT_NAME = "conformance_run_triggered";
|
|
3023
|
+
var MCP_TOOL_EVENT_NAME = "cli_mcp_tool_called";
|
|
2937
3024
|
var TELEMETRY_STATE_VERSION = 1;
|
|
2938
3025
|
var DEFAULT_FLUSH_TIMEOUT_MS = 3e3;
|
|
3026
|
+
var FORCED_EXIT_FLUSH_TIMEOUT_MS = 1e3;
|
|
3027
|
+
var INTERRUPTED_EXIT_CODE = 130;
|
|
2939
3028
|
var SAFE_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
2940
3029
|
"USAGE_ERROR",
|
|
2941
3030
|
"TIMEOUT",
|
|
@@ -3004,6 +3093,9 @@ function initTelemetry(program, cliVersion, options = {}) {
|
|
|
3004
3093
|
const run = {
|
|
3005
3094
|
cliVersion,
|
|
3006
3095
|
options,
|
|
3096
|
+
program,
|
|
3097
|
+
initializedAtMs: Date.now(),
|
|
3098
|
+
forcedExitStarted: false,
|
|
3007
3099
|
commandOptOut: false,
|
|
3008
3100
|
shouldCapture: false,
|
|
3009
3101
|
captured: false,
|
|
@@ -3025,22 +3117,19 @@ function initTelemetry(program, cliVersion, options = {}) {
|
|
|
3025
3117
|
run.conformanceCaptured = false;
|
|
3026
3118
|
});
|
|
3027
3119
|
return {
|
|
3028
|
-
|
|
3029
|
-
const client = run.client;
|
|
3030
|
-
if (!client) {
|
|
3031
|
-
return;
|
|
3032
|
-
}
|
|
3033
|
-
try {
|
|
3034
|
-
const timeoutMs = options.flushTimeoutMs ?? DEFAULT_FLUSH_TIMEOUT_MS;
|
|
3035
|
-
await withTimeout(
|
|
3036
|
-
flushClient(run, client, timeoutMs),
|
|
3037
|
-
timeoutMs
|
|
3038
|
-
);
|
|
3039
|
-
} catch {
|
|
3040
|
-
}
|
|
3041
|
-
}
|
|
3120
|
+
flush: () => flushRun(run, options.flushTimeoutMs ?? DEFAULT_FLUSH_TIMEOUT_MS)
|
|
3042
3121
|
};
|
|
3043
3122
|
}
|
|
3123
|
+
async function flushRun(run, timeoutMs) {
|
|
3124
|
+
const client = run.client;
|
|
3125
|
+
if (!client) {
|
|
3126
|
+
return;
|
|
3127
|
+
}
|
|
3128
|
+
try {
|
|
3129
|
+
await withTimeout(flushClient(run, client, timeoutMs), timeoutMs);
|
|
3130
|
+
} catch {
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3044
3133
|
async function flushClient(run, client, timeoutMs) {
|
|
3045
3134
|
const pendingCaptures = run.pendingCaptures.splice(0);
|
|
3046
3135
|
if (pendingCaptures.length > 0) {
|
|
@@ -3048,7 +3137,7 @@ async function flushClient(run, client, timeoutMs) {
|
|
|
3048
3137
|
}
|
|
3049
3138
|
await client.flush(timeoutMs);
|
|
3050
3139
|
}
|
|
3051
|
-
function captureCommandEvent(exitCode, errorCode) {
|
|
3140
|
+
function captureCommandEvent(exitCode, outcome, errorCode) {
|
|
3052
3141
|
const run = activeRun;
|
|
3053
3142
|
if (!run || !run.shouldCapture || run.captured || !run.startedAtMs || !run.command) {
|
|
3054
3143
|
return;
|
|
@@ -3069,6 +3158,7 @@ function captureCommandEvent(exitCode, errorCode) {
|
|
|
3069
3158
|
command: run.command,
|
|
3070
3159
|
success: exitCode === 0,
|
|
3071
3160
|
exit_code: exitCode,
|
|
3161
|
+
outcome,
|
|
3072
3162
|
duration_ms: Math.max(0, Date.now() - run.startedAtMs),
|
|
3073
3163
|
cli_version: run.cliVersion,
|
|
3074
3164
|
os: process.platform,
|
|
@@ -3082,7 +3172,7 @@ function captureCommandEvent(exitCode, errorCode) {
|
|
|
3082
3172
|
if (run.transport) {
|
|
3083
3173
|
properties.transport = run.transport;
|
|
3084
3174
|
}
|
|
3085
|
-
const safeErrorCode =
|
|
3175
|
+
const safeErrorCode = outcome === "error" || outcome === "usage_error" ? normalizeTelemetryErrorCode(errorCode) : void 0;
|
|
3086
3176
|
if (safeErrorCode) {
|
|
3087
3177
|
properties.error_code = safeErrorCode;
|
|
3088
3178
|
}
|
|
@@ -3090,7 +3180,33 @@ function captureCommandEvent(exitCode, errorCode) {
|
|
|
3090
3180
|
} catch {
|
|
3091
3181
|
}
|
|
3092
3182
|
}
|
|
3093
|
-
function
|
|
3183
|
+
function captureUsageErrorEvent(argv, exitCode = 2) {
|
|
3184
|
+
const run = activeRun;
|
|
3185
|
+
if (!run || run.captured) {
|
|
3186
|
+
return;
|
|
3187
|
+
}
|
|
3188
|
+
if (!run.command) {
|
|
3189
|
+
const commandPath = resolveRegisteredCommandPath(run.program, argv);
|
|
3190
|
+
run.command = commandPath.length > 0 ? commandPath.join(" ") : UNKNOWN_COMMAND;
|
|
3191
|
+
run.commandOptOut = argvOptsOutOfTelemetry(argv);
|
|
3192
|
+
run.startedAtMs = run.initializedAtMs;
|
|
3193
|
+
run.shouldCapture = commandPath[0] !== "telemetry";
|
|
3194
|
+
}
|
|
3195
|
+
captureCommandEvent(exitCode, "usage_error", "USAGE_ERROR");
|
|
3196
|
+
}
|
|
3197
|
+
async function exitInterrupted(exit = (code) => process.exit(code)) {
|
|
3198
|
+
const run = activeRun;
|
|
3199
|
+
if (!run || run.forcedExitStarted) {
|
|
3200
|
+
exit(INTERRUPTED_EXIT_CODE);
|
|
3201
|
+
return;
|
|
3202
|
+
}
|
|
3203
|
+
run.forcedExitStarted = true;
|
|
3204
|
+
recordCommandOutcome("interrupted");
|
|
3205
|
+
captureCommandEvent(INTERRUPTED_EXIT_CODE, "interrupted");
|
|
3206
|
+
await flushRun(run, FORCED_EXIT_FLUSH_TIMEOUT_MS);
|
|
3207
|
+
exit(INTERRUPTED_EXIT_CODE);
|
|
3208
|
+
}
|
|
3209
|
+
function captureConformanceRunEvent(suite, mode) {
|
|
3094
3210
|
const run = activeRun;
|
|
3095
3211
|
if (!run || !run.shouldCapture || run.conformanceCaptured || !run.command) {
|
|
3096
3212
|
return;
|
|
@@ -3109,7 +3225,39 @@ function captureConformanceRunEvent() {
|
|
|
3109
3225
|
decision,
|
|
3110
3226
|
resolveInstallId(run, decision.state),
|
|
3111
3227
|
CONFORMANCE_EVENT_NAME,
|
|
3112
|
-
{ run_source: "cli" }
|
|
3228
|
+
{ run_source: "cli", suite, mode, cli_version: run.cliVersion }
|
|
3229
|
+
);
|
|
3230
|
+
} catch {
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
function captureMcpToolEvent(call) {
|
|
3234
|
+
const run = activeRun;
|
|
3235
|
+
if (!run || !run.shouldCapture || !run.command) {
|
|
3236
|
+
return;
|
|
3237
|
+
}
|
|
3238
|
+
try {
|
|
3239
|
+
const decision = resolveTelemetryDecision({
|
|
3240
|
+
...run.options,
|
|
3241
|
+
commandOptOut: run.commandOptOut
|
|
3242
|
+
});
|
|
3243
|
+
if (!decision.enabled) {
|
|
3244
|
+
return;
|
|
3245
|
+
}
|
|
3246
|
+
const properties = {
|
|
3247
|
+
tool: call.tool,
|
|
3248
|
+
success: call.success,
|
|
3249
|
+
duration_ms: Math.max(0, Math.round(call.durationMs)),
|
|
3250
|
+
cli_version: run.cliVersion
|
|
3251
|
+
};
|
|
3252
|
+
if (!call.success) {
|
|
3253
|
+
properties.error_code = normalizeTelemetryErrorCode(call.errorCode);
|
|
3254
|
+
}
|
|
3255
|
+
sendEvent(
|
|
3256
|
+
run,
|
|
3257
|
+
decision,
|
|
3258
|
+
resolveInstallId(run, decision.state),
|
|
3259
|
+
MCP_TOOL_EVENT_NAME,
|
|
3260
|
+
properties
|
|
3113
3261
|
);
|
|
3114
3262
|
} catch {
|
|
3115
3263
|
}
|
|
@@ -3122,8 +3270,14 @@ function sendEvent(run, decision, distinctId, event, properties) {
|
|
|
3122
3270
|
const client = getOrCreateClient(run);
|
|
3123
3271
|
const pendingCapture = client.capture({ distinctId, event, properties });
|
|
3124
3272
|
if (pendingCapture) {
|
|
3125
|
-
|
|
3126
|
-
}))
|
|
3273
|
+
const settled = pendingCapture.catch(() => {
|
|
3274
|
+
}).then(() => {
|
|
3275
|
+
const index = run.pendingCaptures.indexOf(settled);
|
|
3276
|
+
if (index !== -1) {
|
|
3277
|
+
run.pendingCaptures.splice(index, 1);
|
|
3278
|
+
}
|
|
3279
|
+
});
|
|
3280
|
+
run.pendingCaptures.push(settled);
|
|
3127
3281
|
}
|
|
3128
3282
|
}
|
|
3129
3283
|
function resolveTelemetryDecision(options) {
|
|
@@ -5298,7 +5452,7 @@ function registerAppsCommands(program) {
|
|
|
5298
5452
|
...config,
|
|
5299
5453
|
__suppressTelemetry: true
|
|
5300
5454
|
});
|
|
5301
|
-
captureConformanceRunEvent();
|
|
5455
|
+
captureConformanceRunEvent("apps", "single");
|
|
5302
5456
|
const result = await test.run();
|
|
5303
5457
|
const outputResult = reporter ? result : withRpcLogsIfRequested(
|
|
5304
5458
|
result,
|
|
@@ -5634,7 +5788,7 @@ function registerAppsCommands(program) {
|
|
|
5634
5788
|
// The CLI counts the run itself, under its own opt-outs.
|
|
5635
5789
|
__suppressTelemetry: true
|
|
5636
5790
|
});
|
|
5637
|
-
captureConformanceRunEvent();
|
|
5791
|
+
captureConformanceRunEvent("apps", "suite");
|
|
5638
5792
|
const result = await suite.run();
|
|
5639
5793
|
const outputResult = reporter ? result : withRpcLogsIfRequested(
|
|
5640
5794
|
result,
|
|
@@ -14361,7 +14515,7 @@ Or stop it with:
|
|
|
14361
14515
|
mcpjam cloud projects servers connect-cancel --request ${created.connectionRequestId}
|
|
14362
14516
|
`
|
|
14363
14517
|
);
|
|
14364
|
-
|
|
14518
|
+
setProcessExitCode(1);
|
|
14365
14519
|
}
|
|
14366
14520
|
}
|
|
14367
14521
|
);
|
|
@@ -14445,6 +14599,7 @@ async function pollConnection(options, timeoutMs, connectionRequestId, expiresAt
|
|
|
14445
14599
|
let lastResult;
|
|
14446
14600
|
const onInterrupt = () => {
|
|
14447
14601
|
interrupted = true;
|
|
14602
|
+
recordCommandOutcome("interrupted");
|
|
14448
14603
|
process.stderr.write(
|
|
14449
14604
|
"\nStopped watching. The request continues in the cloud \u2014 open the link above to finish it.\n"
|
|
14450
14605
|
);
|
|
@@ -17676,11 +17831,12 @@ Registered server "${result.grant.name ?? options.server}" in project "${result.
|
|
|
17676
17831
|
const onSignal = () => {
|
|
17677
17832
|
sigints += 1;
|
|
17678
17833
|
if (sigints === 1) {
|
|
17834
|
+
recordCommandOutcome("interrupted");
|
|
17679
17835
|
status("Shutting down tunnel... (Ctrl-C again to force quit)");
|
|
17680
17836
|
void session.stop();
|
|
17681
17837
|
return;
|
|
17682
17838
|
}
|
|
17683
|
-
|
|
17839
|
+
void exitInterrupted();
|
|
17684
17840
|
};
|
|
17685
17841
|
process.on("SIGINT", onSignal);
|
|
17686
17842
|
process.on("SIGTERM", onSignal);
|
|
@@ -18874,6 +19030,64 @@ function estimateTokensFromChars(text) {
|
|
|
18874
19030
|
return Math.ceil(text.length / 4);
|
|
18875
19031
|
}
|
|
18876
19032
|
|
|
19033
|
+
// src/lib/mcp-tool-runner.ts
|
|
19034
|
+
function toToolResult(payload) {
|
|
19035
|
+
return {
|
|
19036
|
+
content: [
|
|
19037
|
+
{
|
|
19038
|
+
type: "text",
|
|
19039
|
+
text: JSON.stringify(payload, null, 2)
|
|
19040
|
+
}
|
|
19041
|
+
]
|
|
19042
|
+
};
|
|
19043
|
+
}
|
|
19044
|
+
function toToolError(normalized) {
|
|
19045
|
+
return {
|
|
19046
|
+
isError: true,
|
|
19047
|
+
content: [
|
|
19048
|
+
{
|
|
19049
|
+
type: "text",
|
|
19050
|
+
text: JSON.stringify(
|
|
19051
|
+
{
|
|
19052
|
+
error: {
|
|
19053
|
+
code: normalized.code,
|
|
19054
|
+
message: normalized.message,
|
|
19055
|
+
...normalized.details === void 0 ? {} : { details: normalized.details }
|
|
19056
|
+
}
|
|
19057
|
+
},
|
|
19058
|
+
null,
|
|
19059
|
+
2
|
|
19060
|
+
)
|
|
19061
|
+
}
|
|
19062
|
+
]
|
|
19063
|
+
};
|
|
19064
|
+
}
|
|
19065
|
+
function createToolRunner(onToolCalled) {
|
|
19066
|
+
const report2 = (call) => {
|
|
19067
|
+
try {
|
|
19068
|
+
onToolCalled?.(call);
|
|
19069
|
+
} catch {
|
|
19070
|
+
}
|
|
19071
|
+
};
|
|
19072
|
+
return async (tool, operation) => {
|
|
19073
|
+
const startedAt = Date.now();
|
|
19074
|
+
try {
|
|
19075
|
+
const result = toToolResult(await operation());
|
|
19076
|
+
report2({ tool, success: true, durationMs: Date.now() - startedAt });
|
|
19077
|
+
return result;
|
|
19078
|
+
} catch (error) {
|
|
19079
|
+
const normalized = normalizeCliError(error);
|
|
19080
|
+
report2({
|
|
19081
|
+
tool,
|
|
19082
|
+
success: false,
|
|
19083
|
+
durationMs: Date.now() - startedAt,
|
|
19084
|
+
errorCode: normalized.code
|
|
19085
|
+
});
|
|
19086
|
+
return toToolError(normalized);
|
|
19087
|
+
}
|
|
19088
|
+
};
|
|
19089
|
+
}
|
|
19090
|
+
|
|
18877
19091
|
// src/lib/mcp-server.ts
|
|
18878
19092
|
var NOTIFICATION_BUFFER_LIMIT = 1e3;
|
|
18879
19093
|
var WATCHED_NOTIFICATION_METHODS = [
|
|
@@ -18990,47 +19204,9 @@ function withToolResultAuthChallenge(result) {
|
|
|
18990
19204
|
_authChallenge: { ...challenge, hint: authChallengeHint(challenge) }
|
|
18991
19205
|
};
|
|
18992
19206
|
}
|
|
18993
|
-
function toToolResult(payload) {
|
|
18994
|
-
return {
|
|
18995
|
-
content: [
|
|
18996
|
-
{
|
|
18997
|
-
type: "text",
|
|
18998
|
-
text: JSON.stringify(payload, null, 2)
|
|
18999
|
-
}
|
|
19000
|
-
]
|
|
19001
|
-
};
|
|
19002
|
-
}
|
|
19003
|
-
function toToolError(error) {
|
|
19004
|
-
const normalized = normalizeCliError(error);
|
|
19005
|
-
return {
|
|
19006
|
-
isError: true,
|
|
19007
|
-
content: [
|
|
19008
|
-
{
|
|
19009
|
-
type: "text",
|
|
19010
|
-
text: JSON.stringify(
|
|
19011
|
-
{
|
|
19012
|
-
error: {
|
|
19013
|
-
code: normalized.code,
|
|
19014
|
-
message: normalized.message,
|
|
19015
|
-
...normalized.details === void 0 ? {} : { details: normalized.details }
|
|
19016
|
-
}
|
|
19017
|
-
},
|
|
19018
|
-
null,
|
|
19019
|
-
2
|
|
19020
|
-
)
|
|
19021
|
-
}
|
|
19022
|
-
]
|
|
19023
|
-
};
|
|
19024
|
-
}
|
|
19025
|
-
async function runTool(operation) {
|
|
19026
|
-
try {
|
|
19027
|
-
return toToolResult(await operation());
|
|
19028
|
-
} catch (error) {
|
|
19029
|
-
return toToolError(error);
|
|
19030
|
-
}
|
|
19031
|
-
}
|
|
19032
19207
|
function createMcpJamMcpServer(options) {
|
|
19033
19208
|
const defaultTimeoutMs = options.defaultTimeoutMs ?? 3e4;
|
|
19209
|
+
const runTool = createToolRunner(options.onToolCalled);
|
|
19034
19210
|
const manager = new MCPClientManager(
|
|
19035
19211
|
{},
|
|
19036
19212
|
{
|
|
@@ -19120,7 +19296,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19120
19296
|
}),
|
|
19121
19297
|
annotations: { readOnlyHint: false, openWorldHint: true }
|
|
19122
19298
|
},
|
|
19123
|
-
async (input) => runTool(async () => {
|
|
19299
|
+
async (input) => runTool("connect_server", async () => {
|
|
19124
19300
|
const { config } = buildTargetConfig(input, defaultTimeoutMs);
|
|
19125
19301
|
const requestedName = input.name?.trim();
|
|
19126
19302
|
if (requestedName && manager.hasServer(requestedName)) {
|
|
@@ -19153,7 +19329,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19153
19329
|
}),
|
|
19154
19330
|
annotations: { readOnlyHint: false, openWorldHint: true }
|
|
19155
19331
|
},
|
|
19156
|
-
async ({ server: name }) => runTool(async () => {
|
|
19332
|
+
async ({ server: name }) => runTool("disconnect_server", async () => {
|
|
19157
19333
|
if (!manager.hasServer(name)) {
|
|
19158
19334
|
throw usageError(`Unknown server "${name}".`);
|
|
19159
19335
|
}
|
|
@@ -19174,7 +19350,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19174
19350
|
inputSchema: z.object({}),
|
|
19175
19351
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
19176
19352
|
},
|
|
19177
|
-
async () => runTool(async () => ({
|
|
19353
|
+
async () => runTool("list_servers", async () => ({
|
|
19178
19354
|
servers: manager.listServers().map(describeServer)
|
|
19179
19355
|
}))
|
|
19180
19356
|
);
|
|
@@ -19188,7 +19364,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19188
19364
|
}),
|
|
19189
19365
|
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
19190
19366
|
},
|
|
19191
|
-
async ({ server: name }) => runTool(async () => {
|
|
19367
|
+
async ({ server: name }) => runTool("server_info", async () => {
|
|
19192
19368
|
requireConnected(name);
|
|
19193
19369
|
return {
|
|
19194
19370
|
server: name,
|
|
@@ -19206,7 +19382,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19206
19382
|
}),
|
|
19207
19383
|
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
19208
19384
|
},
|
|
19209
|
-
async ({ server: name }) => runTool(async () => {
|
|
19385
|
+
async ({ server: name }) => runTool("ping_server", async () => {
|
|
19210
19386
|
requireConnected(name);
|
|
19211
19387
|
const startedAt = Date.now();
|
|
19212
19388
|
await manager.pingServer(name);
|
|
@@ -19228,7 +19404,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19228
19404
|
}),
|
|
19229
19405
|
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
19230
19406
|
},
|
|
19231
|
-
async ({ server: name, cursor }) => runTool(async () => {
|
|
19407
|
+
async ({ server: name, cursor }) => runTool("list_tools", async () => {
|
|
19232
19408
|
requireConnected(name);
|
|
19233
19409
|
return listToolsWithMetadata(manager, { serverId: name, cursor });
|
|
19234
19410
|
})
|
|
@@ -19245,7 +19421,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19245
19421
|
}),
|
|
19246
19422
|
annotations: { readOnlyHint: false, openWorldHint: true }
|
|
19247
19423
|
},
|
|
19248
|
-
async ({ server: name, tool, arguments: args }) => runTool(async () => {
|
|
19424
|
+
async ({ server: name, tool, arguments: args }) => runTool("call_tool", async () => {
|
|
19249
19425
|
requireConnected(name);
|
|
19250
19426
|
return withToolResultAuthChallenge(
|
|
19251
19427
|
await manager.executeTool(name, tool, args ?? {})
|
|
@@ -19264,7 +19440,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19264
19440
|
}),
|
|
19265
19441
|
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
19266
19442
|
},
|
|
19267
|
-
async ({ server: name, cursor, templates }) => runTool(async () => {
|
|
19443
|
+
async ({ server: name, cursor, templates }) => runTool("list_resources", async () => {
|
|
19268
19444
|
requireConnected(name);
|
|
19269
19445
|
const params = cursor !== void 0 ? { cursor } : void 0;
|
|
19270
19446
|
return templates ? manager.listResourceTemplates(name, params) : manager.listResources(name, params);
|
|
@@ -19281,7 +19457,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19281
19457
|
}),
|
|
19282
19458
|
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
19283
19459
|
},
|
|
19284
|
-
async ({ server: name, uri }) => runTool(async () => {
|
|
19460
|
+
async ({ server: name, uri }) => runTool("read_resource", async () => {
|
|
19285
19461
|
requireConnected(name);
|
|
19286
19462
|
return manager.readResource(name, { uri });
|
|
19287
19463
|
})
|
|
@@ -19296,7 +19472,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19296
19472
|
}),
|
|
19297
19473
|
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
19298
19474
|
},
|
|
19299
|
-
async ({ server: name }) => runTool(async () => {
|
|
19475
|
+
async ({ server: name }) => runTool("list_skills", async () => {
|
|
19300
19476
|
requireConnected(name);
|
|
19301
19477
|
return listServerSkillCatalog(manager, name);
|
|
19302
19478
|
})
|
|
@@ -19314,7 +19490,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19314
19490
|
}),
|
|
19315
19491
|
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
19316
19492
|
},
|
|
19317
|
-
async ({ server: name, uri }) => runTool(async () => {
|
|
19493
|
+
async ({ server: name, uri }) => runTool("get_skill", async () => {
|
|
19318
19494
|
requireConnected(name);
|
|
19319
19495
|
try {
|
|
19320
19496
|
return { skill: await getVerifiedServerSkill(manager, { serverId: name, uri }) };
|
|
@@ -19338,7 +19514,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19338
19514
|
}),
|
|
19339
19515
|
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
19340
19516
|
},
|
|
19341
|
-
async ({ server: name, skillUri, resourceUri }) => runTool(async () => {
|
|
19517
|
+
async ({ server: name, skillUri, resourceUri }) => runTool("read_skill_file", async () => {
|
|
19342
19518
|
requireConnected(name);
|
|
19343
19519
|
try {
|
|
19344
19520
|
const skill = await getVerifiedServerSkill(manager, {
|
|
@@ -19369,7 +19545,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19369
19545
|
}),
|
|
19370
19546
|
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
19371
19547
|
},
|
|
19372
|
-
async ({ server: name, cursor }) => runTool(async () => {
|
|
19548
|
+
async ({ server: name, cursor }) => runTool("list_prompts", async () => {
|
|
19373
19549
|
requireConnected(name);
|
|
19374
19550
|
return manager.listPrompts(
|
|
19375
19551
|
name,
|
|
@@ -19389,7 +19565,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19389
19565
|
}),
|
|
19390
19566
|
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
19391
19567
|
},
|
|
19392
|
-
async ({ server: name, prompt, arguments: args }) => runTool(async () => {
|
|
19568
|
+
async ({ server: name, prompt, arguments: args }) => runTool("get_prompt", async () => {
|
|
19393
19569
|
requireConnected(name);
|
|
19394
19570
|
return manager.getPrompt(name, {
|
|
19395
19571
|
name: prompt,
|
|
@@ -19409,7 +19585,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19409
19585
|
}),
|
|
19410
19586
|
annotations: { readOnlyHint: false, openWorldHint: false }
|
|
19411
19587
|
},
|
|
19412
|
-
async ({ server: name, method, clear }) => runTool(async () => {
|
|
19588
|
+
async ({ server: name, method, clear }) => runTool("get_notifications", async () => {
|
|
19413
19589
|
const matches = notifications.filter(
|
|
19414
19590
|
(entry) => (!name || entry.server === name) && (!method || entry.method === method)
|
|
19415
19591
|
);
|
|
@@ -19436,9 +19612,10 @@ function createMcpJamMcpServer(options) {
|
|
|
19436
19612
|
inputSchema: z.object(targetConfigFields),
|
|
19437
19613
|
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
19438
19614
|
},
|
|
19439
|
-
async (input) => runTool(async () => {
|
|
19615
|
+
async (input) => runTool("server_doctor", async () => {
|
|
19440
19616
|
const { config, target } = buildTargetConfig(input, defaultTimeoutMs);
|
|
19441
19617
|
const result = await runServerDoctor({
|
|
19618
|
+
__suppressTelemetry: true,
|
|
19442
19619
|
config,
|
|
19443
19620
|
target: summarizeServerDoctorTarget(target, config),
|
|
19444
19621
|
timeout: input.timeoutMs ?? defaultTimeoutMs
|
|
@@ -19459,7 +19636,7 @@ function createMcpJamMcpServer(options) {
|
|
|
19459
19636
|
}),
|
|
19460
19637
|
annotations: { readOnlyHint: true, openWorldHint: true }
|
|
19461
19638
|
},
|
|
19462
|
-
async ({ url, accessToken, headers, timeoutMs }) => runTool(async () => {
|
|
19639
|
+
async ({ url, accessToken, headers, timeoutMs }) => runTool("probe_server", async () => {
|
|
19463
19640
|
assertHttpUrl(url);
|
|
19464
19641
|
const result = await probeMcpServer({
|
|
19465
19642
|
url,
|
|
@@ -19492,11 +19669,15 @@ function registerMcpCommands(program) {
|
|
|
19492
19669
|
const globalOptions = getGlobalOptions(command);
|
|
19493
19670
|
const handle = createMcpJamMcpServer({
|
|
19494
19671
|
version: package_default.version,
|
|
19495
|
-
defaultTimeoutMs: globalOptions.timeout
|
|
19672
|
+
defaultTimeoutMs: globalOptions.timeout,
|
|
19673
|
+
onToolCalled: captureMcpToolEvent
|
|
19496
19674
|
});
|
|
19497
19675
|
const transport = new StdioServerTransport();
|
|
19498
19676
|
let resolveClosed;
|
|
19499
|
-
const stopOnSignal = () =>
|
|
19677
|
+
const stopOnSignal = () => {
|
|
19678
|
+
recordCommandOutcome("interrupted");
|
|
19679
|
+
resolveClosed();
|
|
19680
|
+
};
|
|
19500
19681
|
const closed = new Promise((resolve2) => {
|
|
19501
19682
|
resolveClosed = resolve2;
|
|
19502
19683
|
handle.server.server.onclose = resolve2;
|
|
@@ -19565,7 +19746,7 @@ function registerProtocolCommands(program) {
|
|
|
19565
19746
|
...config,
|
|
19566
19747
|
__suppressTelemetry: true
|
|
19567
19748
|
});
|
|
19568
|
-
captureConformanceRunEvent();
|
|
19749
|
+
captureConformanceRunEvent("protocol", "single");
|
|
19569
19750
|
const result = await test.run();
|
|
19570
19751
|
writeConformanceOutput2(renderConformanceForCli(result, reporter, format));
|
|
19571
19752
|
reportScore(scoreFromProtocolResult(result), command);
|
|
@@ -19598,7 +19779,7 @@ function registerProtocolCommands(program) {
|
|
|
19598
19779
|
...config,
|
|
19599
19780
|
__suppressTelemetry: true
|
|
19600
19781
|
});
|
|
19601
|
-
captureConformanceRunEvent();
|
|
19782
|
+
captureConformanceRunEvent("protocol", "suite");
|
|
19602
19783
|
const result = await suite.run();
|
|
19603
19784
|
writeConformanceOutput2(renderConformanceForCli(result, reporter, format));
|
|
19604
19785
|
for (const run of result.results) {
|
|
@@ -20148,7 +20329,7 @@ function registerOAuthCommands(program) {
|
|
|
20148
20329
|
...config,
|
|
20149
20330
|
__suppressTelemetry: true
|
|
20150
20331
|
});
|
|
20151
|
-
captureConformanceRunEvent();
|
|
20332
|
+
captureConformanceRunEvent("oauth", "single");
|
|
20152
20333
|
const result = await test.run();
|
|
20153
20334
|
let credentialsFilePath;
|
|
20154
20335
|
let credentialsFileError;
|
|
@@ -20226,7 +20407,7 @@ function registerOAuthCommands(program) {
|
|
|
20226
20407
|
...config,
|
|
20227
20408
|
__suppressTelemetry: true
|
|
20228
20409
|
});
|
|
20229
|
-
captureConformanceRunEvent();
|
|
20410
|
+
captureConformanceRunEvent("oauth", "suite");
|
|
20230
20411
|
const result = await suite.run();
|
|
20231
20412
|
const credentialsResultIndex = findCredentialsResultIndex(result);
|
|
20232
20413
|
let credentialsFilePath;
|
|
@@ -21308,7 +21489,10 @@ function taskWatchTuningFrom(options) {
|
|
|
21308
21489
|
}
|
|
21309
21490
|
async function withWatchSignals(fn) {
|
|
21310
21491
|
const controller = new AbortController();
|
|
21311
|
-
const onSignal = () =>
|
|
21492
|
+
const onSignal = () => {
|
|
21493
|
+
recordCommandOutcome("interrupted");
|
|
21494
|
+
controller.abort();
|
|
21495
|
+
};
|
|
21312
21496
|
process.on("SIGINT", onSignal);
|
|
21313
21497
|
process.on("SIGTERM", onSignal);
|
|
21314
21498
|
try {
|
|
@@ -21474,7 +21658,7 @@ function registerTasksCommands(program) {
|
|
|
21474
21658
|
...config,
|
|
21475
21659
|
__suppressTelemetry: true
|
|
21476
21660
|
});
|
|
21477
|
-
captureConformanceRunEvent();
|
|
21661
|
+
captureConformanceRunEvent("tasks", "single");
|
|
21478
21662
|
const result = await test.run();
|
|
21479
21663
|
const outputResult = reporter ? result : withRpcLogsIfRequested(result, collector, {
|
|
21480
21664
|
format,
|
|
@@ -21614,7 +21798,7 @@ function registerConformanceRunCommand(program) {
|
|
|
21614
21798
|
...oauthReadinessIds ? { readinessIds: oauthReadinessIds } : {}
|
|
21615
21799
|
};
|
|
21616
21800
|
}
|
|
21617
|
-
captureConformanceRunEvent();
|
|
21801
|
+
captureConformanceRunEvent("run", "suite");
|
|
21618
21802
|
const report2 = await runConformance({
|
|
21619
21803
|
server,
|
|
21620
21804
|
suites,
|
|
@@ -24383,6 +24567,8 @@ function registerServerCommands(program) {
|
|
|
24383
24567
|
});
|
|
24384
24568
|
const doctorTarget = summarizeServerDoctorTarget(target, config);
|
|
24385
24569
|
const result = await runServerDoctor({
|
|
24570
|
+
// The CLI counts the run itself, under its own opt-outs.
|
|
24571
|
+
__suppressTelemetry: true,
|
|
24386
24572
|
config,
|
|
24387
24573
|
target: doctorTarget,
|
|
24388
24574
|
timeout: globalOptions.timeout,
|
|
@@ -25181,6 +25367,7 @@ function registerSubscriptionsCommands(program) {
|
|
|
25181
25367
|
}
|
|
25182
25368
|
);
|
|
25183
25369
|
const onSignal = () => {
|
|
25370
|
+
recordCommandOutcome("interrupted");
|
|
25184
25371
|
void session.stop("signal");
|
|
25185
25372
|
};
|
|
25186
25373
|
process.on("SIGINT", onSignal);
|
|
@@ -25519,6 +25706,8 @@ async function runEventsConformanceForCli(args) {
|
|
|
25519
25706
|
);
|
|
25520
25707
|
}
|
|
25521
25708
|
return await runEventsConformance({
|
|
25709
|
+
// The CLI counts the run itself, under its own opt-outs.
|
|
25710
|
+
__suppressTelemetry: true,
|
|
25522
25711
|
manager: args.manager,
|
|
25523
25712
|
serverId: args.serverId,
|
|
25524
25713
|
profile: args.profile,
|
|
@@ -26255,6 +26444,7 @@ function registerWatch(events) {
|
|
|
26255
26444
|
const onSignal = () => {
|
|
26256
26445
|
signals += 1;
|
|
26257
26446
|
if (signals === 1) {
|
|
26447
|
+
recordCommandOutcome("interrupted");
|
|
26258
26448
|
ctx.status("Stopping...");
|
|
26259
26449
|
session.stop("signal");
|
|
26260
26450
|
return;
|
|
@@ -26262,7 +26452,7 @@ function registerWatch(events) {
|
|
|
26262
26452
|
ctx.warn(
|
|
26263
26453
|
"Forced exit: the server subscription (if any) remains until its TTL expires."
|
|
26264
26454
|
);
|
|
26265
|
-
|
|
26455
|
+
void exitInterrupted();
|
|
26266
26456
|
};
|
|
26267
26457
|
process.on("SIGINT", onSignal);
|
|
26268
26458
|
process.on("SIGTERM", onSignal);
|
|
@@ -26592,6 +26782,7 @@ function registerConformance(events) {
|
|
|
26592
26782
|
)
|
|
26593
26783
|
);
|
|
26594
26784
|
}
|
|
26785
|
+
captureConformanceRunEvent("events", "single");
|
|
26595
26786
|
const result = await withEventsConnection(
|
|
26596
26787
|
options,
|
|
26597
26788
|
ctx,
|
|
@@ -28164,6 +28355,15 @@ function localTestExitCodeForResult(result, observed = {}) {
|
|
|
28164
28355
|
if (observed.artifactWriteFailed) codes.push(LOCAL_TEST_EXIT.setup);
|
|
28165
28356
|
return worstOf(codes);
|
|
28166
28357
|
}
|
|
28358
|
+
function recordLocalTestOutcome(exitCode) {
|
|
28359
|
+
if (exitCode === LOCAL_TEST_EXIT.passed || exitCode === LOCAL_TEST_EXIT.failed) {
|
|
28360
|
+
return;
|
|
28361
|
+
}
|
|
28362
|
+
recordCommandOutcome(
|
|
28363
|
+
"error",
|
|
28364
|
+
exitCode === LOCAL_TEST_EXIT.credentials ? "AUTH_FAILED" : exitCode === LOCAL_TEST_EXIT.usage ? "USAGE_ERROR" : void 0
|
|
28365
|
+
);
|
|
28366
|
+
}
|
|
28167
28367
|
|
|
28168
28368
|
// src/commands/test.ts
|
|
28169
28369
|
function collect4(value, previous = []) {
|
|
@@ -28383,6 +28583,7 @@ Received ${signal}; stopping and writing the partial report\u2026
|
|
|
28383
28583
|
`
|
|
28384
28584
|
);
|
|
28385
28585
|
}
|
|
28586
|
+
recordCommandOutcome("interrupted");
|
|
28386
28587
|
controller.abort(new Error(`interrupted by ${signal}`));
|
|
28387
28588
|
};
|
|
28388
28589
|
process.on("SIGINT", onSignal);
|
|
@@ -28465,6 +28666,7 @@ Received ${signal}; stopping and writing the partial report\u2026
|
|
|
28465
28666
|
if (error instanceof CliError) {
|
|
28466
28667
|
writeError(error, globalOptions.format);
|
|
28467
28668
|
setProcessExitCode(error.exitCode);
|
|
28669
|
+
recordCommandOutcome("error", error.code);
|
|
28468
28670
|
return;
|
|
28469
28671
|
}
|
|
28470
28672
|
throw error;
|
|
@@ -28506,6 +28708,10 @@ Received ${signal}; stopping and writing the partial report\u2026
|
|
|
28506
28708
|
} catch (error) {
|
|
28507
28709
|
writeError(error, globalOptions.format);
|
|
28508
28710
|
setProcessExitCode(LOCAL_TEST_EXIT.notEstablished);
|
|
28711
|
+
recordCommandOutcome(
|
|
28712
|
+
"error",
|
|
28713
|
+
error instanceof CliError ? error.code : void 0
|
|
28714
|
+
);
|
|
28509
28715
|
return;
|
|
28510
28716
|
}
|
|
28511
28717
|
if (!globalOptions.quiet) {
|
|
@@ -28518,6 +28724,7 @@ Received ${signal}; stopping and writing the partial report\u2026
|
|
|
28518
28724
|
artifactWriteFailed
|
|
28519
28725
|
});
|
|
28520
28726
|
setProcessExitCode(exitCode);
|
|
28727
|
+
recordLocalTestOutcome(exitCode);
|
|
28521
28728
|
}
|
|
28522
28729
|
);
|
|
28523
28730
|
}
|
|
@@ -29564,6 +29771,7 @@ function registerRegistryCommands(program) {
|
|
|
29564
29771
|
var pkgVersion = package_default.version;
|
|
29565
29772
|
async function main(argv = process.argv, dependencies = {}) {
|
|
29566
29773
|
process.exitCode = 0;
|
|
29774
|
+
resetCommandOutcome();
|
|
29567
29775
|
const program = addGlobalOptions(
|
|
29568
29776
|
new Command().name("mcpjam").version(pkgVersion, "-v, --version", "output the CLI version").description(
|
|
29569
29777
|
"Test, debug, and validate MCP servers locally, or manage MCPJam Cloud via `mcpjam cloud`. Health checks, OAuth conformance, tool-surface diffing, and structured triage from the terminal or CI."
|
|
@@ -29615,10 +29823,8 @@ async function main(argv = process.argv, dependencies = {}) {
|
|
|
29615
29823
|
restoreConsole();
|
|
29616
29824
|
}
|
|
29617
29825
|
const normalizedExitCode = typeof process.exitCode === "number" ? process.exitCode : 0;
|
|
29618
|
-
|
|
29619
|
-
|
|
29620
|
-
normalizedExitCode === 0 ? void 0 : "UNKNOWN_ERROR"
|
|
29621
|
-
);
|
|
29826
|
+
const { outcome, errorCode } = resolveCommandOutcome(normalizedExitCode);
|
|
29827
|
+
captureCommandEvent(normalizedExitCode, outcome, errorCode);
|
|
29622
29828
|
await telemetry.flush();
|
|
29623
29829
|
return {
|
|
29624
29830
|
exitCode: normalizedExitCode,
|
|
@@ -29635,7 +29841,7 @@ async function main(argv = process.argv, dependencies = {}) {
|
|
|
29635
29841
|
};
|
|
29636
29842
|
}
|
|
29637
29843
|
writeError(usageError(error.message), format);
|
|
29638
|
-
|
|
29844
|
+
captureUsageErrorEvent(argv);
|
|
29639
29845
|
await telemetry.flush();
|
|
29640
29846
|
return {
|
|
29641
29847
|
exitCode: 2,
|
|
@@ -29644,7 +29850,15 @@ async function main(argv = process.argv, dependencies = {}) {
|
|
|
29644
29850
|
}
|
|
29645
29851
|
const normalizedError = normalizeCliError(error);
|
|
29646
29852
|
writeError(normalizedError, format);
|
|
29647
|
-
|
|
29853
|
+
if (normalizedError.code === "USAGE_ERROR") {
|
|
29854
|
+
captureUsageErrorEvent(argv, normalizedError.exitCode);
|
|
29855
|
+
} else {
|
|
29856
|
+
const { outcome, errorCode } = resolveCommandOutcome(
|
|
29857
|
+
normalizedError.exitCode,
|
|
29858
|
+
normalizedError.code
|
|
29859
|
+
);
|
|
29860
|
+
captureCommandEvent(normalizedError.exitCode, outcome, errorCode);
|
|
29861
|
+
}
|
|
29648
29862
|
await telemetry.flush();
|
|
29649
29863
|
return {
|
|
29650
29864
|
exitCode: normalizedError.exitCode,
|