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