@alcyone-labs/arg-parser 2.3.0 → 2.4.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/README.md +433 -14
- package/dist/core/ArgParser.d.ts +73 -2
- package/dist/core/ArgParser.d.ts.map +1 -1
- package/dist/core/ArgParserBase.d.ts +6 -0
- package/dist/core/ArgParserBase.d.ts.map +1 -1
- package/dist/core/FlagManager.d.ts.map +1 -1
- package/dist/core/types.d.ts +36 -102
- package/dist/core/types.d.ts.map +1 -1
- package/dist/dxt/DxtGenerator.d.ts +58 -1
- package/dist/dxt/DxtGenerator.d.ts.map +1 -1
- package/dist/index.cjs +1962 -1527
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.min.mjs +6493 -6183
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +1962 -1527
- package/dist/index.mjs.map +1 -1
- package/dist/mcp/mcp-integration.d.ts.map +1 -1
- package/dist/mcp/mcp-lifecycle.d.ts +163 -0
- package/dist/mcp/mcp-lifecycle.d.ts.map +1 -0
- package/dist/mcp/mcp-utils.d.ts +20 -0
- package/dist/mcp/mcp-utils.d.ts.map +1 -0
- package/dist/mcp/zod-compatibility.d.ts +74 -0
- package/dist/mcp/zod-compatibility.d.ts.map +1 -0
- package/dist/utils/debug-utils.d.ts +40 -0
- package/dist/utils/debug-utils.d.ts.map +1 -0
- package/package.json +8 -7
package/dist/index.cjs
CHANGED
|
@@ -31,16 +31,17 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
31
31
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
32
32
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
33
33
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
34
|
-
var __flags, _throwForDuplicateFlags, _appName, _appCommandName, _subCommandName, _parameters, _handler, _throwForDuplicateFlags2, _description, _handleErrors, _autoExit, _parentParser, _lastParseResult, _inheritParentFlags, _subCommands, _flagManager, _dxtGenerator, _configurationManager, _fuzzyMode, _mcpResourcesManager, _mcpPromptsManager, _mcpNotificationsManager, _ArgParserBase_instances, _identifyCommandChainAndParsers_fn, _handleGlobalChecks_fn, _validateMandatoryFlags_fn, _applyDefaultValues_fn, _prepareAndExecuteHandler_fn, parseFlags_fn, _enableFuzzyMode_fn, displayErrorAndExit_fn, _printRecursiveToConsole_fn, _buildRecursiveString_fn, _buildRecursiveJson_fn, _handleSaveToEnvFlag_fn, _handleBuildDxtFlag_fn, _handleMcpServeFlag_fn, _getMcpServerConfiguration_fn, _startUnifiedMcpServer_fn, _findAllMcpSubCommands_fn, _parseMcpTransportOptions_fn, _ArgParser_instances, registerToolAsSubCommand_fn, _startSingleTransport_fn, processAsyncHandlerPromise_fn, _hasDate, _hasTime, _offset;
|
|
34
|
+
var __flags, _throwForDuplicateFlags, _appName, _appCommandName, _subCommandName, _parameters, _handler, _throwForDuplicateFlags2, _description, _handleErrors, _autoExit, _parentParser, _lastParseResult, _inheritParentFlags, _subCommands, _flagManager, _dxtGenerator, _configurationManager, _fuzzyMode, _mcpResourcesManager, _mcpPromptsManager, _mcpNotificationsManager, _ArgParserBase_instances, _identifyCommandChainAndParsers_fn, _handleGlobalChecks_fn, _validateMandatoryFlags_fn, _applyDefaultValues_fn, _prepareAndExecuteHandler_fn, parseFlags_fn, _enableFuzzyMode_fn, displayErrorAndExit_fn, _printRecursiveToConsole_fn, _buildRecursiveString_fn, _buildRecursiveJson_fn, _handleSaveToEnvFlag_fn, _handleBuildDxtFlag_fn, _handleMcpServeFlag_fn, _resolveLoggerConfigForServe_fn, _getMcpServerConfiguration_fn, _startUnifiedMcpServer_fn, _findAllMcpSubCommands_fn, _parseMcpTransportOptions_fn, _ArgParser_instances, _resolveLoggerConfig_fn, registerToolAsSubCommand_fn, _startSingleTransport_fn, processAsyncHandlerPromise_fn, _hasDate, _hasTime, _offset;
|
|
35
35
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
36
36
|
const fs = require("node:fs");
|
|
37
37
|
const path = require("node:path");
|
|
38
38
|
const magicRegexp = require("magic-regexp");
|
|
39
|
+
const getTsconfig = require("get-tsconfig");
|
|
39
40
|
const zod = require("zod");
|
|
40
41
|
const simpleMcpLogger = require("@alcyone-labs/simple-mcp-logger");
|
|
41
42
|
const process$1 = require("node:process");
|
|
42
43
|
const node_crypto = require("node:crypto");
|
|
43
|
-
const
|
|
44
|
+
const node_url = require("node:url");
|
|
44
45
|
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
45
46
|
function _interopNamespaceDefault(e) {
|
|
46
47
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
@@ -1084,7 +1085,7 @@ const zodFlagSchema = zod.z.object({
|
|
|
1084
1085
|
allowMultiple: zod.z.boolean().default(false).describe(
|
|
1085
1086
|
"Allow passing the same flag multiple times, e.g., `-f val1 -f val2` results in an array."
|
|
1086
1087
|
),
|
|
1087
|
-
description: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]).describe("Textual description for help messages."),
|
|
1088
|
+
description: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]).optional().describe("Textual description for help messages."),
|
|
1088
1089
|
options: zod.z.array(zod.z.string().min(1)).min(1, "Flag must have at least one option (e.g., ['-f', '--flag'])").describe("Array of option strings, e.g., ['-f', '--flag']."),
|
|
1089
1090
|
defaultValue: zod.z.any().optional().describe("Default value if the flag is not provided."),
|
|
1090
1091
|
type: zod.z.union([
|
|
@@ -1105,7 +1106,10 @@ const zodFlagSchema = zod.z.object({
|
|
|
1105
1106
|
// Native Object constructor
|
|
1106
1107
|
message: "Must be Object constructor"
|
|
1107
1108
|
}),
|
|
1108
|
-
zod.z.
|
|
1109
|
+
zod.z.custom(
|
|
1110
|
+
(val) => typeof val === "function",
|
|
1111
|
+
"Must be a custom parser function"
|
|
1112
|
+
),
|
|
1109
1113
|
// Custom parser function (value: string) => any | Promise<any>
|
|
1110
1114
|
zod.z.string().refine(
|
|
1111
1115
|
// String literal types
|
|
@@ -1119,24 +1123,26 @@ const zodFlagSchema = zod.z.object({
|
|
|
1119
1123
|
]).default("string").describe(
|
|
1120
1124
|
"Expected data type (constructor or string literal) or a custom parser function. Defaults to 'string'."
|
|
1121
1125
|
),
|
|
1122
|
-
mandatory: zod.z.union([
|
|
1126
|
+
mandatory: zod.z.union([
|
|
1127
|
+
zod.z.boolean(),
|
|
1128
|
+
zod.z.custom(
|
|
1129
|
+
(val) => typeof val === "function",
|
|
1130
|
+
"Must be a boolean or function"
|
|
1131
|
+
)
|
|
1132
|
+
]).optional().describe(
|
|
1123
1133
|
"Makes the flag mandatory, can be a boolean or a function conditional on other args."
|
|
1124
1134
|
),
|
|
1125
1135
|
flagOnly: zod.z.boolean().default(false).describe(
|
|
1126
1136
|
"If true, the flag's presence is noted (true/false), and any subsequent value is not consumed by this flag."
|
|
1127
1137
|
),
|
|
1128
|
-
validate: zod.z.
|
|
1129
|
-
zod.z.union([
|
|
1130
|
-
zod.z.boolean(),
|
|
1131
|
-
zod.z.string(),
|
|
1132
|
-
zod.z.void(),
|
|
1133
|
-
zod.z.promise(zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.void()]))
|
|
1134
|
-
])
|
|
1135
|
-
).optional().describe(
|
|
1138
|
+
validate: zod.z.custom((val) => typeof val === "function", "Must be a validation function").optional().describe(
|
|
1136
1139
|
"Custom validation function for the flag's value (receives value, parsedArgs)."
|
|
1137
1140
|
),
|
|
1138
|
-
enum: zod.z.array(zod.z.any()).optional().describe("Array of allowed values for the flag.")
|
|
1139
|
-
|
|
1141
|
+
enum: zod.z.array(zod.z.any()).optional().describe("Array of allowed values for the flag."),
|
|
1142
|
+
env: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]).optional().describe(
|
|
1143
|
+
"Environment variables that should be set from this flag's value in DXT packages."
|
|
1144
|
+
)
|
|
1145
|
+
}).transform((obj) => {
|
|
1140
1146
|
const newObj = { ...obj };
|
|
1141
1147
|
if ("default" in newObj && newObj["default"] !== void 0 && !("defaultValue" in newObj)) {
|
|
1142
1148
|
newObj["defaultValue"] = newObj["default"];
|
|
@@ -1629,8 +1635,9 @@ class DxtGenerator {
|
|
|
1629
1635
|
);
|
|
1630
1636
|
}
|
|
1631
1637
|
if (!fs__namespace.existsSync(logoPath)) {
|
|
1638
|
+
const currentDir2 = typeof process !== "undefined" ? process.cwd() : "/test";
|
|
1632
1639
|
logoPath = path__namespace.join(
|
|
1633
|
-
|
|
1640
|
+
currentDir2,
|
|
1634
1641
|
"docs",
|
|
1635
1642
|
"MCP",
|
|
1636
1643
|
"icons",
|
|
@@ -1638,8 +1645,9 @@ class DxtGenerator {
|
|
|
1638
1645
|
);
|
|
1639
1646
|
}
|
|
1640
1647
|
if (!fs__namespace.existsSync(logoPath)) {
|
|
1648
|
+
const currentDir2 = typeof process !== "undefined" ? process.cwd() : "/test";
|
|
1641
1649
|
logoPath = path__namespace.join(
|
|
1642
|
-
|
|
1650
|
+
currentDir2,
|
|
1643
1651
|
"node_modules",
|
|
1644
1652
|
"@alcyone-labs",
|
|
1645
1653
|
"arg-parser",
|
|
@@ -1649,8 +1657,9 @@ class DxtGenerator {
|
|
|
1649
1657
|
);
|
|
1650
1658
|
}
|
|
1651
1659
|
if (!fs__namespace.existsSync(logoPath)) {
|
|
1660
|
+
const currentDir2 = typeof process !== "undefined" ? process.cwd() : "/test";
|
|
1652
1661
|
logoPath = path__namespace.join(
|
|
1653
|
-
|
|
1662
|
+
currentDir2,
|
|
1654
1663
|
"dist",
|
|
1655
1664
|
"assets",
|
|
1656
1665
|
"logo_1_small.jpg"
|
|
@@ -1685,12 +1694,12 @@ class DxtGenerator {
|
|
|
1685
1694
|
* Builds a complete DXT package using TSDown CLI for autonomous execution
|
|
1686
1695
|
*/
|
|
1687
1696
|
async buildDxtWithTsdown(entryPointFile, outputDir = "./dxt", withNodeModules = false) {
|
|
1697
|
+
var _a, _b;
|
|
1688
1698
|
try {
|
|
1689
1699
|
console.log(simpleChalk.cyan("🔧 Building DXT package with TSDown..."));
|
|
1690
1700
|
const projectRoot = this.findProjectRoot(entryPointFile);
|
|
1691
1701
|
const absoluteEntryPath = path__namespace.resolve(entryPointFile);
|
|
1692
1702
|
const relativeEntryPath = path__namespace.relative(projectRoot, absoluteEntryPath);
|
|
1693
|
-
const entryFileName = path__namespace.basename(entryPointFile);
|
|
1694
1703
|
console.log(simpleChalk.gray(`Entry point: ${entryPointFile}`));
|
|
1695
1704
|
console.log(simpleChalk.gray(`Project root: ${projectRoot}`));
|
|
1696
1705
|
console.log(simpleChalk.gray(`Relative entry path: ${relativeEntryPath}`));
|
|
@@ -1707,9 +1716,8 @@ class DxtGenerator {
|
|
|
1707
1716
|
console.log(
|
|
1708
1717
|
logoFilename ? simpleChalk.gray(`✓ Logo prepared: ${logoFilename}`) : simpleChalk.gray("⚠ No logo available")
|
|
1709
1718
|
);
|
|
1710
|
-
const originalCwd = process.cwd();
|
|
1719
|
+
const originalCwd = typeof process !== "undefined" ? process.cwd() : "/test";
|
|
1711
1720
|
try {
|
|
1712
|
-
process.chdir(projectRoot);
|
|
1713
1721
|
const { build } = await import("tsdown");
|
|
1714
1722
|
console.log(simpleChalk.gray(`Building with TSDown: ${relativeEntryPath}`));
|
|
1715
1723
|
console.log(
|
|
@@ -1717,23 +1725,51 @@ class DxtGenerator {
|
|
|
1717
1725
|
`${withNodeModules ? "with node_modules" : "without node_modules"}`
|
|
1718
1726
|
)
|
|
1719
1727
|
);
|
|
1728
|
+
const mcpConfig = (_b = (_a = this.argParserInstance).getMcpServerConfig) == null ? void 0 : _b.call(_a);
|
|
1729
|
+
const entryDir = path__namespace.dirname(relativeEntryPath);
|
|
1730
|
+
const preservedOutDir = entryDir !== "." && entryDir !== "" ? path__namespace.resolve(originalCwd, outputDir, entryDir) : path__namespace.resolve(originalCwd, outputDir);
|
|
1720
1731
|
const buildConfig = {
|
|
1721
1732
|
entry: [relativeEntryPath],
|
|
1722
|
-
outDir:
|
|
1733
|
+
outDir: preservedOutDir,
|
|
1723
1734
|
format: ["es"],
|
|
1724
1735
|
target: "node22",
|
|
1725
1736
|
define: {
|
|
1726
1737
|
// Define any compile-time constants
|
|
1727
|
-
NODE_ENV:
|
|
1738
|
+
NODE_ENV: "production"
|
|
1728
1739
|
},
|
|
1740
|
+
dts: true,
|
|
1729
1741
|
minify: false,
|
|
1730
1742
|
sourcemap: false,
|
|
1731
1743
|
// Remove all output folders and artefacts
|
|
1732
1744
|
clean: [outputDir, "./.dxtignore", `${outputDir}.dxt`],
|
|
1733
1745
|
silent: process.env["NO_SILENCE"] !== "1",
|
|
1734
|
-
|
|
1735
|
-
|
|
1746
|
+
unbundle: true,
|
|
1747
|
+
external: (id, importer) => {
|
|
1748
|
+
const external = this.shouldModuleBeExternal(
|
|
1749
|
+
id,
|
|
1750
|
+
importer,
|
|
1751
|
+
withNodeModules
|
|
1752
|
+
);
|
|
1753
|
+
if (Boolean(process.env["DEBUG"]))
|
|
1754
|
+
console.log(
|
|
1755
|
+
`[${simpleChalk.blue("External")}] ${simpleChalk.yellow(external ? "true" : "false")} for module: (${simpleChalk.green(id)}), path: '${simpleChalk.grey(importer ?? "")}'`
|
|
1756
|
+
);
|
|
1757
|
+
return external;
|
|
1758
|
+
},
|
|
1759
|
+
noExternal: (id, importer) => {
|
|
1760
|
+
const external = this.shouldModuleBeExternal(
|
|
1761
|
+
id,
|
|
1762
|
+
importer,
|
|
1763
|
+
withNodeModules
|
|
1764
|
+
);
|
|
1765
|
+
if (Boolean(process.env["DEBUG"]))
|
|
1766
|
+
console.log(
|
|
1767
|
+
`[${simpleChalk.yellow("noExternal")}] ${simpleChalk.yellow(external === false ? "true" : "false")} for module: (${simpleChalk.green(id)}), path: '${simpleChalk.grey(importer ?? "")}'`
|
|
1768
|
+
);
|
|
1769
|
+
return external === false;
|
|
1770
|
+
},
|
|
1736
1771
|
copy: async (options) => {
|
|
1772
|
+
var _a2;
|
|
1737
1773
|
const outputPaths = [
|
|
1738
1774
|
"package.json"
|
|
1739
1775
|
];
|
|
@@ -1745,16 +1781,63 @@ class DxtGenerator {
|
|
|
1745
1781
|
);
|
|
1746
1782
|
outputPaths.push("node_modules");
|
|
1747
1783
|
}
|
|
1784
|
+
const dxtPackageRoot = entryDir !== "." && entryDir !== "" ? path__namespace.dirname(options.outDir) : options.outDir;
|
|
1748
1785
|
if (logoFilename) {
|
|
1749
|
-
const
|
|
1786
|
+
const currentDir = typeof process !== "undefined" ? process.cwd() : "/test";
|
|
1787
|
+
const logoPath = path__namespace.join(currentDir, logoFilename);
|
|
1750
1788
|
if (fs__namespace.existsSync(logoPath)) {
|
|
1751
1789
|
console.log(simpleChalk.gray(`Adding logo from: ${logoPath}`));
|
|
1752
1790
|
outputPaths.push({
|
|
1753
1791
|
from: logoPath,
|
|
1754
|
-
to: path__namespace.join(
|
|
1792
|
+
to: path__namespace.join(dxtPackageRoot, logoFilename)
|
|
1755
1793
|
});
|
|
1756
1794
|
}
|
|
1757
1795
|
}
|
|
1796
|
+
if ((_a2 = mcpConfig == null ? void 0 : mcpConfig.dxt) == null ? void 0 : _a2.include) {
|
|
1797
|
+
console.log(
|
|
1798
|
+
simpleChalk.gray(
|
|
1799
|
+
"📁 Including additional files from DXT configuration..."
|
|
1800
|
+
)
|
|
1801
|
+
);
|
|
1802
|
+
for (const includeItem of mcpConfig.dxt.include) {
|
|
1803
|
+
if (typeof includeItem === "string") {
|
|
1804
|
+
const sourcePath = path__namespace.resolve(projectRoot, includeItem);
|
|
1805
|
+
if (fs__namespace.existsSync(sourcePath)) {
|
|
1806
|
+
console.log(simpleChalk.gray(` • ${includeItem}`));
|
|
1807
|
+
outputPaths.push({
|
|
1808
|
+
from: sourcePath,
|
|
1809
|
+
to: path__namespace.join(dxtPackageRoot, includeItem)
|
|
1810
|
+
});
|
|
1811
|
+
} else {
|
|
1812
|
+
console.warn(
|
|
1813
|
+
simpleChalk.yellow(
|
|
1814
|
+
` ⚠ File not found: ${includeItem} (resolved to ${sourcePath})`
|
|
1815
|
+
)
|
|
1816
|
+
);
|
|
1817
|
+
}
|
|
1818
|
+
} else {
|
|
1819
|
+
const sourcePath = path__namespace.resolve(
|
|
1820
|
+
projectRoot,
|
|
1821
|
+
includeItem.from
|
|
1822
|
+
);
|
|
1823
|
+
if (fs__namespace.existsSync(sourcePath)) {
|
|
1824
|
+
console.log(
|
|
1825
|
+
simpleChalk.gray(` • ${includeItem.from} → ${includeItem.to}`)
|
|
1826
|
+
);
|
|
1827
|
+
outputPaths.push({
|
|
1828
|
+
from: sourcePath,
|
|
1829
|
+
to: path__namespace.join(dxtPackageRoot, includeItem.to)
|
|
1830
|
+
});
|
|
1831
|
+
} else {
|
|
1832
|
+
console.warn(
|
|
1833
|
+
simpleChalk.yellow(
|
|
1834
|
+
` ⚠ File not found: ${includeItem.from} (resolved to ${sourcePath})`
|
|
1835
|
+
)
|
|
1836
|
+
);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1758
1841
|
return outputPaths;
|
|
1759
1842
|
},
|
|
1760
1843
|
platform: "node",
|
|
@@ -1787,7 +1870,7 @@ export default ${JSON.stringify(buildConfig, null, 2)};
|
|
|
1787
1870
|
console.log(simpleChalk.green("✅ TSDown bundling completed"));
|
|
1788
1871
|
const detectedOutputFile = this.detectTsdownOutputFile(
|
|
1789
1872
|
outputDir,
|
|
1790
|
-
|
|
1873
|
+
relativeEntryPath.replace(/\.ts$/, ".js")
|
|
1791
1874
|
);
|
|
1792
1875
|
await this.setupDxtPackageFiles(
|
|
1793
1876
|
entryPointFile,
|
|
@@ -1811,7 +1894,160 @@ export default ${JSON.stringify(buildConfig, null, 2)};
|
|
|
1811
1894
|
}
|
|
1812
1895
|
}
|
|
1813
1896
|
/**
|
|
1814
|
-
*
|
|
1897
|
+
* Checks if a module ID is a Node.js built-in
|
|
1898
|
+
*/
|
|
1899
|
+
isNodeBuiltin(id) {
|
|
1900
|
+
const nodeBuiltins = [
|
|
1901
|
+
"stream",
|
|
1902
|
+
"fs",
|
|
1903
|
+
"path",
|
|
1904
|
+
"url",
|
|
1905
|
+
"util",
|
|
1906
|
+
"events",
|
|
1907
|
+
"child_process",
|
|
1908
|
+
"os",
|
|
1909
|
+
"tty",
|
|
1910
|
+
"process",
|
|
1911
|
+
"crypto",
|
|
1912
|
+
"http",
|
|
1913
|
+
"https",
|
|
1914
|
+
"net",
|
|
1915
|
+
"zlib",
|
|
1916
|
+
"fs/promises",
|
|
1917
|
+
"timers",
|
|
1918
|
+
"timers/promises",
|
|
1919
|
+
"perf_hooks",
|
|
1920
|
+
"async_hooks",
|
|
1921
|
+
"inspector",
|
|
1922
|
+
"v8",
|
|
1923
|
+
"vm",
|
|
1924
|
+
"assert",
|
|
1925
|
+
"constants",
|
|
1926
|
+
"module",
|
|
1927
|
+
"repl",
|
|
1928
|
+
"string_decoder",
|
|
1929
|
+
"punycode",
|
|
1930
|
+
"domain",
|
|
1931
|
+
"querystring",
|
|
1932
|
+
"readline",
|
|
1933
|
+
"worker_threads",
|
|
1934
|
+
"cluster",
|
|
1935
|
+
"dgram",
|
|
1936
|
+
"dns",
|
|
1937
|
+
"buffer"
|
|
1938
|
+
];
|
|
1939
|
+
return nodeBuiltins.includes(id) || id.startsWith("node:");
|
|
1940
|
+
}
|
|
1941
|
+
/**
|
|
1942
|
+
* Determines if a module should be treated as external based on bundling configuration.
|
|
1943
|
+
* This logic is shared between external and noExternal configurations.
|
|
1944
|
+
*
|
|
1945
|
+
* @param id - The module identifier (e.g., 'lodash', '@types/node', './utils')
|
|
1946
|
+
* @param importer - The file path that is importing this module (undefined for entry points)
|
|
1947
|
+
* @param withNodeModules - Whether to include node_modules in the bundle
|
|
1948
|
+
* @returns true if the module should be external (not bundled), false if it should be bundled
|
|
1949
|
+
*
|
|
1950
|
+
* Logic flow:
|
|
1951
|
+
* 1. Node built-ins (fs, path, etc.) are always external
|
|
1952
|
+
* 2. If no importer (entry point), always bundle
|
|
1953
|
+
* 3. If withNodeModules is false, bundle everything except Node built-ins
|
|
1954
|
+
* 4. If withNodeModules is true:
|
|
1955
|
+
* - If importer is from node_modules, make external
|
|
1956
|
+
* - If module resolves to a project file (via TS paths or regular paths), bundle it
|
|
1957
|
+
* - Otherwise, make external (likely npm package)
|
|
1958
|
+
*
|
|
1959
|
+
* @example
|
|
1960
|
+
* // Node built-in - always external
|
|
1961
|
+
* shouldModuleBeExternal('fs', './src/main.ts', true) // returns true
|
|
1962
|
+
*
|
|
1963
|
+
* // Project file via TS paths or regular paths - bundle it
|
|
1964
|
+
* shouldModuleBeExternal('@/utils', './src/main.ts', true) // returns false
|
|
1965
|
+
*
|
|
1966
|
+
* // NPM package - external when withNodeModules=true
|
|
1967
|
+
* shouldModuleBeExternal('lodash', './src/main.ts', true) // returns true
|
|
1968
|
+
*/
|
|
1969
|
+
shouldModuleBeExternal(id, importer, withNodeModules) {
|
|
1970
|
+
if (this.isNodeBuiltin(id)) {
|
|
1971
|
+
return true;
|
|
1972
|
+
}
|
|
1973
|
+
if (importer) {
|
|
1974
|
+
if (withNodeModules) {
|
|
1975
|
+
if (importer.includes("node_modules")) {
|
|
1976
|
+
return true;
|
|
1977
|
+
} else {
|
|
1978
|
+
const resolvedPath = this.resolveModulePath(id, importer);
|
|
1979
|
+
if (resolvedPath) {
|
|
1980
|
+
return false;
|
|
1981
|
+
} else {
|
|
1982
|
+
return true;
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
} else {
|
|
1986
|
+
return false;
|
|
1987
|
+
}
|
|
1988
|
+
} else {
|
|
1989
|
+
return false;
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* Checks if a package ID exists in the local node_modules folder.
|
|
1994
|
+
* Only checks the folder or parent folder that contains the nearest package.json file.
|
|
1995
|
+
* Returns false if no package.json file is found after 3 parent directory traversals.
|
|
1996
|
+
*
|
|
1997
|
+
* Alternative approach using require.resolve():
|
|
1998
|
+
* ```ts
|
|
1999
|
+
* public isNodeModulesPackageWithResolve(packageId: string): boolean {
|
|
2000
|
+
* try {
|
|
2001
|
+
* require.resolve(packageId);
|
|
2002
|
+
* return true;
|
|
2003
|
+
* } catch {
|
|
2004
|
+
* return false;
|
|
2005
|
+
* }
|
|
2006
|
+
* }
|
|
2007
|
+
* ```
|
|
2008
|
+
*
|
|
2009
|
+
* Filesystem approach is preferred for bundler context because:
|
|
2010
|
+
* - Faster (no module resolution overhead)
|
|
2011
|
+
* - No side effects during build
|
|
2012
|
+
* - Predictable behavior in build vs runtime contexts
|
|
2013
|
+
*/
|
|
2014
|
+
isNodeModulesPackage(packageId) {
|
|
2015
|
+
try {
|
|
2016
|
+
const currentDir = typeof process !== "undefined" ? process.cwd() : "/test";
|
|
2017
|
+
let searchDir = currentDir;
|
|
2018
|
+
let attempts = 0;
|
|
2019
|
+
const maxAttempts = 3;
|
|
2020
|
+
while (attempts < maxAttempts) {
|
|
2021
|
+
const packageJsonPath = path__namespace.join(searchDir, "package.json");
|
|
2022
|
+
if (fs__namespace.existsSync(packageJsonPath)) {
|
|
2023
|
+
const nodeModulesPath = path__namespace.join(searchDir, "node_modules");
|
|
2024
|
+
if (!fs__namespace.existsSync(nodeModulesPath)) {
|
|
2025
|
+
return false;
|
|
2026
|
+
}
|
|
2027
|
+
const packagePath = path__namespace.join(nodeModulesPath, packageId);
|
|
2028
|
+
if (fs__namespace.existsSync(packagePath)) {
|
|
2029
|
+
const packagePackageJsonPath = path__namespace.join(
|
|
2030
|
+
packagePath,
|
|
2031
|
+
"package.json"
|
|
2032
|
+
);
|
|
2033
|
+
return fs__namespace.existsSync(packagePackageJsonPath);
|
|
2034
|
+
}
|
|
2035
|
+
return false;
|
|
2036
|
+
}
|
|
2037
|
+
const parentDir = path__namespace.dirname(searchDir);
|
|
2038
|
+
if (parentDir === searchDir) {
|
|
2039
|
+
break;
|
|
2040
|
+
}
|
|
2041
|
+
searchDir = parentDir;
|
|
2042
|
+
attempts++;
|
|
2043
|
+
}
|
|
2044
|
+
return false;
|
|
2045
|
+
} catch (error) {
|
|
2046
|
+
return false;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
/**
|
|
2050
|
+
* Get the path to the .dxtignore template file
|
|
1815
2051
|
*/
|
|
1816
2052
|
getDxtIgnoreTemplatePath() {
|
|
1817
2053
|
const possiblePaths = [
|
|
@@ -1824,7 +2060,7 @@ export default ${JSON.stringify(buildConfig, null, 2)};
|
|
|
1824
2060
|
),
|
|
1825
2061
|
// 2. From node_modules/@alcyone-labs/arg-parser/dist/assets (when installed via npm)
|
|
1826
2062
|
path__namespace.join(
|
|
1827
|
-
process.cwd(),
|
|
2063
|
+
typeof process !== "undefined" ? process.cwd() : "/test",
|
|
1828
2064
|
"node_modules",
|
|
1829
2065
|
"@alcyone-labs",
|
|
1830
2066
|
"arg-parser",
|
|
@@ -1833,9 +2069,9 @@ export default ${JSON.stringify(buildConfig, null, 2)};
|
|
|
1833
2069
|
".dxtignore.template"
|
|
1834
2070
|
),
|
|
1835
2071
|
// 3. From the root directory (development/local build)
|
|
1836
|
-
path__namespace.join(process.cwd(), ".dxtignore.template"),
|
|
2072
|
+
path__namespace.join(typeof process !== "undefined" ? process.cwd() : "/test", ".dxtignore.template"),
|
|
1837
2073
|
// 4. From the library root (when using local file dependency)
|
|
1838
|
-
path__namespace.join(process.cwd(), "..", "..", "..", ".dxtignore.template")
|
|
2074
|
+
path__namespace.join(typeof process !== "undefined" ? process.cwd() : "/test", "..", "..", "..", ".dxtignore.template")
|
|
1839
2075
|
];
|
|
1840
2076
|
for (const ignorePath of possiblePaths) {
|
|
1841
2077
|
if (fs__namespace.existsSync(ignorePath)) {
|
|
@@ -1851,11 +2087,12 @@ export default ${JSON.stringify(buildConfig, null, 2)};
|
|
|
1851
2087
|
*/
|
|
1852
2088
|
async setupDxtPackageFiles(entryPointFile, outputDir = "./dxt", actualOutputFilename, logoFilename = "logo.jpg") {
|
|
1853
2089
|
var _a, _b, _c, _d, _e, _f;
|
|
1854
|
-
const
|
|
2090
|
+
const currentDir = typeof process !== "undefined" ? process.cwd() : "/test";
|
|
2091
|
+
const dxtDir = path__namespace.resolve(currentDir, outputDir);
|
|
1855
2092
|
if (!fs__namespace.existsSync(dxtDir)) {
|
|
1856
2093
|
throw new Error(`TSDown output directory (${outputDir}) not found`);
|
|
1857
2094
|
}
|
|
1858
|
-
const packageJsonPath = path__namespace.join(
|
|
2095
|
+
const packageJsonPath = path__namespace.join(currentDir, "package.json");
|
|
1859
2096
|
let packageInfo = {};
|
|
1860
2097
|
if (fs__namespace.existsSync(packageJsonPath)) {
|
|
1861
2098
|
try {
|
|
@@ -1960,16 +2197,41 @@ export default ${JSON.stringify(buildConfig, null, 2)};
|
|
|
1960
2197
|
*/
|
|
1961
2198
|
detectTsdownOutputFile(outputDir, expectedBaseName) {
|
|
1962
2199
|
try {
|
|
1963
|
-
|
|
2200
|
+
let findJsFiles = function(dir, relativePath = "") {
|
|
2201
|
+
const entries = fs__namespace.readdirSync(dir, { withFileTypes: true });
|
|
2202
|
+
for (const entry of entries) {
|
|
2203
|
+
const fullPath = path__namespace.join(dir, entry.name);
|
|
2204
|
+
const relativeFilePath = path__namespace.join(relativePath, entry.name);
|
|
2205
|
+
if (entry.isDirectory()) {
|
|
2206
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) {
|
|
2207
|
+
continue;
|
|
2208
|
+
}
|
|
2209
|
+
findJsFiles(fullPath, relativeFilePath);
|
|
2210
|
+
} else if ((entry.name.endsWith(".js") || entry.name.endsWith(".mjs")) && !entry.name.includes("chunk-") && !entry.name.includes("dist-") && !entry.name.startsWith(".")) {
|
|
2211
|
+
files.push(relativeFilePath);
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
};
|
|
2215
|
+
const currentDir = typeof process !== "undefined" ? process.cwd() : "/test";
|
|
2216
|
+
const dxtDir = path__namespace.resolve(currentDir, outputDir);
|
|
1964
2217
|
if (!fs__namespace.existsSync(dxtDir)) {
|
|
1965
2218
|
console.warn(
|
|
1966
2219
|
simpleChalk.yellow(`⚠ Output directory (${outputDir}) not found`)
|
|
1967
2220
|
);
|
|
1968
2221
|
return null;
|
|
1969
2222
|
}
|
|
1970
|
-
const files =
|
|
1971
|
-
|
|
1972
|
-
);
|
|
2223
|
+
const files = [];
|
|
2224
|
+
findJsFiles(dxtDir);
|
|
2225
|
+
const expectedJsFile = expectedBaseName.endsWith(".js") ? expectedBaseName : expectedBaseName.replace(/\.ts$/, ".js");
|
|
2226
|
+
const expectedMjsFile = expectedBaseName.endsWith(".mjs") ? expectedBaseName : expectedBaseName.replace(/\.ts$/, ".mjs");
|
|
2227
|
+
if (files.includes(expectedJsFile)) {
|
|
2228
|
+
console.log(simpleChalk.gray(`✓ Detected TSDown output: ${expectedJsFile}`));
|
|
2229
|
+
return expectedJsFile;
|
|
2230
|
+
}
|
|
2231
|
+
if (files.includes(expectedMjsFile)) {
|
|
2232
|
+
console.log(simpleChalk.gray(`✓ Detected TSDown output: ${expectedMjsFile}`));
|
|
2233
|
+
return expectedMjsFile;
|
|
2234
|
+
}
|
|
1973
2235
|
const baseNameWithoutExt = path__namespace.parse(expectedBaseName).name;
|
|
1974
2236
|
for (const ext of [".js", ".mjs"]) {
|
|
1975
2237
|
const exactMatch = `${baseNameWithoutExt}${ext}`;
|
|
@@ -2046,6 +2308,19 @@ export default ${JSON.stringify(buildConfig, null, 2)};
|
|
|
2046
2308
|
generateEnvAndUserConfig() {
|
|
2047
2309
|
const envVars = {};
|
|
2048
2310
|
const userConfig = {};
|
|
2311
|
+
const shouldBeRequired = (flag) => {
|
|
2312
|
+
if (typeof flag.mandatory === "boolean") {
|
|
2313
|
+
return flag.mandatory;
|
|
2314
|
+
}
|
|
2315
|
+
if (typeof flag.mandatory === "function") {
|
|
2316
|
+
return false;
|
|
2317
|
+
}
|
|
2318
|
+
return false;
|
|
2319
|
+
};
|
|
2320
|
+
const shouldBeSensitive = (flag) => {
|
|
2321
|
+
const envVar = flag.env || flag.envVar;
|
|
2322
|
+
return !!envVar;
|
|
2323
|
+
};
|
|
2049
2324
|
const mainFlags = this.argParserInstance.flags;
|
|
2050
2325
|
for (const flag of mainFlags) {
|
|
2051
2326
|
const envVar = flag.env || flag.envVar;
|
|
@@ -2055,10 +2330,10 @@ export default ${JSON.stringify(buildConfig, null, 2)};
|
|
|
2055
2330
|
type: "string",
|
|
2056
2331
|
title: envVar.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()),
|
|
2057
2332
|
description: flag.description || `${envVar} environment variable`,
|
|
2058
|
-
required:
|
|
2059
|
-
//
|
|
2060
|
-
sensitive:
|
|
2061
|
-
//
|
|
2333
|
+
required: shouldBeRequired(flag),
|
|
2334
|
+
// Respect the flag's mandatory setting
|
|
2335
|
+
sensitive: shouldBeSensitive(flag)
|
|
2336
|
+
// Set to sensitive if tied to ENV
|
|
2062
2337
|
};
|
|
2063
2338
|
}
|
|
2064
2339
|
}
|
|
@@ -2074,10 +2349,10 @@ export default ${JSON.stringify(buildConfig, null, 2)};
|
|
|
2074
2349
|
type: "string",
|
|
2075
2350
|
title: envVar.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()),
|
|
2076
2351
|
description: flag.description || `${envVar} environment variable`,
|
|
2077
|
-
required:
|
|
2078
|
-
//
|
|
2079
|
-
sensitive:
|
|
2080
|
-
//
|
|
2352
|
+
required: shouldBeRequired(flag),
|
|
2353
|
+
// Respect the flag's mandatory setting
|
|
2354
|
+
sensitive: shouldBeSensitive(flag)
|
|
2355
|
+
// Set to sensitive if tied to ENV
|
|
2081
2356
|
};
|
|
2082
2357
|
}
|
|
2083
2358
|
}
|
|
@@ -2085,6 +2360,176 @@ export default ${JSON.stringify(buildConfig, null, 2)};
|
|
|
2085
2360
|
}
|
|
2086
2361
|
return { envVars, userConfig };
|
|
2087
2362
|
}
|
|
2363
|
+
resolveModulePath(id, importer) {
|
|
2364
|
+
var _a;
|
|
2365
|
+
try {
|
|
2366
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2367
|
+
console.log(
|
|
2368
|
+
` <${simpleChalk.gray("module-resolve")}> Resolving '${simpleChalk.green(id)}' from '${simpleChalk.gray(importer)}'`
|
|
2369
|
+
);
|
|
2370
|
+
}
|
|
2371
|
+
const tsconfig = getTsconfig.getTsconfig(importer);
|
|
2372
|
+
if (!((_a = tsconfig == null ? void 0 : tsconfig.config.compilerOptions) == null ? void 0 : _a.paths)) {
|
|
2373
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2374
|
+
console.log(
|
|
2375
|
+
` <${simpleChalk.gray("ts-paths")}> No tsconfig or paths found for '${importer}'`
|
|
2376
|
+
);
|
|
2377
|
+
}
|
|
2378
|
+
} else {
|
|
2379
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2380
|
+
const currentDir = typeof process !== "undefined" ? process.cwd() : "/test";
|
|
2381
|
+
console.log(
|
|
2382
|
+
` <${simpleChalk.gray("ts-paths")}> Found tsconfig at '${path__namespace.relative(currentDir, tsconfig.path)}' with paths:`,
|
|
2383
|
+
Object.keys(tsconfig.config.compilerOptions.paths)
|
|
2384
|
+
);
|
|
2385
|
+
}
|
|
2386
|
+
const pathsMatcher = getTsconfig.createPathsMatcher(tsconfig);
|
|
2387
|
+
if (!pathsMatcher) {
|
|
2388
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2389
|
+
console.log(
|
|
2390
|
+
` <${simpleChalk.gray("ts-paths")}> Failed to create paths matcher`
|
|
2391
|
+
);
|
|
2392
|
+
}
|
|
2393
|
+
} else {
|
|
2394
|
+
const possiblePaths = pathsMatcher(id);
|
|
2395
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2396
|
+
console.log(
|
|
2397
|
+
` <${simpleChalk.grey("ts-paths")}> Possible paths for '${id}':`,
|
|
2398
|
+
possiblePaths
|
|
2399
|
+
);
|
|
2400
|
+
}
|
|
2401
|
+
for (const possiblePath of possiblePaths) {
|
|
2402
|
+
const resolvedPath = path__namespace.resolve(
|
|
2403
|
+
path__namespace.dirname(tsconfig.path),
|
|
2404
|
+
possiblePath
|
|
2405
|
+
);
|
|
2406
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2407
|
+
console.log(
|
|
2408
|
+
` <${simpleChalk.grey("ts-paths")}> Trying resolved path: '${resolvedPath}'`
|
|
2409
|
+
);
|
|
2410
|
+
}
|
|
2411
|
+
const extensions2 = [".ts", ".js", ".tsx", ".jsx", ".mjs", ".cjs"];
|
|
2412
|
+
if (fs__namespace.existsSync(resolvedPath) && fs__namespace.statSync(resolvedPath).isFile()) {
|
|
2413
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2414
|
+
console.log(
|
|
2415
|
+
` <${simpleChalk.grey("ts-paths")}> ✓ Resolved '${id}' to '${resolvedPath}'`
|
|
2416
|
+
);
|
|
2417
|
+
}
|
|
2418
|
+
return resolvedPath;
|
|
2419
|
+
}
|
|
2420
|
+
if (resolvedPath.endsWith(".js")) {
|
|
2421
|
+
const basePath = resolvedPath.slice(0, -3);
|
|
2422
|
+
for (const ext of [".ts", ".tsx"]) {
|
|
2423
|
+
const testPath2 = basePath + ext;
|
|
2424
|
+
if (fs__namespace.existsSync(testPath2) && fs__namespace.statSync(testPath2).isFile()) {
|
|
2425
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2426
|
+
console.log(
|
|
2427
|
+
` <${simpleChalk.grey("ts-paths")}> ✓ Resolved '${id}' to '${testPath2}' (replaced .js)`
|
|
2428
|
+
);
|
|
2429
|
+
}
|
|
2430
|
+
return testPath2;
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
for (const ext of extensions2) {
|
|
2435
|
+
const testPath2 = resolvedPath + ext;
|
|
2436
|
+
if (fs__namespace.existsSync(testPath2) && fs__namespace.statSync(testPath2).isFile()) {
|
|
2437
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2438
|
+
console.log(
|
|
2439
|
+
` <${simpleChalk.grey("ts-paths")}> ✓ Resolved '${id}' to '${testPath2}' (added extension)`
|
|
2440
|
+
);
|
|
2441
|
+
}
|
|
2442
|
+
return testPath2;
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
if (fs__namespace.existsSync(resolvedPath) && fs__namespace.statSync(resolvedPath).isDirectory()) {
|
|
2446
|
+
for (const ext of extensions2) {
|
|
2447
|
+
const indexPath = path__namespace.join(resolvedPath, `index${ext}`);
|
|
2448
|
+
if (fs__namespace.existsSync(indexPath)) {
|
|
2449
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2450
|
+
console.log(
|
|
2451
|
+
` <${simpleChalk.grey("ts-paths")}> ✓ Resolved '${id}' to '${indexPath}' (index)`
|
|
2452
|
+
);
|
|
2453
|
+
}
|
|
2454
|
+
return indexPath;
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2462
|
+
console.log(
|
|
2463
|
+
` <${simpleChalk.gray("file-resolve")}> Trying regular file resolution for '${id}'`
|
|
2464
|
+
);
|
|
2465
|
+
}
|
|
2466
|
+
let testPath;
|
|
2467
|
+
if (path__namespace.isAbsolute(id)) {
|
|
2468
|
+
testPath = id;
|
|
2469
|
+
} else {
|
|
2470
|
+
testPath = path__namespace.resolve(path__namespace.dirname(importer), id);
|
|
2471
|
+
}
|
|
2472
|
+
const extensions = [".ts", ".js", ".tsx", ".jsx", ".mjs", ".cjs"];
|
|
2473
|
+
if (fs__namespace.existsSync(testPath) && fs__namespace.statSync(testPath).isFile()) {
|
|
2474
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2475
|
+
console.log(
|
|
2476
|
+
` <${simpleChalk.gray("file-resolve")}> ✓ Resolved '${id}' to '${testPath}'`
|
|
2477
|
+
);
|
|
2478
|
+
}
|
|
2479
|
+
return testPath;
|
|
2480
|
+
}
|
|
2481
|
+
if (testPath.endsWith(".js")) {
|
|
2482
|
+
const basePath = testPath.slice(0, -3);
|
|
2483
|
+
for (const ext of [".ts", ".tsx"]) {
|
|
2484
|
+
const tsPath = basePath + ext;
|
|
2485
|
+
if (fs__namespace.existsSync(tsPath) && fs__namespace.statSync(tsPath).isFile()) {
|
|
2486
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2487
|
+
console.log(
|
|
2488
|
+
` <${simpleChalk.gray("file-resolve")}> ✓ Resolved '${id}' to '${tsPath}' (replaced .js)`
|
|
2489
|
+
);
|
|
2490
|
+
}
|
|
2491
|
+
return tsPath;
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
for (const ext of extensions) {
|
|
2496
|
+
const extPath = testPath + ext;
|
|
2497
|
+
if (fs__namespace.existsSync(extPath) && fs__namespace.statSync(extPath).isFile()) {
|
|
2498
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2499
|
+
console.log(
|
|
2500
|
+
` <${simpleChalk.gray("file-resolve")}> ✓ Resolved '${id}' to '${extPath}' (added extension)`
|
|
2501
|
+
);
|
|
2502
|
+
}
|
|
2503
|
+
return extPath;
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
if (fs__namespace.existsSync(testPath) && fs__namespace.statSync(testPath).isDirectory()) {
|
|
2507
|
+
for (const ext of extensions) {
|
|
2508
|
+
const indexPath = path__namespace.join(testPath, `index${ext}`);
|
|
2509
|
+
if (fs__namespace.existsSync(indexPath)) {
|
|
2510
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2511
|
+
console.log(
|
|
2512
|
+
` <${simpleChalk.gray("file-resolve")}> ✓ Resolved '${id}' to '${indexPath}' (index)`
|
|
2513
|
+
);
|
|
2514
|
+
}
|
|
2515
|
+
return indexPath;
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
if (Boolean(process.env["DEBUG"])) {
|
|
2520
|
+
console.log(
|
|
2521
|
+
` <${simpleChalk.gray("module-resolve")}> ✗ Could not resolve '${id}'`
|
|
2522
|
+
);
|
|
2523
|
+
}
|
|
2524
|
+
} catch (error) {
|
|
2525
|
+
console.warn(
|
|
2526
|
+
simpleChalk.yellow(
|
|
2527
|
+
`Warning: Failed to resolve module path '${id}': ${error}`
|
|
2528
|
+
)
|
|
2529
|
+
);
|
|
2530
|
+
}
|
|
2531
|
+
return null;
|
|
2532
|
+
}
|
|
2088
2533
|
}
|
|
2089
2534
|
class McpNotificationsManager {
|
|
2090
2535
|
constructor() {
|
|
@@ -2556,6 +3001,61 @@ class McpResourcesManager {
|
|
|
2556
3001
|
}
|
|
2557
3002
|
}
|
|
2558
3003
|
}
|
|
3004
|
+
const isDebugEnabled = () => {
|
|
3005
|
+
try {
|
|
3006
|
+
return Boolean(typeof process !== "undefined" && process.env && process.env["DEBUG"]);
|
|
3007
|
+
} catch {
|
|
3008
|
+
return false;
|
|
3009
|
+
}
|
|
3010
|
+
};
|
|
3011
|
+
const debug = {
|
|
3012
|
+
/**
|
|
3013
|
+
* Log a debug message to stderr (only when DEBUG=true)
|
|
3014
|
+
*/
|
|
3015
|
+
log: (...args) => {
|
|
3016
|
+
if (isDebugEnabled()) {
|
|
3017
|
+
console.error("[DEBUG]", ...args);
|
|
3018
|
+
}
|
|
3019
|
+
},
|
|
3020
|
+
/**
|
|
3021
|
+
* Log an error debug message to stderr (only when DEBUG=true)
|
|
3022
|
+
*/
|
|
3023
|
+
error: (...args) => {
|
|
3024
|
+
if (isDebugEnabled()) {
|
|
3025
|
+
console.error("[DEBUG ERROR]", ...args);
|
|
3026
|
+
}
|
|
3027
|
+
},
|
|
3028
|
+
/**
|
|
3029
|
+
* Log a warning debug message to stderr (only when DEBUG=true)
|
|
3030
|
+
*/
|
|
3031
|
+
warn: (...args) => {
|
|
3032
|
+
if (isDebugEnabled()) {
|
|
3033
|
+
console.error("[DEBUG WARN]", ...args);
|
|
3034
|
+
}
|
|
3035
|
+
},
|
|
3036
|
+
/**
|
|
3037
|
+
* Log an info debug message to stderr (only when DEBUG=true)
|
|
3038
|
+
*/
|
|
3039
|
+
info: (...args) => {
|
|
3040
|
+
if (isDebugEnabled()) {
|
|
3041
|
+
console.error("[DEBUG INFO]", ...args);
|
|
3042
|
+
}
|
|
3043
|
+
},
|
|
3044
|
+
/**
|
|
3045
|
+
* Log a debug message with a custom prefix (only when DEBUG=true)
|
|
3046
|
+
*/
|
|
3047
|
+
prefixed: (prefix, ...args) => {
|
|
3048
|
+
if (isDebugEnabled()) {
|
|
3049
|
+
console.error(`[DEBUG ${prefix}]`, ...args);
|
|
3050
|
+
}
|
|
3051
|
+
},
|
|
3052
|
+
/**
|
|
3053
|
+
* Check if debug mode is currently enabled
|
|
3054
|
+
*/
|
|
3055
|
+
get enabled() {
|
|
3056
|
+
return isDebugEnabled();
|
|
3057
|
+
}
|
|
3058
|
+
};
|
|
2559
3059
|
const _FlagManager = class _FlagManager {
|
|
2560
3060
|
constructor(options = {}, initialFlags = []) {
|
|
2561
3061
|
__privateAdd(this, __flags, /* @__PURE__ */ new Map());
|
|
@@ -2596,7 +3096,8 @@ const _FlagManager = class _FlagManager {
|
|
|
2596
3096
|
type: resolvedType,
|
|
2597
3097
|
validate: parsedFromZod["validate"],
|
|
2598
3098
|
enum: parsedFromZod["enum"],
|
|
2599
|
-
mandatory: parsedFromZod["mandatory"]
|
|
3099
|
+
mandatory: parsedFromZod["mandatory"],
|
|
3100
|
+
env: parsedFromZod["env"]
|
|
2600
3101
|
};
|
|
2601
3102
|
}
|
|
2602
3103
|
addFlag(flag) {
|
|
@@ -2990,6 +3491,7 @@ const _ArgParserBase = class _ArgParserBase {
|
|
|
2990
3491
|
}
|
|
2991
3492
|
async parse(processArgs, options) {
|
|
2992
3493
|
var _a, _b;
|
|
3494
|
+
debug.log("ArgParserBase.parse() called with args:", processArgs);
|
|
2993
3495
|
if (processArgs === void 0) {
|
|
2994
3496
|
if (typeof process !== "undefined" && process.argv && Array.isArray(process.argv)) {
|
|
2995
3497
|
processArgs = process.argv.slice(2);
|
|
@@ -3297,6 +3799,14 @@ ${indent(2)}${white(line)}`).join("")}
|
|
|
3297
3799
|
hasFlag(name) {
|
|
3298
3800
|
return __privateGet(this, _flagManager).hasFlag(name);
|
|
3299
3801
|
}
|
|
3802
|
+
/**
|
|
3803
|
+
* Get flag definition by name
|
|
3804
|
+
* @param name Flag name
|
|
3805
|
+
* @returns Flag definition or undefined if not found
|
|
3806
|
+
*/
|
|
3807
|
+
getFlagDefinition(name) {
|
|
3808
|
+
return __privateGet(this, _flagManager).getFlag(name);
|
|
3809
|
+
}
|
|
3300
3810
|
getCommandChain() {
|
|
3301
3811
|
const chain = [];
|
|
3302
3812
|
let currentParser = this;
|
|
@@ -3532,11 +4042,15 @@ _handleGlobalChecks_fn = async function(processArgs, options) {
|
|
|
3532
4042
|
return dxtResult === true ? true : dxtResult;
|
|
3533
4043
|
}
|
|
3534
4044
|
}
|
|
4045
|
+
debug.log("Checking for --s-mcp-serve flag in args:", processArgs);
|
|
3535
4046
|
const mcpServeIndex = processArgs.findIndex(
|
|
3536
4047
|
(arg) => arg === "--s-mcp-serve"
|
|
3537
4048
|
);
|
|
4049
|
+
debug.log("mcpServeIndex:", mcpServeIndex);
|
|
3538
4050
|
if (mcpServeIndex !== -1) {
|
|
4051
|
+
debug.log("Found --s-mcp-serve flag, calling handler");
|
|
3539
4052
|
const mcpServeResult = await __privateMethod(this, _ArgParserBase_instances, _handleMcpServeFlag_fn).call(this, processArgs, mcpServeIndex);
|
|
4053
|
+
debug.log("MCP serve handler returned:", typeof mcpServeResult);
|
|
3540
4054
|
if (mcpServeResult !== false) {
|
|
3541
4055
|
return mcpServeResult === true ? true : mcpServeResult;
|
|
3542
4056
|
}
|
|
@@ -4133,20 +4647,39 @@ _handleBuildDxtFlag_fn = async function(processArgs, buildDxtIndex) {
|
|
|
4133
4647
|
};
|
|
4134
4648
|
_handleMcpServeFlag_fn = async function(processArgs, _mcpServeIndex) {
|
|
4135
4649
|
var _a;
|
|
4650
|
+
debug.log("#_handleMcpServeFlag started");
|
|
4136
4651
|
const transportOptions = __privateMethod(this, _ArgParserBase_instances, _parseMcpTransportOptions_fn).call(this, processArgs);
|
|
4652
|
+
debug.log("Transport options parsed:", JSON.stringify(transportOptions));
|
|
4137
4653
|
const mcpServerConfig = __privateMethod(this, _ArgParserBase_instances, _getMcpServerConfiguration_fn).call(this);
|
|
4654
|
+
debug.log("Got MCP server config:", JSON.stringify(mcpServerConfig));
|
|
4138
4655
|
const effectiveLogPath = transportOptions.logPath || (mcpServerConfig == null ? void 0 : mcpServerConfig.logPath) || "./logs/mcp.log";
|
|
4656
|
+
debug.log("Effective log path:", effectiveLogPath);
|
|
4139
4657
|
const resolvedLogPath = resolveLogPath(effectiveLogPath);
|
|
4658
|
+
debug.log("Resolved log path:", resolvedLogPath);
|
|
4140
4659
|
let mcpLogger;
|
|
4660
|
+
debug.log("About to import simple-mcp-logger");
|
|
4141
4661
|
try {
|
|
4142
4662
|
const mcpLoggerModule = await import("@alcyone-labs/simple-mcp-logger");
|
|
4143
|
-
|
|
4663
|
+
debug.log("Successfully imported simple-mcp-logger");
|
|
4664
|
+
const loggerConfig = __privateMethod(this, _ArgParserBase_instances, _resolveLoggerConfigForServe_fn).call(this, mcpServerConfig, resolvedLogPath);
|
|
4665
|
+
if (typeof loggerConfig === "string") {
|
|
4666
|
+
mcpLogger = mcpLoggerModule.createMcpLogger("MCP Serve", loggerConfig);
|
|
4667
|
+
} else {
|
|
4668
|
+
mcpLogger = mcpLoggerModule.createMcpLogger(
|
|
4669
|
+
loggerConfig.prefix || "MCP Serve",
|
|
4670
|
+
loggerConfig.logToFile
|
|
4671
|
+
);
|
|
4672
|
+
}
|
|
4673
|
+
debug.log("Created MCP logger, about to hijack console");
|
|
4144
4674
|
globalThis.console = mcpLogger;
|
|
4675
|
+
debug.log("Console hijacked successfully");
|
|
4145
4676
|
} catch {
|
|
4677
|
+
debug.log("Failed to import simple-mcp-logger, using fallback");
|
|
4146
4678
|
mcpLogger = {
|
|
4147
4679
|
mcpError: (message) => console.error(`[MCP Serve] ${message}`)
|
|
4148
4680
|
};
|
|
4149
4681
|
}
|
|
4682
|
+
debug.log("MCP logger setup complete, starting MCP serve handler");
|
|
4150
4683
|
try {
|
|
4151
4684
|
mcpLogger.mcpError(
|
|
4152
4685
|
"Starting --s-mcp-serve system flag handler - console hijacked for MCP safety"
|
|
@@ -4169,11 +4702,13 @@ _handleMcpServeFlag_fn = async function(processArgs, _mcpServeIndex) {
|
|
|
4169
4702
|
`Transport options: ${JSON.stringify(transportOptions)}`
|
|
4170
4703
|
);
|
|
4171
4704
|
try {
|
|
4705
|
+
debug.log("About to call #_startUnifiedMcpServer");
|
|
4172
4706
|
mcpLogger.mcpError("Starting unified MCP server with all tools");
|
|
4173
4707
|
await __privateMethod(this, _ArgParserBase_instances, _startUnifiedMcpServer_fn).call(this, mcpServerConfig, {
|
|
4174
4708
|
...transportOptions,
|
|
4175
4709
|
logPath: resolvedLogPath
|
|
4176
4710
|
});
|
|
4711
|
+
debug.log("#_startUnifiedMcpServer completed");
|
|
4177
4712
|
mcpLogger.mcpError("Successfully started unified MCP server");
|
|
4178
4713
|
} catch (error) {
|
|
4179
4714
|
mcpLogger.mcpError(
|
|
@@ -4204,6 +4739,36 @@ _handleMcpServeFlag_fn = async function(processArgs, _mcpServeIndex) {
|
|
|
4204
4739
|
);
|
|
4205
4740
|
}
|
|
4206
4741
|
};
|
|
4742
|
+
/**
|
|
4743
|
+
* Resolve logger configuration for MCP serve with proper priority
|
|
4744
|
+
* @param mcpServerConfig MCP server configuration
|
|
4745
|
+
* @param resolvedLogPath Resolved log path from CLI flags
|
|
4746
|
+
* @returns Logger configuration object or string path
|
|
4747
|
+
*/
|
|
4748
|
+
_resolveLoggerConfigForServe_fn = function(mcpServerConfig, resolvedLogPath) {
|
|
4749
|
+
if (mcpServerConfig == null ? void 0 : mcpServerConfig.log) {
|
|
4750
|
+
if (typeof mcpServerConfig.log === "string") {
|
|
4751
|
+
return {
|
|
4752
|
+
prefix: "MCP Serve",
|
|
4753
|
+
logToFile: resolvedLogPath,
|
|
4754
|
+
level: "error",
|
|
4755
|
+
// Default level for backward compatibility
|
|
4756
|
+
mcpMode: true
|
|
4757
|
+
};
|
|
4758
|
+
} else {
|
|
4759
|
+
return {
|
|
4760
|
+
prefix: "MCP Serve",
|
|
4761
|
+
level: "error",
|
|
4762
|
+
// Default level for backward compatibility
|
|
4763
|
+
mcpMode: true,
|
|
4764
|
+
...mcpServerConfig.log,
|
|
4765
|
+
// Use CLI-resolved path if available, otherwise use config path
|
|
4766
|
+
logToFile: resolvedLogPath
|
|
4767
|
+
};
|
|
4768
|
+
}
|
|
4769
|
+
}
|
|
4770
|
+
return resolvedLogPath;
|
|
4771
|
+
};
|
|
4207
4772
|
/**
|
|
4208
4773
|
* Get MCP server configuration from withMcp() or fallback to addMcpSubCommand()
|
|
4209
4774
|
*/
|
|
@@ -4394,6 +4959,26 @@ _parseMcpTransportOptions_fn = function(processArgs) {
|
|
|
4394
4959
|
return options;
|
|
4395
4960
|
};
|
|
4396
4961
|
let ArgParserBase = _ArgParserBase;
|
|
4962
|
+
function sanitizeMcpToolName(name) {
|
|
4963
|
+
if (!name || typeof name !== "string") {
|
|
4964
|
+
throw new Error("Tool name must be a non-empty string");
|
|
4965
|
+
}
|
|
4966
|
+
let sanitized = name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
4967
|
+
if (!sanitized || /^_+$/.test(sanitized)) {
|
|
4968
|
+
sanitized = "tool";
|
|
4969
|
+
}
|
|
4970
|
+
if (sanitized.length > 64) {
|
|
4971
|
+
sanitized = sanitized.substring(0, 64);
|
|
4972
|
+
}
|
|
4973
|
+
return sanitized;
|
|
4974
|
+
}
|
|
4975
|
+
function isValidMcpToolName(name) {
|
|
4976
|
+
if (!name || typeof name !== "string") {
|
|
4977
|
+
return false;
|
|
4978
|
+
}
|
|
4979
|
+
const mcpNamePattern = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
4980
|
+
return mcpNamePattern.test(name);
|
|
4981
|
+
}
|
|
4397
4982
|
function createMcpSuccessResponse(data2) {
|
|
4398
4983
|
return {
|
|
4399
4984
|
content: [
|
|
@@ -4652,7 +5237,7 @@ function generateMcpToolsFromArgParser(rootParser, options) {
|
|
|
4652
5237
|
} else {
|
|
4653
5238
|
toolName = effectiveCommandName || "cmd";
|
|
4654
5239
|
}
|
|
4655
|
-
toolName = toolName
|
|
5240
|
+
toolName = sanitizeMcpToolName(toolName);
|
|
4656
5241
|
}
|
|
4657
5242
|
if (!toolName)
|
|
4658
5243
|
toolName = currentParser === rootParser && appName ? appName : "cmd";
|
|
@@ -4694,7 +5279,7 @@ function generateMcpToolsFromArgParser(rootParser, options) {
|
|
|
4694
5279
|
inputSchema,
|
|
4695
5280
|
outputSchema,
|
|
4696
5281
|
async execute(mcpInputArgs) {
|
|
4697
|
-
var _a;
|
|
5282
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4698
5283
|
if (process.env["MCP_DEBUG"]) {
|
|
4699
5284
|
console.error(
|
|
4700
5285
|
`[MCP Execute] Starting execution for tool '${toolName}'`
|
|
@@ -4816,12 +5401,32 @@ function generateMcpToolsFromArgParser(rootParser, options) {
|
|
|
4816
5401
|
JSON.stringify(mcpInputArgs, null, 2)
|
|
4817
5402
|
);
|
|
4818
5403
|
}
|
|
5404
|
+
const getFlag = (name) => {
|
|
5405
|
+
if (mcpInputArgs && mcpInputArgs[name] !== void 0) {
|
|
5406
|
+
return mcpInputArgs[name];
|
|
5407
|
+
}
|
|
5408
|
+
if (rootParser) {
|
|
5409
|
+
const flagDef = rootParser.getFlagDefinition(name);
|
|
5410
|
+
if (flagDef) {
|
|
5411
|
+
const envVar = flagDef["env"];
|
|
5412
|
+
if (envVar) {
|
|
5413
|
+
const envKey = Array.isArray(envVar) ? envVar[0] : envVar;
|
|
5414
|
+
if (envKey && process.env[envKey]) {
|
|
5415
|
+
return process.env[envKey];
|
|
5416
|
+
}
|
|
5417
|
+
}
|
|
5418
|
+
return flagDef["defaultValue"];
|
|
5419
|
+
}
|
|
5420
|
+
}
|
|
5421
|
+
return void 0;
|
|
5422
|
+
};
|
|
4819
5423
|
const handlerContext = {
|
|
4820
5424
|
args: mcpInputArgs,
|
|
4821
5425
|
commandChain: [toolName],
|
|
4822
5426
|
parser: rootParser,
|
|
4823
5427
|
parentArgs: void 0,
|
|
4824
|
-
isMcp: true
|
|
5428
|
+
isMcp: true,
|
|
5429
|
+
getFlag
|
|
4825
5430
|
};
|
|
4826
5431
|
const handlerResult = await toolConfig.handler(handlerContext);
|
|
4827
5432
|
if (process.env["MCP_DEBUG"]) {
|
|
@@ -4887,49 +5492,67 @@ function generateMcpToolsFromArgParser(rootParser, options) {
|
|
|
4887
5492
|
error: errPayload.message,
|
|
4888
5493
|
message: errPayload.message
|
|
4889
5494
|
};
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
console.error(
|
|
4894
|
-
`[MCP Debug] Output schema type:`,
|
|
4895
|
-
zodSchema._def.typeName
|
|
4896
|
-
);
|
|
4897
|
-
}
|
|
4898
|
-
if (zodSchema._def.typeName === "ZodObject") {
|
|
4899
|
-
const shapeGetter = zodSchema._def.shape;
|
|
4900
|
-
const shape = typeof shapeGetter === "function" ? shapeGetter() : shapeGetter;
|
|
5495
|
+
try {
|
|
5496
|
+
if (outputSchema && typeof outputSchema === "object" && outputSchema !== null && outputSchema._def) {
|
|
5497
|
+
const zodSchema = outputSchema;
|
|
4901
5498
|
if (process.env["MCP_DEBUG"]) {
|
|
4902
5499
|
console.error(
|
|
4903
|
-
`[MCP Debug]
|
|
4904
|
-
|
|
5500
|
+
`[MCP Debug] Output schema type:`,
|
|
5501
|
+
((_b = zodSchema._def) == null ? void 0 : _b.typeName) || ((_c = zodSchema._def) == null ? void 0 : _c.type)
|
|
4905
5502
|
);
|
|
4906
5503
|
}
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
break;
|
|
4918
|
-
case "ZodBoolean":
|
|
4919
|
-
structuredError[key] = false;
|
|
4920
|
-
break;
|
|
4921
|
-
case "ZodArray":
|
|
4922
|
-
structuredError[key] = [];
|
|
4923
|
-
break;
|
|
4924
|
-
case "ZodObject":
|
|
4925
|
-
structuredError[key] = {};
|
|
4926
|
-
break;
|
|
4927
|
-
default:
|
|
4928
|
-
structuredError[key] = null;
|
|
5504
|
+
if (((_d = zodSchema._def) == null ? void 0 : _d.typeName) === "ZodObject" || ((_e = zodSchema._def) == null ? void 0 : _e.type) === "object") {
|
|
5505
|
+
const shapeGetter = (_f = zodSchema._def) == null ? void 0 : _f.shape;
|
|
5506
|
+
if (shapeGetter) {
|
|
5507
|
+
const shape = typeof shapeGetter === "function" ? shapeGetter() : shapeGetter;
|
|
5508
|
+
if (shape && typeof shape === "object") {
|
|
5509
|
+
if (process.env["MCP_DEBUG"]) {
|
|
5510
|
+
console.error(
|
|
5511
|
+
`[MCP Debug] Schema shape keys:`,
|
|
5512
|
+
Object.keys(shape)
|
|
5513
|
+
);
|
|
4929
5514
|
}
|
|
5515
|
+
Object.keys(shape).forEach((key) => {
|
|
5516
|
+
if (!(key in structuredError)) {
|
|
5517
|
+
const fieldSchema = shape[key];
|
|
5518
|
+
if (fieldSchema && fieldSchema._def) {
|
|
5519
|
+
switch (fieldSchema._def.typeName || fieldSchema._def.type) {
|
|
5520
|
+
case "ZodString":
|
|
5521
|
+
case "string":
|
|
5522
|
+
structuredError[key] = "";
|
|
5523
|
+
break;
|
|
5524
|
+
case "ZodNumber":
|
|
5525
|
+
case "number":
|
|
5526
|
+
structuredError[key] = 0;
|
|
5527
|
+
break;
|
|
5528
|
+
case "ZodBoolean":
|
|
5529
|
+
case "boolean":
|
|
5530
|
+
structuredError[key] = false;
|
|
5531
|
+
break;
|
|
5532
|
+
case "ZodArray":
|
|
5533
|
+
case "array":
|
|
5534
|
+
structuredError[key] = [];
|
|
5535
|
+
break;
|
|
5536
|
+
case "ZodObject":
|
|
5537
|
+
case "object":
|
|
5538
|
+
structuredError[key] = {};
|
|
5539
|
+
break;
|
|
5540
|
+
default:
|
|
5541
|
+
structuredError[key] = null;
|
|
5542
|
+
}
|
|
5543
|
+
}
|
|
5544
|
+
}
|
|
5545
|
+
});
|
|
4930
5546
|
}
|
|
4931
5547
|
}
|
|
4932
|
-
}
|
|
5548
|
+
}
|
|
5549
|
+
}
|
|
5550
|
+
} catch (schemaError) {
|
|
5551
|
+
if (process.env["MCP_DEBUG"]) {
|
|
5552
|
+
console.error(
|
|
5553
|
+
`[MCP Debug] Error processing output schema for structured error:`,
|
|
5554
|
+
schemaError
|
|
5555
|
+
);
|
|
4933
5556
|
}
|
|
4934
5557
|
}
|
|
4935
5558
|
if (process.env["MCP_DEBUG"]) {
|
|
@@ -5019,12 +5642,32 @@ function generateMcpToolsFromArgParser(rootParser, options) {
|
|
|
5019
5642
|
const handlerToCall = finalHandler;
|
|
5020
5643
|
const cleanArgs = { ...mcpInputArgs };
|
|
5021
5644
|
delete cleanArgs["help"];
|
|
5645
|
+
const getFlag = (name) => {
|
|
5646
|
+
if (cleanArgs && cleanArgs[name] !== void 0) {
|
|
5647
|
+
return cleanArgs[name];
|
|
5648
|
+
}
|
|
5649
|
+
if (finalParser) {
|
|
5650
|
+
const flagDef = finalParser.getFlagDefinition(name);
|
|
5651
|
+
if (flagDef) {
|
|
5652
|
+
const envVar = flagDef["env"];
|
|
5653
|
+
if (envVar) {
|
|
5654
|
+
const envKey = Array.isArray(envVar) ? envVar[0] : envVar;
|
|
5655
|
+
if (envKey && process.env[envKey]) {
|
|
5656
|
+
return process.env[envKey];
|
|
5657
|
+
}
|
|
5658
|
+
}
|
|
5659
|
+
return flagDef["defaultValue"];
|
|
5660
|
+
}
|
|
5661
|
+
}
|
|
5662
|
+
return void 0;
|
|
5663
|
+
};
|
|
5022
5664
|
const handlerContext = {
|
|
5023
5665
|
args: cleanArgs,
|
|
5024
5666
|
commandChain: chain,
|
|
5025
5667
|
parser: finalParser,
|
|
5026
5668
|
parentArgs: resolvedParentArgs,
|
|
5027
|
-
isMcp: true
|
|
5669
|
+
isMcp: true,
|
|
5670
|
+
getFlag
|
|
5028
5671
|
};
|
|
5029
5672
|
try {
|
|
5030
5673
|
handlerResponse = await handlerToCall(handlerContext);
|
|
@@ -5133,27 +5776,27 @@ function generateMcpToolsFromArgParser(rootParser, options) {
|
|
|
5133
5776
|
};
|
|
5134
5777
|
if (outputSchema && typeof outputSchema === "object" && outputSchema !== null && outputSchema._def) {
|
|
5135
5778
|
const zodSchema = outputSchema;
|
|
5136
|
-
if (zodSchema._def.
|
|
5779
|
+
if (zodSchema._def.type === "object") {
|
|
5137
5780
|
const shapeGetter = zodSchema._def.shape;
|
|
5138
5781
|
const shape = typeof shapeGetter === "function" ? shapeGetter() : shapeGetter;
|
|
5139
5782
|
Object.keys(shape).forEach((key) => {
|
|
5140
5783
|
if (!(key in structuredError)) {
|
|
5141
5784
|
const fieldSchema = shape[key];
|
|
5142
5785
|
if (fieldSchema && fieldSchema._def) {
|
|
5143
|
-
switch (fieldSchema._def.
|
|
5144
|
-
case "
|
|
5786
|
+
switch (fieldSchema._def.type) {
|
|
5787
|
+
case "string":
|
|
5145
5788
|
structuredError[key] = "";
|
|
5146
5789
|
break;
|
|
5147
|
-
case "
|
|
5790
|
+
case "number":
|
|
5148
5791
|
structuredError[key] = 0;
|
|
5149
5792
|
break;
|
|
5150
|
-
case "
|
|
5793
|
+
case "boolean":
|
|
5151
5794
|
structuredError[key] = false;
|
|
5152
5795
|
break;
|
|
5153
|
-
case "
|
|
5796
|
+
case "array":
|
|
5154
5797
|
structuredError[key] = [];
|
|
5155
5798
|
break;
|
|
5156
|
-
case "
|
|
5799
|
+
case "object":
|
|
5157
5800
|
structuredError[key] = {};
|
|
5158
5801
|
break;
|
|
5159
5802
|
default:
|
|
@@ -5215,18 +5858,61 @@ function compareVersions(v1, v2) {
|
|
|
5215
5858
|
if (v1 === v2) return 0;
|
|
5216
5859
|
return v1 < v2 ? -1 : 1;
|
|
5217
5860
|
}
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5861
|
+
function debugSchemaStructure(schema, label = "Schema") {
|
|
5862
|
+
var _a, _b, _c;
|
|
5863
|
+
if (process.env["MCP_DEBUG"]) {
|
|
5864
|
+
console.error(`[Zod Compatibility Debug] ${label} structure:`);
|
|
5865
|
+
console.error(` - Type: ${typeof schema}`);
|
|
5866
|
+
console.error(` - Constructor: ${(_a = schema == null ? void 0 : schema.constructor) == null ? void 0 : _a.name}`);
|
|
5867
|
+
console.error(` - Has shape: ${!!(schema == null ? void 0 : schema.shape)}`);
|
|
5868
|
+
console.error(` - Has _def: ${!!(schema == null ? void 0 : schema._def)}`);
|
|
5869
|
+
console.error(` - _def.typeName: ${(_b = schema == null ? void 0 : schema._def) == null ? void 0 : _b.typeName}`);
|
|
5870
|
+
console.error(` - _def.type: ${(_c = schema == null ? void 0 : schema._def) == null ? void 0 : _c.type}`);
|
|
5871
|
+
console.error(` - Has parse: ${typeof (schema == null ? void 0 : schema.parse)}`);
|
|
5872
|
+
console.error(` - Has safeParse: ${typeof (schema == null ? void 0 : schema.safeParse)}`);
|
|
5873
|
+
if (schema == null ? void 0 : schema.shape) {
|
|
5874
|
+
console.error(` - Shape keys: ${Object.keys(schema.shape)}`);
|
|
5875
|
+
}
|
|
5226
5876
|
}
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5877
|
+
}
|
|
5878
|
+
function validateMcpSchemaCompatibility(schema) {
|
|
5879
|
+
var _a, _b;
|
|
5880
|
+
try {
|
|
5881
|
+
if (typeof (schema == null ? void 0 : schema.parse) !== "function") {
|
|
5882
|
+
console.warn("[Zod Compatibility] Schema missing parse method");
|
|
5883
|
+
return false;
|
|
5884
|
+
}
|
|
5885
|
+
if (typeof (schema == null ? void 0 : schema.safeParse) !== "function") {
|
|
5886
|
+
console.warn("[Zod Compatibility] Schema missing safeParse method");
|
|
5887
|
+
return false;
|
|
5888
|
+
}
|
|
5889
|
+
if ((((_a = schema == null ? void 0 : schema._def) == null ? void 0 : _a.typeName) === "ZodObject" || ((_b = schema == null ? void 0 : schema._def) == null ? void 0 : _b.type) === "object") && !(schema == null ? void 0 : schema.shape)) {
|
|
5890
|
+
console.warn(
|
|
5891
|
+
"[Zod Compatibility] ZodObject schema missing shape property"
|
|
5892
|
+
);
|
|
5893
|
+
return false;
|
|
5894
|
+
}
|
|
5895
|
+
return true;
|
|
5896
|
+
} catch (error) {
|
|
5897
|
+
console.error(
|
|
5898
|
+
"[Zod Compatibility] Error validating schema compatibility:",
|
|
5899
|
+
error
|
|
5900
|
+
);
|
|
5901
|
+
return false;
|
|
5902
|
+
}
|
|
5903
|
+
}
|
|
5904
|
+
const _ArgParser = class _ArgParser extends ArgParserBase {
|
|
5905
|
+
constructor() {
|
|
5906
|
+
super(...arguments);
|
|
5907
|
+
__privateAdd(this, _ArgParser_instances);
|
|
5908
|
+
this._mcpTools = /* @__PURE__ */ new Map();
|
|
5909
|
+
this._tools = /* @__PURE__ */ new Map();
|
|
5910
|
+
this._outputSchemaMap = /* @__PURE__ */ new Map();
|
|
5911
|
+
this._mcpProtocolVersion = CURRENT_MCP_PROTOCOL_VERSION;
|
|
5912
|
+
}
|
|
5913
|
+
/**
|
|
5914
|
+
* Get the stored MCP server configuration
|
|
5915
|
+
* @returns MCP server configuration if set via withMcp(), undefined otherwise
|
|
5230
5916
|
*/
|
|
5231
5917
|
getMcpServerConfig() {
|
|
5232
5918
|
return this._mcpServerConfig;
|
|
@@ -5285,19 +5971,33 @@ const _ArgParser = class _ArgParser extends ArgParserBase {
|
|
|
5285
5971
|
* @returns This ArgParser instance for chaining
|
|
5286
5972
|
*/
|
|
5287
5973
|
addTool(toolConfig) {
|
|
5288
|
-
|
|
5289
|
-
throw new Error(`Tool with name '${toolConfig.name}' already exists`);
|
|
5290
|
-
}
|
|
5974
|
+
var _a;
|
|
5291
5975
|
if (!toolConfig.name || typeof toolConfig.name !== "string") {
|
|
5292
5976
|
throw new Error("Tool name is required and must be a string");
|
|
5293
5977
|
}
|
|
5294
5978
|
if (!toolConfig.handler || typeof toolConfig.handler !== "function") {
|
|
5295
5979
|
throw new Error("Tool handler is required and must be a function");
|
|
5296
5980
|
}
|
|
5981
|
+
const sanitizedName = sanitizeMcpToolName(toolConfig.name);
|
|
5982
|
+
if (sanitizedName !== toolConfig.name) {
|
|
5983
|
+
const isMcpMode = (_a = globalThis.console) == null ? void 0 : _a.mcpError;
|
|
5984
|
+
if (!isMcpMode) {
|
|
5985
|
+
console.warn(
|
|
5986
|
+
`[ArgParser] Tool name '${toolConfig.name}' was sanitized to '${sanitizedName}' for MCP compatibility`
|
|
5987
|
+
);
|
|
5988
|
+
}
|
|
5989
|
+
}
|
|
5990
|
+
if (this._tools.has(sanitizedName)) {
|
|
5991
|
+
throw new Error(`Tool with name '${sanitizedName}' already exists`);
|
|
5992
|
+
}
|
|
5297
5993
|
if (!Array.isArray(toolConfig.flags)) {
|
|
5298
5994
|
throw new Error("Tool flags must be an array");
|
|
5299
5995
|
}
|
|
5300
|
-
|
|
5996
|
+
const sanitizedToolConfig = {
|
|
5997
|
+
...toolConfig,
|
|
5998
|
+
name: sanitizedName
|
|
5999
|
+
};
|
|
6000
|
+
this._tools.set(sanitizedName, sanitizedToolConfig);
|
|
5301
6001
|
__privateMethod(this, _ArgParser_instances, registerToolAsSubCommand_fn).call(this, toolConfig);
|
|
5302
6002
|
return this;
|
|
5303
6003
|
}
|
|
@@ -5308,13 +6008,40 @@ const _ArgParser = class _ArgParser extends ArgParserBase {
|
|
|
5308
6008
|
* @returns This ArgParser instance for chaining
|
|
5309
6009
|
*/
|
|
5310
6010
|
addMcpTool(toolConfig) {
|
|
5311
|
-
|
|
6011
|
+
var _a;
|
|
6012
|
+
try {
|
|
6013
|
+
if (typeof process !== "undefined" && process.stderr) {
|
|
6014
|
+
process.stderr.write(`[DEPRECATED] addMcpTool() is deprecated and will be removed in v2.0.
|
|
6015
|
+
Please use addTool() instead for a unified CLI/MCP experience.
|
|
6016
|
+
Migration guide: https://github.com/alcyone-labs/arg-parser/blob/main/docs/MCP-MIGRATION.md
|
|
6017
|
+
`);
|
|
6018
|
+
} else {
|
|
6019
|
+
console.warn(`[DEPRECATED] addMcpTool() is deprecated and will be removed in v2.0.
|
|
6020
|
+
Please use addTool() instead for a unified CLI/MCP experience.
|
|
6021
|
+
Migration guide: https://github.com/alcyone-labs/arg-parser/blob/main/docs/MCP-MIGRATION.md`);
|
|
6022
|
+
}
|
|
6023
|
+
} catch {
|
|
6024
|
+
console.warn(`[DEPRECATED] addMcpTool() is deprecated and will be removed in v2.0.
|
|
5312
6025
|
Please use addTool() instead for a unified CLI/MCP experience.
|
|
5313
6026
|
Migration guide: https://github.com/alcyone-labs/arg-parser/blob/main/docs/MCP-MIGRATION.md`);
|
|
5314
|
-
if (this._mcpTools.has(toolConfig.name)) {
|
|
5315
|
-
throw new Error(`MCP tool with name '${toolConfig.name}' already exists`);
|
|
5316
6027
|
}
|
|
5317
|
-
|
|
6028
|
+
const sanitizedName = sanitizeMcpToolName(toolConfig.name);
|
|
6029
|
+
if (sanitizedName !== toolConfig.name) {
|
|
6030
|
+
const isMcpMode = (_a = globalThis.console) == null ? void 0 : _a.mcpError;
|
|
6031
|
+
if (!isMcpMode) {
|
|
6032
|
+
console.warn(
|
|
6033
|
+
`[ArgParser] Tool name '${toolConfig.name}' was sanitized to '${sanitizedName}' for MCP compatibility`
|
|
6034
|
+
);
|
|
6035
|
+
}
|
|
6036
|
+
}
|
|
6037
|
+
if (this._mcpTools.has(sanitizedName)) {
|
|
6038
|
+
throw new Error(`MCP tool with name '${sanitizedName}' already exists`);
|
|
6039
|
+
}
|
|
6040
|
+
const sanitizedToolConfig = {
|
|
6041
|
+
...toolConfig,
|
|
6042
|
+
name: sanitizedName
|
|
6043
|
+
};
|
|
6044
|
+
this._mcpTools.set(sanitizedName, sanitizedToolConfig);
|
|
5318
6045
|
return this;
|
|
5319
6046
|
}
|
|
5320
6047
|
/**
|
|
@@ -5586,7 +6313,7 @@ Migration guide: https://github.com/alcyone-labs/arg-parser/blob/main/docs/MCP-M
|
|
|
5586
6313
|
).map((toolConfig) => ({
|
|
5587
6314
|
name: toolConfig.name,
|
|
5588
6315
|
description: toolConfig.description || `Executes the ${toolConfig.name} tool.`,
|
|
5589
|
-
inputSchema: toolConfig.inputSchema ||
|
|
6316
|
+
inputSchema: toolConfig.inputSchema || zod.z.object({}),
|
|
5590
6317
|
outputSchema: toolConfig.outputSchema,
|
|
5591
6318
|
execute: async (args) => {
|
|
5592
6319
|
try {
|
|
@@ -5646,16 +6373,18 @@ Migration guide: https://github.com/alcyone-labs/arg-parser/blob/main/docs/MCP-M
|
|
|
5646
6373
|
* Create an MCP server with tools generated from this ArgParser
|
|
5647
6374
|
* @param serverInfo Server configuration
|
|
5648
6375
|
* @param toolOptions Optional MCP tool generation options
|
|
6376
|
+
* @param logPath Optional log path (deprecated, use log config in withMcp instead)
|
|
5649
6377
|
* @returns Configured MCP server instance
|
|
5650
6378
|
*/
|
|
5651
6379
|
async createMcpServer(serverInfo, toolOptions, logPath) {
|
|
5652
|
-
var _a, _b;
|
|
5653
|
-
const
|
|
5654
|
-
|
|
6380
|
+
var _a, _b, _c;
|
|
6381
|
+
const loggerConfig = __privateMethod(this, _ArgParser_instances, _resolveLoggerConfig_fn).call(this, logPath);
|
|
6382
|
+
const logger = typeof loggerConfig === "string" ? simpleMcpLogger.createMcpLogger("MCP Server Creation", loggerConfig) : simpleMcpLogger.createMcpLogger(
|
|
6383
|
+
loggerConfig.prefix || "MCP Server Creation",
|
|
6384
|
+
loggerConfig.logToFile
|
|
5655
6385
|
);
|
|
5656
|
-
const logger = simpleMcpLogger.createMcpLogger("MCP Server Creation", resolvedLogPath);
|
|
5657
6386
|
try {
|
|
5658
|
-
const effectiveServerInfo = serverInfo || ((
|
|
6387
|
+
const effectiveServerInfo = serverInfo || ((_a = this._mcpServerConfig) == null ? void 0 : _a.serverInfo);
|
|
5659
6388
|
if (!effectiveServerInfo) {
|
|
5660
6389
|
throw new Error(
|
|
5661
6390
|
"No MCP server configuration found. Use withMcp() to configure server info or provide serverInfo parameter."
|
|
@@ -5664,8 +6393,10 @@ Migration guide: https://github.com/alcyone-labs/arg-parser/blob/main/docs/MCP-M
|
|
|
5664
6393
|
logger.mcpError(
|
|
5665
6394
|
`Creating MCP server: ${effectiveServerInfo.name} v${effectiveServerInfo.version}`
|
|
5666
6395
|
);
|
|
5667
|
-
const { McpServer: McpServer2 } = await Promise.resolve().then(() => mcp);
|
|
5668
|
-
logger.mcpError(
|
|
6396
|
+
const { McpServer: McpServer2, ResourceTemplate: ResourceTemplate2 } = await Promise.resolve().then(() => mcp);
|
|
6397
|
+
logger.mcpError(
|
|
6398
|
+
"Successfully imported McpServer and ResourceTemplate from SDK"
|
|
6399
|
+
);
|
|
5669
6400
|
const server = new McpServer2({
|
|
5670
6401
|
id: effectiveServerInfo.name,
|
|
5671
6402
|
version: effectiveServerInfo.version,
|
|
@@ -5673,6 +6404,61 @@ Migration guide: https://github.com/alcyone-labs/arg-parser/blob/main/docs/MCP-M
|
|
|
5673
6404
|
description: effectiveServerInfo.description
|
|
5674
6405
|
});
|
|
5675
6406
|
logger.mcpError("Successfully created McpServer instance");
|
|
6407
|
+
const isInMcpServeMode = process.argv.includes("--s-mcp-serve");
|
|
6408
|
+
if (((_b = this._mcpServerConfig) == null ? void 0 : _b.lifecycle) && !isInMcpServeMode) {
|
|
6409
|
+
const { McpLifecycleManager: McpLifecycleManager2 } = await Promise.resolve().then(() => mcpLifecycle);
|
|
6410
|
+
const lifecycleManager = new McpLifecycleManager2(
|
|
6411
|
+
this._mcpServerConfig.lifecycle,
|
|
6412
|
+
logger,
|
|
6413
|
+
effectiveServerInfo,
|
|
6414
|
+
this
|
|
6415
|
+
);
|
|
6416
|
+
try {
|
|
6417
|
+
const filteredArgs = process.argv.slice(2).filter(
|
|
6418
|
+
(arg) => !arg.startsWith("--s-mcp-") && arg !== "--s-mcp-serve"
|
|
6419
|
+
);
|
|
6420
|
+
const parsedResult = await this.parse(filteredArgs, {
|
|
6421
|
+
skipHandlerExecution: true,
|
|
6422
|
+
isMcp: true
|
|
6423
|
+
});
|
|
6424
|
+
const parsedArgs = (parsedResult == null ? void 0 : parsedResult.args) || parsedResult || {};
|
|
6425
|
+
lifecycleManager.setParsedArgs(parsedArgs);
|
|
6426
|
+
logger.mcpError(`Lifecycle manager initialized with parsed args: ${Object.keys(parsedArgs).join(", ")}`);
|
|
6427
|
+
} catch (parseError) {
|
|
6428
|
+
logger.mcpError(`Warning: Could not parse arguments for lifecycle manager: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
6429
|
+
}
|
|
6430
|
+
const originalConnect = server.connect.bind(server);
|
|
6431
|
+
server.connect = async (transport) => {
|
|
6432
|
+
logger.mcpError("MCP server connecting with lifecycle events...");
|
|
6433
|
+
const result = await originalConnect(transport);
|
|
6434
|
+
try {
|
|
6435
|
+
await lifecycleManager.handleInitialize(
|
|
6436
|
+
{ name: "mcp-client", version: "1.0.0" },
|
|
6437
|
+
// Default client info
|
|
6438
|
+
"2024-11-05",
|
|
6439
|
+
// Default protocol version
|
|
6440
|
+
{}
|
|
6441
|
+
// Default capabilities
|
|
6442
|
+
);
|
|
6443
|
+
setTimeout(async () => {
|
|
6444
|
+
try {
|
|
6445
|
+
await lifecycleManager.handleInitialized();
|
|
6446
|
+
} catch (error) {
|
|
6447
|
+
logger.mcpError(
|
|
6448
|
+
`Lifecycle onInitialized error: ${error instanceof Error ? error.message : String(error)}`
|
|
6449
|
+
);
|
|
6450
|
+
}
|
|
6451
|
+
}, 100);
|
|
6452
|
+
} catch (error) {
|
|
6453
|
+
logger.mcpError(
|
|
6454
|
+
`Lifecycle onInitialize error: ${error instanceof Error ? error.message : String(error)}`
|
|
6455
|
+
);
|
|
6456
|
+
}
|
|
6457
|
+
return result;
|
|
6458
|
+
};
|
|
6459
|
+
server._lifecycleManager = lifecycleManager;
|
|
6460
|
+
logger.mcpError("Successfully set up MCP lifecycle manager");
|
|
6461
|
+
}
|
|
5676
6462
|
logger.mcpError(
|
|
5677
6463
|
"MCP server will register actual resources and prompts for full capability support"
|
|
5678
6464
|
);
|
|
@@ -5689,29 +6475,122 @@ Migration guide: https://github.com/alcyone-labs/arg-parser/blob/main/docs/MCP-M
|
|
|
5689
6475
|
`After deduplication: ${uniqueTools.length} unique tools`
|
|
5690
6476
|
);
|
|
5691
6477
|
uniqueTools.forEach((tool) => {
|
|
6478
|
+
var _a2, _b2, _c2, _d, _e, _f;
|
|
5692
6479
|
logger.mcpError(`Registering tool: ${tool.name}`);
|
|
5693
|
-
let
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
|
|
5697
|
-
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
}
|
|
6480
|
+
let zodSchema;
|
|
6481
|
+
const toolFromUnified = Array.from(this._tools.values()).find(
|
|
6482
|
+
(t) => t.name === tool.name
|
|
6483
|
+
);
|
|
6484
|
+
const toolFromLegacy = Array.from(this._mcpTools.values()).find(
|
|
6485
|
+
(t) => t.name === tool.name
|
|
6486
|
+
);
|
|
6487
|
+
if (toolFromUnified && toolFromUnified.flags) {
|
|
6488
|
+
zodSchema = convertFlagsToZodSchema(toolFromUnified.flags);
|
|
6489
|
+
} else if (toolFromLegacy && toolFromLegacy.inputSchema) {
|
|
6490
|
+
zodSchema = toolFromLegacy.inputSchema;
|
|
5705
6491
|
} else {
|
|
5706
|
-
|
|
6492
|
+
zodSchema = zod.z.object({});
|
|
6493
|
+
}
|
|
6494
|
+
let mcpCompatibleSchema;
|
|
6495
|
+
try {
|
|
6496
|
+
if (process.env["MCP_DEBUG"]) {
|
|
6497
|
+
console.error(`[MCP Debug] Preparing schema for tool ${tool.name}`);
|
|
6498
|
+
console.error(`[MCP Debug] Input zodSchema:`, zodSchema);
|
|
6499
|
+
}
|
|
6500
|
+
mcpCompatibleSchema = zodSchema;
|
|
6501
|
+
if (process.env["MCP_DEBUG"]) {
|
|
6502
|
+
console.error(
|
|
6503
|
+
`[MCP Debug] Successfully prepared schema for tool ${tool.name}`
|
|
6504
|
+
);
|
|
6505
|
+
}
|
|
6506
|
+
} catch (schemaError) {
|
|
6507
|
+
console.error(
|
|
6508
|
+
`[MCP Debug] Error preparing schema for tool ${tool.name}:`,
|
|
6509
|
+
schemaError
|
|
6510
|
+
);
|
|
6511
|
+
throw schemaError;
|
|
6512
|
+
}
|
|
6513
|
+
if (process.env["MCP_DEBUG"]) {
|
|
6514
|
+
console.error(
|
|
6515
|
+
`[MCP Debug] Prepared mcpCompatibleSchema for tool ${tool.name}:`,
|
|
6516
|
+
JSON.stringify(mcpCompatibleSchema, null, 2)
|
|
6517
|
+
);
|
|
6518
|
+
console.error(
|
|
6519
|
+
`[MCP Debug] Schema properties:`,
|
|
6520
|
+
Object.keys(mcpCompatibleSchema || {})
|
|
6521
|
+
);
|
|
6522
|
+
console.error(
|
|
6523
|
+
`[MCP Debug] Schema def:`,
|
|
6524
|
+
mcpCompatibleSchema == null ? void 0 : mcpCompatibleSchema.def
|
|
6525
|
+
);
|
|
6526
|
+
console.error(
|
|
6527
|
+
`[MCP Debug] Schema shape:`,
|
|
6528
|
+
mcpCompatibleSchema == null ? void 0 : mcpCompatibleSchema.shape
|
|
6529
|
+
);
|
|
6530
|
+
console.error(
|
|
6531
|
+
`[MCP Debug] Schema parse function:`,
|
|
6532
|
+
typeof (mcpCompatibleSchema == null ? void 0 : mcpCompatibleSchema.parse)
|
|
6533
|
+
);
|
|
6534
|
+
}
|
|
6535
|
+
if (process.env["MCP_DEBUG"]) {
|
|
6536
|
+
console.error(
|
|
6537
|
+
`[MCP Debug] About to prepare schema for tool ${tool.name}`
|
|
6538
|
+
);
|
|
6539
|
+
console.error(`[MCP Debug] zodSchema type:`, typeof zodSchema);
|
|
6540
|
+
console.error(`[MCP Debug] zodSchema:`, zodSchema);
|
|
6541
|
+
console.error(
|
|
6542
|
+
`[MCP Debug] zodSchema constructor:`,
|
|
6543
|
+
(_a2 = zodSchema == null ? void 0 : zodSchema.constructor) == null ? void 0 : _a2.name
|
|
6544
|
+
);
|
|
6545
|
+
}
|
|
6546
|
+
debugSchemaStructure(mcpCompatibleSchema, `Tool ${tool.name} schema`);
|
|
6547
|
+
if (!validateMcpSchemaCompatibility(mcpCompatibleSchema)) {
|
|
6548
|
+
logger.mcpError(
|
|
6549
|
+
`Warning: Schema for tool ${tool.name} may not be fully compatible with MCP SDK`
|
|
6550
|
+
);
|
|
5707
6551
|
}
|
|
5708
6552
|
const toolConfig = {
|
|
5709
6553
|
title: tool.name,
|
|
5710
6554
|
// MCP SDK requires title field
|
|
5711
6555
|
description: tool.description || "No description provided.",
|
|
5712
|
-
inputSchema
|
|
5713
|
-
// Use Zod
|
|
6556
|
+
inputSchema: mcpCompatibleSchema
|
|
6557
|
+
// Use Zod v3 compatible schema for MCP SDK
|
|
5714
6558
|
};
|
|
6559
|
+
if (process.env["MCP_DEBUG"]) {
|
|
6560
|
+
console.error(
|
|
6561
|
+
`[MCP Debug] Final toolConfig for ${tool.name}:`,
|
|
6562
|
+
JSON.stringify(toolConfig, null, 2)
|
|
6563
|
+
);
|
|
6564
|
+
console.error(
|
|
6565
|
+
`[MCP Debug] toolConfig.inputSchema type:`,
|
|
6566
|
+
typeof toolConfig.inputSchema
|
|
6567
|
+
);
|
|
6568
|
+
console.error(
|
|
6569
|
+
`[MCP Debug] toolConfig.inputSchema constructor:`,
|
|
6570
|
+
(_c2 = (_b2 = toolConfig.inputSchema) == null ? void 0 : _b2.constructor) == null ? void 0 : _c2.name
|
|
6571
|
+
);
|
|
6572
|
+
console.error(
|
|
6573
|
+
`[MCP Debug] toolConfig.inputSchema._def:`,
|
|
6574
|
+
(_d = toolConfig.inputSchema) == null ? void 0 : _d._def
|
|
6575
|
+
);
|
|
6576
|
+
console.error(
|
|
6577
|
+
`[MCP Debug] toolConfig.inputSchema.shape:`,
|
|
6578
|
+
(_e = toolConfig.inputSchema) == null ? void 0 : _e.shape
|
|
6579
|
+
);
|
|
6580
|
+
console.error(
|
|
6581
|
+
`[MCP Debug] toolConfig.inputSchema._zod:`,
|
|
6582
|
+
(_f = toolConfig.inputSchema) == null ? void 0 : _f._zod
|
|
6583
|
+
);
|
|
6584
|
+
console.error(
|
|
6585
|
+
`[MCP Debug] Schema keys:`,
|
|
6586
|
+
Object.keys(mcpCompatibleSchema || {})
|
|
6587
|
+
);
|
|
6588
|
+
console.error(`[MCP Debug] About to call server.registerTool with:`, {
|
|
6589
|
+
name: tool.name,
|
|
6590
|
+
description: tool.description,
|
|
6591
|
+
inputSchema: mcpCompatibleSchema
|
|
6592
|
+
});
|
|
6593
|
+
}
|
|
5715
6594
|
const simpleExecute = async (args) => {
|
|
5716
6595
|
if (process.env["MCP_DEBUG"]) {
|
|
5717
6596
|
console.error(
|
|
@@ -5761,37 +6640,194 @@ Migration guide: https://github.com/alcyone-labs/arg-parser/blob/main/docs/MCP-M
|
|
|
5761
6640
|
});
|
|
5762
6641
|
logger.mcpError("Successfully registered all tools with MCP server");
|
|
5763
6642
|
const resources = this.getMcpResources();
|
|
5764
|
-
logger.mcpError(
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
"
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
6643
|
+
logger.mcpError(`Registering ${resources.length} MCP resources`);
|
|
6644
|
+
resources.forEach((resource) => {
|
|
6645
|
+
try {
|
|
6646
|
+
const resourceConfig = {
|
|
6647
|
+
title: resource.title || resource.name,
|
|
6648
|
+
description: resource.description || `Resource: ${resource.name}`,
|
|
6649
|
+
mimeType: resource.mimeType || "application/json"
|
|
6650
|
+
};
|
|
6651
|
+
if (resource.uriTemplate.includes("{")) {
|
|
6652
|
+
const resourceTemplate = new ResourceTemplate2(
|
|
6653
|
+
resource.uriTemplate,
|
|
6654
|
+
{ list: void 0 }
|
|
6655
|
+
);
|
|
6656
|
+
const templateHandler = async (uri, params = {}) => {
|
|
6657
|
+
try {
|
|
6658
|
+
const result = await resource.handler(
|
|
6659
|
+
new URL(uri.href || uri),
|
|
6660
|
+
params
|
|
6661
|
+
);
|
|
6662
|
+
return {
|
|
6663
|
+
contents: result.contents.map((content) => {
|
|
6664
|
+
const mcpContent = {
|
|
6665
|
+
uri: content.uri
|
|
6666
|
+
};
|
|
6667
|
+
if (content.text !== void 0) {
|
|
6668
|
+
mcpContent.text = content.text;
|
|
6669
|
+
}
|
|
6670
|
+
if (content.blob !== void 0) {
|
|
6671
|
+
mcpContent.blob = content.blob;
|
|
6672
|
+
}
|
|
6673
|
+
if (content.mimeType !== void 0) {
|
|
6674
|
+
mcpContent.mimeType = content.mimeType;
|
|
6675
|
+
}
|
|
6676
|
+
return mcpContent;
|
|
6677
|
+
})
|
|
6678
|
+
};
|
|
6679
|
+
} catch (error) {
|
|
6680
|
+
logger.mcpError(
|
|
6681
|
+
`Resource template handler error for ${resource.name}: ${error instanceof Error ? error.message : String(error)}`
|
|
6682
|
+
);
|
|
6683
|
+
throw error;
|
|
6684
|
+
}
|
|
6685
|
+
};
|
|
6686
|
+
server.registerResource(
|
|
6687
|
+
resource.name,
|
|
6688
|
+
resourceTemplate,
|
|
6689
|
+
resourceConfig,
|
|
6690
|
+
templateHandler
|
|
6691
|
+
);
|
|
6692
|
+
} else {
|
|
6693
|
+
const resourceHandler = async (uri) => {
|
|
6694
|
+
try {
|
|
6695
|
+
const result = await resource.handler(
|
|
6696
|
+
new URL(uri.href || uri),
|
|
6697
|
+
{}
|
|
6698
|
+
);
|
|
6699
|
+
return {
|
|
6700
|
+
contents: result.contents.map((content) => {
|
|
6701
|
+
const mcpContent = {
|
|
6702
|
+
uri: content.uri
|
|
6703
|
+
};
|
|
6704
|
+
if (content.text !== void 0) {
|
|
6705
|
+
mcpContent.text = content.text;
|
|
6706
|
+
}
|
|
6707
|
+
if (content.blob !== void 0) {
|
|
6708
|
+
mcpContent.blob = content.blob;
|
|
6709
|
+
}
|
|
6710
|
+
if (content.mimeType !== void 0) {
|
|
6711
|
+
mcpContent.mimeType = content.mimeType;
|
|
6712
|
+
}
|
|
6713
|
+
return mcpContent;
|
|
6714
|
+
})
|
|
6715
|
+
};
|
|
6716
|
+
} catch (error) {
|
|
6717
|
+
logger.mcpError(
|
|
6718
|
+
`Resource handler error for ${resource.name}: ${error instanceof Error ? error.message : String(error)}`
|
|
6719
|
+
);
|
|
6720
|
+
throw error;
|
|
6721
|
+
}
|
|
6722
|
+
};
|
|
6723
|
+
server.registerResource(
|
|
6724
|
+
resource.name,
|
|
6725
|
+
resource.uriTemplate,
|
|
6726
|
+
resourceConfig,
|
|
6727
|
+
resourceHandler
|
|
6728
|
+
);
|
|
6729
|
+
}
|
|
6730
|
+
logger.mcpError(`Successfully registered resource: ${resource.name}`);
|
|
6731
|
+
} catch (error) {
|
|
6732
|
+
logger.mcpError(
|
|
6733
|
+
`Failed to register resource ${resource.name}: ${error instanceof Error ? error.message : String(error)}`
|
|
6734
|
+
);
|
|
6735
|
+
}
|
|
6736
|
+
});
|
|
6737
|
+
logger.mcpError("Successfully registered all resources with MCP server");
|
|
5778
6738
|
const prompts = this.getMcpPrompts();
|
|
5779
|
-
logger.mcpError(
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
6739
|
+
logger.mcpError(`Registering ${prompts.length} MCP prompts`);
|
|
6740
|
+
prompts.forEach((prompt) => {
|
|
6741
|
+
try {
|
|
6742
|
+
let mcpCompatibleSchema;
|
|
6743
|
+
try {
|
|
6744
|
+
if (process.env["MCP_DEBUG"]) {
|
|
6745
|
+
console.error(
|
|
6746
|
+
`[MCP Debug] Preparing schema for prompt ${prompt.name}`
|
|
6747
|
+
);
|
|
6748
|
+
console.error(`[MCP Debug] Input argsSchema:`, prompt.argsSchema);
|
|
6749
|
+
}
|
|
6750
|
+
mcpCompatibleSchema = prompt.argsSchema;
|
|
6751
|
+
if (process.env["MCP_DEBUG"]) {
|
|
6752
|
+
console.error(
|
|
6753
|
+
`[MCP Debug] Successfully prepared schema for prompt ${prompt.name}`
|
|
6754
|
+
);
|
|
6755
|
+
}
|
|
6756
|
+
} catch (schemaError) {
|
|
6757
|
+
console.error(
|
|
6758
|
+
`[MCP Debug] Error preparing schema for prompt ${prompt.name}:`,
|
|
6759
|
+
schemaError
|
|
6760
|
+
);
|
|
6761
|
+
throw schemaError;
|
|
6762
|
+
}
|
|
6763
|
+
if (!validateMcpSchemaCompatibility(mcpCompatibleSchema)) {
|
|
6764
|
+
throw new Error(
|
|
6765
|
+
`Schema validation failed for prompt ${prompt.name}`
|
|
6766
|
+
);
|
|
6767
|
+
}
|
|
6768
|
+
if (process.env["MCP_DEBUG"]) {
|
|
6769
|
+
debugSchemaStructure(mcpCompatibleSchema, `prompt ${prompt.name}`);
|
|
6770
|
+
}
|
|
6771
|
+
const promptConfig = {
|
|
6772
|
+
title: prompt.title || prompt.name,
|
|
6773
|
+
// MCP SDK requires title field
|
|
6774
|
+
description: prompt.description || "No description provided.",
|
|
6775
|
+
argsSchema: mcpCompatibleSchema
|
|
6776
|
+
// Use Zod v3 compatible schema for MCP SDK
|
|
6777
|
+
};
|
|
6778
|
+
const promptHandler = async (args) => {
|
|
6779
|
+
try {
|
|
6780
|
+
const validatedArgs = prompt.argsSchema.parse(args);
|
|
6781
|
+
const result = await prompt.handler(validatedArgs);
|
|
6782
|
+
if (process.env["MCP_DEBUG"]) {
|
|
6783
|
+
console.error(
|
|
6784
|
+
`[MCP Debug] Prompt '${prompt.name}' executed successfully`
|
|
6785
|
+
);
|
|
6786
|
+
}
|
|
6787
|
+
return result;
|
|
6788
|
+
} catch (error) {
|
|
6789
|
+
if (process.env["MCP_DEBUG"]) {
|
|
6790
|
+
console.error(
|
|
6791
|
+
`[MCP Debug] Prompt '${prompt.name}' execution error:`,
|
|
6792
|
+
error
|
|
6793
|
+
);
|
|
6794
|
+
}
|
|
6795
|
+
throw error;
|
|
6796
|
+
}
|
|
6797
|
+
};
|
|
6798
|
+
server.registerPrompt(
|
|
6799
|
+
prompt.name,
|
|
6800
|
+
promptConfig,
|
|
6801
|
+
promptHandler
|
|
6802
|
+
);
|
|
6803
|
+
logger.mcpError(`Successfully registered prompt: ${prompt.name}`);
|
|
6804
|
+
} catch (error) {
|
|
6805
|
+
logger.mcpError(
|
|
6806
|
+
`Failed to register prompt ${prompt.name}: ${error instanceof Error ? error.message : String(error)}`
|
|
6807
|
+
);
|
|
6808
|
+
}
|
|
6809
|
+
});
|
|
6810
|
+
logger.mcpError("Successfully registered all prompts with MCP server");
|
|
5793
6811
|
this.setupMcpChangeNotifications(server);
|
|
5794
6812
|
logger.mcpError("Successfully set up MCP change notifications");
|
|
6813
|
+
if (server._lifecycleManager) {
|
|
6814
|
+
const originalClose = (_c = server.close) == null ? void 0 : _c.bind(server);
|
|
6815
|
+
server.close = async () => {
|
|
6816
|
+
logger.mcpError("MCP server shutdown initiated");
|
|
6817
|
+
try {
|
|
6818
|
+
await server._lifecycleManager.handleShutdown(
|
|
6819
|
+
"server_shutdown"
|
|
6820
|
+
);
|
|
6821
|
+
} catch (error) {
|
|
6822
|
+
logger.mcpError(
|
|
6823
|
+
`Error during lifecycle shutdown: ${error instanceof Error ? error.message : String(error)}`
|
|
6824
|
+
);
|
|
6825
|
+
}
|
|
6826
|
+
if (originalClose) {
|
|
6827
|
+
await originalClose();
|
|
6828
|
+
}
|
|
6829
|
+
};
|
|
6830
|
+
}
|
|
5795
6831
|
return server;
|
|
5796
6832
|
} catch (error) {
|
|
5797
6833
|
logger.mcpError(
|
|
@@ -5861,11 +6897,14 @@ Migration guide: https://github.com/alcyone-labs/arg-parser/blob/main/docs/MCP-M
|
|
|
5861
6897
|
}, logPath);
|
|
5862
6898
|
}
|
|
5863
6899
|
async parse(processArgs, options) {
|
|
6900
|
+
debug.log("ArgParser.parse() called with args:", processArgs);
|
|
6901
|
+
debug.log("About to call ArgParserBase.prototype.parse.call()");
|
|
5864
6902
|
let result = await ArgParserBase.prototype.parse.call(
|
|
5865
6903
|
this,
|
|
5866
6904
|
processArgs,
|
|
5867
6905
|
options
|
|
5868
6906
|
);
|
|
6907
|
+
debug.log("ArgParserBase.prototype.parse.call() returned:", typeof result);
|
|
5869
6908
|
const anyResult = result;
|
|
5870
6909
|
if (anyResult._fuzzyModePreventedExecution) {
|
|
5871
6910
|
return result;
|
|
@@ -6100,6 +7139,63 @@ Migration guide: https://github.com/alcyone-labs/arg-parser/blob/main/docs/MCP-M
|
|
|
6100
7139
|
}
|
|
6101
7140
|
};
|
|
6102
7141
|
_ArgParser_instances = new WeakSet();
|
|
7142
|
+
/**
|
|
7143
|
+
* Resolve logger configuration from various sources with proper priority
|
|
7144
|
+
* @param logPathOverride Optional log path override parameter
|
|
7145
|
+
* @returns Logger configuration object for createMcpLogger
|
|
7146
|
+
*/
|
|
7147
|
+
_resolveLoggerConfig_fn = function(logPathOverride) {
|
|
7148
|
+
const mcpConfig = this._mcpServerConfig;
|
|
7149
|
+
if (logPathOverride) {
|
|
7150
|
+
const resolvedPath = resolveLogPath(logPathOverride);
|
|
7151
|
+
return {
|
|
7152
|
+
prefix: "MCP Server Creation",
|
|
7153
|
+
logToFile: resolvedPath,
|
|
7154
|
+
level: "error",
|
|
7155
|
+
// Default level for backward compatibility
|
|
7156
|
+
mcpMode: true
|
|
7157
|
+
};
|
|
7158
|
+
}
|
|
7159
|
+
const hasLogConfig = mcpConfig == null ? void 0 : mcpConfig.log;
|
|
7160
|
+
const hasLogPath = mcpConfig == null ? void 0 : mcpConfig.logPath;
|
|
7161
|
+
if (hasLogConfig || hasLogPath) {
|
|
7162
|
+
let config = {
|
|
7163
|
+
prefix: "MCP Server Creation",
|
|
7164
|
+
level: "error",
|
|
7165
|
+
// Default level for backward compatibility
|
|
7166
|
+
mcpMode: true
|
|
7167
|
+
};
|
|
7168
|
+
if (hasLogConfig && mcpConfig.log) {
|
|
7169
|
+
if (typeof mcpConfig.log === "string") {
|
|
7170
|
+
config.logToFile = resolveLogPath(mcpConfig.log);
|
|
7171
|
+
} else {
|
|
7172
|
+
config = {
|
|
7173
|
+
...config,
|
|
7174
|
+
...mcpConfig.log,
|
|
7175
|
+
// Resolve logToFile path if provided in log config
|
|
7176
|
+
...mcpConfig.log.logToFile && {
|
|
7177
|
+
logToFile: resolveLogPath(mcpConfig.log.logToFile)
|
|
7178
|
+
}
|
|
7179
|
+
};
|
|
7180
|
+
}
|
|
7181
|
+
}
|
|
7182
|
+
if (hasLogPath && mcpConfig.logPath && !config.logToFile) {
|
|
7183
|
+
config.logToFile = resolveLogPath(mcpConfig.logPath);
|
|
7184
|
+
}
|
|
7185
|
+
if (hasLogPath && mcpConfig.logPath && hasLogConfig && mcpConfig.log && typeof mcpConfig.log === "object" && mcpConfig.log.logToFile) {
|
|
7186
|
+
config.logToFile = resolveLogPath(mcpConfig.logPath);
|
|
7187
|
+
}
|
|
7188
|
+
return config;
|
|
7189
|
+
}
|
|
7190
|
+
const defaultPath = resolveLogPath("./logs/mcp.log");
|
|
7191
|
+
return {
|
|
7192
|
+
prefix: "MCP Server Creation",
|
|
7193
|
+
logToFile: defaultPath,
|
|
7194
|
+
level: "error",
|
|
7195
|
+
// Default level for backward compatibility
|
|
7196
|
+
mcpMode: true
|
|
7197
|
+
};
|
|
7198
|
+
};
|
|
6103
7199
|
/**
|
|
6104
7200
|
* Register a tool as a CLI subcommand
|
|
6105
7201
|
* @private
|
|
@@ -6873,53 +7969,62 @@ const SUPPORTED_PROTOCOL_VERSIONS = [
|
|
|
6873
7969
|
const JSONRPC_VERSION = "2.0";
|
|
6874
7970
|
const ProgressTokenSchema = zod.z.union([zod.z.string(), zod.z.number().int()]);
|
|
6875
7971
|
const CursorSchema = zod.z.string();
|
|
6876
|
-
const RequestMetaSchema = zod.z.
|
|
7972
|
+
const RequestMetaSchema = zod.z.looseObject({
|
|
6877
7973
|
/**
|
|
6878
7974
|
* If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
|
|
6879
7975
|
*/
|
|
6880
7976
|
progressToken: zod.z.optional(ProgressTokenSchema)
|
|
6881
|
-
})
|
|
6882
|
-
const BaseRequestParamsSchema = zod.z.
|
|
7977
|
+
});
|
|
7978
|
+
const BaseRequestParamsSchema = zod.z.looseObject({
|
|
6883
7979
|
_meta: zod.z.optional(RequestMetaSchema)
|
|
6884
|
-
})
|
|
7980
|
+
});
|
|
6885
7981
|
const RequestSchema = zod.z.object({
|
|
6886
7982
|
method: zod.z.string(),
|
|
6887
7983
|
params: zod.z.optional(BaseRequestParamsSchema)
|
|
6888
7984
|
});
|
|
6889
|
-
const BaseNotificationParamsSchema = zod.z.
|
|
7985
|
+
const BaseNotificationParamsSchema = zod.z.looseObject({
|
|
6890
7986
|
/**
|
|
6891
7987
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
6892
7988
|
* for notes on _meta usage.
|
|
6893
7989
|
*/
|
|
6894
|
-
_meta: zod.z.optional(zod.z.
|
|
6895
|
-
})
|
|
7990
|
+
_meta: zod.z.optional(zod.z.looseObject({}))
|
|
7991
|
+
});
|
|
6896
7992
|
const NotificationSchema = zod.z.object({
|
|
6897
7993
|
method: zod.z.string(),
|
|
6898
7994
|
params: zod.z.optional(BaseNotificationParamsSchema)
|
|
6899
7995
|
});
|
|
6900
|
-
const ResultSchema = zod.z.
|
|
7996
|
+
const ResultSchema = zod.z.looseObject({
|
|
6901
7997
|
/**
|
|
6902
7998
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
6903
7999
|
* for notes on _meta usage.
|
|
6904
8000
|
*/
|
|
6905
|
-
_meta: zod.z.optional(zod.z.
|
|
6906
|
-
})
|
|
8001
|
+
_meta: zod.z.optional(zod.z.looseObject({}))
|
|
8002
|
+
});
|
|
6907
8003
|
const RequestIdSchema = zod.z.union([zod.z.string(), zod.z.number().int()]);
|
|
6908
|
-
const JSONRPCRequestSchema = zod.z.
|
|
8004
|
+
const JSONRPCRequestSchema = zod.z.strictObject({
|
|
6909
8005
|
jsonrpc: zod.z.literal(JSONRPC_VERSION),
|
|
6910
8006
|
id: RequestIdSchema
|
|
6911
|
-
}).
|
|
6912
|
-
const isJSONRPCRequest = (value) =>
|
|
6913
|
-
const
|
|
8007
|
+
}).extend(RequestSchema.shape);
|
|
8008
|
+
const isJSONRPCRequest = (value) => {
|
|
8009
|
+
const result = JSONRPCRequestSchema.safeParse(value);
|
|
8010
|
+
return result.success;
|
|
8011
|
+
};
|
|
8012
|
+
const JSONRPCNotificationSchema = zod.z.strictObject({
|
|
6914
8013
|
jsonrpc: zod.z.literal(JSONRPC_VERSION)
|
|
6915
|
-
}).
|
|
6916
|
-
const isJSONRPCNotification = (value) =>
|
|
6917
|
-
const
|
|
8014
|
+
}).extend(NotificationSchema.shape);
|
|
8015
|
+
const isJSONRPCNotification = (value) => {
|
|
8016
|
+
const result = JSONRPCNotificationSchema.safeParse(value);
|
|
8017
|
+
return result.success;
|
|
8018
|
+
};
|
|
8019
|
+
const JSONRPCResponseSchema = zod.z.strictObject({
|
|
6918
8020
|
jsonrpc: zod.z.literal(JSONRPC_VERSION),
|
|
6919
8021
|
id: RequestIdSchema,
|
|
6920
8022
|
result: ResultSchema
|
|
6921
|
-
})
|
|
6922
|
-
const isJSONRPCResponse = (value) =>
|
|
8023
|
+
});
|
|
8024
|
+
const isJSONRPCResponse = (value) => {
|
|
8025
|
+
const result = JSONRPCResponseSchema.safeParse(value);
|
|
8026
|
+
return result.success;
|
|
8027
|
+
};
|
|
6923
8028
|
var ErrorCode;
|
|
6924
8029
|
(function(ErrorCode2) {
|
|
6925
8030
|
ErrorCode2[ErrorCode2["ConnectionClosed"] = -32e3] = "ConnectionClosed";
|
|
@@ -6930,7 +8035,7 @@ var ErrorCode;
|
|
|
6930
8035
|
ErrorCode2[ErrorCode2["InvalidParams"] = -32602] = "InvalidParams";
|
|
6931
8036
|
ErrorCode2[ErrorCode2["InternalError"] = -32603] = "InternalError";
|
|
6932
8037
|
})(ErrorCode || (ErrorCode = {}));
|
|
6933
|
-
const JSONRPCErrorSchema = zod.z.
|
|
8038
|
+
const JSONRPCErrorSchema = zod.z.strictObject({
|
|
6934
8039
|
jsonrpc: zod.z.literal(JSONRPC_VERSION),
|
|
6935
8040
|
id: RequestIdSchema,
|
|
6936
8041
|
error: zod.z.object({
|
|
@@ -6947,15 +8052,18 @@ const JSONRPCErrorSchema = zod.z.object({
|
|
|
6947
8052
|
*/
|
|
6948
8053
|
data: zod.z.optional(zod.z.unknown())
|
|
6949
8054
|
})
|
|
6950
|
-
})
|
|
6951
|
-
const isJSONRPCError = (value) =>
|
|
8055
|
+
});
|
|
8056
|
+
const isJSONRPCError = (value) => {
|
|
8057
|
+
const result = JSONRPCErrorSchema.safeParse(value);
|
|
8058
|
+
return result.success;
|
|
8059
|
+
};
|
|
6952
8060
|
const JSONRPCMessageSchema = zod.z.union([
|
|
6953
8061
|
JSONRPCRequestSchema,
|
|
6954
8062
|
JSONRPCNotificationSchema,
|
|
6955
8063
|
JSONRPCResponseSchema,
|
|
6956
8064
|
JSONRPCErrorSchema
|
|
6957
8065
|
]);
|
|
6958
|
-
const EmptyResultSchema =
|
|
8066
|
+
const EmptyResultSchema = zod.z.strictObject({}).extend(ResultSchema.shape);
|
|
6959
8067
|
const CancelledNotificationSchema = NotificationSchema.extend({
|
|
6960
8068
|
method: zod.z.literal("notifications/cancelled"),
|
|
6961
8069
|
params: BaseNotificationParamsSchema.extend({
|
|
@@ -6971,19 +8079,19 @@ const CancelledNotificationSchema = NotificationSchema.extend({
|
|
|
6971
8079
|
reason: zod.z.string().optional()
|
|
6972
8080
|
})
|
|
6973
8081
|
});
|
|
6974
|
-
const BaseMetadataSchema = zod.z.
|
|
8082
|
+
const BaseMetadataSchema = zod.z.looseObject({
|
|
6975
8083
|
/** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
|
|
6976
8084
|
name: zod.z.string(),
|
|
6977
8085
|
/**
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
6982
|
-
|
|
6983
|
-
|
|
6984
|
-
|
|
8086
|
+
* Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
|
|
8087
|
+
* even by those unfamiliar with domain-specific terminology.
|
|
8088
|
+
*
|
|
8089
|
+
* If not provided, the name should be used for display (except for Tool,
|
|
8090
|
+
* where `annotations.title` should be given precedence over using `name`,
|
|
8091
|
+
* if present).
|
|
8092
|
+
*/
|
|
6985
8093
|
title: zod.z.optional(zod.z.string())
|
|
6986
|
-
})
|
|
8094
|
+
});
|
|
6987
8095
|
const ImplementationSchema = BaseMetadataSchema.extend({
|
|
6988
8096
|
version: zod.z.string()
|
|
6989
8097
|
});
|
|
@@ -7021,7 +8129,10 @@ const InitializeRequestSchema = RequestSchema.extend({
|
|
|
7021
8129
|
clientInfo: ImplementationSchema
|
|
7022
8130
|
})
|
|
7023
8131
|
});
|
|
7024
|
-
const isInitializeRequest = (value) =>
|
|
8132
|
+
const isInitializeRequest = (value) => {
|
|
8133
|
+
const result = InitializeRequestSchema.safeParse(value);
|
|
8134
|
+
return result.success;
|
|
8135
|
+
};
|
|
7025
8136
|
const ServerCapabilitiesSchema = zod.z.object({
|
|
7026
8137
|
/**
|
|
7027
8138
|
* Experimental, non-standard capabilities that the server supports.
|
|
@@ -7103,7 +8214,8 @@ const ProgressSchema = zod.z.object({
|
|
|
7103
8214
|
}).passthrough();
|
|
7104
8215
|
const ProgressNotificationSchema = NotificationSchema.extend({
|
|
7105
8216
|
method: zod.z.literal("notifications/progress"),
|
|
7106
|
-
params: BaseNotificationParamsSchema.
|
|
8217
|
+
params: BaseNotificationParamsSchema.extend({
|
|
8218
|
+
...ProgressSchema.shape,
|
|
7107
8219
|
/**
|
|
7108
8220
|
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
|
|
7109
8221
|
*/
|
|
@@ -7126,7 +8238,7 @@ const PaginatedResultSchema = ResultSchema.extend({
|
|
|
7126
8238
|
*/
|
|
7127
8239
|
nextCursor: zod.z.optional(CursorSchema)
|
|
7128
8240
|
});
|
|
7129
|
-
const ResourceContentsSchema = zod.z.
|
|
8241
|
+
const ResourceContentsSchema = zod.z.looseObject({
|
|
7130
8242
|
/**
|
|
7131
8243
|
* The URI of this resource.
|
|
7132
8244
|
*/
|
|
@@ -7139,19 +8251,27 @@ const ResourceContentsSchema = zod.z.object({
|
|
|
7139
8251
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
7140
8252
|
* for notes on _meta usage.
|
|
7141
8253
|
*/
|
|
7142
|
-
_meta: zod.z.optional(zod.z.
|
|
7143
|
-
})
|
|
8254
|
+
_meta: zod.z.optional(zod.z.looseObject({}))
|
|
8255
|
+
});
|
|
7144
8256
|
const TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
7145
8257
|
/**
|
|
7146
8258
|
* The text of the item. This must only be set if the item can actually be represented as text (not binary data).
|
|
7147
8259
|
*/
|
|
7148
8260
|
text: zod.z.string()
|
|
7149
8261
|
});
|
|
8262
|
+
const Base64Schema = zod.z.string().refine((val) => {
|
|
8263
|
+
try {
|
|
8264
|
+
atob(val);
|
|
8265
|
+
return true;
|
|
8266
|
+
} catch (_a) {
|
|
8267
|
+
return false;
|
|
8268
|
+
}
|
|
8269
|
+
}, { message: "Invalid Base64 string" });
|
|
7150
8270
|
const BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
7151
8271
|
/**
|
|
7152
8272
|
* A base64-encoded string representing the binary data of the item.
|
|
7153
8273
|
*/
|
|
7154
|
-
blob:
|
|
8274
|
+
blob: Base64Schema
|
|
7155
8275
|
});
|
|
7156
8276
|
const ResourceSchema = BaseMetadataSchema.extend({
|
|
7157
8277
|
/**
|
|
@@ -7249,7 +8369,7 @@ const ResourceUpdatedNotificationSchema = NotificationSchema.extend({
|
|
|
7249
8369
|
uri: zod.z.string()
|
|
7250
8370
|
})
|
|
7251
8371
|
});
|
|
7252
|
-
const PromptArgumentSchema = zod.z.
|
|
8372
|
+
const PromptArgumentSchema = zod.z.looseObject({
|
|
7253
8373
|
/**
|
|
7254
8374
|
* The name of the argument.
|
|
7255
8375
|
*/
|
|
@@ -7259,10 +8379,10 @@ const PromptArgumentSchema = zod.z.object({
|
|
|
7259
8379
|
*/
|
|
7260
8380
|
description: zod.z.optional(zod.z.string()),
|
|
7261
8381
|
/**
|
|
7262
|
-
* Whether this argument
|
|
8382
|
+
* Whether this argument is required.
|
|
7263
8383
|
*/
|
|
7264
8384
|
required: zod.z.optional(zod.z.boolean())
|
|
7265
|
-
})
|
|
8385
|
+
});
|
|
7266
8386
|
const PromptSchema = BaseMetadataSchema.extend({
|
|
7267
8387
|
/**
|
|
7268
8388
|
* An optional description of what this prompt provides
|
|
@@ -7294,10 +8414,10 @@ const GetPromptRequestSchema = RequestSchema.extend({
|
|
|
7294
8414
|
/**
|
|
7295
8415
|
* Arguments to use for templating the prompt.
|
|
7296
8416
|
*/
|
|
7297
|
-
arguments: zod.z.optional(zod.z.record(zod.z.string()))
|
|
8417
|
+
arguments: zod.z.optional(zod.z.record(zod.z.string(), zod.z.string()))
|
|
7298
8418
|
})
|
|
7299
8419
|
});
|
|
7300
|
-
const TextContentSchema = zod.z.
|
|
8420
|
+
const TextContentSchema = zod.z.looseObject({
|
|
7301
8421
|
type: zod.z.literal("text"),
|
|
7302
8422
|
/**
|
|
7303
8423
|
* The text content of the message.
|
|
@@ -7307,14 +8427,14 @@ const TextContentSchema = zod.z.object({
|
|
|
7307
8427
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
7308
8428
|
* for notes on _meta usage.
|
|
7309
8429
|
*/
|
|
7310
|
-
_meta: zod.z.optional(zod.z.
|
|
7311
|
-
})
|
|
7312
|
-
const ImageContentSchema = zod.z.
|
|
8430
|
+
_meta: zod.z.optional(zod.z.looseObject({}))
|
|
8431
|
+
});
|
|
8432
|
+
const ImageContentSchema = zod.z.looseObject({
|
|
7313
8433
|
type: zod.z.literal("image"),
|
|
7314
8434
|
/**
|
|
7315
8435
|
* The base64-encoded image data.
|
|
7316
8436
|
*/
|
|
7317
|
-
data:
|
|
8437
|
+
data: Base64Schema,
|
|
7318
8438
|
/**
|
|
7319
8439
|
* The MIME type of the image. Different providers may support different image types.
|
|
7320
8440
|
*/
|
|
@@ -7323,14 +8443,14 @@ const ImageContentSchema = zod.z.object({
|
|
|
7323
8443
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
7324
8444
|
* for notes on _meta usage.
|
|
7325
8445
|
*/
|
|
7326
|
-
_meta: zod.z.optional(zod.z.
|
|
7327
|
-
})
|
|
7328
|
-
const AudioContentSchema = zod.z.
|
|
8446
|
+
_meta: zod.z.optional(zod.z.looseObject({}))
|
|
8447
|
+
});
|
|
8448
|
+
const AudioContentSchema = zod.z.looseObject({
|
|
7329
8449
|
type: zod.z.literal("audio"),
|
|
7330
8450
|
/**
|
|
7331
8451
|
* The base64-encoded audio data.
|
|
7332
8452
|
*/
|
|
7333
|
-
data:
|
|
8453
|
+
data: Base64Schema,
|
|
7334
8454
|
/**
|
|
7335
8455
|
* The MIME type of the audio. Different providers may support different audio types.
|
|
7336
8456
|
*/
|
|
@@ -7339,17 +8459,17 @@ const AudioContentSchema = zod.z.object({
|
|
|
7339
8459
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
7340
8460
|
* for notes on _meta usage.
|
|
7341
8461
|
*/
|
|
7342
|
-
_meta: zod.z.optional(zod.z.
|
|
7343
|
-
})
|
|
7344
|
-
const EmbeddedResourceSchema = zod.z.
|
|
8462
|
+
_meta: zod.z.optional(zod.z.looseObject({}))
|
|
8463
|
+
});
|
|
8464
|
+
const EmbeddedResourceSchema = zod.z.looseObject({
|
|
7345
8465
|
type: zod.z.literal("resource"),
|
|
7346
8466
|
resource: zod.z.union([TextResourceContentsSchema, BlobResourceContentsSchema]),
|
|
7347
8467
|
/**
|
|
7348
8468
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
7349
8469
|
* for notes on _meta usage.
|
|
7350
8470
|
*/
|
|
7351
|
-
_meta: zod.z.optional(zod.z.
|
|
7352
|
-
})
|
|
8471
|
+
_meta: zod.z.optional(zod.z.looseObject({}))
|
|
8472
|
+
});
|
|
7353
8473
|
const ResourceLinkSchema = ResourceSchema.extend({
|
|
7354
8474
|
type: zod.z.literal("resource_link")
|
|
7355
8475
|
});
|
|
@@ -7360,10 +8480,10 @@ const ContentBlockSchema = zod.z.union([
|
|
|
7360
8480
|
ResourceLinkSchema,
|
|
7361
8481
|
EmbeddedResourceSchema
|
|
7362
8482
|
]);
|
|
7363
|
-
const PromptMessageSchema = zod.z.
|
|
8483
|
+
const PromptMessageSchema = zod.z.looseObject({
|
|
7364
8484
|
role: zod.z.enum(["user", "assistant"]),
|
|
7365
8485
|
content: ContentBlockSchema
|
|
7366
|
-
})
|
|
8486
|
+
});
|
|
7367
8487
|
const GetPromptResultSchema = ResultSchema.extend({
|
|
7368
8488
|
/**
|
|
7369
8489
|
* An optional description for the prompt.
|
|
@@ -7423,18 +8543,18 @@ const ToolSchema = BaseMetadataSchema.extend({
|
|
|
7423
8543
|
*/
|
|
7424
8544
|
inputSchema: zod.z.object({
|
|
7425
8545
|
type: zod.z.literal("object"),
|
|
7426
|
-
properties: zod.z.optional(zod.z.
|
|
8546
|
+
properties: zod.z.optional(zod.z.looseObject({})),
|
|
7427
8547
|
required: zod.z.optional(zod.z.array(zod.z.string()))
|
|
7428
|
-
})
|
|
8548
|
+
}),
|
|
7429
8549
|
/**
|
|
7430
8550
|
* An optional JSON Schema object defining the structure of the tool's output returned in
|
|
7431
8551
|
* the structuredContent field of a CallToolResult.
|
|
7432
8552
|
*/
|
|
7433
|
-
outputSchema: zod.z.optional(zod.z.
|
|
8553
|
+
outputSchema: zod.z.optional(zod.z.looseObject({
|
|
7434
8554
|
type: zod.z.literal("object"),
|
|
7435
|
-
properties: zod.z.optional(zod.z.
|
|
8555
|
+
properties: zod.z.optional(zod.z.looseObject({})),
|
|
7436
8556
|
required: zod.z.optional(zod.z.array(zod.z.string()))
|
|
7437
|
-
})
|
|
8557
|
+
})),
|
|
7438
8558
|
/**
|
|
7439
8559
|
* Optional additional tool information.
|
|
7440
8560
|
*/
|
|
@@ -7464,7 +8584,7 @@ const CallToolResultSchema = ResultSchema.extend({
|
|
|
7464
8584
|
*
|
|
7465
8585
|
* If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
|
|
7466
8586
|
*/
|
|
7467
|
-
structuredContent: zod.z.
|
|
8587
|
+
structuredContent: zod.z.looseObject({}).optional(),
|
|
7468
8588
|
/**
|
|
7469
8589
|
* Whether the tool call ended in an error.
|
|
7470
8590
|
*
|
|
@@ -7488,7 +8608,7 @@ const CallToolRequestSchema = RequestSchema.extend({
|
|
|
7488
8608
|
method: zod.z.literal("tools/call"),
|
|
7489
8609
|
params: BaseRequestParamsSchema.extend({
|
|
7490
8610
|
name: zod.z.string(),
|
|
7491
|
-
arguments: zod.z.optional(zod.z.record(zod.z.unknown()))
|
|
8611
|
+
arguments: zod.z.optional(zod.z.record(zod.z.string(), zod.z.unknown()))
|
|
7492
8612
|
})
|
|
7493
8613
|
});
|
|
7494
8614
|
const ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
@@ -7530,34 +8650,34 @@ const LoggingMessageNotificationSchema = NotificationSchema.extend({
|
|
|
7530
8650
|
data: zod.z.unknown()
|
|
7531
8651
|
})
|
|
7532
8652
|
});
|
|
7533
|
-
const ModelHintSchema = zod.z.
|
|
8653
|
+
const ModelHintSchema = zod.z.looseObject({
|
|
7534
8654
|
/**
|
|
7535
8655
|
* A hint for a model name.
|
|
7536
8656
|
*/
|
|
7537
8657
|
name: zod.z.string().optional()
|
|
7538
|
-
})
|
|
7539
|
-
const ModelPreferencesSchema = zod.z.
|
|
8658
|
+
});
|
|
8659
|
+
const ModelPreferencesSchema = zod.z.looseObject({
|
|
7540
8660
|
/**
|
|
7541
|
-
* Optional hints to use for model selection.
|
|
8661
|
+
* Optional hints to use for model selection. If multiple models are supported, the client MAY choose how to prioritize these hints to pick a model.
|
|
7542
8662
|
*/
|
|
7543
8663
|
hints: zod.z.optional(zod.z.array(ModelHintSchema)),
|
|
7544
8664
|
/**
|
|
7545
|
-
*
|
|
8665
|
+
* A hint for the model's cost priority. 0 = highest cost, 1 = lowest cost. The client MAY use this to decide which model to use.
|
|
7546
8666
|
*/
|
|
7547
8667
|
costPriority: zod.z.optional(zod.z.number().min(0).max(1)),
|
|
7548
8668
|
/**
|
|
7549
|
-
*
|
|
8669
|
+
* A hint for the model's speed priority. 0 = slowest, 1 = fastest. The client MAY use this to decide which model to use.
|
|
7550
8670
|
*/
|
|
7551
8671
|
speedPriority: zod.z.optional(zod.z.number().min(0).max(1)),
|
|
7552
8672
|
/**
|
|
7553
|
-
*
|
|
8673
|
+
* A hint for the model's intelligence priority. 0 = least intelligent, 1 = most intelligent. The client MAY use this to decide which model to use.
|
|
7554
8674
|
*/
|
|
7555
8675
|
intelligencePriority: zod.z.optional(zod.z.number().min(0).max(1))
|
|
7556
|
-
})
|
|
7557
|
-
const SamplingMessageSchema = zod.z.
|
|
8676
|
+
});
|
|
8677
|
+
const SamplingMessageSchema = zod.z.looseObject({
|
|
7558
8678
|
role: zod.z.enum(["user", "assistant"]),
|
|
7559
8679
|
content: zod.z.union([TextContentSchema, ImageContentSchema, AudioContentSchema])
|
|
7560
|
-
})
|
|
8680
|
+
});
|
|
7561
8681
|
const CreateMessageRequestSchema = RequestSchema.extend({
|
|
7562
8682
|
method: zod.z.literal("sampling/createMessage"),
|
|
7563
8683
|
params: BaseRequestParamsSchema.extend({
|
|
@@ -7579,7 +8699,7 @@ const CreateMessageRequestSchema = RequestSchema.extend({
|
|
|
7579
8699
|
/**
|
|
7580
8700
|
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
7581
8701
|
*/
|
|
7582
|
-
metadata: zod.z.optional(zod.z.
|
|
8702
|
+
metadata: zod.z.optional(zod.z.looseObject({})),
|
|
7583
8703
|
/**
|
|
7584
8704
|
* The server's preferences for which model to select.
|
|
7585
8705
|
*/
|
|
@@ -7602,12 +8722,12 @@ const CreateMessageResultSchema = ResultSchema.extend({
|
|
|
7602
8722
|
AudioContentSchema
|
|
7603
8723
|
])
|
|
7604
8724
|
});
|
|
7605
|
-
const BooleanSchemaSchema = zod.z.
|
|
8725
|
+
const BooleanSchemaSchema = zod.z.looseObject({
|
|
7606
8726
|
type: zod.z.literal("boolean"),
|
|
7607
8727
|
title: zod.z.optional(zod.z.string()),
|
|
7608
8728
|
description: zod.z.optional(zod.z.string()),
|
|
7609
8729
|
default: zod.z.optional(zod.z.boolean())
|
|
7610
|
-
})
|
|
8730
|
+
});
|
|
7611
8731
|
const StringSchemaSchema = zod.z.object({
|
|
7612
8732
|
type: zod.z.literal("string"),
|
|
7613
8733
|
title: zod.z.optional(zod.z.string()),
|
|
@@ -7646,11 +8766,11 @@ const ElicitRequestSchema = RequestSchema.extend({
|
|
|
7646
8766
|
/**
|
|
7647
8767
|
* The schema for the requested user input.
|
|
7648
8768
|
*/
|
|
7649
|
-
requestedSchema: zod.z.
|
|
8769
|
+
requestedSchema: zod.z.looseObject({
|
|
7650
8770
|
type: zod.z.literal("object"),
|
|
7651
8771
|
properties: zod.z.record(zod.z.string(), PrimitiveSchemaDefinitionSchema),
|
|
7652
8772
|
required: zod.z.optional(zod.z.array(zod.z.string()))
|
|
7653
|
-
})
|
|
8773
|
+
})
|
|
7654
8774
|
})
|
|
7655
8775
|
});
|
|
7656
8776
|
const ElicitResultSchema = ResultSchema.extend({
|
|
@@ -7733,7 +8853,7 @@ const RootSchema = zod.z.object({
|
|
|
7733
8853
|
*/
|
|
7734
8854
|
_meta: zod.z.optional(zod.z.object({}).passthrough())
|
|
7735
8855
|
}).passthrough();
|
|
7736
|
-
const ListRootsRequestSchema =
|
|
8856
|
+
const ListRootsRequestSchema = PaginatedRequestSchema.extend({
|
|
7737
8857
|
method: zod.z.literal("roots/list")
|
|
7738
8858
|
});
|
|
7739
8859
|
const ListRootsResultSchema = ResultSchema.extend({
|
|
@@ -7898,6 +9018,10 @@ class Protocol {
|
|
|
7898
9018
|
this._responseHandlers = /* @__PURE__ */ new Map();
|
|
7899
9019
|
this._progressHandlers.clear();
|
|
7900
9020
|
this._pendingDebouncedNotifications.clear();
|
|
9021
|
+
for (const info of this._timeoutInfo.values()) {
|
|
9022
|
+
clearTimeout(info.timeoutId);
|
|
9023
|
+
}
|
|
9024
|
+
this._timeoutInfo.clear();
|
|
7901
9025
|
this._transport = void 0;
|
|
7902
9026
|
(_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
7903
9027
|
const error = new McpError(ErrorCode.ConnectionClosed, "Connection closed");
|
|
@@ -7938,7 +9062,10 @@ class Protocol {
|
|
|
7938
9062
|
sessionId: (_c = this._transport) === null || _c === void 0 ? void 0 : _c.sessionId,
|
|
7939
9063
|
_meta: (_d = request.params) === null || _d === void 0 ? void 0 : _d._meta,
|
|
7940
9064
|
sendNotification: (notification) => this.notification(notification, { relatedRequestId: request.id }),
|
|
7941
|
-
sendRequest: (r, resultSchema, options) => this.request(r, resultSchema, {
|
|
9065
|
+
sendRequest: (r, resultSchema, options) => this.request(r, resultSchema, {
|
|
9066
|
+
...options,
|
|
9067
|
+
relatedRequestId: request.id
|
|
9068
|
+
}),
|
|
7942
9069
|
authInfo: extra === null || extra === void 0 ? void 0 : extra.authInfo,
|
|
7943
9070
|
requestId: request.id,
|
|
7944
9071
|
requestInfo: extra === null || extra === void 0 ? void 0 : extra.requestInfo
|
|
@@ -8014,8 +9141,13 @@ class Protocol {
|
|
|
8014
9141
|
* Closes the connection.
|
|
8015
9142
|
*/
|
|
8016
9143
|
async close() {
|
|
8017
|
-
|
|
8018
|
-
|
|
9144
|
+
const transport = this._transport;
|
|
9145
|
+
if (transport) {
|
|
9146
|
+
await transport.close();
|
|
9147
|
+
if (this._transport === transport) {
|
|
9148
|
+
this._onclose();
|
|
9149
|
+
}
|
|
9150
|
+
}
|
|
8019
9151
|
}
|
|
8020
9152
|
/**
|
|
8021
9153
|
* Sends a request and wait for a response.
|
|
@@ -8085,9 +9217,15 @@ class Protocol {
|
|
|
8085
9217
|
cancel((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.reason);
|
|
8086
9218
|
});
|
|
8087
9219
|
const timeout = (_e = options === null || options === void 0 ? void 0 : options.timeout) !== null && _e !== void 0 ? _e : DEFAULT_REQUEST_TIMEOUT_MSEC;
|
|
8088
|
-
const timeoutHandler = () => cancel(new McpError(ErrorCode.RequestTimeout, "Request timed out", {
|
|
9220
|
+
const timeoutHandler = () => cancel(new McpError(ErrorCode.RequestTimeout, "Request timed out", {
|
|
9221
|
+
timeout
|
|
9222
|
+
}));
|
|
8089
9223
|
this._setupTimeout(messageId, timeout, options === null || options === void 0 ? void 0 : options.maxTotalTimeout, timeoutHandler, (_f = options === null || options === void 0 ? void 0 : options.resetTimeoutOnProgress) !== null && _f !== void 0 ? _f : false);
|
|
8090
|
-
this._transport.send(jsonrpcRequest, {
|
|
9224
|
+
this._transport.send(jsonrpcRequest, {
|
|
9225
|
+
relatedRequestId,
|
|
9226
|
+
resumptionToken,
|
|
9227
|
+
onresumptiontoken
|
|
9228
|
+
}).catch((error) => {
|
|
8091
9229
|
this._cleanupTimeout(messageId);
|
|
8092
9230
|
reject(error);
|
|
8093
9231
|
});
|
|
@@ -13890,7 +15028,7 @@ function requireAjv() {
|
|
|
13890
15028
|
Ajv2.prototype.validateSchema = validateSchema;
|
|
13891
15029
|
Ajv2.prototype.getSchema = getSchema;
|
|
13892
15030
|
Ajv2.prototype.removeSchema = removeSchema;
|
|
13893
|
-
Ajv2.prototype.addFormat =
|
|
15031
|
+
Ajv2.prototype.addFormat = addFormat;
|
|
13894
15032
|
Ajv2.prototype.errorsText = errorsText;
|
|
13895
15033
|
Ajv2.prototype._addSchema = _addSchema;
|
|
13896
15034
|
Ajv2.prototype._compile = _compile;
|
|
@@ -14160,7 +15298,7 @@ function requireAjv() {
|
|
|
14160
15298
|
}
|
|
14161
15299
|
return text.slice(0, -separator.length);
|
|
14162
15300
|
}
|
|
14163
|
-
function
|
|
15301
|
+
function addFormat(name, format2) {
|
|
14164
15302
|
if (typeof format2 == "string") format2 = new RegExp(format2);
|
|
14165
15303
|
this._formats[name] = format2;
|
|
14166
15304
|
return this;
|
|
@@ -14403,1288 +15541,390 @@ class Server extends Protocol {
|
|
|
14403
15541
|
return this.notification({ method: "notifications/prompts/list_changed" });
|
|
14404
15542
|
}
|
|
14405
15543
|
}
|
|
14406
|
-
|
|
14407
|
-
|
|
14408
|
-
|
|
14409
|
-
|
|
14410
|
-
|
|
14411
|
-
|
|
14412
|
-
|
|
14413
|
-
|
|
14414
|
-
|
|
14415
|
-
|
|
14416
|
-
|
|
14417
|
-
|
|
14418
|
-
|
|
14419
|
-
|
|
14420
|
-
|
|
14421
|
-
|
|
14422
|
-
|
|
14423
|
-
|
|
14424
|
-
|
|
14425
|
-
|
|
14426
|
-
|
|
14427
|
-
|
|
14428
|
-
|
|
14429
|
-
|
|
14430
|
-
|
|
14431
|
-
|
|
14432
|
-
|
|
14433
|
-
|
|
14434
|
-
|
|
14435
|
-
|
|
14436
|
-
|
|
14437
|
-
};
|
|
14438
|
-
const getRefs = (options) => {
|
|
14439
|
-
const _options = getDefaultOptions(options);
|
|
14440
|
-
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
14441
|
-
return {
|
|
14442
|
-
..._options,
|
|
14443
|
-
flags: { hasReferencedOpenAiAnyType: false },
|
|
14444
|
-
currentPath,
|
|
14445
|
-
propertyPath: void 0,
|
|
14446
|
-
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
|
|
14447
|
-
def._def,
|
|
14448
|
-
{
|
|
14449
|
-
def: def._def,
|
|
14450
|
-
path: [..._options.basePath, _options.definitionPath, name],
|
|
14451
|
-
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
14452
|
-
jsonSchema: void 0
|
|
14453
|
-
}
|
|
14454
|
-
]))
|
|
14455
|
-
};
|
|
14456
|
-
};
|
|
14457
|
-
function addErrorMessage(res, key, errorMessage, refs) {
|
|
14458
|
-
if (!(refs == null ? void 0 : refs.errorMessages))
|
|
14459
|
-
return;
|
|
14460
|
-
if (errorMessage) {
|
|
14461
|
-
res.errorMessage = {
|
|
14462
|
-
...res.errorMessage,
|
|
14463
|
-
[key]: errorMessage
|
|
15544
|
+
var McpZodTypeKind;
|
|
15545
|
+
(function(McpZodTypeKind2) {
|
|
15546
|
+
McpZodTypeKind2["Completable"] = "McpCompletable";
|
|
15547
|
+
})(McpZodTypeKind || (McpZodTypeKind = {}));
|
|
15548
|
+
class Completable {
|
|
15549
|
+
// ZodType compatibility properties
|
|
15550
|
+
get _output() {
|
|
15551
|
+
return this._wrappedType._output;
|
|
15552
|
+
}
|
|
15553
|
+
get _input() {
|
|
15554
|
+
return this._wrappedType._input;
|
|
15555
|
+
}
|
|
15556
|
+
get def() {
|
|
15557
|
+
return this._wrappedType.def;
|
|
15558
|
+
}
|
|
15559
|
+
get type() {
|
|
15560
|
+
return this._wrappedType.type;
|
|
15561
|
+
}
|
|
15562
|
+
get _zod() {
|
|
15563
|
+
return this._wrappedType._zod;
|
|
15564
|
+
}
|
|
15565
|
+
get "~standard"() {
|
|
15566
|
+
return this._wrappedType["~standard"];
|
|
15567
|
+
}
|
|
15568
|
+
constructor(type2, complete) {
|
|
15569
|
+
this._wrappedType = type2;
|
|
15570
|
+
this._def = {
|
|
15571
|
+
type: type2._def.type,
|
|
15572
|
+
complete,
|
|
15573
|
+
typeName: McpZodTypeKind.Completable,
|
|
15574
|
+
wrappedType: type2
|
|
14464
15575
|
};
|
|
14465
15576
|
}
|
|
14466
|
-
|
|
14467
|
-
|
|
14468
|
-
|
|
14469
|
-
addErrorMessage(res, key, errorMessage, refs);
|
|
14470
|
-
}
|
|
14471
|
-
const getRelativePath = (pathA, pathB) => {
|
|
14472
|
-
let i = 0;
|
|
14473
|
-
for (; i < pathA.length && i < pathB.length; i++) {
|
|
14474
|
-
if (pathA[i] !== pathB[i])
|
|
14475
|
-
break;
|
|
15577
|
+
// Core parsing methods
|
|
15578
|
+
parse(input) {
|
|
15579
|
+
return this._wrappedType.parse(input);
|
|
14476
15580
|
}
|
|
14477
|
-
|
|
14478
|
-
|
|
14479
|
-
function parseAnyDef(refs) {
|
|
14480
|
-
if (refs.target !== "openAi") {
|
|
14481
|
-
return {};
|
|
14482
|
-
}
|
|
14483
|
-
const anyDefinitionPath = [
|
|
14484
|
-
...refs.basePath,
|
|
14485
|
-
refs.definitionPath,
|
|
14486
|
-
refs.openAiAnyTypeName
|
|
14487
|
-
];
|
|
14488
|
-
refs.flags.hasReferencedOpenAiAnyType = true;
|
|
14489
|
-
return {
|
|
14490
|
-
$ref: refs.$refStrategy === "relative" ? getRelativePath(anyDefinitionPath, refs.currentPath) : anyDefinitionPath.join("/")
|
|
14491
|
-
};
|
|
14492
|
-
}
|
|
14493
|
-
function parseArrayDef(def, refs) {
|
|
14494
|
-
var _a, _b, _c;
|
|
14495
|
-
const res = {
|
|
14496
|
-
type: "array"
|
|
14497
|
-
};
|
|
14498
|
-
if (((_a = def.type) == null ? void 0 : _a._def) && ((_c = (_b = def.type) == null ? void 0 : _b._def) == null ? void 0 : _c.typeName) !== zod.ZodFirstPartyTypeKind.ZodAny) {
|
|
14499
|
-
res.items = parseDef(def.type._def, {
|
|
14500
|
-
...refs,
|
|
14501
|
-
currentPath: [...refs.currentPath, "items"]
|
|
14502
|
-
});
|
|
15581
|
+
safeParse(input) {
|
|
15582
|
+
return this._wrappedType.safeParse(input);
|
|
14503
15583
|
}
|
|
14504
|
-
|
|
14505
|
-
|
|
15584
|
+
parseAsync(input) {
|
|
15585
|
+
return this._wrappedType.parseAsync(input);
|
|
14506
15586
|
}
|
|
14507
|
-
|
|
14508
|
-
|
|
15587
|
+
safeParseAsync(input) {
|
|
15588
|
+
return this._wrappedType.safeParseAsync(input);
|
|
14509
15589
|
}
|
|
14510
|
-
|
|
14511
|
-
|
|
14512
|
-
|
|
15590
|
+
// Schema manipulation methods
|
|
15591
|
+
optional() {
|
|
15592
|
+
return new Completable(this._wrappedType.optional(), this._def.complete);
|
|
14513
15593
|
}
|
|
14514
|
-
|
|
14515
|
-
|
|
14516
|
-
|
|
14517
|
-
|
|
14518
|
-
|
|
14519
|
-
|
|
14520
|
-
|
|
14521
|
-
|
|
14522
|
-
|
|
14523
|
-
|
|
14524
|
-
|
|
14525
|
-
|
|
14526
|
-
|
|
14527
|
-
|
|
14528
|
-
|
|
14529
|
-
|
|
14530
|
-
|
|
14531
|
-
|
|
14532
|
-
|
|
14533
|
-
|
|
14534
|
-
|
|
14535
|
-
|
|
14536
|
-
|
|
14537
|
-
|
|
14538
|
-
|
|
14539
|
-
|
|
14540
|
-
|
|
14541
|
-
|
|
14542
|
-
|
|
14543
|
-
|
|
14544
|
-
|
|
14545
|
-
|
|
14546
|
-
|
|
14547
|
-
|
|
14548
|
-
|
|
14549
|
-
|
|
14550
|
-
|
|
14551
|
-
|
|
14552
|
-
|
|
14553
|
-
|
|
14554
|
-
|
|
14555
|
-
|
|
14556
|
-
|
|
15594
|
+
nullable() {
|
|
15595
|
+
return new Completable(this._wrappedType.nullable(), this._def.complete);
|
|
15596
|
+
}
|
|
15597
|
+
nullish() {
|
|
15598
|
+
return new Completable(this._wrappedType.nullish(), this._def.complete);
|
|
15599
|
+
}
|
|
15600
|
+
nonoptional() {
|
|
15601
|
+
return new Completable(this._wrappedType.nonoptional(), this._def.complete);
|
|
15602
|
+
}
|
|
15603
|
+
array() {
|
|
15604
|
+
return this._wrappedType.array();
|
|
15605
|
+
}
|
|
15606
|
+
or(schema) {
|
|
15607
|
+
return this._wrappedType.or(schema);
|
|
15608
|
+
}
|
|
15609
|
+
and(schema) {
|
|
15610
|
+
return this._wrappedType.and(schema);
|
|
15611
|
+
}
|
|
15612
|
+
// Transformation methods
|
|
15613
|
+
transform(transformer) {
|
|
15614
|
+
return this._wrappedType.transform(transformer);
|
|
15615
|
+
}
|
|
15616
|
+
default(defaultValue) {
|
|
15617
|
+
return new Completable(this._wrappedType.default(defaultValue), this._def.complete);
|
|
15618
|
+
}
|
|
15619
|
+
catch(catchValue) {
|
|
15620
|
+
return new Completable(this._wrappedType.catch(catchValue), this._def.complete);
|
|
15621
|
+
}
|
|
15622
|
+
pipe(schema) {
|
|
15623
|
+
return this._wrappedType.pipe(schema);
|
|
15624
|
+
}
|
|
15625
|
+
// Additional ZodType v4 methods
|
|
15626
|
+
register(registry, ...meta) {
|
|
15627
|
+
return this._wrappedType.register(registry, ...meta);
|
|
15628
|
+
}
|
|
15629
|
+
spa(input) {
|
|
15630
|
+
return this._wrappedType.spa(input);
|
|
15631
|
+
}
|
|
15632
|
+
overwrite(overrides) {
|
|
15633
|
+
return new Completable(this._wrappedType.overwrite(overrides), this._def.complete);
|
|
15634
|
+
}
|
|
15635
|
+
prefault(prefaultValue) {
|
|
15636
|
+
return new Completable(this._wrappedType.prefault(prefaultValue), this._def.complete);
|
|
15637
|
+
}
|
|
15638
|
+
// Refinement methods
|
|
15639
|
+
refine(refinement, message) {
|
|
15640
|
+
return this._wrappedType.refine(refinement, message);
|
|
15641
|
+
}
|
|
15642
|
+
superRefine(refinement) {
|
|
15643
|
+
return this._wrappedType.superRefine(refinement);
|
|
15644
|
+
}
|
|
15645
|
+
// Utility methods
|
|
15646
|
+
readonly() {
|
|
15647
|
+
return this._wrappedType.readonly();
|
|
15648
|
+
}
|
|
15649
|
+
describe(description2) {
|
|
15650
|
+
return new Completable(this._wrappedType.describe(description2), this._def.complete);
|
|
15651
|
+
}
|
|
15652
|
+
meta(meta) {
|
|
15653
|
+
return this._wrappedType.meta(meta);
|
|
15654
|
+
}
|
|
15655
|
+
brand() {
|
|
15656
|
+
return this._wrappedType.brand();
|
|
15657
|
+
}
|
|
15658
|
+
check(check) {
|
|
15659
|
+
return this._wrappedType.check(check);
|
|
15660
|
+
}
|
|
15661
|
+
clone() {
|
|
15662
|
+
return new Completable(this._wrappedType.clone(), this._def.complete);
|
|
15663
|
+
}
|
|
15664
|
+
// Status check methods
|
|
15665
|
+
isOptional() {
|
|
15666
|
+
return this._wrappedType.isOptional();
|
|
15667
|
+
}
|
|
15668
|
+
isNullable() {
|
|
15669
|
+
return this._wrappedType.isNullable();
|
|
15670
|
+
}
|
|
15671
|
+
// Utility getters
|
|
15672
|
+
get description() {
|
|
15673
|
+
return this._wrappedType.description;
|
|
15674
|
+
}
|
|
15675
|
+
// Completable-specific methods
|
|
15676
|
+
unwrap() {
|
|
15677
|
+
return this._def.wrappedType;
|
|
15678
|
+
}
|
|
15679
|
+
async complete(value, context) {
|
|
15680
|
+
return this._def.complete(value, context);
|
|
14557
15681
|
}
|
|
14558
|
-
return res;
|
|
14559
|
-
}
|
|
14560
|
-
function parseBooleanDef() {
|
|
14561
|
-
return {
|
|
14562
|
-
type: "boolean"
|
|
14563
|
-
};
|
|
14564
|
-
}
|
|
14565
|
-
function parseBrandedDef(_def, refs) {
|
|
14566
|
-
return parseDef(_def.type._def, refs);
|
|
14567
15682
|
}
|
|
14568
|
-
|
|
14569
|
-
return
|
|
15683
|
+
Completable.create = (type2, complete) => {
|
|
15684
|
+
return new Completable(type2, complete);
|
|
14570
15685
|
};
|
|
14571
|
-
|
|
14572
|
-
|
|
14573
|
-
|
|
14574
|
-
|
|
14575
|
-
|
|
14576
|
-
|
|
15686
|
+
const MAX_TEMPLATE_LENGTH = 1e6;
|
|
15687
|
+
const MAX_VARIABLE_LENGTH = 1e6;
|
|
15688
|
+
const MAX_TEMPLATE_EXPRESSIONS = 1e4;
|
|
15689
|
+
const MAX_REGEX_LENGTH = 1e6;
|
|
15690
|
+
class UriTemplate {
|
|
15691
|
+
/**
|
|
15692
|
+
* Returns true if the given string contains any URI template expressions.
|
|
15693
|
+
* A template expression is a sequence of characters enclosed in curly braces,
|
|
15694
|
+
* like {foo} or {?bar}.
|
|
15695
|
+
*/
|
|
15696
|
+
static isTemplate(str) {
|
|
15697
|
+
return /\{[^}\s]+\}/.test(str);
|
|
14577
15698
|
}
|
|
14578
|
-
|
|
14579
|
-
|
|
14580
|
-
|
|
14581
|
-
|
|
14582
|
-
type: "string",
|
|
14583
|
-
format: "date-time"
|
|
14584
|
-
};
|
|
14585
|
-
case "format:date":
|
|
14586
|
-
return {
|
|
14587
|
-
type: "string",
|
|
14588
|
-
format: "date"
|
|
14589
|
-
};
|
|
14590
|
-
case "integer":
|
|
14591
|
-
return integerDateParser(def, refs);
|
|
15699
|
+
static validateLength(str, max, context) {
|
|
15700
|
+
if (str.length > max) {
|
|
15701
|
+
throw new Error(`${context} exceeds maximum length of ${max} characters (got ${str.length})`);
|
|
15702
|
+
}
|
|
14592
15703
|
}
|
|
14593
|
-
|
|
14594
|
-
|
|
14595
|
-
const res = {
|
|
14596
|
-
type: "integer",
|
|
14597
|
-
format: "unix-time"
|
|
14598
|
-
};
|
|
14599
|
-
if (refs.target === "openApi3") {
|
|
14600
|
-
return res;
|
|
15704
|
+
get variableNames() {
|
|
15705
|
+
return this.parts.flatMap((part) => typeof part === "string" ? [] : part.names);
|
|
14601
15706
|
}
|
|
14602
|
-
|
|
14603
|
-
|
|
14604
|
-
|
|
14605
|
-
|
|
14606
|
-
|
|
14607
|
-
|
|
14608
|
-
|
|
14609
|
-
|
|
14610
|
-
|
|
14611
|
-
|
|
14612
|
-
|
|
15707
|
+
constructor(template) {
|
|
15708
|
+
UriTemplate.validateLength(template, MAX_TEMPLATE_LENGTH, "Template");
|
|
15709
|
+
this.template = template;
|
|
15710
|
+
this.parts = this.parse(template);
|
|
15711
|
+
}
|
|
15712
|
+
toString() {
|
|
15713
|
+
return this.template;
|
|
15714
|
+
}
|
|
15715
|
+
parse(template) {
|
|
15716
|
+
const parts = [];
|
|
15717
|
+
let currentText = "";
|
|
15718
|
+
let i = 0;
|
|
15719
|
+
let expressionCount = 0;
|
|
15720
|
+
while (i < template.length) {
|
|
15721
|
+
if (template[i] === "{") {
|
|
15722
|
+
if (currentText) {
|
|
15723
|
+
parts.push(currentText);
|
|
15724
|
+
currentText = "";
|
|
15725
|
+
}
|
|
15726
|
+
const end = template.indexOf("}", i);
|
|
15727
|
+
if (end === -1)
|
|
15728
|
+
throw new Error("Unclosed template expression");
|
|
15729
|
+
expressionCount++;
|
|
15730
|
+
if (expressionCount > MAX_TEMPLATE_EXPRESSIONS) {
|
|
15731
|
+
throw new Error(`Template contains too many expressions (max ${MAX_TEMPLATE_EXPRESSIONS})`);
|
|
15732
|
+
}
|
|
15733
|
+
const expr = template.slice(i + 1, end);
|
|
15734
|
+
const operator = this.getOperator(expr);
|
|
15735
|
+
const exploded = expr.includes("*");
|
|
15736
|
+
const names = this.getNames(expr);
|
|
15737
|
+
const name = names[0];
|
|
15738
|
+
for (const name2 of names) {
|
|
15739
|
+
UriTemplate.validateLength(name2, MAX_VARIABLE_LENGTH, "Variable name");
|
|
15740
|
+
}
|
|
15741
|
+
parts.push({ name, operator, names, exploded });
|
|
15742
|
+
i = end + 1;
|
|
15743
|
+
} else {
|
|
15744
|
+
currentText += template[i];
|
|
15745
|
+
i++;
|
|
15746
|
+
}
|
|
15747
|
+
}
|
|
15748
|
+
if (currentText) {
|
|
15749
|
+
parts.push(currentText);
|
|
15750
|
+
}
|
|
15751
|
+
return parts;
|
|
15752
|
+
}
|
|
15753
|
+
getOperator(expr) {
|
|
15754
|
+
const operators = ["+", "#", ".", "/", "?", "&"];
|
|
15755
|
+
return operators.find((op) => expr.startsWith(op)) || "";
|
|
15756
|
+
}
|
|
15757
|
+
getNames(expr) {
|
|
15758
|
+
const operator = this.getOperator(expr);
|
|
15759
|
+
return expr.slice(operator.length).split(",").map((name) => name.replace("*", "").trim()).filter((name) => name.length > 0);
|
|
15760
|
+
}
|
|
15761
|
+
encodeValue(value, operator) {
|
|
15762
|
+
UriTemplate.validateLength(value, MAX_VARIABLE_LENGTH, "Variable value");
|
|
15763
|
+
if (operator === "+" || operator === "#") {
|
|
15764
|
+
return encodeURI(value);
|
|
15765
|
+
}
|
|
15766
|
+
return encodeURIComponent(value);
|
|
15767
|
+
}
|
|
15768
|
+
expandPart(part, variables) {
|
|
15769
|
+
if (part.operator === "?" || part.operator === "&") {
|
|
15770
|
+
const pairs = part.names.map((name) => {
|
|
15771
|
+
const value2 = variables[name];
|
|
15772
|
+
if (value2 === void 0)
|
|
15773
|
+
return "";
|
|
15774
|
+
const encoded2 = Array.isArray(value2) ? value2.map((v) => this.encodeValue(v, part.operator)).join(",") : this.encodeValue(value2.toString(), part.operator);
|
|
15775
|
+
return `${name}=${encoded2}`;
|
|
15776
|
+
}).filter((pair) => pair.length > 0);
|
|
15777
|
+
if (pairs.length === 0)
|
|
15778
|
+
return "";
|
|
15779
|
+
const separator = part.operator === "?" ? "?" : "&";
|
|
15780
|
+
return separator + pairs.join("&");
|
|
15781
|
+
}
|
|
15782
|
+
if (part.names.length > 1) {
|
|
15783
|
+
const values2 = part.names.map((name) => variables[name]).filter((v) => v !== void 0);
|
|
15784
|
+
if (values2.length === 0)
|
|
15785
|
+
return "";
|
|
15786
|
+
return values2.map((v) => Array.isArray(v) ? v[0] : v).join(",");
|
|
15787
|
+
}
|
|
15788
|
+
const value = variables[part.name];
|
|
15789
|
+
if (value === void 0)
|
|
15790
|
+
return "";
|
|
15791
|
+
const values = Array.isArray(value) ? value : [value];
|
|
15792
|
+
const encoded = values.map((v) => this.encodeValue(v, part.operator));
|
|
15793
|
+
switch (part.operator) {
|
|
15794
|
+
case "":
|
|
15795
|
+
return encoded.join(",");
|
|
15796
|
+
case "+":
|
|
15797
|
+
return encoded.join(",");
|
|
15798
|
+
case "#":
|
|
15799
|
+
return "#" + encoded.join(",");
|
|
15800
|
+
case ".":
|
|
15801
|
+
return "." + encoded.join(".");
|
|
15802
|
+
case "/":
|
|
15803
|
+
return "/" + encoded.join("/");
|
|
15804
|
+
default:
|
|
15805
|
+
return encoded.join(",");
|
|
15806
|
+
}
|
|
15807
|
+
}
|
|
15808
|
+
expand(variables) {
|
|
15809
|
+
let result = "";
|
|
15810
|
+
let hasQueryParam = false;
|
|
15811
|
+
for (const part of this.parts) {
|
|
15812
|
+
if (typeof part === "string") {
|
|
15813
|
+
result += part;
|
|
15814
|
+
continue;
|
|
15815
|
+
}
|
|
15816
|
+
const expanded = this.expandPart(part, variables);
|
|
15817
|
+
if (!expanded)
|
|
15818
|
+
continue;
|
|
15819
|
+
if ((part.operator === "?" || part.operator === "&") && hasQueryParam) {
|
|
15820
|
+
result += expanded.replace("?", "&");
|
|
15821
|
+
} else {
|
|
15822
|
+
result += expanded;
|
|
15823
|
+
}
|
|
15824
|
+
if (part.operator === "?" || part.operator === "&") {
|
|
15825
|
+
hasQueryParam = true;
|
|
15826
|
+
}
|
|
15827
|
+
}
|
|
15828
|
+
return result;
|
|
15829
|
+
}
|
|
15830
|
+
escapeRegExp(str) {
|
|
15831
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15832
|
+
}
|
|
15833
|
+
partToRegExp(part) {
|
|
15834
|
+
const patterns = [];
|
|
15835
|
+
for (const name2 of part.names) {
|
|
15836
|
+
UriTemplate.validateLength(name2, MAX_VARIABLE_LENGTH, "Variable name");
|
|
15837
|
+
}
|
|
15838
|
+
if (part.operator === "?" || part.operator === "&") {
|
|
15839
|
+
for (let i = 0; i < part.names.length; i++) {
|
|
15840
|
+
const name2 = part.names[i];
|
|
15841
|
+
const prefix = i === 0 ? "\\" + part.operator : "&";
|
|
15842
|
+
patterns.push({
|
|
15843
|
+
pattern: prefix + this.escapeRegExp(name2) + "=([^&]+)",
|
|
15844
|
+
name: name2
|
|
15845
|
+
});
|
|
15846
|
+
}
|
|
15847
|
+
return patterns;
|
|
15848
|
+
}
|
|
15849
|
+
let pattern2;
|
|
15850
|
+
const name = part.name;
|
|
15851
|
+
switch (part.operator) {
|
|
15852
|
+
case "":
|
|
15853
|
+
pattern2 = part.exploded ? "([^/]+(?:,[^/]+)*)" : "([^/,]+)";
|
|
14613
15854
|
break;
|
|
14614
|
-
case "
|
|
14615
|
-
|
|
14616
|
-
|
|
14617
|
-
"maximum",
|
|
14618
|
-
check.value,
|
|
14619
|
-
// This is in milliseconds
|
|
14620
|
-
check.message,
|
|
14621
|
-
refs
|
|
14622
|
-
);
|
|
15855
|
+
case "+":
|
|
15856
|
+
case "#":
|
|
15857
|
+
pattern2 = "(.+)";
|
|
14623
15858
|
break;
|
|
15859
|
+
case ".":
|
|
15860
|
+
pattern2 = "\\.([^/,]+)";
|
|
15861
|
+
break;
|
|
15862
|
+
case "/":
|
|
15863
|
+
pattern2 = "/" + (part.exploded ? "([^/]+(?:,[^/]+)*)" : "([^/,]+)");
|
|
15864
|
+
break;
|
|
15865
|
+
default:
|
|
15866
|
+
pattern2 = "([^/]+)";
|
|
14624
15867
|
}
|
|
15868
|
+
patterns.push({ pattern: pattern2, name });
|
|
15869
|
+
return patterns;
|
|
14625
15870
|
}
|
|
14626
|
-
|
|
14627
|
-
|
|
14628
|
-
|
|
14629
|
-
|
|
14630
|
-
|
|
14631
|
-
|
|
14632
|
-
|
|
14633
|
-
}
|
|
14634
|
-
|
|
14635
|
-
|
|
14636
|
-
|
|
14637
|
-
|
|
14638
|
-
|
|
14639
|
-
type: "string",
|
|
14640
|
-
enum: Array.from(def.values)
|
|
14641
|
-
};
|
|
14642
|
-
}
|
|
14643
|
-
const isJsonSchema7AllOfType = (type2) => {
|
|
14644
|
-
if ("type" in type2 && type2.type === "string")
|
|
14645
|
-
return false;
|
|
14646
|
-
return "allOf" in type2;
|
|
14647
|
-
};
|
|
14648
|
-
function parseIntersectionDef(def, refs) {
|
|
14649
|
-
const allOf2 = [
|
|
14650
|
-
parseDef(def.left._def, {
|
|
14651
|
-
...refs,
|
|
14652
|
-
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
14653
|
-
}),
|
|
14654
|
-
parseDef(def.right._def, {
|
|
14655
|
-
...refs,
|
|
14656
|
-
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
14657
|
-
})
|
|
14658
|
-
].filter((x) => !!x);
|
|
14659
|
-
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
|
|
14660
|
-
const mergedAllOf = [];
|
|
14661
|
-
allOf2.forEach((schema) => {
|
|
14662
|
-
if (isJsonSchema7AllOfType(schema)) {
|
|
14663
|
-
mergedAllOf.push(...schema.allOf);
|
|
14664
|
-
if (schema.unevaluatedProperties === void 0) {
|
|
14665
|
-
unevaluatedProperties = void 0;
|
|
15871
|
+
match(uri) {
|
|
15872
|
+
UriTemplate.validateLength(uri, MAX_TEMPLATE_LENGTH, "URI");
|
|
15873
|
+
let pattern2 = "^";
|
|
15874
|
+
const names = [];
|
|
15875
|
+
for (const part of this.parts) {
|
|
15876
|
+
if (typeof part === "string") {
|
|
15877
|
+
pattern2 += this.escapeRegExp(part);
|
|
15878
|
+
} else {
|
|
15879
|
+
const patterns = this.partToRegExp(part);
|
|
15880
|
+
for (const { pattern: partPattern, name } of patterns) {
|
|
15881
|
+
pattern2 += partPattern;
|
|
15882
|
+
names.push({ name, exploded: part.exploded });
|
|
15883
|
+
}
|
|
14666
15884
|
}
|
|
14667
|
-
}
|
|
14668
|
-
|
|
14669
|
-
|
|
14670
|
-
|
|
14671
|
-
|
|
15885
|
+
}
|
|
15886
|
+
pattern2 += "$";
|
|
15887
|
+
UriTemplate.validateLength(pattern2, MAX_REGEX_LENGTH, "Generated regex pattern");
|
|
15888
|
+
const regex = new RegExp(pattern2);
|
|
15889
|
+
const match = uri.match(regex);
|
|
15890
|
+
if (!match)
|
|
15891
|
+
return null;
|
|
15892
|
+
const result = {};
|
|
15893
|
+
for (let i = 0; i < names.length; i++) {
|
|
15894
|
+
const { name, exploded } = names[i];
|
|
15895
|
+
const value = match[i + 1];
|
|
15896
|
+
const cleanName = name.replace("*", "");
|
|
15897
|
+
if (exploded && value.includes(",")) {
|
|
15898
|
+
result[cleanName] = value.split(",");
|
|
14672
15899
|
} else {
|
|
14673
|
-
|
|
15900
|
+
result[cleanName] = value;
|
|
14674
15901
|
}
|
|
14675
|
-
mergedAllOf.push(nestedSchema);
|
|
14676
15902
|
}
|
|
14677
|
-
|
|
14678
|
-
return mergedAllOf.length ? {
|
|
14679
|
-
allOf: mergedAllOf,
|
|
14680
|
-
...unevaluatedProperties
|
|
14681
|
-
} : void 0;
|
|
14682
|
-
}
|
|
14683
|
-
function parseLiteralDef(def, refs) {
|
|
14684
|
-
const parsedType = typeof def.value;
|
|
14685
|
-
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
14686
|
-
return {
|
|
14687
|
-
type: Array.isArray(def.value) ? "array" : "object"
|
|
14688
|
-
};
|
|
14689
|
-
}
|
|
14690
|
-
if (refs.target === "openApi3") {
|
|
14691
|
-
return {
|
|
14692
|
-
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
14693
|
-
enum: [def.value]
|
|
14694
|
-
};
|
|
15903
|
+
return result;
|
|
14695
15904
|
}
|
|
14696
|
-
return {
|
|
14697
|
-
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
14698
|
-
const: def.value
|
|
14699
|
-
};
|
|
14700
15905
|
}
|
|
14701
|
-
|
|
14702
|
-
|
|
14703
|
-
|
|
14704
|
-
|
|
14705
|
-
|
|
14706
|
-
|
|
14707
|
-
|
|
14708
|
-
|
|
14709
|
-
|
|
14710
|
-
|
|
14711
|
-
|
|
14712
|
-
|
|
15906
|
+
class McpServer {
|
|
15907
|
+
constructor(serverInfo, options) {
|
|
15908
|
+
this._registeredResources = {};
|
|
15909
|
+
this._registeredResourceTemplates = {};
|
|
15910
|
+
this._registeredTools = {};
|
|
15911
|
+
this._registeredPrompts = {};
|
|
15912
|
+
this._toolHandlersInitialized = false;
|
|
15913
|
+
this._completionHandlerInitialized = false;
|
|
15914
|
+
this._resourceHandlersInitialized = false;
|
|
15915
|
+
this._promptHandlersInitialized = false;
|
|
15916
|
+
this.server = new Server(serverInfo, options);
|
|
15917
|
+
}
|
|
14713
15918
|
/**
|
|
14714
|
-
*
|
|
14715
|
-
*
|
|
14716
|
-
* Lazily instantiate since this type of regex isn't supported
|
|
14717
|
-
* in all envs (e.g. React Native).
|
|
15919
|
+
* Attaches to the given transport, starts it, and starts listening for messages.
|
|
14718
15920
|
*
|
|
14719
|
-
*
|
|
14720
|
-
* https://github.com/colinhacks/zod/issues/2433
|
|
14721
|
-
* Fix in Zod:
|
|
14722
|
-
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
14723
|
-
*/
|
|
14724
|
-
emoji: () => {
|
|
14725
|
-
if (emojiRegex === void 0) {
|
|
14726
|
-
emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
14727
|
-
}
|
|
14728
|
-
return emojiRegex;
|
|
14729
|
-
},
|
|
14730
|
-
/**
|
|
14731
|
-
* Unused
|
|
14732
|
-
*/
|
|
14733
|
-
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
14734
|
-
/**
|
|
14735
|
-
* Unused
|
|
15921
|
+
* The `server` object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
|
|
14736
15922
|
*/
|
|
14737
|
-
|
|
14738
|
-
|
|
15923
|
+
async connect(transport) {
|
|
15924
|
+
return await this.server.connect(transport);
|
|
15925
|
+
}
|
|
14739
15926
|
/**
|
|
14740
|
-
*
|
|
14741
|
-
*/
|
|
14742
|
-
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
14743
|
-
ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
14744
|
-
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
14745
|
-
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
14746
|
-
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
14747
|
-
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
14748
|
-
};
|
|
14749
|
-
function parseStringDef(def, refs) {
|
|
14750
|
-
const res = {
|
|
14751
|
-
type: "string"
|
|
14752
|
-
};
|
|
14753
|
-
if (def.checks) {
|
|
14754
|
-
for (const check of def.checks) {
|
|
14755
|
-
switch (check.kind) {
|
|
14756
|
-
case "min":
|
|
14757
|
-
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
14758
|
-
break;
|
|
14759
|
-
case "max":
|
|
14760
|
-
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
14761
|
-
break;
|
|
14762
|
-
case "email":
|
|
14763
|
-
switch (refs.emailStrategy) {
|
|
14764
|
-
case "format:email":
|
|
14765
|
-
addFormat(res, "email", check.message, refs);
|
|
14766
|
-
break;
|
|
14767
|
-
case "format:idn-email":
|
|
14768
|
-
addFormat(res, "idn-email", check.message, refs);
|
|
14769
|
-
break;
|
|
14770
|
-
case "pattern:zod":
|
|
14771
|
-
addPattern(res, zodPatterns.email, check.message, refs);
|
|
14772
|
-
break;
|
|
14773
|
-
}
|
|
14774
|
-
break;
|
|
14775
|
-
case "url":
|
|
14776
|
-
addFormat(res, "uri", check.message, refs);
|
|
14777
|
-
break;
|
|
14778
|
-
case "uuid":
|
|
14779
|
-
addFormat(res, "uuid", check.message, refs);
|
|
14780
|
-
break;
|
|
14781
|
-
case "regex":
|
|
14782
|
-
addPattern(res, check.regex, check.message, refs);
|
|
14783
|
-
break;
|
|
14784
|
-
case "cuid":
|
|
14785
|
-
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
14786
|
-
break;
|
|
14787
|
-
case "cuid2":
|
|
14788
|
-
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
14789
|
-
break;
|
|
14790
|
-
case "startsWith":
|
|
14791
|
-
addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
|
|
14792
|
-
break;
|
|
14793
|
-
case "endsWith":
|
|
14794
|
-
addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
|
|
14795
|
-
break;
|
|
14796
|
-
case "datetime":
|
|
14797
|
-
addFormat(res, "date-time", check.message, refs);
|
|
14798
|
-
break;
|
|
14799
|
-
case "date":
|
|
14800
|
-
addFormat(res, "date", check.message, refs);
|
|
14801
|
-
break;
|
|
14802
|
-
case "time":
|
|
14803
|
-
addFormat(res, "time", check.message, refs);
|
|
14804
|
-
break;
|
|
14805
|
-
case "duration":
|
|
14806
|
-
addFormat(res, "duration", check.message, refs);
|
|
14807
|
-
break;
|
|
14808
|
-
case "length":
|
|
14809
|
-
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
14810
|
-
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
14811
|
-
break;
|
|
14812
|
-
case "includes": {
|
|
14813
|
-
addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
|
|
14814
|
-
break;
|
|
14815
|
-
}
|
|
14816
|
-
case "ip": {
|
|
14817
|
-
if (check.version !== "v6") {
|
|
14818
|
-
addFormat(res, "ipv4", check.message, refs);
|
|
14819
|
-
}
|
|
14820
|
-
if (check.version !== "v4") {
|
|
14821
|
-
addFormat(res, "ipv6", check.message, refs);
|
|
14822
|
-
}
|
|
14823
|
-
break;
|
|
14824
|
-
}
|
|
14825
|
-
case "base64url":
|
|
14826
|
-
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
14827
|
-
break;
|
|
14828
|
-
case "jwt":
|
|
14829
|
-
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
14830
|
-
break;
|
|
14831
|
-
case "cidr": {
|
|
14832
|
-
if (check.version !== "v6") {
|
|
14833
|
-
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
14834
|
-
}
|
|
14835
|
-
if (check.version !== "v4") {
|
|
14836
|
-
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
14837
|
-
}
|
|
14838
|
-
break;
|
|
14839
|
-
}
|
|
14840
|
-
case "emoji":
|
|
14841
|
-
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
14842
|
-
break;
|
|
14843
|
-
case "ulid": {
|
|
14844
|
-
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
14845
|
-
break;
|
|
14846
|
-
}
|
|
14847
|
-
case "base64": {
|
|
14848
|
-
switch (refs.base64Strategy) {
|
|
14849
|
-
case "format:binary": {
|
|
14850
|
-
addFormat(res, "binary", check.message, refs);
|
|
14851
|
-
break;
|
|
14852
|
-
}
|
|
14853
|
-
case "contentEncoding:base64": {
|
|
14854
|
-
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
|
|
14855
|
-
break;
|
|
14856
|
-
}
|
|
14857
|
-
case "pattern:zod": {
|
|
14858
|
-
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
14859
|
-
break;
|
|
14860
|
-
}
|
|
14861
|
-
}
|
|
14862
|
-
break;
|
|
14863
|
-
}
|
|
14864
|
-
case "nanoid": {
|
|
14865
|
-
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
14866
|
-
}
|
|
14867
|
-
}
|
|
14868
|
-
}
|
|
14869
|
-
}
|
|
14870
|
-
return res;
|
|
14871
|
-
}
|
|
14872
|
-
function escapeLiteralCheckValue(literal, refs) {
|
|
14873
|
-
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
14874
|
-
}
|
|
14875
|
-
const ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
14876
|
-
function escapeNonAlphaNumeric(source) {
|
|
14877
|
-
let result = "";
|
|
14878
|
-
for (let i = 0; i < source.length; i++) {
|
|
14879
|
-
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
14880
|
-
result += "\\";
|
|
14881
|
-
}
|
|
14882
|
-
result += source[i];
|
|
14883
|
-
}
|
|
14884
|
-
return result;
|
|
14885
|
-
}
|
|
14886
|
-
function addFormat(schema, value, message, refs) {
|
|
14887
|
-
var _a;
|
|
14888
|
-
if (schema.format || ((_a = schema.anyOf) == null ? void 0 : _a.some((x) => x.format))) {
|
|
14889
|
-
if (!schema.anyOf) {
|
|
14890
|
-
schema.anyOf = [];
|
|
14891
|
-
}
|
|
14892
|
-
if (schema.format) {
|
|
14893
|
-
schema.anyOf.push({
|
|
14894
|
-
format: schema.format,
|
|
14895
|
-
...schema.errorMessage && refs.errorMessages && {
|
|
14896
|
-
errorMessage: { format: schema.errorMessage.format }
|
|
14897
|
-
}
|
|
14898
|
-
});
|
|
14899
|
-
delete schema.format;
|
|
14900
|
-
if (schema.errorMessage) {
|
|
14901
|
-
delete schema.errorMessage.format;
|
|
14902
|
-
if (Object.keys(schema.errorMessage).length === 0) {
|
|
14903
|
-
delete schema.errorMessage;
|
|
14904
|
-
}
|
|
14905
|
-
}
|
|
14906
|
-
}
|
|
14907
|
-
schema.anyOf.push({
|
|
14908
|
-
format: value,
|
|
14909
|
-
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
14910
|
-
});
|
|
14911
|
-
} else {
|
|
14912
|
-
setResponseValueAndErrors(schema, "format", value, message, refs);
|
|
14913
|
-
}
|
|
14914
|
-
}
|
|
14915
|
-
function addPattern(schema, regex, message, refs) {
|
|
14916
|
-
var _a;
|
|
14917
|
-
if (schema.pattern || ((_a = schema.allOf) == null ? void 0 : _a.some((x) => x.pattern))) {
|
|
14918
|
-
if (!schema.allOf) {
|
|
14919
|
-
schema.allOf = [];
|
|
14920
|
-
}
|
|
14921
|
-
if (schema.pattern) {
|
|
14922
|
-
schema.allOf.push({
|
|
14923
|
-
pattern: schema.pattern,
|
|
14924
|
-
...schema.errorMessage && refs.errorMessages && {
|
|
14925
|
-
errorMessage: { pattern: schema.errorMessage.pattern }
|
|
14926
|
-
}
|
|
14927
|
-
});
|
|
14928
|
-
delete schema.pattern;
|
|
14929
|
-
if (schema.errorMessage) {
|
|
14930
|
-
delete schema.errorMessage.pattern;
|
|
14931
|
-
if (Object.keys(schema.errorMessage).length === 0) {
|
|
14932
|
-
delete schema.errorMessage;
|
|
14933
|
-
}
|
|
14934
|
-
}
|
|
14935
|
-
}
|
|
14936
|
-
schema.allOf.push({
|
|
14937
|
-
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
14938
|
-
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
14939
|
-
});
|
|
14940
|
-
} else {
|
|
14941
|
-
setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
|
|
14942
|
-
}
|
|
14943
|
-
}
|
|
14944
|
-
function stringifyRegExpWithFlags(regex, refs) {
|
|
14945
|
-
var _a;
|
|
14946
|
-
if (!refs.applyRegexFlags || !regex.flags) {
|
|
14947
|
-
return regex.source;
|
|
14948
|
-
}
|
|
14949
|
-
const flags = {
|
|
14950
|
-
i: regex.flags.includes("i"),
|
|
14951
|
-
m: regex.flags.includes("m"),
|
|
14952
|
-
s: regex.flags.includes("s")
|
|
14953
|
-
// `.` matches newlines
|
|
14954
|
-
};
|
|
14955
|
-
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
14956
|
-
let pattern2 = "";
|
|
14957
|
-
let isEscaped = false;
|
|
14958
|
-
let inCharGroup = false;
|
|
14959
|
-
let inCharRange = false;
|
|
14960
|
-
for (let i = 0; i < source.length; i++) {
|
|
14961
|
-
if (isEscaped) {
|
|
14962
|
-
pattern2 += source[i];
|
|
14963
|
-
isEscaped = false;
|
|
14964
|
-
continue;
|
|
14965
|
-
}
|
|
14966
|
-
if (flags.i) {
|
|
14967
|
-
if (inCharGroup) {
|
|
14968
|
-
if (source[i].match(/[a-z]/)) {
|
|
14969
|
-
if (inCharRange) {
|
|
14970
|
-
pattern2 += source[i];
|
|
14971
|
-
pattern2 += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
14972
|
-
inCharRange = false;
|
|
14973
|
-
} else if (source[i + 1] === "-" && ((_a = source[i + 2]) == null ? void 0 : _a.match(/[a-z]/))) {
|
|
14974
|
-
pattern2 += source[i];
|
|
14975
|
-
inCharRange = true;
|
|
14976
|
-
} else {
|
|
14977
|
-
pattern2 += `${source[i]}${source[i].toUpperCase()}`;
|
|
14978
|
-
}
|
|
14979
|
-
continue;
|
|
14980
|
-
}
|
|
14981
|
-
} else if (source[i].match(/[a-z]/)) {
|
|
14982
|
-
pattern2 += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
14983
|
-
continue;
|
|
14984
|
-
}
|
|
14985
|
-
}
|
|
14986
|
-
if (flags.m) {
|
|
14987
|
-
if (source[i] === "^") {
|
|
14988
|
-
pattern2 += `(^|(?<=[\r
|
|
14989
|
-
]))`;
|
|
14990
|
-
continue;
|
|
14991
|
-
} else if (source[i] === "$") {
|
|
14992
|
-
pattern2 += `($|(?=[\r
|
|
14993
|
-
]))`;
|
|
14994
|
-
continue;
|
|
14995
|
-
}
|
|
14996
|
-
}
|
|
14997
|
-
if (flags.s && source[i] === ".") {
|
|
14998
|
-
pattern2 += inCharGroup ? `${source[i]}\r
|
|
14999
|
-
` : `[${source[i]}\r
|
|
15000
|
-
]`;
|
|
15001
|
-
continue;
|
|
15002
|
-
}
|
|
15003
|
-
pattern2 += source[i];
|
|
15004
|
-
if (source[i] === "\\") {
|
|
15005
|
-
isEscaped = true;
|
|
15006
|
-
} else if (inCharGroup && source[i] === "]") {
|
|
15007
|
-
inCharGroup = false;
|
|
15008
|
-
} else if (!inCharGroup && source[i] === "[") {
|
|
15009
|
-
inCharGroup = true;
|
|
15010
|
-
}
|
|
15011
|
-
}
|
|
15012
|
-
try {
|
|
15013
|
-
new RegExp(pattern2);
|
|
15014
|
-
} catch {
|
|
15015
|
-
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
15016
|
-
return regex.source;
|
|
15017
|
-
}
|
|
15018
|
-
return pattern2;
|
|
15019
|
-
}
|
|
15020
|
-
function parseRecordDef(def, refs) {
|
|
15021
|
-
var _a, _b, _c, _d, _e, _f;
|
|
15022
|
-
if (refs.target === "openAi") {
|
|
15023
|
-
console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
|
|
15024
|
-
}
|
|
15025
|
-
if (refs.target === "openApi3" && ((_a = def.keyType) == null ? void 0 : _a._def.typeName) === zod.ZodFirstPartyTypeKind.ZodEnum) {
|
|
15026
|
-
return {
|
|
15027
|
-
type: "object",
|
|
15028
|
-
required: def.keyType._def.values,
|
|
15029
|
-
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
15030
|
-
...acc,
|
|
15031
|
-
[key]: parseDef(def.valueType._def, {
|
|
15032
|
-
...refs,
|
|
15033
|
-
currentPath: [...refs.currentPath, "properties", key]
|
|
15034
|
-
}) ?? parseAnyDef(refs)
|
|
15035
|
-
}), {}),
|
|
15036
|
-
additionalProperties: refs.rejectedAdditionalProperties
|
|
15037
|
-
};
|
|
15038
|
-
}
|
|
15039
|
-
const schema = {
|
|
15040
|
-
type: "object",
|
|
15041
|
-
additionalProperties: parseDef(def.valueType._def, {
|
|
15042
|
-
...refs,
|
|
15043
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
15044
|
-
}) ?? refs.allowedAdditionalProperties
|
|
15045
|
-
};
|
|
15046
|
-
if (refs.target === "openApi3") {
|
|
15047
|
-
return schema;
|
|
15048
|
-
}
|
|
15049
|
-
if (((_b = def.keyType) == null ? void 0 : _b._def.typeName) === zod.ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
15050
|
-
const { type: type2, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
15051
|
-
return {
|
|
15052
|
-
...schema,
|
|
15053
|
-
propertyNames: keyType
|
|
15054
|
-
};
|
|
15055
|
-
} else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === zod.ZodFirstPartyTypeKind.ZodEnum) {
|
|
15056
|
-
return {
|
|
15057
|
-
...schema,
|
|
15058
|
-
propertyNames: {
|
|
15059
|
-
enum: def.keyType._def.values
|
|
15060
|
-
}
|
|
15061
|
-
};
|
|
15062
|
-
} else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) === zod.ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === zod.ZodFirstPartyTypeKind.ZodString && ((_f = def.keyType._def.type._def.checks) == null ? void 0 : _f.length)) {
|
|
15063
|
-
const { type: type2, ...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
15064
|
-
return {
|
|
15065
|
-
...schema,
|
|
15066
|
-
propertyNames: keyType
|
|
15067
|
-
};
|
|
15068
|
-
}
|
|
15069
|
-
return schema;
|
|
15070
|
-
}
|
|
15071
|
-
function parseMapDef(def, refs) {
|
|
15072
|
-
if (refs.mapStrategy === "record") {
|
|
15073
|
-
return parseRecordDef(def, refs);
|
|
15074
|
-
}
|
|
15075
|
-
const keys = parseDef(def.keyType._def, {
|
|
15076
|
-
...refs,
|
|
15077
|
-
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
15078
|
-
}) || parseAnyDef(refs);
|
|
15079
|
-
const values = parseDef(def.valueType._def, {
|
|
15080
|
-
...refs,
|
|
15081
|
-
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
15082
|
-
}) || parseAnyDef(refs);
|
|
15083
|
-
return {
|
|
15084
|
-
type: "array",
|
|
15085
|
-
maxItems: 125,
|
|
15086
|
-
items: {
|
|
15087
|
-
type: "array",
|
|
15088
|
-
items: [keys, values],
|
|
15089
|
-
minItems: 2,
|
|
15090
|
-
maxItems: 2
|
|
15091
|
-
}
|
|
15092
|
-
};
|
|
15093
|
-
}
|
|
15094
|
-
function parseNativeEnumDef(def) {
|
|
15095
|
-
const object = def.values;
|
|
15096
|
-
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
15097
|
-
return typeof object[object[key]] !== "number";
|
|
15098
|
-
});
|
|
15099
|
-
const actualValues = actualKeys.map((key) => object[key]);
|
|
15100
|
-
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
15101
|
-
return {
|
|
15102
|
-
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
15103
|
-
enum: actualValues
|
|
15104
|
-
};
|
|
15105
|
-
}
|
|
15106
|
-
function parseNeverDef(refs) {
|
|
15107
|
-
return refs.target === "openAi" ? void 0 : {
|
|
15108
|
-
not: parseAnyDef({
|
|
15109
|
-
...refs,
|
|
15110
|
-
currentPath: [...refs.currentPath, "not"]
|
|
15111
|
-
})
|
|
15112
|
-
};
|
|
15113
|
-
}
|
|
15114
|
-
function parseNullDef(refs) {
|
|
15115
|
-
return refs.target === "openApi3" ? {
|
|
15116
|
-
enum: ["null"],
|
|
15117
|
-
nullable: true
|
|
15118
|
-
} : {
|
|
15119
|
-
type: "null"
|
|
15120
|
-
};
|
|
15121
|
-
}
|
|
15122
|
-
const primitiveMappings = {
|
|
15123
|
-
ZodString: "string",
|
|
15124
|
-
ZodNumber: "number",
|
|
15125
|
-
ZodBigInt: "integer",
|
|
15126
|
-
ZodBoolean: "boolean",
|
|
15127
|
-
ZodNull: "null"
|
|
15128
|
-
};
|
|
15129
|
-
function parseUnionDef(def, refs) {
|
|
15130
|
-
if (refs.target === "openApi3")
|
|
15131
|
-
return asAnyOf(def, refs);
|
|
15132
|
-
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
15133
|
-
if (options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
|
|
15134
|
-
const types = options.reduce((types2, x) => {
|
|
15135
|
-
const type2 = primitiveMappings[x._def.typeName];
|
|
15136
|
-
return type2 && !types2.includes(type2) ? [...types2, type2] : types2;
|
|
15137
|
-
}, []);
|
|
15138
|
-
return {
|
|
15139
|
-
type: types.length > 1 ? types : types[0]
|
|
15140
|
-
};
|
|
15141
|
-
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
15142
|
-
const types = options.reduce((acc, x) => {
|
|
15143
|
-
const type2 = typeof x._def.value;
|
|
15144
|
-
switch (type2) {
|
|
15145
|
-
case "string":
|
|
15146
|
-
case "number":
|
|
15147
|
-
case "boolean":
|
|
15148
|
-
return [...acc, type2];
|
|
15149
|
-
case "bigint":
|
|
15150
|
-
return [...acc, "integer"];
|
|
15151
|
-
case "object":
|
|
15152
|
-
if (x._def.value === null)
|
|
15153
|
-
return [...acc, "null"];
|
|
15154
|
-
case "symbol":
|
|
15155
|
-
case "undefined":
|
|
15156
|
-
case "function":
|
|
15157
|
-
default:
|
|
15158
|
-
return acc;
|
|
15159
|
-
}
|
|
15160
|
-
}, []);
|
|
15161
|
-
if (types.length === options.length) {
|
|
15162
|
-
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
15163
|
-
return {
|
|
15164
|
-
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
15165
|
-
enum: options.reduce((acc, x) => {
|
|
15166
|
-
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
15167
|
-
}, [])
|
|
15168
|
-
};
|
|
15169
|
-
}
|
|
15170
|
-
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
15171
|
-
return {
|
|
15172
|
-
type: "string",
|
|
15173
|
-
enum: options.reduce((acc, x) => [
|
|
15174
|
-
...acc,
|
|
15175
|
-
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
15176
|
-
], [])
|
|
15177
|
-
};
|
|
15178
|
-
}
|
|
15179
|
-
return asAnyOf(def, refs);
|
|
15180
|
-
}
|
|
15181
|
-
const asAnyOf = (def, refs) => {
|
|
15182
|
-
const anyOf2 = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
|
|
15183
|
-
...refs,
|
|
15184
|
-
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
15185
|
-
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
15186
|
-
return anyOf2.length ? { anyOf: anyOf2 } : void 0;
|
|
15187
|
-
};
|
|
15188
|
-
function parseNullableDef(def, refs) {
|
|
15189
|
-
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
15190
|
-
if (refs.target === "openApi3") {
|
|
15191
|
-
return {
|
|
15192
|
-
type: primitiveMappings[def.innerType._def.typeName],
|
|
15193
|
-
nullable: true
|
|
15194
|
-
};
|
|
15195
|
-
}
|
|
15196
|
-
return {
|
|
15197
|
-
type: [
|
|
15198
|
-
primitiveMappings[def.innerType._def.typeName],
|
|
15199
|
-
"null"
|
|
15200
|
-
]
|
|
15201
|
-
};
|
|
15202
|
-
}
|
|
15203
|
-
if (refs.target === "openApi3") {
|
|
15204
|
-
const base2 = parseDef(def.innerType._def, {
|
|
15205
|
-
...refs,
|
|
15206
|
-
currentPath: [...refs.currentPath]
|
|
15207
|
-
});
|
|
15208
|
-
if (base2 && "$ref" in base2)
|
|
15209
|
-
return { allOf: [base2], nullable: true };
|
|
15210
|
-
return base2 && { ...base2, nullable: true };
|
|
15211
|
-
}
|
|
15212
|
-
const base = parseDef(def.innerType._def, {
|
|
15213
|
-
...refs,
|
|
15214
|
-
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
15215
|
-
});
|
|
15216
|
-
return base && { anyOf: [base, { type: "null" }] };
|
|
15217
|
-
}
|
|
15218
|
-
function parseNumberDef(def, refs) {
|
|
15219
|
-
const res = {
|
|
15220
|
-
type: "number"
|
|
15221
|
-
};
|
|
15222
|
-
if (!def.checks)
|
|
15223
|
-
return res;
|
|
15224
|
-
for (const check of def.checks) {
|
|
15225
|
-
switch (check.kind) {
|
|
15226
|
-
case "int":
|
|
15227
|
-
res.type = "integer";
|
|
15228
|
-
addErrorMessage(res, "type", check.message, refs);
|
|
15229
|
-
break;
|
|
15230
|
-
case "min":
|
|
15231
|
-
if (refs.target === "jsonSchema7") {
|
|
15232
|
-
if (check.inclusive) {
|
|
15233
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
15234
|
-
} else {
|
|
15235
|
-
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
15236
|
-
}
|
|
15237
|
-
} else {
|
|
15238
|
-
if (!check.inclusive) {
|
|
15239
|
-
res.exclusiveMinimum = true;
|
|
15240
|
-
}
|
|
15241
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
15242
|
-
}
|
|
15243
|
-
break;
|
|
15244
|
-
case "max":
|
|
15245
|
-
if (refs.target === "jsonSchema7") {
|
|
15246
|
-
if (check.inclusive) {
|
|
15247
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
15248
|
-
} else {
|
|
15249
|
-
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
15250
|
-
}
|
|
15251
|
-
} else {
|
|
15252
|
-
if (!check.inclusive) {
|
|
15253
|
-
res.exclusiveMaximum = true;
|
|
15254
|
-
}
|
|
15255
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
15256
|
-
}
|
|
15257
|
-
break;
|
|
15258
|
-
case "multipleOf":
|
|
15259
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
15260
|
-
break;
|
|
15261
|
-
}
|
|
15262
|
-
}
|
|
15263
|
-
return res;
|
|
15264
|
-
}
|
|
15265
|
-
function parseObjectDef(def, refs) {
|
|
15266
|
-
const forceOptionalIntoNullable = refs.target === "openAi";
|
|
15267
|
-
const result = {
|
|
15268
|
-
type: "object",
|
|
15269
|
-
properties: {}
|
|
15270
|
-
};
|
|
15271
|
-
const required2 = [];
|
|
15272
|
-
const shape = def.shape();
|
|
15273
|
-
for (const propName in shape) {
|
|
15274
|
-
let propDef = shape[propName];
|
|
15275
|
-
if (propDef === void 0 || propDef._def === void 0) {
|
|
15276
|
-
continue;
|
|
15277
|
-
}
|
|
15278
|
-
let propOptional = safeIsOptional(propDef);
|
|
15279
|
-
if (propOptional && forceOptionalIntoNullable) {
|
|
15280
|
-
if (propDef._def.typeName === "ZodOptional") {
|
|
15281
|
-
propDef = propDef._def.innerType;
|
|
15282
|
-
}
|
|
15283
|
-
if (!propDef.isNullable()) {
|
|
15284
|
-
propDef = propDef.nullable();
|
|
15285
|
-
}
|
|
15286
|
-
propOptional = false;
|
|
15287
|
-
}
|
|
15288
|
-
const parsedDef = parseDef(propDef._def, {
|
|
15289
|
-
...refs,
|
|
15290
|
-
currentPath: [...refs.currentPath, "properties", propName],
|
|
15291
|
-
propertyPath: [...refs.currentPath, "properties", propName]
|
|
15292
|
-
});
|
|
15293
|
-
if (parsedDef === void 0) {
|
|
15294
|
-
continue;
|
|
15295
|
-
}
|
|
15296
|
-
result.properties[propName] = parsedDef;
|
|
15297
|
-
if (!propOptional) {
|
|
15298
|
-
required2.push(propName);
|
|
15299
|
-
}
|
|
15300
|
-
}
|
|
15301
|
-
if (required2.length) {
|
|
15302
|
-
result.required = required2;
|
|
15303
|
-
}
|
|
15304
|
-
const additionalProperties2 = decideAdditionalProperties(def, refs);
|
|
15305
|
-
if (additionalProperties2 !== void 0) {
|
|
15306
|
-
result.additionalProperties = additionalProperties2;
|
|
15307
|
-
}
|
|
15308
|
-
return result;
|
|
15309
|
-
}
|
|
15310
|
-
function decideAdditionalProperties(def, refs) {
|
|
15311
|
-
if (def.catchall._def.typeName !== "ZodNever") {
|
|
15312
|
-
return parseDef(def.catchall._def, {
|
|
15313
|
-
...refs,
|
|
15314
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
15315
|
-
});
|
|
15316
|
-
}
|
|
15317
|
-
switch (def.unknownKeys) {
|
|
15318
|
-
case "passthrough":
|
|
15319
|
-
return refs.allowedAdditionalProperties;
|
|
15320
|
-
case "strict":
|
|
15321
|
-
return refs.rejectedAdditionalProperties;
|
|
15322
|
-
case "strip":
|
|
15323
|
-
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
15324
|
-
}
|
|
15325
|
-
}
|
|
15326
|
-
function safeIsOptional(schema) {
|
|
15327
|
-
try {
|
|
15328
|
-
return schema.isOptional();
|
|
15329
|
-
} catch {
|
|
15330
|
-
return true;
|
|
15331
|
-
}
|
|
15332
|
-
}
|
|
15333
|
-
const parseOptionalDef = (def, refs) => {
|
|
15334
|
-
var _a;
|
|
15335
|
-
if (refs.currentPath.toString() === ((_a = refs.propertyPath) == null ? void 0 : _a.toString())) {
|
|
15336
|
-
return parseDef(def.innerType._def, refs);
|
|
15337
|
-
}
|
|
15338
|
-
const innerSchema = parseDef(def.innerType._def, {
|
|
15339
|
-
...refs,
|
|
15340
|
-
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
15341
|
-
});
|
|
15342
|
-
return innerSchema ? {
|
|
15343
|
-
anyOf: [
|
|
15344
|
-
{
|
|
15345
|
-
not: parseAnyDef(refs)
|
|
15346
|
-
},
|
|
15347
|
-
innerSchema
|
|
15348
|
-
]
|
|
15349
|
-
} : parseAnyDef(refs);
|
|
15350
|
-
};
|
|
15351
|
-
const parsePipelineDef = (def, refs) => {
|
|
15352
|
-
if (refs.pipeStrategy === "input") {
|
|
15353
|
-
return parseDef(def.in._def, refs);
|
|
15354
|
-
} else if (refs.pipeStrategy === "output") {
|
|
15355
|
-
return parseDef(def.out._def, refs);
|
|
15356
|
-
}
|
|
15357
|
-
const a = parseDef(def.in._def, {
|
|
15358
|
-
...refs,
|
|
15359
|
-
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
15360
|
-
});
|
|
15361
|
-
const b = parseDef(def.out._def, {
|
|
15362
|
-
...refs,
|
|
15363
|
-
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
15364
|
-
});
|
|
15365
|
-
return {
|
|
15366
|
-
allOf: [a, b].filter((x) => x !== void 0)
|
|
15367
|
-
};
|
|
15368
|
-
};
|
|
15369
|
-
function parsePromiseDef(def, refs) {
|
|
15370
|
-
return parseDef(def.type._def, refs);
|
|
15371
|
-
}
|
|
15372
|
-
function parseSetDef(def, refs) {
|
|
15373
|
-
const items2 = parseDef(def.valueType._def, {
|
|
15374
|
-
...refs,
|
|
15375
|
-
currentPath: [...refs.currentPath, "items"]
|
|
15376
|
-
});
|
|
15377
|
-
const schema = {
|
|
15378
|
-
type: "array",
|
|
15379
|
-
uniqueItems: true,
|
|
15380
|
-
items: items2
|
|
15381
|
-
};
|
|
15382
|
-
if (def.minSize) {
|
|
15383
|
-
setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
15384
|
-
}
|
|
15385
|
-
if (def.maxSize) {
|
|
15386
|
-
setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
15387
|
-
}
|
|
15388
|
-
return schema;
|
|
15389
|
-
}
|
|
15390
|
-
function parseTupleDef(def, refs) {
|
|
15391
|
-
if (def.rest) {
|
|
15392
|
-
return {
|
|
15393
|
-
type: "array",
|
|
15394
|
-
minItems: def.items.length,
|
|
15395
|
-
items: def.items.map((x, i) => parseDef(x._def, {
|
|
15396
|
-
...refs,
|
|
15397
|
-
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
15398
|
-
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
|
|
15399
|
-
additionalItems: parseDef(def.rest._def, {
|
|
15400
|
-
...refs,
|
|
15401
|
-
currentPath: [...refs.currentPath, "additionalItems"]
|
|
15402
|
-
})
|
|
15403
|
-
};
|
|
15404
|
-
} else {
|
|
15405
|
-
return {
|
|
15406
|
-
type: "array",
|
|
15407
|
-
minItems: def.items.length,
|
|
15408
|
-
maxItems: def.items.length,
|
|
15409
|
-
items: def.items.map((x, i) => parseDef(x._def, {
|
|
15410
|
-
...refs,
|
|
15411
|
-
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
15412
|
-
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
|
|
15413
|
-
};
|
|
15414
|
-
}
|
|
15415
|
-
}
|
|
15416
|
-
function parseUndefinedDef(refs) {
|
|
15417
|
-
return {
|
|
15418
|
-
not: parseAnyDef(refs)
|
|
15419
|
-
};
|
|
15420
|
-
}
|
|
15421
|
-
function parseUnknownDef(refs) {
|
|
15422
|
-
return parseAnyDef(refs);
|
|
15423
|
-
}
|
|
15424
|
-
const parseReadonlyDef = (def, refs) => {
|
|
15425
|
-
return parseDef(def.innerType._def, refs);
|
|
15426
|
-
};
|
|
15427
|
-
const selectParser = (def, typeName, refs) => {
|
|
15428
|
-
switch (typeName) {
|
|
15429
|
-
case zod.ZodFirstPartyTypeKind.ZodString:
|
|
15430
|
-
return parseStringDef(def, refs);
|
|
15431
|
-
case zod.ZodFirstPartyTypeKind.ZodNumber:
|
|
15432
|
-
return parseNumberDef(def, refs);
|
|
15433
|
-
case zod.ZodFirstPartyTypeKind.ZodObject:
|
|
15434
|
-
return parseObjectDef(def, refs);
|
|
15435
|
-
case zod.ZodFirstPartyTypeKind.ZodBigInt:
|
|
15436
|
-
return parseBigintDef(def, refs);
|
|
15437
|
-
case zod.ZodFirstPartyTypeKind.ZodBoolean:
|
|
15438
|
-
return parseBooleanDef();
|
|
15439
|
-
case zod.ZodFirstPartyTypeKind.ZodDate:
|
|
15440
|
-
return parseDateDef(def, refs);
|
|
15441
|
-
case zod.ZodFirstPartyTypeKind.ZodUndefined:
|
|
15442
|
-
return parseUndefinedDef(refs);
|
|
15443
|
-
case zod.ZodFirstPartyTypeKind.ZodNull:
|
|
15444
|
-
return parseNullDef(refs);
|
|
15445
|
-
case zod.ZodFirstPartyTypeKind.ZodArray:
|
|
15446
|
-
return parseArrayDef(def, refs);
|
|
15447
|
-
case zod.ZodFirstPartyTypeKind.ZodUnion:
|
|
15448
|
-
case zod.ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
|
|
15449
|
-
return parseUnionDef(def, refs);
|
|
15450
|
-
case zod.ZodFirstPartyTypeKind.ZodIntersection:
|
|
15451
|
-
return parseIntersectionDef(def, refs);
|
|
15452
|
-
case zod.ZodFirstPartyTypeKind.ZodTuple:
|
|
15453
|
-
return parseTupleDef(def, refs);
|
|
15454
|
-
case zod.ZodFirstPartyTypeKind.ZodRecord:
|
|
15455
|
-
return parseRecordDef(def, refs);
|
|
15456
|
-
case zod.ZodFirstPartyTypeKind.ZodLiteral:
|
|
15457
|
-
return parseLiteralDef(def, refs);
|
|
15458
|
-
case zod.ZodFirstPartyTypeKind.ZodEnum:
|
|
15459
|
-
return parseEnumDef(def);
|
|
15460
|
-
case zod.ZodFirstPartyTypeKind.ZodNativeEnum:
|
|
15461
|
-
return parseNativeEnumDef(def);
|
|
15462
|
-
case zod.ZodFirstPartyTypeKind.ZodNullable:
|
|
15463
|
-
return parseNullableDef(def, refs);
|
|
15464
|
-
case zod.ZodFirstPartyTypeKind.ZodOptional:
|
|
15465
|
-
return parseOptionalDef(def, refs);
|
|
15466
|
-
case zod.ZodFirstPartyTypeKind.ZodMap:
|
|
15467
|
-
return parseMapDef(def, refs);
|
|
15468
|
-
case zod.ZodFirstPartyTypeKind.ZodSet:
|
|
15469
|
-
return parseSetDef(def, refs);
|
|
15470
|
-
case zod.ZodFirstPartyTypeKind.ZodLazy:
|
|
15471
|
-
return () => def.getter()._def;
|
|
15472
|
-
case zod.ZodFirstPartyTypeKind.ZodPromise:
|
|
15473
|
-
return parsePromiseDef(def, refs);
|
|
15474
|
-
case zod.ZodFirstPartyTypeKind.ZodNaN:
|
|
15475
|
-
case zod.ZodFirstPartyTypeKind.ZodNever:
|
|
15476
|
-
return parseNeverDef(refs);
|
|
15477
|
-
case zod.ZodFirstPartyTypeKind.ZodEffects:
|
|
15478
|
-
return parseEffectsDef(def, refs);
|
|
15479
|
-
case zod.ZodFirstPartyTypeKind.ZodAny:
|
|
15480
|
-
return parseAnyDef(refs);
|
|
15481
|
-
case zod.ZodFirstPartyTypeKind.ZodUnknown:
|
|
15482
|
-
return parseUnknownDef(refs);
|
|
15483
|
-
case zod.ZodFirstPartyTypeKind.ZodDefault:
|
|
15484
|
-
return parseDefaultDef(def, refs);
|
|
15485
|
-
case zod.ZodFirstPartyTypeKind.ZodBranded:
|
|
15486
|
-
return parseBrandedDef(def, refs);
|
|
15487
|
-
case zod.ZodFirstPartyTypeKind.ZodReadonly:
|
|
15488
|
-
return parseReadonlyDef(def, refs);
|
|
15489
|
-
case zod.ZodFirstPartyTypeKind.ZodCatch:
|
|
15490
|
-
return parseCatchDef(def, refs);
|
|
15491
|
-
case zod.ZodFirstPartyTypeKind.ZodPipeline:
|
|
15492
|
-
return parsePipelineDef(def, refs);
|
|
15493
|
-
case zod.ZodFirstPartyTypeKind.ZodFunction:
|
|
15494
|
-
case zod.ZodFirstPartyTypeKind.ZodVoid:
|
|
15495
|
-
case zod.ZodFirstPartyTypeKind.ZodSymbol:
|
|
15496
|
-
return void 0;
|
|
15497
|
-
default:
|
|
15498
|
-
return /* @__PURE__ */ ((_) => void 0)();
|
|
15499
|
-
}
|
|
15500
|
-
};
|
|
15501
|
-
function parseDef(def, refs, forceResolution = false) {
|
|
15502
|
-
var _a;
|
|
15503
|
-
const seenItem = refs.seen.get(def);
|
|
15504
|
-
if (refs.override) {
|
|
15505
|
-
const overrideResult = (_a = refs.override) == null ? void 0 : _a.call(refs, def, refs, seenItem, forceResolution);
|
|
15506
|
-
if (overrideResult !== ignoreOverride) {
|
|
15507
|
-
return overrideResult;
|
|
15508
|
-
}
|
|
15509
|
-
}
|
|
15510
|
-
if (seenItem && !forceResolution) {
|
|
15511
|
-
const seenSchema = get$ref(seenItem, refs);
|
|
15512
|
-
if (seenSchema !== void 0) {
|
|
15513
|
-
return seenSchema;
|
|
15514
|
-
}
|
|
15515
|
-
}
|
|
15516
|
-
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
15517
|
-
refs.seen.set(def, newItem);
|
|
15518
|
-
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
15519
|
-
const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
15520
|
-
if (jsonSchema) {
|
|
15521
|
-
addMeta(def, refs, jsonSchema);
|
|
15522
|
-
}
|
|
15523
|
-
if (refs.postProcess) {
|
|
15524
|
-
const postProcessResult = refs.postProcess(jsonSchema, def, refs);
|
|
15525
|
-
newItem.jsonSchema = jsonSchema;
|
|
15526
|
-
return postProcessResult;
|
|
15527
|
-
}
|
|
15528
|
-
newItem.jsonSchema = jsonSchema;
|
|
15529
|
-
return jsonSchema;
|
|
15530
|
-
}
|
|
15531
|
-
const get$ref = (item, refs) => {
|
|
15532
|
-
switch (refs.$refStrategy) {
|
|
15533
|
-
case "root":
|
|
15534
|
-
return { $ref: item.path.join("/") };
|
|
15535
|
-
case "relative":
|
|
15536
|
-
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
15537
|
-
case "none":
|
|
15538
|
-
case "seen": {
|
|
15539
|
-
if (item.path.length < refs.currentPath.length && item.path.every((value, index2) => refs.currentPath[index2] === value)) {
|
|
15540
|
-
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
15541
|
-
return parseAnyDef(refs);
|
|
15542
|
-
}
|
|
15543
|
-
return refs.$refStrategy === "seen" ? parseAnyDef(refs) : void 0;
|
|
15544
|
-
}
|
|
15545
|
-
}
|
|
15546
|
-
};
|
|
15547
|
-
const addMeta = (def, refs, jsonSchema) => {
|
|
15548
|
-
if (def.description) {
|
|
15549
|
-
jsonSchema.description = def.description;
|
|
15550
|
-
if (refs.markdownDescription) {
|
|
15551
|
-
jsonSchema.markdownDescription = def.description;
|
|
15552
|
-
}
|
|
15553
|
-
}
|
|
15554
|
-
return jsonSchema;
|
|
15555
|
-
};
|
|
15556
|
-
const zodToJsonSchema = (schema, options) => {
|
|
15557
|
-
const refs = getRefs(options);
|
|
15558
|
-
let definitions2 = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name2, schema2]) => ({
|
|
15559
|
-
...acc,
|
|
15560
|
-
[name2]: parseDef(schema2._def, {
|
|
15561
|
-
...refs,
|
|
15562
|
-
currentPath: [...refs.basePath, refs.definitionPath, name2]
|
|
15563
|
-
}, true) ?? parseAnyDef(refs)
|
|
15564
|
-
}), {}) : void 0;
|
|
15565
|
-
const name = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
15566
|
-
const main = parseDef(schema._def, name === void 0 ? refs : {
|
|
15567
|
-
...refs,
|
|
15568
|
-
currentPath: [...refs.basePath, refs.definitionPath, name]
|
|
15569
|
-
}, false) ?? parseAnyDef(refs);
|
|
15570
|
-
const title2 = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
15571
|
-
if (title2 !== void 0) {
|
|
15572
|
-
main.title = title2;
|
|
15573
|
-
}
|
|
15574
|
-
if (refs.flags.hasReferencedOpenAiAnyType) {
|
|
15575
|
-
if (!definitions2) {
|
|
15576
|
-
definitions2 = {};
|
|
15577
|
-
}
|
|
15578
|
-
if (!definitions2[refs.openAiAnyTypeName]) {
|
|
15579
|
-
definitions2[refs.openAiAnyTypeName] = {
|
|
15580
|
-
// Skipping "object" as no properties can be defined and additionalProperties must be "false"
|
|
15581
|
-
type: ["string", "number", "integer", "boolean", "array", "null"],
|
|
15582
|
-
items: {
|
|
15583
|
-
$ref: refs.$refStrategy === "relative" ? "1" : [
|
|
15584
|
-
...refs.basePath,
|
|
15585
|
-
refs.definitionPath,
|
|
15586
|
-
refs.openAiAnyTypeName
|
|
15587
|
-
].join("/")
|
|
15588
|
-
}
|
|
15589
|
-
};
|
|
15590
|
-
}
|
|
15591
|
-
}
|
|
15592
|
-
const combined = name === void 0 ? definitions2 ? {
|
|
15593
|
-
...main,
|
|
15594
|
-
[refs.definitionPath]: definitions2
|
|
15595
|
-
} : main : {
|
|
15596
|
-
$ref: [
|
|
15597
|
-
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
15598
|
-
refs.definitionPath,
|
|
15599
|
-
name
|
|
15600
|
-
].join("/"),
|
|
15601
|
-
[refs.definitionPath]: {
|
|
15602
|
-
...definitions2,
|
|
15603
|
-
[name]: main
|
|
15604
|
-
}
|
|
15605
|
-
};
|
|
15606
|
-
if (refs.target === "jsonSchema7") {
|
|
15607
|
-
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
15608
|
-
} else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
|
|
15609
|
-
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
15610
|
-
}
|
|
15611
|
-
if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
|
|
15612
|
-
console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
|
|
15613
|
-
}
|
|
15614
|
-
return combined;
|
|
15615
|
-
};
|
|
15616
|
-
var McpZodTypeKind;
|
|
15617
|
-
(function(McpZodTypeKind2) {
|
|
15618
|
-
McpZodTypeKind2["Completable"] = "McpCompletable";
|
|
15619
|
-
})(McpZodTypeKind || (McpZodTypeKind = {}));
|
|
15620
|
-
class Completable extends zod.ZodType {
|
|
15621
|
-
_parse(input) {
|
|
15622
|
-
const { ctx } = this._processInputParams(input);
|
|
15623
|
-
const data2 = ctx.data;
|
|
15624
|
-
return this._def.type._parse({
|
|
15625
|
-
data: data2,
|
|
15626
|
-
path: ctx.path,
|
|
15627
|
-
parent: ctx
|
|
15628
|
-
});
|
|
15629
|
-
}
|
|
15630
|
-
unwrap() {
|
|
15631
|
-
return this._def.type;
|
|
15632
|
-
}
|
|
15633
|
-
}
|
|
15634
|
-
Completable.create = (type2, params) => {
|
|
15635
|
-
return new Completable({
|
|
15636
|
-
type: type2,
|
|
15637
|
-
typeName: McpZodTypeKind.Completable,
|
|
15638
|
-
complete: params.complete,
|
|
15639
|
-
...processCreateParams(params)
|
|
15640
|
-
});
|
|
15641
|
-
};
|
|
15642
|
-
function processCreateParams(params) {
|
|
15643
|
-
if (!params)
|
|
15644
|
-
return {};
|
|
15645
|
-
const { errorMap, invalid_type_error, required_error, description: description2 } = params;
|
|
15646
|
-
if (errorMap && (invalid_type_error || required_error)) {
|
|
15647
|
-
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
15648
|
-
}
|
|
15649
|
-
if (errorMap)
|
|
15650
|
-
return { errorMap, description: description2 };
|
|
15651
|
-
const customMap = (iss, ctx) => {
|
|
15652
|
-
var _a, _b;
|
|
15653
|
-
const { message } = params;
|
|
15654
|
-
if (iss.code === "invalid_enum_value") {
|
|
15655
|
-
return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
|
|
15656
|
-
}
|
|
15657
|
-
if (typeof ctx.data === "undefined") {
|
|
15658
|
-
return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
|
|
15659
|
-
}
|
|
15660
|
-
if (iss.code !== "invalid_type")
|
|
15661
|
-
return { message: ctx.defaultError };
|
|
15662
|
-
return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
|
|
15663
|
-
};
|
|
15664
|
-
return { errorMap: customMap, description: description2 };
|
|
15665
|
-
}
|
|
15666
|
-
class McpServer {
|
|
15667
|
-
constructor(serverInfo, options) {
|
|
15668
|
-
this._registeredResources = {};
|
|
15669
|
-
this._registeredResourceTemplates = {};
|
|
15670
|
-
this._registeredTools = {};
|
|
15671
|
-
this._registeredPrompts = {};
|
|
15672
|
-
this._toolHandlersInitialized = false;
|
|
15673
|
-
this._completionHandlerInitialized = false;
|
|
15674
|
-
this._resourceHandlersInitialized = false;
|
|
15675
|
-
this._promptHandlersInitialized = false;
|
|
15676
|
-
this.server = new Server(serverInfo, options);
|
|
15677
|
-
}
|
|
15678
|
-
/**
|
|
15679
|
-
* Attaches to the given transport, starts it, and starts listening for messages.
|
|
15680
|
-
*
|
|
15681
|
-
* The `server` object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
|
|
15682
|
-
*/
|
|
15683
|
-
async connect(transport) {
|
|
15684
|
-
return await this.server.connect(transport);
|
|
15685
|
-
}
|
|
15686
|
-
/**
|
|
15687
|
-
* Closes the connection.
|
|
15927
|
+
* Closes the connection.
|
|
15688
15928
|
*/
|
|
15689
15929
|
async close() {
|
|
15690
15930
|
await this.server.close();
|
|
@@ -15706,13 +15946,11 @@ class McpServer {
|
|
|
15706
15946
|
name,
|
|
15707
15947
|
title: tool.title,
|
|
15708
15948
|
description: tool.description,
|
|
15709
|
-
inputSchema: tool.inputSchema ?
|
|
15710
|
-
strictUnions: true
|
|
15711
|
-
}) : EMPTY_OBJECT_JSON_SCHEMA,
|
|
15949
|
+
inputSchema: tool.inputSchema ? safeToJSONSchema(tool.inputSchema) : EMPTY_OBJECT_JSON_SCHEMA,
|
|
15712
15950
|
annotations: tool.annotations
|
|
15713
15951
|
};
|
|
15714
15952
|
if (tool.outputSchema) {
|
|
15715
|
-
toolDefinition.outputSchema =
|
|
15953
|
+
toolDefinition.outputSchema = safeToJSONSchema(tool.outputSchema);
|
|
15716
15954
|
}
|
|
15717
15955
|
return toolDefinition;
|
|
15718
15956
|
})
|
|
@@ -15810,8 +16048,17 @@ class McpServer {
|
|
|
15810
16048
|
if (!(field instanceof Completable)) {
|
|
15811
16049
|
return EMPTY_COMPLETION_RESULT;
|
|
15812
16050
|
}
|
|
15813
|
-
const
|
|
15814
|
-
|
|
16051
|
+
const suggestions = await field.complete(request.params.argument.value, request.params.context);
|
|
16052
|
+
return createCompletionResult(suggestions);
|
|
16053
|
+
}
|
|
16054
|
+
async getFieldCompletions(field, request) {
|
|
16055
|
+
if (!field) {
|
|
16056
|
+
return EMPTY_COMPLETION_RESULT;
|
|
16057
|
+
}
|
|
16058
|
+
if (!(field instanceof Completable)) {
|
|
16059
|
+
return EMPTY_COMPLETION_RESULT;
|
|
16060
|
+
}
|
|
16061
|
+
const suggestions = await field.complete(request.params.argument.value, request.params.context);
|
|
15815
16062
|
return createCompletionResult(suggestions);
|
|
15816
16063
|
}
|
|
15817
16064
|
async handleResourceCompletion(request, ref2) {
|
|
@@ -16079,8 +16326,8 @@ class McpServer {
|
|
|
16079
16326
|
const registeredTool = {
|
|
16080
16327
|
title: title2,
|
|
16081
16328
|
description: description2,
|
|
16082
|
-
inputSchema: inputSchema === void 0 ? void 0 : zod.z.object(inputSchema),
|
|
16083
|
-
outputSchema: outputSchema === void 0 ? void 0 : zod.z.object(outputSchema),
|
|
16329
|
+
inputSchema: inputSchema === void 0 ? void 0 : isZodTypeLike(inputSchema) ? inputSchema : zod.z.object(inputSchema),
|
|
16330
|
+
outputSchema: outputSchema === void 0 ? void 0 : isZodTypeLike(outputSchema) ? outputSchema : zod.z.object(outputSchema),
|
|
16084
16331
|
annotations,
|
|
16085
16332
|
callback,
|
|
16086
16333
|
enabled: true,
|
|
@@ -16214,32 +16461,72 @@ class McpServer {
|
|
|
16214
16461
|
}
|
|
16215
16462
|
}
|
|
16216
16463
|
}
|
|
16464
|
+
class ResourceTemplate {
|
|
16465
|
+
constructor(uriTemplate, _callbacks) {
|
|
16466
|
+
this._callbacks = _callbacks;
|
|
16467
|
+
this._uriTemplate = typeof uriTemplate === "string" ? new UriTemplate(uriTemplate) : uriTemplate;
|
|
16468
|
+
}
|
|
16469
|
+
/**
|
|
16470
|
+
* Gets the URI template pattern.
|
|
16471
|
+
*/
|
|
16472
|
+
get uriTemplate() {
|
|
16473
|
+
return this._uriTemplate;
|
|
16474
|
+
}
|
|
16475
|
+
/**
|
|
16476
|
+
* Gets the list callback, if one was provided.
|
|
16477
|
+
*/
|
|
16478
|
+
get listCallback() {
|
|
16479
|
+
return this._callbacks.list;
|
|
16480
|
+
}
|
|
16481
|
+
/**
|
|
16482
|
+
* Gets the callback for completing a specific URI template variable, if one was provided.
|
|
16483
|
+
*/
|
|
16484
|
+
completeCallback(variable) {
|
|
16485
|
+
var _a;
|
|
16486
|
+
return (_a = this._callbacks.complete) === null || _a === void 0 ? void 0 : _a[variable];
|
|
16487
|
+
}
|
|
16488
|
+
}
|
|
16217
16489
|
const EMPTY_OBJECT_JSON_SCHEMA = {
|
|
16218
16490
|
type: "object",
|
|
16219
16491
|
properties: {}
|
|
16220
16492
|
};
|
|
16493
|
+
function safeToJSONSchema(schema) {
|
|
16494
|
+
try {
|
|
16495
|
+
if (!schema)
|
|
16496
|
+
return EMPTY_OBJECT_JSON_SCHEMA;
|
|
16497
|
+
return zod.z.toJSONSchema(schema);
|
|
16498
|
+
} catch (error) {
|
|
16499
|
+
console.error("JSON Schema generation failed:", error);
|
|
16500
|
+
return EMPTY_OBJECT_JSON_SCHEMA;
|
|
16501
|
+
}
|
|
16502
|
+
}
|
|
16221
16503
|
function isZodRawShape(obj) {
|
|
16222
16504
|
if (typeof obj !== "object" || obj === null)
|
|
16223
16505
|
return false;
|
|
16224
16506
|
const isEmptyObject = Object.keys(obj).length === 0;
|
|
16225
|
-
|
|
16507
|
+
const filteredValues = Object.entries(obj).filter(([key]) => key !== "~standard").map(([, value]) => value);
|
|
16508
|
+
return isEmptyObject || filteredValues.some(isZodTypeLike);
|
|
16226
16509
|
}
|
|
16227
16510
|
function isZodTypeLike(value) {
|
|
16228
16511
|
return value !== null && typeof value === "object" && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
16229
16512
|
}
|
|
16230
16513
|
function promptArgumentsFromSchema(schema) {
|
|
16231
|
-
return Object.entries(schema.shape).map(([name, field]) =>
|
|
16232
|
-
|
|
16233
|
-
|
|
16234
|
-
|
|
16235
|
-
|
|
16514
|
+
return Object.entries(schema.shape).map(([name, field]) => {
|
|
16515
|
+
var _a, _b, _c;
|
|
16516
|
+
return {
|
|
16517
|
+
name,
|
|
16518
|
+
description: field.description,
|
|
16519
|
+
required: !((_c = (_b = (_a = field).isOptional) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : false)
|
|
16520
|
+
};
|
|
16521
|
+
});
|
|
16236
16522
|
}
|
|
16237
16523
|
function createCompletionResult(suggestions) {
|
|
16524
|
+
const filteredSuggestions = suggestions.filter((s) => s !== void 0);
|
|
16238
16525
|
return {
|
|
16239
16526
|
completion: {
|
|
16240
|
-
values:
|
|
16241
|
-
total:
|
|
16242
|
-
hasMore:
|
|
16527
|
+
values: filteredSuggestions.slice(0, 100),
|
|
16528
|
+
total: filteredSuggestions.length,
|
|
16529
|
+
hasMore: filteredSuggestions.length > 100
|
|
16243
16530
|
}
|
|
16244
16531
|
};
|
|
16245
16532
|
}
|
|
@@ -16251,7 +16538,152 @@ const EMPTY_COMPLETION_RESULT = {
|
|
|
16251
16538
|
};
|
|
16252
16539
|
const mcp = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
16253
16540
|
__proto__: null,
|
|
16254
|
-
McpServer
|
|
16541
|
+
McpServer,
|
|
16542
|
+
ResourceTemplate
|
|
16543
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
16544
|
+
class McpLifecycleManager {
|
|
16545
|
+
constructor(events, logger, serverInfo, argParser) {
|
|
16546
|
+
this.events = events;
|
|
16547
|
+
this.logger = logger;
|
|
16548
|
+
this.serverInfo = serverInfo;
|
|
16549
|
+
this.argParser = argParser;
|
|
16550
|
+
this.state = {
|
|
16551
|
+
initialized: false,
|
|
16552
|
+
ready: false,
|
|
16553
|
+
shuttingDown: false
|
|
16554
|
+
};
|
|
16555
|
+
this.parsedArgs = {};
|
|
16556
|
+
}
|
|
16557
|
+
/**
|
|
16558
|
+
* Set the parsed arguments for flag access
|
|
16559
|
+
*/
|
|
16560
|
+
setParsedArgs(parsedArgs) {
|
|
16561
|
+
this.parsedArgs = parsedArgs;
|
|
16562
|
+
}
|
|
16563
|
+
/**
|
|
16564
|
+
* Get a flag value from parsed arguments or environment variables
|
|
16565
|
+
*/
|
|
16566
|
+
getFlag(name) {
|
|
16567
|
+
if (this.parsedArgs && this.parsedArgs[name] !== void 0) {
|
|
16568
|
+
return this.parsedArgs[name];
|
|
16569
|
+
}
|
|
16570
|
+
if (this.argParser) {
|
|
16571
|
+
const flagDef = this.argParser.getFlagDefinition(name);
|
|
16572
|
+
if (flagDef) {
|
|
16573
|
+
if (flagDef.env && process.env[flagDef.env]) {
|
|
16574
|
+
return process.env[flagDef.env];
|
|
16575
|
+
}
|
|
16576
|
+
return flagDef.defaultValue;
|
|
16577
|
+
}
|
|
16578
|
+
}
|
|
16579
|
+
return void 0;
|
|
16580
|
+
}
|
|
16581
|
+
/**
|
|
16582
|
+
* Handle the initialize request
|
|
16583
|
+
*/
|
|
16584
|
+
async handleInitialize(clientInfo, protocolVersion, clientCapabilities) {
|
|
16585
|
+
if (this.state.initialized) {
|
|
16586
|
+
this.logger.mcpError("Initialize called multiple times");
|
|
16587
|
+
return;
|
|
16588
|
+
}
|
|
16589
|
+
this.state.clientInfo = clientInfo;
|
|
16590
|
+
this.state.protocolVersion = protocolVersion;
|
|
16591
|
+
this.state.clientCapabilities = clientCapabilities;
|
|
16592
|
+
this.state.initialized = true;
|
|
16593
|
+
if (this.events.onInitialize) {
|
|
16594
|
+
const context = {
|
|
16595
|
+
getFlag: (name) => this.getFlag(name),
|
|
16596
|
+
logger: this.logger,
|
|
16597
|
+
serverInfo: this.serverInfo,
|
|
16598
|
+
clientInfo,
|
|
16599
|
+
protocolVersion,
|
|
16600
|
+
clientCapabilities
|
|
16601
|
+
};
|
|
16602
|
+
try {
|
|
16603
|
+
await this.events.onInitialize(context);
|
|
16604
|
+
this.logger.mcpError("Lifecycle onInitialize completed successfully");
|
|
16605
|
+
} catch (error) {
|
|
16606
|
+
this.logger.mcpError(
|
|
16607
|
+
`Lifecycle onInitialize failed: ${error instanceof Error ? error.message : String(error)}`
|
|
16608
|
+
);
|
|
16609
|
+
throw error;
|
|
16610
|
+
}
|
|
16611
|
+
}
|
|
16612
|
+
}
|
|
16613
|
+
/**
|
|
16614
|
+
* Handle the initialized notification
|
|
16615
|
+
*/
|
|
16616
|
+
async handleInitialized() {
|
|
16617
|
+
if (!this.state.initialized) {
|
|
16618
|
+
this.logger.mcpError("Initialized called before initialize");
|
|
16619
|
+
return;
|
|
16620
|
+
}
|
|
16621
|
+
if (this.state.ready) {
|
|
16622
|
+
this.logger.mcpError("Initialized called multiple times");
|
|
16623
|
+
return;
|
|
16624
|
+
}
|
|
16625
|
+
this.state.ready = true;
|
|
16626
|
+
if (this.events.onInitialized && this.state.clientInfo) {
|
|
16627
|
+
const context = {
|
|
16628
|
+
getFlag: (name) => this.getFlag(name),
|
|
16629
|
+
logger: this.logger,
|
|
16630
|
+
serverInfo: this.serverInfo,
|
|
16631
|
+
clientInfo: this.state.clientInfo,
|
|
16632
|
+
protocolVersion: this.state.protocolVersion
|
|
16633
|
+
};
|
|
16634
|
+
try {
|
|
16635
|
+
await this.events.onInitialized(context);
|
|
16636
|
+
this.logger.mcpError("Lifecycle onInitialized completed successfully");
|
|
16637
|
+
} catch (error) {
|
|
16638
|
+
this.logger.mcpError(
|
|
16639
|
+
`Lifecycle onInitialized failed: ${error instanceof Error ? error.message : String(error)}`
|
|
16640
|
+
);
|
|
16641
|
+
throw error;
|
|
16642
|
+
}
|
|
16643
|
+
}
|
|
16644
|
+
}
|
|
16645
|
+
/**
|
|
16646
|
+
* Handle server shutdown
|
|
16647
|
+
*/
|
|
16648
|
+
async handleShutdown(reason, error) {
|
|
16649
|
+
if (this.state.shuttingDown) {
|
|
16650
|
+
return;
|
|
16651
|
+
}
|
|
16652
|
+
this.state.shuttingDown = true;
|
|
16653
|
+
if (this.events.onShutdown) {
|
|
16654
|
+
const context = {
|
|
16655
|
+
getFlag: (name) => this.getFlag(name),
|
|
16656
|
+
logger: this.logger,
|
|
16657
|
+
serverInfo: this.serverInfo,
|
|
16658
|
+
reason,
|
|
16659
|
+
error
|
|
16660
|
+
};
|
|
16661
|
+
try {
|
|
16662
|
+
await this.events.onShutdown(context);
|
|
16663
|
+
this.logger.mcpError("Lifecycle onShutdown completed successfully");
|
|
16664
|
+
} catch (shutdownError) {
|
|
16665
|
+
this.logger.mcpError(
|
|
16666
|
+
`Lifecycle onShutdown failed: ${shutdownError instanceof Error ? shutdownError.message : String(shutdownError)}`
|
|
16667
|
+
);
|
|
16668
|
+
}
|
|
16669
|
+
}
|
|
16670
|
+
}
|
|
16671
|
+
/**
|
|
16672
|
+
* Get current lifecycle state
|
|
16673
|
+
*/
|
|
16674
|
+
getState() {
|
|
16675
|
+
return { ...this.state };
|
|
16676
|
+
}
|
|
16677
|
+
/**
|
|
16678
|
+
* Check if the server is ready for operations
|
|
16679
|
+
*/
|
|
16680
|
+
isReady() {
|
|
16681
|
+
return this.state.ready && !this.state.shuttingDown;
|
|
16682
|
+
}
|
|
16683
|
+
}
|
|
16684
|
+
const mcpLifecycle = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
16685
|
+
__proto__: null,
|
|
16686
|
+
McpLifecycleManager
|
|
16255
16687
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
16256
16688
|
class ReadBuffer {
|
|
16257
16689
|
append(chunk) {
|
|
@@ -22829,7 +23261,7 @@ class SSEServerTransport {
|
|
|
22829
23261
|
Connection: "keep-alive"
|
|
22830
23262
|
});
|
|
22831
23263
|
const dummyBase = "http://localhost";
|
|
22832
|
-
const endpointUrl = new
|
|
23264
|
+
const endpointUrl = new node_url.URL(this._endpoint, dummyBase);
|
|
22833
23265
|
endpointUrl.searchParams.set("sessionId", this._sessionId);
|
|
22834
23266
|
const relativeUrlWithSession = endpointUrl.pathname + endpointUrl.search + endpointUrl.hash;
|
|
22835
23267
|
this.res.write(`event: endpoint
|
|
@@ -24541,6 +24973,7 @@ exports.createTomlPluginAsync = createTomlPluginAsync;
|
|
|
24541
24973
|
exports.createYamlPlugin = createYamlPlugin;
|
|
24542
24974
|
exports.createYamlPluginAsync = createYamlPluginAsync;
|
|
24543
24975
|
exports.cwdRelative = cwdRelative;
|
|
24976
|
+
exports.debug = debug;
|
|
24544
24977
|
exports.detectEntryPoint = detectEntryPoint;
|
|
24545
24978
|
exports.enableConfigPlugins = enableConfigPlugins;
|
|
24546
24979
|
exports.enableOptionalConfigPlugins = enableOptionalConfigPlugins;
|
|
@@ -24551,7 +24984,9 @@ exports.generateMcpToolsFromArgParser = generateMcpToolsFromArgParser;
|
|
|
24551
24984
|
exports.getEntryPointFromImportMeta = getEntryPointFromImportMeta;
|
|
24552
24985
|
exports.getJsonSchemaTypeFromFlag = getJsonSchemaTypeFromFlag;
|
|
24553
24986
|
exports.globalConfigPluginRegistry = globalConfigPluginRegistry;
|
|
24987
|
+
exports.isValidMcpToolName = isValidMcpToolName;
|
|
24554
24988
|
exports.legacyCwdPath = legacyCwdPath;
|
|
24555
24989
|
exports.resolveLogPath = resolveLogPath;
|
|
24990
|
+
exports.sanitizeMcpToolName = sanitizeMcpToolName;
|
|
24556
24991
|
exports.zodFlagSchema = zodFlagSchema;
|
|
24557
24992
|
//# sourceMappingURL=index.cjs.map
|