fixparser-plugin-mcp 9.1.7-bfafe1e3 → 9.1.7-bfcb9d6f

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/MCPLocal.ts
@@ -35,791 +25,102 @@ __export(MCPLocal_exports, {
35
25
  module.exports = __toCommonJS(MCPLocal_exports);
36
26
  var import_server = require("@modelcontextprotocol/sdk/server/index.js");
37
27
  var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
38
- var import_fixparser3 = require("fixparser");
39
- var import_zod = require("zod");
40
-
41
- // src/schemas/schemas.ts
42
- var toolSchemas = {
43
- parse: {
44
- description: "Parses a FIX message and describes it in plain language",
45
- schema: {
46
- type: "object",
47
- properties: {
48
- fixString: { type: "string" }
49
- },
50
- required: ["fixString"]
51
- }
52
- },
53
- parseToJSON: {
54
- description: "Parses a FIX message into JSON",
55
- schema: {
56
- type: "object",
57
- properties: {
58
- fixString: { type: "string" }
59
- },
60
- required: ["fixString"]
61
- }
62
- },
63
- verifyOrder: {
64
- description: "Verifies order parameters before execution. verifyOrder must be called before executeOrder.",
65
- schema: {
66
- type: "object",
67
- properties: {
68
- clOrdID: { type: "string" },
69
- handlInst: {
70
- type: "string",
71
- enum: ["1", "2", "3"],
72
- description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
73
- },
74
- quantity: { type: "string" },
75
- price: { type: "string" },
76
- ordType: {
77
- type: "string",
78
- enum: [
79
- "1",
80
- "2",
81
- "3",
82
- "4",
83
- "5",
84
- "6",
85
- "7",
86
- "8",
87
- "9",
88
- "A",
89
- "B",
90
- "C",
91
- "D",
92
- "E",
93
- "F",
94
- "G",
95
- "H",
96
- "I",
97
- "J",
98
- "K",
99
- "L",
100
- "M",
101
- "P",
102
- "Q",
103
- "R",
104
- "S"
105
- ],
106
- description: "Order Type: 1=Market, 2=Limit, 3=Stop, 4=StopLimit, 5=MarketOnClose, 6=WithOrWithout, 7=LimitOrBetter, 8=LimitWithOrWithout, 9=OnBasis, A=OnClose, B=LimitOnClose, C=ForexMarket, D=PreviouslyQuoted, E=PreviouslyIndicated, F=ForexLimit, G=ForexSwap, H=ForexPreviouslyQuoted, I=Funari, J=MarketIfTouched, K=MarketWithLeftOverAsLimit, L=PreviousFundValuationPoint, M=NextFundValuationPoint, P=Pegged, Q=CounterOrderSelection, R=StopOnBidOrOffer, S=StopLimitOnBidOrOffer"
107
- },
108
- side: {
109
- type: "string",
110
- enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
111
- description: "Side: 1=Buy, 2=Sell, 3=BuyMinus, 4=SellPlus, 5=SellShort, 6=SellShortExempt, 7=Undisclosed, 8=Cross, 9=CrossShort, A=CrossShortExempt, B=AsDefined, C=Opposite, D=Subscribe, E=Redeem, F=Lend, G=Borrow, H=SellUndisclosed"
112
- },
113
- symbol: { type: "string" },
114
- timeInForce: {
115
- type: "string",
116
- enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
117
- description: "Time In Force: 0=Day, 1=GoodTillCancel, 2=AtTheOpening, 3=ImmediateOrCancel, 4=FillOrKill, 5=GoodTillCrossing, 6=GoodTillDate, 7=AtTheClose, 8=GoodThroughCrossing, 9=AtCrossing, A=GoodForTime, B=GoodForAuction, C=GoodForMonth"
118
- }
119
- },
120
- required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
121
- }
122
- },
123
- executeOrder: {
124
- description: "Executes a verified order. verifyOrder must be called before executeOrder. user has to explicitly allow executeOrder.",
125
- schema: {
126
- type: "object",
127
- properties: {
128
- clOrdID: { type: "string" },
129
- handlInst: {
130
- type: "string",
131
- enum: ["1", "2", "3"],
132
- description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
133
- },
134
- quantity: { type: "string" },
135
- price: { type: "string" },
136
- ordType: {
137
- type: "string",
138
- enum: [
139
- "1",
140
- "2",
141
- "3",
142
- "4",
143
- "5",
144
- "6",
145
- "7",
146
- "8",
147
- "9",
148
- "A",
149
- "B",
150
- "C",
151
- "D",
152
- "E",
153
- "F",
154
- "G",
155
- "H",
156
- "I",
157
- "J",
158
- "K",
159
- "L",
160
- "M",
161
- "P",
162
- "Q",
163
- "R",
164
- "S"
165
- ],
166
- description: "Order Type: 1=Market, 2=Limit, 3=Stop, 4=StopLimit, 5=MarketOnClose, 6=WithOrWithout, 7=LimitOrBetter, 8=LimitWithOrWithout, 9=OnBasis, A=OnClose, B=LimitOnClose, C=ForexMarket, D=PreviouslyQuoted, E=PreviouslyIndicated, F=ForexLimit, G=ForexSwap, H=ForexPreviouslyQuoted, I=Funari, J=MarketIfTouched, K=MarketWithLeftOverAsLimit, L=PreviousFundValuationPoint, M=NextFundValuationPoint, P=Pegged, Q=CounterOrderSelection, R=StopOnBidOrOffer, S=StopLimitOnBidOrOffer"
167
- },
168
- side: {
169
- type: "string",
170
- enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
171
- description: "Side: 1=Buy, 2=Sell, 3=BuyMinus, 4=SellPlus, 5=SellShort, 6=SellShortExempt, 7=Undisclosed, 8=Cross, 9=CrossShort, A=CrossShortExempt, B=AsDefined, C=Opposite, D=Subscribe, E=Redeem, F=Lend, G=Borrow, H=SellUndisclosed"
172
- },
173
- symbol: { type: "string" },
174
- timeInForce: {
175
- type: "string",
176
- enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
177
- description: "Time In Force: 0=Day, 1=GoodTillCancel, 2=AtTheOpening, 3=ImmediateOrCancel, 4=FillOrKill, 5=GoodTillCrossing, 6=GoodTillDate, 7=AtTheClose, 8=GoodThroughCrossing, 9=AtCrossing, A=GoodForTime, B=GoodForAuction, C=GoodForMonth"
178
- }
179
- },
180
- required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
181
- }
182
- },
183
- marketDataRequest: {
184
- description: "Requests market data for specified symbols",
185
- schema: {
186
- type: "object",
187
- properties: {
188
- mdUpdateType: {
189
- type: "string",
190
- enum: ["0", "1"],
191
- description: "Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"
192
- },
193
- symbols: { type: "array", items: { type: "string" } },
194
- mdReqID: { type: "string" },
195
- subscriptionRequestType: {
196
- type: "string",
197
- enum: ["0", "1", "2"],
198
- description: "Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"
199
- },
200
- mdEntryTypes: {
201
- type: "array",
202
- items: {
203
- type: "string",
204
- enum: [
205
- "0",
206
- "1",
207
- "2",
208
- "3",
209
- "4",
210
- "5",
211
- "6",
212
- "7",
213
- "8",
214
- "9",
215
- "A",
216
- "B",
217
- "C",
218
- "D",
219
- "E",
220
- "F",
221
- "G",
222
- "H",
223
- "I",
224
- "J",
225
- "K",
226
- "L",
227
- "M",
228
- "N",
229
- "O",
230
- "P",
231
- "Q",
232
- "R",
233
- "S",
234
- "T",
235
- "U",
236
- "V",
237
- "W",
238
- "X",
239
- "Y",
240
- "Z"
241
- ]
242
- },
243
- description: "Market Data Entry Types: 0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price, 5=Closing Price, 6=Settlement Price, 7=High Price, 8=Low Price, 9=Trade Volume, A=Open Interest, B=Simulated Sell Price, C=Simulated Buy Price, D=Empty Book, E=Session High Bid, F=Session Low Offer, G=Fixing Price, H=Electronic Volume, I=Threshold Limits and Price Band Variation, J=Clearing Price, K=Open Interest Change, L=Last Trade Price, M=Last Trade Volume, N=Last Trade Time, O=Last Trade Tick, P=Last Trade Exchange, Q=Last Trade ID, R=Last Trade Side, S=Last Trade Price Change, T=Last Trade Price Change Percent, U=Last Trade Price Change Basis Points, V=Last Trade Price Change Points, W=Last Trade Price Change Ticks, X=Last Trade Price Change Ticks Percent, Y=Last Trade Price Change Ticks Basis Points, Z=Last Trade Price Change Ticks Points"
244
- }
245
- },
246
- required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType"]
247
- }
248
- },
249
- getStockGraph: {
250
- description: "Generates a price chart for a given symbol",
251
- schema: {
252
- type: "object",
253
- properties: {
254
- symbol: { type: "string" }
255
- },
256
- required: ["symbol"]
257
- }
258
- },
259
- getStockPriceHistory: {
260
- description: "Returns price history for a given symbol",
261
- schema: {
262
- type: "object",
263
- properties: {
264
- symbol: { type: "string" }
265
- },
266
- required: ["symbol"]
267
- }
268
- }
269
- };
270
-
271
- // src/tools/marketData.ts
272
28
  var import_fixparser = require("fixparser");
273
- var import_quickchart_js = __toESM(require("quickchart-js"), 1);
274
- var createMarketDataRequestHandler = (parser, pendingRequests) => {
275
- return async (args) => {
276
- try {
277
- const response = new Promise((resolve) => {
278
- pendingRequests.set(args.mdReqID, resolve);
279
- });
280
- const entryTypes = args.mdEntryTypes || [import_fixparser.MDEntryType.Bid, import_fixparser.MDEntryType.Offer, import_fixparser.MDEntryType.TradeVolume];
281
- const messageFields = [
282
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
283
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
284
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
285
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
286
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
287
- new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
288
- new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
289
- new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
290
- new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
291
- ];
292
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
293
- args.symbols.forEach((symbol) => {
294
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
295
- });
296
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, entryTypes.length));
297
- entryTypes.forEach((entryType) => {
298
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
299
- });
300
- const mdr = parser.createMessage(...messageFields);
301
- if (!parser.connected) {
302
- return {
303
- content: [
304
- {
305
- type: "text",
306
- text: "Error: Not connected. Ignoring message.",
307
- uri: "marketDataRequest"
308
- }
309
- ],
310
- isError: true
311
- };
312
- }
313
- parser.send(mdr);
314
- const fixData = await response;
315
- return {
316
- content: [
317
- {
318
- type: "text",
319
- text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
320
- uri: "marketDataRequest"
321
- }
322
- ]
323
- };
324
- } catch (error) {
325
- return {
326
- content: [
327
- {
328
- type: "text",
329
- text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
330
- uri: "marketDataRequest"
331
- }
332
- ],
333
- isError: true
334
- };
335
- }
336
- };
337
- };
338
- var createGetStockGraphHandler = (marketDataPrices) => {
339
- return async (args) => {
340
- try {
341
- const symbol = args.symbol;
342
- const priceHistory = marketDataPrices.get(symbol) || [];
343
- if (priceHistory.length === 0) {
344
- return {
345
- content: [
346
- {
347
- type: "text",
348
- text: `No price data available for ${symbol}`,
349
- uri: "getStockGraph"
350
- }
351
- ]
352
- };
353
- }
354
- const chart = new import_quickchart_js.default();
355
- chart.setWidth(600);
356
- chart.setHeight(300);
357
- const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
358
- const bidData = priceHistory.map((point) => point.bid);
359
- const offerData = priceHistory.map((point) => point.offer);
360
- const spreadData = priceHistory.map((point) => point.spread);
361
- const volumeData = priceHistory.map((point) => point.volume);
362
- chart.setConfig({
363
- type: "line",
364
- data: {
365
- labels,
366
- datasets: [
367
- {
368
- label: "Bid",
369
- data: bidData,
370
- borderColor: "#28a745",
371
- backgroundColor: "rgba(40, 167, 69, 0.1)",
372
- fill: false,
373
- tension: 0.4
374
- },
375
- {
376
- label: "Offer",
377
- data: offerData,
378
- borderColor: "#dc3545",
379
- backgroundColor: "rgba(220, 53, 69, 0.1)",
380
- fill: false,
381
- tension: 0.4
382
- },
383
- {
384
- label: "Spread",
385
- data: spreadData,
386
- borderColor: "#6c757d",
387
- backgroundColor: "rgba(108, 117, 125, 0.1)",
388
- fill: false,
389
- tension: 0.4
390
- },
391
- {
392
- label: "Volume",
393
- data: volumeData,
394
- borderColor: "#007bff",
395
- backgroundColor: "rgba(0, 123, 255, 0.1)",
396
- fill: true,
397
- tension: 0.4,
398
- yAxisID: "volume"
399
- }
400
- ]
401
- },
402
- options: {
403
- plugins: {
404
- title: {
405
- display: true,
406
- text: `${symbol} Market Data`,
407
- font: {
408
- size: 16,
409
- weight: "bold"
410
- }
411
- },
412
- legend: {
413
- display: true
414
- }
415
- },
416
- scales: {
417
- y: {
418
- beginAtZero: false,
419
- grid: {
420
- color: "#e9ecef"
421
- }
422
- },
423
- volume: {
424
- position: "right",
425
- beginAtZero: true,
426
- grid: {
427
- display: false
428
- }
429
- },
430
- x: {
431
- grid: {
432
- display: false
433
- }
434
- }
435
- }
436
- }
437
- });
438
- const imageBuffer = await chart.toBinary();
439
- const base64Image = imageBuffer.toString("base64");
440
- console.log("-------------------------------------------");
441
- console.log("b64", base64Image);
442
- console.log("-------------------------------------------");
443
- return {
444
- content: [
445
- {
446
- type: "image",
447
- image: {
448
- source: {
449
- data: base64Image
450
- }
451
- },
452
- uri: "getStockGraph",
453
- mimeType: "image/png"
454
- }
455
- ]
456
- };
457
- } catch (error) {
458
- return {
459
- content: [
460
- {
461
- type: "text",
462
- text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
463
- uri: "getStockGraph"
464
- }
465
- ],
466
- isError: true
467
- };
468
- }
469
- };
470
- };
471
- var createGetStockPriceHistoryHandler = (marketDataPrices) => {
472
- return async (args) => {
473
- try {
474
- const symbol = args.symbol;
475
- const priceHistory = marketDataPrices.get(symbol) || [];
476
- if (priceHistory.length === 0) {
477
- return {
478
- content: [
479
- {
480
- type: "text",
481
- text: `No price data available for ${symbol}`,
482
- uri: "getStockPriceHistory"
483
- }
484
- ]
485
- };
486
- }
487
- return {
488
- content: [
489
- {
490
- type: "text",
491
- text: JSON.stringify(
492
- {
493
- symbol,
494
- count: priceHistory.length,
495
- data: priceHistory.map((point) => ({
496
- timestamp: new Date(point.timestamp).toISOString(),
497
- bid: point.bid,
498
- offer: point.offer,
499
- spread: point.spread,
500
- volume: point.volume
501
- }))
502
- },
503
- null,
504
- 2
505
- ),
506
- uri: "getStockPriceHistory"
507
- }
508
- ]
509
- };
510
- } catch (error) {
511
- return {
512
- content: [
513
- {
514
- type: "text",
515
- text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
516
- uri: "getStockPriceHistory"
517
- }
518
- ],
519
- isError: true
520
- };
521
- }
522
- };
523
- };
524
-
525
- // src/tools/order.ts
526
- var import_fixparser2 = require("fixparser");
527
- var ordTypeNames = {
528
- "1": "Market",
529
- "2": "Limit",
530
- "3": "Stop",
531
- "4": "StopLimit",
532
- "5": "MarketOnClose",
533
- "6": "WithOrWithout",
534
- "7": "LimitOrBetter",
535
- "8": "LimitWithOrWithout",
536
- "9": "OnBasis",
537
- A: "OnClose",
538
- B: "LimitOnClose",
539
- C: "ForexMarket",
540
- D: "PreviouslyQuoted",
541
- E: "PreviouslyIndicated",
542
- F: "ForexLimit",
543
- G: "ForexSwap",
544
- H: "ForexPreviouslyQuoted",
545
- I: "Funari",
546
- J: "MarketIfTouched",
547
- K: "MarketWithLeftOverAsLimit",
548
- L: "PreviousFundValuationPoint",
549
- M: "NextFundValuationPoint",
550
- P: "Pegged",
551
- Q: "CounterOrderSelection",
552
- R: "StopOnBidOrOffer",
553
- S: "StopLimitOnBidOrOffer"
554
- };
555
- var sideNames = {
556
- "1": "Buy",
557
- "2": "Sell",
558
- "3": "BuyMinus",
559
- "4": "SellPlus",
560
- "5": "SellShort",
561
- "6": "SellShortExempt",
562
- "7": "Undisclosed",
563
- "8": "Cross",
564
- "9": "CrossShort",
565
- A: "CrossShortExempt",
566
- B: "AsDefined",
567
- C: "Opposite",
568
- D: "Subscribe",
569
- E: "Redeem",
570
- F: "Lend",
571
- G: "Borrow",
572
- H: "SellUndisclosed"
573
- };
574
- var timeInForceNames = {
575
- "0": "Day",
576
- "1": "GoodTillCancel",
577
- "2": "AtTheOpening",
578
- "3": "ImmediateOrCancel",
579
- "4": "FillOrKill",
580
- "5": "GoodTillCrossing",
581
- "6": "GoodTillDate",
582
- "7": "AtTheClose",
583
- "8": "GoodThroughCrossing",
584
- "9": "AtCrossing",
585
- A: "GoodForTime",
586
- B: "GoodForAuction",
587
- C: "GoodForMonth"
588
- };
589
- var handlInstNames = {
590
- "1": "AutomatedExecutionNoIntervention",
591
- "2": "AutomatedExecutionInterventionOK",
592
- "3": "ManualOrder"
593
- };
594
- var createVerifyOrderHandler = (parser, verifiedOrders) => {
595
- return async (args) => {
596
- try {
597
- verifiedOrders.set(args.clOrdID, {
598
- clOrdID: args.clOrdID,
599
- handlInst: args.handlInst,
600
- quantity: Number.parseFloat(String(args.quantity)),
601
- price: Number.parseFloat(String(args.price)),
602
- ordType: args.ordType,
603
- side: args.side,
604
- symbol: args.symbol,
605
- timeInForce: args.timeInForce
606
- });
607
- return {
608
- content: [
609
- {
610
- type: "text",
611
- text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
612
-
613
- Parameters verified:
614
- - ClOrdID: ${args.clOrdID}
615
- - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
616
- - Quantity: ${args.quantity}
617
- - Price: ${args.price}
618
- - OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
619
- - Side: ${args.side} (${sideNames[args.side]})
620
- - Symbol: ${args.symbol}
621
- - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
622
-
623
- To execute this order, call the executeOrder tool with these exact same parameters.`,
624
- uri: "verifyOrder"
625
- }
626
- ]
627
- };
628
- } catch (error) {
629
- return {
630
- content: [
631
- {
632
- type: "text",
633
- text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
634
- uri: "verifyOrder"
635
- }
636
- ],
637
- isError: true
638
- };
639
- }
640
- };
641
- };
642
- var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
643
- return async (args) => {
644
- try {
645
- const verifiedOrder = verifiedOrders.get(args.clOrdID);
646
- if (!verifiedOrder) {
647
- return {
648
- content: [
649
- {
650
- type: "text",
651
- text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
652
- uri: "executeOrder"
653
- }
654
- ],
655
- isError: true
656
- };
657
- }
658
- 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) {
659
- return {
660
- content: [
661
- {
662
- type: "text",
663
- text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
664
- uri: "executeOrder"
665
- }
666
- ],
667
- isError: true
668
- };
669
- }
670
- const response = new Promise((resolve) => {
671
- pendingRequests.set(args.clOrdID, resolve);
672
- });
673
- const order = parser.createMessage(
674
- new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
675
- new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
676
- new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
677
- new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
678
- new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
679
- new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
680
- new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
681
- new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
682
- new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
683
- new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
684
- new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
685
- new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
686
- new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
687
- new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
688
- );
689
- if (!parser.connected) {
690
- return {
691
- content: [
692
- {
693
- type: "text",
694
- text: "Error: Not connected. Ignoring message.",
695
- uri: "executeOrder"
696
- }
697
- ],
698
- isError: true
699
- };
700
- }
701
- parser.send(order);
702
- const fixData = await response;
703
- verifiedOrders.delete(args.clOrdID);
704
- return {
705
- content: [
706
- {
707
- type: "text",
708
- 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())}`,
709
- uri: "executeOrder"
710
- }
711
- ]
712
- };
713
- } catch (error) {
714
- return {
715
- content: [
716
- {
717
- type: "text",
718
- text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
719
- uri: "executeOrder"
720
- }
721
- ],
722
- isError: true
723
- };
724
- }
725
- };
726
- };
727
-
728
- // src/tools/parse.ts
729
- var createParseHandler = (parser) => {
730
- return async (args) => {
731
- try {
732
- const parsedMessage = parser.parse(args.fixString);
733
- if (!parsedMessage || parsedMessage.length === 0) {
734
- return {
735
- content: [
736
- {
737
- type: "text",
738
- text: "Error: Failed to parse FIX string",
739
- uri: "parse"
740
- }
741
- ],
742
- isError: true
743
- };
744
- }
745
- return {
746
- content: [
747
- {
748
- type: "text",
749
- text: `${parsedMessage[0].description}
750
- ${parsedMessage[0].messageTypeDescription}`,
751
- uri: "parse"
752
- }
753
- ]
754
- };
755
- } catch (error) {
756
- return {
757
- content: [
758
- {
759
- type: "text",
760
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
761
- uri: "parse"
762
- }
763
- ],
764
- isError: true
765
- };
766
- }
767
- };
768
- };
769
-
770
- // src/tools/parseToJSON.ts
771
- var createParseToJSONHandler = (parser) => {
772
- return async (args) => {
773
- try {
774
- const parsedMessage = parser.parse(args.fixString);
775
- if (!parsedMessage || parsedMessage.length === 0) {
776
- return {
777
- content: [
778
- {
779
- type: "text",
780
- text: "Error: Failed to parse FIX string",
781
- uri: "parseToJSON"
782
- }
783
- ],
784
- isError: true
785
- };
786
- }
787
- return {
788
- content: [
789
- {
790
- type: "text",
791
- text: `${parsedMessage[0].toFIXJSON()}`,
792
- uri: "parseToJSON"
793
- }
794
- ]
795
- };
796
- } catch (error) {
797
- return {
798
- content: [
799
- {
800
- type: "text",
801
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
802
- uri: "parseToJSON"
803
- }
804
- ],
805
- isError: true
806
- };
807
- }
808
- };
809
- };
810
-
811
- // src/tools/index.ts
812
- var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
813
- parse: createParseHandler(parser),
814
- parseToJSON: createParseToJSONHandler(parser),
815
- verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
816
- executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
817
- marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
818
- getStockGraph: createGetStockGraphHandler(marketDataPrices),
819
- getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
29
+ var import_zod = require("zod");
30
+ var fixStringSchema = import_zod.z.object({
31
+ fixString: import_zod.z.string()
32
+ });
33
+ var orderSchema = import_zod.z.object({
34
+ clOrdID: import_zod.z.string(),
35
+ handlInst: import_zod.z.enum(["1", "2", "3"]),
36
+ quantity: import_zod.z.string(),
37
+ price: import_zod.z.string(),
38
+ ordType: import_zod.z.enum([
39
+ "1",
40
+ "2",
41
+ "3",
42
+ "4",
43
+ "5",
44
+ "6",
45
+ "7",
46
+ "8",
47
+ "9",
48
+ "A",
49
+ "B",
50
+ "C",
51
+ "D",
52
+ "E",
53
+ "F",
54
+ "G",
55
+ "H",
56
+ "I",
57
+ "J",
58
+ "K",
59
+ "L",
60
+ "M",
61
+ "P",
62
+ "Q",
63
+ "R",
64
+ "S"
65
+ ]),
66
+ side: import_zod.z.enum(["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"]),
67
+ symbol: import_zod.z.string(),
68
+ timeInForce: import_zod.z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"])
69
+ });
70
+ var marketDataRequestSchema = import_zod.z.object({
71
+ mdUpdateType: import_zod.z.enum(["0", "1"]),
72
+ symbols: import_zod.z.array(import_zod.z.string()),
73
+ mdReqID: import_zod.z.string(),
74
+ subscriptionRequestType: import_zod.z.enum(["0", "1", "2"]),
75
+ mdEntryTypes: import_zod.z.array(
76
+ import_zod.z.enum([
77
+ "0",
78
+ "1",
79
+ "2",
80
+ "3",
81
+ "4",
82
+ "5",
83
+ "6",
84
+ "7",
85
+ "8",
86
+ "9",
87
+ "A",
88
+ "B",
89
+ "C",
90
+ "D",
91
+ "E",
92
+ "F",
93
+ "G",
94
+ "H",
95
+ "J",
96
+ "K",
97
+ "L",
98
+ "M",
99
+ "N",
100
+ "O",
101
+ "P",
102
+ "Q",
103
+ "R",
104
+ "S",
105
+ "T",
106
+ "U",
107
+ "V",
108
+ "W",
109
+ "X",
110
+ "Y",
111
+ "Z",
112
+ "a",
113
+ "b",
114
+ "c",
115
+ "d",
116
+ "e",
117
+ "g",
118
+ "h",
119
+ "i",
120
+ "t"
121
+ ])
122
+ )
820
123
  });
821
-
822
- // src/MCPLocal.ts
823
124
  var MCPLocal = class {
824
125
  parser;
825
126
  server = new import_server.Server(
@@ -829,16 +130,162 @@ var MCPLocal = class {
829
130
  },
830
131
  {
831
132
  capabilities: {
832
- tools: Object.entries(toolSchemas).reduce(
833
- (acc, [name, { description, schema }]) => {
834
- acc[name] = {
835
- description,
836
- parameters: schema
837
- };
838
- return acc;
133
+ tools: {
134
+ parse: {
135
+ description: "Parses a FIX message and describes it in plain language",
136
+ parameters: {
137
+ type: "object",
138
+ properties: {
139
+ fixString: { type: "string" }
140
+ },
141
+ required: ["fixString"]
142
+ }
839
143
  },
840
- {}
841
- )
144
+ parseToJSON: {
145
+ description: "Parses a FIX message into JSON",
146
+ parameters: {
147
+ type: "object",
148
+ properties: {
149
+ fixString: { type: "string" }
150
+ },
151
+ required: ["fixString"]
152
+ }
153
+ },
154
+ verifyOrder: {
155
+ description: "Verifies order parameters before execution",
156
+ parameters: {
157
+ type: "object",
158
+ properties: {
159
+ clOrdID: { type: "string" },
160
+ handlInst: { type: "string", enum: ["1", "2", "3"] },
161
+ quantity: { type: "string" },
162
+ price: { type: "string" },
163
+ ordType: {
164
+ type: "string",
165
+ enum: [
166
+ "1",
167
+ "2",
168
+ "3",
169
+ "4",
170
+ "5",
171
+ "6",
172
+ "7",
173
+ "8",
174
+ "9",
175
+ "A",
176
+ "B",
177
+ "C",
178
+ "D",
179
+ "E",
180
+ "F",
181
+ "G",
182
+ "H",
183
+ "I",
184
+ "J",
185
+ "K",
186
+ "L",
187
+ "M",
188
+ "P",
189
+ "Q",
190
+ "R",
191
+ "S"
192
+ ]
193
+ },
194
+ side: {
195
+ type: "string",
196
+ enum: [
197
+ "1",
198
+ "2",
199
+ "3",
200
+ "4",
201
+ "5",
202
+ "6",
203
+ "7",
204
+ "8",
205
+ "9",
206
+ "A",
207
+ "B",
208
+ "C",
209
+ "D",
210
+ "E",
211
+ "F",
212
+ "G",
213
+ "H"
214
+ ]
215
+ },
216
+ symbol: { type: "string" },
217
+ timeInForce: {
218
+ type: "string",
219
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
220
+ }
221
+ },
222
+ required: [
223
+ "clOrdID",
224
+ "handlInst",
225
+ "quantity",
226
+ "price",
227
+ "ordType",
228
+ "side",
229
+ "symbol",
230
+ "timeInForce"
231
+ ]
232
+ }
233
+ },
234
+ executeOrder: {
235
+ description: "Executes a verified order",
236
+ parameters: {
237
+ type: "object",
238
+ properties: {
239
+ clOrdID: { type: "string" },
240
+ handlInst: { type: "string", enum: ["1", "2", "3"] },
241
+ quantity: { type: "string" },
242
+ price: { type: "string" },
243
+ ordType: { type: "string" },
244
+ side: { type: "string" },
245
+ symbol: { type: "string" },
246
+ timeInForce: { type: "string" }
247
+ },
248
+ required: [
249
+ "clOrdID",
250
+ "handlInst",
251
+ "quantity",
252
+ "price",
253
+ "ordType",
254
+ "side",
255
+ "symbol",
256
+ "timeInForce"
257
+ ]
258
+ }
259
+ },
260
+ marketDataRequest: {
261
+ description: "Requests market data for specified symbols",
262
+ parameters: {
263
+ type: "object",
264
+ properties: {
265
+ mdUpdateType: { type: "string", enum: ["0", "1"] },
266
+ symbols: { type: "array", items: { type: "string" } },
267
+ mdReqID: { type: "string" },
268
+ subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
269
+ mdEntryTypes: { type: "array", items: { type: "string" } }
270
+ },
271
+ required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType", "mdEntryTypes"]
272
+ }
273
+ }
274
+ },
275
+ resources: {
276
+ greeting: {
277
+ description: "A simple greeting resource",
278
+ uri: "greeting-resource"
279
+ },
280
+ stockGraph: {
281
+ description: "Generates a price chart for a given symbol",
282
+ uri: "stockGraph/{symbol}"
283
+ },
284
+ stockPriceHistory: {
285
+ description: "Returns price history for a given symbol",
286
+ uri: "stockPriceHistory/{symbol}"
287
+ }
288
+ }
842
289
  }
843
290
  }
844
291
  );
@@ -846,6 +293,7 @@ var MCPLocal = class {
846
293
  onReady = void 0;
847
294
  pendingRequests = /* @__PURE__ */ new Map();
848
295
  verifiedOrders = /* @__PURE__ */ new Map();
296
+ // Store market data prices with timestamps
849
297
  marketDataPrices = /* @__PURE__ */ new Map();
850
298
  MAX_PRICE_HISTORY = 1e5;
851
299
  // Maximum number of price points to store per symbol
@@ -860,63 +308,50 @@ var MCPLocal = class {
860
308
  message: `MCP Server received message: ${message.messageType}: ${message.description}`
861
309
  });
862
310
  const msgType = message.messageType;
863
- if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.ExecutionReport || msgType === import_fixparser3.Messages.Reject || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
311
+ if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport || msgType === import_fixparser.Messages.Reject || msgType === import_fixparser.Messages.MarketDataIncrementalRefresh) {
864
312
  this.parser?.logger.log({
865
313
  level: "info",
866
314
  message: `MCP Server handling message type: ${msgType}`
867
315
  });
868
316
  let id;
869
- if (msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
870
- const symbol = message.getField(import_fixparser3.Fields.Symbol);
871
- const entryType = message.getField(import_fixparser3.Fields.MDEntryType);
872
- const price = message.getField(import_fixparser3.Fields.MDEntryPx);
873
- const size = message.getField(import_fixparser3.Fields.MDEntrySize);
874
- const timestamp = message.getField(import_fixparser3.Fields.MDEntryTime)?.value || Date.now();
317
+ if (msgType === import_fixparser.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
318
+ const symbol = message.getField(import_fixparser.Fields.Symbol);
319
+ const price = message.getField(import_fixparser.Fields.MDEntryPx);
320
+ const timestamp = message.getField(import_fixparser.Fields.MDEntryTime)?.value || Date.now();
875
321
  if (symbol?.value && price?.value) {
876
322
  const symbolStr = String(symbol.value);
877
323
  const priceNum = Number(price.value);
878
- const sizeNum = size?.value ? Number(size.value) : 0;
879
324
  const priceHistory = this.marketDataPrices.get(symbolStr) || [];
880
- const lastEntry = priceHistory[priceHistory.length - 1] || {
881
- timestamp: 0,
882
- bid: 0,
883
- offer: 0,
884
- spread: 0,
885
- volume: 0
886
- };
887
- const newEntry = {
325
+ priceHistory.push({
888
326
  timestamp: Number(timestamp),
889
- bid: entryType?.value === import_fixparser3.MDEntryType.Bid ? priceNum : lastEntry.bid,
890
- offer: entryType?.value === import_fixparser3.MDEntryType.Offer ? priceNum : lastEntry.offer,
891
- spread: entryType?.value === import_fixparser3.MDEntryType.Offer ? priceNum - lastEntry.bid : entryType?.value === import_fixparser3.MDEntryType.Bid ? lastEntry.offer - priceNum : lastEntry.spread,
892
- volume: entryType?.value === import_fixparser3.MDEntryType.TradeVolume ? sizeNum : lastEntry.volume
893
- };
894
- priceHistory.push(newEntry);
327
+ price: priceNum
328
+ });
895
329
  if (priceHistory.length > this.MAX_PRICE_HISTORY) {
896
330
  priceHistory.shift();
897
331
  }
898
332
  this.marketDataPrices.set(symbolStr, priceHistory);
899
333
  this.parser?.logger.log({
900
334
  level: "info",
901
- message: `MCP Server added ${symbol}: ${JSON.stringify(newEntry)}`
335
+ message: `MCP Server added ${symbol}: ${priceNum}`
902
336
  });
903
337
  this.server.notification({
904
338
  method: "priceUpdate",
905
339
  params: {
906
340
  symbol: symbolStr,
907
- ...newEntry
341
+ price: priceNum,
342
+ timestamp: Number(timestamp)
908
343
  }
909
344
  });
910
345
  }
911
346
  }
912
- if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
913
- const mdReqID = message.getField(import_fixparser3.Fields.MDReqID);
347
+ if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
348
+ const mdReqID = message.getField(import_fixparser.Fields.MDReqID);
914
349
  if (mdReqID) id = String(mdReqID.value);
915
- } else if (msgType === import_fixparser3.Messages.ExecutionReport) {
916
- const clOrdID = message.getField(import_fixparser3.Fields.ClOrdID);
350
+ } else if (msgType === import_fixparser.Messages.ExecutionReport) {
351
+ const clOrdID = message.getField(import_fixparser.Fields.ClOrdID);
917
352
  if (clOrdID) id = String(clOrdID.value);
918
- } else if (msgType === import_fixparser3.Messages.Reject) {
919
- const refSeqNum = message.getField(import_fixparser3.Fields.RefSeqNum);
353
+ } else if (msgType === import_fixparser.Messages.Reject) {
354
+ const refSeqNum = message.getField(import_fixparser.Fields.RefSeqNum);
920
355
  if (refSeqNum) id = String(refSeqNum.value);
921
356
  }
922
357
  if (id) {
@@ -941,55 +376,721 @@ var MCPLocal = class {
941
376
  if (!this.server) {
942
377
  return;
943
378
  }
379
+ this.server.setRequestHandler(
380
+ import_zod.z.object({ method: import_zod.z.literal("resources/list") }),
381
+ async (request, extra) => {
382
+ return {
383
+ resources: [
384
+ {
385
+ name: "greeting",
386
+ description: "A simple greeting resource",
387
+ uri: "greeting-resource"
388
+ }
389
+ ]
390
+ };
391
+ }
392
+ );
393
+ this.server.setRequestHandler(
394
+ import_zod.z.object({ method: import_zod.z.literal("resources/templates/list") }),
395
+ async (request, extra) => {
396
+ return {
397
+ resourceTemplates: [
398
+ {
399
+ name: "stockGraph",
400
+ description: "Generates a price chart for a given symbol",
401
+ uriTemplate: "stockGraph/{symbol}",
402
+ parameters: {
403
+ type: "object",
404
+ properties: {
405
+ symbol: { type: "string" }
406
+ },
407
+ required: ["symbol"]
408
+ }
409
+ },
410
+ {
411
+ name: "stockPriceHistory",
412
+ description: "Returns price history for a given symbol",
413
+ uriTemplate: "stockPriceHistory/{symbol}",
414
+ parameters: {
415
+ type: "object",
416
+ properties: {
417
+ symbol: { type: "string" }
418
+ },
419
+ required: ["symbol"]
420
+ }
421
+ }
422
+ ]
423
+ };
424
+ }
425
+ );
944
426
  this.server.setRequestHandler(
945
427
  import_zod.z.object({ method: import_zod.z.literal("tools/list") }),
946
428
  async (request, extra) => {
947
429
  return {
948
- tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
949
- name,
950
- description,
951
- inputSchema: schema
952
- }))
430
+ tools: [
431
+ {
432
+ name: "parse",
433
+ description: "Parses a FIX message and describes it in plain language",
434
+ inputSchema: {
435
+ type: "object",
436
+ properties: {
437
+ fixString: { type: "string" }
438
+ },
439
+ required: ["fixString"]
440
+ }
441
+ },
442
+ {
443
+ name: "parseToJSON",
444
+ description: "Parses a FIX message into JSON",
445
+ inputSchema: {
446
+ type: "object",
447
+ properties: {
448
+ fixString: { type: "string" }
449
+ },
450
+ required: ["fixString"]
451
+ }
452
+ },
453
+ {
454
+ name: "verifyOrder",
455
+ description: "Verifies order parameters before execution",
456
+ inputSchema: {
457
+ type: "object",
458
+ properties: {
459
+ clOrdID: { type: "string" },
460
+ handlInst: { type: "string", enum: ["1", "2", "3"] },
461
+ quantity: { type: "string" },
462
+ price: { type: "string" },
463
+ ordType: {
464
+ type: "string",
465
+ enum: [
466
+ "1",
467
+ "2",
468
+ "3",
469
+ "4",
470
+ "5",
471
+ "6",
472
+ "7",
473
+ "8",
474
+ "9",
475
+ "A",
476
+ "B",
477
+ "C",
478
+ "D",
479
+ "E",
480
+ "F",
481
+ "G",
482
+ "H",
483
+ "I",
484
+ "J",
485
+ "K",
486
+ "L",
487
+ "M",
488
+ "P",
489
+ "Q",
490
+ "R",
491
+ "S"
492
+ ]
493
+ },
494
+ side: {
495
+ type: "string",
496
+ enum: [
497
+ "1",
498
+ "2",
499
+ "3",
500
+ "4",
501
+ "5",
502
+ "6",
503
+ "7",
504
+ "8",
505
+ "9",
506
+ "A",
507
+ "B",
508
+ "C",
509
+ "D",
510
+ "E",
511
+ "F",
512
+ "G",
513
+ "H"
514
+ ]
515
+ },
516
+ symbol: { type: "string" },
517
+ timeInForce: {
518
+ type: "string",
519
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
520
+ }
521
+ },
522
+ required: [
523
+ "clOrdID",
524
+ "handlInst",
525
+ "quantity",
526
+ "price",
527
+ "ordType",
528
+ "side",
529
+ "symbol",
530
+ "timeInForce"
531
+ ]
532
+ }
533
+ },
534
+ {
535
+ name: "executeOrder",
536
+ description: "Executes a verified order",
537
+ inputSchema: {
538
+ type: "object",
539
+ properties: {
540
+ clOrdID: { type: "string" },
541
+ handlInst: { type: "string", enum: ["1", "2", "3"] },
542
+ quantity: { type: "string" },
543
+ price: { type: "string" },
544
+ ordType: { type: "string" },
545
+ side: { type: "string" },
546
+ symbol: { type: "string" },
547
+ timeInForce: { type: "string" }
548
+ },
549
+ required: [
550
+ "clOrdID",
551
+ "handlInst",
552
+ "quantity",
553
+ "price",
554
+ "ordType",
555
+ "side",
556
+ "symbol",
557
+ "timeInForce"
558
+ ]
559
+ }
560
+ },
561
+ {
562
+ name: "marketDataRequest",
563
+ description: "Requests market data for specified symbols",
564
+ inputSchema: {
565
+ type: "object",
566
+ properties: {
567
+ mdUpdateType: { type: "string", enum: ["0", "1"] },
568
+ symbols: { type: "array", items: { type: "string" } },
569
+ mdReqID: { type: "string" },
570
+ subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
571
+ mdEntryTypes: { type: "array", items: { type: "string" } }
572
+ },
573
+ required: [
574
+ "mdUpdateType",
575
+ "symbols",
576
+ "mdReqID",
577
+ "subscriptionRequestType",
578
+ "mdEntryTypes"
579
+ ]
580
+ }
581
+ }
582
+ ]
953
583
  };
954
584
  }
955
585
  );
956
586
  this.server.setRequestHandler(
957
587
  import_zod.z.object({
958
- method: import_zod.z.literal("tools/call"),
588
+ method: import_zod.z.literal("resources/read"),
959
589
  params: import_zod.z.object({
960
- name: import_zod.z.string(),
961
- arguments: import_zod.z.any(),
962
- _meta: import_zod.z.object({
963
- progressToken: import_zod.z.number()
964
- }).optional()
590
+ uri: import_zod.z.string()
965
591
  })
966
592
  }),
967
593
  async (request, extra) => {
968
- const { name, arguments: args } = request.params;
969
- const toolHandlers = createToolHandlers(
970
- this.parser,
971
- this.verifiedOrders,
972
- this.pendingRequests,
973
- this.marketDataPrices
974
- );
975
- const handler = toolHandlers[name];
976
- if (!handler) {
594
+ const { uri } = request.params;
595
+ switch (uri) {
596
+ case "greeting-resource":
597
+ return {
598
+ contents: [
599
+ {
600
+ type: "text",
601
+ text: "Hello, world!",
602
+ uri: "greeting-resource"
603
+ }
604
+ ]
605
+ };
606
+ case "stockGraph":
607
+ return {
608
+ contents: [
609
+ {
610
+ type: "text",
611
+ text: "This resource requires a symbol parameter. Please use the stockGraph/{symbol} resource.",
612
+ uri: "stockGraph"
613
+ }
614
+ ]
615
+ };
616
+ case "stockPriceHistory":
617
+ return {
618
+ contents: [
619
+ {
620
+ type: "text",
621
+ text: "This resource requires a symbol parameter. Please use the stockPriceHistory/{symbol} resource.",
622
+ uri: "stockPriceHistory"
623
+ }
624
+ ]
625
+ };
626
+ default:
627
+ if (uri.startsWith("stockGraph/")) {
628
+ const symbol = uri.split("/")[1];
629
+ const priceHistory = this.marketDataPrices.get(symbol) || [];
630
+ if (priceHistory.length === 0) {
631
+ return {
632
+ contents: [
633
+ {
634
+ type: "text",
635
+ text: `No price data available for ${symbol}`
636
+ }
637
+ ]
638
+ };
639
+ }
640
+ const width = 600;
641
+ const height = 300;
642
+ const padding = 40;
643
+ const xScale = (width - 2 * padding) / (priceHistory.length - 1);
644
+ const yMin = Math.min(...priceHistory.map((d) => d.price));
645
+ const yMax = Math.max(...priceHistory.map((d) => d.price));
646
+ const yScale = (height - 2 * padding) / (yMax - yMin);
647
+ const points = priceHistory.map((d, i) => {
648
+ const x = padding + i * xScale;
649
+ const y = height - padding - (d.price - yMin) * yScale;
650
+ return `${x},${y}`;
651
+ }).join(" L ");
652
+ const svg = `<?xml version="1.0" encoding="UTF-8"?>
653
+ <svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
654
+ <!-- Background -->
655
+ <rect width="100%" height="100%" fill="#f8f9fa"/>
656
+
657
+ <!-- Grid lines -->
658
+ <g stroke="#e9ecef" stroke-width="1">
659
+ ${Array.from({ length: 5 }, (_, i) => {
660
+ const y = padding + (height - 2 * padding) * i / 4;
661
+ return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
662
+ }).join("\n")}
663
+ </g>
664
+
665
+ <!-- Price line -->
666
+ <path d="M ${points}"
667
+ fill="none"
668
+ stroke="#007bff"
669
+ stroke-width="2"/>
670
+
671
+ <!-- Data points -->
672
+ ${priceHistory.map((d, i) => {
673
+ const x = padding + i * xScale;
674
+ const y = height - padding - (d.price - yMin) * yScale;
675
+ return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
676
+ }).join("\n")}
677
+
678
+ <!-- Labels -->
679
+ <g font-family="Arial" font-size="12" fill="#495057">
680
+ ${Array.from({ length: 5 }, (_, i) => {
681
+ const x = padding + (width - 2 * padding) * i / 4;
682
+ const index = Math.floor((priceHistory.length - 1) * i / 4);
683
+ const timestamp = new Date(priceHistory[index].timestamp).toLocaleTimeString();
684
+ return `<text x="${x + padding}" y="${height - padding + 20}" text-anchor="middle">${timestamp}</text>`;
685
+ }).join("\n")}
686
+ ${Array.from({ length: 5 }, (_, i) => {
687
+ const y = padding + (height - 2 * padding) * i / 4;
688
+ const price = yMax - (yMax - yMin) * i / 4;
689
+ return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
690
+ }).join("\n")}
691
+ </g>
692
+
693
+ <!-- Title -->
694
+ <text x="${width / 2}" y="${padding / 2}"
695
+ font-family="Arial" font-size="16" font-weight="bold"
696
+ text-anchor="middle" fill="#212529">
697
+ ${symbol} - Price Chart (${priceHistory.length} points)
698
+ </text>
699
+ </svg>`;
700
+ return {
701
+ contents: [
702
+ {
703
+ type: "text",
704
+ text: svg
705
+ }
706
+ ]
707
+ };
708
+ }
709
+ if (uri.startsWith("stockPriceHistory/")) {
710
+ const symbol = uri.split("/")[1];
711
+ const priceHistory = this.marketDataPrices.get(symbol) || [];
712
+ if (priceHistory.length === 0) {
713
+ return {
714
+ contents: [
715
+ {
716
+ type: "text",
717
+ text: `No price data available for ${symbol}`
718
+ }
719
+ ]
720
+ };
721
+ }
722
+ return {
723
+ contents: [
724
+ {
725
+ type: "text",
726
+ text: JSON.stringify(
727
+ {
728
+ symbol,
729
+ count: priceHistory.length,
730
+ prices: priceHistory.map((point) => ({
731
+ timestamp: new Date(point.timestamp).toISOString(),
732
+ price: point.price
733
+ }))
734
+ },
735
+ null,
736
+ 2
737
+ )
738
+ }
739
+ ]
740
+ };
741
+ }
742
+ return {
743
+ contents: [
744
+ {
745
+ type: "text",
746
+ text: `Resource not found: ${uri}`,
747
+ uri
748
+ }
749
+ ],
750
+ isError: true
751
+ };
752
+ }
753
+ }
754
+ );
755
+ this.server.setRequestHandler(
756
+ import_zod.z.object({
757
+ method: import_zod.z.literal("parse"),
758
+ params: fixStringSchema
759
+ }),
760
+ async (request, extra) => {
761
+ try {
762
+ const args = request.params;
763
+ const parsedMessage = this.parser?.parse(args.fixString);
764
+ if (!parsedMessage || parsedMessage.length === 0) {
765
+ return {
766
+ contents: [{ type: "text", text: "Error: Failed to parse FIX string" }],
767
+ isError: true
768
+ };
769
+ }
770
+ return {
771
+ contents: [
772
+ {
773
+ type: "text",
774
+ text: `${parsedMessage[0].description}
775
+ ${parsedMessage[0].messageTypeDescription}`
776
+ }
777
+ ]
778
+ };
779
+ } catch (error) {
977
780
  return {
978
- content: [
781
+ contents: [
979
782
  {
980
783
  type: "text",
981
- text: `Tool not found: ${name}`,
982
- uri: name
784
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
785
+ }
786
+ ],
787
+ isError: true
788
+ };
789
+ }
790
+ }
791
+ );
792
+ this.server.setRequestHandler(
793
+ import_zod.z.object({
794
+ method: import_zod.z.literal("parseToJSON"),
795
+ params: fixStringSchema
796
+ }),
797
+ async (request, extra) => {
798
+ try {
799
+ const args = request.params;
800
+ const parsedMessage = this.parser?.parse(args.fixString);
801
+ if (!parsedMessage || parsedMessage.length === 0) {
802
+ return {
803
+ contents: [{ type: "text", text: "Error: Failed to parse FIX string" }],
804
+ isError: true
805
+ };
806
+ }
807
+ return {
808
+ contents: [
809
+ {
810
+ type: "text",
811
+ text: `${parsedMessage[0].toFIXJSON()}`
812
+ }
813
+ ]
814
+ };
815
+ } catch (error) {
816
+ return {
817
+ contents: [
818
+ {
819
+ type: "text",
820
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
821
+ }
822
+ ],
823
+ isError: true
824
+ };
825
+ }
826
+ }
827
+ );
828
+ this.server.setRequestHandler(
829
+ import_zod.z.object({
830
+ method: import_zod.z.literal("verifyOrder"),
831
+ params: orderSchema
832
+ }),
833
+ async (request, extra) => {
834
+ try {
835
+ const args = request.params;
836
+ this.verifiedOrders.set(args.clOrdID, {
837
+ clOrdID: args.clOrdID,
838
+ handlInst: args.handlInst,
839
+ quantity: Number.parseFloat(args.quantity),
840
+ price: Number.parseFloat(args.price),
841
+ ordType: args.ordType,
842
+ side: args.side,
843
+ symbol: args.symbol,
844
+ timeInForce: args.timeInForce
845
+ });
846
+ const ordTypeNames = {
847
+ "1": "Market",
848
+ "2": "Limit",
849
+ "3": "Stop",
850
+ "4": "StopLimit",
851
+ "5": "MarketOnClose",
852
+ "6": "WithOrWithout",
853
+ "7": "LimitOrBetter",
854
+ "8": "LimitWithOrWithout",
855
+ "9": "OnBasis",
856
+ A: "OnClose",
857
+ B: "LimitOnClose",
858
+ C: "ForexMarket",
859
+ D: "PreviouslyQuoted",
860
+ E: "PreviouslyIndicated",
861
+ F: "ForexLimit",
862
+ G: "ForexSwap",
863
+ H: "ForexPreviouslyQuoted",
864
+ I: "Funari",
865
+ J: "MarketIfTouched",
866
+ K: "MarketWithLeftOverAsLimit",
867
+ L: "PreviousFundValuationPoint",
868
+ M: "NextFundValuationPoint",
869
+ P: "Pegged",
870
+ Q: "CounterOrderSelection",
871
+ R: "StopOnBidOrOffer",
872
+ S: "StopLimitOnBidOrOffer"
873
+ };
874
+ const sideNames = {
875
+ "1": "Buy",
876
+ "2": "Sell",
877
+ "3": "BuyMinus",
878
+ "4": "SellPlus",
879
+ "5": "SellShort",
880
+ "6": "SellShortExempt",
881
+ "7": "Undisclosed",
882
+ "8": "Cross",
883
+ "9": "CrossShort",
884
+ A: "CrossShortExempt",
885
+ B: "AsDefined",
886
+ C: "Opposite",
887
+ D: "Subscribe",
888
+ E: "Redeem",
889
+ F: "Lend",
890
+ G: "Borrow",
891
+ H: "SellUndisclosed"
892
+ };
893
+ const timeInForceNames = {
894
+ "0": "Day",
895
+ "1": "GoodTillCancel",
896
+ "2": "AtTheOpening",
897
+ "3": "ImmediateOrCancel",
898
+ "4": "FillOrKill",
899
+ "5": "GoodTillCrossing",
900
+ "6": "GoodTillDate",
901
+ "7": "AtTheClose",
902
+ "8": "GoodThroughCrossing",
903
+ "9": "AtCrossing",
904
+ A: "GoodForTime",
905
+ B: "GoodForAuction",
906
+ C: "GoodForMonth"
907
+ };
908
+ const handlInstNames = {
909
+ "1": "AutomatedExecutionNoIntervention",
910
+ "2": "AutomatedExecutionInterventionOK",
911
+ "3": "ManualOrder"
912
+ };
913
+ return {
914
+ contents: [
915
+ {
916
+ type: "text",
917
+ text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
918
+
919
+ Parameters verified:
920
+ - ClOrdID: ${args.clOrdID}
921
+ - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
922
+ - Quantity: ${args.quantity}
923
+ - Price: ${args.price}
924
+ - OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
925
+ - Side: ${args.side} (${sideNames[args.side]})
926
+ - Symbol: ${args.symbol}
927
+ - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
928
+
929
+ To execute this order, call the executeOrder tool with these exact same parameters.`
930
+ }
931
+ ]
932
+ };
933
+ } catch (error) {
934
+ return {
935
+ contents: [
936
+ {
937
+ type: "text",
938
+ text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
939
+ }
940
+ ],
941
+ isError: true
942
+ };
943
+ }
944
+ }
945
+ );
946
+ this.server.setRequestHandler(
947
+ import_zod.z.object({
948
+ method: import_zod.z.literal("executeOrder"),
949
+ params: orderSchema
950
+ }),
951
+ async (request, extra) => {
952
+ try {
953
+ const args = request.params;
954
+ const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
955
+ if (!verifiedOrder) {
956
+ return {
957
+ contents: [
958
+ {
959
+ type: "text",
960
+ text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
961
+ }
962
+ ],
963
+ isError: true
964
+ };
965
+ }
966
+ if (verifiedOrder.handlInst !== args.handlInst || verifiedOrder.quantity !== Number.parseFloat(args.quantity) || verifiedOrder.price !== Number.parseFloat(args.price) || verifiedOrder.ordType !== args.ordType || verifiedOrder.side !== args.side || verifiedOrder.symbol !== args.symbol || verifiedOrder.timeInForce !== args.timeInForce) {
967
+ return {
968
+ contents: [
969
+ {
970
+ type: "text",
971
+ text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
972
+ }
973
+ ],
974
+ isError: true
975
+ };
976
+ }
977
+ const response = new Promise((resolve) => {
978
+ this.pendingRequests.set(args.clOrdID, resolve);
979
+ });
980
+ const order = this.parser?.createMessage(
981
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
982
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
983
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
984
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
985
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
986
+ new import_fixparser.Field(import_fixparser.Fields.ClOrdID, args.clOrdID),
987
+ new import_fixparser.Field(import_fixparser.Fields.Side, args.side),
988
+ new import_fixparser.Field(import_fixparser.Fields.Symbol, args.symbol),
989
+ new import_fixparser.Field(import_fixparser.Fields.OrderQty, Number.parseFloat(args.quantity)),
990
+ new import_fixparser.Field(import_fixparser.Fields.Price, Number.parseFloat(args.price)),
991
+ new import_fixparser.Field(import_fixparser.Fields.OrdType, args.ordType),
992
+ new import_fixparser.Field(import_fixparser.Fields.HandlInst, args.handlInst),
993
+ new import_fixparser.Field(import_fixparser.Fields.TimeInForce, args.timeInForce),
994
+ new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
995
+ );
996
+ if (!this.parser?.connected) {
997
+ return {
998
+ contents: [
999
+ {
1000
+ type: "text",
1001
+ text: "Error: Not connected. Ignoring message."
1002
+ }
1003
+ ],
1004
+ isError: true
1005
+ };
1006
+ }
1007
+ this.parser?.send(order);
1008
+ const fixData = await response;
1009
+ this.verifiedOrders.delete(args.clOrdID);
1010
+ return {
1011
+ contents: [
1012
+ {
1013
+ type: "text",
1014
+ text: fixData.messageType === import_fixparser.Messages.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
1015
+ }
1016
+ ]
1017
+ };
1018
+ } catch (error) {
1019
+ return {
1020
+ contents: [
1021
+ {
1022
+ type: "text",
1023
+ text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
1024
+ }
1025
+ ],
1026
+ isError: true
1027
+ };
1028
+ }
1029
+ }
1030
+ );
1031
+ this.server.setRequestHandler(
1032
+ import_zod.z.object({
1033
+ method: import_zod.z.literal("marketDataRequest"),
1034
+ params: marketDataRequestSchema
1035
+ }),
1036
+ async (request, extra) => {
1037
+ try {
1038
+ const args = request.params;
1039
+ const response = new Promise((resolve) => {
1040
+ this.pendingRequests.set(args.mdReqID, resolve);
1041
+ });
1042
+ const messageFields = [
1043
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
1044
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
1045
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
1046
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
1047
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
1048
+ new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
1049
+ new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
1050
+ new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
1051
+ new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
1052
+ ];
1053
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
1054
+ args.symbols.forEach((symbol) => {
1055
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
1056
+ });
1057
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, args.mdEntryTypes.length));
1058
+ args.mdEntryTypes.forEach((entryType) => {
1059
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
1060
+ });
1061
+ const mdr = this.parser?.createMessage(...messageFields);
1062
+ if (!this.parser?.connected) {
1063
+ return {
1064
+ contents: [
1065
+ {
1066
+ type: "text",
1067
+ text: "Error: Not connected. Ignoring message."
1068
+ }
1069
+ ],
1070
+ isError: true
1071
+ };
1072
+ }
1073
+ this.parser?.send(mdr);
1074
+ const fixData = await response;
1075
+ return {
1076
+ contents: [
1077
+ {
1078
+ type: "text",
1079
+ text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`
1080
+ }
1081
+ ]
1082
+ };
1083
+ } catch (error) {
1084
+ return {
1085
+ contents: [
1086
+ {
1087
+ type: "text",
1088
+ text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
983
1089
  }
984
1090
  ],
985
1091
  isError: true
986
1092
  };
987
1093
  }
988
- const result = await handler(args);
989
- return {
990
- content: result.content,
991
- isError: result.isError
992
- };
993
1094
  }
994
1095
  );
995
1096
  process.on("SIGINT", async () => {