fixparser-plugin-mcp 9.1.7-ce8f7927 → 9.1.7-d47799ff

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,770 +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
- description: "Market Data Entry Types: 0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price, 5=Closing Price, 6=Settlement Price, 7=High Price, 8=Low Price, 9=Trade Volume, A=Open Interest, B=Simulated Sell Price, C=Simulated Buy Price, D=Empty Book, E=Session High Bid, F=Session Low Offer, G=Fixing Price, H=Electronic Volume, I=Threshold Limits and Price Band Variation, J=Clearing Price, K=Open Interest Change, L=Last Trade Price, M=Last Trade Volume, N=Last Trade Time, O=Last Trade Tick, P=Last Trade Exchange, Q=Last Trade ID, R=Last Trade Side, S=Last Trade Price Change, T=Last Trade Price Change Percent, U=Last Trade Price Change Basis Points, V=Last Trade Price Change Points, W=Last Trade Price Change Ticks, X=Last Trade Price Change Ticks Percent, Y=Last Trade Price Change Ticks Basis Points, Z=Last Trade Price Change Ticks Points"
243
- }
244
- }
245
- },
246
- required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType", "mdEntryTypes"]
247
- }
248
- },
249
- getStockGraph: {
250
- description: "Generates a price chart for a given symbol",
251
- schema: {
252
- type: "object",
253
- properties: {
254
- symbol: { type: "string" }
255
- },
256
- required: ["symbol"]
257
- }
258
- },
259
- getStockPriceHistory: {
260
- description: "Returns price history for a given symbol",
261
- schema: {
262
- type: "object",
263
- properties: {
264
- symbol: { type: "string" }
265
- },
266
- required: ["symbol"]
267
- }
268
- }
269
- };
270
-
271
- // src/tools/marketData.ts
272
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 messageFields = [
281
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
282
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
283
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
284
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
285
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
286
- new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
287
- new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
288
- new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
289
- new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
290
- ];
291
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
292
- args.symbols.forEach((symbol) => {
293
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
294
- });
295
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, args.mdEntryTypes.length));
296
- args.mdEntryTypes.forEach((entryType) => {
297
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
298
- });
299
- const mdr = parser.createMessage(...messageFields);
300
- if (!parser.connected) {
301
- return {
302
- content: [
303
- {
304
- type: "text",
305
- text: "Error: Not connected. Ignoring message.",
306
- uri: "marketDataRequest"
307
- }
308
- ],
309
- isError: true
310
- };
311
- }
312
- parser.send(mdr);
313
- const fixData = await response;
314
- return {
315
- content: [
316
- {
317
- type: "text",
318
- text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
319
- uri: "marketDataRequest"
320
- }
321
- ]
322
- };
323
- } catch (error) {
324
- return {
325
- content: [
326
- {
327
- type: "text",
328
- text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
329
- uri: "marketDataRequest"
330
- }
331
- ],
332
- isError: true
333
- };
334
- }
335
- };
336
- };
337
- var createGetStockGraphHandler = (marketDataPrices) => {
338
- return async (args) => {
339
- try {
340
- const symbol = args.symbol;
341
- const priceHistory = marketDataPrices.get(symbol) || [];
342
- if (priceHistory.length === 0) {
343
- return {
344
- content: [
345
- {
346
- type: "text",
347
- text: `No price data available for ${symbol}`,
348
- uri: "getStockGraph"
349
- }
350
- ]
351
- };
352
- }
353
- const chart = new import_quickchart_js.default();
354
- chart.setWidth(600);
355
- chart.setHeight(300);
356
- const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
357
- const data = priceHistory.map((point) => point.price);
358
- chart.setConfig({
359
- type: "line",
360
- data: {
361
- labels,
362
- datasets: [
363
- {
364
- label: symbol,
365
- data,
366
- borderColor: "#007bff",
367
- backgroundColor: "rgba(0, 123, 255, 0.1)",
368
- fill: true,
369
- tension: 0.4
370
- }
371
- ]
372
- },
373
- options: {
374
- plugins: {
375
- title: {
376
- display: true,
377
- text: `${symbol} Price History`,
378
- font: {
379
- size: 16,
380
- weight: "bold"
381
- }
382
- },
383
- legend: {
384
- display: true
385
- }
386
- },
387
- scales: {
388
- y: {
389
- beginAtZero: false,
390
- grid: {
391
- color: "#e9ecef"
392
- }
393
- },
394
- x: {
395
- grid: {
396
- display: false
397
- }
398
- }
399
- }
400
- }
401
- });
402
- const imageBuffer = await chart.toBinary();
403
- const base64Image = imageBuffer.toString("base64");
404
- return {
405
- content: [
406
- {
407
- type: "image",
408
- image: {
409
- source: {
410
- data: base64Image
411
- }
412
- },
413
- uri: "getStockGraph",
414
- mimeType: "image/png"
415
- }
416
- ]
417
- };
418
- } catch (error) {
419
- return {
420
- content: [
421
- {
422
- type: "text",
423
- text: `Error: ${error instanceof Error ? error.message : "Failed to generate stock graph"}`,
424
- uri: "getStockGraph"
425
- }
426
- ],
427
- isError: true
428
- };
429
- }
430
- };
431
- };
432
- var createGetStockPriceHistoryHandler = (marketDataPrices) => {
433
- return async (args) => {
434
- try {
435
- const symbol = args.symbol;
436
- const priceHistory = marketDataPrices.get(symbol) || [];
437
- if (priceHistory.length === 0) {
438
- return {
439
- content: [
440
- {
441
- type: "text",
442
- text: `No price data available for ${symbol}`,
443
- uri: "getStockPriceHistory"
444
- }
445
- ]
446
- };
447
- }
448
- return {
449
- content: [
450
- {
451
- type: "text",
452
- text: JSON.stringify(
453
- {
454
- symbol,
455
- count: priceHistory.length,
456
- prices: priceHistory.map((point) => ({
457
- timestamp: new Date(point.timestamp).toISOString(),
458
- price: point.price
459
- }))
460
- },
461
- null,
462
- 2
463
- ),
464
- uri: "getStockPriceHistory"
465
- }
466
- ]
467
- };
468
- } catch (error) {
469
- return {
470
- content: [
471
- {
472
- type: "text",
473
- text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
474
- uri: "getStockPriceHistory"
475
- }
476
- ],
477
- isError: true
478
- };
479
- }
480
- };
481
- };
482
-
483
- // src/tools/order.ts
484
- var import_fixparser2 = require("fixparser");
485
- var ordTypeNames = {
486
- "1": "Market",
487
- "2": "Limit",
488
- "3": "Stop",
489
- "4": "StopLimit",
490
- "5": "MarketOnClose",
491
- "6": "WithOrWithout",
492
- "7": "LimitOrBetter",
493
- "8": "LimitWithOrWithout",
494
- "9": "OnBasis",
495
- A: "OnClose",
496
- B: "LimitOnClose",
497
- C: "ForexMarket",
498
- D: "PreviouslyQuoted",
499
- E: "PreviouslyIndicated",
500
- F: "ForexLimit",
501
- G: "ForexSwap",
502
- H: "ForexPreviouslyQuoted",
503
- I: "Funari",
504
- J: "MarketIfTouched",
505
- K: "MarketWithLeftOverAsLimit",
506
- L: "PreviousFundValuationPoint",
507
- M: "NextFundValuationPoint",
508
- P: "Pegged",
509
- Q: "CounterOrderSelection",
510
- R: "StopOnBidOrOffer",
511
- S: "StopLimitOnBidOrOffer"
512
- };
513
- var sideNames = {
514
- "1": "Buy",
515
- "2": "Sell",
516
- "3": "BuyMinus",
517
- "4": "SellPlus",
518
- "5": "SellShort",
519
- "6": "SellShortExempt",
520
- "7": "Undisclosed",
521
- "8": "Cross",
522
- "9": "CrossShort",
523
- A: "CrossShortExempt",
524
- B: "AsDefined",
525
- C: "Opposite",
526
- D: "Subscribe",
527
- E: "Redeem",
528
- F: "Lend",
529
- G: "Borrow",
530
- H: "SellUndisclosed"
531
- };
532
- var timeInForceNames = {
533
- "0": "Day",
534
- "1": "GoodTillCancel",
535
- "2": "AtTheOpening",
536
- "3": "ImmediateOrCancel",
537
- "4": "FillOrKill",
538
- "5": "GoodTillCrossing",
539
- "6": "GoodTillDate",
540
- "7": "AtTheClose",
541
- "8": "GoodThroughCrossing",
542
- "9": "AtCrossing",
543
- A: "GoodForTime",
544
- B: "GoodForAuction",
545
- C: "GoodForMonth"
546
- };
547
- var handlInstNames = {
548
- "1": "AutomatedExecutionNoIntervention",
549
- "2": "AutomatedExecutionInterventionOK",
550
- "3": "ManualOrder"
551
- };
552
- var createVerifyOrderHandler = (parser, verifiedOrders) => {
553
- return async (args) => {
554
- try {
555
- verifiedOrders.set(args.clOrdID, {
556
- clOrdID: args.clOrdID,
557
- handlInst: args.handlInst,
558
- quantity: Number.parseFloat(String(args.quantity)),
559
- price: Number.parseFloat(String(args.price)),
560
- ordType: args.ordType,
561
- side: args.side,
562
- symbol: args.symbol,
563
- timeInForce: args.timeInForce
564
- });
565
- return {
566
- content: [
567
- {
568
- type: "text",
569
- text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
570
-
571
- Parameters verified:
572
- - ClOrdID: ${args.clOrdID}
573
- - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
574
- - Quantity: ${args.quantity}
575
- - Price: ${args.price}
576
- - OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
577
- - Side: ${args.side} (${sideNames[args.side]})
578
- - Symbol: ${args.symbol}
579
- - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
580
-
581
- To execute this order, call the executeOrder tool with these exact same parameters.`,
582
- uri: "verifyOrder"
583
- }
584
- ]
585
- };
586
- } catch (error) {
587
- return {
588
- content: [
589
- {
590
- type: "text",
591
- text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
592
- uri: "verifyOrder"
593
- }
594
- ],
595
- isError: true
596
- };
597
- }
598
- };
599
- };
600
- var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
601
- return async (args) => {
602
- try {
603
- const verifiedOrder = verifiedOrders.get(args.clOrdID);
604
- if (!verifiedOrder) {
605
- return {
606
- content: [
607
- {
608
- type: "text",
609
- text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
610
- uri: "executeOrder"
611
- }
612
- ],
613
- isError: true
614
- };
615
- }
616
- if (verifiedOrder.handlInst !== args.handlInst || verifiedOrder.quantity !== Number.parseFloat(String(args.quantity)) || verifiedOrder.price !== Number.parseFloat(String(args.price)) || verifiedOrder.ordType !== args.ordType || verifiedOrder.side !== args.side || verifiedOrder.symbol !== args.symbol || verifiedOrder.timeInForce !== args.timeInForce) {
617
- return {
618
- content: [
619
- {
620
- type: "text",
621
- text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
622
- uri: "executeOrder"
623
- }
624
- ],
625
- isError: true
626
- };
627
- }
628
- const response = new Promise((resolve) => {
629
- pendingRequests.set(args.clOrdID, resolve);
630
- });
631
- const order = parser.createMessage(
632
- new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
633
- new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
634
- new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
635
- new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
636
- new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
637
- new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
638
- new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
639
- new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
640
- new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
641
- new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
642
- new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
643
- new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
644
- new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
645
- new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
646
- );
647
- if (!parser.connected) {
648
- return {
649
- content: [
650
- {
651
- type: "text",
652
- text: "Error: Not connected. Ignoring message.",
653
- uri: "executeOrder"
654
- }
655
- ],
656
- isError: true
657
- };
658
- }
659
- parser.send(order);
660
- const fixData = await response;
661
- verifiedOrders.delete(args.clOrdID);
662
- return {
663
- content: [
664
- {
665
- type: "text",
666
- text: fixData.messageType === import_fixparser2.Messages.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`,
667
- uri: "executeOrder"
668
- }
669
- ]
670
- };
671
- } catch (error) {
672
- return {
673
- content: [
674
- {
675
- type: "text",
676
- text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
677
- uri: "executeOrder"
678
- }
679
- ],
680
- isError: true
681
- };
682
- }
683
- };
684
- };
685
-
686
- // src/tools/parse.ts
687
- var createParseHandler = (parser) => {
688
- return async (args) => {
689
- try {
690
- const parsedMessage = parser.parse(args.fixString);
691
- if (!parsedMessage || parsedMessage.length === 0) {
692
- return {
693
- content: [
694
- {
695
- type: "text",
696
- text: "Error: Failed to parse FIX string",
697
- uri: "parse"
698
- }
699
- ],
700
- isError: true
701
- };
702
- }
703
- return {
704
- content: [
705
- {
706
- type: "text",
707
- text: `${parsedMessage[0].description}
708
- ${parsedMessage[0].messageTypeDescription}`,
709
- uri: "parse"
710
- }
711
- ]
712
- };
713
- } catch (error) {
714
- return {
715
- content: [
716
- {
717
- type: "text",
718
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
719
- uri: "parse"
720
- }
721
- ],
722
- isError: true
723
- };
724
- }
725
- };
726
- };
727
-
728
- // src/tools/parseToJSON.ts
729
- var createParseToJSONHandler = (parser) => {
730
- return async (args) => {
731
- try {
732
- const parsedMessage = parser.parse(args.fixString);
733
- if (!parsedMessage || parsedMessage.length === 0) {
734
- return {
735
- content: [
736
- {
737
- type: "text",
738
- text: "Error: Failed to parse FIX string",
739
- uri: "parseToJSON"
740
- }
741
- ],
742
- isError: true
743
- };
744
- }
745
- return {
746
- content: [
747
- {
748
- type: "text",
749
- text: `${parsedMessage[0].toFIXJSON()}`,
750
- uri: "parseToJSON"
751
- }
752
- ]
753
- };
754
- } catch (error) {
755
- return {
756
- content: [
757
- {
758
- type: "text",
759
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
760
- uri: "parseToJSON"
761
- }
762
- ],
763
- isError: true
764
- };
765
- }
766
- };
767
- };
768
-
769
- // src/tools/index.ts
770
- var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
771
- parse: createParseHandler(parser),
772
- parseToJSON: createParseToJSONHandler(parser),
773
- verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
774
- executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
775
- marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
776
- getStockGraph: createGetStockGraphHandler(marketDataPrices),
777
- getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
778
- });
779
-
780
- // src/MCPLocal.ts
29
+ var import_zod = require("zod");
781
30
  var MCPLocal = class {
782
31
  parser;
783
- server = new import_server.Server(
32
+ server = new import_mcp.McpServer(
784
33
  {
785
34
  name: "fixparser",
786
35
  version: "1.0.0"
787
36
  },
788
37
  {
789
38
  capabilities: {
790
- tools: Object.entries(toolSchemas).reduce(
791
- (acc, [name, { description, schema }]) => {
792
- acc[name] = {
793
- description,
794
- parameters: schema
795
- };
796
- return acc;
797
- },
798
- {}
799
- )
39
+ tools: {},
40
+ prompts: {},
41
+ resources: {}
800
42
  }
801
43
  }
802
44
  );
@@ -804,64 +46,23 @@ var MCPLocal = class {
804
46
  onReady = void 0;
805
47
  pendingRequests = /* @__PURE__ */ new Map();
806
48
  verifiedOrders = /* @__PURE__ */ new Map();
807
- marketDataPrices = /* @__PURE__ */ new Map();
808
- MAX_PRICE_HISTORY = 1e5;
809
- // Maximum number of price points to store per symbol
810
49
  constructor({ logger, onReady }) {
811
50
  if (onReady) this.onReady = onReady;
812
51
  }
813
52
  async register(parser) {
814
53
  this.parser = parser;
815
54
  this.parser.addOnMessageCallback((message) => {
816
- this.parser?.logger.log({
817
- level: "info",
818
- message: `MCP Server received message: ${message.messageType}: ${message.description}`
819
- });
820
55
  const msgType = message.messageType;
821
- if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.ExecutionReport || msgType === import_fixparser3.Messages.Reject || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
822
- this.parser?.logger.log({
823
- level: "info",
824
- message: `MCP Server handling message type: ${msgType}`
825
- });
56
+ if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport || msgType === import_fixparser.Messages.Reject) {
826
57
  let id;
827
- if (msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
828
- const symbol = message.getField(import_fixparser3.Fields.Symbol);
829
- const price = message.getField(import_fixparser3.Fields.MDEntryPx);
830
- const timestamp = message.getField(import_fixparser3.Fields.MDEntryTime)?.value || Date.now();
831
- if (symbol?.value && price?.value) {
832
- const symbolStr = String(symbol.value);
833
- const priceNum = Number(price.value);
834
- const priceHistory = this.marketDataPrices.get(symbolStr) || [];
835
- priceHistory.push({
836
- timestamp: Number(timestamp),
837
- price: priceNum
838
- });
839
- if (priceHistory.length > this.MAX_PRICE_HISTORY) {
840
- priceHistory.shift();
841
- }
842
- this.marketDataPrices.set(symbolStr, priceHistory);
843
- this.parser?.logger.log({
844
- level: "info",
845
- message: `MCP Server added ${symbol}: ${priceNum}`
846
- });
847
- this.server.notification({
848
- method: "priceUpdate",
849
- params: {
850
- symbol: symbolStr,
851
- price: priceNum,
852
- timestamp: Number(timestamp)
853
- }
854
- });
855
- }
856
- }
857
- if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
858
- const mdReqID = message.getField(import_fixparser3.Fields.MDReqID);
58
+ if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
59
+ const mdReqID = message.getField(import_fixparser.Fields.MDReqID);
859
60
  if (mdReqID) id = String(mdReqID.value);
860
- } else if (msgType === import_fixparser3.Messages.ExecutionReport) {
861
- 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);
862
63
  if (clOrdID) id = String(clOrdID.value);
863
- } else if (msgType === import_fixparser3.Messages.Reject) {
864
- 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);
865
66
  if (refSeqNum) id = String(refSeqNum.value);
866
67
  }
867
68
  if (id) {
@@ -886,54 +87,601 @@ var MCPLocal = class {
886
87
  if (!this.server) {
887
88
  return;
888
89
  }
889
- this.server.setRequestHandler(
890
- import_zod.z.object({ method: import_zod.z.literal("tools/list") }),
891
- async (request, extra) => {
892
- return {
893
- tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
894
- name,
895
- description,
896
- inputSchema: schema
897
- }))
898
- };
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
+ }
125
+ }
126
+ );
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) {
151
+ return {
152
+ content: [
153
+ {
154
+ type: "text",
155
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
156
+ }
157
+ ],
158
+ isError: true
159
+ };
160
+ }
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
+ }
899
311
  }
900
312
  );
901
- this.server.setRequestHandler(
902
- import_zod.z.object({
903
- method: import_zod.z.literal("tools/call"),
904
- params: import_zod.z.object({
905
- name: import_zod.z.string(),
906
- arguments: import_zod.z.any(),
907
- _meta: import_zod.z.object({
908
- progressToken: import_zod.z.number()
909
- }).optional()
910
- })
911
- }),
912
- async (request, extra) => {
913
- const { name, arguments: args } = request.params;
914
- const toolHandlers = createToolHandlers(
915
- this.parser,
916
- this.verifiedOrders,
917
- this.pendingRequests,
918
- this.marketDataPrices
919
- );
920
- const handler = toolHandlers[name];
921
- if (!handler) {
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) {
922
365
  return {
923
366
  content: [
924
367
  {
925
368
  type: "text",
926
- text: `Tool not found: ${name}`,
927
- uri: name
369
+ text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
928
370
  }
929
371
  ],
930
372
  isError: true
931
373
  };
932
374
  }
933
- const result = await handler(args);
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) => {
934
431
  return {
935
- content: result.content,
936
- isError: result.isError
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>`;
678
+ return {
679
+ contents: [
680
+ {
681
+ uri: uri.href,
682
+ text: svg
683
+ }
684
+ ]
937
685
  };
938
686
  }
939
687
  );