fixparser-plugin-mcp 9.1.7-c5ae06ce → 9.1.7-ce8f7927

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/MCPLocal.ts
@@ -23,21 +33,770 @@ __export(MCPLocal_exports, {
23
33
  MCPLocal: () => MCPLocal
24
34
  });
25
35
  module.exports = __toCommonJS(MCPLocal_exports);
26
- var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
36
+ var import_server = require("@modelcontextprotocol/sdk/server/index.js");
27
37
  var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
28
- var import_fixparser = require("fixparser");
38
+ var import_fixparser3 = require("fixparser");
29
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
+ 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"
243
+ }
244
+ }
245
+ },
246
+ required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType", "mdEntryTypes"]
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
+ 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 messageFields = [
281
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
282
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
283
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
284
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
285
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
286
+ new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
287
+ new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
288
+ new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
289
+ new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
290
+ ];
291
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
292
+ args.symbols.forEach((symbol) => {
293
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
294
+ });
295
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, args.mdEntryTypes.length));
296
+ args.mdEntryTypes.forEach((entryType) => {
297
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
298
+ });
299
+ const mdr = parser.createMessage(...messageFields);
300
+ if (!parser.connected) {
301
+ return {
302
+ content: [
303
+ {
304
+ type: "text",
305
+ text: "Error: Not connected. Ignoring message.",
306
+ uri: "marketDataRequest"
307
+ }
308
+ ],
309
+ isError: true
310
+ };
311
+ }
312
+ parser.send(mdr);
313
+ const fixData = await response;
314
+ return {
315
+ content: [
316
+ {
317
+ type: "text",
318
+ text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
319
+ uri: "marketDataRequest"
320
+ }
321
+ ]
322
+ };
323
+ } catch (error) {
324
+ return {
325
+ content: [
326
+ {
327
+ type: "text",
328
+ text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
329
+ uri: "marketDataRequest"
330
+ }
331
+ ],
332
+ isError: true
333
+ };
334
+ }
335
+ };
336
+ };
337
+ var createGetStockGraphHandler = (marketDataPrices) => {
338
+ return async (args) => {
339
+ try {
340
+ const symbol = args.symbol;
341
+ const priceHistory = marketDataPrices.get(symbol) || [];
342
+ if (priceHistory.length === 0) {
343
+ return {
344
+ content: [
345
+ {
346
+ type: "text",
347
+ text: `No price data available for ${symbol}`,
348
+ uri: "getStockGraph"
349
+ }
350
+ ]
351
+ };
352
+ }
353
+ const chart = new import_quickchart_js.default();
354
+ chart.setWidth(600);
355
+ chart.setHeight(300);
356
+ const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
357
+ const data = priceHistory.map((point) => point.price);
358
+ chart.setConfig({
359
+ type: "line",
360
+ data: {
361
+ labels,
362
+ datasets: [
363
+ {
364
+ label: symbol,
365
+ data,
366
+ borderColor: "#007bff",
367
+ backgroundColor: "rgba(0, 123, 255, 0.1)",
368
+ fill: true,
369
+ tension: 0.4
370
+ }
371
+ ]
372
+ },
373
+ options: {
374
+ plugins: {
375
+ title: {
376
+ display: true,
377
+ text: `${symbol} Price History`,
378
+ font: {
379
+ size: 16,
380
+ weight: "bold"
381
+ }
382
+ },
383
+ legend: {
384
+ display: true
385
+ }
386
+ },
387
+ scales: {
388
+ y: {
389
+ beginAtZero: false,
390
+ grid: {
391
+ color: "#e9ecef"
392
+ }
393
+ },
394
+ x: {
395
+ grid: {
396
+ display: false
397
+ }
398
+ }
399
+ }
400
+ }
401
+ });
402
+ const imageBuffer = await chart.toBinary();
403
+ const base64Image = imageBuffer.toString("base64");
404
+ return {
405
+ content: [
406
+ {
407
+ type: "image",
408
+ image: {
409
+ source: {
410
+ data: base64Image
411
+ }
412
+ },
413
+ uri: "getStockGraph",
414
+ mimeType: "image/png"
415
+ }
416
+ ]
417
+ };
418
+ } catch (error) {
419
+ return {
420
+ content: [
421
+ {
422
+ type: "text",
423
+ text: `Error: ${error instanceof Error ? error.message : "Failed to generate stock graph"}`,
424
+ uri: "getStockGraph"
425
+ }
426
+ ],
427
+ isError: true
428
+ };
429
+ }
430
+ };
431
+ };
432
+ var createGetStockPriceHistoryHandler = (marketDataPrices) => {
433
+ return async (args) => {
434
+ try {
435
+ const symbol = args.symbol;
436
+ const priceHistory = marketDataPrices.get(symbol) || [];
437
+ if (priceHistory.length === 0) {
438
+ return {
439
+ content: [
440
+ {
441
+ type: "text",
442
+ text: `No price data available for ${symbol}`,
443
+ uri: "getStockPriceHistory"
444
+ }
445
+ ]
446
+ };
447
+ }
448
+ return {
449
+ content: [
450
+ {
451
+ type: "text",
452
+ text: JSON.stringify(
453
+ {
454
+ symbol,
455
+ count: priceHistory.length,
456
+ prices: priceHistory.map((point) => ({
457
+ timestamp: new Date(point.timestamp).toISOString(),
458
+ price: point.price
459
+ }))
460
+ },
461
+ null,
462
+ 2
463
+ ),
464
+ uri: "getStockPriceHistory"
465
+ }
466
+ ]
467
+ };
468
+ } catch (error) {
469
+ return {
470
+ content: [
471
+ {
472
+ type: "text",
473
+ text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
474
+ uri: "getStockPriceHistory"
475
+ }
476
+ ],
477
+ isError: true
478
+ };
479
+ }
480
+ };
481
+ };
482
+
483
+ // src/tools/order.ts
484
+ var import_fixparser2 = require("fixparser");
485
+ var ordTypeNames = {
486
+ "1": "Market",
487
+ "2": "Limit",
488
+ "3": "Stop",
489
+ "4": "StopLimit",
490
+ "5": "MarketOnClose",
491
+ "6": "WithOrWithout",
492
+ "7": "LimitOrBetter",
493
+ "8": "LimitWithOrWithout",
494
+ "9": "OnBasis",
495
+ A: "OnClose",
496
+ B: "LimitOnClose",
497
+ C: "ForexMarket",
498
+ D: "PreviouslyQuoted",
499
+ E: "PreviouslyIndicated",
500
+ F: "ForexLimit",
501
+ G: "ForexSwap",
502
+ H: "ForexPreviouslyQuoted",
503
+ I: "Funari",
504
+ J: "MarketIfTouched",
505
+ K: "MarketWithLeftOverAsLimit",
506
+ L: "PreviousFundValuationPoint",
507
+ M: "NextFundValuationPoint",
508
+ P: "Pegged",
509
+ Q: "CounterOrderSelection",
510
+ R: "StopOnBidOrOffer",
511
+ S: "StopLimitOnBidOrOffer"
512
+ };
513
+ var sideNames = {
514
+ "1": "Buy",
515
+ "2": "Sell",
516
+ "3": "BuyMinus",
517
+ "4": "SellPlus",
518
+ "5": "SellShort",
519
+ "6": "SellShortExempt",
520
+ "7": "Undisclosed",
521
+ "8": "Cross",
522
+ "9": "CrossShort",
523
+ A: "CrossShortExempt",
524
+ B: "AsDefined",
525
+ C: "Opposite",
526
+ D: "Subscribe",
527
+ E: "Redeem",
528
+ F: "Lend",
529
+ G: "Borrow",
530
+ H: "SellUndisclosed"
531
+ };
532
+ var timeInForceNames = {
533
+ "0": "Day",
534
+ "1": "GoodTillCancel",
535
+ "2": "AtTheOpening",
536
+ "3": "ImmediateOrCancel",
537
+ "4": "FillOrKill",
538
+ "5": "GoodTillCrossing",
539
+ "6": "GoodTillDate",
540
+ "7": "AtTheClose",
541
+ "8": "GoodThroughCrossing",
542
+ "9": "AtCrossing",
543
+ A: "GoodForTime",
544
+ B: "GoodForAuction",
545
+ C: "GoodForMonth"
546
+ };
547
+ var handlInstNames = {
548
+ "1": "AutomatedExecutionNoIntervention",
549
+ "2": "AutomatedExecutionInterventionOK",
550
+ "3": "ManualOrder"
551
+ };
552
+ var createVerifyOrderHandler = (parser, verifiedOrders) => {
553
+ return async (args) => {
554
+ try {
555
+ verifiedOrders.set(args.clOrdID, {
556
+ clOrdID: args.clOrdID,
557
+ handlInst: args.handlInst,
558
+ quantity: Number.parseFloat(String(args.quantity)),
559
+ price: Number.parseFloat(String(args.price)),
560
+ ordType: args.ordType,
561
+ side: args.side,
562
+ symbol: args.symbol,
563
+ timeInForce: args.timeInForce
564
+ });
565
+ return {
566
+ content: [
567
+ {
568
+ type: "text",
569
+ text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
570
+
571
+ Parameters verified:
572
+ - ClOrdID: ${args.clOrdID}
573
+ - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
574
+ - Quantity: ${args.quantity}
575
+ - Price: ${args.price}
576
+ - OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
577
+ - Side: ${args.side} (${sideNames[args.side]})
578
+ - Symbol: ${args.symbol}
579
+ - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
580
+
581
+ To execute this order, call the executeOrder tool with these exact same parameters.`,
582
+ uri: "verifyOrder"
583
+ }
584
+ ]
585
+ };
586
+ } catch (error) {
587
+ return {
588
+ content: [
589
+ {
590
+ type: "text",
591
+ text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
592
+ uri: "verifyOrder"
593
+ }
594
+ ],
595
+ isError: true
596
+ };
597
+ }
598
+ };
599
+ };
600
+ var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
601
+ return async (args) => {
602
+ try {
603
+ const verifiedOrder = verifiedOrders.get(args.clOrdID);
604
+ if (!verifiedOrder) {
605
+ return {
606
+ content: [
607
+ {
608
+ type: "text",
609
+ text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
610
+ uri: "executeOrder"
611
+ }
612
+ ],
613
+ isError: true
614
+ };
615
+ }
616
+ 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) {
617
+ return {
618
+ content: [
619
+ {
620
+ type: "text",
621
+ text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
622
+ uri: "executeOrder"
623
+ }
624
+ ],
625
+ isError: true
626
+ };
627
+ }
628
+ const response = new Promise((resolve) => {
629
+ pendingRequests.set(args.clOrdID, resolve);
630
+ });
631
+ const order = parser.createMessage(
632
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
633
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
634
+ new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
635
+ new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
636
+ new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
637
+ new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
638
+ new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
639
+ new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
640
+ new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
641
+ new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
642
+ new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
643
+ new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
644
+ new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
645
+ new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
646
+ );
647
+ if (!parser.connected) {
648
+ return {
649
+ content: [
650
+ {
651
+ type: "text",
652
+ text: "Error: Not connected. Ignoring message.",
653
+ uri: "executeOrder"
654
+ }
655
+ ],
656
+ isError: true
657
+ };
658
+ }
659
+ parser.send(order);
660
+ const fixData = await response;
661
+ verifiedOrders.delete(args.clOrdID);
662
+ return {
663
+ content: [
664
+ {
665
+ type: "text",
666
+ 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())}`,
667
+ uri: "executeOrder"
668
+ }
669
+ ]
670
+ };
671
+ } catch (error) {
672
+ return {
673
+ content: [
674
+ {
675
+ type: "text",
676
+ text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
677
+ uri: "executeOrder"
678
+ }
679
+ ],
680
+ isError: true
681
+ };
682
+ }
683
+ };
684
+ };
685
+
686
+ // src/tools/parse.ts
687
+ var createParseHandler = (parser) => {
688
+ return async (args) => {
689
+ try {
690
+ const parsedMessage = parser.parse(args.fixString);
691
+ if (!parsedMessage || parsedMessage.length === 0) {
692
+ return {
693
+ content: [
694
+ {
695
+ type: "text",
696
+ text: "Error: Failed to parse FIX string",
697
+ uri: "parse"
698
+ }
699
+ ],
700
+ isError: true
701
+ };
702
+ }
703
+ return {
704
+ content: [
705
+ {
706
+ type: "text",
707
+ text: `${parsedMessage[0].description}
708
+ ${parsedMessage[0].messageTypeDescription}`,
709
+ uri: "parse"
710
+ }
711
+ ]
712
+ };
713
+ } catch (error) {
714
+ return {
715
+ content: [
716
+ {
717
+ type: "text",
718
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
719
+ uri: "parse"
720
+ }
721
+ ],
722
+ isError: true
723
+ };
724
+ }
725
+ };
726
+ };
727
+
728
+ // src/tools/parseToJSON.ts
729
+ var createParseToJSONHandler = (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: "parseToJSON"
740
+ }
741
+ ],
742
+ isError: true
743
+ };
744
+ }
745
+ return {
746
+ content: [
747
+ {
748
+ type: "text",
749
+ text: `${parsedMessage[0].toFIXJSON()}`,
750
+ uri: "parseToJSON"
751
+ }
752
+ ]
753
+ };
754
+ } catch (error) {
755
+ return {
756
+ content: [
757
+ {
758
+ type: "text",
759
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
760
+ uri: "parseToJSON"
761
+ }
762
+ ],
763
+ isError: true
764
+ };
765
+ }
766
+ };
767
+ };
768
+
769
+ // src/tools/index.ts
770
+ var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
771
+ parse: createParseHandler(parser),
772
+ parseToJSON: createParseToJSONHandler(parser),
773
+ verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
774
+ executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
775
+ marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
776
+ getStockGraph: createGetStockGraphHandler(marketDataPrices),
777
+ getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
778
+ });
779
+
780
+ // src/MCPLocal.ts
30
781
  var MCPLocal = class {
31
782
  parser;
32
- server = new import_mcp.McpServer(
783
+ server = new import_server.Server(
33
784
  {
34
785
  name: "fixparser",
35
786
  version: "1.0.0"
36
787
  },
37
788
  {
38
789
  capabilities: {
39
- tools: {},
40
- resources: {}
790
+ tools: Object.entries(toolSchemas).reduce(
791
+ (acc, [name, { description, schema }]) => {
792
+ acc[name] = {
793
+ description,
794
+ parameters: schema
795
+ };
796
+ return acc;
797
+ },
798
+ {}
799
+ )
41
800
  }
42
801
  }
43
802
  );
@@ -45,7 +804,6 @@ var MCPLocal = class {
45
804
  onReady = void 0;
46
805
  pendingRequests = /* @__PURE__ */ new Map();
47
806
  verifiedOrders = /* @__PURE__ */ new Map();
48
- // Store market data prices with timestamps
49
807
  marketDataPrices = /* @__PURE__ */ new Map();
50
808
  MAX_PRICE_HISTORY = 1e5;
51
809
  // Maximum number of price points to store per symbol
@@ -55,13 +813,21 @@ var MCPLocal = class {
55
813
  async register(parser) {
56
814
  this.parser = parser;
57
815
  this.parser.addOnMessageCallback((message) => {
816
+ this.parser?.logger.log({
817
+ level: "info",
818
+ message: `MCP Server received message: ${message.messageType}: ${message.description}`
819
+ });
58
820
  const msgType = message.messageType;
59
- if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport || msgType === import_fixparser.Messages.Reject || msgType === import_fixparser.Messages.MarketDataIncrementalRefresh) {
821
+ if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.ExecutionReport || msgType === import_fixparser3.Messages.Reject || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
822
+ this.parser?.logger.log({
823
+ level: "info",
824
+ message: `MCP Server handling message type: ${msgType}`
825
+ });
60
826
  let id;
61
- if (msgType === import_fixparser.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
62
- const symbol = message.getField(import_fixparser.Fields.Symbol);
63
- const price = message.getField(import_fixparser.Fields.MDEntryPx);
64
- const timestamp = message.getField(import_fixparser.Fields.MDEntryTime)?.value || Date.now();
827
+ if (msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
828
+ const symbol = message.getField(import_fixparser3.Fields.Symbol);
829
+ const price = message.getField(import_fixparser3.Fields.MDEntryPx);
830
+ const timestamp = message.getField(import_fixparser3.Fields.MDEntryTime)?.value || Date.now();
65
831
  if (symbol?.value && price?.value) {
66
832
  const symbolStr = String(symbol.value);
67
833
  const priceNum = Number(price.value);
@@ -74,16 +840,28 @@ var MCPLocal = class {
74
840
  priceHistory.shift();
75
841
  }
76
842
  this.marketDataPrices.set(symbolStr, priceHistory);
843
+ this.parser?.logger.log({
844
+ level: "info",
845
+ message: `MCP Server added ${symbol}: ${priceNum}`
846
+ });
847
+ this.server.notification({
848
+ method: "priceUpdate",
849
+ params: {
850
+ symbol: symbolStr,
851
+ price: priceNum,
852
+ timestamp: Number(timestamp)
853
+ }
854
+ });
77
855
  }
78
856
  }
79
- if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
80
- const mdReqID = message.getField(import_fixparser.Fields.MDReqID);
857
+ if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
858
+ const mdReqID = message.getField(import_fixparser3.Fields.MDReqID);
81
859
  if (mdReqID) id = String(mdReqID.value);
82
- } else if (msgType === import_fixparser.Messages.ExecutionReport) {
83
- const clOrdID = message.getField(import_fixparser.Fields.ClOrdID);
860
+ } else if (msgType === import_fixparser3.Messages.ExecutionReport) {
861
+ const clOrdID = message.getField(import_fixparser3.Fields.ClOrdID);
84
862
  if (clOrdID) id = String(clOrdID.value);
85
- } else if (msgType === import_fixparser.Messages.Reject) {
86
- const refSeqNum = message.getField(import_fixparser.Fields.RefSeqNum);
863
+ } else if (msgType === import_fixparser3.Messages.Reject) {
864
+ const refSeqNum = message.getField(import_fixparser3.Fields.RefSeqNum);
87
865
  if (refSeqNum) id = String(refSeqNum.value);
88
866
  }
89
867
  if (id) {
@@ -108,423 +886,54 @@ var MCPLocal = class {
108
886
  if (!this.server) {
109
887
  return;
110
888
  }
111
- this.server.tool(
112
- "parse",
113
- "Parses a FIX message and describes it in plain language",
114
- {
115
- fixString: import_zod.z.string().describe("FIX message string to parse")
116
- },
117
- async (args) => {
118
- try {
119
- const parsedMessage = this.parser?.parse(args.fixString);
120
- if (!parsedMessage || parsedMessage.length === 0) {
121
- return {
122
- content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
123
- isError: true
124
- };
125
- }
126
- return {
127
- content: [
128
- {
129
- type: "text",
130
- text: `${parsedMessage[0].description}
131
- ${parsedMessage[0].messageTypeDescription}`
132
- }
133
- ]
134
- };
135
- } catch (error) {
136
- return {
137
- content: [
138
- {
139
- type: "text",
140
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
141
- }
142
- ],
143
- isError: true
144
- };
145
- }
146
- }
147
- );
148
- this.server.tool(
149
- "parseToJSON",
150
- "Parses a FIX message into JSON",
151
- {
152
- fixString: import_zod.z.string().describe("FIX message string to parse")
153
- },
154
- async (args) => {
155
- try {
156
- const parsedMessage = this.parser?.parse(args.fixString);
157
- if (!parsedMessage || parsedMessage.length === 0) {
158
- return {
159
- content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
160
- isError: true
161
- };
162
- }
163
- return {
164
- content: [
165
- {
166
- type: "text",
167
- text: `${parsedMessage[0].toFIXJSON()}`
168
- }
169
- ]
170
- };
171
- } catch (error) {
172
- return {
173
- content: [
174
- {
175
- type: "text",
176
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
177
- }
178
- ],
179
- isError: true
180
- };
181
- }
182
- }
183
- );
184
- this.server.tool(
185
- "verifyOrder",
186
- "Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
187
- {
188
- clOrdID: import_zod.z.string().describe("Client Order ID"),
189
- handlInst: import_zod.z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
190
- quantity: import_zod.z.string().describe("Order quantity"),
191
- price: import_zod.z.string().describe("Order price"),
192
- ordType: import_zod.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
193
- side: import_zod.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
194
- symbol: import_zod.z.string().describe("Trading symbol"),
195
- timeInForce: import_zod.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
196
- },
197
- async (args) => {
198
- try {
199
- this.verifiedOrders.set(args.clOrdID, {
200
- clOrdID: args.clOrdID,
201
- handlInst: args.handlInst,
202
- quantity: Number.parseFloat(args.quantity),
203
- price: Number.parseFloat(args.price),
204
- ordType: args.ordType,
205
- side: args.side,
206
- symbol: args.symbol,
207
- timeInForce: args.timeInForce
208
- });
209
- return {
210
- content: [
211
- {
212
- type: "text",
213
- text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
214
-
215
- Parameters verified:
216
- - ClOrdID: ${args.clOrdID}
217
- - HandlInst: ${args.handlInst}
218
- - Quantity: ${args.quantity}
219
- - Price: ${args.price}
220
- - OrdType: ${args.ordType}
221
- - Side: ${args.side}
222
- - Symbol: ${args.symbol}
223
- - TimeInForce: ${args.timeInForce}
224
-
225
- To execute this order, call the executeOrder tool with these exact same parameters.`
226
- }
227
- ]
228
- };
229
- } catch (error) {
230
- return {
231
- content: [
232
- {
233
- type: "text",
234
- text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
235
- }
236
- ],
237
- isError: true
238
- };
239
- }
240
- }
241
- );
242
- this.server.tool(
243
- "executeOrder",
244
- "Executes a New Order Single after verification. This is the second step - only call after successful verification.",
245
- {
246
- clOrdID: import_zod.z.string().describe("Client Order ID"),
247
- handlInst: import_zod.z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
248
- quantity: import_zod.z.string().describe("Order quantity"),
249
- price: import_zod.z.string().describe("Order price"),
250
- ordType: import_zod.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
251
- side: import_zod.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
252
- symbol: import_zod.z.string().describe("Trading symbol"),
253
- timeInForce: import_zod.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
254
- },
255
- async (args) => {
256
- try {
257
- const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
258
- if (!verifiedOrder) {
259
- return {
260
- content: [
261
- {
262
- type: "text",
263
- text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
264
- }
265
- ],
266
- isError: true
267
- };
268
- }
269
- 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) {
270
- return {
271
- content: [
272
- {
273
- type: "text",
274
- text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
275
- }
276
- ],
277
- isError: true
278
- };
279
- }
280
- const response = new Promise((resolve) => {
281
- this.pendingRequests.set(args.clOrdID, resolve);
282
- });
283
- const order = this.parser?.createMessage(
284
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
285
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
286
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
287
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
288
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
289
- new import_fixparser.Field(import_fixparser.Fields.ClOrdID, args.clOrdID),
290
- new import_fixparser.Field(import_fixparser.Fields.Side, args.side),
291
- new import_fixparser.Field(import_fixparser.Fields.Symbol, args.symbol),
292
- new import_fixparser.Field(import_fixparser.Fields.OrderQty, Number.parseFloat(args.quantity)),
293
- new import_fixparser.Field(import_fixparser.Fields.Price, Number.parseFloat(args.price)),
294
- new import_fixparser.Field(import_fixparser.Fields.OrdType, args.ordType),
295
- new import_fixparser.Field(import_fixparser.Fields.HandlInst, args.handlInst),
296
- new import_fixparser.Field(import_fixparser.Fields.TimeInForce, args.timeInForce),
297
- new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
298
- );
299
- if (!this.parser?.connected) {
300
- return {
301
- content: [
302
- {
303
- type: "text",
304
- text: "Error: Not connected. Ignoring message."
305
- }
306
- ],
307
- isError: true
308
- };
309
- }
310
- this.parser?.send(order);
311
- const fixData = await response;
312
- this.verifiedOrders.delete(args.clOrdID);
313
- return {
314
- content: [
315
- {
316
- type: "text",
317
- 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())}`
318
- }
319
- ]
320
- };
321
- } catch (error) {
322
- return {
323
- content: [
324
- {
325
- type: "text",
326
- text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
327
- }
328
- ],
329
- isError: true
330
- };
331
- }
889
+ this.server.setRequestHandler(
890
+ import_zod.z.object({ method: import_zod.z.literal("tools/list") }),
891
+ async (request, extra) => {
892
+ return {
893
+ tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
894
+ name,
895
+ description,
896
+ inputSchema: schema
897
+ }))
898
+ };
332
899
  }
333
900
  );
334
- this.server.tool(
335
- "marketDataRequest",
336
- "Sends a request for Market Data with the given symbol. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",
337
- {
338
- mdUpdateType: import_zod.z.enum(["0", "1"]).describe("Market data update type (0=FullRefresh, 1=IncrementalRefresh)"),
339
- symbols: import_zod.z.array(import_zod.z.string()).min(1).describe("Array of trading symbols"),
340
- mdReqID: import_zod.z.string().describe("Market data request ID"),
341
- subscriptionRequestType: import_zod.z.enum(["0", "1", "2"]).describe("Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)"),
342
- mdEntryTypes: import_zod.z.array(import_zod.z.string()).min(1).describe("Array of market data entry types (0=Bid, 1=Offer, 2=Trade, etc.)")
343
- },
344
- async (args) => {
345
- try {
346
- const response = new Promise((resolve) => {
347
- this.pendingRequests.set(args.mdReqID, resolve);
348
- });
349
- const messageFields = [
350
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
351
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
352
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
353
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
354
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
355
- new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
356
- new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
357
- new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
358
- new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
359
- ];
360
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
361
- args.symbols.forEach((symbol) => {
362
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
363
- });
364
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, args.mdEntryTypes.length));
365
- args.mdEntryTypes.forEach((entryType) => {
366
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
367
- });
368
- const mdr = this.parser?.createMessage(...messageFields);
369
- if (!this.parser?.connected) {
370
- return {
371
- content: [
372
- {
373
- type: "text",
374
- text: "Error: Not connected. Ignoring message."
375
- }
376
- ],
377
- isError: true
378
- };
379
- }
380
- this.parser?.send(mdr);
381
- const fixData = await response;
382
- return {
383
- content: [
384
- {
385
- type: "text",
386
- text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`
387
- }
388
- ]
389
- };
390
- } catch (error) {
901
+ this.server.setRequestHandler(
902
+ import_zod.z.object({
903
+ method: import_zod.z.literal("tools/call"),
904
+ params: import_zod.z.object({
905
+ name: import_zod.z.string(),
906
+ arguments: import_zod.z.any(),
907
+ _meta: import_zod.z.object({
908
+ progressToken: import_zod.z.number()
909
+ }).optional()
910
+ })
911
+ }),
912
+ async (request, extra) => {
913
+ const { name, arguments: args } = request.params;
914
+ const toolHandlers = createToolHandlers(
915
+ this.parser,
916
+ this.verifiedOrders,
917
+ this.pendingRequests,
918
+ this.marketDataPrices
919
+ );
920
+ const handler = toolHandlers[name];
921
+ if (!handler) {
391
922
  return {
392
923
  content: [
393
924
  {
394
925
  type: "text",
395
- text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
926
+ text: `Tool not found: ${name}`,
927
+ uri: name
396
928
  }
397
929
  ],
398
930
  isError: true
399
931
  };
400
932
  }
401
- }
402
- );
403
- this.server.resource(
404
- "greeting-resource",
405
- "https://example.com/greetings/default",
406
- { mimeType: "text/plain" },
407
- async () => {
933
+ const result = await handler(args);
408
934
  return {
409
- contents: [
410
- {
411
- uri: "https://example.com/greetings/default",
412
- text: "Hello, world!"
413
- }
414
- ]
415
- };
416
- }
417
- );
418
- this.server.resource(
419
- "stockGraph",
420
- new import_mcp.ResourceTemplate("stock://{symbol}", { list: void 0 }),
421
- async (uri, variables) => {
422
- const symbol = String(variables.symbol);
423
- const priceHistory = this.marketDataPrices.get(symbol) || [];
424
- if (priceHistory.length === 0) {
425
- return {
426
- contents: [
427
- {
428
- uri: uri.href,
429
- text: `No price data available for ${symbol}`
430
- }
431
- ]
432
- };
433
- }
434
- const width = 600;
435
- const height = 300;
436
- const padding = 40;
437
- const xScale = (width - 2 * padding) / (priceHistory.length - 1);
438
- const yMin = Math.min(...priceHistory.map((d) => d.price));
439
- const yMax = Math.max(...priceHistory.map((d) => d.price));
440
- const yScale = (height - 2 * padding) / (yMax - yMin);
441
- const points = priceHistory.map((d, i) => {
442
- const x = padding + i * xScale;
443
- const y = height - padding - (d.price - yMin) * yScale;
444
- return `${x},${y}`;
445
- }).join(" L ");
446
- const svg = `<?xml version="1.0" encoding="UTF-8"?>
447
- <svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
448
- <!-- Background -->
449
- <rect width="100%" height="100%" fill="#f8f9fa"/>
450
-
451
- <!-- Grid lines -->
452
- <g stroke="#e9ecef" stroke-width="1">
453
- ${Array.from({ length: 5 }, (_, i) => {
454
- const y = padding + (height - 2 * padding) * i / 4;
455
- return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
456
- }).join("\n")}
457
- </g>
458
-
459
- <!-- Price line -->
460
- <path d="M ${points}"
461
- fill="none"
462
- stroke="#007bff"
463
- stroke-width="2"/>
464
-
465
- <!-- Data points -->
466
- ${priceHistory.map((d, i) => {
467
- const x = padding + i * xScale;
468
- const y = height - padding - (d.price - yMin) * yScale;
469
- return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
470
- }).join("\n")}
471
-
472
- <!-- Labels -->
473
- <g font-family="Arial" font-size="12" fill="#495057">
474
- ${Array.from({ length: 5 }, (_, i) => {
475
- const x = padding + (width - 2 * padding) * i / 4;
476
- const index = Math.floor((priceHistory.length - 1) * i / 4);
477
- const timestamp = new Date(priceHistory[index].timestamp).toLocaleTimeString();
478
- return `<text x="${x + padding}" y="${height - padding + 20}" text-anchor="middle">${timestamp}</text>`;
479
- }).join("\n")}
480
- ${Array.from({ length: 5 }, (_, i) => {
481
- const y = padding + (height - 2 * padding) * i / 4;
482
- const price = yMax - (yMax - yMin) * i / 4;
483
- return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
484
- }).join("\n")}
485
- </g>
486
-
487
- <!-- Title -->
488
- <text x="${width / 2}" y="${padding / 2}"
489
- font-family="Arial" font-size="16" font-weight="bold"
490
- text-anchor="middle" fill="#212529">
491
- ${symbol} - Price Chart (${priceHistory.length} points)
492
- </text>
493
- </svg>`;
494
- return {
495
- contents: [
496
- {
497
- uri: uri.href,
498
- text: svg
499
- }
500
- ]
501
- };
502
- }
503
- );
504
- this.server.resource(
505
- "stockPriceHistory",
506
- new import_mcp.ResourceTemplate("price-history://{symbol}", { list: void 0 }),
507
- async (uri, variables) => {
508
- const symbol = String(variables.symbol);
509
- const priceHistory = this.marketDataPrices.get(symbol) || [];
510
- return {
511
- contents: [
512
- {
513
- uri: uri.href,
514
- text: JSON.stringify(
515
- {
516
- symbol,
517
- count: priceHistory.length,
518
- prices: priceHistory.map((point) => ({
519
- timestamp: new Date(point.timestamp).toISOString(),
520
- price: point.price
521
- }))
522
- },
523
- null,
524
- 2
525
- )
526
- }
527
- ]
935
+ content: result.content,
936
+ isError: result.isError
528
937
  };
529
938
  }
530
939
  );