fixparser-plugin-mcp 9.1.7-46844c62 → 9.1.7-4a3d3ac7

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