@mcpjam/cli 3.13.0 → 3.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { Command, CommanderError } from 'commander';
3
3
  import { realpathSync, mkdirSync, writeFileSync, readFileSync, existsSync, statSync, closeSync, renameSync, openSync } from 'fs';
4
4
  import { pathToFileURL } from 'url';
5
- import { probeMcpServer, redactSensitiveValue, runServerDoctor, collectServerSnapshot, serializeStableServerSnapshot, serializeServerSnapshot, buildServerDiffReport, validateToolCallResult, isCallToolResultError, buildToolCallValidationReport, listResources, readResource, listTools, listPrompts, getPrompt, MCPAppsConformanceTest, MCPAppsConformanceSuite, runOAuthLogin, OAuthConformanceTest, OAuthConformanceSuite, MCPConformanceTest, MCPConformanceSuite, withEphemeralClient, diffServerSnapshots, ServerSnapshotFormatError, renderStructuredRunJUnitXml, renderStructuredRunJson, toConformanceReport, renderConformanceReportJUnitXml, renderConformanceReportJson, formatOAuthConformanceHuman, formatOAuthConformanceSuiteHuman, fetchOAuthMetadata, executeOAuthProxy, executeDebugOAuthProxy, generateRandomString, generateCodeChallenge, createInteractiveAuthorizationSession, openUrlInBrowser, MCPClientManager, MCP_APPS_CHECK_CATEGORIES, MCP_APPS_CHECK_IDS, OAuthProxyError, MCP_CHECK_CATEGORIES, MCP_CHECK_IDS } from '@mcpjam/sdk';
5
+ import { probeMcpServer, redactSensitiveValue, runServerDoctor, collectServerSnapshot, serializeStableServerSnapshot, serializeServerSnapshot, buildServerDiffReport, validateToolCallResult, isCallToolResultError, buildToolCallValidationReport, listResources, readResource, listTools, listPrompts, getPrompt, MCPAppsConformanceTest, MCPAppsConformanceSuite, runOAuthLogin, OAuthConformanceTest, OAuthConformanceSuite, runXaaFlow, MCPConformanceTest, MCPConformanceSuite, withEphemeralClient, diffServerSnapshots, ServerSnapshotFormatError, renderStructuredRunJUnitXml, renderStructuredRunJson, toConformanceReport, renderConformanceReportJUnitXml, renderConformanceReportJson, formatOAuthConformanceHuman, formatOAuthConformanceSuiteHuman, fetchOAuthMetadata, executeOAuthProxy, executeDebugOAuthProxy, normalizeRegistrationStrategy, normalizeIdentityAssertionFormat, IDENTITY_ASSERTION_FORMATS, XAA_CONFIDENTIAL_CIMD_ORIGIN, initXaaClientKeyPair, buildConfidentialCimdUrl, getXaaClientJwks, generateRandomString, generateCodeChallenge, createInteractiveAuthorizationSession, openUrlInBrowser, MCPClientManager, MCP_APPS_CHECK_CATEGORIES, MCP_APPS_CHECK_IDS, OAuthProxyError, isLoopbackHost, MCP_CHECK_CATEGORIES, MCP_CHECK_IDS } from '@mcpjam/sdk';
6
6
  import { mkdir, writeFile, readFile, chmod, rename, rm } from 'fs/promises';
7
7
  import path2, { dirname, join, basename } from 'path';
8
8
  import { randomUUID } from 'crypto';
@@ -23,7 +23,7 @@ import { WebSocket } from 'ws';
23
23
 
24
24
  // package.json
25
25
  var package_default = {
26
- version: "3.13.0"};
26
+ version: "3.15.0"};
27
27
 
28
28
  // src/lib/output.ts
29
29
  var DEFAULT_OUTPUT_FORMAT = "json";
@@ -6543,6 +6543,311 @@ function statusToErrorCode(status) {
6543
6543
  if (status === 504) return "TIMEOUT";
6544
6544
  return "INTERNAL_ERROR";
6545
6545
  }
6546
+ function registerXaaCommands(program) {
6547
+ const xaa = program.command("xaa").description(
6548
+ "Run the Cross-App Access (ID-JAG) debugger against an MCP server"
6549
+ );
6550
+ xaa.command("run").description(
6551
+ "Self-issue an ID-JAG, redeem it at the target authorization server (RFC 7523), and call the MCP server with the resulting access token"
6552
+ ).requiredOption("--url <url>", "Target MCP server URL (the protected resource)").requiredOption(
6553
+ "--issuer-base-url <url>",
6554
+ "Origin the local mock IdP issues from (the AS must be able to fetch its JWKS from here to validate the ID-JAG)"
6555
+ ).requiredOption("--sub <subject>", "Simulated end-user subject identifier").option(
6556
+ "--client-id <id>",
6557
+ "OAuth client the ID-JAG is issued for; also presented at redemption. Required for --registration preregistered (the default); rejected for dcr/cimd (the identity is derived)"
6558
+ ).option(
6559
+ "--registration <method>",
6560
+ "Client-registration strategy: preregistered (default); dcr (RFC 7591 dynamic registration at the RAS \u2014 a diagnostic that simulates the IdP\u2192RAS client_id mapping and may leave a registration behind each run); or cimd (Client ID Metadata Document \u2014 public client, interop-only, not a recommended production posture)",
6561
+ parseRegistration
6562
+ ).option(
6563
+ "--client-metadata-url <url>",
6564
+ "CIMD only: the Client ID Metadata Document URL to present as the client_id (default: the hosted XAA debugger document)"
6565
+ ).option(
6566
+ "--client-auth <method>",
6567
+ "CIMD only: how the client authenticates. none (public, default) or private-key-jwt (confidential \u2014 generates a client key, publishes it via the hosted reflector, and signs a client_assertion)",
6568
+ parseClientAuth
6569
+ ).option(
6570
+ "--cimd-metadata-origin <url>",
6571
+ "Confidential CIMD only: origin hosting the metadata-document reflector (default: the hosted app.mcpjam.com). An http loopback origin is a dev-only opt-in (requires no --https-only)"
6572
+ ).option(
6573
+ "--authz-server-issuer <issuer>",
6574
+ "Target authorization-server issuer. When set, protected-resource metadata discovery is skipped"
6575
+ ).option(
6576
+ "--token-endpoint <url>",
6577
+ "Authorization-server token endpoint. When set, AS-metadata discovery is skipped"
6578
+ ).option("--email <email>", "Simulated end-user email claim").option("--client-secret <secret>", "OAuth client secret presented at redemption").option(
6579
+ "--token-endpoint-auth-method <method>",
6580
+ "Token endpoint client authentication: client_secret_basic, client_secret_post, or none (default: infer from metadata)",
6581
+ parseTokenEndpointAuthMethod
6582
+ ).option(
6583
+ "--assertion-format <format>",
6584
+ "Identity assertion format the mock IdP mints: oidc (ID token, default) or saml (SAML 2.0 assertion)",
6585
+ parseAssertionFormat
6586
+ ).option("--scopes <scopes>", "Space-separated scope string").option(
6587
+ "--https-only",
6588
+ "Reject non-HTTPS / private targets (default: allow http/localhost for local dev)"
6589
+ ).action(async (options, command) => {
6590
+ const globalOptions = getGlobalOptions(command);
6591
+ const format = globalOptions.format;
6592
+ const config = buildXaaConfig(
6593
+ options,
6594
+ globalOptions.timeout
6595
+ );
6596
+ resolveConfidentialCimd(config, globalOptions.quiet);
6597
+ const isTTY = process.stderr.isTTY && !globalOptions.quiet;
6598
+ if (isTTY) {
6599
+ config.onProgress = (message) => {
6600
+ process.stderr.write(`\r\x1B[K${message}`);
6601
+ };
6602
+ }
6603
+ let result;
6604
+ try {
6605
+ result = await runXaaFlow(config);
6606
+ } finally {
6607
+ if (isTTY) {
6608
+ process.stderr.write("\r\x1B[K");
6609
+ }
6610
+ }
6611
+ if (!result) {
6612
+ throw cliError("INTERNAL_ERROR", "XAA flow did not return a result.");
6613
+ }
6614
+ writeResult(redactXaaResult(result), format);
6615
+ printRegistrationNotes(result, globalOptions.quiet);
6616
+ if (!result.completed) {
6617
+ setProcessExitCode(1);
6618
+ }
6619
+ });
6620
+ }
6621
+ function printRegistrationNotes(result, quiet) {
6622
+ if (quiet) return;
6623
+ const reg = result.registration;
6624
+ if (!reg) return;
6625
+ if (reg.strategy === "dcr" && reg.clientId) {
6626
+ const safeClientId = reg.clientId.replace(/[\u0000-\u001f\u007f-\u009f]/g, "");
6627
+ process.stderr.write(
6628
+ `Note: DCR is a RAS diagnostic \u2014 the CLI supplies the IdP\u2192RAS client_id mapping itself (simulated IdP), so a real enterprise IdP would still need to be told the RAS-minted client_id ("${safeClientId}"). Each run may leave another registration behind (no RFC 7592 cleanup).
6629
+ `
6630
+ );
6631
+ }
6632
+ if (reg.strategy === "cimd" && reg.warnings.some((w) => w.code === "public_client")) {
6633
+ process.stderr.write(
6634
+ `Note: public-client CIMD \u2014 interoperability passed, but the security posture is not recommended (ID-JAG draft-04 \xA79.1 recommends confidential clients / private_key_jwt).
6635
+ `
6636
+ );
6637
+ }
6638
+ }
6639
+ function redactXaaResult(result) {
6640
+ const rawIdJag = result.idJag?.token;
6641
+ const masked = result.idJag ? { ...result, idJag: { ...result.idJag, token: "[REDACTED]" } } : result;
6642
+ const scrubbed = redactSensitiveValue(masked);
6643
+ const afterRaw = rawIdJag ? replaceRawValue(scrubbed, rawIdJag) : scrubbed;
6644
+ return result.registration ? { ...afterRaw, registration: result.registration } : afterRaw;
6645
+ }
6646
+ function replaceRawValue(value, secret) {
6647
+ if (typeof value === "string") {
6648
+ return value.includes(secret) ? value.split(secret).join("[REDACTED]") : value;
6649
+ }
6650
+ if (Array.isArray(value)) {
6651
+ return value.map((entry) => replaceRawValue(entry, secret));
6652
+ }
6653
+ if (value && typeof value === "object") {
6654
+ return Object.fromEntries(
6655
+ Object.entries(value).map(([key, entryValue]) => [
6656
+ key,
6657
+ replaceRawValue(entryValue, secret)
6658
+ ])
6659
+ );
6660
+ }
6661
+ return value;
6662
+ }
6663
+ function buildXaaConfig(options, timeoutMs) {
6664
+ const serverUrl = options.url.trim();
6665
+ assertValidUrl3(serverUrl, "server URL");
6666
+ const issuerBaseUrl = options.issuerBaseUrl.trim();
6667
+ assertValidUrl3(issuerBaseUrl, "issuer base URL");
6668
+ const subject = options.sub.trim();
6669
+ if (!subject) {
6670
+ throw usageError("--sub must not be empty.");
6671
+ }
6672
+ const strategy = options.registration ?? "preregistered";
6673
+ const isDynamic = strategy === "dcr" || strategy === "cimd";
6674
+ const clientId = options.clientId?.trim() || void 0;
6675
+ if (strategy === "preregistered" && !clientId) {
6676
+ throw usageError(
6677
+ "--client-id is required for the preregistered strategy (the default). Use --registration dcr or --registration cimd to obtain the client identity dynamically."
6678
+ );
6679
+ }
6680
+ if (isDynamic && clientId) {
6681
+ throw usageError(
6682
+ `--client-id must not be set with --registration ${strategy}: the client identity is ${strategy === "dcr" ? "minted by dynamic registration" : "the client-metadata-document URL"}.`
6683
+ );
6684
+ }
6685
+ if (isDynamic && options.clientSecret) {
6686
+ throw usageError(
6687
+ `--client-secret must not be set with --registration ${strategy}.`
6688
+ );
6689
+ }
6690
+ if (isDynamic && options.tokenEndpointAuthMethod) {
6691
+ throw usageError(
6692
+ `--token-endpoint-auth-method must not be set with --registration ${strategy}: the auth method is derived from ${strategy === "dcr" ? "the registration response" : "the metadata document"}.`
6693
+ );
6694
+ }
6695
+ const clientMetadataUrl = options.clientMetadataUrl?.trim() || void 0;
6696
+ if (clientMetadataUrl) {
6697
+ assertValidUrl3(clientMetadataUrl, "client metadata URL");
6698
+ if (strategy !== "cimd") {
6699
+ throw usageError(
6700
+ "--client-metadata-url is only valid with --registration cimd."
6701
+ );
6702
+ }
6703
+ }
6704
+ const clientAuth = options.clientAuth ?? "none";
6705
+ const cimdMetadataOrigin = options.cimdMetadataOrigin?.trim() || void 0;
6706
+ if (clientAuth === "private_key_jwt" && strategy !== "cimd") {
6707
+ throw usageError(
6708
+ "--client-auth private-key-jwt is only valid with --registration cimd."
6709
+ );
6710
+ }
6711
+ if (clientAuth === "private_key_jwt" && clientMetadataUrl) {
6712
+ throw usageError(
6713
+ "--client-metadata-url cannot be combined with --client-auth private-key-jwt: the confidential client publishes its own metadata document via the reflector."
6714
+ );
6715
+ }
6716
+ if (cimdMetadataOrigin) {
6717
+ assertValidUrl3(cimdMetadataOrigin, "CIMD metadata origin");
6718
+ if (clientAuth !== "private_key_jwt") {
6719
+ throw usageError(
6720
+ "--cimd-metadata-origin is only valid with --client-auth private-key-jwt."
6721
+ );
6722
+ }
6723
+ const parsed = new URL(cimdMetadataOrigin);
6724
+ if (parsed.pathname !== "/" || parsed.search || parsed.hash) {
6725
+ throw usageError(
6726
+ "--cimd-metadata-origin must be a bare origin (scheme + host[:port]) with no path, query, or fragment."
6727
+ );
6728
+ }
6729
+ }
6730
+ const authzServerIssuer = options.authzServerIssuer?.trim() || void 0;
6731
+ if (authzServerIssuer) {
6732
+ assertValidUrl3(authzServerIssuer, "authorization server issuer");
6733
+ }
6734
+ const tokenEndpoint = options.tokenEndpoint?.trim() || void 0;
6735
+ if (tokenEndpoint) {
6736
+ assertValidUrl3(tokenEndpoint, "token endpoint");
6737
+ if (isDynamic) {
6738
+ throw usageError(
6739
+ `--token-endpoint must not be set with --registration ${strategy}: it skips the authorization-server metadata discovery that ${strategy === "dcr" ? "DCR needs (registration_endpoint)" : "CIMD needs (client_id_metadata_document_supported)"}.`
6740
+ );
6741
+ }
6742
+ }
6743
+ if (timeoutMs !== void 0 && (!Number.isFinite(timeoutMs) || timeoutMs <= 0)) {
6744
+ throw usageError("--timeout must be a positive number.");
6745
+ }
6746
+ if (options.tokenEndpointAuthMethod !== "none" && options.tokenEndpointAuthMethod !== void 0 && !options.clientSecret) {
6747
+ throw usageError(
6748
+ `--token-endpoint-auth-method ${options.tokenEndpointAuthMethod} requires --client-secret.`
6749
+ );
6750
+ }
6751
+ return {
6752
+ serverUrl,
6753
+ issuerBaseUrl,
6754
+ subject,
6755
+ ...clientId ? { clientId } : {},
6756
+ ...strategy !== "preregistered" ? { registrationStrategy: strategy } : {},
6757
+ ...clientMetadataUrl ? { clientIdMetadataUrl: clientMetadataUrl } : {},
6758
+ ...clientAuth !== "none" ? { clientAuth } : {},
6759
+ ...cimdMetadataOrigin ? { cimdMetadataOrigin } : {},
6760
+ ...authzServerIssuer ? { authzServerIssuer } : {},
6761
+ ...tokenEndpoint ? { tokenEndpoint } : {},
6762
+ ...options.email?.trim() ? { email: options.email.trim() } : {},
6763
+ ...options.clientSecret ? { clientSecret: options.clientSecret } : {},
6764
+ ...options.tokenEndpointAuthMethod ? { tokenEndpointAuthMethod: options.tokenEndpointAuthMethod } : {},
6765
+ // --assertion-format is a PRESET setting both identity axes together:
6766
+ // "saml" mints a SAML 2.0 assertion AND a saml-nameid `sub_id` in the
6767
+ // ID-JAG. "oidc" (the default) leaves both fields unset so the SDK's own
6768
+ // defaults ("oidc" / "oauth-sub") apply, matching how the other optionals
6769
+ // preserve undefined. Programmatic users can still mix the axes on
6770
+ // XaaFlowConfig directly.
6771
+ ...options.assertionFormat === "saml" ? {
6772
+ identityAssertionFormat: "saml",
6773
+ subjectIdentifierFormat: "saml-nameid"
6774
+ } : {},
6775
+ ...options.scopes?.trim() ? { scope: options.scopes.trim() } : {},
6776
+ ...timeoutMs !== void 0 ? { timeoutMs } : {},
6777
+ httpsOnly: options.httpsOnly ?? false
6778
+ };
6779
+ }
6780
+ function parseRegistration(value) {
6781
+ const strategy = normalizeRegistrationStrategy(value);
6782
+ if (!strategy) {
6783
+ throw usageError(
6784
+ "--registration must be preregistered, dcr, or cimd."
6785
+ );
6786
+ }
6787
+ return strategy;
6788
+ }
6789
+ function isLoopbackHttpOrigin(origin) {
6790
+ try {
6791
+ const { protocol, hostname } = new URL(origin);
6792
+ return protocol === "http:" && isLoopbackHost(hostname);
6793
+ } catch {
6794
+ return false;
6795
+ }
6796
+ }
6797
+ function resolveConfidentialCimd(config, quiet) {
6798
+ if (config.clientAuth !== "private_key_jwt") return;
6799
+ const origin = config.cimdMetadataOrigin ?? XAA_CONFIDENTIAL_CIMD_ORIGIN;
6800
+ const loopback = isLoopbackHttpOrigin(origin);
6801
+ if (loopback && config.httpsOnly) {
6802
+ throw usageError(
6803
+ "--cimd-metadata-origin is an http loopback URL, but --https-only is set. Use an HTTPS origin, or drop --https-only for local dev."
6804
+ );
6805
+ }
6806
+ initXaaClientKeyPair();
6807
+ config.clientIdMetadataUrl = buildConfidentialCimdUrl(
6808
+ getXaaClientJwks().keys[0],
6809
+ origin
6810
+ );
6811
+ if (loopback) {
6812
+ config.allowLoopbackClientMetadata = true;
6813
+ if (!quiet) {
6814
+ process.stderr.write(
6815
+ `Note: using a loopback CIMD reflector (${origin}) \u2014 dev-only and non-standard (CIMD requires HTTPS); production uses ${XAA_CONFIDENTIAL_CIMD_ORIGIN}.
6816
+ `
6817
+ );
6818
+ }
6819
+ }
6820
+ }
6821
+ function parseClientAuth(value) {
6822
+ if (value === "none") return "none";
6823
+ if (value === "private-key-jwt" || value === "private_key_jwt")
6824
+ return "private_key_jwt";
6825
+ throw usageError("--client-auth must be none or private-key-jwt.");
6826
+ }
6827
+ function parseTokenEndpointAuthMethod(value) {
6828
+ if (value === "client_secret_basic" || value === "client_secret_post" || value === "none") {
6829
+ return value;
6830
+ }
6831
+ throw usageError(
6832
+ "--token-endpoint-auth-method must be client_secret_basic, client_secret_post, or none."
6833
+ );
6834
+ }
6835
+ function parseAssertionFormat(value) {
6836
+ const normalized = normalizeIdentityAssertionFormat(value);
6837
+ if (normalized) {
6838
+ return normalized;
6839
+ }
6840
+ throw usageError(
6841
+ `--assertion-format must be ${IDENTITY_ASSERTION_FORMATS.join(" or ")}.`
6842
+ );
6843
+ }
6844
+ function assertValidUrl3(value, label) {
6845
+ try {
6846
+ new URL(value);
6847
+ } catch {
6848
+ throw usageError(`Invalid ${label}: ${value}`);
6849
+ }
6850
+ }
6546
6851
  function registerPromptCommands(program) {
6547
6852
  const prompts = program.command("prompts").description("List and fetch MCP prompts");
6548
6853
  addHostOption(
@@ -9605,6 +9910,7 @@ async function main(argv = process.argv, dependencies = {}) {
9605
9910
  registerPromptCommands(program);
9606
9911
  registerAppsCommands(program);
9607
9912
  registerOAuthCommands(program);
9913
+ registerXaaCommands(program);
9608
9914
  registerProtocolCommands(program);
9609
9915
  registerAuthCommands(program);
9610
9916
  registerProjectsCommands(program);