fixparser-plugin-mcp 9.1.7-fe71108a → 9.1.7-ff35b2c1

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