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