fixparser-plugin-mcp 9.1.7-b2bba224 → 9.1.7-b386e09a

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