@mcpjam/cli 2.0.0 → 2.0.1

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 ADDED
@@ -0,0 +1,144 @@
1
+ # @mcpjam/cli
2
+
3
+ Test, debug, and validate MCP servers — health checks, OAuth conformance, tool-surface diffing, and structured triage from the terminal or CI.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i -g @mcpjam/cli
9
+ ```
10
+
11
+ Or run without installing:
12
+
13
+ ```bash
14
+ npx -y @mcpjam/cli@latest --help
15
+ ```
16
+
17
+ ## Commands
18
+
19
+ ```
20
+ $ mcpjam --help
21
+
22
+ Usage: mcpjam [options] [command]
23
+
24
+ Test, debug, and validate MCP servers — health checks, OAuth conformance,
25
+ tool-surface diffing, and structured triage from the terminal or CI
26
+
27
+ Options:
28
+ -v, --version output the CLI version
29
+ --timeout <ms> Request timeout in milliseconds (default: 30000)
30
+ --rpc Include RPC logs in JSON output
31
+ --format <format> Output format
32
+ -h, --help display help for command
33
+
34
+ Commands:
35
+ server Inspect MCP server connectivity and capabilities
36
+ tools List and invoke MCP server tools
37
+ resources List and read MCP resources
38
+ prompts List and fetch MCP prompts
39
+ apps Fetch MCP App and ChatGPT App widget content
40
+ oauth Run MCP OAuth login, proxy, and conformance flows
41
+ protocol MCP protocol inspection and conformance checks
42
+ ```
43
+
44
+ ## Quick start
45
+
46
+ ```bash
47
+ # Probe: is the server reachable? What transport? Is OAuth configured?
48
+ mcpjam server probe --url https://your-server.com/mcp
49
+
50
+ # Health check: MCP handshake, tool/resource/prompt sweep, exit code 0 or fail
51
+ mcpjam server doctor --url https://your-server.com/mcp --access-token $TOKEN
52
+
53
+ # OAuth login
54
+ mcpjam oauth login --url https://your-server.com/mcp --protocol-version 2025-11-25
55
+
56
+ # List tools with full schemas
57
+ mcpjam tools list --url https://your-server.com/mcp --access-token $TOKEN --format json
58
+ ```
59
+
60
+ ## Why
61
+
62
+ MCP servers ship without the testing infrastructure REST APIs take for granted. No health checks, no OAuth conformance tests, no deploy-time regression detection. `mcpjam` fills that gap.
63
+
64
+ ## What it does
65
+
66
+ ### CI gate on every deploy
67
+
68
+ Run `server doctor` in your pipeline. It probes connectivity, runs the MCP handshake, and sweeps every tool, resource, and prompt. Exit code 0 or the build fails.
69
+
70
+ ```bash
71
+ mcpjam server doctor --url $MCP_SERVER_URL --access-token $TOKEN --format json
72
+ ```
73
+
74
+ ### Catch breaking changes before they ship
75
+
76
+ `server export` snapshots your entire tool surface — names, schemas, descriptions, capabilities — as diffable JSON. A renamed parameter or changed description shows up in the diff.
77
+
78
+ ```bash
79
+ mcpjam server export --url $URL --access-token $TOKEN > before.json
80
+ # deploy...
81
+ mcpjam server export --url $URL --access-token $TOKEN > after.json
82
+ diff <(jq -S . before.json) <(jq -S . after.json)
83
+ ```
84
+
85
+ ### OAuth conformance across the full matrix
86
+
87
+ Cover the full registration × protocol version × auth mode matrix from a single config file. Outputs JUnit XML.
88
+
89
+ ```bash
90
+ mcpjam oauth conformance-suite --config ./oauth-matrix.json --format junit-xml > report.xml
91
+ ```
92
+
93
+ ### Verify tokens work end-to-end
94
+
95
+ OAuth can succeed while `tools/list` returns 401 because the audience, scope, or session init is wrong. `--verify-call-tool` completes the full chain — OAuth, MCP connect, tool call — and reports which step fails.
96
+
97
+ ```bash
98
+ mcpjam oauth conformance --url $URL --protocol-version 2025-11-25 \
99
+ --registration dcr --verify-call-tool your_critical_tool
100
+ ```
101
+
102
+ ### Protocol version compatibility
103
+
104
+ MCP has shipped three protocol versions (2025-03-26, 2025-06-18, 2025-11-25). Clients upgrade on their own schedule. Declare the version matrix once and test on every push.
105
+
106
+ ```json
107
+ {
108
+ "flows": [
109
+ { "label": "2025-03-26/dcr", "protocolVersion": "2025-03-26", "registrationStrategy": "dcr" },
110
+ { "label": "2025-06-18/dcr", "protocolVersion": "2025-06-18", "registrationStrategy": "dcr" },
111
+ { "label": "2025-11-25/cimd", "protocolVersion": "2025-11-25", "registrationStrategy": "cimd" }
112
+ ]
113
+ }
114
+ ```
115
+
116
+ ### Structured debug artifacts
117
+
118
+ `--debug-out` captures a JSON artifact with every request and response in the OAuth and MCP flow. Attach it to a ticket — no reproduction steps required.
119
+
120
+ ```bash
121
+ mcpjam oauth login --url $URL --protocol-version 2025-11-25 \
122
+ --registration dcr --debug-out oauth-debug.json
123
+ ```
124
+
125
+ ### Incident triage
126
+
127
+ Separate your failures from host-side failures. `--rpc` records what your server returned — transport type, status codes, raw JSON-RPC pairs — as a structured artifact for postmortems.
128
+
129
+ ```bash
130
+ mcpjam server doctor --url $URL --access-token $TOKEN --rpc --out incident-triage.json
131
+ ```
132
+
133
+ ### Tool surface audit
134
+
135
+ Pipe the full schema inventory into your own linter, review it in a PR, or check whether descriptions are clear enough for tool selection.
136
+
137
+ ```bash
138
+ mcpjam tools list --url $URL --access-token $TOKEN --format json \
139
+ | jq '.tools[] | {name, description, inputSchema}'
140
+ ```
141
+
142
+ ## Documentation
143
+
144
+ Full docs at [docs.mcpjam.com/cli](https://docs.mcpjam.com/cli).
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.0";
15
+ var version = "2.0.1";
16
16
 
17
17
  // src/lib/output.ts
18
18
  var DEFAULT_OUTPUT_FORMAT = "json";
@@ -95,7 +95,10 @@ function parseOutputFormat(value) {
95
95
  }
96
96
  throw usageError(`Invalid output format "${value}". Use "json" or "human".`);
97
97
  }
98
- function detectOutputFormatFromArgv(argv) {
98
+ function resolveOutputFormat(value, isTTY) {
99
+ return parseOutputFormat(value ?? (isTTY ? "human" : "json"));
100
+ }
101
+ function detectOutputFormatFromArgv(argv, isTTY = process.stdout.isTTY) {
99
102
  for (let index = 0; index < argv.length; index += 1) {
100
103
  const token = argv[index];
101
104
  if (token === "--format") {
@@ -105,7 +108,7 @@ function detectOutputFormatFromArgv(argv) {
105
108
  return parseLooseOutputFormat(token.slice("--format=".length));
106
109
  }
107
110
  }
108
- return DEFAULT_OUTPUT_FORMAT;
111
+ return isTTY ? "human" : DEFAULT_OUTPUT_FORMAT;
109
112
  }
110
113
  function parseLooseOutputFormat(value) {
111
114
  return value === "human" ? "human" : DEFAULT_OUTPUT_FORMAT;
@@ -360,7 +363,7 @@ function addSharedServerOptions(command) {
360
363
  function getGlobalOptions(command) {
361
364
  const options = command.optsWithGlobals();
362
365
  return {
363
- format: parseOutputFormat(options.format ?? "json"),
366
+ format: resolveOutputFormat(options.format, process.stdout.isTTY),
364
367
  timeout: options.timeout ?? 3e4,
365
368
  rpc: options.rpc ?? false
366
369
  };
@@ -413,6 +416,34 @@ function parsePromptArguments(value) {
413
416
  Object.entries(raw).map(([key, entryValue]) => [key, String(entryValue)])
414
417
  );
415
418
  }
419
+ function resolveAliasedStringOption(options, aliases, label, config) {
420
+ const provided = aliases.map((alias) => {
421
+ const value = options[alias.key];
422
+ if (typeof value !== "string") {
423
+ return void 0;
424
+ }
425
+ const normalized = value.trim();
426
+ if (!normalized) {
427
+ return void 0;
428
+ }
429
+ return {
430
+ flag: alias.flag,
431
+ value: normalized
432
+ };
433
+ }).filter((entry) => entry !== void 0);
434
+ const flagsText = aliases.map((alias) => alias.flag).join(" or ");
435
+ if (provided.length === 0) {
436
+ if (config?.required) {
437
+ throw usageError(`${label} is required. Use ${flagsText}.`);
438
+ }
439
+ return void 0;
440
+ }
441
+ const values = new Set(provided.map((entry) => entry.value));
442
+ if (values.size > 1) {
443
+ throw usageError(`Specify only one of ${flagsText}.`);
444
+ }
445
+ return provided[0]?.value;
446
+ }
416
447
  function parseServerConfig(options) {
417
448
  const url = options.url?.trim();
418
449
  const command = options.command?.trim();
@@ -559,7 +590,7 @@ function resolveHttpAccessToken(options) {
559
590
  function registerAppsCommands(program) {
560
591
  const apps = program.command("apps").description("Fetch MCP App and ChatGPT App widget content");
561
592
  addSharedServerOptions(
562
- apps.command("mcp-widget").description("Fetch hosted-style MCP App widget content").requiredOption("--resource-uri <uri>", "Widget resource URI").requiredOption("--tool-id <id>", "Tool call id used for runtime injection").requiredOption("--tool-name <name>", "Tool name used for runtime injection").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(
593
+ 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("--tool-id <id>", "Tool call id used for runtime injection").requiredOption("--tool-name <name>", "Tool name used for runtime injection").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(
563
594
  "--csp-mode <mode>",
564
595
  "CSP mode: permissive or widget-declared"
565
596
  ).option("--template <uri>", "Optional ui:// template override").option("--view-mode <mode>", "Widget view mode").option("--view-params <json>", "Widget view params as JSON")
@@ -567,6 +598,15 @@ function registerAppsCommands(program) {
567
598
  const globalOptions = getGlobalOptions(command);
568
599
  const target = describeTarget(options);
569
600
  const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
601
+ const resourceUri = resolveAliasedStringOption(
602
+ options,
603
+ [
604
+ { key: "resourceUri", flag: "--resource-uri" },
605
+ { key: "uri", flag: "--uri" }
606
+ ],
607
+ "Widget resource URI",
608
+ { required: true }
609
+ );
570
610
  const config = parseServerConfig({
571
611
  ...options,
572
612
  timeout: globalOptions.timeout
@@ -574,7 +614,7 @@ function registerAppsCommands(program) {
574
614
  const result = await withEphemeralManager(
575
615
  config,
576
616
  (manager, serverId) => buildMcpWidgetContent(manager, serverId, {
577
- resourceUri: options.resourceUri,
617
+ resourceUri,
578
618
  toolId: options.toolId,
579
619
  toolName: options.toolName,
580
620
  toolInput: parseJsonRecord(options.toolInput, "Tool input") ?? {},
@@ -593,7 +633,7 @@ function registerAppsCommands(program) {
593
633
  writeResult(withRpcLogsIfRequested(result, collector, globalOptions), globalOptions.format);
594
634
  });
595
635
  addSharedServerOptions(
596
- apps.command("chatgpt-widget").description("Fetch hosted-style ChatGPT App widget content").requiredOption("--uri <uri>", "Widget resource URI").requiredOption("--tool-id <id>", "Tool call id used for runtime injection").requiredOption("--tool-name <name>", "Tool name used for runtime injection").option("--tool-input <json>", "Tool input payload as JSON").option("--tool-output <json>", "Tool output payload as JSON").option(
636
+ 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("--tool-id <id>", "Tool call id used for runtime injection").requiredOption("--tool-name <name>", "Tool name used for runtime injection").option("--tool-input <json>", "Tool input payload as JSON").option("--tool-output <json>", "Tool output payload as JSON").option(
597
637
  "--tool-response-metadata <json>",
598
638
  "Tool response metadata as a JSON object"
599
639
  ).option("--theme <theme>", "Widget theme: light or dark").option(
@@ -604,6 +644,15 @@ function registerAppsCommands(program) {
604
644
  const globalOptions = getGlobalOptions(command);
605
645
  const target = describeTarget(options);
606
646
  const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
647
+ const resourceUri = resolveAliasedStringOption(
648
+ options,
649
+ [
650
+ { key: "resourceUri", flag: "--resource-uri" },
651
+ { key: "uri", flag: "--uri" }
652
+ ],
653
+ "Widget resource URI",
654
+ { required: true }
655
+ );
607
656
  const config = parseServerConfig({
608
657
  ...options,
609
658
  timeout: globalOptions.timeout
@@ -611,7 +660,7 @@ function registerAppsCommands(program) {
611
660
  const result = await withEphemeralManager(
612
661
  config,
613
662
  (manager, serverId) => buildChatGptWidgetContent(manager, serverId, {
614
- uri: options.uri,
663
+ uri: resourceUri,
615
664
  toolId: options.toolId,
616
665
  toolName: options.toolName,
617
666
  toolInput: parseJsonRecord(options.toolInput, "Tool input") ?? {},
@@ -710,11 +759,7 @@ function registerProtocolCommands(program) {
710
759
  }
711
760
  function getFormat(command) {
712
761
  const opts = command.optsWithGlobals();
713
- const value = opts.format ?? "json";
714
- if (value === "json" || value === "human") {
715
- return value;
716
- }
717
- throw usageError(`Invalid output format "${value}". Use "json" or "human".`);
762
+ return resolveOutputFormat(opts.format, process.stdout.isTTY);
718
763
  }
719
764
  function collectInvalidEntries(values, allowedValues) {
720
765
  return (values ?? []).filter((value) => !allowedValues.includes(value));
@@ -1622,11 +1667,20 @@ function registerPromptCommands(program) {
1622
1667
  writeResult(withRpcLogsIfRequested(result, collector, globalOptions), globalOptions.format);
1623
1668
  });
1624
1669
  addSharedServerOptions(
1625
- prompts.command("get").description("Get a named prompt from an MCP server").requiredOption("--name <prompt>", "Prompt name").option("--prompt-args <json>", "Prompt arguments as a JSON object")
1670
+ 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")
1626
1671
  ).action(async (options, command) => {
1627
1672
  const globalOptions = getGlobalOptions(command);
1628
1673
  const target = describeTarget(options);
1629
1674
  const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
1675
+ const promptName = resolveAliasedStringOption(
1676
+ options,
1677
+ [
1678
+ { key: "promptName", flag: "--prompt-name" },
1679
+ { key: "name", flag: "--name" }
1680
+ ],
1681
+ "Prompt name",
1682
+ { required: true }
1683
+ );
1630
1684
  const config = parseServerConfig({
1631
1685
  ...options,
1632
1686
  timeout: globalOptions.timeout
@@ -1636,7 +1690,7 @@ function registerPromptCommands(program) {
1636
1690
  config,
1637
1691
  (manager, serverId) => sdk.getPrompt(manager, {
1638
1692
  serverId,
1639
- name: options.name,
1693
+ name: promptName,
1640
1694
  arguments: promptArguments
1641
1695
  }),
1642
1696
  {
@@ -1670,18 +1724,27 @@ function registerResourcesCommands(program) {
1670
1724
  writeResult(withRpcLogsIfRequested(result, collector, globalOptions), globalOptions.format);
1671
1725
  });
1672
1726
  addSharedServerOptions(
1673
- resources.command("read").description("Read a resource from an MCP server").requiredOption("--uri <uri>", "Resource URI")
1727
+ resources.command("read").description("Read a resource from an MCP server").option("--resource-uri <uri>", "Resource URI").option("--uri <uri>", "Alias for --resource-uri")
1674
1728
  ).action(async (options, command) => {
1675
1729
  const globalOptions = getGlobalOptions(command);
1676
1730
  const target = describeTarget(options);
1677
1731
  const collector = globalOptions.rpc ? createCliRpcLogCollector({ __cli__: target }) : void 0;
1732
+ const resourceUri = resolveAliasedStringOption(
1733
+ options,
1734
+ [
1735
+ { key: "resourceUri", flag: "--resource-uri" },
1736
+ { key: "uri", flag: "--uri" }
1737
+ ],
1738
+ "Resource URI",
1739
+ { required: true }
1740
+ );
1678
1741
  const config = parseServerConfig({
1679
1742
  ...options,
1680
1743
  timeout: globalOptions.timeout
1681
1744
  });
1682
1745
  const result = await withEphemeralManager(
1683
1746
  config,
1684
- (manager, serverId) => sdk.readResource(manager, { serverId, uri: options.uri }),
1747
+ (manager, serverId) => sdk.readResource(manager, { serverId, uri: resourceUri }),
1685
1748
  {
1686
1749
  timeout: globalOptions.timeout,
1687
1750
  rpcLogger: collector?.rpcLogger
@@ -2074,8 +2137,6 @@ function registerServerCommands(program) {
2074
2137
  writeResult(withRpcLogsIfRequested(result, collector, globalOptions), globalOptions.format);
2075
2138
  });
2076
2139
  }
2077
-
2078
- // src/commands/tools.ts
2079
2140
  function registerToolsCommands(program) {
2080
2141
  const tools = program.command("tools").description("List and invoke MCP server tools");
2081
2142
  addSharedServerOptions(
@@ -2103,7 +2164,7 @@ function registerToolsCommands(program) {
2103
2164
  writeResult(withRpcLogsIfRequested(result, collector, globalOptions), globalOptions.format);
2104
2165
  });
2105
2166
  addSharedServerOptions(
2106
- tools.command("call").description("Call an MCP tool").requiredOption("--name <tool>", "Tool name").option("--params <json>", "Tool parameter object as JSON").option(
2167
+ 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(
2107
2168
  "--debug-out <path>",
2108
2169
  "Write a structured debug artifact to a file"
2109
2170
  )
@@ -2116,14 +2177,31 @@ function registerToolsCommands(program) {
2116
2177
  ...options,
2117
2178
  timeout: globalOptions.timeout
2118
2179
  });
2119
- const params = parseJsonRecord(options.params, "Tool parameters") ?? {};
2180
+ const toolName = resolveAliasedStringOption(
2181
+ options,
2182
+ [
2183
+ { key: "toolName", flag: "--tool-name" },
2184
+ { key: "name", flag: "--name" }
2185
+ ],
2186
+ "Tool name",
2187
+ { required: true }
2188
+ );
2189
+ const paramsInput = resolveAliasedStringOption(
2190
+ options,
2191
+ [
2192
+ { key: "toolArgs", flag: "--tool-args" },
2193
+ { key: "params", flag: "--params" }
2194
+ ],
2195
+ "Tool parameters"
2196
+ );
2197
+ const params = parseJsonRecord(paramsInput, "Tool parameters") ?? {};
2120
2198
  const targetSummary = summarizeServerDoctorTarget(target, config);
2121
2199
  let result;
2122
2200
  let commandError;
2123
2201
  try {
2124
2202
  result = await withEphemeralManager(
2125
2203
  config,
2126
- (manager, serverId) => manager.executeTool(serverId, options.name, params),
2204
+ (manager, serverId) => manager.executeTool(serverId, toolName, params),
2127
2205
  {
2128
2206
  timeout: globalOptions.timeout,
2129
2207
  rpcLogger: primaryCollector?.rpcLogger
@@ -2137,7 +2215,7 @@ function registerToolsCommands(program) {
2137
2215
  format: globalOptions.format,
2138
2216
  commandName: "tools call",
2139
2217
  commandInput: {
2140
- toolName: options.name,
2218
+ toolName,
2141
2219
  params
2142
2220
  },
2143
2221
  target: targetSummary,
@@ -2165,6 +2243,9 @@ function registerToolsCommands(program) {
2165
2243
  withRpcLogsIfRequested(result, primaryCollector, globalOptions),
2166
2244
  globalOptions.format
2167
2245
  );
2246
+ if (sdk.isCallToolResultError(result)) {
2247
+ setProcessExitCode(1);
2248
+ }
2168
2249
  });
2169
2250
  }
2170
2251
 
@@ -2172,7 +2253,7 @@ function registerToolsCommands(program) {
2172
2253
  async function main(argv = process.argv) {
2173
2254
  const program = addGlobalOptions(
2174
2255
  new commander.Command().name("mcpjam").version(version, "-v, --version", "output the CLI version").description(
2175
- "Stateless MCP server probing, debugging, OAuth login, and conformance commands backed by @mcpjam/sdk"
2256
+ "Test, debug, and validate MCP servers \u2014 health checks, OAuth conformance, tool-surface diffing, and structured triage from the terminal or CI"
2176
2257
  ).allowExcessArguments(false).exitOverride().configureOutput({
2177
2258
  writeOut: (value) => process.stdout.write(value),
2178
2259
  writeErr: () => {