fixparser-plugin-mcp 9.1.7-f34f63d7 → 9.1.7-fa7eb92e

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,1280 +3,177 @@ 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");
11
+ import { Field, Fields, Messages } from "fixparser";
12
+ var parseInputSchema = {
13
+ type: "object",
14
+ properties: {
15
+ fixString: {
16
+ type: "string",
17
+ description: "FIX message string to parse"
348
18
  }
349
- return emojiRegex;
350
19
  },
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-_]*$/
20
+ required: ["fixString"]
369
21
  };
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 {
22
+ var parseToJSONInputSchema = {
23
+ type: "object",
24
+ properties: {
25
+ fixString: {
805
26
  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;
27
+ description: "FIX message string to parse"
1202
28
  }
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("/");
29
+ },
30
+ required: ["fixString"]
1212
31
  };
1213
- var addMeta = (def, refs, jsonSchema) => {
1214
- if (def.description) {
1215
- jsonSchema.description = def.description;
1216
- if (refs.markdownDescription) {
1217
- jsonSchema.markdownDescription = def.description;
32
+ var newOrderSingleInputSchema = {
33
+ type: "object",
34
+ properties: {
35
+ clOrdID: {
36
+ type: "string",
37
+ description: "Client Order ID"
38
+ },
39
+ handlInst: {
40
+ type: "string",
41
+ enum: ["1", "2", "3"],
42
+ 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)'
43
+ },
44
+ quantity: {
45
+ type: "number",
46
+ description: "Order quantity"
47
+ },
48
+ price: {
49
+ type: "number",
50
+ description: "Order price"
51
+ },
52
+ ordType: {
53
+ type: "string",
54
+ enum: [
55
+ "1",
56
+ "2",
57
+ "3",
58
+ "4",
59
+ "5",
60
+ "6",
61
+ "7",
62
+ "8",
63
+ "9",
64
+ "A",
65
+ "B",
66
+ "C",
67
+ "D",
68
+ "E",
69
+ "F",
70
+ "G",
71
+ "H",
72
+ "I",
73
+ "J",
74
+ "K",
75
+ "L",
76
+ "M",
77
+ "P",
78
+ "Q",
79
+ "R",
80
+ "S"
81
+ ],
82
+ 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)'
83
+ },
84
+ side: {
85
+ type: "string",
86
+ enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
87
+ 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)'
88
+ },
89
+ symbol: {
90
+ type: "string",
91
+ description: "Trading symbol"
92
+ },
93
+ timeInForce: {
94
+ type: "string",
95
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
96
+ 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)'
1218
97
  }
1219
- }
1220
- return jsonSchema;
98
+ },
99
+ required: ["clOrdID", "quantity", "price", "side", "symbol"]
1221
100
  };
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
101
+ var marketDataRequestInputSchema = {
102
+ type: "object",
103
+ properties: {
104
+ mdUpdateType: {
105
+ type: "string",
106
+ enum: ["0", "1"],
107
+ description: 'Market data update type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for FullRefresh, "1" for IncrementalRefresh)'
108
+ },
109
+ symbol: {
110
+ type: "string",
111
+ description: "Trading symbol"
112
+ },
113
+ mdReqID: {
114
+ type: "string",
115
+ description: "Market data request ID"
116
+ },
117
+ subscriptionRequestType: {
118
+ type: "string",
119
+ enum: ["0", "1", "2"],
120
+ 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)'
121
+ },
122
+ mdEntryType: {
123
+ type: "string",
124
+ enum: [
125
+ "0",
126
+ "1",
127
+ "2",
128
+ "3",
129
+ "4",
130
+ "5",
131
+ "6",
132
+ "7",
133
+ "8",
134
+ "9",
135
+ "A",
136
+ "B",
137
+ "C",
138
+ "D",
139
+ "E",
140
+ "F",
141
+ "G",
142
+ "H",
143
+ "J",
144
+ "K",
145
+ "L",
146
+ "M",
147
+ "N",
148
+ "O",
149
+ "P",
150
+ "Q",
151
+ "S",
152
+ "R",
153
+ "T",
154
+ "U",
155
+ "V",
156
+ "W",
157
+ "X",
158
+ "Y",
159
+ "Z",
160
+ "a",
161
+ "b",
162
+ "c",
163
+ "d",
164
+ "e",
165
+ "g",
166
+ "h",
167
+ "i",
168
+ "t"
169
+ ],
170
+ 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)'
1254
171
  }
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;
172
+ },
173
+ required: ["symbol", "mdReqID"]
1265
174
  };
1266
-
1267
- // src/MCPLocal.ts
1268
- import {
1269
- Field,
1270
- Fields,
1271
- HandlInst,
1272
- MDEntryType,
1273
- Messages,
1274
- OrdType,
1275
- SubscriptionRequestType,
1276
- TimeInForce
1277
- } from "fixparser";
1278
175
  var MCPLocal = class {
1279
- logger;
176
+ // private logger: Logger | undefined;
1280
177
  parser;
1281
178
  server = new Server(
1282
179
  {
@@ -1284,39 +181,48 @@ var MCPLocal = class {
1284
181
  version: "1.0.0"
1285
182
  },
1286
183
  {
1287
- capabilities: { tools: {} }
184
+ capabilities: {
185
+ tools: {},
186
+ prompts: {},
187
+ resources: {}
188
+ }
1288
189
  }
1289
190
  );
1290
191
  transport = new StdioServerTransport();
1291
192
  onReady = void 0;
1292
193
  pendingRequests = /* @__PURE__ */ new Map();
1293
194
  constructor({ logger, onReady }) {
1294
- if (logger) this.logger = logger;
1295
195
  if (onReady) this.onReady = onReady;
1296
196
  }
1297
197
  async register(parser) {
1298
198
  this.parser = parser;
1299
199
  this.parser.addOnMessageCallback((message) => {
1300
- this.logger?.log({
1301
- level: "info",
1302
- message: `FIXParser (MCP): (${parser.protocol?.toUpperCase()}): << received ${message.description}`
1303
- });
1304
200
  const msgType = message.messageType;
1305
- if (msgType === Messages.MarketDataSnapshotFullRefresh || msgType === Messages.ExecutionReport) {
1306
- const idField = msgType === Messages.MarketDataSnapshotFullRefresh ? message.getField(Fields.MDReqID) : message.getField(Fields.ClOrdID);
201
+ if (msgType === Messages.MarketDataSnapshotFullRefresh || msgType === Messages.ExecutionReport || msgType === Messages.Reject) {
202
+ const idField = msgType === Messages.MarketDataSnapshotFullRefresh ? message.getField(Fields.MDReqID) : msgType === Messages.Reject ? message.getField(Fields.RefSeqNum) : message.getField(Fields.ClOrdID);
1307
203
  if (idField) {
1308
204
  const id = idField.value;
1309
205
  if (typeof id === "string" || typeof id === "number") {
1310
- const callback = this.pendingRequests.get(String(id));
1311
- if (callback) {
1312
- callback(message);
1313
- this.pendingRequests.delete(String(id));
206
+ if (msgType === Messages.Reject) {
207
+ const refMsgType = message.getField(Fields.RefMsgType);
208
+ if (refMsgType && refMsgType.value === Messages.NewOrderSingle) {
209
+ const callback = this.pendingRequests.get(String(id));
210
+ if (callback) {
211
+ callback(message);
212
+ this.pendingRequests.delete(String(id));
213
+ }
214
+ }
215
+ } else {
216
+ const callback = this.pendingRequests.get(String(id));
217
+ if (callback) {
218
+ callback(message);
219
+ this.pendingRequests.delete(String(id));
220
+ }
1314
221
  }
1315
222
  }
1316
223
  }
1317
224
  }
1318
225
  });
1319
- this.logger = parser.logger;
1320
226
  this.addWorkflows();
1321
227
  await this.server.connect(this.transport);
1322
228
  if (this.onReady) {
@@ -1325,19 +231,27 @@ var MCPLocal = class {
1325
231
  }
1326
232
  addWorkflows() {
1327
233
  if (!this.parser) {
1328
- this.logger?.log({
1329
- level: "error",
1330
- message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of workflows..."
1331
- });
1332
234
  return;
1333
235
  }
1334
236
  if (!this.server) {
1335
- this.logger?.log({
1336
- level: "error",
1337
- message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of workflows..."
1338
- });
1339
237
  return;
1340
238
  }
239
+ const validateArgs = (args, schema) => {
240
+ const result = {};
241
+ for (const [key, propSchema] of Object.entries(schema.properties || {})) {
242
+ const prop = propSchema;
243
+ const value = args?.[key];
244
+ if (prop.required && (value === void 0 || value === null)) {
245
+ throw new Error(`Required property '${key}' is missing`);
246
+ }
247
+ if (value !== void 0) {
248
+ result[key] = value;
249
+ } else if (prop.default !== void 0) {
250
+ result[key] = prop.default;
251
+ }
252
+ }
253
+ return result;
254
+ };
1341
255
  this.server.setRequestHandler(ListResourcesRequestSchema, async () => {
1342
256
  return {
1343
257
  resources: []
@@ -1349,143 +263,22 @@ var MCPLocal = class {
1349
263
  {
1350
264
  name: "parse",
1351
265
  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
- )
266
+ inputSchema: parseInputSchema
1358
267
  },
1359
268
  {
1360
269
  name: "parseToJSON",
1361
270
  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
- )
271
+ inputSchema: parseToJSONInputSchema
1368
272
  },
1369
273
  {
1370
274
  name: "newOrderSingle",
1371
275
  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
- )
276
+ inputSchema: newOrderSingleInputSchema
1430
277
  },
1431
278
  {
1432
279
  name: "marketDataRequest",
1433
280
  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
- )
281
+ inputSchema: marketDataRequestInputSchema
1489
282
  }
1490
283
  ]
1491
284
  };
@@ -1494,10 +287,8 @@ var MCPLocal = class {
1494
287
  const { name, arguments: args } = request.params;
1495
288
  switch (name) {
1496
289
  case "parse": {
1497
- const { fixString } = z.object({
1498
- fixString: z.string().describe("FIX message string to parse")
1499
- }).parse(args || {});
1500
290
  try {
291
+ const { fixString } = validateArgs(args, parseInputSchema);
1501
292
  const parsedMessage = this.parser?.parse(fixString);
1502
293
  if (!parsedMessage || parsedMessage.length === 0) {
1503
294
  return {
@@ -1509,7 +300,8 @@ var MCPLocal = class {
1509
300
  content: [
1510
301
  {
1511
302
  type: "text",
1512
- text: `Parsed FIX message: ${fixString} (placeholder implementation)`
303
+ text: `${parsedMessage[0].description}
304
+ ${parsedMessage[0].messageTypeDescription}`
1513
305
  }
1514
306
  ]
1515
307
  };
@@ -1519,17 +311,15 @@ var MCPLocal = class {
1519
311
  content: [
1520
312
  {
1521
313
  type: "text",
1522
- text: "Error: Failed to parse FIX string"
314
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
1523
315
  }
1524
316
  ]
1525
317
  };
1526
318
  }
1527
319
  }
1528
320
  case "parseToJSON": {
1529
- const { fixString } = z.object({
1530
- fixString: z.string().describe("FIX message string to parse")
1531
- }).parse(args || {});
1532
321
  try {
322
+ const { fixString } = validateArgs(args, parseToJSONInputSchema);
1533
323
  const parsedMessage = this.parser?.parse(fixString);
1534
324
  if (!parsedMessage || parsedMessage.length === 0) {
1535
325
  return {
@@ -1541,7 +331,7 @@ var MCPLocal = class {
1541
331
  content: [
1542
332
  {
1543
333
  type: "text",
1544
- text: JSON.stringify({ fixString, parsed: "placeholder" })
334
+ text: `${parsedMessage[0].toFIXJSON()}`
1545
335
  }
1546
336
  ]
1547
337
  };
@@ -1551,220 +341,324 @@ var MCPLocal = class {
1551
341
  content: [
1552
342
  {
1553
343
  type: "text",
1554
- text: "Error: Failed to parse FIX string"
344
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
1555
345
  }
1556
346
  ]
1557
347
  };
1558
348
  }
1559
349
  }
1560
350
  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) {
1636
- this.logger?.log({
1637
- level: "error",
1638
- message: "FIXParser (MCP): -- Not connected. Ignoring message."
351
+ try {
352
+ const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = validateArgs(args, newOrderSingleInputSchema);
353
+ const response = new Promise((resolve) => {
354
+ this.pendingRequests.set(clOrdID, resolve);
1639
355
  });
356
+ const order = this.parser?.createMessage(
357
+ new Field(Fields.MsgType, Messages.NewOrderSingle),
358
+ new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
359
+ new Field(Fields.SenderCompID, this.parser?.sender),
360
+ new Field(Fields.TargetCompID, this.parser?.target),
361
+ new Field(Fields.SendingTime, this.parser?.getTimestamp()),
362
+ new Field(Fields.ClOrdID, clOrdID),
363
+ new Field(Fields.Side, side),
364
+ new Field(Fields.Symbol, symbol),
365
+ new Field(Fields.OrderQty, quantity),
366
+ new Field(Fields.Price, price),
367
+ new Field(Fields.OrdType, ordType),
368
+ new Field(Fields.HandlInst, handlInst),
369
+ new Field(Fields.TimeInForce, timeInForce),
370
+ new Field(Fields.TransactTime, this.parser?.getTimestamp())
371
+ );
372
+ if (!this.parser?.connected) {
373
+ return {
374
+ isError: true,
375
+ content: [
376
+ {
377
+ type: "text",
378
+ text: "Error: Not connected. Ignoring message."
379
+ }
380
+ ]
381
+ };
382
+ }
383
+ this.parser?.send(order);
384
+ const fixData = await response;
385
+ return {
386
+ content: [
387
+ {
388
+ type: "text",
389
+ text: fixData.messageType === Messages.Reject ? `Reject message for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
390
+ }
391
+ ]
392
+ };
393
+ } catch (error) {
1640
394
  return {
1641
395
  isError: true,
1642
396
  content: [
1643
397
  {
1644
398
  type: "text",
1645
- text: "Error: Not connected. Ignoring message."
399
+ text: `Error: ${error instanceof Error ? error.message : "Failed to create order"}`
1646
400
  }
1647
401
  ]
1648
402
  };
1649
403
  }
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
404
  }
1665
405
  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) {
1737
- this.logger?.log({
1738
- level: "error",
1739
- message: "FIXParser (MCP): -- Not connected. Ignoring message."
406
+ try {
407
+ const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = validateArgs(
408
+ args,
409
+ marketDataRequestInputSchema
410
+ );
411
+ const response = new Promise((resolve) => {
412
+ this.pendingRequests.set(mdReqID, resolve);
1740
413
  });
414
+ const marketDataRequest = this.parser?.createMessage(
415
+ new Field(Fields.MsgType, Messages.MarketDataRequest),
416
+ new Field(Fields.SenderCompID, this.parser?.sender),
417
+ new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
418
+ new Field(Fields.TargetCompID, this.parser?.target),
419
+ new Field(Fields.SendingTime, this.parser?.getTimestamp()),
420
+ new Field(Fields.MarketDepth, 0),
421
+ new Field(Fields.MDUpdateType, mdUpdateType),
422
+ new Field(Fields.NoRelatedSym, 1),
423
+ new Field(Fields.Symbol, symbol),
424
+ new Field(Fields.MDReqID, mdReqID),
425
+ new Field(Fields.SubscriptionRequestType, subscriptionRequestType),
426
+ new Field(Fields.NoMDEntryTypes, 1),
427
+ new Field(Fields.MDEntryType, mdEntryType)
428
+ );
429
+ if (!this.parser?.connected) {
430
+ return {
431
+ isError: true,
432
+ content: [
433
+ {
434
+ type: "text",
435
+ text: "Error: Not connected. Ignoring message."
436
+ }
437
+ ]
438
+ };
439
+ }
440
+ this.parser?.send(marketDataRequest);
441
+ const fixData = await response;
442
+ return {
443
+ content: [
444
+ {
445
+ type: "text",
446
+ text: `Market data for ${symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
447
+ }
448
+ ]
449
+ };
450
+ } catch (error) {
1741
451
  return {
1742
452
  isError: true,
1743
453
  content: [
1744
454
  {
1745
455
  type: "text",
1746
- text: "Error: Not connected. Ignoring message."
456
+ text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
1747
457
  }
1748
458
  ]
1749
459
  };
1750
460
  }
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;
461
+ }
462
+ default:
463
+ throw new Error(`Unknown tool: ${name}`);
464
+ }
465
+ });
466
+ this.server.setRequestHandler(ListPromptsRequestSchema, async () => {
467
+ return {
468
+ prompts: [
469
+ {
470
+ name: "parse",
471
+ description: "Parses a FIX message and describes it in plain language",
472
+ arguments: [
473
+ {
474
+ name: "fixString",
475
+ description: "FIX message string to parse",
476
+ required: true
477
+ }
478
+ ]
479
+ },
480
+ {
481
+ name: "parseToJSON",
482
+ description: "Parses a FIX message into JSON",
483
+ arguments: [
484
+ {
485
+ name: "fixString",
486
+ description: "FIX message string to parse",
487
+ required: true
488
+ }
489
+ ]
490
+ },
491
+ {
492
+ name: "newOrderSingle",
493
+ description: "Creates and sends a New Order Single",
494
+ arguments: [
495
+ {
496
+ name: "clOrdID",
497
+ description: "Client Order ID",
498
+ required: true
499
+ },
500
+ {
501
+ name: "handlInst",
502
+ description: "Handling instruction",
503
+ required: true
504
+ },
505
+ {
506
+ name: "quantity",
507
+ description: "Order quantity",
508
+ required: true
509
+ },
510
+ {
511
+ name: "price",
512
+ description: "Order price",
513
+ required: true
514
+ },
515
+ {
516
+ name: "ordType",
517
+ description: "Order type",
518
+ required: true
519
+ },
520
+ {
521
+ name: "side",
522
+ 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)",
523
+ required: true
524
+ },
525
+ {
526
+ name: "symbol",
527
+ description: "Trading symbol",
528
+ required: true
529
+ },
530
+ {
531
+ name: "timeInForce",
532
+ description: "Time in force",
533
+ required: true
534
+ }
535
+ ]
536
+ },
537
+ {
538
+ name: "marketDataRequest",
539
+ description: "Sends a request for Market Data with the given symbol",
540
+ arguments: [
541
+ {
542
+ name: "mdUpdateType",
543
+ description: "Market data update type",
544
+ required: true
545
+ },
546
+ {
547
+ name: "symbol",
548
+ description: "Trading symbol",
549
+ required: true
550
+ },
551
+ {
552
+ name: "mdReqID",
553
+ description: "Market data request ID",
554
+ required: true
555
+ },
556
+ {
557
+ name: "subscriptionRequestType",
558
+ description: "Subscription request type",
559
+ required: true
560
+ },
561
+ {
562
+ name: "mdEntryType",
563
+ description: "Market data entry type",
564
+ required: true
565
+ }
566
+ ]
567
+ }
568
+ ]
569
+ };
570
+ });
571
+ this.server.setRequestHandler(GetPromptRequestSchema, async (request) => {
572
+ const { name, arguments: args } = request.params;
573
+ switch (name) {
574
+ case "parse": {
575
+ const fixString = args?.fixString || "";
576
+ return {
577
+ messages: [
578
+ {
579
+ role: "user",
580
+ content: {
581
+ type: "text",
582
+ text: `Please parse and explain this FIX message: ${fixString}`
583
+ }
584
+ }
585
+ ]
586
+ };
587
+ }
588
+ case "parseToJSON": {
589
+ const fixString = args?.fixString || "";
590
+ return {
591
+ messages: [
592
+ {
593
+ role: "user",
594
+ content: {
595
+ type: "text",
596
+ text: `Please parse the FIX message to JSON: ${fixString}`
597
+ }
598
+ }
599
+ ]
600
+ };
601
+ }
602
+ case "newOrderSingle": {
603
+ const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = args || {};
1757
604
  return {
1758
- content: [
605
+ messages: [
1759
606
  {
1760
- type: "text",
1761
- text: `Market data for ${symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
607
+ role: "user",
608
+ content: {
609
+ type: "text",
610
+ text: [
611
+ "Create a New Order Single FIX message with the following parameters:",
612
+ `- ClOrdID: ${clOrdID}`,
613
+ `- 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)`,
614
+ `- Quantity: ${quantity}`,
615
+ `- Price: ${price}`,
616
+ `- 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)`,
617
+ `- Side: ${side} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Buy, '2' for Sell)`,
618
+ `- Symbol: ${symbol}`,
619
+ `- 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)`,
620
+ "",
621
+ '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.',
622
+ '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.',
623
+ "",
624
+ "IMPORTANT: The response will be either:",
625
+ "1. An Execution Report (MsgType=8) if the order was successfully placed",
626
+ "2. A Reject message (MsgType=3) if the order failed to execute (e.g., due to missing or invalid parameters)"
627
+ ].join("\n")
628
+ }
629
+ }
630
+ ]
631
+ };
632
+ }
633
+ case "marketDataRequest": {
634
+ const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = args || {};
635
+ return {
636
+ messages: [
637
+ {
638
+ role: "user",
639
+ content: {
640
+ type: "text",
641
+ text: [
642
+ "Create a Market Data Request FIX message with the following parameters:",
643
+ `- MDUpdateType: ${mdUpdateType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for FullRefresh, '1' for IncrementalRefresh)`,
644
+ `- Symbol: ${symbol}`,
645
+ `- MDReqID: ${mdReqID}`,
646
+ `- 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)`,
647
+ `- 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)`,
648
+ "",
649
+ "Format the response as a JSON object with FIX tag numbers as keys and their corresponding values.",
650
+ "",
651
+ '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.',
652
+ '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.',
653
+ '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.'
654
+ ].join("\n")
655
+ }
1762
656
  }
1763
657
  ]
1764
658
  };
1765
659
  }
1766
660
  default:
1767
- throw new Error(`Unknown tool: ${name}`);
661
+ throw new Error(`Unknown prompt: ${name}`);
1768
662
  }
1769
663
  });
1770
664
  process.on("SIGINT", async () => {