fixparser-plugin-mcp 9.1.7-af630b11 → 9.1.7-b2bba224
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/build/cjs/MCPLocal.js +321 -1613
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/esm/MCPLocal.mjs +330 -1622
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +4 -7
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +4 -7
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +6 -5
- package/types/MCPLocal.d.ts +0 -1
package/build/esm/MCPLocal.mjs
CHANGED
|
@@ -8,1265 +8,6 @@ import {
|
|
|
8
8
|
ListResourcesRequestSchema,
|
|
9
9
|
ListToolsRequestSchema
|
|
10
10
|
} from "@modelcontextprotocol/sdk/types.js";
|
|
11
|
-
import { z } from "zod";
|
|
12
|
-
|
|
13
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
14
|
-
var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
15
|
-
var defaultOptions = {
|
|
16
|
-
name: void 0,
|
|
17
|
-
$refStrategy: "root",
|
|
18
|
-
basePath: ["#"],
|
|
19
|
-
effectStrategy: "input",
|
|
20
|
-
pipeStrategy: "all",
|
|
21
|
-
dateStrategy: "format:date-time",
|
|
22
|
-
mapStrategy: "entries",
|
|
23
|
-
removeAdditionalStrategy: "passthrough",
|
|
24
|
-
allowedAdditionalProperties: true,
|
|
25
|
-
rejectedAdditionalProperties: false,
|
|
26
|
-
definitionPath: "definitions",
|
|
27
|
-
target: "jsonSchema7",
|
|
28
|
-
strictUnions: false,
|
|
29
|
-
definitions: {},
|
|
30
|
-
errorMessages: false,
|
|
31
|
-
markdownDescription: false,
|
|
32
|
-
patternStrategy: "escape",
|
|
33
|
-
applyRegexFlags: false,
|
|
34
|
-
emailStrategy: "format:email",
|
|
35
|
-
base64Strategy: "contentEncoding:base64",
|
|
36
|
-
nameStrategy: "ref"
|
|
37
|
-
};
|
|
38
|
-
var getDefaultOptions = (options) => typeof options === "string" ? {
|
|
39
|
-
...defaultOptions,
|
|
40
|
-
name: options
|
|
41
|
-
} : {
|
|
42
|
-
...defaultOptions,
|
|
43
|
-
...options
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/Refs.js
|
|
47
|
-
var getRefs = (options) => {
|
|
48
|
-
const _options = getDefaultOptions(options);
|
|
49
|
-
const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
50
|
-
return {
|
|
51
|
-
..._options,
|
|
52
|
-
currentPath,
|
|
53
|
-
propertyPath: void 0,
|
|
54
|
-
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
|
|
55
|
-
def._def,
|
|
56
|
-
{
|
|
57
|
-
def: def._def,
|
|
58
|
-
path: [..._options.basePath, _options.definitionPath, name],
|
|
59
|
-
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
60
|
-
jsonSchema: void 0
|
|
61
|
-
}
|
|
62
|
-
]))
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/errorMessages.js
|
|
67
|
-
function addErrorMessage(res, key, errorMessage, refs) {
|
|
68
|
-
if (!refs?.errorMessages)
|
|
69
|
-
return;
|
|
70
|
-
if (errorMessage) {
|
|
71
|
-
res.errorMessage = {
|
|
72
|
-
...res.errorMessage,
|
|
73
|
-
[key]: errorMessage
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
78
|
-
res[key] = value;
|
|
79
|
-
addErrorMessage(res, key, errorMessage, refs);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
83
|
-
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod";
|
|
84
|
-
|
|
85
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/any.js
|
|
86
|
-
function parseAnyDef() {
|
|
87
|
-
return {};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
91
|
-
import { ZodFirstPartyTypeKind } from "zod";
|
|
92
|
-
function parseArrayDef(def, refs) {
|
|
93
|
-
const res = {
|
|
94
|
-
type: "array"
|
|
95
|
-
};
|
|
96
|
-
if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
|
|
97
|
-
res.items = parseDef(def.type._def, {
|
|
98
|
-
...refs,
|
|
99
|
-
currentPath: [...refs.currentPath, "items"]
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
if (def.minLength) {
|
|
103
|
-
setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
104
|
-
}
|
|
105
|
-
if (def.maxLength) {
|
|
106
|
-
setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
107
|
-
}
|
|
108
|
-
if (def.exactLength) {
|
|
109
|
-
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
110
|
-
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
111
|
-
}
|
|
112
|
-
return res;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
|
|
116
|
-
function parseBigintDef(def, refs) {
|
|
117
|
-
const res = {
|
|
118
|
-
type: "integer",
|
|
119
|
-
format: "int64"
|
|
120
|
-
};
|
|
121
|
-
if (!def.checks)
|
|
122
|
-
return res;
|
|
123
|
-
for (const check of def.checks) {
|
|
124
|
-
switch (check.kind) {
|
|
125
|
-
case "min":
|
|
126
|
-
if (refs.target === "jsonSchema7") {
|
|
127
|
-
if (check.inclusive) {
|
|
128
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
129
|
-
} else {
|
|
130
|
-
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
131
|
-
}
|
|
132
|
-
} else {
|
|
133
|
-
if (!check.inclusive) {
|
|
134
|
-
res.exclusiveMinimum = true;
|
|
135
|
-
}
|
|
136
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
137
|
-
}
|
|
138
|
-
break;
|
|
139
|
-
case "max":
|
|
140
|
-
if (refs.target === "jsonSchema7") {
|
|
141
|
-
if (check.inclusive) {
|
|
142
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
143
|
-
} else {
|
|
144
|
-
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
145
|
-
}
|
|
146
|
-
} else {
|
|
147
|
-
if (!check.inclusive) {
|
|
148
|
-
res.exclusiveMaximum = true;
|
|
149
|
-
}
|
|
150
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
151
|
-
}
|
|
152
|
-
break;
|
|
153
|
-
case "multipleOf":
|
|
154
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return res;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
162
|
-
function parseBooleanDef() {
|
|
163
|
-
return {
|
|
164
|
-
type: "boolean"
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
|
|
169
|
-
function parseBrandedDef(_def, refs) {
|
|
170
|
-
return parseDef(_def.type._def, refs);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
|
|
174
|
-
var parseCatchDef = (def, refs) => {
|
|
175
|
-
return parseDef(def.innerType._def, refs);
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/date.js
|
|
179
|
-
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
180
|
-
const strategy = overrideDateStrategy ?? refs.dateStrategy;
|
|
181
|
-
if (Array.isArray(strategy)) {
|
|
182
|
-
return {
|
|
183
|
-
anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
switch (strategy) {
|
|
187
|
-
case "string":
|
|
188
|
-
case "format:date-time":
|
|
189
|
-
return {
|
|
190
|
-
type: "string",
|
|
191
|
-
format: "date-time"
|
|
192
|
-
};
|
|
193
|
-
case "format:date":
|
|
194
|
-
return {
|
|
195
|
-
type: "string",
|
|
196
|
-
format: "date"
|
|
197
|
-
};
|
|
198
|
-
case "integer":
|
|
199
|
-
return integerDateParser(def, refs);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
var integerDateParser = (def, refs) => {
|
|
203
|
-
const res = {
|
|
204
|
-
type: "integer",
|
|
205
|
-
format: "unix-time"
|
|
206
|
-
};
|
|
207
|
-
if (refs.target === "openApi3") {
|
|
208
|
-
return res;
|
|
209
|
-
}
|
|
210
|
-
for (const check of def.checks) {
|
|
211
|
-
switch (check.kind) {
|
|
212
|
-
case "min":
|
|
213
|
-
setResponseValueAndErrors(
|
|
214
|
-
res,
|
|
215
|
-
"minimum",
|
|
216
|
-
check.value,
|
|
217
|
-
// This is in milliseconds
|
|
218
|
-
check.message,
|
|
219
|
-
refs
|
|
220
|
-
);
|
|
221
|
-
break;
|
|
222
|
-
case "max":
|
|
223
|
-
setResponseValueAndErrors(
|
|
224
|
-
res,
|
|
225
|
-
"maximum",
|
|
226
|
-
check.value,
|
|
227
|
-
// This is in milliseconds
|
|
228
|
-
check.message,
|
|
229
|
-
refs
|
|
230
|
-
);
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return res;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/default.js
|
|
238
|
-
function parseDefaultDef(_def, refs) {
|
|
239
|
-
return {
|
|
240
|
-
...parseDef(_def.innerType._def, refs),
|
|
241
|
-
default: _def.defaultValue()
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
|
|
246
|
-
function parseEffectsDef(_def, refs) {
|
|
247
|
-
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : {};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
|
|
251
|
-
function parseEnumDef(def) {
|
|
252
|
-
return {
|
|
253
|
-
type: "string",
|
|
254
|
-
enum: Array.from(def.values)
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
259
|
-
var isJsonSchema7AllOfType = (type) => {
|
|
260
|
-
if ("type" in type && type.type === "string")
|
|
261
|
-
return false;
|
|
262
|
-
return "allOf" in type;
|
|
263
|
-
};
|
|
264
|
-
function parseIntersectionDef(def, refs) {
|
|
265
|
-
const allOf = [
|
|
266
|
-
parseDef(def.left._def, {
|
|
267
|
-
...refs,
|
|
268
|
-
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
269
|
-
}),
|
|
270
|
-
parseDef(def.right._def, {
|
|
271
|
-
...refs,
|
|
272
|
-
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
273
|
-
})
|
|
274
|
-
].filter((x) => !!x);
|
|
275
|
-
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
|
|
276
|
-
const mergedAllOf = [];
|
|
277
|
-
allOf.forEach((schema) => {
|
|
278
|
-
if (isJsonSchema7AllOfType(schema)) {
|
|
279
|
-
mergedAllOf.push(...schema.allOf);
|
|
280
|
-
if (schema.unevaluatedProperties === void 0) {
|
|
281
|
-
unevaluatedProperties = void 0;
|
|
282
|
-
}
|
|
283
|
-
} else {
|
|
284
|
-
let nestedSchema = schema;
|
|
285
|
-
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
286
|
-
const { additionalProperties, ...rest } = schema;
|
|
287
|
-
nestedSchema = rest;
|
|
288
|
-
} else {
|
|
289
|
-
unevaluatedProperties = void 0;
|
|
290
|
-
}
|
|
291
|
-
mergedAllOf.push(nestedSchema);
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
return mergedAllOf.length ? {
|
|
295
|
-
allOf: mergedAllOf,
|
|
296
|
-
...unevaluatedProperties
|
|
297
|
-
} : void 0;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
|
|
301
|
-
function parseLiteralDef(def, refs) {
|
|
302
|
-
const parsedType = typeof def.value;
|
|
303
|
-
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
304
|
-
return {
|
|
305
|
-
type: Array.isArray(def.value) ? "array" : "object"
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
if (refs.target === "openApi3") {
|
|
309
|
-
return {
|
|
310
|
-
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
311
|
-
enum: [def.value]
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
return {
|
|
315
|
-
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
316
|
-
const: def.value
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
321
|
-
import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2 } from "zod";
|
|
322
|
-
|
|
323
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
324
|
-
var emojiRegex = void 0;
|
|
325
|
-
var zodPatterns = {
|
|
326
|
-
/**
|
|
327
|
-
* `c` was changed to `[cC]` to replicate /i flag
|
|
328
|
-
*/
|
|
329
|
-
cuid: /^[cC][^\s-]{8,}$/,
|
|
330
|
-
cuid2: /^[0-9a-z]+$/,
|
|
331
|
-
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
332
|
-
/**
|
|
333
|
-
* `a-z` was added to replicate /i flag
|
|
334
|
-
*/
|
|
335
|
-
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
336
|
-
/**
|
|
337
|
-
* Constructed a valid Unicode RegExp
|
|
338
|
-
*
|
|
339
|
-
* Lazily instantiate since this type of regex isn't supported
|
|
340
|
-
* in all envs (e.g. React Native).
|
|
341
|
-
*
|
|
342
|
-
* See:
|
|
343
|
-
* https://github.com/colinhacks/zod/issues/2433
|
|
344
|
-
* Fix in Zod:
|
|
345
|
-
* https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
|
|
346
|
-
*/
|
|
347
|
-
emoji: () => {
|
|
348
|
-
if (emojiRegex === void 0) {
|
|
349
|
-
emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
350
|
-
}
|
|
351
|
-
return emojiRegex;
|
|
352
|
-
},
|
|
353
|
-
/**
|
|
354
|
-
* Unused
|
|
355
|
-
*/
|
|
356
|
-
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}$/,
|
|
357
|
-
/**
|
|
358
|
-
* Unused
|
|
359
|
-
*/
|
|
360
|
-
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
361
|
-
ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
|
|
362
|
-
/**
|
|
363
|
-
* Unused
|
|
364
|
-
*/
|
|
365
|
-
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})))$/,
|
|
366
|
-
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])$/,
|
|
367
|
-
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
368
|
-
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
369
|
-
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
370
|
-
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
371
|
-
};
|
|
372
|
-
function parseStringDef(def, refs) {
|
|
373
|
-
const res = {
|
|
374
|
-
type: "string"
|
|
375
|
-
};
|
|
376
|
-
if (def.checks) {
|
|
377
|
-
for (const check of def.checks) {
|
|
378
|
-
switch (check.kind) {
|
|
379
|
-
case "min":
|
|
380
|
-
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
381
|
-
break;
|
|
382
|
-
case "max":
|
|
383
|
-
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
384
|
-
break;
|
|
385
|
-
case "email":
|
|
386
|
-
switch (refs.emailStrategy) {
|
|
387
|
-
case "format:email":
|
|
388
|
-
addFormat(res, "email", check.message, refs);
|
|
389
|
-
break;
|
|
390
|
-
case "format:idn-email":
|
|
391
|
-
addFormat(res, "idn-email", check.message, refs);
|
|
392
|
-
break;
|
|
393
|
-
case "pattern:zod":
|
|
394
|
-
addPattern(res, zodPatterns.email, check.message, refs);
|
|
395
|
-
break;
|
|
396
|
-
}
|
|
397
|
-
break;
|
|
398
|
-
case "url":
|
|
399
|
-
addFormat(res, "uri", check.message, refs);
|
|
400
|
-
break;
|
|
401
|
-
case "uuid":
|
|
402
|
-
addFormat(res, "uuid", check.message, refs);
|
|
403
|
-
break;
|
|
404
|
-
case "regex":
|
|
405
|
-
addPattern(res, check.regex, check.message, refs);
|
|
406
|
-
break;
|
|
407
|
-
case "cuid":
|
|
408
|
-
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
409
|
-
break;
|
|
410
|
-
case "cuid2":
|
|
411
|
-
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
412
|
-
break;
|
|
413
|
-
case "startsWith":
|
|
414
|
-
addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
|
|
415
|
-
break;
|
|
416
|
-
case "endsWith":
|
|
417
|
-
addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
|
|
418
|
-
break;
|
|
419
|
-
case "datetime":
|
|
420
|
-
addFormat(res, "date-time", check.message, refs);
|
|
421
|
-
break;
|
|
422
|
-
case "date":
|
|
423
|
-
addFormat(res, "date", check.message, refs);
|
|
424
|
-
break;
|
|
425
|
-
case "time":
|
|
426
|
-
addFormat(res, "time", check.message, refs);
|
|
427
|
-
break;
|
|
428
|
-
case "duration":
|
|
429
|
-
addFormat(res, "duration", check.message, refs);
|
|
430
|
-
break;
|
|
431
|
-
case "length":
|
|
432
|
-
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
433
|
-
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
434
|
-
break;
|
|
435
|
-
case "includes": {
|
|
436
|
-
addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
|
|
437
|
-
break;
|
|
438
|
-
}
|
|
439
|
-
case "ip": {
|
|
440
|
-
if (check.version !== "v6") {
|
|
441
|
-
addFormat(res, "ipv4", check.message, refs);
|
|
442
|
-
}
|
|
443
|
-
if (check.version !== "v4") {
|
|
444
|
-
addFormat(res, "ipv6", check.message, refs);
|
|
445
|
-
}
|
|
446
|
-
break;
|
|
447
|
-
}
|
|
448
|
-
case "base64url":
|
|
449
|
-
addPattern(res, zodPatterns.base64url, check.message, refs);
|
|
450
|
-
break;
|
|
451
|
-
case "jwt":
|
|
452
|
-
addPattern(res, zodPatterns.jwt, check.message, refs);
|
|
453
|
-
break;
|
|
454
|
-
case "cidr": {
|
|
455
|
-
if (check.version !== "v6") {
|
|
456
|
-
addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
|
|
457
|
-
}
|
|
458
|
-
if (check.version !== "v4") {
|
|
459
|
-
addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
|
|
460
|
-
}
|
|
461
|
-
break;
|
|
462
|
-
}
|
|
463
|
-
case "emoji":
|
|
464
|
-
addPattern(res, zodPatterns.emoji(), check.message, refs);
|
|
465
|
-
break;
|
|
466
|
-
case "ulid": {
|
|
467
|
-
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
468
|
-
break;
|
|
469
|
-
}
|
|
470
|
-
case "base64": {
|
|
471
|
-
switch (refs.base64Strategy) {
|
|
472
|
-
case "format:binary": {
|
|
473
|
-
addFormat(res, "binary", check.message, refs);
|
|
474
|
-
break;
|
|
475
|
-
}
|
|
476
|
-
case "contentEncoding:base64": {
|
|
477
|
-
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
|
|
478
|
-
break;
|
|
479
|
-
}
|
|
480
|
-
case "pattern:zod": {
|
|
481
|
-
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
482
|
-
break;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
break;
|
|
486
|
-
}
|
|
487
|
-
case "nanoid": {
|
|
488
|
-
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
489
|
-
}
|
|
490
|
-
case "toLowerCase":
|
|
491
|
-
case "toUpperCase":
|
|
492
|
-
case "trim":
|
|
493
|
-
break;
|
|
494
|
-
default:
|
|
495
|
-
/* @__PURE__ */ ((_) => {
|
|
496
|
-
})(check);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
return res;
|
|
501
|
-
}
|
|
502
|
-
function escapeLiteralCheckValue(literal, refs) {
|
|
503
|
-
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
|
|
504
|
-
}
|
|
505
|
-
var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
506
|
-
function escapeNonAlphaNumeric(source) {
|
|
507
|
-
let result = "";
|
|
508
|
-
for (let i = 0; i < source.length; i++) {
|
|
509
|
-
if (!ALPHA_NUMERIC.has(source[i])) {
|
|
510
|
-
result += "\\";
|
|
511
|
-
}
|
|
512
|
-
result += source[i];
|
|
513
|
-
}
|
|
514
|
-
return result;
|
|
515
|
-
}
|
|
516
|
-
function addFormat(schema, value, message, refs) {
|
|
517
|
-
if (schema.format || schema.anyOf?.some((x) => x.format)) {
|
|
518
|
-
if (!schema.anyOf) {
|
|
519
|
-
schema.anyOf = [];
|
|
520
|
-
}
|
|
521
|
-
if (schema.format) {
|
|
522
|
-
schema.anyOf.push({
|
|
523
|
-
format: schema.format,
|
|
524
|
-
...schema.errorMessage && refs.errorMessages && {
|
|
525
|
-
errorMessage: { format: schema.errorMessage.format }
|
|
526
|
-
}
|
|
527
|
-
});
|
|
528
|
-
delete schema.format;
|
|
529
|
-
if (schema.errorMessage) {
|
|
530
|
-
delete schema.errorMessage.format;
|
|
531
|
-
if (Object.keys(schema.errorMessage).length === 0) {
|
|
532
|
-
delete schema.errorMessage;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
schema.anyOf.push({
|
|
537
|
-
format: value,
|
|
538
|
-
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
539
|
-
});
|
|
540
|
-
} else {
|
|
541
|
-
setResponseValueAndErrors(schema, "format", value, message, refs);
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
function addPattern(schema, regex, message, refs) {
|
|
545
|
-
if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
|
|
546
|
-
if (!schema.allOf) {
|
|
547
|
-
schema.allOf = [];
|
|
548
|
-
}
|
|
549
|
-
if (schema.pattern) {
|
|
550
|
-
schema.allOf.push({
|
|
551
|
-
pattern: schema.pattern,
|
|
552
|
-
...schema.errorMessage && refs.errorMessages && {
|
|
553
|
-
errorMessage: { pattern: schema.errorMessage.pattern }
|
|
554
|
-
}
|
|
555
|
-
});
|
|
556
|
-
delete schema.pattern;
|
|
557
|
-
if (schema.errorMessage) {
|
|
558
|
-
delete schema.errorMessage.pattern;
|
|
559
|
-
if (Object.keys(schema.errorMessage).length === 0) {
|
|
560
|
-
delete schema.errorMessage;
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
schema.allOf.push({
|
|
565
|
-
pattern: stringifyRegExpWithFlags(regex, refs),
|
|
566
|
-
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
567
|
-
});
|
|
568
|
-
} else {
|
|
569
|
-
setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
function stringifyRegExpWithFlags(regex, refs) {
|
|
573
|
-
if (!refs.applyRegexFlags || !regex.flags) {
|
|
574
|
-
return regex.source;
|
|
575
|
-
}
|
|
576
|
-
const flags = {
|
|
577
|
-
i: regex.flags.includes("i"),
|
|
578
|
-
m: regex.flags.includes("m"),
|
|
579
|
-
s: regex.flags.includes("s")
|
|
580
|
-
// `.` matches newlines
|
|
581
|
-
};
|
|
582
|
-
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
583
|
-
let pattern = "";
|
|
584
|
-
let isEscaped = false;
|
|
585
|
-
let inCharGroup = false;
|
|
586
|
-
let inCharRange = false;
|
|
587
|
-
for (let i = 0; i < source.length; i++) {
|
|
588
|
-
if (isEscaped) {
|
|
589
|
-
pattern += source[i];
|
|
590
|
-
isEscaped = false;
|
|
591
|
-
continue;
|
|
592
|
-
}
|
|
593
|
-
if (flags.i) {
|
|
594
|
-
if (inCharGroup) {
|
|
595
|
-
if (source[i].match(/[a-z]/)) {
|
|
596
|
-
if (inCharRange) {
|
|
597
|
-
pattern += source[i];
|
|
598
|
-
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
599
|
-
inCharRange = false;
|
|
600
|
-
} else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
|
|
601
|
-
pattern += source[i];
|
|
602
|
-
inCharRange = true;
|
|
603
|
-
} else {
|
|
604
|
-
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
605
|
-
}
|
|
606
|
-
continue;
|
|
607
|
-
}
|
|
608
|
-
} else if (source[i].match(/[a-z]/)) {
|
|
609
|
-
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
610
|
-
continue;
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
if (flags.m) {
|
|
614
|
-
if (source[i] === "^") {
|
|
615
|
-
pattern += `(^|(?<=[\r
|
|
616
|
-
]))`;
|
|
617
|
-
continue;
|
|
618
|
-
} else if (source[i] === "$") {
|
|
619
|
-
pattern += `($|(?=[\r
|
|
620
|
-
]))`;
|
|
621
|
-
continue;
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
if (flags.s && source[i] === ".") {
|
|
625
|
-
pattern += inCharGroup ? `${source[i]}\r
|
|
626
|
-
` : `[${source[i]}\r
|
|
627
|
-
]`;
|
|
628
|
-
continue;
|
|
629
|
-
}
|
|
630
|
-
pattern += source[i];
|
|
631
|
-
if (source[i] === "\\") {
|
|
632
|
-
isEscaped = true;
|
|
633
|
-
} else if (inCharGroup && source[i] === "]") {
|
|
634
|
-
inCharGroup = false;
|
|
635
|
-
} else if (!inCharGroup && source[i] === "[") {
|
|
636
|
-
inCharGroup = true;
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
try {
|
|
640
|
-
new RegExp(pattern);
|
|
641
|
-
} catch {
|
|
642
|
-
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
643
|
-
return regex.source;
|
|
644
|
-
}
|
|
645
|
-
return pattern;
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
649
|
-
function parseRecordDef(def, refs) {
|
|
650
|
-
if (refs.target === "openAi") {
|
|
651
|
-
console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
|
|
652
|
-
}
|
|
653
|
-
if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
654
|
-
return {
|
|
655
|
-
type: "object",
|
|
656
|
-
required: def.keyType._def.values,
|
|
657
|
-
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
658
|
-
...acc,
|
|
659
|
-
[key]: parseDef(def.valueType._def, {
|
|
660
|
-
...refs,
|
|
661
|
-
currentPath: [...refs.currentPath, "properties", key]
|
|
662
|
-
}) ?? {}
|
|
663
|
-
}), {}),
|
|
664
|
-
additionalProperties: refs.rejectedAdditionalProperties
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
const schema = {
|
|
668
|
-
type: "object",
|
|
669
|
-
additionalProperties: parseDef(def.valueType._def, {
|
|
670
|
-
...refs,
|
|
671
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
672
|
-
}) ?? refs.allowedAdditionalProperties
|
|
673
|
-
};
|
|
674
|
-
if (refs.target === "openApi3") {
|
|
675
|
-
return schema;
|
|
676
|
-
}
|
|
677
|
-
if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.checks?.length) {
|
|
678
|
-
const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
|
|
679
|
-
return {
|
|
680
|
-
...schema,
|
|
681
|
-
propertyNames: keyType
|
|
682
|
-
};
|
|
683
|
-
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodEnum) {
|
|
684
|
-
return {
|
|
685
|
-
...schema,
|
|
686
|
-
propertyNames: {
|
|
687
|
-
enum: def.keyType._def.values
|
|
688
|
-
}
|
|
689
|
-
};
|
|
690
|
-
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind2.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind2.ZodString && def.keyType._def.type._def.checks?.length) {
|
|
691
|
-
const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
692
|
-
return {
|
|
693
|
-
...schema,
|
|
694
|
-
propertyNames: keyType
|
|
695
|
-
};
|
|
696
|
-
}
|
|
697
|
-
return schema;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/map.js
|
|
701
|
-
function parseMapDef(def, refs) {
|
|
702
|
-
if (refs.mapStrategy === "record") {
|
|
703
|
-
return parseRecordDef(def, refs);
|
|
704
|
-
}
|
|
705
|
-
const keys = parseDef(def.keyType._def, {
|
|
706
|
-
...refs,
|
|
707
|
-
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
708
|
-
}) || {};
|
|
709
|
-
const values = parseDef(def.valueType._def, {
|
|
710
|
-
...refs,
|
|
711
|
-
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
712
|
-
}) || {};
|
|
713
|
-
return {
|
|
714
|
-
type: "array",
|
|
715
|
-
maxItems: 125,
|
|
716
|
-
items: {
|
|
717
|
-
type: "array",
|
|
718
|
-
items: [keys, values],
|
|
719
|
-
minItems: 2,
|
|
720
|
-
maxItems: 2
|
|
721
|
-
}
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
726
|
-
function parseNativeEnumDef(def) {
|
|
727
|
-
const object = def.values;
|
|
728
|
-
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
729
|
-
return typeof object[object[key]] !== "number";
|
|
730
|
-
});
|
|
731
|
-
const actualValues = actualKeys.map((key) => object[key]);
|
|
732
|
-
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
733
|
-
return {
|
|
734
|
-
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
735
|
-
enum: actualValues
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/never.js
|
|
740
|
-
function parseNeverDef() {
|
|
741
|
-
return {
|
|
742
|
-
not: {}
|
|
743
|
-
};
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/null.js
|
|
747
|
-
function parseNullDef(refs) {
|
|
748
|
-
return refs.target === "openApi3" ? {
|
|
749
|
-
enum: ["null"],
|
|
750
|
-
nullable: true
|
|
751
|
-
} : {
|
|
752
|
-
type: "null"
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/union.js
|
|
757
|
-
var primitiveMappings = {
|
|
758
|
-
ZodString: "string",
|
|
759
|
-
ZodNumber: "number",
|
|
760
|
-
ZodBigInt: "integer",
|
|
761
|
-
ZodBoolean: "boolean",
|
|
762
|
-
ZodNull: "null"
|
|
763
|
-
};
|
|
764
|
-
function parseUnionDef(def, refs) {
|
|
765
|
-
if (refs.target === "openApi3")
|
|
766
|
-
return asAnyOf(def, refs);
|
|
767
|
-
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
768
|
-
if (options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
|
|
769
|
-
const types = options.reduce((types2, x) => {
|
|
770
|
-
const type = primitiveMappings[x._def.typeName];
|
|
771
|
-
return type && !types2.includes(type) ? [...types2, type] : types2;
|
|
772
|
-
}, []);
|
|
773
|
-
return {
|
|
774
|
-
type: types.length > 1 ? types : types[0]
|
|
775
|
-
};
|
|
776
|
-
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
777
|
-
const types = options.reduce((acc, x) => {
|
|
778
|
-
const type = typeof x._def.value;
|
|
779
|
-
switch (type) {
|
|
780
|
-
case "string":
|
|
781
|
-
case "number":
|
|
782
|
-
case "boolean":
|
|
783
|
-
return [...acc, type];
|
|
784
|
-
case "bigint":
|
|
785
|
-
return [...acc, "integer"];
|
|
786
|
-
case "object":
|
|
787
|
-
if (x._def.value === null)
|
|
788
|
-
return [...acc, "null"];
|
|
789
|
-
case "symbol":
|
|
790
|
-
case "undefined":
|
|
791
|
-
case "function":
|
|
792
|
-
default:
|
|
793
|
-
return acc;
|
|
794
|
-
}
|
|
795
|
-
}, []);
|
|
796
|
-
if (types.length === options.length) {
|
|
797
|
-
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
798
|
-
return {
|
|
799
|
-
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
800
|
-
enum: options.reduce((acc, x) => {
|
|
801
|
-
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
802
|
-
}, [])
|
|
803
|
-
};
|
|
804
|
-
}
|
|
805
|
-
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
806
|
-
return {
|
|
807
|
-
type: "string",
|
|
808
|
-
enum: options.reduce((acc, x) => [
|
|
809
|
-
...acc,
|
|
810
|
-
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
811
|
-
], [])
|
|
812
|
-
};
|
|
813
|
-
}
|
|
814
|
-
return asAnyOf(def, refs);
|
|
815
|
-
}
|
|
816
|
-
var asAnyOf = (def, refs) => {
|
|
817
|
-
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
|
|
818
|
-
...refs,
|
|
819
|
-
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
820
|
-
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
821
|
-
return anyOf.length ? { anyOf } : void 0;
|
|
822
|
-
};
|
|
823
|
-
|
|
824
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
825
|
-
function parseNullableDef(def, refs) {
|
|
826
|
-
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
827
|
-
if (refs.target === "openApi3") {
|
|
828
|
-
return {
|
|
829
|
-
type: primitiveMappings[def.innerType._def.typeName],
|
|
830
|
-
nullable: true
|
|
831
|
-
};
|
|
832
|
-
}
|
|
833
|
-
return {
|
|
834
|
-
type: [
|
|
835
|
-
primitiveMappings[def.innerType._def.typeName],
|
|
836
|
-
"null"
|
|
837
|
-
]
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
if (refs.target === "openApi3") {
|
|
841
|
-
const base2 = parseDef(def.innerType._def, {
|
|
842
|
-
...refs,
|
|
843
|
-
currentPath: [...refs.currentPath]
|
|
844
|
-
});
|
|
845
|
-
if (base2 && "$ref" in base2)
|
|
846
|
-
return { allOf: [base2], nullable: true };
|
|
847
|
-
return base2 && { ...base2, nullable: true };
|
|
848
|
-
}
|
|
849
|
-
const base = parseDef(def.innerType._def, {
|
|
850
|
-
...refs,
|
|
851
|
-
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
852
|
-
});
|
|
853
|
-
return base && { anyOf: [base, { type: "null" }] };
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/number.js
|
|
857
|
-
function parseNumberDef(def, refs) {
|
|
858
|
-
const res = {
|
|
859
|
-
type: "number"
|
|
860
|
-
};
|
|
861
|
-
if (!def.checks)
|
|
862
|
-
return res;
|
|
863
|
-
for (const check of def.checks) {
|
|
864
|
-
switch (check.kind) {
|
|
865
|
-
case "int":
|
|
866
|
-
res.type = "integer";
|
|
867
|
-
addErrorMessage(res, "type", check.message, refs);
|
|
868
|
-
break;
|
|
869
|
-
case "min":
|
|
870
|
-
if (refs.target === "jsonSchema7") {
|
|
871
|
-
if (check.inclusive) {
|
|
872
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
873
|
-
} else {
|
|
874
|
-
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
875
|
-
}
|
|
876
|
-
} else {
|
|
877
|
-
if (!check.inclusive) {
|
|
878
|
-
res.exclusiveMinimum = true;
|
|
879
|
-
}
|
|
880
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
881
|
-
}
|
|
882
|
-
break;
|
|
883
|
-
case "max":
|
|
884
|
-
if (refs.target === "jsonSchema7") {
|
|
885
|
-
if (check.inclusive) {
|
|
886
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
887
|
-
} else {
|
|
888
|
-
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
889
|
-
}
|
|
890
|
-
} else {
|
|
891
|
-
if (!check.inclusive) {
|
|
892
|
-
res.exclusiveMaximum = true;
|
|
893
|
-
}
|
|
894
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
895
|
-
}
|
|
896
|
-
break;
|
|
897
|
-
case "multipleOf":
|
|
898
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
899
|
-
break;
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
return res;
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
906
|
-
import { ZodOptional } from "zod";
|
|
907
|
-
function parseObjectDef(def, refs) {
|
|
908
|
-
const forceOptionalIntoNullable = refs.target === "openAi";
|
|
909
|
-
const result = {
|
|
910
|
-
type: "object",
|
|
911
|
-
properties: {}
|
|
912
|
-
};
|
|
913
|
-
const required = [];
|
|
914
|
-
const shape = def.shape();
|
|
915
|
-
for (const propName in shape) {
|
|
916
|
-
let propDef = shape[propName];
|
|
917
|
-
if (propDef === void 0 || propDef._def === void 0) {
|
|
918
|
-
continue;
|
|
919
|
-
}
|
|
920
|
-
let propOptional = safeIsOptional(propDef);
|
|
921
|
-
if (propOptional && forceOptionalIntoNullable) {
|
|
922
|
-
if (propDef instanceof ZodOptional) {
|
|
923
|
-
propDef = propDef._def.innerType;
|
|
924
|
-
}
|
|
925
|
-
if (!propDef.isNullable()) {
|
|
926
|
-
propDef = propDef.nullable();
|
|
927
|
-
}
|
|
928
|
-
propOptional = false;
|
|
929
|
-
}
|
|
930
|
-
const parsedDef = parseDef(propDef._def, {
|
|
931
|
-
...refs,
|
|
932
|
-
currentPath: [...refs.currentPath, "properties", propName],
|
|
933
|
-
propertyPath: [...refs.currentPath, "properties", propName]
|
|
934
|
-
});
|
|
935
|
-
if (parsedDef === void 0) {
|
|
936
|
-
continue;
|
|
937
|
-
}
|
|
938
|
-
result.properties[propName] = parsedDef;
|
|
939
|
-
if (!propOptional) {
|
|
940
|
-
required.push(propName);
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
if (required.length) {
|
|
944
|
-
result.required = required;
|
|
945
|
-
}
|
|
946
|
-
const additionalProperties = decideAdditionalProperties(def, refs);
|
|
947
|
-
if (additionalProperties !== void 0) {
|
|
948
|
-
result.additionalProperties = additionalProperties;
|
|
949
|
-
}
|
|
950
|
-
return result;
|
|
951
|
-
}
|
|
952
|
-
function decideAdditionalProperties(def, refs) {
|
|
953
|
-
if (def.catchall._def.typeName !== "ZodNever") {
|
|
954
|
-
return parseDef(def.catchall._def, {
|
|
955
|
-
...refs,
|
|
956
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
957
|
-
});
|
|
958
|
-
}
|
|
959
|
-
switch (def.unknownKeys) {
|
|
960
|
-
case "passthrough":
|
|
961
|
-
return refs.allowedAdditionalProperties;
|
|
962
|
-
case "strict":
|
|
963
|
-
return refs.rejectedAdditionalProperties;
|
|
964
|
-
case "strip":
|
|
965
|
-
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
function safeIsOptional(schema) {
|
|
969
|
-
try {
|
|
970
|
-
return schema.isOptional();
|
|
971
|
-
} catch {
|
|
972
|
-
return true;
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
977
|
-
var parseOptionalDef = (def, refs) => {
|
|
978
|
-
if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
|
|
979
|
-
return parseDef(def.innerType._def, refs);
|
|
980
|
-
}
|
|
981
|
-
const innerSchema = parseDef(def.innerType._def, {
|
|
982
|
-
...refs,
|
|
983
|
-
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
984
|
-
});
|
|
985
|
-
return innerSchema ? {
|
|
986
|
-
anyOf: [
|
|
987
|
-
{
|
|
988
|
-
not: {}
|
|
989
|
-
},
|
|
990
|
-
innerSchema
|
|
991
|
-
]
|
|
992
|
-
} : {};
|
|
993
|
-
};
|
|
994
|
-
|
|
995
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
996
|
-
var parsePipelineDef = (def, refs) => {
|
|
997
|
-
if (refs.pipeStrategy === "input") {
|
|
998
|
-
return parseDef(def.in._def, refs);
|
|
999
|
-
} else if (refs.pipeStrategy === "output") {
|
|
1000
|
-
return parseDef(def.out._def, refs);
|
|
1001
|
-
}
|
|
1002
|
-
const a = parseDef(def.in._def, {
|
|
1003
|
-
...refs,
|
|
1004
|
-
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1005
|
-
});
|
|
1006
|
-
const b = parseDef(def.out._def, {
|
|
1007
|
-
...refs,
|
|
1008
|
-
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
1009
|
-
});
|
|
1010
|
-
return {
|
|
1011
|
-
allOf: [a, b].filter((x) => x !== void 0)
|
|
1012
|
-
};
|
|
1013
|
-
};
|
|
1014
|
-
|
|
1015
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
|
|
1016
|
-
function parsePromiseDef(def, refs) {
|
|
1017
|
-
return parseDef(def.type._def, refs);
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/set.js
|
|
1021
|
-
function parseSetDef(def, refs) {
|
|
1022
|
-
const items = parseDef(def.valueType._def, {
|
|
1023
|
-
...refs,
|
|
1024
|
-
currentPath: [...refs.currentPath, "items"]
|
|
1025
|
-
});
|
|
1026
|
-
const schema = {
|
|
1027
|
-
type: "array",
|
|
1028
|
-
uniqueItems: true,
|
|
1029
|
-
items
|
|
1030
|
-
};
|
|
1031
|
-
if (def.minSize) {
|
|
1032
|
-
setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
1033
|
-
}
|
|
1034
|
-
if (def.maxSize) {
|
|
1035
|
-
setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
1036
|
-
}
|
|
1037
|
-
return schema;
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
1041
|
-
function parseTupleDef(def, refs) {
|
|
1042
|
-
if (def.rest) {
|
|
1043
|
-
return {
|
|
1044
|
-
type: "array",
|
|
1045
|
-
minItems: def.items.length,
|
|
1046
|
-
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1047
|
-
...refs,
|
|
1048
|
-
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1049
|
-
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
|
|
1050
|
-
additionalItems: parseDef(def.rest._def, {
|
|
1051
|
-
...refs,
|
|
1052
|
-
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1053
|
-
})
|
|
1054
|
-
};
|
|
1055
|
-
} else {
|
|
1056
|
-
return {
|
|
1057
|
-
type: "array",
|
|
1058
|
-
minItems: def.items.length,
|
|
1059
|
-
maxItems: def.items.length,
|
|
1060
|
-
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1061
|
-
...refs,
|
|
1062
|
-
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1063
|
-
})).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
|
|
1064
|
-
};
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
1069
|
-
function parseUndefinedDef() {
|
|
1070
|
-
return {
|
|
1071
|
-
not: {}
|
|
1072
|
-
};
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
|
|
1076
|
-
function parseUnknownDef() {
|
|
1077
|
-
return {};
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
|
|
1081
|
-
var parseReadonlyDef = (def, refs) => {
|
|
1082
|
-
return parseDef(def.innerType._def, refs);
|
|
1083
|
-
};
|
|
1084
|
-
|
|
1085
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
1086
|
-
var selectParser = (def, typeName, refs) => {
|
|
1087
|
-
switch (typeName) {
|
|
1088
|
-
case ZodFirstPartyTypeKind3.ZodString:
|
|
1089
|
-
return parseStringDef(def, refs);
|
|
1090
|
-
case ZodFirstPartyTypeKind3.ZodNumber:
|
|
1091
|
-
return parseNumberDef(def, refs);
|
|
1092
|
-
case ZodFirstPartyTypeKind3.ZodObject:
|
|
1093
|
-
return parseObjectDef(def, refs);
|
|
1094
|
-
case ZodFirstPartyTypeKind3.ZodBigInt:
|
|
1095
|
-
return parseBigintDef(def, refs);
|
|
1096
|
-
case ZodFirstPartyTypeKind3.ZodBoolean:
|
|
1097
|
-
return parseBooleanDef();
|
|
1098
|
-
case ZodFirstPartyTypeKind3.ZodDate:
|
|
1099
|
-
return parseDateDef(def, refs);
|
|
1100
|
-
case ZodFirstPartyTypeKind3.ZodUndefined:
|
|
1101
|
-
return parseUndefinedDef();
|
|
1102
|
-
case ZodFirstPartyTypeKind3.ZodNull:
|
|
1103
|
-
return parseNullDef(refs);
|
|
1104
|
-
case ZodFirstPartyTypeKind3.ZodArray:
|
|
1105
|
-
return parseArrayDef(def, refs);
|
|
1106
|
-
case ZodFirstPartyTypeKind3.ZodUnion:
|
|
1107
|
-
case ZodFirstPartyTypeKind3.ZodDiscriminatedUnion:
|
|
1108
|
-
return parseUnionDef(def, refs);
|
|
1109
|
-
case ZodFirstPartyTypeKind3.ZodIntersection:
|
|
1110
|
-
return parseIntersectionDef(def, refs);
|
|
1111
|
-
case ZodFirstPartyTypeKind3.ZodTuple:
|
|
1112
|
-
return parseTupleDef(def, refs);
|
|
1113
|
-
case ZodFirstPartyTypeKind3.ZodRecord:
|
|
1114
|
-
return parseRecordDef(def, refs);
|
|
1115
|
-
case ZodFirstPartyTypeKind3.ZodLiteral:
|
|
1116
|
-
return parseLiteralDef(def, refs);
|
|
1117
|
-
case ZodFirstPartyTypeKind3.ZodEnum:
|
|
1118
|
-
return parseEnumDef(def);
|
|
1119
|
-
case ZodFirstPartyTypeKind3.ZodNativeEnum:
|
|
1120
|
-
return parseNativeEnumDef(def);
|
|
1121
|
-
case ZodFirstPartyTypeKind3.ZodNullable:
|
|
1122
|
-
return parseNullableDef(def, refs);
|
|
1123
|
-
case ZodFirstPartyTypeKind3.ZodOptional:
|
|
1124
|
-
return parseOptionalDef(def, refs);
|
|
1125
|
-
case ZodFirstPartyTypeKind3.ZodMap:
|
|
1126
|
-
return parseMapDef(def, refs);
|
|
1127
|
-
case ZodFirstPartyTypeKind3.ZodSet:
|
|
1128
|
-
return parseSetDef(def, refs);
|
|
1129
|
-
case ZodFirstPartyTypeKind3.ZodLazy:
|
|
1130
|
-
return () => def.getter()._def;
|
|
1131
|
-
case ZodFirstPartyTypeKind3.ZodPromise:
|
|
1132
|
-
return parsePromiseDef(def, refs);
|
|
1133
|
-
case ZodFirstPartyTypeKind3.ZodNaN:
|
|
1134
|
-
case ZodFirstPartyTypeKind3.ZodNever:
|
|
1135
|
-
return parseNeverDef();
|
|
1136
|
-
case ZodFirstPartyTypeKind3.ZodEffects:
|
|
1137
|
-
return parseEffectsDef(def, refs);
|
|
1138
|
-
case ZodFirstPartyTypeKind3.ZodAny:
|
|
1139
|
-
return parseAnyDef();
|
|
1140
|
-
case ZodFirstPartyTypeKind3.ZodUnknown:
|
|
1141
|
-
return parseUnknownDef();
|
|
1142
|
-
case ZodFirstPartyTypeKind3.ZodDefault:
|
|
1143
|
-
return parseDefaultDef(def, refs);
|
|
1144
|
-
case ZodFirstPartyTypeKind3.ZodBranded:
|
|
1145
|
-
return parseBrandedDef(def, refs);
|
|
1146
|
-
case ZodFirstPartyTypeKind3.ZodReadonly:
|
|
1147
|
-
return parseReadonlyDef(def, refs);
|
|
1148
|
-
case ZodFirstPartyTypeKind3.ZodCatch:
|
|
1149
|
-
return parseCatchDef(def, refs);
|
|
1150
|
-
case ZodFirstPartyTypeKind3.ZodPipeline:
|
|
1151
|
-
return parsePipelineDef(def, refs);
|
|
1152
|
-
case ZodFirstPartyTypeKind3.ZodFunction:
|
|
1153
|
-
case ZodFirstPartyTypeKind3.ZodVoid:
|
|
1154
|
-
case ZodFirstPartyTypeKind3.ZodSymbol:
|
|
1155
|
-
return void 0;
|
|
1156
|
-
default:
|
|
1157
|
-
return /* @__PURE__ */ ((_) => void 0)(typeName);
|
|
1158
|
-
}
|
|
1159
|
-
};
|
|
1160
|
-
|
|
1161
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/parseDef.js
|
|
1162
|
-
function parseDef(def, refs, forceResolution = false) {
|
|
1163
|
-
const seenItem = refs.seen.get(def);
|
|
1164
|
-
if (refs.override) {
|
|
1165
|
-
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
1166
|
-
if (overrideResult !== ignoreOverride) {
|
|
1167
|
-
return overrideResult;
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
if (seenItem && !forceResolution) {
|
|
1171
|
-
const seenSchema = get$ref(seenItem, refs);
|
|
1172
|
-
if (seenSchema !== void 0) {
|
|
1173
|
-
return seenSchema;
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
|
|
1177
|
-
refs.seen.set(def, newItem);
|
|
1178
|
-
const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
|
|
1179
|
-
const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
1180
|
-
if (jsonSchema) {
|
|
1181
|
-
addMeta(def, refs, jsonSchema);
|
|
1182
|
-
}
|
|
1183
|
-
if (refs.postProcess) {
|
|
1184
|
-
const postProcessResult = refs.postProcess(jsonSchema, def, refs);
|
|
1185
|
-
newItem.jsonSchema = jsonSchema;
|
|
1186
|
-
return postProcessResult;
|
|
1187
|
-
}
|
|
1188
|
-
newItem.jsonSchema = jsonSchema;
|
|
1189
|
-
return jsonSchema;
|
|
1190
|
-
}
|
|
1191
|
-
var get$ref = (item, refs) => {
|
|
1192
|
-
switch (refs.$refStrategy) {
|
|
1193
|
-
case "root":
|
|
1194
|
-
return { $ref: item.path.join("/") };
|
|
1195
|
-
case "relative":
|
|
1196
|
-
return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
1197
|
-
case "none":
|
|
1198
|
-
case "seen": {
|
|
1199
|
-
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
1200
|
-
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
1201
|
-
return {};
|
|
1202
|
-
}
|
|
1203
|
-
return refs.$refStrategy === "seen" ? {} : void 0;
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
};
|
|
1207
|
-
var getRelativePath = (pathA, pathB) => {
|
|
1208
|
-
let i = 0;
|
|
1209
|
-
for (; i < pathA.length && i < pathB.length; i++) {
|
|
1210
|
-
if (pathA[i] !== pathB[i])
|
|
1211
|
-
break;
|
|
1212
|
-
}
|
|
1213
|
-
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
1214
|
-
};
|
|
1215
|
-
var addMeta = (def, refs, jsonSchema) => {
|
|
1216
|
-
if (def.description) {
|
|
1217
|
-
jsonSchema.description = def.description;
|
|
1218
|
-
if (refs.markdownDescription) {
|
|
1219
|
-
jsonSchema.markdownDescription = def.description;
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
return jsonSchema;
|
|
1223
|
-
};
|
|
1224
|
-
|
|
1225
|
-
// ../../node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
|
|
1226
|
-
var zodToJsonSchema = (schema, options) => {
|
|
1227
|
-
const refs = getRefs(options);
|
|
1228
|
-
const definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name2, schema2]) => ({
|
|
1229
|
-
...acc,
|
|
1230
|
-
[name2]: parseDef(schema2._def, {
|
|
1231
|
-
...refs,
|
|
1232
|
-
currentPath: [...refs.basePath, refs.definitionPath, name2]
|
|
1233
|
-
}, true) ?? {}
|
|
1234
|
-
}), {}) : void 0;
|
|
1235
|
-
const name = typeof options === "string" ? options : options?.nameStrategy === "title" ? void 0 : options?.name;
|
|
1236
|
-
const main = parseDef(schema._def, name === void 0 ? refs : {
|
|
1237
|
-
...refs,
|
|
1238
|
-
currentPath: [...refs.basePath, refs.definitionPath, name]
|
|
1239
|
-
}, false) ?? {};
|
|
1240
|
-
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
1241
|
-
if (title !== void 0) {
|
|
1242
|
-
main.title = title;
|
|
1243
|
-
}
|
|
1244
|
-
const combined = name === void 0 ? definitions ? {
|
|
1245
|
-
...main,
|
|
1246
|
-
[refs.definitionPath]: definitions
|
|
1247
|
-
} : main : {
|
|
1248
|
-
$ref: [
|
|
1249
|
-
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
1250
|
-
refs.definitionPath,
|
|
1251
|
-
name
|
|
1252
|
-
].join("/"),
|
|
1253
|
-
[refs.definitionPath]: {
|
|
1254
|
-
...definitions,
|
|
1255
|
-
[name]: main
|
|
1256
|
-
}
|
|
1257
|
-
};
|
|
1258
|
-
if (refs.target === "jsonSchema7") {
|
|
1259
|
-
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
1260
|
-
} else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
|
|
1261
|
-
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
1262
|
-
}
|
|
1263
|
-
if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
|
|
1264
|
-
console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
|
|
1265
|
-
}
|
|
1266
|
-
return combined;
|
|
1267
|
-
};
|
|
1268
|
-
|
|
1269
|
-
// src/MCPLocal.ts
|
|
1270
11
|
import {
|
|
1271
12
|
Field,
|
|
1272
13
|
Fields,
|
|
@@ -1277,8 +18,177 @@ import {
|
|
|
1277
18
|
SubscriptionRequestType,
|
|
1278
19
|
TimeInForce
|
|
1279
20
|
} from "fixparser";
|
|
21
|
+
var parseInputSchema = {
|
|
22
|
+
type: "object",
|
|
23
|
+
properties: {
|
|
24
|
+
fixString: {
|
|
25
|
+
type: "string",
|
|
26
|
+
description: "FIX message string to parse"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
required: ["fixString"]
|
|
30
|
+
};
|
|
31
|
+
var parseToJSONInputSchema = {
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
fixString: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "FIX message string to parse"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
required: ["fixString"]
|
|
40
|
+
};
|
|
41
|
+
var newOrderSingleInputSchema = {
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {
|
|
44
|
+
clOrdID: {
|
|
45
|
+
type: "string",
|
|
46
|
+
description: "Client Order ID"
|
|
47
|
+
},
|
|
48
|
+
handlInst: {
|
|
49
|
+
type: "string",
|
|
50
|
+
enum: ["1", "2", "3"],
|
|
51
|
+
default: HandlInst.AutomatedExecutionNoIntervention,
|
|
52
|
+
description: 'Handling instruction (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Manual, "2" for Automated, "3" for AutomatedNoIntervention)'
|
|
53
|
+
},
|
|
54
|
+
quantity: {
|
|
55
|
+
type: "number",
|
|
56
|
+
description: "Order quantity"
|
|
57
|
+
},
|
|
58
|
+
price: {
|
|
59
|
+
type: "number",
|
|
60
|
+
description: "Order price"
|
|
61
|
+
},
|
|
62
|
+
ordType: {
|
|
63
|
+
type: "string",
|
|
64
|
+
enum: [
|
|
65
|
+
"1",
|
|
66
|
+
"2",
|
|
67
|
+
"3",
|
|
68
|
+
"4",
|
|
69
|
+
"5",
|
|
70
|
+
"6",
|
|
71
|
+
"7",
|
|
72
|
+
"8",
|
|
73
|
+
"9",
|
|
74
|
+
"A",
|
|
75
|
+
"B",
|
|
76
|
+
"C",
|
|
77
|
+
"D",
|
|
78
|
+
"E",
|
|
79
|
+
"F",
|
|
80
|
+
"G",
|
|
81
|
+
"H",
|
|
82
|
+
"I",
|
|
83
|
+
"J",
|
|
84
|
+
"K",
|
|
85
|
+
"L",
|
|
86
|
+
"M",
|
|
87
|
+
"P",
|
|
88
|
+
"Q",
|
|
89
|
+
"R",
|
|
90
|
+
"S"
|
|
91
|
+
],
|
|
92
|
+
default: OrdType.Market,
|
|
93
|
+
description: 'Order type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Market, "2" for Limit, "3" for Stop)'
|
|
94
|
+
},
|
|
95
|
+
side: {
|
|
96
|
+
type: "string",
|
|
97
|
+
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
98
|
+
description: 'Order side (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Buy, "2" for Sell, "3" for BuyMinus, "4" for SellPlus, "5" for SellShort, "6" for SellShortExempt, "7" for Undisclosed, "8" for Cross, "9" for CrossShort, "A" for CrossShortExempt, "B" for AsDefined, "C" for Opposite, "D" for Subscribe, "E" for Redeem, "F" for Lend, "G" for Borrow, "H" for SellUndisclosed)'
|
|
99
|
+
},
|
|
100
|
+
symbol: {
|
|
101
|
+
type: "string",
|
|
102
|
+
description: "Trading symbol"
|
|
103
|
+
},
|
|
104
|
+
timeInForce: {
|
|
105
|
+
type: "string",
|
|
106
|
+
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
107
|
+
default: TimeInForce.Day,
|
|
108
|
+
description: 'Time in force (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Day, "1" for Good Till Cancel, "2" for At Opening, "3" for Immediate or Cancel, "4" for Fill or Kill, "5" for Good Till Crossing, "6" for Good Till Date)'
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
required: ["clOrdID", "quantity", "price", "side", "symbol"]
|
|
112
|
+
};
|
|
113
|
+
var marketDataRequestInputSchema = {
|
|
114
|
+
type: "object",
|
|
115
|
+
properties: {
|
|
116
|
+
mdUpdateType: {
|
|
117
|
+
type: "string",
|
|
118
|
+
enum: ["0", "1"],
|
|
119
|
+
default: "0",
|
|
120
|
+
description: 'Market data update type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for FullRefresh, "1" for IncrementalRefresh)'
|
|
121
|
+
},
|
|
122
|
+
symbol: {
|
|
123
|
+
type: "string",
|
|
124
|
+
description: "Trading symbol"
|
|
125
|
+
},
|
|
126
|
+
mdReqID: {
|
|
127
|
+
type: "string",
|
|
128
|
+
description: "Market data request ID"
|
|
129
|
+
},
|
|
130
|
+
subscriptionRequestType: {
|
|
131
|
+
type: "string",
|
|
132
|
+
enum: ["0", "1", "2"],
|
|
133
|
+
default: SubscriptionRequestType.SnapshotAndUpdates,
|
|
134
|
+
description: 'Subscription request type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Snapshot + Updates, "1" for Snapshot, "2" for Unsubscribe)'
|
|
135
|
+
},
|
|
136
|
+
mdEntryType: {
|
|
137
|
+
type: "string",
|
|
138
|
+
enum: [
|
|
139
|
+
"0",
|
|
140
|
+
"1",
|
|
141
|
+
"2",
|
|
142
|
+
"3",
|
|
143
|
+
"4",
|
|
144
|
+
"5",
|
|
145
|
+
"6",
|
|
146
|
+
"7",
|
|
147
|
+
"8",
|
|
148
|
+
"9",
|
|
149
|
+
"A",
|
|
150
|
+
"B",
|
|
151
|
+
"C",
|
|
152
|
+
"D",
|
|
153
|
+
"E",
|
|
154
|
+
"F",
|
|
155
|
+
"G",
|
|
156
|
+
"H",
|
|
157
|
+
"J",
|
|
158
|
+
"K",
|
|
159
|
+
"L",
|
|
160
|
+
"M",
|
|
161
|
+
"N",
|
|
162
|
+
"O",
|
|
163
|
+
"P",
|
|
164
|
+
"Q",
|
|
165
|
+
"S",
|
|
166
|
+
"R",
|
|
167
|
+
"T",
|
|
168
|
+
"U",
|
|
169
|
+
"V",
|
|
170
|
+
"W",
|
|
171
|
+
"X",
|
|
172
|
+
"Y",
|
|
173
|
+
"Z",
|
|
174
|
+
"a",
|
|
175
|
+
"b",
|
|
176
|
+
"c",
|
|
177
|
+
"d",
|
|
178
|
+
"e",
|
|
179
|
+
"g",
|
|
180
|
+
"h",
|
|
181
|
+
"i",
|
|
182
|
+
"t"
|
|
183
|
+
],
|
|
184
|
+
default: MDEntryType.Bid,
|
|
185
|
+
description: 'Market data entry type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Bid, "1" for Offer, "2" for Trade, "3" for Index Value, "4" for Opening Price)'
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
required: ["symbol", "mdReqID"]
|
|
189
|
+
};
|
|
1280
190
|
var MCPLocal = class {
|
|
1281
|
-
logger;
|
|
191
|
+
// private logger: Logger | undefined;
|
|
1282
192
|
parser;
|
|
1283
193
|
server = new Server(
|
|
1284
194
|
{
|
|
@@ -1287,15 +197,9 @@ var MCPLocal = class {
|
|
|
1287
197
|
},
|
|
1288
198
|
{
|
|
1289
199
|
capabilities: {
|
|
1290
|
-
tools: {
|
|
1291
|
-
|
|
1292
|
-
}
|
|
1293
|
-
prompts: {
|
|
1294
|
-
listChanged: true
|
|
1295
|
-
},
|
|
1296
|
-
resources: {
|
|
1297
|
-
listChanged: true
|
|
1298
|
-
}
|
|
200
|
+
tools: {},
|
|
201
|
+
prompts: {},
|
|
202
|
+
resources: {}
|
|
1299
203
|
}
|
|
1300
204
|
}
|
|
1301
205
|
);
|
|
@@ -1303,32 +207,37 @@ var MCPLocal = class {
|
|
|
1303
207
|
onReady = void 0;
|
|
1304
208
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
1305
209
|
constructor({ logger, onReady }) {
|
|
1306
|
-
if (logger) this.logger = logger;
|
|
1307
210
|
if (onReady) this.onReady = onReady;
|
|
1308
211
|
}
|
|
1309
212
|
async register(parser) {
|
|
1310
213
|
this.parser = parser;
|
|
1311
214
|
this.parser.addOnMessageCallback((message) => {
|
|
1312
|
-
this.logger?.log({
|
|
1313
|
-
level: "info",
|
|
1314
|
-
message: `FIXParser (MCP): (${parser.protocol?.toUpperCase()}): << received ${message.description}`
|
|
1315
|
-
});
|
|
1316
215
|
const msgType = message.messageType;
|
|
1317
|
-
if (msgType === Messages.MarketDataSnapshotFullRefresh || msgType === Messages.ExecutionReport) {
|
|
1318
|
-
const idField = msgType === Messages.MarketDataSnapshotFullRefresh ? message.getField(Fields.MDReqID) : message.getField(Fields.ClOrdID);
|
|
216
|
+
if (msgType === Messages.MarketDataSnapshotFullRefresh || msgType === Messages.ExecutionReport || msgType === Messages.Reject) {
|
|
217
|
+
const idField = msgType === Messages.MarketDataSnapshotFullRefresh ? message.getField(Fields.MDReqID) : msgType === Messages.Reject ? message.getField(Fields.RefSeqNum) : message.getField(Fields.ClOrdID);
|
|
1319
218
|
if (idField) {
|
|
1320
219
|
const id = idField.value;
|
|
1321
220
|
if (typeof id === "string" || typeof id === "number") {
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
221
|
+
if (msgType === Messages.Reject) {
|
|
222
|
+
const refMsgType = message.getField(Fields.RefMsgType);
|
|
223
|
+
if (refMsgType && refMsgType.value === Messages.NewOrderSingle) {
|
|
224
|
+
const callback = this.pendingRequests.get(String(id));
|
|
225
|
+
if (callback) {
|
|
226
|
+
callback(message);
|
|
227
|
+
this.pendingRequests.delete(String(id));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
const callback = this.pendingRequests.get(String(id));
|
|
232
|
+
if (callback) {
|
|
233
|
+
callback(message);
|
|
234
|
+
this.pendingRequests.delete(String(id));
|
|
235
|
+
}
|
|
1326
236
|
}
|
|
1327
237
|
}
|
|
1328
238
|
}
|
|
1329
239
|
}
|
|
1330
240
|
});
|
|
1331
|
-
this.logger = parser.logger;
|
|
1332
241
|
this.addWorkflows();
|
|
1333
242
|
await this.server.connect(this.transport);
|
|
1334
243
|
if (this.onReady) {
|
|
@@ -1337,19 +246,27 @@ var MCPLocal = class {
|
|
|
1337
246
|
}
|
|
1338
247
|
addWorkflows() {
|
|
1339
248
|
if (!this.parser) {
|
|
1340
|
-
this.logger?.log({
|
|
1341
|
-
level: "error",
|
|
1342
|
-
message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of workflows..."
|
|
1343
|
-
});
|
|
1344
249
|
return;
|
|
1345
250
|
}
|
|
1346
251
|
if (!this.server) {
|
|
1347
|
-
this.logger?.log({
|
|
1348
|
-
level: "error",
|
|
1349
|
-
message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of workflows..."
|
|
1350
|
-
});
|
|
1351
252
|
return;
|
|
1352
253
|
}
|
|
254
|
+
const validateArgs = (args, schema) => {
|
|
255
|
+
const result = {};
|
|
256
|
+
for (const [key, propSchema] of Object.entries(schema.properties || {})) {
|
|
257
|
+
const prop = propSchema;
|
|
258
|
+
const value = args?.[key];
|
|
259
|
+
if (prop.required && (value === void 0 || value === null)) {
|
|
260
|
+
throw new Error(`Required property '${key}' is missing`);
|
|
261
|
+
}
|
|
262
|
+
if (value !== void 0) {
|
|
263
|
+
result[key] = value;
|
|
264
|
+
} else if (prop.default !== void 0) {
|
|
265
|
+
result[key] = prop.default;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return result;
|
|
269
|
+
};
|
|
1353
270
|
this.server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
1354
271
|
return {
|
|
1355
272
|
resources: []
|
|
@@ -1361,143 +278,22 @@ var MCPLocal = class {
|
|
|
1361
278
|
{
|
|
1362
279
|
name: "parse",
|
|
1363
280
|
description: "Parses a FIX message and describes it in plain language",
|
|
1364
|
-
inputSchema:
|
|
1365
|
-
z.object({
|
|
1366
|
-
fixString: z.string().describe("FIX message string to parse")
|
|
1367
|
-
}),
|
|
1368
|
-
{ name: "ParseInput" }
|
|
1369
|
-
)
|
|
281
|
+
inputSchema: parseInputSchema
|
|
1370
282
|
},
|
|
1371
283
|
{
|
|
1372
284
|
name: "parseToJSON",
|
|
1373
285
|
description: "Parses a FIX message into JSON",
|
|
1374
|
-
inputSchema:
|
|
1375
|
-
z.object({
|
|
1376
|
-
fixString: z.string().describe("FIX message string to parse")
|
|
1377
|
-
}),
|
|
1378
|
-
{ name: "ParseToJSONInput" }
|
|
1379
|
-
)
|
|
286
|
+
inputSchema: parseToJSONInputSchema
|
|
1380
287
|
},
|
|
1381
288
|
{
|
|
1382
289
|
name: "newOrderSingle",
|
|
1383
290
|
description: "Creates and sends a New Order Single",
|
|
1384
|
-
inputSchema:
|
|
1385
|
-
z.object({
|
|
1386
|
-
clOrdID: z.string().describe("Client Order ID"),
|
|
1387
|
-
handlInst: z.enum(["1", "2", "3"]).default(HandlInst.AutomatedExecutionNoIntervention).optional().describe("Handling instruction"),
|
|
1388
|
-
quantity: z.number().describe("Order quantity"),
|
|
1389
|
-
price: z.number().describe("Order price"),
|
|
1390
|
-
ordType: z.enum([
|
|
1391
|
-
"1",
|
|
1392
|
-
"2",
|
|
1393
|
-
"3",
|
|
1394
|
-
"4",
|
|
1395
|
-
"5",
|
|
1396
|
-
"6",
|
|
1397
|
-
"7",
|
|
1398
|
-
"8",
|
|
1399
|
-
"9",
|
|
1400
|
-
"A",
|
|
1401
|
-
"B",
|
|
1402
|
-
"C",
|
|
1403
|
-
"D",
|
|
1404
|
-
"E",
|
|
1405
|
-
"F",
|
|
1406
|
-
"G",
|
|
1407
|
-
"H",
|
|
1408
|
-
"I",
|
|
1409
|
-
"J",
|
|
1410
|
-
"K",
|
|
1411
|
-
"L",
|
|
1412
|
-
"M",
|
|
1413
|
-
"P",
|
|
1414
|
-
"Q",
|
|
1415
|
-
"R",
|
|
1416
|
-
"S"
|
|
1417
|
-
]).default("1").optional().describe("Order type"),
|
|
1418
|
-
side: z.enum([
|
|
1419
|
-
"1",
|
|
1420
|
-
"2",
|
|
1421
|
-
"3",
|
|
1422
|
-
"4",
|
|
1423
|
-
"5",
|
|
1424
|
-
"6",
|
|
1425
|
-
"7",
|
|
1426
|
-
"8",
|
|
1427
|
-
"9",
|
|
1428
|
-
"A",
|
|
1429
|
-
"B",
|
|
1430
|
-
"C",
|
|
1431
|
-
"D",
|
|
1432
|
-
"E",
|
|
1433
|
-
"F",
|
|
1434
|
-
"G",
|
|
1435
|
-
"H"
|
|
1436
|
-
]).describe("Order side (1=Buy, 2=Sell)"),
|
|
1437
|
-
symbol: z.string().describe("Trading symbol"),
|
|
1438
|
-
timeInForce: z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]).default(TimeInForce.Day).optional().describe("Time in force")
|
|
1439
|
-
}),
|
|
1440
|
-
{ name: "NewOrderSingleInput" }
|
|
1441
|
-
)
|
|
291
|
+
inputSchema: newOrderSingleInputSchema
|
|
1442
292
|
},
|
|
1443
293
|
{
|
|
1444
294
|
name: "marketDataRequest",
|
|
1445
295
|
description: "Sends a request for Market Data with the given symbol",
|
|
1446
|
-
inputSchema:
|
|
1447
|
-
z.object({
|
|
1448
|
-
mdUpdateType: z.enum(["0", "1"]).default("0").optional().describe("Market data update type"),
|
|
1449
|
-
symbol: z.string().describe("Trading symbol"),
|
|
1450
|
-
mdReqID: z.string().describe("Market data request ID"),
|
|
1451
|
-
subscriptionRequestType: z.enum(["0", "1", "2"]).default(SubscriptionRequestType.SnapshotAndUpdates).optional().describe("Subscription request type"),
|
|
1452
|
-
mdEntryType: z.enum([
|
|
1453
|
-
"0",
|
|
1454
|
-
"1",
|
|
1455
|
-
"2",
|
|
1456
|
-
"3",
|
|
1457
|
-
"4",
|
|
1458
|
-
"5",
|
|
1459
|
-
"6",
|
|
1460
|
-
"7",
|
|
1461
|
-
"8",
|
|
1462
|
-
"9",
|
|
1463
|
-
"A",
|
|
1464
|
-
"B",
|
|
1465
|
-
"C",
|
|
1466
|
-
"D",
|
|
1467
|
-
"E",
|
|
1468
|
-
"F",
|
|
1469
|
-
"G",
|
|
1470
|
-
"H",
|
|
1471
|
-
"J",
|
|
1472
|
-
"K",
|
|
1473
|
-
"L",
|
|
1474
|
-
"M",
|
|
1475
|
-
"N",
|
|
1476
|
-
"O",
|
|
1477
|
-
"P",
|
|
1478
|
-
"Q",
|
|
1479
|
-
"S",
|
|
1480
|
-
"R",
|
|
1481
|
-
"T",
|
|
1482
|
-
"U",
|
|
1483
|
-
"V",
|
|
1484
|
-
"W",
|
|
1485
|
-
"X",
|
|
1486
|
-
"Y",
|
|
1487
|
-
"Z",
|
|
1488
|
-
"a",
|
|
1489
|
-
"b",
|
|
1490
|
-
"c",
|
|
1491
|
-
"d",
|
|
1492
|
-
"e",
|
|
1493
|
-
"g",
|
|
1494
|
-
"h",
|
|
1495
|
-
"i",
|
|
1496
|
-
"t"
|
|
1497
|
-
]).default(MDEntryType.Bid).optional().describe("Market data entry type")
|
|
1498
|
-
}),
|
|
1499
|
-
{ name: "MarketDataRequestInput" }
|
|
1500
|
-
)
|
|
296
|
+
inputSchema: marketDataRequestInputSchema
|
|
1501
297
|
}
|
|
1502
298
|
]
|
|
1503
299
|
};
|
|
@@ -1506,10 +302,8 @@ var MCPLocal = class {
|
|
|
1506
302
|
const { name, arguments: args } = request.params;
|
|
1507
303
|
switch (name) {
|
|
1508
304
|
case "parse": {
|
|
1509
|
-
const { fixString } = z.object({
|
|
1510
|
-
fixString: z.string().describe("FIX message string to parse")
|
|
1511
|
-
}).parse(args || {});
|
|
1512
305
|
try {
|
|
306
|
+
const { fixString } = validateArgs(args, parseInputSchema);
|
|
1513
307
|
const parsedMessage = this.parser?.parse(fixString);
|
|
1514
308
|
if (!parsedMessage || parsedMessage.length === 0) {
|
|
1515
309
|
return {
|
|
@@ -1521,7 +315,8 @@ var MCPLocal = class {
|
|
|
1521
315
|
content: [
|
|
1522
316
|
{
|
|
1523
317
|
type: "text",
|
|
1524
|
-
text:
|
|
318
|
+
text: `${parsedMessage[0].description}
|
|
319
|
+
${parsedMessage[0].messageTypeDescription}`
|
|
1525
320
|
}
|
|
1526
321
|
]
|
|
1527
322
|
};
|
|
@@ -1531,17 +326,15 @@ var MCPLocal = class {
|
|
|
1531
326
|
content: [
|
|
1532
327
|
{
|
|
1533
328
|
type: "text",
|
|
1534
|
-
text:
|
|
329
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
1535
330
|
}
|
|
1536
331
|
]
|
|
1537
332
|
};
|
|
1538
333
|
}
|
|
1539
334
|
}
|
|
1540
335
|
case "parseToJSON": {
|
|
1541
|
-
const { fixString } = z.object({
|
|
1542
|
-
fixString: z.string().describe("FIX message string to parse")
|
|
1543
|
-
}).parse(args || {});
|
|
1544
336
|
try {
|
|
337
|
+
const { fixString } = validateArgs(args, parseToJSONInputSchema);
|
|
1545
338
|
const parsedMessage = this.parser?.parse(fixString);
|
|
1546
339
|
if (!parsedMessage || parsedMessage.length === 0) {
|
|
1547
340
|
return {
|
|
@@ -1553,7 +346,7 @@ var MCPLocal = class {
|
|
|
1553
346
|
content: [
|
|
1554
347
|
{
|
|
1555
348
|
type: "text",
|
|
1556
|
-
text:
|
|
349
|
+
text: `${parsedMessage[0].toFIXJSON()}`
|
|
1557
350
|
}
|
|
1558
351
|
]
|
|
1559
352
|
};
|
|
@@ -1563,217 +356,123 @@ var MCPLocal = class {
|
|
|
1563
356
|
content: [
|
|
1564
357
|
{
|
|
1565
358
|
type: "text",
|
|
1566
|
-
text:
|
|
359
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
1567
360
|
}
|
|
1568
361
|
]
|
|
1569
362
|
};
|
|
1570
363
|
}
|
|
1571
364
|
}
|
|
1572
365
|
case "newOrderSingle": {
|
|
1573
|
-
|
|
1574
|
-
clOrdID
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
price: z.number().describe("Order price"),
|
|
1578
|
-
ordType: z.enum([
|
|
1579
|
-
"1",
|
|
1580
|
-
"2",
|
|
1581
|
-
"3",
|
|
1582
|
-
"4",
|
|
1583
|
-
"5",
|
|
1584
|
-
"6",
|
|
1585
|
-
"7",
|
|
1586
|
-
"8",
|
|
1587
|
-
"9",
|
|
1588
|
-
"A",
|
|
1589
|
-
"B",
|
|
1590
|
-
"C",
|
|
1591
|
-
"D",
|
|
1592
|
-
"E",
|
|
1593
|
-
"F",
|
|
1594
|
-
"G",
|
|
1595
|
-
"H",
|
|
1596
|
-
"I",
|
|
1597
|
-
"J",
|
|
1598
|
-
"K",
|
|
1599
|
-
"L",
|
|
1600
|
-
"M",
|
|
1601
|
-
"P",
|
|
1602
|
-
"Q",
|
|
1603
|
-
"R",
|
|
1604
|
-
"S"
|
|
1605
|
-
]).default(OrdType.Market).optional().describe("Order type"),
|
|
1606
|
-
side: z.enum([
|
|
1607
|
-
"1",
|
|
1608
|
-
"2",
|
|
1609
|
-
"3",
|
|
1610
|
-
"4",
|
|
1611
|
-
"5",
|
|
1612
|
-
"6",
|
|
1613
|
-
"7",
|
|
1614
|
-
"8",
|
|
1615
|
-
"9",
|
|
1616
|
-
"A",
|
|
1617
|
-
"B",
|
|
1618
|
-
"C",
|
|
1619
|
-
"D",
|
|
1620
|
-
"E",
|
|
1621
|
-
"F",
|
|
1622
|
-
"G",
|
|
1623
|
-
"H"
|
|
1624
|
-
]).describe("Order side (1=Buy, 2=Sell)"),
|
|
1625
|
-
symbol: z.string().describe("Trading symbol"),
|
|
1626
|
-
timeInForce: z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]).default(TimeInForce.Day).optional().describe("Time in force")
|
|
1627
|
-
}).parse(args || {});
|
|
1628
|
-
const response = new Promise((resolve) => {
|
|
1629
|
-
this.pendingRequests.set(clOrdID, resolve);
|
|
1630
|
-
});
|
|
1631
|
-
const order = this.parser?.createMessage(
|
|
1632
|
-
new Field(Fields.MsgType, Messages.NewOrderSingle),
|
|
1633
|
-
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
1634
|
-
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
1635
|
-
new Field(Fields.TargetCompID, this.parser?.target),
|
|
1636
|
-
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
1637
|
-
new Field(Fields.ClOrdID, clOrdID),
|
|
1638
|
-
new Field(Fields.Side, side),
|
|
1639
|
-
new Field(Fields.Symbol, symbol),
|
|
1640
|
-
new Field(Fields.OrderQty, quantity),
|
|
1641
|
-
new Field(Fields.Price, price),
|
|
1642
|
-
new Field(Fields.OrdType, ordType),
|
|
1643
|
-
new Field(Fields.HandlInst, handlInst),
|
|
1644
|
-
new Field(Fields.TimeInForce, timeInForce),
|
|
1645
|
-
new Field(Fields.TransactTime, this.parser?.getTimestamp())
|
|
1646
|
-
);
|
|
1647
|
-
if (!this.parser?.connected) {
|
|
1648
|
-
this.logger?.log({
|
|
1649
|
-
level: "error",
|
|
1650
|
-
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
366
|
+
try {
|
|
367
|
+
const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = validateArgs(args, newOrderSingleInputSchema);
|
|
368
|
+
const response = new Promise((resolve) => {
|
|
369
|
+
this.pendingRequests.set(clOrdID, resolve);
|
|
1651
370
|
});
|
|
371
|
+
const order = this.parser?.createMessage(
|
|
372
|
+
new Field(Fields.MsgType, Messages.NewOrderSingle),
|
|
373
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
374
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
375
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
376
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
377
|
+
new Field(Fields.ClOrdID, clOrdID),
|
|
378
|
+
new Field(Fields.Side, side),
|
|
379
|
+
new Field(Fields.Symbol, symbol),
|
|
380
|
+
new Field(Fields.OrderQty, quantity),
|
|
381
|
+
new Field(Fields.Price, price),
|
|
382
|
+
new Field(Fields.OrdType, ordType),
|
|
383
|
+
new Field(Fields.HandlInst, handlInst),
|
|
384
|
+
new Field(Fields.TimeInForce, timeInForce),
|
|
385
|
+
new Field(Fields.TransactTime, this.parser?.getTimestamp())
|
|
386
|
+
);
|
|
387
|
+
if (!this.parser?.connected) {
|
|
388
|
+
return {
|
|
389
|
+
isError: true,
|
|
390
|
+
content: [
|
|
391
|
+
{
|
|
392
|
+
type: "text",
|
|
393
|
+
text: "Error: Not connected. Ignoring message."
|
|
394
|
+
}
|
|
395
|
+
]
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
this.parser?.send(order);
|
|
399
|
+
const fixData = await response;
|
|
400
|
+
return {
|
|
401
|
+
content: [
|
|
402
|
+
{
|
|
403
|
+
type: "text",
|
|
404
|
+
text: fixData.messageType === Messages.Reject ? `Reject message for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
405
|
+
}
|
|
406
|
+
]
|
|
407
|
+
};
|
|
408
|
+
} catch (error) {
|
|
1652
409
|
return {
|
|
1653
410
|
isError: true,
|
|
1654
411
|
content: [
|
|
1655
412
|
{
|
|
1656
413
|
type: "text",
|
|
1657
|
-
text:
|
|
414
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to create order"}`
|
|
1658
415
|
}
|
|
1659
416
|
]
|
|
1660
417
|
};
|
|
1661
418
|
}
|
|
1662
|
-
this.parser?.send(order);
|
|
1663
|
-
this.logger?.log({
|
|
1664
|
-
level: "info",
|
|
1665
|
-
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${order?.description}`
|
|
1666
|
-
});
|
|
1667
|
-
const fixData = await response;
|
|
1668
|
-
return {
|
|
1669
|
-
content: [
|
|
1670
|
-
{
|
|
1671
|
-
type: "text",
|
|
1672
|
-
text: `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
1673
|
-
}
|
|
1674
|
-
]
|
|
1675
|
-
};
|
|
1676
419
|
}
|
|
1677
420
|
case "marketDataRequest": {
|
|
1678
|
-
|
|
1679
|
-
mdUpdateType
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
"1",
|
|
1686
|
-
"2",
|
|
1687
|
-
"3",
|
|
1688
|
-
"4",
|
|
1689
|
-
"5",
|
|
1690
|
-
"6",
|
|
1691
|
-
"7",
|
|
1692
|
-
"8",
|
|
1693
|
-
"9",
|
|
1694
|
-
"A",
|
|
1695
|
-
"B",
|
|
1696
|
-
"C",
|
|
1697
|
-
"D",
|
|
1698
|
-
"E",
|
|
1699
|
-
"F",
|
|
1700
|
-
"G",
|
|
1701
|
-
"H",
|
|
1702
|
-
"J",
|
|
1703
|
-
"K",
|
|
1704
|
-
"L",
|
|
1705
|
-
"M",
|
|
1706
|
-
"N",
|
|
1707
|
-
"O",
|
|
1708
|
-
"P",
|
|
1709
|
-
"Q",
|
|
1710
|
-
"S",
|
|
1711
|
-
"R",
|
|
1712
|
-
"T",
|
|
1713
|
-
"U",
|
|
1714
|
-
"V",
|
|
1715
|
-
"W",
|
|
1716
|
-
"X",
|
|
1717
|
-
"Y",
|
|
1718
|
-
"Z",
|
|
1719
|
-
"a",
|
|
1720
|
-
"b",
|
|
1721
|
-
"c",
|
|
1722
|
-
"d",
|
|
1723
|
-
"e",
|
|
1724
|
-
"g",
|
|
1725
|
-
"h",
|
|
1726
|
-
"i",
|
|
1727
|
-
"t"
|
|
1728
|
-
]).default(MDEntryType.Bid).optional().describe("Market data entry type")
|
|
1729
|
-
}).parse(args || {});
|
|
1730
|
-
const response = new Promise((resolve) => {
|
|
1731
|
-
this.pendingRequests.set(mdReqID, resolve);
|
|
1732
|
-
});
|
|
1733
|
-
const marketDataRequest = this.parser?.createMessage(
|
|
1734
|
-
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
1735
|
-
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
1736
|
-
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
1737
|
-
new Field(Fields.TargetCompID, this.parser?.target),
|
|
1738
|
-
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
1739
|
-
new Field(Fields.MarketDepth, 0),
|
|
1740
|
-
new Field(Fields.MDUpdateType, mdUpdateType),
|
|
1741
|
-
new Field(Fields.NoRelatedSym, 1),
|
|
1742
|
-
new Field(Fields.Symbol, symbol),
|
|
1743
|
-
new Field(Fields.MDReqID, mdReqID),
|
|
1744
|
-
new Field(Fields.SubscriptionRequestType, subscriptionRequestType),
|
|
1745
|
-
new Field(Fields.NoMDEntryTypes, 1),
|
|
1746
|
-
new Field(Fields.MDEntryType, mdEntryType)
|
|
1747
|
-
);
|
|
1748
|
-
if (!this.parser?.connected) {
|
|
1749
|
-
this.logger?.log({
|
|
1750
|
-
level: "error",
|
|
1751
|
-
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
421
|
+
try {
|
|
422
|
+
const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = validateArgs(
|
|
423
|
+
args,
|
|
424
|
+
marketDataRequestInputSchema
|
|
425
|
+
);
|
|
426
|
+
const response = new Promise((resolve) => {
|
|
427
|
+
this.pendingRequests.set(mdReqID, resolve);
|
|
1752
428
|
});
|
|
429
|
+
const marketDataRequest = this.parser?.createMessage(
|
|
430
|
+
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
431
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
432
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
433
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
434
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
435
|
+
new Field(Fields.MarketDepth, 0),
|
|
436
|
+
new Field(Fields.MDUpdateType, mdUpdateType),
|
|
437
|
+
new Field(Fields.NoRelatedSym, 1),
|
|
438
|
+
new Field(Fields.Symbol, symbol),
|
|
439
|
+
new Field(Fields.MDReqID, mdReqID),
|
|
440
|
+
new Field(Fields.SubscriptionRequestType, subscriptionRequestType),
|
|
441
|
+
new Field(Fields.NoMDEntryTypes, 1),
|
|
442
|
+
new Field(Fields.MDEntryType, mdEntryType)
|
|
443
|
+
);
|
|
444
|
+
if (!this.parser?.connected) {
|
|
445
|
+
return {
|
|
446
|
+
isError: true,
|
|
447
|
+
content: [
|
|
448
|
+
{
|
|
449
|
+
type: "text",
|
|
450
|
+
text: "Error: Not connected. Ignoring message."
|
|
451
|
+
}
|
|
452
|
+
]
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
this.parser?.send(marketDataRequest);
|
|
456
|
+
const fixData = await response;
|
|
457
|
+
return {
|
|
458
|
+
content: [
|
|
459
|
+
{
|
|
460
|
+
type: "text",
|
|
461
|
+
text: `Market data for ${symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
462
|
+
}
|
|
463
|
+
]
|
|
464
|
+
};
|
|
465
|
+
} catch (error) {
|
|
1753
466
|
return {
|
|
1754
467
|
isError: true,
|
|
1755
468
|
content: [
|
|
1756
469
|
{
|
|
1757
470
|
type: "text",
|
|
1758
|
-
text:
|
|
471
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
1759
472
|
}
|
|
1760
473
|
]
|
|
1761
474
|
};
|
|
1762
475
|
}
|
|
1763
|
-
this.parser?.send(marketDataRequest);
|
|
1764
|
-
this.logger?.log({
|
|
1765
|
-
level: "info",
|
|
1766
|
-
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${marketDataRequest?.description}`
|
|
1767
|
-
});
|
|
1768
|
-
const fixData = await response;
|
|
1769
|
-
return {
|
|
1770
|
-
content: [
|
|
1771
|
-
{
|
|
1772
|
-
type: "text",
|
|
1773
|
-
text: `Market data for ${symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
1774
|
-
}
|
|
1775
|
-
]
|
|
1776
|
-
};
|
|
1777
476
|
}
|
|
1778
477
|
default:
|
|
1779
478
|
throw new Error(`Unknown tool: ${name}`);
|
|
@@ -1816,7 +515,7 @@ var MCPLocal = class {
|
|
|
1816
515
|
{
|
|
1817
516
|
name: "handlInst",
|
|
1818
517
|
description: "Handling instruction",
|
|
1819
|
-
required:
|
|
518
|
+
required: true
|
|
1820
519
|
},
|
|
1821
520
|
{
|
|
1822
521
|
name: "quantity",
|
|
@@ -1831,11 +530,11 @@ var MCPLocal = class {
|
|
|
1831
530
|
{
|
|
1832
531
|
name: "ordType",
|
|
1833
532
|
description: "Order type",
|
|
1834
|
-
required:
|
|
533
|
+
required: true
|
|
1835
534
|
},
|
|
1836
535
|
{
|
|
1837
536
|
name: "side",
|
|
1838
|
-
description: "Order side (1=Buy, 2=Sell)",
|
|
537
|
+
description: "Order side (1=Buy, 2=Sell, 3=BuyMinus, 4=SellPlus, 5=SellShort, 6=SellShortExempt, 7=Undisclosed, 8=Cross, 9=CrossShort, A=CrossShortExempt, B=AsDefined, C=Opposite, D=Subscribe, E=Redeem, F=Lend, G=Borrow, H=SellUndisclosed)",
|
|
1839
538
|
required: true
|
|
1840
539
|
},
|
|
1841
540
|
{
|
|
@@ -1846,7 +545,7 @@ var MCPLocal = class {
|
|
|
1846
545
|
{
|
|
1847
546
|
name: "timeInForce",
|
|
1848
547
|
description: "Time in force",
|
|
1849
|
-
required:
|
|
548
|
+
required: true
|
|
1850
549
|
}
|
|
1851
550
|
]
|
|
1852
551
|
},
|
|
@@ -1857,7 +556,7 @@ var MCPLocal = class {
|
|
|
1857
556
|
{
|
|
1858
557
|
name: "mdUpdateType",
|
|
1859
558
|
description: "Market data update type",
|
|
1860
|
-
required:
|
|
559
|
+
required: true
|
|
1861
560
|
},
|
|
1862
561
|
{
|
|
1863
562
|
name: "symbol",
|
|
@@ -1872,12 +571,12 @@ var MCPLocal = class {
|
|
|
1872
571
|
{
|
|
1873
572
|
name: "subscriptionRequestType",
|
|
1874
573
|
description: "Subscription request type",
|
|
1875
|
-
required:
|
|
574
|
+
required: true
|
|
1876
575
|
},
|
|
1877
576
|
{
|
|
1878
577
|
name: "mdEntryType",
|
|
1879
578
|
description: "Market data entry type",
|
|
1880
|
-
required:
|
|
579
|
+
required: true
|
|
1881
580
|
}
|
|
1882
581
|
]
|
|
1883
582
|
}
|
|
@@ -1926,15 +625,20 @@ var MCPLocal = class {
|
|
|
1926
625
|
text: [
|
|
1927
626
|
"Create a New Order Single FIX message with the following parameters:",
|
|
1928
627
|
`- ClOrdID: ${clOrdID}`,
|
|
1929
|
-
`- HandlInst: ${handlInst ?? "
|
|
628
|
+
`- HandlInst: ${handlInst ?? "3"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Manual, '2' for Automated, '3' for AutomatedNoIntervention)`,
|
|
1930
629
|
`- Quantity: ${quantity}`,
|
|
1931
630
|
`- Price: ${price}`,
|
|
1932
|
-
`- OrdType: ${ordType ?? "
|
|
1933
|
-
`- Side: ${side}`,
|
|
631
|
+
`- OrdType: ${ordType ?? "1"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Market, '2' for Limit, '3' for Stop)`,
|
|
632
|
+
`- Side: ${side} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Buy, '2' for Sell)`,
|
|
1934
633
|
`- Symbol: ${symbol}`,
|
|
1935
|
-
`- TimeInForce: ${timeInForce ?? "
|
|
634
|
+
`- TimeInForce: ${timeInForce ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for Day, '1' for Good Till Cancel, '2' for At Opening, '3' for Immediate or Cancel, '4' for Fill or Kill, '5' for Good Till Crossing, '6' for Good Till Date)`,
|
|
1936
635
|
"",
|
|
1937
|
-
|
|
636
|
+
'Note: For the OrdType parameter, always use the numeric/alphabetic value (e.g., "1" for Market, "2" for Limit, "3" for Stop) as defined in the FIX protocol, not the descriptive name.',
|
|
637
|
+
'Note: For the TimeInForce parameter, always use the numeric/alphabetic value (e.g., "0" for Day, "1" for Good Till Cancel, "2" for At Opening) as defined in the FIX protocol, not the descriptive name.',
|
|
638
|
+
"",
|
|
639
|
+
"IMPORTANT: The response will be either:",
|
|
640
|
+
"1. An Execution Report (MsgType=8) if the order was successfully placed",
|
|
641
|
+
"2. A Reject message (MsgType=3) if the order failed to execute (e.g., due to missing or invalid parameters)"
|
|
1938
642
|
].join("\n")
|
|
1939
643
|
}
|
|
1940
644
|
}
|
|
@@ -1951,13 +655,17 @@ var MCPLocal = class {
|
|
|
1951
655
|
type: "text",
|
|
1952
656
|
text: [
|
|
1953
657
|
"Create a Market Data Request FIX message with the following parameters:",
|
|
1954
|
-
`- MDUpdateType: ${mdUpdateType ?? "
|
|
658
|
+
`- MDUpdateType: ${mdUpdateType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for FullRefresh, '1' for IncrementalRefresh)`,
|
|
1955
659
|
`- Symbol: ${symbol}`,
|
|
1956
660
|
`- MDReqID: ${mdReqID}`,
|
|
1957
|
-
`- SubscriptionRequestType: ${subscriptionRequestType ?? "
|
|
1958
|
-
`- MDEntryType: ${mdEntryType ?? "
|
|
661
|
+
`- SubscriptionRequestType: ${subscriptionRequestType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for Snapshot + Updates, '1' for Snapshot, '2' for Unsubscribe)`,
|
|
662
|
+
`- MDEntryType: ${mdEntryType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for Bid, '1' for Offer, '2' for Trade, '3' for Index Value, '4' for Opening Price)`,
|
|
663
|
+
"",
|
|
664
|
+
"Format the response as a JSON object with FIX tag numbers as keys and their corresponding values.",
|
|
1959
665
|
"",
|
|
1960
|
-
|
|
666
|
+
'Note: For the MDUpdateType parameter, always use the numeric/alphabetic value (e.g., "0" for FullRefresh, "1" for IncrementalRefresh) as defined in the FIX protocol, not the descriptive name.',
|
|
667
|
+
'Note: For the SubscriptionRequestType parameter, always use the numeric/alphabetic value (e.g., "0" for Snapshot + Updates, "1" for Snapshot, "2" for Unsubscribe) as defined in the FIX protocol, not the descriptive name.',
|
|
668
|
+
'Note: For the MDEntryType parameter, always use the numeric/alphabetic value (e.g., "0" for Bid, "1" for Offer, "2" for Trade, "3" for Index Value, "4" for Opening Price) as defined in the FIX protocol, not the descriptive name.'
|
|
1961
669
|
].join("\n")
|
|
1962
670
|
}
|
|
1963
671
|
}
|