fixparser-plugin-mcp 9.1.7-eb1de32a → 9.1.7-edd9ee17

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.
@@ -35,9 +35,51 @@ __export(MCPLocal_exports, {
35
35
  module.exports = __toCommonJS(MCPLocal_exports);
36
36
  var import_server = require("@modelcontextprotocol/sdk/server/index.js");
37
37
  var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
38
- var import_fixparser3 = require("fixparser");
39
38
  var import_zod = require("zod");
40
39
 
40
+ // src/MCPBase.ts
41
+ var MCPBase = class {
42
+ /**
43
+ * Optional logger instance for diagnostics and output.
44
+ * @protected
45
+ */
46
+ logger;
47
+ /**
48
+ * FIXParser instance, set during plugin register().
49
+ * @protected
50
+ */
51
+ parser;
52
+ /**
53
+ * Called when server is setup and listening.
54
+ * @protected
55
+ */
56
+ onReady = void 0;
57
+ /**
58
+ * Map to store verified orders before execution
59
+ * @protected
60
+ */
61
+ verifiedOrders = /* @__PURE__ */ new Map();
62
+ /**
63
+ * Map to store pending market data requests
64
+ * @protected
65
+ */
66
+ pendingRequests = /* @__PURE__ */ new Map();
67
+ /**
68
+ * Map to store market data prices
69
+ * @protected
70
+ */
71
+ marketDataPrices = /* @__PURE__ */ new Map();
72
+ /**
73
+ * Maximum number of price history entries to keep per symbol
74
+ * @protected
75
+ */
76
+ MAX_PRICE_HISTORY = 1e5;
77
+ constructor({ logger, onReady }) {
78
+ this.logger = logger;
79
+ this.onReady = onReady;
80
+ }
81
+ };
82
+
41
83
  // src/schemas/schemas.ts
42
84
  var toolSchemas = {
43
85
  parse: {
@@ -121,7 +163,7 @@ var toolSchemas = {
121
163
  }
122
164
  },
123
165
  executeOrder: {
124
- description: "Executes a verified order. verifyOrder must be called before executeOrder. user has to explicitly allow executeOrder.",
166
+ description: "Executes a verified order. verifyOrder must be called before executeOrder.",
125
167
  schema: {
126
168
  type: "object",
127
169
  properties: {
@@ -238,12 +280,12 @@ var toolSchemas = {
238
280
  "X",
239
281
  "Y",
240
282
  "Z"
241
- ],
242
- 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"
243
- }
283
+ ]
284
+ },
285
+ 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"
244
286
  }
245
287
  },
246
- required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType", "mdEntryTypes"]
288
+ required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType"]
247
289
  }
248
290
  },
249
291
  getStockGraph: {
@@ -274,9 +316,63 @@ var import_quickchart_js = __toESM(require("quickchart-js"), 1);
274
316
  var createMarketDataRequestHandler = (parser, pendingRequests) => {
275
317
  return async (args) => {
276
318
  try {
319
+ parser.logger.log({
320
+ level: "info",
321
+ message: `Sending market data request for symbols: ${args.symbols.join(", ")}`
322
+ });
277
323
  const response = new Promise((resolve) => {
278
324
  pendingRequests.set(args.mdReqID, resolve);
325
+ parser.logger.log({
326
+ level: "info",
327
+ message: `Registered callback for market data request ID: ${args.mdReqID}`
328
+ });
279
329
  });
330
+ const entryTypes = args.mdEntryTypes || [
331
+ import_fixparser.MDEntryType.Bid,
332
+ import_fixparser.MDEntryType.Offer,
333
+ import_fixparser.MDEntryType.Trade,
334
+ import_fixparser.MDEntryType.IndexValue,
335
+ import_fixparser.MDEntryType.OpeningPrice,
336
+ import_fixparser.MDEntryType.ClosingPrice,
337
+ import_fixparser.MDEntryType.SettlementPrice,
338
+ import_fixparser.MDEntryType.TradingSessionHighPrice,
339
+ import_fixparser.MDEntryType.TradingSessionLowPrice,
340
+ import_fixparser.MDEntryType.VWAP,
341
+ import_fixparser.MDEntryType.Imbalance,
342
+ import_fixparser.MDEntryType.TradeVolume,
343
+ import_fixparser.MDEntryType.OpenInterest,
344
+ import_fixparser.MDEntryType.CompositeUnderlyingPrice,
345
+ import_fixparser.MDEntryType.SimulatedSellPrice,
346
+ import_fixparser.MDEntryType.SimulatedBuyPrice,
347
+ import_fixparser.MDEntryType.MarginRate,
348
+ import_fixparser.MDEntryType.MidPrice,
349
+ import_fixparser.MDEntryType.EmptyBook,
350
+ import_fixparser.MDEntryType.SettleHighPrice,
351
+ import_fixparser.MDEntryType.SettleLowPrice,
352
+ import_fixparser.MDEntryType.PriorSettlePrice,
353
+ import_fixparser.MDEntryType.SessionHighBid,
354
+ import_fixparser.MDEntryType.SessionLowOffer,
355
+ import_fixparser.MDEntryType.EarlyPrices,
356
+ import_fixparser.MDEntryType.AuctionClearingPrice,
357
+ import_fixparser.MDEntryType.SwapValueFactor,
358
+ import_fixparser.MDEntryType.DailyValueAdjustmentForLongPositions,
359
+ import_fixparser.MDEntryType.CumulativeValueAdjustmentForLongPositions,
360
+ import_fixparser.MDEntryType.DailyValueAdjustmentForShortPositions,
361
+ import_fixparser.MDEntryType.CumulativeValueAdjustmentForShortPositions,
362
+ import_fixparser.MDEntryType.FixingPrice,
363
+ import_fixparser.MDEntryType.CashRate,
364
+ import_fixparser.MDEntryType.RecoveryRate,
365
+ import_fixparser.MDEntryType.RecoveryRateForLong,
366
+ import_fixparser.MDEntryType.RecoveryRateForShort,
367
+ import_fixparser.MDEntryType.MarketBid,
368
+ import_fixparser.MDEntryType.MarketOffer,
369
+ import_fixparser.MDEntryType.ShortSaleMinPrice,
370
+ import_fixparser.MDEntryType.PreviousClosingPrice,
371
+ import_fixparser.MDEntryType.ThresholdLimitPriceBanding,
372
+ import_fixparser.MDEntryType.DailyFinancingValue,
373
+ import_fixparser.MDEntryType.AccruedFinancingValue,
374
+ import_fixparser.MDEntryType.TWAP
375
+ ];
280
376
  const messageFields = [
281
377
  new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
282
378
  new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
@@ -292,12 +388,16 @@ var createMarketDataRequestHandler = (parser, pendingRequests) => {
292
388
  args.symbols.forEach((symbol) => {
293
389
  messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
294
390
  });
295
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, args.mdEntryTypes.length));
296
- args.mdEntryTypes.forEach((entryType) => {
391
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, entryTypes.length));
392
+ entryTypes.forEach((entryType) => {
297
393
  messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
298
394
  });
299
395
  const mdr = parser.createMessage(...messageFields);
300
396
  if (!parser.connected) {
397
+ parser.logger.log({
398
+ level: "error",
399
+ message: "Not connected. Cannot send market data request."
400
+ });
301
401
  return {
302
402
  content: [
303
403
  {
@@ -309,8 +409,16 @@ var createMarketDataRequestHandler = (parser, pendingRequests) => {
309
409
  isError: true
310
410
  };
311
411
  }
412
+ parser.logger.log({
413
+ level: "info",
414
+ message: `Sending market data request message: ${JSON.stringify(mdr?.toFIXJSON())}`
415
+ });
312
416
  parser.send(mdr);
313
417
  const fixData = await response;
418
+ parser.logger.log({
419
+ level: "info",
420
+ message: `Received market data response for request ID: ${args.mdReqID}`
421
+ });
314
422
  return {
315
423
  content: [
316
424
  {
@@ -351,18 +459,73 @@ var createGetStockGraphHandler = (marketDataPrices) => {
351
459
  };
352
460
  }
353
461
  const chart = new import_quickchart_js.default();
354
- chart.setWidth(600);
355
- chart.setHeight(300);
462
+ chart.setWidth(1200);
463
+ chart.setHeight(600);
464
+ chart.setBackgroundColor("transparent");
356
465
  const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
357
- const data = priceHistory.map((point) => point.price);
358
- chart.setConfig({
466
+ const bidData = priceHistory.map((point) => point.bid);
467
+ const offerData = priceHistory.map((point) => point.offer);
468
+ const spreadData = priceHistory.map((point) => point.spread);
469
+ const volumeData = priceHistory.map((point) => point.volume);
470
+ const tradeData = priceHistory.map((point) => point.trade);
471
+ const vwapData = priceHistory.map((point) => point.vwap);
472
+ const twapData = priceHistory.map((point) => point.twap);
473
+ const config = {
359
474
  type: "line",
360
475
  data: {
361
476
  labels,
362
477
  datasets: [
363
478
  {
364
- label: symbol,
365
- data,
479
+ label: "Bid",
480
+ data: bidData,
481
+ borderColor: "#28a745",
482
+ backgroundColor: "rgba(40, 167, 69, 0.1)",
483
+ fill: false,
484
+ tension: 0.4
485
+ },
486
+ {
487
+ label: "Offer",
488
+ data: offerData,
489
+ borderColor: "#dc3545",
490
+ backgroundColor: "rgba(220, 53, 69, 0.1)",
491
+ fill: false,
492
+ tension: 0.4
493
+ },
494
+ {
495
+ label: "Spread",
496
+ data: spreadData,
497
+ borderColor: "#6c757d",
498
+ backgroundColor: "rgba(108, 117, 125, 0.1)",
499
+ fill: false,
500
+ tension: 0.4
501
+ },
502
+ {
503
+ label: "Trade",
504
+ data: tradeData,
505
+ borderColor: "#ffc107",
506
+ backgroundColor: "rgba(255, 193, 7, 0.1)",
507
+ fill: false,
508
+ tension: 0.4
509
+ },
510
+ {
511
+ label: "VWAP",
512
+ data: vwapData,
513
+ borderColor: "#17a2b8",
514
+ backgroundColor: "rgba(23, 162, 184, 0.1)",
515
+ fill: false,
516
+ tension: 0.4
517
+ },
518
+ {
519
+ label: "TWAP",
520
+ data: twapData,
521
+ borderColor: "#6610f2",
522
+ backgroundColor: "rgba(102, 16, 242, 0.1)",
523
+ fill: false,
524
+ tension: 0.4
525
+ },
526
+ {
527
+ label: "Volume",
528
+ data: volumeData,
366
529
  borderColor: "#007bff",
367
530
  backgroundColor: "rgba(0, 123, 255, 0.1)",
368
531
  fill: true,
@@ -371,46 +534,32 @@ var createGetStockGraphHandler = (marketDataPrices) => {
371
534
  ]
372
535
  },
373
536
  options: {
537
+ responsive: true,
374
538
  plugins: {
375
539
  title: {
376
540
  display: true,
377
- text: `${symbol} Price History`,
378
- font: {
379
- size: 16,
380
- weight: "bold"
381
- }
382
- },
383
- legend: {
384
- display: true
541
+ text: `${symbol} Market Data`
385
542
  }
386
543
  },
387
544
  scales: {
388
545
  y: {
389
- beginAtZero: false,
390
- grid: {
391
- color: "#e9ecef"
392
- }
393
- },
394
- x: {
395
- grid: {
396
- display: false
397
- }
546
+ beginAtZero: false
398
547
  }
399
548
  }
400
549
  }
401
- });
550
+ };
551
+ chart.setConfig(config);
402
552
  const imageBuffer = await chart.toBinary();
403
- const base64Image = imageBuffer.toString("base64");
553
+ const base64 = imageBuffer.toString("base64");
404
554
  return {
405
555
  content: [
406
556
  {
407
- type: "image",
408
- text: base64Image,
409
- source: {
410
- data: base64Image
411
- },
412
- uri: "getStockGraph",
413
- mimeType: "image/png"
557
+ type: "resource",
558
+ resource: {
559
+ uri: "resource://graph",
560
+ mimeType: "image/png",
561
+ blob: base64
562
+ }
414
563
  }
415
564
  ]
416
565
  };
@@ -419,7 +568,7 @@ var createGetStockGraphHandler = (marketDataPrices) => {
419
568
  content: [
420
569
  {
421
570
  type: "text",
422
- text: `Error: ${error instanceof Error ? error.message : "Failed to generate stock graph"}`,
571
+ text: `Error: ${error instanceof Error ? error.message : "Failed to generate graph"}`,
423
572
  uri: "getStockGraph"
424
573
  }
425
574
  ],
@@ -452,9 +601,53 @@ var createGetStockPriceHistoryHandler = (marketDataPrices) => {
452
601
  {
453
602
  symbol,
454
603
  count: priceHistory.length,
455
- prices: priceHistory.map((point) => ({
604
+ data: priceHistory.map((point) => ({
456
605
  timestamp: new Date(point.timestamp).toISOString(),
457
- price: point.price
606
+ bid: point.bid,
607
+ offer: point.offer,
608
+ spread: point.spread,
609
+ volume: point.volume,
610
+ trade: point.trade,
611
+ indexValue: point.indexValue,
612
+ openingPrice: point.openingPrice,
613
+ closingPrice: point.closingPrice,
614
+ settlementPrice: point.settlementPrice,
615
+ tradingSessionHighPrice: point.tradingSessionHighPrice,
616
+ tradingSessionLowPrice: point.tradingSessionLowPrice,
617
+ vwap: point.vwap,
618
+ imbalance: point.imbalance,
619
+ openInterest: point.openInterest,
620
+ compositeUnderlyingPrice: point.compositeUnderlyingPrice,
621
+ simulatedSellPrice: point.simulatedSellPrice,
622
+ simulatedBuyPrice: point.simulatedBuyPrice,
623
+ marginRate: point.marginRate,
624
+ midPrice: point.midPrice,
625
+ emptyBook: point.emptyBook,
626
+ settleHighPrice: point.settleHighPrice,
627
+ settleLowPrice: point.settleLowPrice,
628
+ priorSettlePrice: point.priorSettlePrice,
629
+ sessionHighBid: point.sessionHighBid,
630
+ sessionLowOffer: point.sessionLowOffer,
631
+ earlyPrices: point.earlyPrices,
632
+ auctionClearingPrice: point.auctionClearingPrice,
633
+ swapValueFactor: point.swapValueFactor,
634
+ dailyValueAdjustmentForLongPositions: point.dailyValueAdjustmentForLongPositions,
635
+ cumulativeValueAdjustmentForLongPositions: point.cumulativeValueAdjustmentForLongPositions,
636
+ dailyValueAdjustmentForShortPositions: point.dailyValueAdjustmentForShortPositions,
637
+ cumulativeValueAdjustmentForShortPositions: point.cumulativeValueAdjustmentForShortPositions,
638
+ fixingPrice: point.fixingPrice,
639
+ cashRate: point.cashRate,
640
+ recoveryRate: point.recoveryRate,
641
+ recoveryRateForLong: point.recoveryRateForLong,
642
+ recoveryRateForShort: point.recoveryRateForShort,
643
+ marketBid: point.marketBid,
644
+ marketOffer: point.marketOffer,
645
+ shortSaleMinPrice: point.shortSaleMinPrice,
646
+ previousClosingPrice: point.previousClosingPrice,
647
+ thresholdLimitPriceBanding: point.thresholdLimitPriceBanding,
648
+ dailyFinancingValue: point.dailyFinancingValue,
649
+ accruedFinancingValue: point.accruedFinancingValue,
650
+ twap: point.twap
458
651
  }))
459
652
  },
460
653
  null,
@@ -469,7 +662,7 @@ var createGetStockPriceHistoryHandler = (marketDataPrices) => {
469
662
  content: [
470
663
  {
471
664
  type: "text",
472
- text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
665
+ text: `Error: ${error instanceof Error ? error.message : "Failed to get price history"}`,
473
666
  uri: "getStockPriceHistory"
474
667
  }
475
668
  ],
@@ -577,7 +770,7 @@ Parameters verified:
577
770
  - Symbol: ${args.symbol}
578
771
  - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
579
772
 
580
- To execute this order, call the executeOrder tool with these exact same parameters.`,
773
+ To execute this order, call the executeOrder tool with these exact same parameters. Important: The user has to explicitly confirm before executeOrder is called!`,
581
774
  uri: "verifyOrder"
582
775
  }
583
776
  ]
@@ -776,9 +969,285 @@ var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPri
776
969
  getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
777
970
  });
778
971
 
972
+ // src/utils/messageHandler.ts
973
+ var import_fixparser3 = require("fixparser");
974
+ function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPriceHistory, onPriceUpdate) {
975
+ parser.logger.log({
976
+ level: "info",
977
+ message: `MCP Server received message: ${message.messageType}: ${message.description}`
978
+ });
979
+ const msgType = message.messageType;
980
+ if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
981
+ const symbol = message.getField(import_fixparser3.Fields.Symbol)?.value;
982
+ parser.logger.log({
983
+ level: "info",
984
+ message: `Processing market data for symbol: ${symbol}`
985
+ });
986
+ const fixJson = message.toFIXJSON();
987
+ const entries = fixJson.Body?.NoMDEntries || [];
988
+ parser.logger.log({
989
+ level: "info",
990
+ message: `Found ${entries.length} market data entries`
991
+ });
992
+ const data = {
993
+ timestamp: Date.now(),
994
+ bid: 0,
995
+ offer: 0,
996
+ spread: 0,
997
+ volume: 0,
998
+ trade: 0,
999
+ indexValue: 0,
1000
+ openingPrice: 0,
1001
+ closingPrice: 0,
1002
+ settlementPrice: 0,
1003
+ tradingSessionHighPrice: 0,
1004
+ tradingSessionLowPrice: 0,
1005
+ vwap: 0,
1006
+ imbalance: 0,
1007
+ openInterest: 0,
1008
+ compositeUnderlyingPrice: 0,
1009
+ simulatedSellPrice: 0,
1010
+ simulatedBuyPrice: 0,
1011
+ marginRate: 0,
1012
+ midPrice: 0,
1013
+ emptyBook: 0,
1014
+ settleHighPrice: 0,
1015
+ settleLowPrice: 0,
1016
+ priorSettlePrice: 0,
1017
+ sessionHighBid: 0,
1018
+ sessionLowOffer: 0,
1019
+ earlyPrices: 0,
1020
+ auctionClearingPrice: 0,
1021
+ swapValueFactor: 0,
1022
+ dailyValueAdjustmentForLongPositions: 0,
1023
+ cumulativeValueAdjustmentForLongPositions: 0,
1024
+ dailyValueAdjustmentForShortPositions: 0,
1025
+ cumulativeValueAdjustmentForShortPositions: 0,
1026
+ fixingPrice: 0,
1027
+ cashRate: 0,
1028
+ recoveryRate: 0,
1029
+ recoveryRateForLong: 0,
1030
+ recoveryRateForShort: 0,
1031
+ marketBid: 0,
1032
+ marketOffer: 0,
1033
+ shortSaleMinPrice: 0,
1034
+ previousClosingPrice: 0,
1035
+ thresholdLimitPriceBanding: 0,
1036
+ dailyFinancingValue: 0,
1037
+ accruedFinancingValue: 0,
1038
+ twap: 0
1039
+ };
1040
+ for (const entry of entries) {
1041
+ const entryType = entry.MDEntryType;
1042
+ const price = entry.MDEntryPx ? Number.parseFloat(entry.MDEntryPx) : 0;
1043
+ const size = entry.MDEntrySize ? Number.parseFloat(entry.MDEntrySize) : 0;
1044
+ if (entryType === import_fixparser3.MDEntryType.Bid || entryType === import_fixparser3.MDEntryType.Offer || entryType === import_fixparser3.MDEntryType.TradeVolume) {
1045
+ parser.logger.log({
1046
+ level: "info",
1047
+ message: `Market Data Entry - Type: ${entryType}, Price: ${price}, Size: ${size}`
1048
+ });
1049
+ }
1050
+ switch (entryType) {
1051
+ case import_fixparser3.MDEntryType.Bid:
1052
+ data.bid = price;
1053
+ break;
1054
+ case import_fixparser3.MDEntryType.Offer:
1055
+ data.offer = price;
1056
+ break;
1057
+ case import_fixparser3.MDEntryType.Trade:
1058
+ data.trade = price;
1059
+ break;
1060
+ case import_fixparser3.MDEntryType.IndexValue:
1061
+ data.indexValue = price;
1062
+ break;
1063
+ case import_fixparser3.MDEntryType.OpeningPrice:
1064
+ data.openingPrice = price;
1065
+ break;
1066
+ case import_fixparser3.MDEntryType.ClosingPrice:
1067
+ data.closingPrice = price;
1068
+ break;
1069
+ case import_fixparser3.MDEntryType.SettlementPrice:
1070
+ data.settlementPrice = price;
1071
+ break;
1072
+ case import_fixparser3.MDEntryType.TradingSessionHighPrice:
1073
+ data.tradingSessionHighPrice = price;
1074
+ break;
1075
+ case import_fixparser3.MDEntryType.TradingSessionLowPrice:
1076
+ data.tradingSessionLowPrice = price;
1077
+ break;
1078
+ case import_fixparser3.MDEntryType.VWAP:
1079
+ data.vwap = price;
1080
+ break;
1081
+ case import_fixparser3.MDEntryType.Imbalance:
1082
+ data.imbalance = size;
1083
+ break;
1084
+ case import_fixparser3.MDEntryType.TradeVolume:
1085
+ data.volume = size;
1086
+ break;
1087
+ case import_fixparser3.MDEntryType.OpenInterest:
1088
+ data.openInterest = size;
1089
+ break;
1090
+ case import_fixparser3.MDEntryType.CompositeUnderlyingPrice:
1091
+ data.compositeUnderlyingPrice = price;
1092
+ break;
1093
+ case import_fixparser3.MDEntryType.SimulatedSellPrice:
1094
+ data.simulatedSellPrice = price;
1095
+ break;
1096
+ case import_fixparser3.MDEntryType.SimulatedBuyPrice:
1097
+ data.simulatedBuyPrice = price;
1098
+ break;
1099
+ case import_fixparser3.MDEntryType.MarginRate:
1100
+ data.marginRate = price;
1101
+ break;
1102
+ case import_fixparser3.MDEntryType.MidPrice:
1103
+ data.midPrice = price;
1104
+ break;
1105
+ case import_fixparser3.MDEntryType.EmptyBook:
1106
+ data.emptyBook = 1;
1107
+ break;
1108
+ case import_fixparser3.MDEntryType.SettleHighPrice:
1109
+ data.settleHighPrice = price;
1110
+ break;
1111
+ case import_fixparser3.MDEntryType.SettleLowPrice:
1112
+ data.settleLowPrice = price;
1113
+ break;
1114
+ case import_fixparser3.MDEntryType.PriorSettlePrice:
1115
+ data.priorSettlePrice = price;
1116
+ break;
1117
+ case import_fixparser3.MDEntryType.SessionHighBid:
1118
+ data.sessionHighBid = price;
1119
+ break;
1120
+ case import_fixparser3.MDEntryType.SessionLowOffer:
1121
+ data.sessionLowOffer = price;
1122
+ break;
1123
+ case import_fixparser3.MDEntryType.EarlyPrices:
1124
+ data.earlyPrices = price;
1125
+ break;
1126
+ case import_fixparser3.MDEntryType.AuctionClearingPrice:
1127
+ data.auctionClearingPrice = price;
1128
+ break;
1129
+ case import_fixparser3.MDEntryType.SwapValueFactor:
1130
+ data.swapValueFactor = price;
1131
+ break;
1132
+ case import_fixparser3.MDEntryType.DailyValueAdjustmentForLongPositions:
1133
+ data.dailyValueAdjustmentForLongPositions = price;
1134
+ break;
1135
+ case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForLongPositions:
1136
+ data.cumulativeValueAdjustmentForLongPositions = price;
1137
+ break;
1138
+ case import_fixparser3.MDEntryType.DailyValueAdjustmentForShortPositions:
1139
+ data.dailyValueAdjustmentForShortPositions = price;
1140
+ break;
1141
+ case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForShortPositions:
1142
+ data.cumulativeValueAdjustmentForShortPositions = price;
1143
+ break;
1144
+ case import_fixparser3.MDEntryType.FixingPrice:
1145
+ data.fixingPrice = price;
1146
+ break;
1147
+ case import_fixparser3.MDEntryType.CashRate:
1148
+ data.cashRate = price;
1149
+ break;
1150
+ case import_fixparser3.MDEntryType.RecoveryRate:
1151
+ data.recoveryRate = price;
1152
+ break;
1153
+ case import_fixparser3.MDEntryType.RecoveryRateForLong:
1154
+ data.recoveryRateForLong = price;
1155
+ break;
1156
+ case import_fixparser3.MDEntryType.RecoveryRateForShort:
1157
+ data.recoveryRateForShort = price;
1158
+ break;
1159
+ case import_fixparser3.MDEntryType.MarketBid:
1160
+ data.marketBid = price;
1161
+ break;
1162
+ case import_fixparser3.MDEntryType.MarketOffer:
1163
+ data.marketOffer = price;
1164
+ break;
1165
+ case import_fixparser3.MDEntryType.ShortSaleMinPrice:
1166
+ data.shortSaleMinPrice = price;
1167
+ break;
1168
+ case import_fixparser3.MDEntryType.PreviousClosingPrice:
1169
+ data.previousClosingPrice = price;
1170
+ break;
1171
+ case import_fixparser3.MDEntryType.ThresholdLimitPriceBanding:
1172
+ data.thresholdLimitPriceBanding = price;
1173
+ break;
1174
+ case import_fixparser3.MDEntryType.DailyFinancingValue:
1175
+ data.dailyFinancingValue = price;
1176
+ break;
1177
+ case import_fixparser3.MDEntryType.AccruedFinancingValue:
1178
+ data.accruedFinancingValue = price;
1179
+ break;
1180
+ case import_fixparser3.MDEntryType.TWAP:
1181
+ data.twap = price;
1182
+ break;
1183
+ }
1184
+ }
1185
+ data.spread = data.offer - data.bid;
1186
+ if (!marketDataPrices.has(symbol)) {
1187
+ parser.logger.log({
1188
+ level: "info",
1189
+ message: `Creating new price history array for symbol: ${symbol}`
1190
+ });
1191
+ marketDataPrices.set(symbol, []);
1192
+ }
1193
+ const prices = marketDataPrices.get(symbol);
1194
+ prices.push(data);
1195
+ parser.logger.log({
1196
+ level: "info",
1197
+ message: `Updated price history for ${symbol}. Current size: ${prices.length}`
1198
+ });
1199
+ if (prices.length > maxPriceHistory) {
1200
+ prices.splice(0, prices.length - maxPriceHistory);
1201
+ parser.logger.log({
1202
+ level: "info",
1203
+ message: `Trimmed price history for ${symbol} to ${maxPriceHistory} entries`
1204
+ });
1205
+ }
1206
+ onPriceUpdate?.(symbol, data);
1207
+ const mdReqID = message.getField(import_fixparser3.Fields.MDReqID)?.value;
1208
+ if (mdReqID) {
1209
+ const callback = pendingRequests.get(mdReqID);
1210
+ if (callback) {
1211
+ callback(message);
1212
+ pendingRequests.delete(mdReqID);
1213
+ parser.logger.log({
1214
+ level: "info",
1215
+ message: `Resolved market data request for ID: ${mdReqID}`
1216
+ });
1217
+ }
1218
+ }
1219
+ } else if (msgType === import_fixparser3.Messages.ExecutionReport) {
1220
+ const reqId = message.getField(import_fixparser3.Fields.ClOrdID)?.value;
1221
+ const callback = pendingRequests.get(reqId);
1222
+ if (callback) {
1223
+ callback(message);
1224
+ pendingRequests.delete(reqId);
1225
+ }
1226
+ }
1227
+ }
1228
+
779
1229
  // src/MCPLocal.ts
780
- var MCPLocal = class {
781
- parser;
1230
+ var MCPLocal = class extends MCPBase {
1231
+ /**
1232
+ * Map to store verified orders before execution
1233
+ * @private
1234
+ */
1235
+ verifiedOrders = /* @__PURE__ */ new Map();
1236
+ /**
1237
+ * Map to store pending requests and their callbacks
1238
+ * @private
1239
+ */
1240
+ pendingRequests = /* @__PURE__ */ new Map();
1241
+ /**
1242
+ * Map to store market data prices for each symbol
1243
+ * @private
1244
+ */
1245
+ marketDataPrices = /* @__PURE__ */ new Map();
1246
+ /**
1247
+ * Maximum number of price history entries to keep per symbol
1248
+ * @private
1249
+ */
1250
+ MAX_PRICE_HISTORY = 1e5;
782
1251
  server = new import_server.Server(
783
1252
  {
784
1253
  name: "fixparser",
@@ -800,77 +1269,13 @@ var MCPLocal = class {
800
1269
  }
801
1270
  );
802
1271
  transport = new import_stdio.StdioServerTransport();
803
- onReady = void 0;
804
- pendingRequests = /* @__PURE__ */ new Map();
805
- verifiedOrders = /* @__PURE__ */ new Map();
806
- marketDataPrices = /* @__PURE__ */ new Map();
807
- MAX_PRICE_HISTORY = 1e5;
808
- // Maximum number of price points to store per symbol
809
1272
  constructor({ logger, onReady }) {
810
- if (onReady) this.onReady = onReady;
1273
+ super({ logger, onReady });
811
1274
  }
812
1275
  async register(parser) {
813
1276
  this.parser = parser;
814
1277
  this.parser.addOnMessageCallback((message) => {
815
- this.parser?.logger.log({
816
- level: "info",
817
- message: `MCP Server received message: ${message.messageType}: ${message.description}`
818
- });
819
- const msgType = message.messageType;
820
- if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.ExecutionReport || msgType === import_fixparser3.Messages.Reject || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
821
- this.parser?.logger.log({
822
- level: "info",
823
- message: `MCP Server handling message type: ${msgType}`
824
- });
825
- let id;
826
- if (msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
827
- const symbol = message.getField(import_fixparser3.Fields.Symbol);
828
- const price = message.getField(import_fixparser3.Fields.MDEntryPx);
829
- const timestamp = message.getField(import_fixparser3.Fields.MDEntryTime)?.value || Date.now();
830
- if (symbol?.value && price?.value) {
831
- const symbolStr = String(symbol.value);
832
- const priceNum = Number(price.value);
833
- const priceHistory = this.marketDataPrices.get(symbolStr) || [];
834
- priceHistory.push({
835
- timestamp: Number(timestamp),
836
- price: priceNum
837
- });
838
- if (priceHistory.length > this.MAX_PRICE_HISTORY) {
839
- priceHistory.shift();
840
- }
841
- this.marketDataPrices.set(symbolStr, priceHistory);
842
- this.parser?.logger.log({
843
- level: "info",
844
- message: `MCP Server added ${symbol}: ${priceNum}`
845
- });
846
- this.server.notification({
847
- method: "priceUpdate",
848
- params: {
849
- symbol: symbolStr,
850
- price: priceNum,
851
- timestamp: Number(timestamp)
852
- }
853
- });
854
- }
855
- }
856
- if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
857
- const mdReqID = message.getField(import_fixparser3.Fields.MDReqID);
858
- if (mdReqID) id = String(mdReqID.value);
859
- } else if (msgType === import_fixparser3.Messages.ExecutionReport) {
860
- const clOrdID = message.getField(import_fixparser3.Fields.ClOrdID);
861
- if (clOrdID) id = String(clOrdID.value);
862
- } else if (msgType === import_fixparser3.Messages.Reject) {
863
- const refSeqNum = message.getField(import_fixparser3.Fields.RefSeqNum);
864
- if (refSeqNum) id = String(refSeqNum.value);
865
- }
866
- if (id) {
867
- const callback = this.pendingRequests.get(id);
868
- if (callback) {
869
- callback(message);
870
- this.pendingRequests.delete(id);
871
- }
872
- }
873
- }
1278
+ handleMessage(message, this.parser, this.pendingRequests, this.marketDataPrices, this.MAX_PRICE_HISTORY);
874
1279
  });
875
1280
  this.addWorkflows();
876
1281
  await this.server.connect(this.transport);
@@ -885,18 +1290,15 @@ var MCPLocal = class {
885
1290
  if (!this.server) {
886
1291
  return;
887
1292
  }
888
- this.server.setRequestHandler(
889
- import_zod.z.object({ method: import_zod.z.literal("tools/list") }),
890
- async (request, extra) => {
891
- return {
892
- tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
893
- name,
894
- description,
895
- inputSchema: schema
896
- }))
897
- };
898
- }
899
- );
1293
+ this.server.setRequestHandler(import_zod.z.object({ method: import_zod.z.literal("tools/list") }), async () => {
1294
+ return {
1295
+ tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
1296
+ name,
1297
+ description,
1298
+ inputSchema: schema
1299
+ }))
1300
+ };
1301
+ });
900
1302
  this.server.setRequestHandler(
901
1303
  import_zod.z.object({
902
1304
  method: import_zod.z.literal("tools/call"),
@@ -908,7 +1310,7 @@ var MCPLocal = class {
908
1310
  }).optional()
909
1311
  })
910
1312
  }),
911
- async (request, extra) => {
1313
+ async (request) => {
912
1314
  const { name, arguments: args } = request.params;
913
1315
  const toolHandlers = createToolHandlers(
914
1316
  this.parser,