fixparser-plugin-mcp 9.1.7-525accda → 9.1.7-52ccb1d5

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