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