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