fixparser-plugin-mcp 9.1.6-da9cb1d7 → 9.1.7-03aa39bd

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.
@@ -0,0 +1,1089 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/MCPLocal.ts
21
+ var MCPLocal_exports = {};
22
+ __export(MCPLocal_exports, {
23
+ MCPLocal: () => MCPLocal
24
+ });
25
+ module.exports = __toCommonJS(MCPLocal_exports);
26
+ var import_server = require("@modelcontextprotocol/sdk/server/index.js");
27
+ var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
28
+ var import_fixparser = require("fixparser");
29
+ var import_zod = require("zod");
30
+ var fixStringSchema = import_zod.z.object({
31
+ fixString: import_zod.z.string()
32
+ });
33
+ var orderSchema = import_zod.z.object({
34
+ clOrdID: import_zod.z.string(),
35
+ handlInst: import_zod.z.enum(["1", "2", "3"]),
36
+ quantity: import_zod.z.string(),
37
+ price: import_zod.z.string(),
38
+ ordType: import_zod.z.enum([
39
+ "1",
40
+ "2",
41
+ "3",
42
+ "4",
43
+ "5",
44
+ "6",
45
+ "7",
46
+ "8",
47
+ "9",
48
+ "A",
49
+ "B",
50
+ "C",
51
+ "D",
52
+ "E",
53
+ "F",
54
+ "G",
55
+ "H",
56
+ "I",
57
+ "J",
58
+ "K",
59
+ "L",
60
+ "M",
61
+ "P",
62
+ "Q",
63
+ "R",
64
+ "S"
65
+ ]),
66
+ side: import_zod.z.enum(["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"]),
67
+ symbol: import_zod.z.string(),
68
+ timeInForce: import_zod.z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"])
69
+ });
70
+ var marketDataRequestSchema = import_zod.z.object({
71
+ mdUpdateType: import_zod.z.enum(["0", "1"]),
72
+ symbols: import_zod.z.array(import_zod.z.string()),
73
+ mdReqID: import_zod.z.string(),
74
+ subscriptionRequestType: import_zod.z.enum(["0", "1", "2"]),
75
+ mdEntryTypes: import_zod.z.array(
76
+ import_zod.z.enum([
77
+ "0",
78
+ "1",
79
+ "2",
80
+ "3",
81
+ "4",
82
+ "5",
83
+ "6",
84
+ "7",
85
+ "8",
86
+ "9",
87
+ "A",
88
+ "B",
89
+ "C",
90
+ "D",
91
+ "E",
92
+ "F",
93
+ "G",
94
+ "H",
95
+ "J",
96
+ "K",
97
+ "L",
98
+ "M",
99
+ "N",
100
+ "O",
101
+ "P",
102
+ "Q",
103
+ "R",
104
+ "S",
105
+ "T",
106
+ "U",
107
+ "V",
108
+ "W",
109
+ "X",
110
+ "Y",
111
+ "Z",
112
+ "a",
113
+ "b",
114
+ "c",
115
+ "d",
116
+ "e",
117
+ "g",
118
+ "h",
119
+ "i",
120
+ "t"
121
+ ])
122
+ )
123
+ });
124
+ var MCPLocal = class {
125
+ parser;
126
+ server = new import_server.Server(
127
+ {
128
+ name: "fixparser",
129
+ version: "1.0.0"
130
+ },
131
+ {
132
+ capabilities: {
133
+ tools: {
134
+ parse: {
135
+ description: "Parses a FIX message and describes it in plain language",
136
+ parameters: {
137
+ type: "object",
138
+ properties: {
139
+ fixString: { type: "string" }
140
+ },
141
+ required: ["fixString"]
142
+ }
143
+ },
144
+ parseToJSON: {
145
+ description: "Parses a FIX message into JSON",
146
+ parameters: {
147
+ type: "object",
148
+ properties: {
149
+ fixString: { type: "string" }
150
+ },
151
+ required: ["fixString"]
152
+ }
153
+ },
154
+ verifyOrder: {
155
+ description: "Verifies order parameters before execution",
156
+ parameters: {
157
+ type: "object",
158
+ properties: {
159
+ clOrdID: { type: "string" },
160
+ handlInst: { type: "string", enum: ["1", "2", "3"] },
161
+ quantity: { type: "string" },
162
+ price: { type: "string" },
163
+ ordType: {
164
+ type: "string",
165
+ enum: [
166
+ "1",
167
+ "2",
168
+ "3",
169
+ "4",
170
+ "5",
171
+ "6",
172
+ "7",
173
+ "8",
174
+ "9",
175
+ "A",
176
+ "B",
177
+ "C",
178
+ "D",
179
+ "E",
180
+ "F",
181
+ "G",
182
+ "H",
183
+ "I",
184
+ "J",
185
+ "K",
186
+ "L",
187
+ "M",
188
+ "P",
189
+ "Q",
190
+ "R",
191
+ "S"
192
+ ]
193
+ },
194
+ side: {
195
+ type: "string",
196
+ enum: [
197
+ "1",
198
+ "2",
199
+ "3",
200
+ "4",
201
+ "5",
202
+ "6",
203
+ "7",
204
+ "8",
205
+ "9",
206
+ "A",
207
+ "B",
208
+ "C",
209
+ "D",
210
+ "E",
211
+ "F",
212
+ "G",
213
+ "H"
214
+ ]
215
+ },
216
+ symbol: { type: "string" },
217
+ timeInForce: {
218
+ type: "string",
219
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
220
+ }
221
+ },
222
+ required: [
223
+ "clOrdID",
224
+ "handlInst",
225
+ "quantity",
226
+ "price",
227
+ "ordType",
228
+ "side",
229
+ "symbol",
230
+ "timeInForce"
231
+ ]
232
+ }
233
+ },
234
+ executeOrder: {
235
+ description: "Executes a verified order",
236
+ parameters: {
237
+ type: "object",
238
+ properties: {
239
+ clOrdID: { type: "string" },
240
+ handlInst: { type: "string", enum: ["1", "2", "3"] },
241
+ quantity: { type: "string" },
242
+ price: { type: "string" },
243
+ ordType: { type: "string" },
244
+ side: { type: "string" },
245
+ symbol: { type: "string" },
246
+ timeInForce: { type: "string" }
247
+ },
248
+ required: [
249
+ "clOrdID",
250
+ "handlInst",
251
+ "quantity",
252
+ "price",
253
+ "ordType",
254
+ "side",
255
+ "symbol",
256
+ "timeInForce"
257
+ ]
258
+ }
259
+ },
260
+ marketDataRequest: {
261
+ description: "Requests market data for specified symbols",
262
+ parameters: {
263
+ type: "object",
264
+ properties: {
265
+ mdUpdateType: { type: "string", enum: ["0", "1"] },
266
+ symbols: { type: "array", items: { type: "string" } },
267
+ mdReqID: { type: "string" },
268
+ subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
269
+ mdEntryTypes: { type: "array", items: { type: "string" } }
270
+ },
271
+ required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType", "mdEntryTypes"]
272
+ }
273
+ }
274
+ },
275
+ resources: {
276
+ greeting: {
277
+ description: "A simple greeting resource",
278
+ uri: "greeting-resource"
279
+ },
280
+ stockGraph: {
281
+ description: "Generates a price chart for a given symbol",
282
+ uri: "stockGraph/{symbol}"
283
+ },
284
+ stockPriceHistory: {
285
+ description: "Returns price history for a given symbol",
286
+ uri: "stockPriceHistory/{symbol}"
287
+ }
288
+ }
289
+ }
290
+ }
291
+ );
292
+ transport = new import_stdio.StdioServerTransport();
293
+ onReady = void 0;
294
+ pendingRequests = /* @__PURE__ */ new Map();
295
+ verifiedOrders = /* @__PURE__ */ new Map();
296
+ // Store market data prices with timestamps
297
+ marketDataPrices = /* @__PURE__ */ new Map();
298
+ MAX_PRICE_HISTORY = 1e5;
299
+ // Maximum number of price points to store per symbol
300
+ constructor({ logger, onReady }) {
301
+ if (onReady) this.onReady = onReady;
302
+ }
303
+ async register(parser) {
304
+ this.parser = parser;
305
+ this.parser.addOnMessageCallback((message) => {
306
+ this.parser?.logger.log({
307
+ level: "info",
308
+ message: `MCP Server received message: ${message.messageType}: ${message.description}`
309
+ });
310
+ const msgType = message.messageType;
311
+ if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport || msgType === import_fixparser.Messages.Reject || msgType === import_fixparser.Messages.MarketDataIncrementalRefresh) {
312
+ this.parser?.logger.log({
313
+ level: "info",
314
+ message: `MCP Server handling message type: ${msgType}`
315
+ });
316
+ let id;
317
+ if (msgType === import_fixparser.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
318
+ const symbol = message.getField(import_fixparser.Fields.Symbol);
319
+ const price = message.getField(import_fixparser.Fields.MDEntryPx);
320
+ const timestamp = message.getField(import_fixparser.Fields.MDEntryTime)?.value || Date.now();
321
+ if (symbol?.value && price?.value) {
322
+ const symbolStr = String(symbol.value);
323
+ const priceNum = Number(price.value);
324
+ const priceHistory = this.marketDataPrices.get(symbolStr) || [];
325
+ priceHistory.push({
326
+ timestamp: Number(timestamp),
327
+ price: priceNum
328
+ });
329
+ if (priceHistory.length > this.MAX_PRICE_HISTORY) {
330
+ priceHistory.shift();
331
+ }
332
+ this.marketDataPrices.set(symbolStr, priceHistory);
333
+ this.parser?.logger.log({
334
+ level: "info",
335
+ message: `MCP Server added ${symbol}: ${priceNum}`
336
+ });
337
+ }
338
+ }
339
+ if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
340
+ const mdReqID = message.getField(import_fixparser.Fields.MDReqID);
341
+ if (mdReqID) id = String(mdReqID.value);
342
+ } else if (msgType === import_fixparser.Messages.ExecutionReport) {
343
+ const clOrdID = message.getField(import_fixparser.Fields.ClOrdID);
344
+ if (clOrdID) id = String(clOrdID.value);
345
+ } else if (msgType === import_fixparser.Messages.Reject) {
346
+ const refSeqNum = message.getField(import_fixparser.Fields.RefSeqNum);
347
+ if (refSeqNum) id = String(refSeqNum.value);
348
+ }
349
+ if (id) {
350
+ const callback = this.pendingRequests.get(id);
351
+ if (callback) {
352
+ callback(message);
353
+ this.pendingRequests.delete(id);
354
+ }
355
+ }
356
+ }
357
+ });
358
+ this.addWorkflows();
359
+ await this.server.connect(this.transport);
360
+ if (this.onReady) {
361
+ this.onReady();
362
+ }
363
+ }
364
+ addWorkflows() {
365
+ if (!this.parser) {
366
+ return;
367
+ }
368
+ if (!this.server) {
369
+ return;
370
+ }
371
+ this.server.setRequestHandler(
372
+ import_zod.z.object({ method: import_zod.z.literal("resources/list") }),
373
+ async (request, extra) => {
374
+ return {
375
+ resources: [
376
+ {
377
+ name: "greeting",
378
+ description: "A simple greeting resource",
379
+ uri: "greeting-resource"
380
+ },
381
+ {
382
+ name: "stockGraph",
383
+ description: "Generates a price chart for a given symbol",
384
+ uri: "stockGraph",
385
+ parameters: {
386
+ type: "object",
387
+ properties: {
388
+ symbol: { type: "string" }
389
+ },
390
+ required: ["symbol"]
391
+ }
392
+ },
393
+ {
394
+ name: "stockPriceHistory",
395
+ description: "Returns price history for a given symbol",
396
+ uri: "stockPriceHistory",
397
+ parameters: {
398
+ type: "object",
399
+ properties: {
400
+ symbol: { type: "string" }
401
+ },
402
+ required: ["symbol"]
403
+ }
404
+ }
405
+ ]
406
+ };
407
+ }
408
+ );
409
+ this.server.setRequestHandler(
410
+ import_zod.z.object({ method: import_zod.z.literal("tools/list") }),
411
+ async (request, extra) => {
412
+ return {
413
+ tools: [
414
+ {
415
+ name: "parse",
416
+ description: "Parses a FIX message and describes it in plain language",
417
+ inputSchema: {
418
+ type: "object",
419
+ properties: {
420
+ fixString: { type: "string" }
421
+ },
422
+ required: ["fixString"]
423
+ }
424
+ },
425
+ {
426
+ name: "parseToJSON",
427
+ description: "Parses a FIX message into JSON",
428
+ inputSchema: {
429
+ type: "object",
430
+ properties: {
431
+ fixString: { type: "string" }
432
+ },
433
+ required: ["fixString"]
434
+ }
435
+ },
436
+ {
437
+ name: "verifyOrder",
438
+ description: "Verifies order parameters before execution",
439
+ inputSchema: {
440
+ type: "object",
441
+ properties: {
442
+ clOrdID: { type: "string" },
443
+ handlInst: { type: "string", enum: ["1", "2", "3"] },
444
+ quantity: { type: "string" },
445
+ price: { type: "string" },
446
+ ordType: {
447
+ type: "string",
448
+ enum: [
449
+ "1",
450
+ "2",
451
+ "3",
452
+ "4",
453
+ "5",
454
+ "6",
455
+ "7",
456
+ "8",
457
+ "9",
458
+ "A",
459
+ "B",
460
+ "C",
461
+ "D",
462
+ "E",
463
+ "F",
464
+ "G",
465
+ "H",
466
+ "I",
467
+ "J",
468
+ "K",
469
+ "L",
470
+ "M",
471
+ "P",
472
+ "Q",
473
+ "R",
474
+ "S"
475
+ ]
476
+ },
477
+ side: {
478
+ type: "string",
479
+ enum: [
480
+ "1",
481
+ "2",
482
+ "3",
483
+ "4",
484
+ "5",
485
+ "6",
486
+ "7",
487
+ "8",
488
+ "9",
489
+ "A",
490
+ "B",
491
+ "C",
492
+ "D",
493
+ "E",
494
+ "F",
495
+ "G",
496
+ "H"
497
+ ]
498
+ },
499
+ symbol: { type: "string" },
500
+ timeInForce: {
501
+ type: "string",
502
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
503
+ }
504
+ },
505
+ required: [
506
+ "clOrdID",
507
+ "handlInst",
508
+ "quantity",
509
+ "price",
510
+ "ordType",
511
+ "side",
512
+ "symbol",
513
+ "timeInForce"
514
+ ]
515
+ }
516
+ },
517
+ {
518
+ name: "executeOrder",
519
+ description: "Executes a verified order",
520
+ inputSchema: {
521
+ type: "object",
522
+ properties: {
523
+ clOrdID: { type: "string" },
524
+ handlInst: { type: "string", enum: ["1", "2", "3"] },
525
+ quantity: { type: "string" },
526
+ price: { type: "string" },
527
+ ordType: { type: "string" },
528
+ side: { type: "string" },
529
+ symbol: { type: "string" },
530
+ timeInForce: { type: "string" }
531
+ },
532
+ required: [
533
+ "clOrdID",
534
+ "handlInst",
535
+ "quantity",
536
+ "price",
537
+ "ordType",
538
+ "side",
539
+ "symbol",
540
+ "timeInForce"
541
+ ]
542
+ }
543
+ },
544
+ {
545
+ name: "marketDataRequest",
546
+ description: "Requests market data for specified symbols",
547
+ inputSchema: {
548
+ type: "object",
549
+ properties: {
550
+ mdUpdateType: { type: "string", enum: ["0", "1"] },
551
+ symbols: { type: "array", items: { type: "string" } },
552
+ mdReqID: { type: "string" },
553
+ subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
554
+ mdEntryTypes: { type: "array", items: { type: "string" } }
555
+ },
556
+ required: [
557
+ "mdUpdateType",
558
+ "symbols",
559
+ "mdReqID",
560
+ "subscriptionRequestType",
561
+ "mdEntryTypes"
562
+ ]
563
+ }
564
+ }
565
+ ]
566
+ };
567
+ }
568
+ );
569
+ this.server.setRequestHandler(
570
+ import_zod.z.object({
571
+ method: import_zod.z.literal("resources/read"),
572
+ params: import_zod.z.object({
573
+ uri: import_zod.z.string()
574
+ })
575
+ }),
576
+ async (request, extra) => {
577
+ const { uri } = request.params;
578
+ switch (uri) {
579
+ case "greeting-resource":
580
+ return {
581
+ contents: [
582
+ {
583
+ type: "text",
584
+ text: "Hello, world!",
585
+ uri: "greeting-resource"
586
+ }
587
+ ]
588
+ };
589
+ case "stockGraph":
590
+ return {
591
+ contents: [
592
+ {
593
+ type: "text",
594
+ text: "This resource requires a symbol parameter. Please use the stockGraph/{symbol} resource.",
595
+ uri: "stockGraph"
596
+ }
597
+ ]
598
+ };
599
+ case "stockPriceHistory":
600
+ return {
601
+ contents: [
602
+ {
603
+ type: "text",
604
+ text: "This resource requires a symbol parameter. Please use the stockPriceHistory/{symbol} resource.",
605
+ uri: "stockPriceHistory"
606
+ }
607
+ ]
608
+ };
609
+ default:
610
+ if (uri.startsWith("stockGraph/")) {
611
+ const symbol = uri.split("/")[1];
612
+ const priceHistory = this.marketDataPrices.get(symbol) || [];
613
+ if (priceHistory.length === 0) {
614
+ return {
615
+ contents: [
616
+ {
617
+ type: "text",
618
+ text: `No price data available for ${symbol}`
619
+ }
620
+ ]
621
+ };
622
+ }
623
+ const width = 600;
624
+ const height = 300;
625
+ const padding = 40;
626
+ const xScale = (width - 2 * padding) / (priceHistory.length - 1);
627
+ const yMin = Math.min(...priceHistory.map((d) => d.price));
628
+ const yMax = Math.max(...priceHistory.map((d) => d.price));
629
+ const yScale = (height - 2 * padding) / (yMax - yMin);
630
+ const points = priceHistory.map((d, i) => {
631
+ const x = padding + i * xScale;
632
+ const y = height - padding - (d.price - yMin) * yScale;
633
+ return `${x},${y}`;
634
+ }).join(" L ");
635
+ const svg = `<?xml version="1.0" encoding="UTF-8"?>
636
+ <svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
637
+ <!-- Background -->
638
+ <rect width="100%" height="100%" fill="#f8f9fa"/>
639
+
640
+ <!-- Grid lines -->
641
+ <g stroke="#e9ecef" stroke-width="1">
642
+ ${Array.from({ length: 5 }, (_, i) => {
643
+ const y = padding + (height - 2 * padding) * i / 4;
644
+ return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
645
+ }).join("\n")}
646
+ </g>
647
+
648
+ <!-- Price line -->
649
+ <path d="M ${points}"
650
+ fill="none"
651
+ stroke="#007bff"
652
+ stroke-width="2"/>
653
+
654
+ <!-- Data points -->
655
+ ${priceHistory.map((d, i) => {
656
+ const x = padding + i * xScale;
657
+ const y = height - padding - (d.price - yMin) * yScale;
658
+ return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
659
+ }).join("\n")}
660
+
661
+ <!-- Labels -->
662
+ <g font-family="Arial" font-size="12" fill="#495057">
663
+ ${Array.from({ length: 5 }, (_, i) => {
664
+ const x = padding + (width - 2 * padding) * i / 4;
665
+ const index = Math.floor((priceHistory.length - 1) * i / 4);
666
+ const timestamp = new Date(priceHistory[index].timestamp).toLocaleTimeString();
667
+ return `<text x="${x + padding}" y="${height - padding + 20}" text-anchor="middle">${timestamp}</text>`;
668
+ }).join("\n")}
669
+ ${Array.from({ length: 5 }, (_, i) => {
670
+ const y = padding + (height - 2 * padding) * i / 4;
671
+ const price = yMax - (yMax - yMin) * i / 4;
672
+ return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
673
+ }).join("\n")}
674
+ </g>
675
+
676
+ <!-- Title -->
677
+ <text x="${width / 2}" y="${padding / 2}"
678
+ font-family="Arial" font-size="16" font-weight="bold"
679
+ text-anchor="middle" fill="#212529">
680
+ ${symbol} - Price Chart (${priceHistory.length} points)
681
+ </text>
682
+ </svg>`;
683
+ return {
684
+ contents: [
685
+ {
686
+ type: "text",
687
+ text: svg
688
+ }
689
+ ]
690
+ };
691
+ }
692
+ if (uri.startsWith("stockPriceHistory/")) {
693
+ const symbol = uri.split("/")[1];
694
+ const priceHistory = this.marketDataPrices.get(symbol) || [];
695
+ if (priceHistory.length === 0) {
696
+ return {
697
+ contents: [
698
+ {
699
+ type: "text",
700
+ text: `No price data available for ${symbol}`
701
+ }
702
+ ]
703
+ };
704
+ }
705
+ return {
706
+ contents: [
707
+ {
708
+ type: "text",
709
+ text: JSON.stringify(
710
+ {
711
+ symbol,
712
+ count: priceHistory.length,
713
+ prices: priceHistory.map((point) => ({
714
+ timestamp: new Date(point.timestamp).toISOString(),
715
+ price: point.price
716
+ }))
717
+ },
718
+ null,
719
+ 2
720
+ )
721
+ }
722
+ ]
723
+ };
724
+ }
725
+ return {
726
+ contents: [
727
+ {
728
+ type: "text",
729
+ text: `Resource not found: ${uri}`,
730
+ uri
731
+ }
732
+ ],
733
+ isError: true
734
+ };
735
+ }
736
+ }
737
+ );
738
+ this.server.setRequestHandler(
739
+ import_zod.z.object({
740
+ method: import_zod.z.literal("parse"),
741
+ params: fixStringSchema
742
+ }),
743
+ async (request, extra) => {
744
+ try {
745
+ const args = request.params;
746
+ const parsedMessage = this.parser?.parse(args.fixString);
747
+ if (!parsedMessage || parsedMessage.length === 0) {
748
+ return {
749
+ contents: [{ type: "text", text: "Error: Failed to parse FIX string" }],
750
+ isError: true
751
+ };
752
+ }
753
+ return {
754
+ contents: [
755
+ {
756
+ type: "text",
757
+ text: `${parsedMessage[0].description}
758
+ ${parsedMessage[0].messageTypeDescription}`
759
+ }
760
+ ]
761
+ };
762
+ } catch (error) {
763
+ return {
764
+ contents: [
765
+ {
766
+ type: "text",
767
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
768
+ }
769
+ ],
770
+ isError: true
771
+ };
772
+ }
773
+ }
774
+ );
775
+ this.server.setRequestHandler(
776
+ import_zod.z.object({
777
+ method: import_zod.z.literal("parseToJSON"),
778
+ params: fixStringSchema
779
+ }),
780
+ async (request, extra) => {
781
+ try {
782
+ const args = request.params;
783
+ const parsedMessage = this.parser?.parse(args.fixString);
784
+ if (!parsedMessage || parsedMessage.length === 0) {
785
+ return {
786
+ contents: [{ type: "text", text: "Error: Failed to parse FIX string" }],
787
+ isError: true
788
+ };
789
+ }
790
+ return {
791
+ contents: [
792
+ {
793
+ type: "text",
794
+ text: `${parsedMessage[0].toFIXJSON()}`
795
+ }
796
+ ]
797
+ };
798
+ } catch (error) {
799
+ return {
800
+ contents: [
801
+ {
802
+ type: "text",
803
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
804
+ }
805
+ ],
806
+ isError: true
807
+ };
808
+ }
809
+ }
810
+ );
811
+ this.server.setRequestHandler(
812
+ import_zod.z.object({
813
+ method: import_zod.z.literal("verifyOrder"),
814
+ params: orderSchema
815
+ }),
816
+ async (request, extra) => {
817
+ try {
818
+ const args = request.params;
819
+ this.verifiedOrders.set(args.clOrdID, {
820
+ clOrdID: args.clOrdID,
821
+ handlInst: args.handlInst,
822
+ quantity: Number.parseFloat(args.quantity),
823
+ price: Number.parseFloat(args.price),
824
+ ordType: args.ordType,
825
+ side: args.side,
826
+ symbol: args.symbol,
827
+ timeInForce: args.timeInForce
828
+ });
829
+ const ordTypeNames = {
830
+ "1": "Market",
831
+ "2": "Limit",
832
+ "3": "Stop",
833
+ "4": "StopLimit",
834
+ "5": "MarketOnClose",
835
+ "6": "WithOrWithout",
836
+ "7": "LimitOrBetter",
837
+ "8": "LimitWithOrWithout",
838
+ "9": "OnBasis",
839
+ A: "OnClose",
840
+ B: "LimitOnClose",
841
+ C: "ForexMarket",
842
+ D: "PreviouslyQuoted",
843
+ E: "PreviouslyIndicated",
844
+ F: "ForexLimit",
845
+ G: "ForexSwap",
846
+ H: "ForexPreviouslyQuoted",
847
+ I: "Funari",
848
+ J: "MarketIfTouched",
849
+ K: "MarketWithLeftOverAsLimit",
850
+ L: "PreviousFundValuationPoint",
851
+ M: "NextFundValuationPoint",
852
+ P: "Pegged",
853
+ Q: "CounterOrderSelection",
854
+ R: "StopOnBidOrOffer",
855
+ S: "StopLimitOnBidOrOffer"
856
+ };
857
+ const sideNames = {
858
+ "1": "Buy",
859
+ "2": "Sell",
860
+ "3": "BuyMinus",
861
+ "4": "SellPlus",
862
+ "5": "SellShort",
863
+ "6": "SellShortExempt",
864
+ "7": "Undisclosed",
865
+ "8": "Cross",
866
+ "9": "CrossShort",
867
+ A: "CrossShortExempt",
868
+ B: "AsDefined",
869
+ C: "Opposite",
870
+ D: "Subscribe",
871
+ E: "Redeem",
872
+ F: "Lend",
873
+ G: "Borrow",
874
+ H: "SellUndisclosed"
875
+ };
876
+ const timeInForceNames = {
877
+ "0": "Day",
878
+ "1": "GoodTillCancel",
879
+ "2": "AtTheOpening",
880
+ "3": "ImmediateOrCancel",
881
+ "4": "FillOrKill",
882
+ "5": "GoodTillCrossing",
883
+ "6": "GoodTillDate",
884
+ "7": "AtTheClose",
885
+ "8": "GoodThroughCrossing",
886
+ "9": "AtCrossing",
887
+ A: "GoodForTime",
888
+ B: "GoodForAuction",
889
+ C: "GoodForMonth"
890
+ };
891
+ const handlInstNames = {
892
+ "1": "AutomatedExecutionNoIntervention",
893
+ "2": "AutomatedExecutionInterventionOK",
894
+ "3": "ManualOrder"
895
+ };
896
+ return {
897
+ contents: [
898
+ {
899
+ type: "text",
900
+ text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
901
+
902
+ Parameters verified:
903
+ - ClOrdID: ${args.clOrdID}
904
+ - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
905
+ - Quantity: ${args.quantity}
906
+ - Price: ${args.price}
907
+ - OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
908
+ - Side: ${args.side} (${sideNames[args.side]})
909
+ - Symbol: ${args.symbol}
910
+ - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
911
+
912
+ To execute this order, call the executeOrder tool with these exact same parameters.`
913
+ }
914
+ ]
915
+ };
916
+ } catch (error) {
917
+ return {
918
+ contents: [
919
+ {
920
+ type: "text",
921
+ text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
922
+ }
923
+ ],
924
+ isError: true
925
+ };
926
+ }
927
+ }
928
+ );
929
+ this.server.setRequestHandler(
930
+ import_zod.z.object({
931
+ method: import_zod.z.literal("executeOrder"),
932
+ params: orderSchema
933
+ }),
934
+ async (request, extra) => {
935
+ try {
936
+ const args = request.params;
937
+ const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
938
+ if (!verifiedOrder) {
939
+ return {
940
+ contents: [
941
+ {
942
+ type: "text",
943
+ text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
944
+ }
945
+ ],
946
+ isError: true
947
+ };
948
+ }
949
+ if (verifiedOrder.handlInst !== args.handlInst || verifiedOrder.quantity !== Number.parseFloat(args.quantity) || verifiedOrder.price !== Number.parseFloat(args.price) || verifiedOrder.ordType !== args.ordType || verifiedOrder.side !== args.side || verifiedOrder.symbol !== args.symbol || verifiedOrder.timeInForce !== args.timeInForce) {
950
+ return {
951
+ contents: [
952
+ {
953
+ type: "text",
954
+ text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
955
+ }
956
+ ],
957
+ isError: true
958
+ };
959
+ }
960
+ const response = new Promise((resolve) => {
961
+ this.pendingRequests.set(args.clOrdID, resolve);
962
+ });
963
+ const order = this.parser?.createMessage(
964
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
965
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
966
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
967
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
968
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
969
+ new import_fixparser.Field(import_fixparser.Fields.ClOrdID, args.clOrdID),
970
+ new import_fixparser.Field(import_fixparser.Fields.Side, args.side),
971
+ new import_fixparser.Field(import_fixparser.Fields.Symbol, args.symbol),
972
+ new import_fixparser.Field(import_fixparser.Fields.OrderQty, Number.parseFloat(args.quantity)),
973
+ new import_fixparser.Field(import_fixparser.Fields.Price, Number.parseFloat(args.price)),
974
+ new import_fixparser.Field(import_fixparser.Fields.OrdType, args.ordType),
975
+ new import_fixparser.Field(import_fixparser.Fields.HandlInst, args.handlInst),
976
+ new import_fixparser.Field(import_fixparser.Fields.TimeInForce, args.timeInForce),
977
+ new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
978
+ );
979
+ if (!this.parser?.connected) {
980
+ return {
981
+ contents: [
982
+ {
983
+ type: "text",
984
+ text: "Error: Not connected. Ignoring message."
985
+ }
986
+ ],
987
+ isError: true
988
+ };
989
+ }
990
+ this.parser?.send(order);
991
+ const fixData = await response;
992
+ this.verifiedOrders.delete(args.clOrdID);
993
+ return {
994
+ contents: [
995
+ {
996
+ type: "text",
997
+ text: fixData.messageType === import_fixparser.Messages.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
998
+ }
999
+ ]
1000
+ };
1001
+ } catch (error) {
1002
+ return {
1003
+ contents: [
1004
+ {
1005
+ type: "text",
1006
+ text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
1007
+ }
1008
+ ],
1009
+ isError: true
1010
+ };
1011
+ }
1012
+ }
1013
+ );
1014
+ this.server.setRequestHandler(
1015
+ import_zod.z.object({
1016
+ method: import_zod.z.literal("marketDataRequest"),
1017
+ params: marketDataRequestSchema
1018
+ }),
1019
+ async (request, extra) => {
1020
+ try {
1021
+ const args = request.params;
1022
+ const response = new Promise((resolve) => {
1023
+ this.pendingRequests.set(args.mdReqID, resolve);
1024
+ });
1025
+ const messageFields = [
1026
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
1027
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
1028
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
1029
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
1030
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
1031
+ new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
1032
+ new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
1033
+ new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
1034
+ new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
1035
+ ];
1036
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
1037
+ args.symbols.forEach((symbol) => {
1038
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
1039
+ });
1040
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, args.mdEntryTypes.length));
1041
+ args.mdEntryTypes.forEach((entryType) => {
1042
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
1043
+ });
1044
+ const mdr = this.parser?.createMessage(...messageFields);
1045
+ if (!this.parser?.connected) {
1046
+ return {
1047
+ contents: [
1048
+ {
1049
+ type: "text",
1050
+ text: "Error: Not connected. Ignoring message."
1051
+ }
1052
+ ],
1053
+ isError: true
1054
+ };
1055
+ }
1056
+ this.parser?.send(mdr);
1057
+ const fixData = await response;
1058
+ return {
1059
+ contents: [
1060
+ {
1061
+ type: "text",
1062
+ text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`
1063
+ }
1064
+ ]
1065
+ };
1066
+ } catch (error) {
1067
+ return {
1068
+ contents: [
1069
+ {
1070
+ type: "text",
1071
+ text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
1072
+ }
1073
+ ],
1074
+ isError: true
1075
+ };
1076
+ }
1077
+ }
1078
+ );
1079
+ process.on("SIGINT", async () => {
1080
+ await this.server.close();
1081
+ process.exit(0);
1082
+ });
1083
+ }
1084
+ };
1085
+ // Annotate the CommonJS export names for ESM import in node:
1086
+ 0 && (module.exports = {
1087
+ MCPLocal
1088
+ });
1089
+ //# sourceMappingURL=MCPLocal.js.map