fixparser-plugin-mcp 9.1.7-9eab5b4d → 9.1.7-a0e655a2

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