fixparser-plugin-mcp 9.1.7-148b599b → 9.1.7-1736d80f

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