fixparser-plugin-mcp 9.1.7-8fdb1e41 → 9.1.7-945d3edd

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,1343 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ MCPLocal: () => MCPLocal,
34
+ MCPRemote: () => MCPRemote
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/MCPLocal.ts
39
+ var import_server = require("@modelcontextprotocol/sdk/server/index.js");
40
+ var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
41
+ var import_zod = require("zod");
42
+
43
+ // src/MCPBase.ts
44
+ var MCPBase = class {
45
+ /**
46
+ * Optional logger instance for diagnostics and output.
47
+ * @protected
48
+ */
49
+ logger;
50
+ /**
51
+ * FIXParser instance, set during plugin register().
52
+ * @protected
53
+ */
54
+ parser;
55
+ /**
56
+ * Called when server is setup and listening.
57
+ * @protected
58
+ */
59
+ onReady = void 0;
60
+ /**
61
+ * Map to store verified orders before execution
62
+ * @protected
63
+ */
64
+ verifiedOrders = /* @__PURE__ */ new Map();
65
+ /**
66
+ * Map to store pending market data requests
67
+ * @protected
68
+ */
69
+ pendingRequests = /* @__PURE__ */ new Map();
70
+ /**
71
+ * Map to store market data prices
72
+ * @protected
73
+ */
74
+ marketDataPrices = /* @__PURE__ */ new Map();
75
+ /**
76
+ * Maximum number of price history entries to keep per symbol
77
+ * @protected
78
+ */
79
+ MAX_PRICE_HISTORY = 1e5;
80
+ constructor({ logger, onReady }) {
81
+ this.logger = logger;
82
+ this.onReady = onReady;
83
+ }
84
+ };
85
+
86
+ // src/schemas/schemas.ts
87
+ var toolSchemas = {
88
+ parse: {
89
+ description: "Parses a FIX message and describes it in plain language",
90
+ schema: {
91
+ type: "object",
92
+ properties: {
93
+ fixString: { type: "string" }
94
+ },
95
+ required: ["fixString"]
96
+ }
97
+ },
98
+ parseToJSON: {
99
+ description: "Parses a FIX message into JSON",
100
+ schema: {
101
+ type: "object",
102
+ properties: {
103
+ fixString: { type: "string" }
104
+ },
105
+ required: ["fixString"]
106
+ }
107
+ },
108
+ verifyOrder: {
109
+ description: "Verifies order parameters before execution. verifyOrder must be called before executeOrder.",
110
+ schema: {
111
+ type: "object",
112
+ properties: {
113
+ clOrdID: { type: "string" },
114
+ handlInst: {
115
+ type: "string",
116
+ enum: ["1", "2", "3"],
117
+ description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
118
+ },
119
+ quantity: { type: "string" },
120
+ price: { type: "string" },
121
+ ordType: {
122
+ type: "string",
123
+ enum: [
124
+ "1",
125
+ "2",
126
+ "3",
127
+ "4",
128
+ "5",
129
+ "6",
130
+ "7",
131
+ "8",
132
+ "9",
133
+ "A",
134
+ "B",
135
+ "C",
136
+ "D",
137
+ "E",
138
+ "F",
139
+ "G",
140
+ "H",
141
+ "I",
142
+ "J",
143
+ "K",
144
+ "L",
145
+ "M",
146
+ "P",
147
+ "Q",
148
+ "R",
149
+ "S"
150
+ ],
151
+ description: "Order Type: 1=Market, 2=Limit, 3=Stop, 4=StopLimit, 5=MarketOnClose, 6=WithOrWithout, 7=LimitOrBetter, 8=LimitWithOrWithout, 9=OnBasis, A=OnClose, B=LimitOnClose, C=ForexMarket, D=PreviouslyQuoted, E=PreviouslyIndicated, F=ForexLimit, G=ForexSwap, H=ForexPreviouslyQuoted, I=Funari, J=MarketIfTouched, K=MarketWithLeftOverAsLimit, L=PreviousFundValuationPoint, M=NextFundValuationPoint, P=Pegged, Q=CounterOrderSelection, R=StopOnBidOrOffer, S=StopLimitOnBidOrOffer"
152
+ },
153
+ side: {
154
+ type: "string",
155
+ enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
156
+ description: "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"
157
+ },
158
+ symbol: { type: "string" },
159
+ timeInForce: {
160
+ type: "string",
161
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
162
+ description: "Time In Force: 0=Day, 1=GoodTillCancel, 2=AtTheOpening, 3=ImmediateOrCancel, 4=FillOrKill, 5=GoodTillCrossing, 6=GoodTillDate, 7=AtTheClose, 8=GoodThroughCrossing, 9=AtCrossing, A=GoodForTime, B=GoodForAuction, C=GoodForMonth"
163
+ }
164
+ },
165
+ required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
166
+ }
167
+ },
168
+ executeOrder: {
169
+ description: "Executes a verified order. verifyOrder must be called before executeOrder.",
170
+ schema: {
171
+ type: "object",
172
+ properties: {
173
+ clOrdID: { type: "string" },
174
+ handlInst: {
175
+ type: "string",
176
+ enum: ["1", "2", "3"],
177
+ description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
178
+ },
179
+ quantity: { type: "string" },
180
+ price: { type: "string" },
181
+ ordType: {
182
+ type: "string",
183
+ enum: [
184
+ "1",
185
+ "2",
186
+ "3",
187
+ "4",
188
+ "5",
189
+ "6",
190
+ "7",
191
+ "8",
192
+ "9",
193
+ "A",
194
+ "B",
195
+ "C",
196
+ "D",
197
+ "E",
198
+ "F",
199
+ "G",
200
+ "H",
201
+ "I",
202
+ "J",
203
+ "K",
204
+ "L",
205
+ "M",
206
+ "P",
207
+ "Q",
208
+ "R",
209
+ "S"
210
+ ],
211
+ description: "Order Type: 1=Market, 2=Limit, 3=Stop, 4=StopLimit, 5=MarketOnClose, 6=WithOrWithout, 7=LimitOrBetter, 8=LimitWithOrWithout, 9=OnBasis, A=OnClose, B=LimitOnClose, C=ForexMarket, D=PreviouslyQuoted, E=PreviouslyIndicated, F=ForexLimit, G=ForexSwap, H=ForexPreviouslyQuoted, I=Funari, J=MarketIfTouched, K=MarketWithLeftOverAsLimit, L=PreviousFundValuationPoint, M=NextFundValuationPoint, P=Pegged, Q=CounterOrderSelection, R=StopOnBidOrOffer, S=StopLimitOnBidOrOffer"
212
+ },
213
+ side: {
214
+ type: "string",
215
+ enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
216
+ description: "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"
217
+ },
218
+ symbol: { type: "string" },
219
+ timeInForce: {
220
+ type: "string",
221
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
222
+ description: "Time In Force: 0=Day, 1=GoodTillCancel, 2=AtTheOpening, 3=ImmediateOrCancel, 4=FillOrKill, 5=GoodTillCrossing, 6=GoodTillDate, 7=AtTheClose, 8=GoodThroughCrossing, 9=AtCrossing, A=GoodForTime, B=GoodForAuction, C=GoodForMonth"
223
+ }
224
+ },
225
+ required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
226
+ }
227
+ },
228
+ marketDataRequest: {
229
+ description: "Requests market data for specified symbols",
230
+ schema: {
231
+ type: "object",
232
+ properties: {
233
+ mdUpdateType: {
234
+ type: "string",
235
+ enum: ["0", "1"],
236
+ description: "Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"
237
+ },
238
+ symbols: { type: "array", items: { type: "string" } },
239
+ mdReqID: { type: "string" },
240
+ subscriptionRequestType: {
241
+ type: "string",
242
+ enum: ["0", "1", "2"],
243
+ description: "Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"
244
+ },
245
+ mdEntryTypes: {
246
+ type: "array",
247
+ items: {
248
+ type: "string",
249
+ enum: [
250
+ "0",
251
+ "1",
252
+ "2",
253
+ "3",
254
+ "4",
255
+ "5",
256
+ "6",
257
+ "7",
258
+ "8",
259
+ "9",
260
+ "A",
261
+ "B",
262
+ "C",
263
+ "D",
264
+ "E",
265
+ "F",
266
+ "G",
267
+ "H",
268
+ "I",
269
+ "J",
270
+ "K",
271
+ "L",
272
+ "M",
273
+ "N",
274
+ "O",
275
+ "P",
276
+ "Q",
277
+ "R",
278
+ "S",
279
+ "T",
280
+ "U",
281
+ "V",
282
+ "W",
283
+ "X",
284
+ "Y",
285
+ "Z"
286
+ ]
287
+ },
288
+ description: "Market Data Entry Types: 0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price, 5=Closing Price, 6=Settlement Price, 7=High Price, 8=Low Price, 9=Trade Volume, A=Open Interest, B=Simulated Sell Price, C=Simulated Buy Price, D=Empty Book, E=Session High Bid, F=Session Low Offer, G=Fixing Price, H=Electronic Volume, I=Threshold Limits and Price Band Variation, J=Clearing Price, K=Open Interest Change, L=Last Trade Price, M=Last Trade Volume, N=Last Trade Time, O=Last Trade Tick, P=Last Trade Exchange, Q=Last Trade ID, R=Last Trade Side, S=Last Trade Price Change, T=Last Trade Price Change Percent, U=Last Trade Price Change Basis Points, V=Last Trade Price Change Points, W=Last Trade Price Change Ticks, X=Last Trade Price Change Ticks Percent, Y=Last Trade Price Change Ticks Basis Points, Z=Last Trade Price Change Ticks Points"
289
+ }
290
+ },
291
+ required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType"]
292
+ }
293
+ },
294
+ getStockGraph: {
295
+ description: "Generates a price chart for a given symbol",
296
+ schema: {
297
+ type: "object",
298
+ properties: {
299
+ symbol: { type: "string" }
300
+ },
301
+ required: ["symbol"]
302
+ }
303
+ },
304
+ getStockPriceHistory: {
305
+ description: "Returns price history for a given symbol",
306
+ schema: {
307
+ type: "object",
308
+ properties: {
309
+ symbol: { type: "string" }
310
+ },
311
+ required: ["symbol"]
312
+ }
313
+ }
314
+ };
315
+
316
+ // src/tools/marketData.ts
317
+ var import_fixparser = require("fixparser");
318
+ var import_quickchart_js = __toESM(require("quickchart-js"), 1);
319
+ var createMarketDataRequestHandler = (parser, pendingRequests) => {
320
+ return async (args) => {
321
+ try {
322
+ const entryTypes = args.mdEntryTypes || [import_fixparser.MDEntryType.Bid, import_fixparser.MDEntryType.Offer, import_fixparser.MDEntryType.TradeVolume];
323
+ const messageFields = [
324
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
325
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
326
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
327
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
328
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
329
+ new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
330
+ new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
331
+ new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
332
+ new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
333
+ ];
334
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
335
+ args.symbols.forEach((symbol) => {
336
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
337
+ });
338
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, entryTypes.length));
339
+ entryTypes.forEach((entryType) => {
340
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
341
+ });
342
+ const mdr = parser.createMessage(...messageFields);
343
+ if (!parser.connected) {
344
+ return {
345
+ content: [
346
+ {
347
+ type: "text",
348
+ text: "Error: Not connected. Ignoring message.",
349
+ uri: "marketDataRequest"
350
+ }
351
+ ],
352
+ isError: true
353
+ };
354
+ }
355
+ parser.send(mdr);
356
+ return {
357
+ content: [
358
+ {
359
+ type: "text",
360
+ text: "Subscription to Market Data successful",
361
+ uri: "marketDataRequest"
362
+ }
363
+ ]
364
+ };
365
+ } catch (error) {
366
+ return {
367
+ content: [
368
+ {
369
+ type: "text",
370
+ text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
371
+ uri: "marketDataRequest"
372
+ }
373
+ ],
374
+ isError: true
375
+ };
376
+ }
377
+ };
378
+ };
379
+ var createGetStockGraphHandler = (marketDataPrices) => {
380
+ return async (args) => {
381
+ try {
382
+ const symbol = args.symbol;
383
+ const priceHistory = marketDataPrices.get(symbol) || [];
384
+ if (priceHistory.length === 0) {
385
+ return {
386
+ content: [
387
+ {
388
+ type: "text",
389
+ text: `No price data available for ${symbol}`,
390
+ uri: "getStockGraph"
391
+ }
392
+ ]
393
+ };
394
+ }
395
+ const chart = new import_quickchart_js.default();
396
+ chart.setWidth(1200);
397
+ chart.setHeight(600);
398
+ chart.setBackgroundColor("transparent");
399
+ const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
400
+ const bidData = priceHistory.map((point) => point.bid);
401
+ const offerData = priceHistory.map((point) => point.offer);
402
+ const spreadData = priceHistory.map((point) => point.spread);
403
+ const volumeData = priceHistory.map((point) => point.volume);
404
+ const config = {
405
+ type: "line",
406
+ data: {
407
+ labels,
408
+ datasets: [
409
+ {
410
+ label: "Bid",
411
+ data: bidData,
412
+ borderColor: "#28a745",
413
+ backgroundColor: "rgba(40, 167, 69, 0.1)",
414
+ fill: false,
415
+ tension: 0.4
416
+ },
417
+ {
418
+ label: "Offer",
419
+ data: offerData,
420
+ borderColor: "#dc3545",
421
+ backgroundColor: "rgba(220, 53, 69, 0.1)",
422
+ fill: false,
423
+ tension: 0.4
424
+ },
425
+ {
426
+ label: "Spread",
427
+ data: spreadData,
428
+ borderColor: "#6c757d",
429
+ backgroundColor: "rgba(108, 117, 125, 0.1)",
430
+ fill: false,
431
+ tension: 0.4
432
+ },
433
+ {
434
+ label: "Volume",
435
+ data: volumeData,
436
+ borderColor: "#007bff",
437
+ backgroundColor: "rgba(0, 123, 255, 0.1)",
438
+ fill: true,
439
+ tension: 0.4
440
+ }
441
+ ]
442
+ },
443
+ options: {
444
+ responsive: true,
445
+ plugins: {
446
+ title: {
447
+ display: true,
448
+ text: `${symbol} Market Data`
449
+ }
450
+ },
451
+ scales: {
452
+ y: {
453
+ beginAtZero: false
454
+ }
455
+ }
456
+ }
457
+ };
458
+ chart.setConfig(config);
459
+ const imageBuffer = await chart.toBinary();
460
+ const base64 = imageBuffer.toString("base64");
461
+ return {
462
+ content: [
463
+ {
464
+ type: "resource",
465
+ resource: {
466
+ uri: "resource://graph",
467
+ mimeType: "image/png",
468
+ blob: base64
469
+ }
470
+ }
471
+ ]
472
+ };
473
+ } catch (error) {
474
+ return {
475
+ content: [
476
+ {
477
+ type: "text",
478
+ text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
479
+ uri: "getStockGraph"
480
+ }
481
+ ],
482
+ isError: true
483
+ };
484
+ }
485
+ };
486
+ };
487
+ var createGetStockPriceHistoryHandler = (marketDataPrices) => {
488
+ return async (args) => {
489
+ try {
490
+ const symbol = args.symbol;
491
+ const priceHistory = marketDataPrices.get(symbol) || [];
492
+ if (priceHistory.length === 0) {
493
+ return {
494
+ content: [
495
+ {
496
+ type: "text",
497
+ text: `No price data available for ${symbol}`,
498
+ uri: "getStockPriceHistory"
499
+ }
500
+ ]
501
+ };
502
+ }
503
+ return {
504
+ content: [
505
+ {
506
+ type: "text",
507
+ text: JSON.stringify(
508
+ {
509
+ symbol,
510
+ count: priceHistory.length,
511
+ data: priceHistory.map((point) => ({
512
+ timestamp: new Date(point.timestamp).toISOString(),
513
+ bid: point.bid,
514
+ offer: point.offer,
515
+ spread: point.spread,
516
+ volume: point.volume
517
+ }))
518
+ },
519
+ null,
520
+ 2
521
+ ),
522
+ uri: "getStockPriceHistory"
523
+ }
524
+ ]
525
+ };
526
+ } catch (error) {
527
+ return {
528
+ content: [
529
+ {
530
+ type: "text",
531
+ text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
532
+ uri: "getStockPriceHistory"
533
+ }
534
+ ],
535
+ isError: true
536
+ };
537
+ }
538
+ };
539
+ };
540
+
541
+ // src/tools/order.ts
542
+ var import_fixparser2 = require("fixparser");
543
+ var ordTypeNames = {
544
+ "1": "Market",
545
+ "2": "Limit",
546
+ "3": "Stop",
547
+ "4": "StopLimit",
548
+ "5": "MarketOnClose",
549
+ "6": "WithOrWithout",
550
+ "7": "LimitOrBetter",
551
+ "8": "LimitWithOrWithout",
552
+ "9": "OnBasis",
553
+ A: "OnClose",
554
+ B: "LimitOnClose",
555
+ C: "ForexMarket",
556
+ D: "PreviouslyQuoted",
557
+ E: "PreviouslyIndicated",
558
+ F: "ForexLimit",
559
+ G: "ForexSwap",
560
+ H: "ForexPreviouslyQuoted",
561
+ I: "Funari",
562
+ J: "MarketIfTouched",
563
+ K: "MarketWithLeftOverAsLimit",
564
+ L: "PreviousFundValuationPoint",
565
+ M: "NextFundValuationPoint",
566
+ P: "Pegged",
567
+ Q: "CounterOrderSelection",
568
+ R: "StopOnBidOrOffer",
569
+ S: "StopLimitOnBidOrOffer"
570
+ };
571
+ var sideNames = {
572
+ "1": "Buy",
573
+ "2": "Sell",
574
+ "3": "BuyMinus",
575
+ "4": "SellPlus",
576
+ "5": "SellShort",
577
+ "6": "SellShortExempt",
578
+ "7": "Undisclosed",
579
+ "8": "Cross",
580
+ "9": "CrossShort",
581
+ A: "CrossShortExempt",
582
+ B: "AsDefined",
583
+ C: "Opposite",
584
+ D: "Subscribe",
585
+ E: "Redeem",
586
+ F: "Lend",
587
+ G: "Borrow",
588
+ H: "SellUndisclosed"
589
+ };
590
+ var timeInForceNames = {
591
+ "0": "Day",
592
+ "1": "GoodTillCancel",
593
+ "2": "AtTheOpening",
594
+ "3": "ImmediateOrCancel",
595
+ "4": "FillOrKill",
596
+ "5": "GoodTillCrossing",
597
+ "6": "GoodTillDate",
598
+ "7": "AtTheClose",
599
+ "8": "GoodThroughCrossing",
600
+ "9": "AtCrossing",
601
+ A: "GoodForTime",
602
+ B: "GoodForAuction",
603
+ C: "GoodForMonth"
604
+ };
605
+ var handlInstNames = {
606
+ "1": "AutomatedExecutionNoIntervention",
607
+ "2": "AutomatedExecutionInterventionOK",
608
+ "3": "ManualOrder"
609
+ };
610
+ var createVerifyOrderHandler = (parser, verifiedOrders) => {
611
+ return async (args) => {
612
+ try {
613
+ verifiedOrders.set(args.clOrdID, {
614
+ clOrdID: args.clOrdID,
615
+ handlInst: args.handlInst,
616
+ quantity: Number.parseFloat(String(args.quantity)),
617
+ price: Number.parseFloat(String(args.price)),
618
+ ordType: args.ordType,
619
+ side: args.side,
620
+ symbol: args.symbol,
621
+ timeInForce: args.timeInForce
622
+ });
623
+ return {
624
+ content: [
625
+ {
626
+ type: "text",
627
+ text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
628
+
629
+ Parameters verified:
630
+ - ClOrdID: ${args.clOrdID}
631
+ - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
632
+ - Quantity: ${args.quantity}
633
+ - Price: ${args.price}
634
+ - OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
635
+ - Side: ${args.side} (${sideNames[args.side]})
636
+ - Symbol: ${args.symbol}
637
+ - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
638
+
639
+ To execute this order, call the executeOrder tool with these exact same parameters.`,
640
+ uri: "verifyOrder"
641
+ }
642
+ ]
643
+ };
644
+ } catch (error) {
645
+ return {
646
+ content: [
647
+ {
648
+ type: "text",
649
+ text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
650
+ uri: "verifyOrder"
651
+ }
652
+ ],
653
+ isError: true
654
+ };
655
+ }
656
+ };
657
+ };
658
+ var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
659
+ return async (args) => {
660
+ try {
661
+ const verifiedOrder = verifiedOrders.get(args.clOrdID);
662
+ if (!verifiedOrder) {
663
+ return {
664
+ content: [
665
+ {
666
+ type: "text",
667
+ text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
668
+ uri: "executeOrder"
669
+ }
670
+ ],
671
+ isError: true
672
+ };
673
+ }
674
+ if (verifiedOrder.handlInst !== args.handlInst || verifiedOrder.quantity !== Number.parseFloat(String(args.quantity)) || verifiedOrder.price !== Number.parseFloat(String(args.price)) || verifiedOrder.ordType !== args.ordType || verifiedOrder.side !== args.side || verifiedOrder.symbol !== args.symbol || verifiedOrder.timeInForce !== args.timeInForce) {
675
+ return {
676
+ content: [
677
+ {
678
+ type: "text",
679
+ text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
680
+ uri: "executeOrder"
681
+ }
682
+ ],
683
+ isError: true
684
+ };
685
+ }
686
+ const response = new Promise((resolve) => {
687
+ pendingRequests.set(args.clOrdID, resolve);
688
+ });
689
+ const order = parser.createMessage(
690
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
691
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
692
+ new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
693
+ new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
694
+ new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
695
+ new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
696
+ new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
697
+ new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
698
+ new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
699
+ new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
700
+ new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
701
+ new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
702
+ new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
703
+ new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
704
+ );
705
+ if (!parser.connected) {
706
+ return {
707
+ content: [
708
+ {
709
+ type: "text",
710
+ text: "Error: Not connected. Ignoring message.",
711
+ uri: "executeOrder"
712
+ }
713
+ ],
714
+ isError: true
715
+ };
716
+ }
717
+ parser.send(order);
718
+ const fixData = await response;
719
+ verifiedOrders.delete(args.clOrdID);
720
+ return {
721
+ content: [
722
+ {
723
+ type: "text",
724
+ text: fixData.messageType === import_fixparser2.Messages.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`,
725
+ uri: "executeOrder"
726
+ }
727
+ ]
728
+ };
729
+ } catch (error) {
730
+ return {
731
+ content: [
732
+ {
733
+ type: "text",
734
+ text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
735
+ uri: "executeOrder"
736
+ }
737
+ ],
738
+ isError: true
739
+ };
740
+ }
741
+ };
742
+ };
743
+
744
+ // src/tools/parse.ts
745
+ var createParseHandler = (parser) => {
746
+ return async (args) => {
747
+ try {
748
+ const parsedMessage = parser.parse(args.fixString);
749
+ if (!parsedMessage || parsedMessage.length === 0) {
750
+ return {
751
+ content: [
752
+ {
753
+ type: "text",
754
+ text: "Error: Failed to parse FIX string",
755
+ uri: "parse"
756
+ }
757
+ ],
758
+ isError: true
759
+ };
760
+ }
761
+ return {
762
+ content: [
763
+ {
764
+ type: "text",
765
+ text: `${parsedMessage[0].description}
766
+ ${parsedMessage[0].messageTypeDescription}`,
767
+ uri: "parse"
768
+ }
769
+ ]
770
+ };
771
+ } catch (error) {
772
+ return {
773
+ content: [
774
+ {
775
+ type: "text",
776
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
777
+ uri: "parse"
778
+ }
779
+ ],
780
+ isError: true
781
+ };
782
+ }
783
+ };
784
+ };
785
+
786
+ // src/tools/parseToJSON.ts
787
+ var createParseToJSONHandler = (parser) => {
788
+ return async (args) => {
789
+ try {
790
+ const parsedMessage = parser.parse(args.fixString);
791
+ if (!parsedMessage || parsedMessage.length === 0) {
792
+ return {
793
+ content: [
794
+ {
795
+ type: "text",
796
+ text: "Error: Failed to parse FIX string",
797
+ uri: "parseToJSON"
798
+ }
799
+ ],
800
+ isError: true
801
+ };
802
+ }
803
+ return {
804
+ content: [
805
+ {
806
+ type: "text",
807
+ text: `${parsedMessage[0].toFIXJSON()}`,
808
+ uri: "parseToJSON"
809
+ }
810
+ ]
811
+ };
812
+ } catch (error) {
813
+ return {
814
+ content: [
815
+ {
816
+ type: "text",
817
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
818
+ uri: "parseToJSON"
819
+ }
820
+ ],
821
+ isError: true
822
+ };
823
+ }
824
+ };
825
+ };
826
+
827
+ // src/tools/index.ts
828
+ var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
829
+ parse: createParseHandler(parser),
830
+ parseToJSON: createParseToJSONHandler(parser),
831
+ verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
832
+ executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
833
+ marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
834
+ getStockGraph: createGetStockGraphHandler(marketDataPrices),
835
+ getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
836
+ });
837
+
838
+ // src/utils/messageHandler.ts
839
+ var import_fixparser3 = require("fixparser");
840
+ function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPriceHistory, onPriceUpdate) {
841
+ parser.logger.log({
842
+ level: "info",
843
+ message: `MCP Server received message: ${message.messageType}: ${message.description}`
844
+ });
845
+ const msgType = message.messageType;
846
+ if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
847
+ const symbol = message.getField(import_fixparser3.Fields.Symbol)?.value;
848
+ const entries = message.getField(import_fixparser3.Fields.NoMDEntries)?.value;
849
+ let bid = 0;
850
+ let offer = 0;
851
+ let volume = 0;
852
+ const entryTypes = message.getFields(import_fixparser3.Fields.MDEntryType);
853
+ const entryPrices = message.getFields(import_fixparser3.Fields.MDEntryPx);
854
+ const entrySizes = message.getFields(import_fixparser3.Fields.MDEntrySize);
855
+ if (entryTypes && entryPrices && entrySizes) {
856
+ for (let i = 0; i < entries; i++) {
857
+ const entryType = entryTypes[i]?.value;
858
+ const entryPrice = Number.parseFloat(entryPrices[i]?.value);
859
+ const entrySize = Number.parseFloat(entrySizes[i]?.value);
860
+ if (entryType === import_fixparser3.MDEntryType.Bid) {
861
+ bid = entryPrice;
862
+ } else if (entryType === import_fixparser3.MDEntryType.Offer) {
863
+ offer = entryPrice;
864
+ }
865
+ volume += entrySize;
866
+ }
867
+ }
868
+ const spread = offer - bid;
869
+ const timestamp = Date.now();
870
+ const data = {
871
+ timestamp,
872
+ bid,
873
+ offer,
874
+ spread,
875
+ volume
876
+ };
877
+ if (!marketDataPrices.has(symbol)) {
878
+ marketDataPrices.set(symbol, []);
879
+ }
880
+ const prices = marketDataPrices.get(symbol);
881
+ prices.push(data);
882
+ if (prices.length > maxPriceHistory) {
883
+ prices.splice(0, prices.length - maxPriceHistory);
884
+ }
885
+ onPriceUpdate?.(symbol, data);
886
+ } else if (msgType === import_fixparser3.Messages.ExecutionReport) {
887
+ const reqId = message.getField(import_fixparser3.Fields.ClOrdID)?.value;
888
+ const callback = pendingRequests.get(reqId);
889
+ if (callback) {
890
+ callback(message);
891
+ pendingRequests.delete(reqId);
892
+ }
893
+ }
894
+ }
895
+
896
+ // src/MCPLocal.ts
897
+ var MCPLocal = class extends MCPBase {
898
+ /**
899
+ * Map to store verified orders before execution
900
+ * @private
901
+ */
902
+ verifiedOrders = /* @__PURE__ */ new Map();
903
+ /**
904
+ * Map to store pending requests and their callbacks
905
+ * @private
906
+ */
907
+ pendingRequests = /* @__PURE__ */ new Map();
908
+ /**
909
+ * Map to store market data prices for each symbol
910
+ * @private
911
+ */
912
+ marketDataPrices = /* @__PURE__ */ new Map();
913
+ /**
914
+ * Maximum number of price points to store per symbol
915
+ * @private
916
+ */
917
+ MAX_PRICE_HISTORY = 1e5;
918
+ server = new import_server.Server(
919
+ {
920
+ name: "fixparser",
921
+ version: "1.0.0"
922
+ },
923
+ {
924
+ capabilities: {
925
+ tools: Object.entries(toolSchemas).reduce(
926
+ (acc, [name, { description, schema }]) => {
927
+ acc[name] = {
928
+ description,
929
+ parameters: schema
930
+ };
931
+ return acc;
932
+ },
933
+ {}
934
+ )
935
+ }
936
+ }
937
+ );
938
+ transport = new import_stdio.StdioServerTransport();
939
+ constructor({ logger, onReady }) {
940
+ super({ logger, onReady });
941
+ }
942
+ async register(parser) {
943
+ this.parser = parser;
944
+ this.parser.addOnMessageCallback((message) => {
945
+ handleMessage(message, this.parser, this.pendingRequests, this.marketDataPrices, this.MAX_PRICE_HISTORY);
946
+ });
947
+ this.addWorkflows();
948
+ await this.server.connect(this.transport);
949
+ if (this.onReady) {
950
+ this.onReady();
951
+ }
952
+ }
953
+ addWorkflows() {
954
+ if (!this.parser) {
955
+ return;
956
+ }
957
+ if (!this.server) {
958
+ return;
959
+ }
960
+ this.server.setRequestHandler(import_zod.z.object({ method: import_zod.z.literal("tools/list") }), async () => {
961
+ return {
962
+ tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
963
+ name,
964
+ description,
965
+ inputSchema: schema
966
+ }))
967
+ };
968
+ });
969
+ this.server.setRequestHandler(
970
+ import_zod.z.object({
971
+ method: import_zod.z.literal("tools/call"),
972
+ params: import_zod.z.object({
973
+ name: import_zod.z.string(),
974
+ arguments: import_zod.z.any(),
975
+ _meta: import_zod.z.object({
976
+ progressToken: import_zod.z.number()
977
+ }).optional()
978
+ })
979
+ }),
980
+ async (request) => {
981
+ const { name, arguments: args } = request.params;
982
+ const toolHandlers = createToolHandlers(
983
+ this.parser,
984
+ this.verifiedOrders,
985
+ this.pendingRequests,
986
+ this.marketDataPrices
987
+ );
988
+ const handler = toolHandlers[name];
989
+ if (!handler) {
990
+ return {
991
+ content: [
992
+ {
993
+ type: "text",
994
+ text: `Tool not found: ${name}`,
995
+ uri: name
996
+ }
997
+ ],
998
+ isError: true
999
+ };
1000
+ }
1001
+ const result = await handler(args);
1002
+ return {
1003
+ content: result.content,
1004
+ isError: result.isError
1005
+ };
1006
+ }
1007
+ );
1008
+ process.on("SIGINT", async () => {
1009
+ await this.server.close();
1010
+ process.exit(0);
1011
+ });
1012
+ }
1013
+ };
1014
+
1015
+ // src/MCPRemote.ts
1016
+ var import_node_crypto = require("node:crypto");
1017
+ var import_node_http = require("node:http");
1018
+ var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
1019
+ var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
1020
+ var import_types = require("@modelcontextprotocol/sdk/types.js");
1021
+ var import_zod2 = require("zod");
1022
+ var transports = {};
1023
+ function jsonSchemaToZod(schema) {
1024
+ if (schema.type === "object") {
1025
+ const shape = {};
1026
+ for (const [key, prop] of Object.entries(schema.properties || {})) {
1027
+ const propSchema = prop;
1028
+ if (propSchema.type === "string") {
1029
+ if (propSchema.enum) {
1030
+ shape[key] = import_zod2.z.enum(propSchema.enum);
1031
+ } else {
1032
+ shape[key] = import_zod2.z.string();
1033
+ }
1034
+ } else if (propSchema.type === "number") {
1035
+ shape[key] = import_zod2.z.number();
1036
+ } else if (propSchema.type === "boolean") {
1037
+ shape[key] = import_zod2.z.boolean();
1038
+ } else if (propSchema.type === "array") {
1039
+ if (propSchema.items.type === "string") {
1040
+ shape[key] = import_zod2.z.array(import_zod2.z.string());
1041
+ } else if (propSchema.items.type === "number") {
1042
+ shape[key] = import_zod2.z.array(import_zod2.z.number());
1043
+ } else if (propSchema.items.type === "boolean") {
1044
+ shape[key] = import_zod2.z.array(import_zod2.z.boolean());
1045
+ } else {
1046
+ shape[key] = import_zod2.z.array(import_zod2.z.any());
1047
+ }
1048
+ } else {
1049
+ shape[key] = import_zod2.z.any();
1050
+ }
1051
+ }
1052
+ return shape;
1053
+ }
1054
+ return {};
1055
+ }
1056
+ var MCPRemote = class extends MCPBase {
1057
+ /**
1058
+ * Port number the server will listen on.
1059
+ * @private
1060
+ */
1061
+ port;
1062
+ /**
1063
+ * Node.js HTTP server instance created internally.
1064
+ * @private
1065
+ */
1066
+ httpServer;
1067
+ /**
1068
+ * MCP server instance handling MCP protocol logic.
1069
+ * @private
1070
+ */
1071
+ mcpServer;
1072
+ /**
1073
+ * Optional name of the plugin/server instance.
1074
+ * @private
1075
+ */
1076
+ serverName;
1077
+ /**
1078
+ * Optional version string of the plugin/server.
1079
+ * @private
1080
+ */
1081
+ serverVersion;
1082
+ /**
1083
+ * Map to store verified orders before execution
1084
+ * @private
1085
+ */
1086
+ verifiedOrders = /* @__PURE__ */ new Map();
1087
+ /**
1088
+ * Map to store pending requests and their callbacks
1089
+ * @private
1090
+ */
1091
+ pendingRequests = /* @__PURE__ */ new Map();
1092
+ /**
1093
+ * Map to store market data prices for each symbol
1094
+ * @private
1095
+ */
1096
+ marketDataPrices = /* @__PURE__ */ new Map();
1097
+ /**
1098
+ * Maximum number of price points to store per symbol
1099
+ * @private
1100
+ */
1101
+ MAX_PRICE_HISTORY = 1e5;
1102
+ constructor({ port, logger, onReady }) {
1103
+ super({ logger, onReady });
1104
+ this.port = port;
1105
+ }
1106
+ async register(parser) {
1107
+ this.parser = parser;
1108
+ this.logger = parser.logger;
1109
+ this.logger?.log({
1110
+ level: "info",
1111
+ message: `FIXParser (MCP): -- Plugin registered. Creating MCP server on port ${this.port}...`
1112
+ });
1113
+ this.parser.addOnMessageCallback((message) => {
1114
+ if (this.parser) {
1115
+ handleMessage(
1116
+ message,
1117
+ this.parser,
1118
+ this.pendingRequests,
1119
+ this.marketDataPrices,
1120
+ this.MAX_PRICE_HISTORY
1121
+ );
1122
+ }
1123
+ });
1124
+ this.httpServer = (0, import_node_http.createServer)(async (req, res) => {
1125
+ this.logger?.log({
1126
+ level: "info",
1127
+ message: `Incoming request: ${req.method} ${req.url}`
1128
+ });
1129
+ if (!req.url || !req.method) {
1130
+ this.logger?.log({
1131
+ level: "error",
1132
+ message: "Invalid request: missing URL or method"
1133
+ });
1134
+ res.writeHead(400);
1135
+ res.end("Bad Request");
1136
+ return;
1137
+ }
1138
+ if (req.url === "/mcp") {
1139
+ const sessionId = req.headers["mcp-session-id"];
1140
+ this.logger?.log({
1141
+ level: "info",
1142
+ message: `MCP request received. Session ID: ${sessionId || "none"}, headers: ${req.headers}`
1143
+ });
1144
+ if (req.method === "POST") {
1145
+ const bodyChunks = [];
1146
+ req.on("data", (chunk) => {
1147
+ bodyChunks.push(chunk);
1148
+ });
1149
+ req.on("end", async () => {
1150
+ let parsed;
1151
+ const body = Buffer.concat(bodyChunks).toString();
1152
+ try {
1153
+ parsed = JSON.parse(body);
1154
+ this.logger?.log({
1155
+ level: "info",
1156
+ message: `Parsed request body: ${JSON.stringify(parsed)}`
1157
+ });
1158
+ } catch (err) {
1159
+ this.logger?.log({
1160
+ level: "error",
1161
+ message: `Failed to parse JSON body: ${err}`
1162
+ });
1163
+ res.writeHead(400);
1164
+ res.end(JSON.stringify({ error: "Invalid JSON" }));
1165
+ return;
1166
+ }
1167
+ let transport;
1168
+ if (sessionId && transports[sessionId]) {
1169
+ this.logger?.log({
1170
+ level: "info",
1171
+ message: `Using existing transport for session: ${sessionId}`
1172
+ });
1173
+ transport = transports[sessionId];
1174
+ } else if (!sessionId && req.method === "POST" && (0, import_types.isInitializeRequest)(parsed)) {
1175
+ this.logger?.log({
1176
+ level: "info",
1177
+ message: "Creating new transport for initialization request"
1178
+ });
1179
+ transport = new import_streamableHttp.StreamableHTTPServerTransport({
1180
+ sessionIdGenerator: () => (0, import_node_crypto.randomUUID)(),
1181
+ onsessioninitialized: (sessionId2) => {
1182
+ this.logger?.log({
1183
+ level: "info",
1184
+ message: `New session initialized: ${sessionId2}`
1185
+ });
1186
+ transports[sessionId2] = transport;
1187
+ }
1188
+ });
1189
+ transport.onclose = () => {
1190
+ if (transport.sessionId) {
1191
+ this.logger?.log({
1192
+ level: "info",
1193
+ message: `Session closed: ${transport.sessionId}`
1194
+ });
1195
+ delete transports[transport.sessionId];
1196
+ }
1197
+ };
1198
+ this.mcpServer = new import_mcp.McpServer({
1199
+ name: this.serverName || "FIXParser",
1200
+ version: this.serverVersion || "1.0.0"
1201
+ });
1202
+ this.setupTools();
1203
+ await this.mcpServer.connect(transport);
1204
+ } else {
1205
+ this.logger?.log({
1206
+ level: "error",
1207
+ message: "Invalid request: No valid session ID provided"
1208
+ });
1209
+ res.writeHead(400, { "Content-Type": "application/json" });
1210
+ res.end(
1211
+ JSON.stringify({
1212
+ jsonrpc: "2.0",
1213
+ error: {
1214
+ code: -32e3,
1215
+ message: "Bad Request: No valid session ID provided"
1216
+ },
1217
+ id: null
1218
+ })
1219
+ );
1220
+ return;
1221
+ }
1222
+ try {
1223
+ await transport.handleRequest(req, res, parsed);
1224
+ this.logger?.log({
1225
+ level: "info",
1226
+ message: "Request handled successfully"
1227
+ });
1228
+ } catch (error) {
1229
+ this.logger?.log({
1230
+ level: "error",
1231
+ message: `Error handling request: ${error}`
1232
+ });
1233
+ throw error;
1234
+ }
1235
+ });
1236
+ } else if (req.method === "GET" || req.method === "DELETE") {
1237
+ if (!sessionId || !transports[sessionId]) {
1238
+ this.logger?.log({
1239
+ level: "error",
1240
+ message: `Invalid session ID for ${req.method} request: ${sessionId}`
1241
+ });
1242
+ res.writeHead(400);
1243
+ res.end("Invalid or missing session ID");
1244
+ return;
1245
+ }
1246
+ const transport = transports[sessionId];
1247
+ try {
1248
+ await transport.handleRequest(req, res);
1249
+ this.logger?.log({
1250
+ level: "info",
1251
+ message: `${req.method} request handled successfully for session: ${sessionId}`
1252
+ });
1253
+ } catch (error) {
1254
+ this.logger?.log({
1255
+ level: "error",
1256
+ message: `Error handling ${req.method} request: ${error}`
1257
+ });
1258
+ throw error;
1259
+ }
1260
+ } else {
1261
+ this.logger?.log({
1262
+ level: "error",
1263
+ message: `Method not allowed: ${req.method}`
1264
+ });
1265
+ res.writeHead(405);
1266
+ res.end("Method Not Allowed");
1267
+ }
1268
+ } else {
1269
+ this.logger?.log({
1270
+ level: "error",
1271
+ message: `Not found: ${req.url}`
1272
+ });
1273
+ res.writeHead(404);
1274
+ res.end("Not Found");
1275
+ }
1276
+ });
1277
+ this.httpServer.listen(this.port, () => {
1278
+ this.logger?.log({
1279
+ level: "info",
1280
+ message: `FIXParser (MCP): -- Server listening on http://localhost:${this.port}...`
1281
+ });
1282
+ });
1283
+ if (this.onReady) {
1284
+ this.onReady();
1285
+ }
1286
+ }
1287
+ setupTools() {
1288
+ if (!this.parser) {
1289
+ this.logger?.log({
1290
+ level: "error",
1291
+ message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of tools..."
1292
+ });
1293
+ return;
1294
+ }
1295
+ if (!this.mcpServer) {
1296
+ this.logger?.log({
1297
+ level: "error",
1298
+ message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of tools..."
1299
+ });
1300
+ return;
1301
+ }
1302
+ const toolHandlers = createToolHandlers(
1303
+ this.parser,
1304
+ this.verifiedOrders,
1305
+ this.pendingRequests,
1306
+ this.marketDataPrices
1307
+ );
1308
+ Object.entries(toolSchemas).forEach(([name, { description, schema }]) => {
1309
+ this.mcpServer?.registerTool(
1310
+ name,
1311
+ {
1312
+ description,
1313
+ inputSchema: jsonSchemaToZod(schema)
1314
+ },
1315
+ async (args) => {
1316
+ const handler = toolHandlers[name];
1317
+ if (!handler) {
1318
+ return {
1319
+ content: [
1320
+ {
1321
+ type: "text",
1322
+ text: `Tool not found: ${name}`
1323
+ }
1324
+ ],
1325
+ isError: true
1326
+ };
1327
+ }
1328
+ const result = await handler(args);
1329
+ return {
1330
+ content: result.content,
1331
+ isError: result.isError
1332
+ };
1333
+ }
1334
+ );
1335
+ });
1336
+ }
1337
+ };
1338
+ // Annotate the CommonJS export names for ESM import in node:
1339
+ 0 && (module.exports = {
1340
+ MCPLocal,
1341
+ MCPRemote
1342
+ });
1343
+ //# sourceMappingURL=index.js.map