fixparser-plugin-mcp 9.1.7-2eb6d03c → 9.1.7-3302db05

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,179 +35,767 @@ __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_fixparser3 = require("fixparser");
39
+ var import_zod = require("zod");
40
+
41
+ // src/schemas/schemas.ts
42
+ var toolSchemas = {
43
+ parse: {
44
+ description: "Parses a FIX message and describes it in plain language",
45
+ schema: {
46
+ type: "object",
47
+ properties: {
48
+ fixString: { type: "string" }
49
+ },
50
+ required: ["fixString"]
36
51
  }
37
52
  },
38
- required: ["fixString"]
39
- };
40
- var parseToJSONInputSchema = {
41
- type: "object",
42
- properties: {
43
- fixString: {
44
- type: "string",
45
- description: "FIX message string to parse"
53
+ parseToJSON: {
54
+ description: "Parses a FIX message into JSON",
55
+ schema: {
56
+ type: "object",
57
+ properties: {
58
+ fixString: { type: "string" }
59
+ },
60
+ required: ["fixString"]
46
61
  }
47
62
  },
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"
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"
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 (1=Buy, 2=Sell)"
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"
63
+ verifyOrder: {
64
+ description: "Verifies order parameters before execution. verifyOrder must be called before executeOrder.",
65
+ schema: {
66
+ type: "object",
67
+ properties: {
68
+ clOrdID: { type: "string" },
69
+ handlInst: {
70
+ type: "string",
71
+ enum: ["1", "2", "3"],
72
+ description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
73
+ },
74
+ quantity: { type: "string" },
75
+ price: { type: "string" },
76
+ ordType: {
77
+ type: "string",
78
+ enum: [
79
+ "1",
80
+ "2",
81
+ "3",
82
+ "4",
83
+ "5",
84
+ "6",
85
+ "7",
86
+ "8",
87
+ "9",
88
+ "A",
89
+ "B",
90
+ "C",
91
+ "D",
92
+ "E",
93
+ "F",
94
+ "G",
95
+ "H",
96
+ "I",
97
+ "J",
98
+ "K",
99
+ "L",
100
+ "M",
101
+ "P",
102
+ "Q",
103
+ "R",
104
+ "S"
105
+ ],
106
+ 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"
107
+ },
108
+ side: {
109
+ type: "string",
110
+ enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
111
+ 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"
112
+ },
113
+ symbol: { type: "string" },
114
+ timeInForce: {
115
+ type: "string",
116
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
117
+ 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"
118
+ }
119
+ },
120
+ required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
118
121
  }
119
122
  },
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"
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"
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"
123
+ executeOrder: {
124
+ description: "Executes a verified order. verifyOrder must be called before executeOrder. user has to explicitly allow executeOrder.",
125
+ schema: {
126
+ type: "object",
127
+ properties: {
128
+ clOrdID: { type: "string" },
129
+ handlInst: {
130
+ type: "string",
131
+ enum: ["1", "2", "3"],
132
+ description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
133
+ },
134
+ quantity: { type: "string" },
135
+ price: { type: "string" },
136
+ ordType: {
137
+ type: "string",
138
+ enum: [
139
+ "1",
140
+ "2",
141
+ "3",
142
+ "4",
143
+ "5",
144
+ "6",
145
+ "7",
146
+ "8",
147
+ "9",
148
+ "A",
149
+ "B",
150
+ "C",
151
+ "D",
152
+ "E",
153
+ "F",
154
+ "G",
155
+ "H",
156
+ "I",
157
+ "J",
158
+ "K",
159
+ "L",
160
+ "M",
161
+ "P",
162
+ "Q",
163
+ "R",
164
+ "S"
165
+ ],
166
+ 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"
167
+ },
168
+ side: {
169
+ type: "string",
170
+ enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
171
+ 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"
172
+ },
173
+ symbol: { type: "string" },
174
+ timeInForce: {
175
+ type: "string",
176
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
177
+ 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"
178
+ }
179
+ },
180
+ required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
195
181
  }
196
182
  },
197
- required: ["symbol", "mdReqID"]
183
+ marketDataRequest: {
184
+ description: "Requests market data for specified symbols",
185
+ schema: {
186
+ type: "object",
187
+ properties: {
188
+ mdUpdateType: {
189
+ type: "string",
190
+ enum: ["0", "1"],
191
+ description: "Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"
192
+ },
193
+ symbols: { type: "array", items: { type: "string" } },
194
+ mdReqID: { type: "string" },
195
+ subscriptionRequestType: {
196
+ type: "string",
197
+ enum: ["0", "1", "2"],
198
+ description: "Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"
199
+ },
200
+ mdEntryTypes: {
201
+ type: "array",
202
+ items: {
203
+ type: "string",
204
+ enum: [
205
+ "0",
206
+ "1",
207
+ "2",
208
+ "3",
209
+ "4",
210
+ "5",
211
+ "6",
212
+ "7",
213
+ "8",
214
+ "9",
215
+ "A",
216
+ "B",
217
+ "C",
218
+ "D",
219
+ "E",
220
+ "F",
221
+ "G",
222
+ "H",
223
+ "I",
224
+ "J",
225
+ "K",
226
+ "L",
227
+ "M",
228
+ "N",
229
+ "O",
230
+ "P",
231
+ "Q",
232
+ "R",
233
+ "S",
234
+ "T",
235
+ "U",
236
+ "V",
237
+ "W",
238
+ "X",
239
+ "Y",
240
+ "Z"
241
+ ]
242
+ },
243
+ 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
+ }
245
+ },
246
+ required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType"]
247
+ }
248
+ },
249
+ getStockGraph: {
250
+ description: "Generates a price chart for a given symbol",
251
+ schema: {
252
+ type: "object",
253
+ properties: {
254
+ symbol: { type: "string" }
255
+ },
256
+ required: ["symbol"]
257
+ }
258
+ },
259
+ getStockPriceHistory: {
260
+ description: "Returns price history for a given symbol",
261
+ schema: {
262
+ type: "object",
263
+ properties: {
264
+ symbol: { type: "string" }
265
+ },
266
+ required: ["symbol"]
267
+ }
268
+ }
269
+ };
270
+
271
+ // src/tools/marketData.ts
272
+ var import_fixparser = require("fixparser");
273
+ var import_quickchart_js = __toESM(require("quickchart-js"), 1);
274
+ var createMarketDataRequestHandler = (parser, pendingRequests) => {
275
+ return async (args) => {
276
+ try {
277
+ const response = new Promise((resolve) => {
278
+ pendingRequests.set(args.mdReqID, resolve);
279
+ });
280
+ const entryTypes = args.mdEntryTypes || [import_fixparser.MDEntryType.Bid, import_fixparser.MDEntryType.Offer, import_fixparser.MDEntryType.TradeVolume];
281
+ const messageFields = [
282
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
283
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
284
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
285
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
286
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
287
+ new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
288
+ new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
289
+ new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
290
+ new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
291
+ ];
292
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
293
+ args.symbols.forEach((symbol) => {
294
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
295
+ });
296
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, entryTypes.length));
297
+ entryTypes.forEach((entryType) => {
298
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
299
+ });
300
+ const mdr = parser.createMessage(...messageFields);
301
+ if (!parser.connected) {
302
+ return {
303
+ content: [
304
+ {
305
+ type: "text",
306
+ text: "Error: Not connected. Ignoring message.",
307
+ uri: "marketDataRequest"
308
+ }
309
+ ],
310
+ isError: true
311
+ };
312
+ }
313
+ parser.send(mdr);
314
+ const fixData = await response;
315
+ return {
316
+ content: [
317
+ {
318
+ type: "text",
319
+ text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
320
+ uri: "marketDataRequest"
321
+ }
322
+ ]
323
+ };
324
+ } catch (error) {
325
+ return {
326
+ content: [
327
+ {
328
+ type: "text",
329
+ text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
330
+ uri: "marketDataRequest"
331
+ }
332
+ ],
333
+ isError: true
334
+ };
335
+ }
336
+ };
337
+ };
338
+ var createGetStockGraphHandler = (marketDataPrices) => {
339
+ return async (args) => {
340
+ try {
341
+ const symbol = args.symbol;
342
+ const priceHistory = marketDataPrices.get(symbol) || [];
343
+ if (priceHistory.length === 0) {
344
+ return {
345
+ content: [
346
+ {
347
+ type: "text",
348
+ text: `No price data available for ${symbol}`,
349
+ uri: "getStockGraph"
350
+ }
351
+ ]
352
+ };
353
+ }
354
+ const chart = new import_quickchart_js.default();
355
+ chart.setWidth(1200);
356
+ chart.setHeight(600);
357
+ chart.setBackgroundColor("transparent");
358
+ const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
359
+ const bidData = priceHistory.map((point) => point.bid);
360
+ const offerData = priceHistory.map((point) => point.offer);
361
+ const spreadData = priceHistory.map((point) => point.spread);
362
+ const volumeData = priceHistory.map((point) => point.volume);
363
+ const config = {
364
+ type: "line",
365
+ data: {
366
+ labels,
367
+ datasets: [
368
+ {
369
+ label: "Bid",
370
+ data: bidData,
371
+ borderColor: "#28a745",
372
+ backgroundColor: "rgba(40, 167, 69, 0.1)",
373
+ fill: false,
374
+ tension: 0.4
375
+ },
376
+ {
377
+ label: "Offer",
378
+ data: offerData,
379
+ borderColor: "#dc3545",
380
+ backgroundColor: "rgba(220, 53, 69, 0.1)",
381
+ fill: false,
382
+ tension: 0.4
383
+ },
384
+ {
385
+ label: "Spread",
386
+ data: spreadData,
387
+ borderColor: "#6c757d",
388
+ backgroundColor: "rgba(108, 117, 125, 0.1)",
389
+ fill: false,
390
+ tension: 0.4
391
+ },
392
+ {
393
+ label: "Volume",
394
+ data: volumeData,
395
+ borderColor: "#007bff",
396
+ backgroundColor: "rgba(0, 123, 255, 0.1)",
397
+ fill: true,
398
+ tension: 0.4
399
+ }
400
+ ]
401
+ },
402
+ options: {
403
+ responsive: true,
404
+ plugins: {
405
+ title: {
406
+ display: true,
407
+ text: `${symbol} Market Data`
408
+ }
409
+ },
410
+ scales: {
411
+ y: {
412
+ beginAtZero: false
413
+ }
414
+ }
415
+ }
416
+ };
417
+ chart.setConfig(config);
418
+ const imageBuffer = await chart.toBinary();
419
+ const base64 = imageBuffer.toString("base64");
420
+ return {
421
+ content: [
422
+ {
423
+ type: "resource",
424
+ resource: {
425
+ uri: "resource://graph",
426
+ mimeType: "image/png",
427
+ blob: base64
428
+ }
429
+ }
430
+ ]
431
+ };
432
+ } catch (error) {
433
+ return {
434
+ content: [
435
+ {
436
+ type: "text",
437
+ text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
438
+ uri: "getStockGraph"
439
+ }
440
+ ],
441
+ isError: true
442
+ };
443
+ }
444
+ };
445
+ };
446
+ var createGetStockPriceHistoryHandler = (marketDataPrices) => {
447
+ return async (args) => {
448
+ try {
449
+ const symbol = args.symbol;
450
+ const priceHistory = marketDataPrices.get(symbol) || [];
451
+ if (priceHistory.length === 0) {
452
+ return {
453
+ content: [
454
+ {
455
+ type: "text",
456
+ text: `No price data available for ${symbol}`,
457
+ uri: "getStockPriceHistory"
458
+ }
459
+ ]
460
+ };
461
+ }
462
+ return {
463
+ content: [
464
+ {
465
+ type: "text",
466
+ text: JSON.stringify(
467
+ {
468
+ symbol,
469
+ count: priceHistory.length,
470
+ data: priceHistory.map((point) => ({
471
+ timestamp: new Date(point.timestamp).toISOString(),
472
+ bid: point.bid,
473
+ offer: point.offer,
474
+ spread: point.spread,
475
+ volume: point.volume
476
+ }))
477
+ },
478
+ null,
479
+ 2
480
+ ),
481
+ uri: "getStockPriceHistory"
482
+ }
483
+ ]
484
+ };
485
+ } catch (error) {
486
+ return {
487
+ content: [
488
+ {
489
+ type: "text",
490
+ text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
491
+ uri: "getStockPriceHistory"
492
+ }
493
+ ],
494
+ isError: true
495
+ };
496
+ }
497
+ };
498
+ };
499
+
500
+ // src/tools/order.ts
501
+ var import_fixparser2 = require("fixparser");
502
+ var ordTypeNames = {
503
+ "1": "Market",
504
+ "2": "Limit",
505
+ "3": "Stop",
506
+ "4": "StopLimit",
507
+ "5": "MarketOnClose",
508
+ "6": "WithOrWithout",
509
+ "7": "LimitOrBetter",
510
+ "8": "LimitWithOrWithout",
511
+ "9": "OnBasis",
512
+ A: "OnClose",
513
+ B: "LimitOnClose",
514
+ C: "ForexMarket",
515
+ D: "PreviouslyQuoted",
516
+ E: "PreviouslyIndicated",
517
+ F: "ForexLimit",
518
+ G: "ForexSwap",
519
+ H: "ForexPreviouslyQuoted",
520
+ I: "Funari",
521
+ J: "MarketIfTouched",
522
+ K: "MarketWithLeftOverAsLimit",
523
+ L: "PreviousFundValuationPoint",
524
+ M: "NextFundValuationPoint",
525
+ P: "Pegged",
526
+ Q: "CounterOrderSelection",
527
+ R: "StopOnBidOrOffer",
528
+ S: "StopLimitOnBidOrOffer"
529
+ };
530
+ var sideNames = {
531
+ "1": "Buy",
532
+ "2": "Sell",
533
+ "3": "BuyMinus",
534
+ "4": "SellPlus",
535
+ "5": "SellShort",
536
+ "6": "SellShortExempt",
537
+ "7": "Undisclosed",
538
+ "8": "Cross",
539
+ "9": "CrossShort",
540
+ A: "CrossShortExempt",
541
+ B: "AsDefined",
542
+ C: "Opposite",
543
+ D: "Subscribe",
544
+ E: "Redeem",
545
+ F: "Lend",
546
+ G: "Borrow",
547
+ H: "SellUndisclosed"
548
+ };
549
+ var timeInForceNames = {
550
+ "0": "Day",
551
+ "1": "GoodTillCancel",
552
+ "2": "AtTheOpening",
553
+ "3": "ImmediateOrCancel",
554
+ "4": "FillOrKill",
555
+ "5": "GoodTillCrossing",
556
+ "6": "GoodTillDate",
557
+ "7": "AtTheClose",
558
+ "8": "GoodThroughCrossing",
559
+ "9": "AtCrossing",
560
+ A: "GoodForTime",
561
+ B: "GoodForAuction",
562
+ C: "GoodForMonth"
563
+ };
564
+ var handlInstNames = {
565
+ "1": "AutomatedExecutionNoIntervention",
566
+ "2": "AutomatedExecutionInterventionOK",
567
+ "3": "ManualOrder"
568
+ };
569
+ var createVerifyOrderHandler = (parser, verifiedOrders) => {
570
+ return async (args) => {
571
+ try {
572
+ verifiedOrders.set(args.clOrdID, {
573
+ clOrdID: args.clOrdID,
574
+ handlInst: args.handlInst,
575
+ quantity: Number.parseFloat(String(args.quantity)),
576
+ price: Number.parseFloat(String(args.price)),
577
+ ordType: args.ordType,
578
+ side: args.side,
579
+ symbol: args.symbol,
580
+ timeInForce: args.timeInForce
581
+ });
582
+ return {
583
+ content: [
584
+ {
585
+ type: "text",
586
+ text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
587
+
588
+ Parameters verified:
589
+ - ClOrdID: ${args.clOrdID}
590
+ - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
591
+ - Quantity: ${args.quantity}
592
+ - Price: ${args.price}
593
+ - OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
594
+ - Side: ${args.side} (${sideNames[args.side]})
595
+ - Symbol: ${args.symbol}
596
+ - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
597
+
598
+ To execute this order, call the executeOrder tool with these exact same parameters.`,
599
+ uri: "verifyOrder"
600
+ }
601
+ ]
602
+ };
603
+ } catch (error) {
604
+ return {
605
+ content: [
606
+ {
607
+ type: "text",
608
+ text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
609
+ uri: "verifyOrder"
610
+ }
611
+ ],
612
+ isError: true
613
+ };
614
+ }
615
+ };
616
+ };
617
+ var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
618
+ return async (args) => {
619
+ try {
620
+ const verifiedOrder = verifiedOrders.get(args.clOrdID);
621
+ if (!verifiedOrder) {
622
+ return {
623
+ content: [
624
+ {
625
+ type: "text",
626
+ text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
627
+ uri: "executeOrder"
628
+ }
629
+ ],
630
+ isError: true
631
+ };
632
+ }
633
+ 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) {
634
+ return {
635
+ content: [
636
+ {
637
+ type: "text",
638
+ text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
639
+ uri: "executeOrder"
640
+ }
641
+ ],
642
+ isError: true
643
+ };
644
+ }
645
+ const response = new Promise((resolve) => {
646
+ pendingRequests.set(args.clOrdID, resolve);
647
+ });
648
+ const order = parser.createMessage(
649
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
650
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
651
+ new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
652
+ new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
653
+ new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
654
+ new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
655
+ new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
656
+ new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
657
+ new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
658
+ new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
659
+ new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
660
+ new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
661
+ new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
662
+ new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
663
+ );
664
+ if (!parser.connected) {
665
+ return {
666
+ content: [
667
+ {
668
+ type: "text",
669
+ text: "Error: Not connected. Ignoring message.",
670
+ uri: "executeOrder"
671
+ }
672
+ ],
673
+ isError: true
674
+ };
675
+ }
676
+ parser.send(order);
677
+ const fixData = await response;
678
+ verifiedOrders.delete(args.clOrdID);
679
+ return {
680
+ content: [
681
+ {
682
+ type: "text",
683
+ 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())}`,
684
+ uri: "executeOrder"
685
+ }
686
+ ]
687
+ };
688
+ } catch (error) {
689
+ return {
690
+ content: [
691
+ {
692
+ type: "text",
693
+ text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
694
+ uri: "executeOrder"
695
+ }
696
+ ],
697
+ isError: true
698
+ };
699
+ }
700
+ };
701
+ };
702
+
703
+ // src/tools/parse.ts
704
+ var createParseHandler = (parser) => {
705
+ return async (args) => {
706
+ try {
707
+ const parsedMessage = parser.parse(args.fixString);
708
+ if (!parsedMessage || parsedMessage.length === 0) {
709
+ return {
710
+ content: [
711
+ {
712
+ type: "text",
713
+ text: "Error: Failed to parse FIX string",
714
+ uri: "parse"
715
+ }
716
+ ],
717
+ isError: true
718
+ };
719
+ }
720
+ return {
721
+ content: [
722
+ {
723
+ type: "text",
724
+ text: `${parsedMessage[0].description}
725
+ ${parsedMessage[0].messageTypeDescription}`,
726
+ uri: "parse"
727
+ }
728
+ ]
729
+ };
730
+ } catch (error) {
731
+ return {
732
+ content: [
733
+ {
734
+ type: "text",
735
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
736
+ uri: "parse"
737
+ }
738
+ ],
739
+ isError: true
740
+ };
741
+ }
742
+ };
743
+ };
744
+
745
+ // src/tools/parseToJSON.ts
746
+ var createParseToJSONHandler = (parser) => {
747
+ return async (args) => {
748
+ try {
749
+ const parsedMessage = parser.parse(args.fixString);
750
+ if (!parsedMessage || parsedMessage.length === 0) {
751
+ return {
752
+ content: [
753
+ {
754
+ type: "text",
755
+ text: "Error: Failed to parse FIX string",
756
+ uri: "parseToJSON"
757
+ }
758
+ ],
759
+ isError: true
760
+ };
761
+ }
762
+ return {
763
+ content: [
764
+ {
765
+ type: "text",
766
+ text: `${parsedMessage[0].toFIXJSON()}`,
767
+ uri: "parseToJSON"
768
+ }
769
+ ]
770
+ };
771
+ } catch (error) {
772
+ return {
773
+ content: [
774
+ {
775
+ type: "text",
776
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
777
+ uri: "parseToJSON"
778
+ }
779
+ ],
780
+ isError: true
781
+ };
782
+ }
783
+ };
198
784
  };
785
+
786
+ // src/tools/index.ts
787
+ var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
788
+ parse: createParseHandler(parser),
789
+ parseToJSON: createParseToJSONHandler(parser),
790
+ verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
791
+ executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
792
+ marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
793
+ getStockGraph: createGetStockGraphHandler(marketDataPrices),
794
+ getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
795
+ });
796
+
797
+ // src/MCPLocal.ts
199
798
  var MCPLocal = class {
200
- logger;
201
799
  parser;
202
800
  server = new import_server.Server(
203
801
  {
@@ -205,39 +803,106 @@ var MCPLocal = class {
205
803
  version: "1.0.0"
206
804
  },
207
805
  {
208
- capabilities: { tools: {} }
806
+ capabilities: {
807
+ tools: Object.entries(toolSchemas).reduce(
808
+ (acc, [name, { description, schema }]) => {
809
+ acc[name] = {
810
+ description,
811
+ parameters: schema
812
+ };
813
+ return acc;
814
+ },
815
+ {}
816
+ )
817
+ }
209
818
  }
210
819
  );
211
820
  transport = new import_stdio.StdioServerTransport();
212
821
  onReady = void 0;
213
822
  pendingRequests = /* @__PURE__ */ new Map();
823
+ verifiedOrders = /* @__PURE__ */ new Map();
824
+ marketDataPrices = /* @__PURE__ */ new Map();
825
+ MAX_PRICE_HISTORY = 1e5;
826
+ // Maximum number of price points to store per symbol
214
827
  constructor({ logger, onReady }) {
215
- if (logger) this.logger = logger;
216
828
  if (onReady) this.onReady = onReady;
217
829
  }
218
830
  async register(parser) {
219
831
  this.parser = parser;
220
832
  this.parser.addOnMessageCallback((message) => {
221
- this.logger?.log({
833
+ this.parser?.logger.log({
222
834
  level: "info",
223
- message: `FIXParser (MCP): (${parser.protocol?.toUpperCase()}): << received ${message.description}`
835
+ message: `MCP Server received message: ${message.messageType}: ${message.description}`
224
836
  });
225
837
  const msgType = message.messageType;
226
- if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport) {
227
- const idField = msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh ? message.getField(import_fixparser.Fields.MDReqID) : message.getField(import_fixparser.Fields.ClOrdID);
228
- if (idField) {
229
- const id = idField.value;
230
- if (typeof id === "string" || typeof id === "number") {
231
- const callback = this.pendingRequests.get(String(id));
232
- if (callback) {
233
- callback(message);
234
- this.pendingRequests.delete(String(id));
838
+ if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.ExecutionReport || msgType === import_fixparser3.Messages.Reject || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
839
+ this.parser?.logger.log({
840
+ level: "info",
841
+ message: `MCP Server handling message type: ${msgType}`
842
+ });
843
+ let id;
844
+ if (msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
845
+ const symbol = message.getField(import_fixparser3.Fields.Symbol);
846
+ const entryType = message.getField(import_fixparser3.Fields.MDEntryType);
847
+ const price = message.getField(import_fixparser3.Fields.MDEntryPx);
848
+ const size = message.getField(import_fixparser3.Fields.MDEntrySize);
849
+ const timestamp = message.getField(import_fixparser3.Fields.MDEntryTime)?.value || Date.now();
850
+ if (symbol?.value && price?.value) {
851
+ const symbolStr = String(symbol.value);
852
+ const priceNum = Number(price.value);
853
+ const sizeNum = size?.value ? Number(size.value) : 0;
854
+ const priceHistory = this.marketDataPrices.get(symbolStr) || [];
855
+ const lastEntry = priceHistory[priceHistory.length - 1] || {
856
+ timestamp: 0,
857
+ bid: 0,
858
+ offer: 0,
859
+ spread: 0,
860
+ volume: 0
861
+ };
862
+ const newEntry = {
863
+ timestamp: Number(timestamp),
864
+ bid: entryType?.value === import_fixparser3.MDEntryType.Bid ? priceNum : lastEntry.bid,
865
+ offer: entryType?.value === import_fixparser3.MDEntryType.Offer ? priceNum : lastEntry.offer,
866
+ spread: entryType?.value === import_fixparser3.MDEntryType.Offer ? priceNum - lastEntry.bid : entryType?.value === import_fixparser3.MDEntryType.Bid ? lastEntry.offer - priceNum : lastEntry.spread,
867
+ volume: entryType?.value === import_fixparser3.MDEntryType.TradeVolume ? sizeNum : lastEntry.volume
868
+ };
869
+ priceHistory.push(newEntry);
870
+ if (priceHistory.length > this.MAX_PRICE_HISTORY) {
871
+ priceHistory.shift();
235
872
  }
873
+ this.marketDataPrices.set(symbolStr, priceHistory);
874
+ this.parser?.logger.log({
875
+ level: "info",
876
+ message: `MCP Server added ${symbol}: ${JSON.stringify(newEntry)}`
877
+ });
878
+ this.server.notification({
879
+ method: "priceUpdate",
880
+ params: {
881
+ symbol: symbolStr,
882
+ ...newEntry
883
+ }
884
+ });
885
+ }
886
+ }
887
+ if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
888
+ const mdReqID = message.getField(import_fixparser3.Fields.MDReqID);
889
+ if (mdReqID) id = String(mdReqID.value);
890
+ } else if (msgType === import_fixparser3.Messages.ExecutionReport) {
891
+ const clOrdID = message.getField(import_fixparser3.Fields.ClOrdID);
892
+ if (clOrdID) id = String(clOrdID.value);
893
+ } else if (msgType === import_fixparser3.Messages.Reject) {
894
+ const refSeqNum = message.getField(import_fixparser3.Fields.RefSeqNum);
895
+ if (refSeqNum) id = String(refSeqNum.value);
896
+ }
897
+ if (id) {
898
+ const callback = this.pendingRequests.get(id);
899
+ if (callback) {
900
+ callback(message);
901
+ this.pendingRequests.delete(id);
236
902
  }
237
903
  }
238
904
  }
239
905
  });
240
- this.logger = parser.logger;
241
906
  this.addWorkflows();
242
907
  await this.server.connect(this.transport);
243
908
  if (this.onReady) {
@@ -246,450 +911,62 @@ var MCPLocal = class {
246
911
  }
247
912
  addWorkflows() {
248
913
  if (!this.parser) {
249
- this.logger?.log({
250
- level: "error",
251
- message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of workflows..."
252
- });
253
914
  return;
254
915
  }
255
916
  if (!this.server) {
256
- this.logger?.log({
257
- level: "error",
258
- message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of workflows..."
259
- });
260
917
  return;
261
918
  }
262
- const validateArgs = (args, schema) => {
263
- const result = {};
264
- for (const [key, propSchema] of Object.entries(schema.properties || {})) {
265
- const prop = propSchema;
266
- const value = args?.[key];
267
- if (prop.required && (value === void 0 || value === null)) {
268
- throw new Error(`Required property '${key}' is missing`);
269
- }
270
- if (value !== void 0) {
271
- result[key] = value;
272
- } else if (prop.default !== void 0) {
273
- result[key] = prop.default;
274
- }
919
+ this.server.setRequestHandler(
920
+ import_zod.z.object({ method: import_zod.z.literal("tools/list") }),
921
+ async (request, extra) => {
922
+ return {
923
+ tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
924
+ name,
925
+ description,
926
+ inputSchema: schema
927
+ }))
928
+ };
275
929
  }
276
- return result;
277
- };
278
- this.server.setRequestHandler(import_types.ListResourcesRequestSchema, async () => {
279
- return {
280
- resources: []
281
- };
282
- });
283
- this.server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
284
- return {
285
- tools: [
286
- {
287
- name: "parse",
288
- description: "Parses a FIX message and describes it in plain language",
289
- inputSchema: parseInputSchema
290
- },
291
- {
292
- name: "parseToJSON",
293
- description: "Parses a FIX message into JSON",
294
- inputSchema: parseToJSONInputSchema
295
- },
296
- {
297
- name: "newOrderSingle",
298
- description: "Creates and sends a New Order Single",
299
- inputSchema: newOrderSingleInputSchema
300
- },
301
- {
302
- name: "marketDataRequest",
303
- description: "Sends a request for Market Data with the given symbol",
304
- inputSchema: marketDataRequestInputSchema
305
- }
306
- ]
307
- };
308
- });
309
- this.server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
310
- const { name, arguments: args } = request.params;
311
- switch (name) {
312
- case "parse": {
313
- try {
314
- const { fixString } = validateArgs(args, parseInputSchema);
315
- const parsedMessage = this.parser?.parse(fixString);
316
- if (!parsedMessage || parsedMessage.length === 0) {
317
- return {
318
- isError: true,
319
- content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
320
- };
321
- }
322
- return {
323
- content: [
324
- {
325
- type: "text",
326
- text: `Parsed FIX message: ${fixString} (placeholder implementation)`
327
- }
328
- ]
329
- };
330
- } catch (error) {
331
- return {
332
- isError: true,
333
- content: [
334
- {
335
- type: "text",
336
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
337
- }
338
- ]
339
- };
340
- }
341
- }
342
- case "parseToJSON": {
343
- try {
344
- const { fixString } = validateArgs(args, parseToJSONInputSchema);
345
- const parsedMessage = this.parser?.parse(fixString);
346
- if (!parsedMessage || parsedMessage.length === 0) {
347
- return {
348
- isError: true,
349
- content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
350
- };
351
- }
352
- return {
353
- content: [
354
- {
355
- type: "text",
356
- text: JSON.stringify({ fixString, parsed: "placeholder" })
357
- }
358
- ]
359
- };
360
- } catch (error) {
361
- return {
362
- isError: true,
363
- content: [
364
- {
365
- type: "text",
366
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
367
- }
368
- ]
369
- };
370
- }
371
- }
372
- case "newOrderSingle": {
373
- try {
374
- const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = validateArgs(args, newOrderSingleInputSchema);
375
- const response = new Promise((resolve) => {
376
- this.pendingRequests.set(clOrdID, resolve);
377
- });
378
- const order = this.parser?.createMessage(
379
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
380
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
381
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
382
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
383
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
384
- new import_fixparser.Field(import_fixparser.Fields.ClOrdID, clOrdID),
385
- new import_fixparser.Field(import_fixparser.Fields.Side, side),
386
- new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
387
- new import_fixparser.Field(import_fixparser.Fields.OrderQty, quantity),
388
- new import_fixparser.Field(import_fixparser.Fields.Price, price),
389
- new import_fixparser.Field(import_fixparser.Fields.OrdType, ordType),
390
- new import_fixparser.Field(import_fixparser.Fields.HandlInst, handlInst),
391
- new import_fixparser.Field(import_fixparser.Fields.TimeInForce, timeInForce),
392
- new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
393
- );
394
- if (!this.parser?.connected) {
395
- this.logger?.log({
396
- level: "error",
397
- message: "FIXParser (MCP): -- Not connected. Ignoring message."
398
- });
399
- return {
400
- isError: true,
401
- content: [
402
- {
403
- type: "text",
404
- text: "Error: Not connected. Ignoring message."
405
- }
406
- ]
407
- };
408
- }
409
- this.parser?.send(order);
410
- this.logger?.log({
411
- level: "info",
412
- message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${order?.description}`
413
- });
414
- const fixData = await response;
415
- return {
416
- content: [
417
- {
418
- type: "text",
419
- text: `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
420
- }
421
- ]
422
- };
423
- } catch (error) {
424
- return {
425
- isError: true,
426
- content: [
427
- {
428
- type: "text",
429
- text: `Error: ${error instanceof Error ? error.message : "Failed to create order"}`
430
- }
431
- ]
432
- };
433
- }
434
- }
435
- case "marketDataRequest": {
436
- try {
437
- const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = validateArgs(
438
- args,
439
- marketDataRequestInputSchema
440
- );
441
- const response = new Promise((resolve) => {
442
- this.pendingRequests.set(mdReqID, resolve);
443
- });
444
- const marketDataRequest = this.parser?.createMessage(
445
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
446
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
447
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
448
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
449
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
450
- new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
451
- new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, mdUpdateType),
452
- new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, 1),
453
- new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
454
- new import_fixparser.Field(import_fixparser.Fields.MDReqID, mdReqID),
455
- new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, subscriptionRequestType),
456
- new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
457
- new import_fixparser.Field(import_fixparser.Fields.MDEntryType, mdEntryType)
458
- );
459
- if (!this.parser?.connected) {
460
- this.logger?.log({
461
- level: "error",
462
- message: "FIXParser (MCP): -- Not connected. Ignoring message."
463
- });
464
- return {
465
- isError: true,
466
- content: [
467
- {
468
- type: "text",
469
- text: "Error: Not connected. Ignoring message."
470
- }
471
- ]
472
- };
473
- }
474
- this.parser?.send(marketDataRequest);
475
- this.logger?.log({
476
- level: "info",
477
- message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${marketDataRequest?.description}`
478
- });
479
- const fixData = await response;
480
- return {
481
- content: [
482
- {
483
- type: "text",
484
- text: `Market data for ${symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
485
- }
486
- ]
487
- };
488
- } catch (error) {
489
- return {
490
- isError: true,
491
- content: [
492
- {
493
- type: "text",
494
- text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
495
- }
496
- ]
497
- };
498
- }
499
- }
500
- default:
501
- throw new Error(`Unknown tool: ${name}`);
502
- }
503
- });
504
- this.server.setRequestHandler(import_types.ListPromptsRequestSchema, async () => {
505
- return {
506
- prompts: [
507
- {
508
- name: "parse",
509
- description: "Parses a FIX message and describes it in plain language",
510
- arguments: [
511
- {
512
- name: "fixString",
513
- description: "FIX message string to parse",
514
- required: true
515
- }
516
- ]
517
- },
518
- {
519
- name: "parseToJSON",
520
- description: "Parses a FIX message into JSON",
521
- arguments: [
522
- {
523
- name: "fixString",
524
- description: "FIX message string to parse",
525
- required: true
526
- }
527
- ]
528
- },
529
- {
530
- name: "newOrderSingle",
531
- description: "Creates and sends a New Order Single",
532
- arguments: [
533
- {
534
- name: "clOrdID",
535
- description: "Client Order ID",
536
- required: true
537
- },
538
- {
539
- name: "handlInst",
540
- description: "Handling instruction",
541
- required: false
542
- },
543
- {
544
- name: "quantity",
545
- description: "Order quantity",
546
- required: true
547
- },
548
- {
549
- name: "price",
550
- description: "Order price",
551
- required: true
552
- },
553
- {
554
- name: "ordType",
555
- description: "Order type",
556
- required: false
557
- },
558
- {
559
- name: "side",
560
- description: "Order side (1=Buy, 2=Sell)",
561
- required: true
562
- },
563
- {
564
- name: "symbol",
565
- description: "Trading symbol",
566
- required: true
567
- },
568
- {
569
- name: "timeInForce",
570
- description: "Time in force",
571
- required: false
572
- }
573
- ]
574
- },
575
- {
576
- name: "marketDataRequest",
577
- description: "Sends a request for Market Data with the given symbol",
578
- arguments: [
579
- {
580
- name: "mdUpdateType",
581
- description: "Market data update type",
582
- required: false
583
- },
584
- {
585
- name: "symbol",
586
- description: "Trading symbol",
587
- required: true
588
- },
589
- {
590
- name: "mdReqID",
591
- description: "Market data request ID",
592
- required: true
593
- },
594
- {
595
- name: "subscriptionRequestType",
596
- description: "Subscription request type",
597
- required: false
598
- },
599
- {
600
- name: "mdEntryType",
601
- description: "Market data entry type",
602
- required: false
603
- }
604
- ]
605
- }
606
- ]
607
- };
608
- });
609
- this.server.setRequestHandler(import_types.GetPromptRequestSchema, async (request) => {
610
- const { name, arguments: args } = request.params;
611
- switch (name) {
612
- case "parse": {
613
- const fixString = args?.fixString || "";
614
- return {
615
- messages: [
616
- {
617
- role: "user",
618
- content: {
619
- type: "text",
620
- text: `Please parse and explain this FIX message: ${fixString}`
621
- }
622
- }
623
- ]
624
- };
625
- }
626
- case "parseToJSON": {
627
- const fixString = args?.fixString || "";
930
+ );
931
+ this.server.setRequestHandler(
932
+ import_zod.z.object({
933
+ method: import_zod.z.literal("tools/call"),
934
+ params: import_zod.z.object({
935
+ name: import_zod.z.string(),
936
+ arguments: import_zod.z.any(),
937
+ _meta: import_zod.z.object({
938
+ progressToken: import_zod.z.number()
939
+ }).optional()
940
+ })
941
+ }),
942
+ async (request, extra) => {
943
+ const { name, arguments: args } = request.params;
944
+ const toolHandlers = createToolHandlers(
945
+ this.parser,
946
+ this.verifiedOrders,
947
+ this.pendingRequests,
948
+ this.marketDataPrices
949
+ );
950
+ const handler = toolHandlers[name];
951
+ if (!handler) {
628
952
  return {
629
- messages: [
953
+ content: [
630
954
  {
631
- role: "user",
632
- content: {
633
- type: "text",
634
- text: `Please parse the FIX message to JSON: ${fixString}`
635
- }
955
+ type: "text",
956
+ text: `Tool not found: ${name}`,
957
+ uri: name
636
958
  }
637
- ]
959
+ ],
960
+ isError: true
638
961
  };
639
962
  }
640
- case "newOrderSingle": {
641
- const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = args || {};
642
- return {
643
- messages: [
644
- {
645
- role: "user",
646
- content: {
647
- type: "text",
648
- text: [
649
- "Create a New Order Single FIX message with the following parameters:",
650
- `- ClOrdID: ${clOrdID}`,
651
- `- HandlInst: ${handlInst ?? "default"}`,
652
- `- Quantity: ${quantity}`,
653
- `- Price: ${price}`,
654
- `- OrdType: ${ordType ?? "default (Market)"}`,
655
- `- Side: ${side}`,
656
- `- Symbol: ${symbol}`,
657
- `- TimeInForce: ${timeInForce ?? "default (Day)"}`,
658
- "",
659
- "Format the response as a JSON object with FIX tag numbers as keys and their corresponding values."
660
- ].join("\n")
661
- }
662
- }
663
- ]
664
- };
665
- }
666
- case "marketDataRequest": {
667
- const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = args || {};
668
- return {
669
- messages: [
670
- {
671
- role: "user",
672
- content: {
673
- type: "text",
674
- text: [
675
- "Create a Market Data Request FIX message with the following parameters:",
676
- `- MDUpdateType: ${mdUpdateType ?? "default (0 = FullRefresh)"}`,
677
- `- Symbol: ${symbol}`,
678
- `- MDReqID: ${mdReqID}`,
679
- `- SubscriptionRequestType: ${subscriptionRequestType ?? "default (0 = Snapshot + Updates)"}`,
680
- `- MDEntryType: ${mdEntryType ?? "default (0 = Bid)"}`,
681
- "",
682
- "Format the response as a JSON object with FIX tag numbers as keys and their corresponding values."
683
- ].join("\n")
684
- }
685
- }
686
- ]
687
- };
688
- }
689
- default:
690
- throw new Error(`Unknown prompt: ${name}`);
963
+ const result = await handler(args);
964
+ return {
965
+ content: result.content,
966
+ isError: result.isError
967
+ };
691
968
  }
692
- });
969
+ );
693
970
  process.on("SIGINT", async () => {
694
971
  await this.server.close();
695
972
  process.exit(0);