@mcpjam/cli 3.3.1 → 3.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/dist/index.js +44 -84
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Command, CommanderError } from 'commander';
|
|
|
3
3
|
import { realpathSync, readFileSync, existsSync, closeSync, mkdirSync, writeFileSync, renameSync, statSync, openSync } from 'fs';
|
|
4
4
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
5
5
|
import { probeMcpServer, runServerDoctor, collectServerSnapshot, serializeStableServerSnapshot, serializeServerSnapshot, buildServerDiffReport, validateToolCallResult, isCallToolResultError, buildToolCallValidationReport, listResources, readResource, listPrompts, getPrompt, MCPAppsConformanceTest, MCPAppsConformanceSuite, runOAuthLogin, OAuthConformanceTest, OAuthConformanceSuite, MCPConformanceTest, MCPConformanceSuite, redactSensitiveValue, withEphemeralClient, diffServerSnapshots, ServerSnapshotFormatError, renderStructuredRunJUnitXml, renderStructuredRunJson, toConformanceReport, renderConformanceReportJUnitXml, renderConformanceReportJson, formatOAuthConformanceHuman, formatOAuthConformanceSuiteHuman, fetchOAuthMetadata, executeOAuthProxy, executeDebugOAuthProxy, MCP_APPS_CHECK_CATEGORIES, MCP_APPS_CHECK_IDS, OAuthProxyError, MCP_CHECK_CATEGORIES, MCP_CHECK_IDS } from '@mcpjam/sdk';
|
|
6
|
-
import { mkdir, writeFile,
|
|
6
|
+
import { mkdir, writeFile, readFile, chmod, rename, rm } from 'fs/promises';
|
|
7
7
|
import path2, { join, dirname } from 'path';
|
|
8
8
|
import { randomUUID } from 'crypto';
|
|
9
9
|
import { PostHog } from 'posthog-node';
|
|
@@ -12,7 +12,7 @@ import os, { homedir } from 'os';
|
|
|
12
12
|
|
|
13
13
|
// package.json
|
|
14
14
|
var package_default = {
|
|
15
|
-
version: "3.2
|
|
15
|
+
version: "3.3.2"};
|
|
16
16
|
|
|
17
17
|
// src/lib/output.ts
|
|
18
18
|
var DEFAULT_OUTPUT_FORMAT = "json";
|
|
@@ -1419,7 +1419,10 @@ async function writeCommandDebugArtifact(options, dependencies = {}) {
|
|
|
1419
1419
|
outcome: options.outcome,
|
|
1420
1420
|
snapshot: snapshotResult.snapshot,
|
|
1421
1421
|
snapshotError: snapshotResult.snapshotError,
|
|
1422
|
-
collectors: [
|
|
1422
|
+
collectors: [
|
|
1423
|
+
...options.collectors ?? [],
|
|
1424
|
+
options.snapshot?.collector
|
|
1425
|
+
]
|
|
1423
1426
|
});
|
|
1424
1427
|
const artifactPath = await writeDebugArtifact(options.outputPath, payload);
|
|
1425
1428
|
if (options.format === "human" && !options.quiet) {
|
|
@@ -1465,12 +1468,8 @@ async function writeDebugArtifact(outputPath, payload) {
|
|
|
1465
1468
|
resolvedPath,
|
|
1466
1469
|
`${JSON.stringify(redactedPayload, null, 2)}
|
|
1467
1470
|
`,
|
|
1468
|
-
|
|
1469
|
-
encoding: "utf8",
|
|
1470
|
-
mode: 384
|
|
1471
|
-
}
|
|
1471
|
+
"utf8"
|
|
1472
1472
|
);
|
|
1473
|
-
await chmod(resolvedPath, 384);
|
|
1474
1473
|
} catch (error) {
|
|
1475
1474
|
throw operationalError(
|
|
1476
1475
|
`Failed to write debug artifact to "${resolvedPath}".`,
|
|
@@ -1605,7 +1604,6 @@ function extractHeaders(headers) {
|
|
|
1605
1604
|
// src/commands/oauth.ts
|
|
1606
1605
|
var DYNAMIC_CLIENT_ID_PLACEHOLDER = "__dynamic_registration_client__";
|
|
1607
1606
|
var DYNAMIC_CLIENT_SECRET_PLACEHOLDER = "__dynamic_registration_secret__";
|
|
1608
|
-
var DEFAULT_OAUTH_STEP_TIMEOUT_MS = 12e4;
|
|
1609
1607
|
function getOAuthFormat(command) {
|
|
1610
1608
|
const opts = command.optsWithGlobals();
|
|
1611
1609
|
return resolveOAuthOutputFormat(opts.format, process.stdout.isTTY);
|
|
@@ -1622,28 +1620,6 @@ function writeOAuthOutput(output) {
|
|
|
1622
1620
|
process.stdout.write(output.endsWith("\n") ? output : `${output}
|
|
1623
1621
|
`);
|
|
1624
1622
|
}
|
|
1625
|
-
function createOAuthProgressReporter(quiet) {
|
|
1626
|
-
let wroteInlineProgress = false;
|
|
1627
|
-
return {
|
|
1628
|
-
onProgress(message) {
|
|
1629
|
-
if (quiet) {
|
|
1630
|
-
return;
|
|
1631
|
-
}
|
|
1632
|
-
if (process.stderr.isTTY) {
|
|
1633
|
-
wroteInlineProgress = true;
|
|
1634
|
-
process.stderr.write(`\r\x1B[K${message}`);
|
|
1635
|
-
return;
|
|
1636
|
-
}
|
|
1637
|
-
process.stderr.write(`${message}
|
|
1638
|
-
`);
|
|
1639
|
-
},
|
|
1640
|
-
clear() {
|
|
1641
|
-
if (!quiet && process.stderr.isTTY && wroteInlineProgress) {
|
|
1642
|
-
process.stderr.write("\r\x1B[K");
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
};
|
|
1646
|
-
}
|
|
1647
1623
|
function buildOAuthLoginDebugOutcome(options) {
|
|
1648
1624
|
if (options.commandError !== void 0) {
|
|
1649
1625
|
return {
|
|
@@ -1697,28 +1673,35 @@ function registerOAuthCommands(program) {
|
|
|
1697
1673
|
"--step-timeout <ms>",
|
|
1698
1674
|
"Per-step timeout in milliseconds",
|
|
1699
1675
|
(value) => parsePositiveInteger(value, "Step timeout"),
|
|
1700
|
-
|
|
1676
|
+
3e4
|
|
1701
1677
|
).option(
|
|
1702
1678
|
"--verify-tools",
|
|
1703
1679
|
"After OAuth succeeds, verify the token by listing MCP tools"
|
|
1704
1680
|
).option(
|
|
1705
1681
|
"--verify-call-tool <name>",
|
|
1706
1682
|
"After listing tools, also call the named tool"
|
|
1707
|
-
).option(
|
|
1683
|
+
).option(
|
|
1684
|
+
"--debug-out <path>",
|
|
1685
|
+
"Write a structured debug artifact to a file"
|
|
1686
|
+
).option(
|
|
1708
1687
|
"--credentials-out <path>",
|
|
1709
1688
|
"Write OAuth credentials to <path> (mode 0600); stdout output has secret fields redacted to [SAVED_TO_FILE]"
|
|
1710
|
-
).option(
|
|
1711
|
-
"--print-url",
|
|
1712
|
-
"In interactive mode, print the consent URL to stderr instead of launching a browser"
|
|
1713
1689
|
).action(async (options, command) => {
|
|
1714
1690
|
const globalOptions = getGlobalOptions(command);
|
|
1715
1691
|
const format = getOAuthFormat(command);
|
|
1716
|
-
const config = buildOAuthLoginConfig(
|
|
1717
|
-
|
|
1718
|
-
|
|
1692
|
+
const config = buildOAuthLoginConfig(
|
|
1693
|
+
options,
|
|
1694
|
+
{
|
|
1695
|
+
defaultAuthMode: "interactive"
|
|
1696
|
+
}
|
|
1697
|
+
);
|
|
1719
1698
|
const snapshotCollector = options.debugOut ? createCliRpcLogCollector({ __cli__: config.serverUrl }) : void 0;
|
|
1720
|
-
const
|
|
1721
|
-
|
|
1699
|
+
const isTTY = process.stderr.isTTY && !globalOptions.quiet;
|
|
1700
|
+
if (isTTY) {
|
|
1701
|
+
config.onProgress = (message) => {
|
|
1702
|
+
process.stderr.write(`\r\x1B[K${message}`);
|
|
1703
|
+
};
|
|
1704
|
+
}
|
|
1722
1705
|
let result;
|
|
1723
1706
|
let commandError;
|
|
1724
1707
|
try {
|
|
@@ -1726,7 +1709,9 @@ function registerOAuthCommands(program) {
|
|
|
1726
1709
|
} catch (error) {
|
|
1727
1710
|
commandError = error;
|
|
1728
1711
|
} finally {
|
|
1729
|
-
|
|
1712
|
+
if (isTTY) {
|
|
1713
|
+
process.stderr.write("\r\x1B[K");
|
|
1714
|
+
}
|
|
1730
1715
|
}
|
|
1731
1716
|
const snapshotConfig = buildOAuthLoginSnapshotConfig(config, result);
|
|
1732
1717
|
const target = summarizeServerDoctorTarget(
|
|
@@ -1737,20 +1722,14 @@ function registerOAuthCommands(program) {
|
|
|
1737
1722
|
let credentialsFileError;
|
|
1738
1723
|
if (commandError === void 0 && result && options.credentialsOut && hasCredentialsToSave(result)) {
|
|
1739
1724
|
try {
|
|
1740
|
-
progress.onProgress("Saving OAuth credentials...");
|
|
1741
1725
|
credentialsFilePath = await writeCredentialsFile(
|
|
1742
1726
|
options.credentialsOut,
|
|
1743
1727
|
result
|
|
1744
1728
|
);
|
|
1745
|
-
progress.onProgress(
|
|
1746
|
-
`OAuth credentials saved to ${credentialsFilePath}.`
|
|
1747
|
-
);
|
|
1748
1729
|
} catch (error) {
|
|
1749
1730
|
credentialsFileError = error;
|
|
1750
|
-
progress.onProgress("Failed to save OAuth credentials.");
|
|
1751
1731
|
}
|
|
1752
1732
|
}
|
|
1753
|
-
progress.clear();
|
|
1754
1733
|
await writeCommandDebugArtifact({
|
|
1755
1734
|
outputPath: options.debugOut,
|
|
1756
1735
|
format,
|
|
@@ -1769,7 +1748,7 @@ function registerOAuthCommands(program) {
|
|
|
1769
1748
|
input: {
|
|
1770
1749
|
config: snapshotConfig,
|
|
1771
1750
|
target,
|
|
1772
|
-
timeout: config.stepTimeout ??
|
|
1751
|
+
timeout: config.stepTimeout ?? 3e4
|
|
1773
1752
|
},
|
|
1774
1753
|
collector: snapshotCollector
|
|
1775
1754
|
} : void 0
|
|
@@ -1778,10 +1757,7 @@ function registerOAuthCommands(program) {
|
|
|
1778
1757
|
throw commandError;
|
|
1779
1758
|
}
|
|
1780
1759
|
if (!result) {
|
|
1781
|
-
throw cliError(
|
|
1782
|
-
"INTERNAL_ERROR",
|
|
1783
|
-
"OAuth login did not return a result."
|
|
1784
|
-
);
|
|
1760
|
+
throw cliError("INTERNAL_ERROR", "OAuth login did not return a result.");
|
|
1785
1761
|
}
|
|
1786
1762
|
if (options.credentialsOut) {
|
|
1787
1763
|
writeResult(
|
|
@@ -1820,7 +1796,7 @@ function registerOAuthCommands(program) {
|
|
|
1820
1796
|
"--step-timeout <ms>",
|
|
1821
1797
|
"Per-step timeout in milliseconds",
|
|
1822
1798
|
(value) => parsePositiveInteger(value, "Step timeout"),
|
|
1823
|
-
|
|
1799
|
+
3e4
|
|
1824
1800
|
).option(
|
|
1825
1801
|
"--verify-tools",
|
|
1826
1802
|
"After OAuth succeeds, verify the token by listing MCP tools"
|
|
@@ -1840,13 +1816,9 @@ function registerOAuthCommands(program) {
|
|
|
1840
1816
|
"--reporter <reporter>",
|
|
1841
1817
|
"Structured reporter output: json-summary or junit-xml"
|
|
1842
1818
|
).action(async (options, command) => {
|
|
1843
|
-
const reporter = parseReporterFormat(
|
|
1844
|
-
options.reporter
|
|
1845
|
-
);
|
|
1819
|
+
const reporter = parseReporterFormat(options.reporter);
|
|
1846
1820
|
const format = getOAuthConformanceFormat(command, reporter);
|
|
1847
|
-
const config = buildOAuthConformanceConfig(
|
|
1848
|
-
options
|
|
1849
|
-
);
|
|
1821
|
+
const config = buildOAuthConformanceConfig(options);
|
|
1850
1822
|
const result = await new OAuthConformanceTest(config).run();
|
|
1851
1823
|
let credentialsFilePath;
|
|
1852
1824
|
let credentialsFileError;
|
|
@@ -1887,9 +1859,7 @@ function registerOAuthCommands(program) {
|
|
|
1887
1859
|
"--reporter <reporter>",
|
|
1888
1860
|
"Structured reporter output: json-summary or junit-xml"
|
|
1889
1861
|
).action(async (options, command) => {
|
|
1890
|
-
const reporter = parseReporterFormat(
|
|
1891
|
-
options.reporter
|
|
1892
|
-
);
|
|
1862
|
+
const reporter = parseReporterFormat(options.reporter);
|
|
1893
1863
|
const format = getOAuthConformanceFormat(command, reporter);
|
|
1894
1864
|
const config = loadOAuthSuiteConfig(options.config);
|
|
1895
1865
|
if (options.verifyTools || options.verifyCallTool) {
|
|
@@ -1902,10 +1872,7 @@ function registerOAuthCommands(program) {
|
|
|
1902
1872
|
}
|
|
1903
1873
|
config.defaults = {
|
|
1904
1874
|
...config.defaults,
|
|
1905
|
-
verification: {
|
|
1906
|
-
...config.defaults?.verification,
|
|
1907
|
-
...cliVerification
|
|
1908
|
-
}
|
|
1875
|
+
verification: { ...config.defaults?.verification, ...cliVerification }
|
|
1909
1876
|
};
|
|
1910
1877
|
}
|
|
1911
1878
|
const suite = new OAuthConformanceSuite(config);
|
|
@@ -2030,12 +1997,7 @@ function buildOAuthConformanceConfig(options, defaults) {
|
|
|
2030
1997
|
listTools: options.verifyTools ?? !!options.verifyCallTool,
|
|
2031
1998
|
...options.verifyCallTool ? { callTool: { name: options.verifyCallTool } } : {}
|
|
2032
1999
|
} : void 0;
|
|
2033
|
-
const auth = buildAuthConfig(
|
|
2034
|
-
authMode,
|
|
2035
|
-
registrationStrategy,
|
|
2036
|
-
clientId,
|
|
2037
|
-
clientSecret
|
|
2038
|
-
);
|
|
2000
|
+
const auth = buildAuthConfig(authMode, registrationStrategy, clientId, clientSecret);
|
|
2039
2001
|
if (options.printUrl && auth.mode === "interactive") {
|
|
2040
2002
|
auth.openUrl = async (url) => {
|
|
2041
2003
|
process.stderr.write(`OAUTH_CONSENT_URL: ${url}
|
|
@@ -2051,7 +2013,7 @@ function buildOAuthConformanceConfig(options, defaults) {
|
|
|
2051
2013
|
scopes: options.scopes?.trim() || void 0,
|
|
2052
2014
|
customHeaders,
|
|
2053
2015
|
redirectUrl,
|
|
2054
|
-
stepTimeout: options.stepTimeout ??
|
|
2016
|
+
stepTimeout: options.stepTimeout ?? 3e4,
|
|
2055
2017
|
verification,
|
|
2056
2018
|
oauthConformanceChecks: options.conformanceChecks ?? false
|
|
2057
2019
|
};
|
|
@@ -2141,7 +2103,7 @@ function buildOAuthLoginConfig(options, defaults) {
|
|
|
2141
2103
|
scopes: options.scopes?.trim() || void 0,
|
|
2142
2104
|
customHeaders,
|
|
2143
2105
|
redirectUrl,
|
|
2144
|
-
stepTimeout: options.stepTimeout ??
|
|
2106
|
+
stepTimeout: options.stepTimeout ?? 3e4,
|
|
2145
2107
|
verification,
|
|
2146
2108
|
oauthConformanceChecks: false
|
|
2147
2109
|
};
|
|
@@ -2162,14 +2124,14 @@ function summarizeOAuthLoginCommandInput(options) {
|
|
|
2162
2124
|
hasClientSecret: Boolean(options.clientSecret),
|
|
2163
2125
|
verifyTools: options.verifyTools ?? false,
|
|
2164
2126
|
verifyCallTool: options.verifyCallTool ?? void 0,
|
|
2165
|
-
stepTimeout: options.stepTimeout ??
|
|
2127
|
+
stepTimeout: options.stepTimeout ?? 3e4
|
|
2166
2128
|
};
|
|
2167
2129
|
}
|
|
2168
2130
|
function buildOAuthLoginSnapshotConfig(config, result) {
|
|
2169
2131
|
const baseConfig = {
|
|
2170
2132
|
url: config.serverUrl,
|
|
2171
2133
|
...config.customHeaders ? { requestInit: { headers: config.customHeaders } } : {},
|
|
2172
|
-
timeout: config.stepTimeout ??
|
|
2134
|
+
timeout: config.stepTimeout ?? 3e4
|
|
2173
2135
|
};
|
|
2174
2136
|
if (!result) {
|
|
2175
2137
|
return baseConfig;
|
|
@@ -2220,9 +2182,7 @@ function parseProtocolVersion(value) {
|
|
|
2220
2182
|
return value;
|
|
2221
2183
|
}
|
|
2222
2184
|
throw usageError(
|
|
2223
|
-
`Invalid protocol version "${value}". Use ${[
|
|
2224
|
-
...VALID_PROTOCOL_VERSIONS
|
|
2225
|
-
].join(", ")}.`
|
|
2185
|
+
`Invalid protocol version "${value}". Use ${[...VALID_PROTOCOL_VERSIONS].join(", ")}.`
|
|
2226
2186
|
);
|
|
2227
2187
|
}
|
|
2228
2188
|
function parseRequiredProtocolVersion(value) {
|
|
@@ -2238,14 +2198,14 @@ function parseRegistrationStrategy(value) {
|
|
|
2238
2198
|
return value;
|
|
2239
2199
|
}
|
|
2240
2200
|
throw usageError(
|
|
2241
|
-
`Invalid registration strategy "${value}". Use ${[
|
|
2242
|
-
...VALID_REGISTRATION_STRATEGIES
|
|
2243
|
-
].join(", ")}.`
|
|
2201
|
+
`Invalid registration strategy "${value}". Use ${[...VALID_REGISTRATION_STRATEGIES].join(", ")}.`
|
|
2244
2202
|
);
|
|
2245
2203
|
}
|
|
2246
2204
|
function parseRequiredRegistrationStrategy(value) {
|
|
2247
2205
|
if (!value) {
|
|
2248
|
-
throw usageError(
|
|
2206
|
+
throw usageError(
|
|
2207
|
+
"--registration is required for oauth conformance flows."
|
|
2208
|
+
);
|
|
2249
2209
|
}
|
|
2250
2210
|
return parseRegistrationStrategy(value);
|
|
2251
2211
|
}
|