fixparser-plugin-mcp 9.1.7-400318ef → 9.1.7-46844c62

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