fixparser-plugin-mcp 9.1.7-f34f63d7 → 9.1.7-f3ba3218

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