fixparser-plugin-mcp 9.1.7-3c6fd297 → 9.1.7-3f807208

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,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
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
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/MCPRemote.ts
@@ -39,877 +29,29 @@ var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
39
29
  var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
40
30
  var import_types = require("@modelcontextprotocol/sdk/types.js");
41
31
  var import_zod = require("zod");
42
-
43
- // src/MCPBase.ts
44
- var MCPBase = class {
32
+ var import_fixparser = require("fixparser");
33
+ var transports = {};
34
+ var MCPRemote = class {
35
+ /**
36
+ * Port number the server will listen on.
37
+ * @private
38
+ */
39
+ port;
45
40
  /**
46
41
  * Optional logger instance for diagnostics and output.
47
- * @protected
42
+ * @private
48
43
  */
49
44
  logger;
50
45
  /**
51
46
  * FIXParser instance, set during plugin register().
52
- * @protected
53
- */
54
- parser;
55
- /**
56
- * Called when server is setup and listening.
57
- * @protected
58
- */
59
- onReady = void 0;
60
- /**
61
- * Map to store verified orders before execution
62
- * @protected
63
- */
64
- verifiedOrders = /* @__PURE__ */ new Map();
65
- /**
66
- * Map to store pending market data requests
67
- * @protected
68
- */
69
- pendingRequests = /* @__PURE__ */ new Map();
70
- /**
71
- * Map to store market data prices
72
- * @protected
73
- */
74
- marketDataPrices = /* @__PURE__ */ new Map();
75
- /**
76
- * Maximum number of price history entries to keep per symbol
77
- * @protected
78
- */
79
- MAX_PRICE_HISTORY = 1e5;
80
- constructor({ logger, onReady }) {
81
- this.logger = logger;
82
- this.onReady = onReady;
83
- }
84
- };
85
-
86
- // src/schemas/schemas.ts
87
- var toolSchemas = {
88
- parse: {
89
- description: "Parses a FIX message and describes it in plain language",
90
- schema: {
91
- type: "object",
92
- properties: {
93
- fixString: { type: "string" }
94
- },
95
- required: ["fixString"]
96
- }
97
- },
98
- parseToJSON: {
99
- description: "Parses a FIX message into JSON",
100
- schema: {
101
- type: "object",
102
- properties: {
103
- fixString: { type: "string" }
104
- },
105
- required: ["fixString"]
106
- }
107
- },
108
- verifyOrder: {
109
- description: "Verifies order parameters before execution. verifyOrder must be called before executeOrder.",
110
- schema: {
111
- type: "object",
112
- properties: {
113
- clOrdID: { type: "string" },
114
- handlInst: {
115
- type: "string",
116
- enum: ["1", "2", "3"],
117
- description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
118
- },
119
- quantity: { type: "string" },
120
- price: { type: "string" },
121
- ordType: {
122
- type: "string",
123
- enum: [
124
- "1",
125
- "2",
126
- "3",
127
- "4",
128
- "5",
129
- "6",
130
- "7",
131
- "8",
132
- "9",
133
- "A",
134
- "B",
135
- "C",
136
- "D",
137
- "E",
138
- "F",
139
- "G",
140
- "H",
141
- "I",
142
- "J",
143
- "K",
144
- "L",
145
- "M",
146
- "P",
147
- "Q",
148
- "R",
149
- "S"
150
- ],
151
- 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"
152
- },
153
- side: {
154
- type: "string",
155
- enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
156
- 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"
157
- },
158
- symbol: { type: "string" },
159
- timeInForce: {
160
- type: "string",
161
- enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
162
- 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"
163
- }
164
- },
165
- required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
166
- }
167
- },
168
- executeOrder: {
169
- description: "Executes a verified order. verifyOrder must be called before executeOrder. user has to explicitly allow executeOrder.",
170
- schema: {
171
- type: "object",
172
- properties: {
173
- clOrdID: { type: "string" },
174
- handlInst: {
175
- type: "string",
176
- enum: ["1", "2", "3"],
177
- description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
178
- },
179
- quantity: { type: "string" },
180
- price: { type: "string" },
181
- ordType: {
182
- type: "string",
183
- enum: [
184
- "1",
185
- "2",
186
- "3",
187
- "4",
188
- "5",
189
- "6",
190
- "7",
191
- "8",
192
- "9",
193
- "A",
194
- "B",
195
- "C",
196
- "D",
197
- "E",
198
- "F",
199
- "G",
200
- "H",
201
- "I",
202
- "J",
203
- "K",
204
- "L",
205
- "M",
206
- "P",
207
- "Q",
208
- "R",
209
- "S"
210
- ],
211
- 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"
212
- },
213
- side: {
214
- type: "string",
215
- enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
216
- 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"
217
- },
218
- symbol: { type: "string" },
219
- timeInForce: {
220
- type: "string",
221
- enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
222
- 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"
223
- }
224
- },
225
- required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
226
- }
227
- },
228
- marketDataRequest: {
229
- description: "Requests market data for specified symbols",
230
- schema: {
231
- type: "object",
232
- properties: {
233
- mdUpdateType: {
234
- type: "string",
235
- enum: ["0", "1"],
236
- description: "Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"
237
- },
238
- symbols: { type: "array", items: { type: "string" } },
239
- mdReqID: { type: "string" },
240
- subscriptionRequestType: {
241
- type: "string",
242
- enum: ["0", "1", "2"],
243
- description: "Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"
244
- },
245
- mdEntryTypes: {
246
- type: "array",
247
- items: {
248
- type: "string",
249
- enum: [
250
- "0",
251
- "1",
252
- "2",
253
- "3",
254
- "4",
255
- "5",
256
- "6",
257
- "7",
258
- "8",
259
- "9",
260
- "A",
261
- "B",
262
- "C",
263
- "D",
264
- "E",
265
- "F",
266
- "G",
267
- "H",
268
- "I",
269
- "J",
270
- "K",
271
- "L",
272
- "M",
273
- "N",
274
- "O",
275
- "P",
276
- "Q",
277
- "R",
278
- "S",
279
- "T",
280
- "U",
281
- "V",
282
- "W",
283
- "X",
284
- "Y",
285
- "Z"
286
- ]
287
- },
288
- 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"
289
- }
290
- },
291
- required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType"]
292
- }
293
- },
294
- getStockGraph: {
295
- description: "Generates a price chart for a given symbol",
296
- schema: {
297
- type: "object",
298
- properties: {
299
- symbol: { type: "string" }
300
- },
301
- required: ["symbol"]
302
- }
303
- },
304
- getStockPriceHistory: {
305
- description: "Returns price history for a given symbol",
306
- schema: {
307
- type: "object",
308
- properties: {
309
- symbol: { type: "string" }
310
- },
311
- required: ["symbol"]
312
- }
313
- }
314
- };
315
-
316
- // src/tools/marketData.ts
317
- var import_fixparser = require("fixparser");
318
- var import_quickchart_js = __toESM(require("quickchart-js"), 1);
319
- var createMarketDataRequestHandler = (parser, pendingRequests) => {
320
- return async (args) => {
321
- try {
322
- const response = new Promise((resolve) => {
323
- pendingRequests.set(args.mdReqID, resolve);
324
- });
325
- const entryTypes = args.mdEntryTypes || [import_fixparser.MDEntryType.Bid, import_fixparser.MDEntryType.Offer, import_fixparser.MDEntryType.TradeVolume];
326
- const messageFields = [
327
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
328
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
329
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
330
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
331
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
332
- new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
333
- new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
334
- new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
335
- new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
336
- ];
337
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
338
- args.symbols.forEach((symbol) => {
339
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
340
- });
341
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, entryTypes.length));
342
- entryTypes.forEach((entryType) => {
343
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
344
- });
345
- const mdr = parser.createMessage(...messageFields);
346
- if (!parser.connected) {
347
- return {
348
- content: [
349
- {
350
- type: "text",
351
- text: "Error: Not connected. Ignoring message.",
352
- uri: "marketDataRequest"
353
- }
354
- ],
355
- isError: true
356
- };
357
- }
358
- parser.send(mdr);
359
- const fixData = await response;
360
- return {
361
- content: [
362
- {
363
- type: "text",
364
- text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
365
- uri: "marketDataRequest"
366
- }
367
- ]
368
- };
369
- } catch (error) {
370
- return {
371
- content: [
372
- {
373
- type: "text",
374
- text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
375
- uri: "marketDataRequest"
376
- }
377
- ],
378
- isError: true
379
- };
380
- }
381
- };
382
- };
383
- var createGetStockGraphHandler = (marketDataPrices) => {
384
- return async (args) => {
385
- try {
386
- const symbol = args.symbol;
387
- const priceHistory = marketDataPrices.get(symbol) || [];
388
- if (priceHistory.length === 0) {
389
- return {
390
- content: [
391
- {
392
- type: "text",
393
- text: `No price data available for ${symbol}`,
394
- uri: "getStockGraph"
395
- }
396
- ]
397
- };
398
- }
399
- const chart = new import_quickchart_js.default();
400
- chart.setWidth(1200);
401
- chart.setHeight(600);
402
- chart.setBackgroundColor("transparent");
403
- const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
404
- const bidData = priceHistory.map((point) => point.bid);
405
- const offerData = priceHistory.map((point) => point.offer);
406
- const spreadData = priceHistory.map((point) => point.spread);
407
- const volumeData = priceHistory.map((point) => point.volume);
408
- const config = {
409
- type: "line",
410
- data: {
411
- labels,
412
- datasets: [
413
- {
414
- label: "Bid",
415
- data: bidData,
416
- borderColor: "#28a745",
417
- backgroundColor: "rgba(40, 167, 69, 0.1)",
418
- fill: false,
419
- tension: 0.4
420
- },
421
- {
422
- label: "Offer",
423
- data: offerData,
424
- borderColor: "#dc3545",
425
- backgroundColor: "rgba(220, 53, 69, 0.1)",
426
- fill: false,
427
- tension: 0.4
428
- },
429
- {
430
- label: "Spread",
431
- data: spreadData,
432
- borderColor: "#6c757d",
433
- backgroundColor: "rgba(108, 117, 125, 0.1)",
434
- fill: false,
435
- tension: 0.4
436
- },
437
- {
438
- label: "Volume",
439
- data: volumeData,
440
- borderColor: "#007bff",
441
- backgroundColor: "rgba(0, 123, 255, 0.1)",
442
- fill: true,
443
- tension: 0.4
444
- }
445
- ]
446
- },
447
- options: {
448
- responsive: true,
449
- plugins: {
450
- title: {
451
- display: true,
452
- text: `${symbol} Market Data`
453
- }
454
- },
455
- scales: {
456
- y: {
457
- beginAtZero: false
458
- }
459
- }
460
- }
461
- };
462
- chart.setConfig(config);
463
- const imageBuffer = await chart.toBinary();
464
- const base64 = imageBuffer.toString("base64");
465
- return {
466
- content: [
467
- {
468
- type: "resource",
469
- resource: {
470
- uri: "resource://graph",
471
- mimeType: "image/png",
472
- blob: base64
473
- }
474
- }
475
- ]
476
- };
477
- } catch (error) {
478
- return {
479
- content: [
480
- {
481
- type: "text",
482
- text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
483
- uri: "getStockGraph"
484
- }
485
- ],
486
- isError: true
487
- };
488
- }
489
- };
490
- };
491
- var createGetStockPriceHistoryHandler = (marketDataPrices) => {
492
- return async (args) => {
493
- try {
494
- const symbol = args.symbol;
495
- const priceHistory = marketDataPrices.get(symbol) || [];
496
- if (priceHistory.length === 0) {
497
- return {
498
- content: [
499
- {
500
- type: "text",
501
- text: `No price data available for ${symbol}`,
502
- uri: "getStockPriceHistory"
503
- }
504
- ]
505
- };
506
- }
507
- return {
508
- content: [
509
- {
510
- type: "text",
511
- text: JSON.stringify(
512
- {
513
- symbol,
514
- count: priceHistory.length,
515
- data: priceHistory.map((point) => ({
516
- timestamp: new Date(point.timestamp).toISOString(),
517
- bid: point.bid,
518
- offer: point.offer,
519
- spread: point.spread,
520
- volume: point.volume
521
- }))
522
- },
523
- null,
524
- 2
525
- ),
526
- uri: "getStockPriceHistory"
527
- }
528
- ]
529
- };
530
- } catch (error) {
531
- return {
532
- content: [
533
- {
534
- type: "text",
535
- text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
536
- uri: "getStockPriceHistory"
537
- }
538
- ],
539
- isError: true
540
- };
541
- }
542
- };
543
- };
544
-
545
- // src/tools/order.ts
546
- var import_fixparser2 = require("fixparser");
547
- var ordTypeNames = {
548
- "1": "Market",
549
- "2": "Limit",
550
- "3": "Stop",
551
- "4": "StopLimit",
552
- "5": "MarketOnClose",
553
- "6": "WithOrWithout",
554
- "7": "LimitOrBetter",
555
- "8": "LimitWithOrWithout",
556
- "9": "OnBasis",
557
- A: "OnClose",
558
- B: "LimitOnClose",
559
- C: "ForexMarket",
560
- D: "PreviouslyQuoted",
561
- E: "PreviouslyIndicated",
562
- F: "ForexLimit",
563
- G: "ForexSwap",
564
- H: "ForexPreviouslyQuoted",
565
- I: "Funari",
566
- J: "MarketIfTouched",
567
- K: "MarketWithLeftOverAsLimit",
568
- L: "PreviousFundValuationPoint",
569
- M: "NextFundValuationPoint",
570
- P: "Pegged",
571
- Q: "CounterOrderSelection",
572
- R: "StopOnBidOrOffer",
573
- S: "StopLimitOnBidOrOffer"
574
- };
575
- var sideNames = {
576
- "1": "Buy",
577
- "2": "Sell",
578
- "3": "BuyMinus",
579
- "4": "SellPlus",
580
- "5": "SellShort",
581
- "6": "SellShortExempt",
582
- "7": "Undisclosed",
583
- "8": "Cross",
584
- "9": "CrossShort",
585
- A: "CrossShortExempt",
586
- B: "AsDefined",
587
- C: "Opposite",
588
- D: "Subscribe",
589
- E: "Redeem",
590
- F: "Lend",
591
- G: "Borrow",
592
- H: "SellUndisclosed"
593
- };
594
- var timeInForceNames = {
595
- "0": "Day",
596
- "1": "GoodTillCancel",
597
- "2": "AtTheOpening",
598
- "3": "ImmediateOrCancel",
599
- "4": "FillOrKill",
600
- "5": "GoodTillCrossing",
601
- "6": "GoodTillDate",
602
- "7": "AtTheClose",
603
- "8": "GoodThroughCrossing",
604
- "9": "AtCrossing",
605
- A: "GoodForTime",
606
- B: "GoodForAuction",
607
- C: "GoodForMonth"
608
- };
609
- var handlInstNames = {
610
- "1": "AutomatedExecutionNoIntervention",
611
- "2": "AutomatedExecutionInterventionOK",
612
- "3": "ManualOrder"
613
- };
614
- var createVerifyOrderHandler = (parser, verifiedOrders) => {
615
- return async (args) => {
616
- try {
617
- verifiedOrders.set(args.clOrdID, {
618
- clOrdID: args.clOrdID,
619
- handlInst: args.handlInst,
620
- quantity: Number.parseFloat(String(args.quantity)),
621
- price: Number.parseFloat(String(args.price)),
622
- ordType: args.ordType,
623
- side: args.side,
624
- symbol: args.symbol,
625
- timeInForce: args.timeInForce
626
- });
627
- return {
628
- content: [
629
- {
630
- type: "text",
631
- text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
632
-
633
- Parameters verified:
634
- - ClOrdID: ${args.clOrdID}
635
- - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
636
- - Quantity: ${args.quantity}
637
- - Price: ${args.price}
638
- - OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
639
- - Side: ${args.side} (${sideNames[args.side]})
640
- - Symbol: ${args.symbol}
641
- - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
642
-
643
- To execute this order, call the executeOrder tool with these exact same parameters.`,
644
- uri: "verifyOrder"
645
- }
646
- ]
647
- };
648
- } catch (error) {
649
- return {
650
- content: [
651
- {
652
- type: "text",
653
- text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
654
- uri: "verifyOrder"
655
- }
656
- ],
657
- isError: true
658
- };
659
- }
660
- };
661
- };
662
- var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
663
- return async (args) => {
664
- try {
665
- const verifiedOrder = verifiedOrders.get(args.clOrdID);
666
- if (!verifiedOrder) {
667
- return {
668
- content: [
669
- {
670
- type: "text",
671
- text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
672
- uri: "executeOrder"
673
- }
674
- ],
675
- isError: true
676
- };
677
- }
678
- 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) {
679
- return {
680
- content: [
681
- {
682
- type: "text",
683
- text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
684
- uri: "executeOrder"
685
- }
686
- ],
687
- isError: true
688
- };
689
- }
690
- const response = new Promise((resolve) => {
691
- pendingRequests.set(args.clOrdID, resolve);
692
- });
693
- const order = parser.createMessage(
694
- new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
695
- new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
696
- new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
697
- new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
698
- new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
699
- new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
700
- new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
701
- new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
702
- new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
703
- new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
704
- new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
705
- new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
706
- new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
707
- new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
708
- );
709
- if (!parser.connected) {
710
- return {
711
- content: [
712
- {
713
- type: "text",
714
- text: "Error: Not connected. Ignoring message.",
715
- uri: "executeOrder"
716
- }
717
- ],
718
- isError: true
719
- };
720
- }
721
- parser.send(order);
722
- const fixData = await response;
723
- verifiedOrders.delete(args.clOrdID);
724
- return {
725
- content: [
726
- {
727
- type: "text",
728
- 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())}`,
729
- uri: "executeOrder"
730
- }
731
- ]
732
- };
733
- } catch (error) {
734
- return {
735
- content: [
736
- {
737
- type: "text",
738
- text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
739
- uri: "executeOrder"
740
- }
741
- ],
742
- isError: true
743
- };
744
- }
745
- };
746
- };
747
-
748
- // src/tools/parse.ts
749
- var createParseHandler = (parser) => {
750
- return async (args) => {
751
- try {
752
- const parsedMessage = parser.parse(args.fixString);
753
- if (!parsedMessage || parsedMessage.length === 0) {
754
- return {
755
- content: [
756
- {
757
- type: "text",
758
- text: "Error: Failed to parse FIX string",
759
- uri: "parse"
760
- }
761
- ],
762
- isError: true
763
- };
764
- }
765
- return {
766
- content: [
767
- {
768
- type: "text",
769
- text: `${parsedMessage[0].description}
770
- ${parsedMessage[0].messageTypeDescription}`,
771
- uri: "parse"
772
- }
773
- ]
774
- };
775
- } catch (error) {
776
- return {
777
- content: [
778
- {
779
- type: "text",
780
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
781
- uri: "parse"
782
- }
783
- ],
784
- isError: true
785
- };
786
- }
787
- };
788
- };
789
-
790
- // src/tools/parseToJSON.ts
791
- var createParseToJSONHandler = (parser) => {
792
- return async (args) => {
793
- try {
794
- const parsedMessage = parser.parse(args.fixString);
795
- if (!parsedMessage || parsedMessage.length === 0) {
796
- return {
797
- content: [
798
- {
799
- type: "text",
800
- text: "Error: Failed to parse FIX string",
801
- uri: "parseToJSON"
802
- }
803
- ],
804
- isError: true
805
- };
806
- }
807
- return {
808
- content: [
809
- {
810
- type: "text",
811
- text: `${parsedMessage[0].toFIXJSON()}`,
812
- uri: "parseToJSON"
813
- }
814
- ]
815
- };
816
- } catch (error) {
817
- return {
818
- content: [
819
- {
820
- type: "text",
821
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
822
- uri: "parseToJSON"
823
- }
824
- ],
825
- isError: true
826
- };
827
- }
828
- };
829
- };
830
-
831
- // src/tools/index.ts
832
- var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
833
- parse: createParseHandler(parser),
834
- parseToJSON: createParseToJSONHandler(parser),
835
- verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
836
- executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
837
- marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
838
- getStockGraph: createGetStockGraphHandler(marketDataPrices),
839
- getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
840
- });
841
-
842
- // src/utils/messageHandler.ts
843
- var import_fixparser3 = require("fixparser");
844
- function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPriceHistory, onPriceUpdate) {
845
- parser.logger.log({
846
- level: "info",
847
- message: `MCP Server received message: ${message.messageType}: ${message.description}`
848
- });
849
- const msgType = message.messageType;
850
- if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
851
- const symbol = message.getField(import_fixparser3.Fields.Symbol)?.value;
852
- const entries = message.getField(import_fixparser3.Fields.NoMDEntries)?.value;
853
- let bid = 0;
854
- let offer = 0;
855
- let volume = 0;
856
- const entryTypes = message.getFields(import_fixparser3.Fields.MDEntryType);
857
- const entryPrices = message.getFields(import_fixparser3.Fields.MDEntryPx);
858
- const entrySizes = message.getFields(import_fixparser3.Fields.MDEntrySize);
859
- if (entryTypes && entryPrices && entrySizes) {
860
- for (let i = 0; i < entries; i++) {
861
- const entryType = entryTypes[i]?.value;
862
- const entryPrice = Number.parseFloat(entryPrices[i]?.value);
863
- const entrySize = Number.parseFloat(entrySizes[i]?.value);
864
- if (entryType === import_fixparser3.MDEntryType.Bid) {
865
- bid = entryPrice;
866
- } else if (entryType === import_fixparser3.MDEntryType.Offer) {
867
- offer = entryPrice;
868
- }
869
- volume += entrySize;
870
- }
871
- }
872
- const spread = offer - bid;
873
- const timestamp = Date.now();
874
- const data = {
875
- timestamp,
876
- bid,
877
- offer,
878
- spread,
879
- volume
880
- };
881
- if (!marketDataPrices.has(symbol)) {
882
- marketDataPrices.set(symbol, []);
883
- }
884
- const prices = marketDataPrices.get(symbol);
885
- prices.push(data);
886
- if (prices.length > maxPriceHistory) {
887
- prices.splice(0, prices.length - maxPriceHistory);
888
- }
889
- onPriceUpdate?.(symbol, data);
890
- } else if (msgType === import_fixparser3.Messages.ExecutionReport) {
891
- const reqId = message.getField(import_fixparser3.Fields.ClOrdID)?.value;
892
- const callback = pendingRequests.get(reqId);
893
- if (callback) {
894
- callback(message);
895
- pendingRequests.delete(reqId);
896
- }
897
- }
898
- }
899
-
900
- // src/MCPRemote.ts
901
- var transports = {};
902
- var MCPRemote = class extends MCPBase {
903
- /**
904
- * Port number the server will listen on.
905
47
  * @private
906
48
  */
907
- port;
49
+ parser;
908
50
  /**
909
51
  * Node.js HTTP server instance created internally.
910
52
  * @private
911
53
  */
912
- httpServer;
54
+ server;
913
55
  /**
914
56
  * MCP server instance handling MCP protocol logic.
915
57
  * @private
@@ -919,85 +61,89 @@ var MCPRemote = class extends MCPBase {
919
61
  * Optional name of the plugin/server instance.
920
62
  * @private
921
63
  */
922
- serverName;
64
+ name;
923
65
  /**
924
66
  * Optional version string of the plugin/server.
925
67
  * @private
926
68
  */
927
- serverVersion;
69
+ version;
928
70
  /**
929
- * Map to store verified orders before execution
71
+ * Called when server is setup and listening.
930
72
  * @private
931
73
  */
932
- verifiedOrders = /* @__PURE__ */ new Map();
74
+ onReady = void 0;
933
75
  /**
934
- * Map to store pending requests and their callbacks
76
+ * A map of pending market data requests, keyed by MDReqID.
77
+ * Each entry contains a resolver function that is called when the corresponding
78
+ * FIX Message is received.
935
79
  * @private
80
+ * @type {Map<string, (data: Message) => void>}
936
81
  */
937
82
  pendingRequests = /* @__PURE__ */ new Map();
938
- /**
939
- * Map to store market data prices for each symbol
940
- * @private
941
- */
942
- marketDataPrices = /* @__PURE__ */ new Map();
943
- /**
944
- * Maximum number of price points to store per symbol
945
- * @private
946
- */
947
- MAX_PRICE_HISTORY = 1e5;
948
83
  constructor({ port, logger, onReady }) {
949
- super({ logger, onReady });
950
84
  this.port = port;
85
+ if (logger) this.logger = logger;
86
+ if (onReady) this.onReady = onReady;
951
87
  }
952
88
  async register(parser) {
953
89
  this.parser = parser;
90
+ this.parser.addOnMessageCallback((message) => {
91
+ this.logger?.log({
92
+ level: "info",
93
+ message: `FIXParser (MCP): (${parser.protocol?.toUpperCase()}): << received ${message.description}`
94
+ });
95
+ const msgType = message.messageType;
96
+ if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport) {
97
+ const idField = msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh ? message.getField(import_fixparser.Fields.MDReqID) : message.getField(import_fixparser.Fields.ClOrdID);
98
+ if (idField) {
99
+ const id = idField.value;
100
+ if (typeof id === "string" || typeof id === "number") {
101
+ const callback = this.pendingRequests.get(String(id));
102
+ if (callback) {
103
+ callback(message);
104
+ this.pendingRequests.delete(String(id));
105
+ }
106
+ }
107
+ }
108
+ }
109
+ });
954
110
  this.logger = parser.logger;
955
111
  this.logger?.log({
956
112
  level: "info",
957
113
  message: `FIXParser (MCP): -- Plugin registered. Creating MCP server on port ${this.port}...`
958
114
  });
959
- this.parser.addOnMessageCallback((message) => {
960
- if (this.parser) {
961
- handleMessage(
962
- message,
963
- this.parser,
964
- this.pendingRequests,
965
- this.marketDataPrices,
966
- this.MAX_PRICE_HISTORY,
967
- (symbol, data) => {
968
- this.mcpServer?.tool(
969
- "priceUpdate",
970
- {
971
- description: "Price update notification",
972
- schema: import_zod.z.object({
973
- symbol: import_zod.z.string(),
974
- timestamp: import_zod.z.number(),
975
- bid: import_zod.z.number(),
976
- offer: import_zod.z.number(),
977
- spread: import_zod.z.number(),
978
- volume: import_zod.z.number()
979
- })
980
- },
981
- () => ({
982
- content: [
983
- {
984
- type: "text",
985
- text: JSON.stringify({ symbol, ...data })
986
- }
987
- ]
988
- })
989
- );
990
- }
991
- );
992
- }
993
- });
994
- this.httpServer = (0, import_node_http.createServer)(async (req, res) => {
115
+ this.server = (0, import_node_http.createServer)(async (req, res) => {
995
116
  if (!req.url || !req.method) {
996
117
  res.writeHead(400);
997
118
  res.end("Bad Request");
998
119
  return;
999
120
  }
1000
- if (req.url === "/mcp") {
121
+ const url = new URL(req.url, `http://${req.headers.host}`);
122
+ if (url.pathname === "/.well-known/oauth-authorization-server") {
123
+ const config = {
124
+ issuer: "https://accounts.google.com",
125
+ authorization_endpoint: "https://accounts.google.com/o/oauth2/v2/auth",
126
+ token_endpoint: "https://oauth2.googleapis.com/token",
127
+ jwks_uri: "https://www.googleapis.com/oauth2/v3/certs",
128
+ response_types_supported: [
129
+ "code",
130
+ "token",
131
+ "id_token",
132
+ "code token",
133
+ "code id_token",
134
+ "token id_token",
135
+ "code token id_token"
136
+ ],
137
+ subject_types_supported: ["public"],
138
+ id_token_signing_alg_values_supported: ["RS256"],
139
+ scopes_supported: ["openid", "email", "profile"],
140
+ token_endpoint_auth_methods_supported: ["client_secret_basic", "client_secret_post"]
141
+ };
142
+ res.writeHead(200, { "Content-Type": "application/json" });
143
+ res.end(JSON.stringify(config));
144
+ return;
145
+ }
146
+ if (url.pathname === "/") {
1001
147
  const sessionId = req.headers["mcp-session-id"];
1002
148
  if (req.method === "POST") {
1003
149
  const bodyChunks = [];
@@ -1030,10 +176,10 @@ var MCPRemote = class extends MCPBase {
1030
176
  }
1031
177
  };
1032
178
  this.mcpServer = new import_mcp.McpServer({
1033
- name: this.serverName || "FIXParser",
1034
- version: this.serverVersion || "1.0.0"
179
+ name: this.name || "FIXParser",
180
+ version: this.version || "1.0.0"
1035
181
  });
1036
- this.setupTools();
182
+ this.addWorkflows();
1037
183
  await this.mcpServer.connect(transport);
1038
184
  } else {
1039
185
  res.writeHead(400, { "Content-Type": "application/json" });
@@ -1063,12 +209,12 @@ var MCPRemote = class extends MCPBase {
1063
209
  res.writeHead(405);
1064
210
  res.end("Method Not Allowed");
1065
211
  }
1066
- } else {
1067
- res.writeHead(404);
1068
- res.end("Not Found");
212
+ return;
1069
213
  }
214
+ res.writeHead(404);
215
+ res.end("Not Found");
1070
216
  });
1071
- this.httpServer.listen(this.port, () => {
217
+ this.server.listen(this.port, () => {
1072
218
  this.logger?.log({
1073
219
  level: "info",
1074
220
  message: `FIXParser (MCP): -- Server listening on http://localhost:${this.port}...`
@@ -1078,84 +224,381 @@ var MCPRemote = class extends MCPBase {
1078
224
  this.onReady();
1079
225
  }
1080
226
  }
1081
- setupTools() {
227
+ addWorkflows() {
1082
228
  if (!this.parser) {
1083
229
  this.logger?.log({
1084
230
  level: "error",
1085
- message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of tools..."
231
+ message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of workflows..."
1086
232
  });
1087
233
  return;
1088
234
  }
1089
235
  if (!this.mcpServer) {
1090
236
  this.logger?.log({
1091
237
  level: "error",
1092
- message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of tools..."
238
+ message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of workflows..."
1093
239
  });
1094
240
  return;
1095
241
  }
1096
242
  this.mcpServer.tool(
1097
- "tools/list",
243
+ "parse",
244
+ "Parses a FIX message and describes it in plain language",
245
+ { fixString: import_zod.z.string() },
246
+ async ({ fixString }) => {
247
+ const parsedMessage = this.parser?.parse(fixString);
248
+ if (!parsedMessage || parsedMessage.length === 0) {
249
+ this.logger?.log({
250
+ level: "error",
251
+ message: "FIXParser (MCP): -- Failed to parse FIX string"
252
+ });
253
+ return {
254
+ isError: true,
255
+ content: [
256
+ {
257
+ type: "text",
258
+ text: "Error: Failed to parse FIX string"
259
+ }
260
+ ]
261
+ };
262
+ }
263
+ return {
264
+ content: [
265
+ {
266
+ type: "text",
267
+ text: parsedMessage ? `${parsedMessage[0].description} - ${parsedMessage[0].messageTypeDescription}` : ""
268
+ }
269
+ ]
270
+ };
271
+ }
272
+ );
273
+ this.mcpServer.prompt(
274
+ "parse",
275
+ "Parses a FIX message and describes it in plain language",
276
+ { fixString: import_zod.z.string() },
277
+ ({ fixString }) => ({
278
+ messages: [
279
+ {
280
+ role: "user",
281
+ content: {
282
+ type: "text",
283
+ text: `Please parse and explain this FIX message: ${fixString}`
284
+ }
285
+ }
286
+ ]
287
+ })
288
+ );
289
+ this.mcpServer.tool(
290
+ "parseToJSON",
291
+ "Parses a FIX message into JSON",
292
+ { fixString: import_zod.z.string() },
293
+ async ({ fixString }) => {
294
+ const parsedMessage = this.parser?.parse(fixString);
295
+ if (!parsedMessage || parsedMessage.length === 0) {
296
+ this.logger?.log({
297
+ level: "error",
298
+ message: "FIXParser (MCP): -- Failed to parse FIX string"
299
+ });
300
+ return {
301
+ isError: true,
302
+ content: [
303
+ {
304
+ type: "text",
305
+ text: "Error: Failed to parse FIX string"
306
+ }
307
+ ]
308
+ };
309
+ }
310
+ return {
311
+ content: [
312
+ {
313
+ type: "text",
314
+ text: parsedMessage ? JSON.stringify(parsedMessage[0].toFIXJSON()) : ""
315
+ }
316
+ ]
317
+ };
318
+ }
319
+ );
320
+ this.mcpServer.prompt(
321
+ "parseToJSON",
322
+ "Parses a FIX message into JSON",
323
+ { fixString: import_zod.z.string() },
324
+ ({ fixString }) => ({
325
+ messages: [
326
+ {
327
+ role: "user",
328
+ content: {
329
+ type: "text",
330
+ text: `Please parse the FIX message to JSON: ${fixString}`
331
+ }
332
+ }
333
+ ]
334
+ })
335
+ );
336
+ this.mcpServer.tool(
337
+ "newOrderSingle",
338
+ "Creates and sends a New Order Single",
1098
339
  {
1099
- description: "List available tools",
1100
- schema: import_zod.z.object({})
340
+ clOrdID: import_zod.z.string(),
341
+ handlInst: import_zod.z.enum(["1", "2", "3"]).default(import_fixparser.HandlInst.AutomatedExecutionNoIntervention).optional(),
342
+ quantity: import_zod.z.number(),
343
+ price: import_zod.z.number(),
344
+ ordType: import_zod.z.enum([
345
+ "1",
346
+ "2",
347
+ "3",
348
+ "4",
349
+ "5",
350
+ "6",
351
+ "7",
352
+ "8",
353
+ "9",
354
+ "A",
355
+ "B",
356
+ "C",
357
+ "D",
358
+ "E",
359
+ "F",
360
+ "G",
361
+ "H",
362
+ "I",
363
+ "J",
364
+ "K",
365
+ "L",
366
+ "M",
367
+ "P",
368
+ "Q",
369
+ "R",
370
+ "S"
371
+ ]).default(import_fixparser.OrdType.Market).optional(),
372
+ side: import_zod.z.enum(["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"]),
373
+ // 1 = Buy, 2 = Sell...
374
+ symbol: import_zod.z.string(),
375
+ timeInForce: import_zod.z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]).default(import_fixparser.TimeInForce.Day).optional()
1101
376
  },
1102
- async () => {
377
+ async ({ clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce }) => {
378
+ const response = new Promise((resolve) => {
379
+ this.pendingRequests.set(clOrdID, resolve);
380
+ });
381
+ const order = this.parser?.createMessage(
382
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
383
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
384
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
385
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
386
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
387
+ new import_fixparser.Field(import_fixparser.Fields.ClOrdID, clOrdID),
388
+ new import_fixparser.Field(import_fixparser.Fields.Side, side),
389
+ new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
390
+ new import_fixparser.Field(import_fixparser.Fields.OrderQty, quantity),
391
+ new import_fixparser.Field(import_fixparser.Fields.Price, price),
392
+ new import_fixparser.Field(import_fixparser.Fields.OrdType, ordType),
393
+ new import_fixparser.Field(import_fixparser.Fields.HandlInst, handlInst),
394
+ new import_fixparser.Field(import_fixparser.Fields.TimeInForce, timeInForce),
395
+ new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
396
+ );
397
+ if (!this.parser?.connected) {
398
+ this.logger?.log({
399
+ level: "error",
400
+ message: "FIXParser (MCP): -- Not connected. Ignoring message."
401
+ });
402
+ return {
403
+ isError: true,
404
+ content: [
405
+ {
406
+ type: "text",
407
+ text: "Error: Not connected. Ignoring message."
408
+ }
409
+ ]
410
+ };
411
+ }
412
+ this.parser?.send(order);
413
+ this.logger?.log({
414
+ level: "info",
415
+ message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${order?.description}`
416
+ });
417
+ const fixData = await response;
1103
418
  return {
1104
419
  content: [
1105
420
  {
1106
421
  type: "text",
1107
- text: JSON.stringify(
1108
- Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
1109
- name,
1110
- description,
1111
- inputSchema: schema
1112
- }))
1113
- )
422
+ text: `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
1114
423
  }
1115
424
  ]
1116
425
  };
1117
426
  }
1118
427
  );
428
+ this.mcpServer.prompt(
429
+ "newOrderSingle",
430
+ "Creates and sends a New Order Single",
431
+ {
432
+ clOrdID: import_zod.z.string(),
433
+ handlInst: import_zod.z.string(),
434
+ quantity: import_zod.z.string(),
435
+ price: import_zod.z.string(),
436
+ ordType: import_zod.z.string(),
437
+ side: import_zod.z.string(),
438
+ symbol: import_zod.z.string(),
439
+ timeInForce: import_zod.z.string()
440
+ },
441
+ ({ clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce }) => ({
442
+ messages: [
443
+ {
444
+ role: "user",
445
+ content: {
446
+ type: "text",
447
+ text: [
448
+ "Create a New Order Single FIX message with the following parameters:",
449
+ `- ClOrdID: ${clOrdID}`,
450
+ `- HandlInst: ${handlInst ?? "default"}`,
451
+ `- Quantity: ${quantity}`,
452
+ `- Price: ${price}`,
453
+ `- OrdType: ${ordType ?? "default (Market)"}`,
454
+ `- Side: ${side}`,
455
+ `- Symbol: ${symbol}`,
456
+ `- TimeInForce: ${timeInForce ?? "default (Day)"}`,
457
+ "",
458
+ "Format the response as a JSON object with FIX tag numbers as keys and their corresponding values."
459
+ ].join("\n")
460
+ }
461
+ }
462
+ ]
463
+ })
464
+ );
1119
465
  this.mcpServer.tool(
1120
- "tools/call",
466
+ "marketDataRequest",
467
+ "Sends a request for Market Data with the given symbol",
1121
468
  {
1122
- description: "Call a tool",
1123
- schema: import_zod.z.object({
1124
- name: import_zod.z.string(),
1125
- arguments: import_zod.z.any(),
1126
- _meta: import_zod.z.object({
1127
- progressToken: import_zod.z.number()
1128
- }).optional()
1129
- })
469
+ mdUpdateType: import_zod.z.enum(["0", "1"]).default("0").optional(),
470
+ // MDUpdateType.FullRefresh
471
+ symbol: import_zod.z.string(),
472
+ mdReqID: import_zod.z.string(),
473
+ subscriptionRequestType: import_zod.z.enum(["0", "1", "2"]).default(import_fixparser.SubscriptionRequestType.SnapshotAndUpdates).optional(),
474
+ mdEntryType: import_zod.z.enum([
475
+ "0",
476
+ "1",
477
+ "2",
478
+ "3",
479
+ "4",
480
+ "5",
481
+ "6",
482
+ "7",
483
+ "8",
484
+ "9",
485
+ "A",
486
+ "B",
487
+ "C",
488
+ "D",
489
+ "E",
490
+ "F",
491
+ "G",
492
+ "H",
493
+ "J",
494
+ "K",
495
+ "L",
496
+ "M",
497
+ "N",
498
+ "O",
499
+ "P",
500
+ "Q",
501
+ "S",
502
+ "R",
503
+ "T",
504
+ "U",
505
+ "V",
506
+ "W",
507
+ "X",
508
+ "Y",
509
+ "Z",
510
+ "a",
511
+ "b",
512
+ "c",
513
+ "d",
514
+ "e",
515
+ "g",
516
+ "h",
517
+ "i",
518
+ "t"
519
+ ]).default(import_fixparser.MDEntryType.Bid).optional()
1130
520
  },
1131
- async (request) => {
1132
- const { name, arguments: args } = request;
1133
- const toolHandlers = createToolHandlers(
1134
- this.parser,
1135
- this.verifiedOrders,
1136
- this.pendingRequests,
1137
- this.marketDataPrices
521
+ async ({ mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType }) => {
522
+ const response = new Promise((resolve) => {
523
+ this.pendingRequests.set(mdReqID, resolve);
524
+ });
525
+ const marketDataRequest = this.parser?.createMessage(
526
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
527
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
528
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
529
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
530
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
531
+ new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
532
+ new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, mdUpdateType),
533
+ new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, 1),
534
+ new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
535
+ new import_fixparser.Field(import_fixparser.Fields.MDReqID, mdReqID),
536
+ new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, subscriptionRequestType),
537
+ new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
538
+ new import_fixparser.Field(import_fixparser.Fields.MDEntryType, mdEntryType)
1138
539
  );
1139
- const handler = toolHandlers[name];
1140
- if (!handler) {
540
+ if (!this.parser?.connected) {
541
+ this.logger?.log({
542
+ level: "error",
543
+ message: "FIXParser (MCP): -- Not connected. Ignoring message."
544
+ });
1141
545
  return {
546
+ isError: true,
1142
547
  content: [
1143
548
  {
1144
549
  type: "text",
1145
- text: `Tool not found: ${name}`,
1146
- uri: name
550
+ text: "Error: Not connected. Ignoring message."
1147
551
  }
1148
- ],
1149
- isError: true
552
+ ]
1150
553
  };
1151
554
  }
1152
- const result = await handler(args);
555
+ this.parser?.send(marketDataRequest);
556
+ this.logger?.log({
557
+ level: "info",
558
+ message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${marketDataRequest?.description}`
559
+ });
560
+ const fixData = await response;
1153
561
  return {
1154
- content: result.content,
1155
- isError: result.isError
562
+ content: [
563
+ {
564
+ type: "text",
565
+ text: `Market data for ${symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
566
+ }
567
+ ]
1156
568
  };
1157
569
  }
1158
570
  );
571
+ this.mcpServer.prompt(
572
+ "marketDataRequest",
573
+ "Sends a request for Market Data with the given symbol",
574
+ {
575
+ mdUpdateType: import_zod.z.string(),
576
+ symbol: import_zod.z.string(),
577
+ mdReqID: import_zod.z.string(),
578
+ subscriptionRequestType: import_zod.z.string(),
579
+ mdEntryType: import_zod.z.string()
580
+ },
581
+ ({ mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType }) => ({
582
+ messages: [
583
+ {
584
+ role: "user",
585
+ content: {
586
+ type: "text",
587
+ text: [
588
+ "Create a Market Data Request FIX message with the following parameters:",
589
+ `- MDUpdateType: ${mdUpdateType ?? "default (0 = FullRefresh)"}`,
590
+ `- Symbol: ${symbol}`,
591
+ `- MDReqID: ${mdReqID}`,
592
+ `- SubscriptionRequestType: ${subscriptionRequestType ?? "default (0 = Snapshot + Updates)"}`,
593
+ `- MDEntryType: ${mdEntryType ?? "default (0 = Bid)"}`,
594
+ "",
595
+ "Format the response as a JSON object with FIX tag numbers as keys and their corresponding values."
596
+ ].join("\n")
597
+ }
598
+ }
599
+ ]
600
+ })
601
+ );
1159
602
  }
1160
603
  };
1161
604
  // Annotate the CommonJS export names for ESM import in node: