fixparser-plugin-mcp 9.1.7-9d6b5ca3 → 9.1.7-9eab5b4d

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.
@@ -1,51 +1,9 @@
1
1
  // src/MCPLocal.ts
2
2
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { Fields as Fields3, MDEntryType as MDEntryType2, Messages as Messages3 } from "fixparser";
4
5
  import { z } from "zod";
5
6
 
6
- // src/MCPBase.ts
7
- var MCPBase = class {
8
- /**
9
- * Optional logger instance for diagnostics and output.
10
- * @protected
11
- */
12
- logger;
13
- /**
14
- * FIXParser instance, set during plugin register().
15
- * @protected
16
- */
17
- parser;
18
- /**
19
- * Called when server is setup and listening.
20
- * @protected
21
- */
22
- onReady = void 0;
23
- /**
24
- * Map to store verified orders before execution
25
- * @protected
26
- */
27
- verifiedOrders = /* @__PURE__ */ new Map();
28
- /**
29
- * Map to store pending market data requests
30
- * @protected
31
- */
32
- pendingRequests = /* @__PURE__ */ new Map();
33
- /**
34
- * Map to store market data prices
35
- * @protected
36
- */
37
- marketDataPrices = /* @__PURE__ */ new Map();
38
- /**
39
- * Maximum number of price history entries to keep per symbol
40
- * @protected
41
- */
42
- MAX_PRICE_HISTORY = 1e5;
43
- constructor({ logger, onReady }) {
44
- this.logger = logger;
45
- this.onReady = onReady;
46
- }
47
- };
48
-
49
7
  // src/schemas/schemas.ts
50
8
  var toolSchemas = {
51
9
  parse: {
@@ -129,7 +87,7 @@ var toolSchemas = {
129
87
  }
130
88
  },
131
89
  executeOrder: {
132
- description: "Executes a verified order. verifyOrder must be called before executeOrder.",
90
+ description: "Executes a verified order. verifyOrder must be called before executeOrder. user has to explicitly allow executeOrder.",
133
91
  schema: {
134
92
  type: "object",
135
93
  properties: {
@@ -282,63 +240,10 @@ import QuickChart from "quickchart-js";
282
240
  var createMarketDataRequestHandler = (parser, pendingRequests) => {
283
241
  return async (args) => {
284
242
  try {
285
- parser.logger.log({
286
- level: "info",
287
- message: `Sending market data request for symbols: ${args.symbols.join(", ")}`
288
- });
289
243
  const response = new Promise((resolve) => {
290
244
  pendingRequests.set(args.mdReqID, resolve);
291
- parser.logger.log({
292
- level: "info",
293
- message: `Registered callback for market data request ID: ${args.mdReqID}`
294
- });
295
245
  });
296
- const entryTypes = args.mdEntryTypes || [
297
- MDEntryType.Bid,
298
- MDEntryType.Offer,
299
- MDEntryType.Trade,
300
- MDEntryType.IndexValue,
301
- MDEntryType.OpeningPrice,
302
- MDEntryType.ClosingPrice,
303
- MDEntryType.SettlementPrice,
304
- MDEntryType.TradingSessionHighPrice,
305
- MDEntryType.TradingSessionLowPrice,
306
- MDEntryType.VWAP,
307
- MDEntryType.Imbalance,
308
- MDEntryType.TradeVolume,
309
- MDEntryType.OpenInterest,
310
- MDEntryType.CompositeUnderlyingPrice,
311
- MDEntryType.SimulatedSellPrice,
312
- MDEntryType.SimulatedBuyPrice,
313
- MDEntryType.MarginRate,
314
- MDEntryType.MidPrice,
315
- MDEntryType.EmptyBook,
316
- MDEntryType.SettleHighPrice,
317
- MDEntryType.SettleLowPrice,
318
- MDEntryType.PriorSettlePrice,
319
- MDEntryType.SessionHighBid,
320
- MDEntryType.SessionLowOffer,
321
- MDEntryType.EarlyPrices,
322
- MDEntryType.AuctionClearingPrice,
323
- MDEntryType.SwapValueFactor,
324
- MDEntryType.DailyValueAdjustmentForLongPositions,
325
- MDEntryType.CumulativeValueAdjustmentForLongPositions,
326
- MDEntryType.DailyValueAdjustmentForShortPositions,
327
- MDEntryType.CumulativeValueAdjustmentForShortPositions,
328
- MDEntryType.FixingPrice,
329
- MDEntryType.CashRate,
330
- MDEntryType.RecoveryRate,
331
- MDEntryType.RecoveryRateForLong,
332
- MDEntryType.RecoveryRateForShort,
333
- MDEntryType.MarketBid,
334
- MDEntryType.MarketOffer,
335
- MDEntryType.ShortSaleMinPrice,
336
- MDEntryType.PreviousClosingPrice,
337
- MDEntryType.ThresholdLimitPriceBanding,
338
- MDEntryType.DailyFinancingValue,
339
- MDEntryType.AccruedFinancingValue,
340
- MDEntryType.TWAP
341
- ];
246
+ const entryTypes = args.mdEntryTypes || [MDEntryType.Bid, MDEntryType.Offer, MDEntryType.TradeVolume];
342
247
  const messageFields = [
343
248
  new Field(Fields.MsgType, Messages.MarketDataRequest),
344
249
  new Field(Fields.SenderCompID, parser.sender),
@@ -360,10 +265,6 @@ var createMarketDataRequestHandler = (parser, pendingRequests) => {
360
265
  });
361
266
  const mdr = parser.createMessage(...messageFields);
362
267
  if (!parser.connected) {
363
- parser.logger.log({
364
- level: "error",
365
- message: "Not connected. Cannot send market data request."
366
- });
367
268
  return {
368
269
  content: [
369
270
  {
@@ -375,16 +276,8 @@ var createMarketDataRequestHandler = (parser, pendingRequests) => {
375
276
  isError: true
376
277
  };
377
278
  }
378
- parser.logger.log({
379
- level: "info",
380
- message: `Sending market data request message: ${JSON.stringify(mdr?.toFIXJSON())}`
381
- });
382
279
  parser.send(mdr);
383
280
  const fixData = await response;
384
- parser.logger.log({
385
- level: "info",
386
- message: `Received market data response for request ID: ${args.mdReqID}`
387
- });
388
281
  return {
389
282
  content: [
390
283
  {
@@ -425,17 +318,13 @@ var createGetStockGraphHandler = (marketDataPrices) => {
425
318
  };
426
319
  }
427
320
  const chart = new QuickChart();
428
- chart.setWidth(1200);
429
- chart.setHeight(600);
430
- chart.setBackgroundColor("transparent");
321
+ chart.setWidth(600);
322
+ chart.setHeight(300);
431
323
  const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
432
324
  const bidData = priceHistory.map((point) => point.bid);
433
325
  const offerData = priceHistory.map((point) => point.offer);
434
326
  const spreadData = priceHistory.map((point) => point.spread);
435
327
  const volumeData = priceHistory.map((point) => point.volume);
436
- const tradeData = priceHistory.map((point) => point.trade);
437
- const vwapData = priceHistory.map((point) => point.vwap);
438
- const twapData = priceHistory.map((point) => point.twap);
439
328
  const config = {
440
329
  type: "line",
441
330
  data: {
@@ -465,30 +354,6 @@ var createGetStockGraphHandler = (marketDataPrices) => {
465
354
  fill: false,
466
355
  tension: 0.4
467
356
  },
468
- {
469
- label: "Trade",
470
- data: tradeData,
471
- borderColor: "#ffc107",
472
- backgroundColor: "rgba(255, 193, 7, 0.1)",
473
- fill: false,
474
- tension: 0.4
475
- },
476
- {
477
- label: "VWAP",
478
- data: vwapData,
479
- borderColor: "#17a2b8",
480
- backgroundColor: "rgba(23, 162, 184, 0.1)",
481
- fill: false,
482
- tension: 0.4
483
- },
484
- {
485
- label: "TWAP",
486
- data: twapData,
487
- borderColor: "#6610f2",
488
- backgroundColor: "rgba(102, 16, 242, 0.1)",
489
- fill: false,
490
- tension: 0.4
491
- },
492
357
  {
493
358
  label: "Volume",
494
359
  data: volumeData,
@@ -516,16 +381,16 @@ var createGetStockGraphHandler = (marketDataPrices) => {
516
381
  };
517
382
  chart.setConfig(config);
518
383
  const imageBuffer = await chart.toBinary();
519
- const base64 = imageBuffer.toString("base64");
384
+ const base64Image = imageBuffer.toString("base64");
520
385
  return {
521
386
  content: [
522
387
  {
523
- type: "resource",
524
- resource: {
525
- uri: "resource://graph",
526
- mimeType: "image/png",
527
- blob: base64
528
- }
388
+ type: "image",
389
+ image: {
390
+ source: `data:image/png;base64,${base64Image}`
391
+ },
392
+ uri: "getStockGraph",
393
+ mimeType: "image/png"
529
394
  }
530
395
  ]
531
396
  };
@@ -534,7 +399,7 @@ var createGetStockGraphHandler = (marketDataPrices) => {
534
399
  content: [
535
400
  {
536
401
  type: "text",
537
- text: `Error: ${error instanceof Error ? error.message : "Failed to generate graph"}`,
402
+ text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
538
403
  uri: "getStockGraph"
539
404
  }
540
405
  ],
@@ -572,48 +437,7 @@ var createGetStockPriceHistoryHandler = (marketDataPrices) => {
572
437
  bid: point.bid,
573
438
  offer: point.offer,
574
439
  spread: point.spread,
575
- volume: point.volume,
576
- trade: point.trade,
577
- indexValue: point.indexValue,
578
- openingPrice: point.openingPrice,
579
- closingPrice: point.closingPrice,
580
- settlementPrice: point.settlementPrice,
581
- tradingSessionHighPrice: point.tradingSessionHighPrice,
582
- tradingSessionLowPrice: point.tradingSessionLowPrice,
583
- vwap: point.vwap,
584
- imbalance: point.imbalance,
585
- openInterest: point.openInterest,
586
- compositeUnderlyingPrice: point.compositeUnderlyingPrice,
587
- simulatedSellPrice: point.simulatedSellPrice,
588
- simulatedBuyPrice: point.simulatedBuyPrice,
589
- marginRate: point.marginRate,
590
- midPrice: point.midPrice,
591
- emptyBook: point.emptyBook,
592
- settleHighPrice: point.settleHighPrice,
593
- settleLowPrice: point.settleLowPrice,
594
- priorSettlePrice: point.priorSettlePrice,
595
- sessionHighBid: point.sessionHighBid,
596
- sessionLowOffer: point.sessionLowOffer,
597
- earlyPrices: point.earlyPrices,
598
- auctionClearingPrice: point.auctionClearingPrice,
599
- swapValueFactor: point.swapValueFactor,
600
- dailyValueAdjustmentForLongPositions: point.dailyValueAdjustmentForLongPositions,
601
- cumulativeValueAdjustmentForLongPositions: point.cumulativeValueAdjustmentForLongPositions,
602
- dailyValueAdjustmentForShortPositions: point.dailyValueAdjustmentForShortPositions,
603
- cumulativeValueAdjustmentForShortPositions: point.cumulativeValueAdjustmentForShortPositions,
604
- fixingPrice: point.fixingPrice,
605
- cashRate: point.cashRate,
606
- recoveryRate: point.recoveryRate,
607
- recoveryRateForLong: point.recoveryRateForLong,
608
- recoveryRateForShort: point.recoveryRateForShort,
609
- marketBid: point.marketBid,
610
- marketOffer: point.marketOffer,
611
- shortSaleMinPrice: point.shortSaleMinPrice,
612
- previousClosingPrice: point.previousClosingPrice,
613
- thresholdLimitPriceBanding: point.thresholdLimitPriceBanding,
614
- dailyFinancingValue: point.dailyFinancingValue,
615
- accruedFinancingValue: point.accruedFinancingValue,
616
- twap: point.twap
440
+ volume: point.volume
617
441
  }))
618
442
  },
619
443
  null,
@@ -628,7 +452,7 @@ var createGetStockPriceHistoryHandler = (marketDataPrices) => {
628
452
  content: [
629
453
  {
630
454
  type: "text",
631
- text: `Error: ${error instanceof Error ? error.message : "Failed to get price history"}`,
455
+ text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
632
456
  uri: "getStockPriceHistory"
633
457
  }
634
458
  ],
@@ -736,7 +560,7 @@ Parameters verified:
736
560
  - Symbol: ${args.symbol}
737
561
  - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
738
562
 
739
- To execute this order, call the executeOrder tool with these exact same parameters. Important: The user has to explicitly confirm before executeOrder is called!`,
563
+ To execute this order, call the executeOrder tool with these exact same parameters.`,
740
564
  uri: "verifyOrder"
741
565
  }
742
566
  ]
@@ -935,255 +759,9 @@ var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPri
935
759
  getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
936
760
  });
937
761
 
938
- // src/utils/messageHandler.ts
939
- import { Fields as Fields3, MDEntryType as MDEntryType2, Messages as Messages3 } from "fixparser";
940
- function getEnumValue(enumObj, name) {
941
- return enumObj[name] || name;
942
- }
943
- function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPriceHistory, onPriceUpdate) {
944
- const msgType = message.messageType;
945
- if (msgType === Messages3.MarketDataSnapshotFullRefresh || msgType === Messages3.MarketDataIncrementalRefresh) {
946
- const symbol = message.getField(Fields3.Symbol)?.value;
947
- const fixJson = message.toFIXJSON();
948
- const entries = fixJson.Body?.NoMDEntries || [];
949
- const data = {
950
- timestamp: Date.now(),
951
- bid: 0,
952
- offer: 0,
953
- spread: 0,
954
- volume: 0,
955
- trade: 0,
956
- indexValue: 0,
957
- openingPrice: 0,
958
- closingPrice: 0,
959
- settlementPrice: 0,
960
- tradingSessionHighPrice: 0,
961
- tradingSessionLowPrice: 0,
962
- vwap: 0,
963
- imbalance: 0,
964
- openInterest: 0,
965
- compositeUnderlyingPrice: 0,
966
- simulatedSellPrice: 0,
967
- simulatedBuyPrice: 0,
968
- marginRate: 0,
969
- midPrice: 0,
970
- emptyBook: 0,
971
- settleHighPrice: 0,
972
- settleLowPrice: 0,
973
- priorSettlePrice: 0,
974
- sessionHighBid: 0,
975
- sessionLowOffer: 0,
976
- earlyPrices: 0,
977
- auctionClearingPrice: 0,
978
- swapValueFactor: 0,
979
- dailyValueAdjustmentForLongPositions: 0,
980
- cumulativeValueAdjustmentForLongPositions: 0,
981
- dailyValueAdjustmentForShortPositions: 0,
982
- cumulativeValueAdjustmentForShortPositions: 0,
983
- fixingPrice: 0,
984
- cashRate: 0,
985
- recoveryRate: 0,
986
- recoveryRateForLong: 0,
987
- recoveryRateForShort: 0,
988
- marketBid: 0,
989
- marketOffer: 0,
990
- shortSaleMinPrice: 0,
991
- previousClosingPrice: 0,
992
- thresholdLimitPriceBanding: 0,
993
- dailyFinancingValue: 0,
994
- accruedFinancingValue: 0,
995
- twap: 0
996
- };
997
- for (const entry of entries) {
998
- const entryType = entry.MDEntryType;
999
- const price = entry.MDEntryPx ? Number.parseFloat(entry.MDEntryPx) : 0;
1000
- const size = entry.MDEntrySize ? Number.parseFloat(entry.MDEntrySize) : 0;
1001
- const enumValue = getEnumValue(MDEntryType2, entryType);
1002
- switch (enumValue) {
1003
- case MDEntryType2.Bid:
1004
- data.bid = price;
1005
- break;
1006
- case MDEntryType2.Offer:
1007
- data.offer = price;
1008
- break;
1009
- case MDEntryType2.Trade:
1010
- data.trade = price;
1011
- break;
1012
- case MDEntryType2.IndexValue:
1013
- data.indexValue = price;
1014
- break;
1015
- case MDEntryType2.OpeningPrice:
1016
- data.openingPrice = price;
1017
- break;
1018
- case MDEntryType2.ClosingPrice:
1019
- data.closingPrice = price;
1020
- break;
1021
- case MDEntryType2.SettlementPrice:
1022
- data.settlementPrice = price;
1023
- break;
1024
- case MDEntryType2.TradingSessionHighPrice:
1025
- data.tradingSessionHighPrice = price;
1026
- break;
1027
- case MDEntryType2.TradingSessionLowPrice:
1028
- data.tradingSessionLowPrice = price;
1029
- break;
1030
- case MDEntryType2.VWAP:
1031
- data.vwap = price;
1032
- break;
1033
- case MDEntryType2.Imbalance:
1034
- data.imbalance = size;
1035
- break;
1036
- case MDEntryType2.TradeVolume:
1037
- data.volume = size;
1038
- break;
1039
- case MDEntryType2.OpenInterest:
1040
- data.openInterest = size;
1041
- break;
1042
- case MDEntryType2.CompositeUnderlyingPrice:
1043
- data.compositeUnderlyingPrice = price;
1044
- break;
1045
- case MDEntryType2.SimulatedSellPrice:
1046
- data.simulatedSellPrice = price;
1047
- break;
1048
- case MDEntryType2.SimulatedBuyPrice:
1049
- data.simulatedBuyPrice = price;
1050
- break;
1051
- case MDEntryType2.MarginRate:
1052
- data.marginRate = price;
1053
- break;
1054
- case MDEntryType2.MidPrice:
1055
- data.midPrice = price;
1056
- break;
1057
- case MDEntryType2.EmptyBook:
1058
- data.emptyBook = 1;
1059
- break;
1060
- case MDEntryType2.SettleHighPrice:
1061
- data.settleHighPrice = price;
1062
- break;
1063
- case MDEntryType2.SettleLowPrice:
1064
- data.settleLowPrice = price;
1065
- break;
1066
- case MDEntryType2.PriorSettlePrice:
1067
- data.priorSettlePrice = price;
1068
- break;
1069
- case MDEntryType2.SessionHighBid:
1070
- data.sessionHighBid = price;
1071
- break;
1072
- case MDEntryType2.SessionLowOffer:
1073
- data.sessionLowOffer = price;
1074
- break;
1075
- case MDEntryType2.EarlyPrices:
1076
- data.earlyPrices = price;
1077
- break;
1078
- case MDEntryType2.AuctionClearingPrice:
1079
- data.auctionClearingPrice = price;
1080
- break;
1081
- case MDEntryType2.SwapValueFactor:
1082
- data.swapValueFactor = price;
1083
- break;
1084
- case MDEntryType2.DailyValueAdjustmentForLongPositions:
1085
- data.dailyValueAdjustmentForLongPositions = price;
1086
- break;
1087
- case MDEntryType2.CumulativeValueAdjustmentForLongPositions:
1088
- data.cumulativeValueAdjustmentForLongPositions = price;
1089
- break;
1090
- case MDEntryType2.DailyValueAdjustmentForShortPositions:
1091
- data.dailyValueAdjustmentForShortPositions = price;
1092
- break;
1093
- case MDEntryType2.CumulativeValueAdjustmentForShortPositions:
1094
- data.cumulativeValueAdjustmentForShortPositions = price;
1095
- break;
1096
- case MDEntryType2.FixingPrice:
1097
- data.fixingPrice = price;
1098
- break;
1099
- case MDEntryType2.CashRate:
1100
- data.cashRate = price;
1101
- break;
1102
- case MDEntryType2.RecoveryRate:
1103
- data.recoveryRate = price;
1104
- break;
1105
- case MDEntryType2.RecoveryRateForLong:
1106
- data.recoveryRateForLong = price;
1107
- break;
1108
- case MDEntryType2.RecoveryRateForShort:
1109
- data.recoveryRateForShort = price;
1110
- break;
1111
- case MDEntryType2.MarketBid:
1112
- data.marketBid = price;
1113
- break;
1114
- case MDEntryType2.MarketOffer:
1115
- data.marketOffer = price;
1116
- break;
1117
- case MDEntryType2.ShortSaleMinPrice:
1118
- data.shortSaleMinPrice = price;
1119
- break;
1120
- case MDEntryType2.PreviousClosingPrice:
1121
- data.previousClosingPrice = price;
1122
- break;
1123
- case MDEntryType2.ThresholdLimitPriceBanding:
1124
- data.thresholdLimitPriceBanding = price;
1125
- break;
1126
- case MDEntryType2.DailyFinancingValue:
1127
- data.dailyFinancingValue = price;
1128
- break;
1129
- case MDEntryType2.AccruedFinancingValue:
1130
- data.accruedFinancingValue = price;
1131
- break;
1132
- case MDEntryType2.TWAP:
1133
- data.twap = price;
1134
- break;
1135
- }
1136
- }
1137
- data.spread = data.offer - data.bid;
1138
- if (!marketDataPrices.has(symbol)) {
1139
- marketDataPrices.set(symbol, []);
1140
- }
1141
- const prices = marketDataPrices.get(symbol);
1142
- prices.push(data);
1143
- if (prices.length > maxPriceHistory) {
1144
- prices.splice(0, prices.length - maxPriceHistory);
1145
- }
1146
- onPriceUpdate?.(symbol, data);
1147
- const mdReqID = message.getField(Fields3.MDReqID)?.value;
1148
- if (mdReqID) {
1149
- const callback = pendingRequests.get(mdReqID);
1150
- if (callback) {
1151
- callback(message);
1152
- pendingRequests.delete(mdReqID);
1153
- }
1154
- }
1155
- } else if (msgType === Messages3.ExecutionReport) {
1156
- const reqId = message.getField(Fields3.ClOrdID)?.value;
1157
- const callback = pendingRequests.get(reqId);
1158
- if (callback) {
1159
- callback(message);
1160
- pendingRequests.delete(reqId);
1161
- }
1162
- }
1163
- }
1164
-
1165
762
  // src/MCPLocal.ts
1166
- var MCPLocal = class extends MCPBase {
1167
- /**
1168
- * Map to store verified orders before execution
1169
- * @private
1170
- */
1171
- verifiedOrders = /* @__PURE__ */ new Map();
1172
- /**
1173
- * Map to store pending requests and their callbacks
1174
- * @private
1175
- */
1176
- pendingRequests = /* @__PURE__ */ new Map();
1177
- /**
1178
- * Map to store market data prices for each symbol
1179
- * @private
1180
- */
1181
- marketDataPrices = /* @__PURE__ */ new Map();
1182
- /**
1183
- * Maximum number of price history entries to keep per symbol
1184
- * @private
1185
- */
1186
- MAX_PRICE_HISTORY = 1e5;
763
+ var MCPLocal = class {
764
+ parser;
1187
765
  server = new Server(
1188
766
  {
1189
767
  name: "fixparser",
@@ -1205,13 +783,90 @@ var MCPLocal = class extends MCPBase {
1205
783
  }
1206
784
  );
1207
785
  transport = new StdioServerTransport();
786
+ onReady = void 0;
787
+ pendingRequests = /* @__PURE__ */ new Map();
788
+ verifiedOrders = /* @__PURE__ */ new Map();
789
+ marketDataPrices = /* @__PURE__ */ new Map();
790
+ MAX_PRICE_HISTORY = 1e5;
791
+ // Maximum number of price points to store per symbol
1208
792
  constructor({ logger, onReady }) {
1209
- super({ logger, onReady });
793
+ if (onReady) this.onReady = onReady;
1210
794
  }
1211
795
  async register(parser) {
1212
796
  this.parser = parser;
1213
797
  this.parser.addOnMessageCallback((message) => {
1214
- handleMessage(message, this.parser, this.pendingRequests, this.marketDataPrices, this.MAX_PRICE_HISTORY);
798
+ this.parser?.logger.log({
799
+ level: "info",
800
+ message: `MCP Server received message: ${message.messageType}: ${message.description}`
801
+ });
802
+ const msgType = message.messageType;
803
+ if (msgType === Messages3.MarketDataSnapshotFullRefresh || msgType === Messages3.ExecutionReport || msgType === Messages3.Reject || msgType === Messages3.MarketDataIncrementalRefresh) {
804
+ this.parser?.logger.log({
805
+ level: "info",
806
+ message: `MCP Server handling message type: ${msgType}`
807
+ });
808
+ let id;
809
+ if (msgType === Messages3.MarketDataIncrementalRefresh || msgType === Messages3.MarketDataSnapshotFullRefresh) {
810
+ const symbol = message.getField(Fields3.Symbol);
811
+ const entryType = message.getField(Fields3.MDEntryType);
812
+ const price = message.getField(Fields3.MDEntryPx);
813
+ const size = message.getField(Fields3.MDEntrySize);
814
+ const timestamp = message.getField(Fields3.MDEntryTime)?.value || Date.now();
815
+ if (symbol?.value && price?.value) {
816
+ const symbolStr = String(symbol.value);
817
+ const priceNum = Number(price.value);
818
+ const sizeNum = size?.value ? Number(size.value) : 0;
819
+ const priceHistory = this.marketDataPrices.get(symbolStr) || [];
820
+ const lastEntry = priceHistory[priceHistory.length - 1] || {
821
+ timestamp: 0,
822
+ bid: 0,
823
+ offer: 0,
824
+ spread: 0,
825
+ volume: 0
826
+ };
827
+ const newEntry = {
828
+ timestamp: Number(timestamp),
829
+ bid: entryType?.value === MDEntryType2.Bid ? priceNum : lastEntry.bid,
830
+ offer: entryType?.value === MDEntryType2.Offer ? priceNum : lastEntry.offer,
831
+ spread: entryType?.value === MDEntryType2.Offer ? priceNum - lastEntry.bid : entryType?.value === MDEntryType2.Bid ? lastEntry.offer - priceNum : lastEntry.spread,
832
+ volume: entryType?.value === MDEntryType2.TradeVolume ? sizeNum : lastEntry.volume
833
+ };
834
+ priceHistory.push(newEntry);
835
+ if (priceHistory.length > this.MAX_PRICE_HISTORY) {
836
+ priceHistory.shift();
837
+ }
838
+ this.marketDataPrices.set(symbolStr, priceHistory);
839
+ this.parser?.logger.log({
840
+ level: "info",
841
+ message: `MCP Server added ${symbol}: ${JSON.stringify(newEntry)}`
842
+ });
843
+ this.server.notification({
844
+ method: "priceUpdate",
845
+ params: {
846
+ symbol: symbolStr,
847
+ ...newEntry
848
+ }
849
+ });
850
+ }
851
+ }
852
+ if (msgType === Messages3.MarketDataSnapshotFullRefresh) {
853
+ const mdReqID = message.getField(Fields3.MDReqID);
854
+ if (mdReqID) id = String(mdReqID.value);
855
+ } else if (msgType === Messages3.ExecutionReport) {
856
+ const clOrdID = message.getField(Fields3.ClOrdID);
857
+ if (clOrdID) id = String(clOrdID.value);
858
+ } else if (msgType === Messages3.Reject) {
859
+ const refSeqNum = message.getField(Fields3.RefSeqNum);
860
+ if (refSeqNum) id = String(refSeqNum.value);
861
+ }
862
+ if (id) {
863
+ const callback = this.pendingRequests.get(id);
864
+ if (callback) {
865
+ callback(message);
866
+ this.pendingRequests.delete(id);
867
+ }
868
+ }
869
+ }
1215
870
  });
1216
871
  this.addWorkflows();
1217
872
  await this.server.connect(this.transport);
@@ -1226,15 +881,18 @@ var MCPLocal = class extends MCPBase {
1226
881
  if (!this.server) {
1227
882
  return;
1228
883
  }
1229
- this.server.setRequestHandler(z.object({ method: z.literal("tools/list") }), async () => {
1230
- return {
1231
- tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
1232
- name,
1233
- description,
1234
- inputSchema: schema
1235
- }))
1236
- };
1237
- });
884
+ this.server.setRequestHandler(
885
+ z.object({ method: z.literal("tools/list") }),
886
+ async (request, extra) => {
887
+ return {
888
+ tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
889
+ name,
890
+ description,
891
+ inputSchema: schema
892
+ }))
893
+ };
894
+ }
895
+ );
1238
896
  this.server.setRequestHandler(
1239
897
  z.object({
1240
898
  method: z.literal("tools/call"),
@@ -1246,7 +904,7 @@ var MCPLocal = class extends MCPBase {
1246
904
  }).optional()
1247
905
  })
1248
906
  }),
1249
- async (request) => {
907
+ async (request, extra) => {
1250
908
  const { name, arguments: args } = request.params;
1251
909
  const toolHandlers = createToolHandlers(
1252
910
  this.parser,