fixparser-plugin-mcp 9.1.7-bfcb9d6f → 9.1.7-c415bb75

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,897 +35,643 @@ __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");
29
38
  var import_zod = require("zod");
30
- var fixStringSchema = import_zod.z.object({
31
- fixString: import_zod.z.string()
32
- });
33
- var orderSchema = import_zod.z.object({
34
- clOrdID: import_zod.z.string(),
35
- handlInst: import_zod.z.enum(["1", "2", "3"]),
36
- quantity: import_zod.z.string(),
37
- price: import_zod.z.string(),
38
- ordType: import_zod.z.enum([
39
- "1",
40
- "2",
41
- "3",
42
- "4",
43
- "5",
44
- "6",
45
- "7",
46
- "8",
47
- "9",
48
- "A",
49
- "B",
50
- "C",
51
- "D",
52
- "E",
53
- "F",
54
- "G",
55
- "H",
56
- "I",
57
- "J",
58
- "K",
59
- "L",
60
- "M",
61
- "P",
62
- "Q",
63
- "R",
64
- "S"
65
- ]),
66
- side: import_zod.z.enum(["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"]),
67
- symbol: import_zod.z.string(),
68
- timeInForce: import_zod.z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"])
69
- });
70
- var marketDataRequestSchema = import_zod.z.object({
71
- mdUpdateType: import_zod.z.enum(["0", "1"]),
72
- symbols: import_zod.z.array(import_zod.z.string()),
73
- mdReqID: import_zod.z.string(),
74
- subscriptionRequestType: import_zod.z.enum(["0", "1", "2"]),
75
- mdEntryTypes: import_zod.z.array(
76
- import_zod.z.enum([
77
- "0",
78
- "1",
79
- "2",
80
- "3",
81
- "4",
82
- "5",
83
- "6",
84
- "7",
85
- "8",
86
- "9",
87
- "A",
88
- "B",
89
- "C",
90
- "D",
91
- "E",
92
- "F",
93
- "G",
94
- "H",
95
- "J",
96
- "K",
97
- "L",
98
- "M",
99
- "N",
100
- "O",
101
- "P",
102
- "Q",
103
- "R",
104
- "S",
105
- "T",
106
- "U",
107
- "V",
108
- "W",
109
- "X",
110
- "Y",
111
- "Z",
112
- "a",
113
- "b",
114
- "c",
115
- "d",
116
- "e",
117
- "g",
118
- "h",
119
- "i",
120
- "t"
121
- ])
122
- )
123
- });
124
- var MCPLocal = class {
39
+
40
+ // src/MCPBase.ts
41
+ var MCPBase = class {
42
+ /**
43
+ * Optional logger instance for diagnostics and output.
44
+ * @protected
45
+ */
46
+ logger;
47
+ /**
48
+ * FIXParser instance, set during plugin register().
49
+ * @protected
50
+ */
125
51
  parser;
126
- server = new import_server.Server(
127
- {
128
- name: "fixparser",
129
- version: "1.0.0"
130
- },
131
- {
132
- capabilities: {
133
- tools: {
134
- parse: {
135
- description: "Parses a FIX message and describes it in plain language",
136
- parameters: {
137
- type: "object",
138
- properties: {
139
- fixString: { type: "string" }
140
- },
141
- required: ["fixString"]
142
- }
143
- },
144
- parseToJSON: {
145
- description: "Parses a FIX message into JSON",
146
- parameters: {
147
- type: "object",
148
- properties: {
149
- fixString: { type: "string" }
150
- },
151
- required: ["fixString"]
152
- }
153
- },
154
- verifyOrder: {
155
- description: "Verifies order parameters before execution",
156
- parameters: {
157
- type: "object",
158
- properties: {
159
- clOrdID: { type: "string" },
160
- handlInst: { type: "string", enum: ["1", "2", "3"] },
161
- quantity: { type: "string" },
162
- price: { type: "string" },
163
- ordType: {
164
- type: "string",
165
- enum: [
166
- "1",
167
- "2",
168
- "3",
169
- "4",
170
- "5",
171
- "6",
172
- "7",
173
- "8",
174
- "9",
175
- "A",
176
- "B",
177
- "C",
178
- "D",
179
- "E",
180
- "F",
181
- "G",
182
- "H",
183
- "I",
184
- "J",
185
- "K",
186
- "L",
187
- "M",
188
- "P",
189
- "Q",
190
- "R",
191
- "S"
192
- ]
193
- },
194
- side: {
195
- type: "string",
196
- enum: [
197
- "1",
198
- "2",
199
- "3",
200
- "4",
201
- "5",
202
- "6",
203
- "7",
204
- "8",
205
- "9",
206
- "A",
207
- "B",
208
- "C",
209
- "D",
210
- "E",
211
- "F",
212
- "G",
213
- "H"
214
- ]
215
- },
216
- symbol: { type: "string" },
217
- timeInForce: {
218
- type: "string",
219
- enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
220
- }
221
- },
222
- required: [
223
- "clOrdID",
224
- "handlInst",
225
- "quantity",
226
- "price",
227
- "ordType",
228
- "side",
229
- "symbol",
230
- "timeInForce"
231
- ]
232
- }
233
- },
234
- executeOrder: {
235
- description: "Executes a verified order",
236
- parameters: {
237
- type: "object",
238
- properties: {
239
- clOrdID: { type: "string" },
240
- handlInst: { type: "string", enum: ["1", "2", "3"] },
241
- quantity: { type: "string" },
242
- price: { type: "string" },
243
- ordType: { type: "string" },
244
- side: { type: "string" },
245
- symbol: { type: "string" },
246
- timeInForce: { type: "string" }
247
- },
248
- required: [
249
- "clOrdID",
250
- "handlInst",
251
- "quantity",
252
- "price",
253
- "ordType",
254
- "side",
255
- "symbol",
256
- "timeInForce"
257
- ]
258
- }
259
- },
260
- marketDataRequest: {
261
- description: "Requests market data for specified symbols",
262
- parameters: {
263
- type: "object",
264
- properties: {
265
- mdUpdateType: { type: "string", enum: ["0", "1"] },
266
- symbols: { type: "array", items: { type: "string" } },
267
- mdReqID: { type: "string" },
268
- subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
269
- mdEntryTypes: { type: "array", items: { type: "string" } }
270
- },
271
- required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType", "mdEntryTypes"]
272
- }
273
- }
274
- },
275
- resources: {
276
- greeting: {
277
- description: "A simple greeting resource",
278
- uri: "greeting-resource"
279
- },
280
- stockGraph: {
281
- description: "Generates a price chart for a given symbol",
282
- uri: "stockGraph/{symbol}"
283
- },
284
- stockPriceHistory: {
285
- description: "Returns price history for a given symbol",
286
- uri: "stockPriceHistory/{symbol}"
287
- }
288
- }
289
- }
290
- }
291
- );
292
- transport = new import_stdio.StdioServerTransport();
52
+ /**
53
+ * Called when server is setup and listening.
54
+ * @protected
55
+ */
293
56
  onReady = void 0;
294
- pendingRequests = /* @__PURE__ */ new Map();
57
+ /**
58
+ * Map to store verified orders before execution
59
+ * @protected
60
+ */
295
61
  verifiedOrders = /* @__PURE__ */ new Map();
296
- // Store market data prices with timestamps
62
+ /**
63
+ * Map to store pending market data requests
64
+ * @protected
65
+ */
66
+ pendingRequests = /* @__PURE__ */ new Map();
67
+ /**
68
+ * Map to store market data prices
69
+ * @protected
70
+ */
297
71
  marketDataPrices = /* @__PURE__ */ new Map();
72
+ /**
73
+ * Maximum number of price history entries to keep per symbol
74
+ * @protected
75
+ */
298
76
  MAX_PRICE_HISTORY = 1e5;
299
- // Maximum number of price points to store per symbol
300
77
  constructor({ logger, onReady }) {
301
- if (onReady) this.onReady = onReady;
78
+ this.logger = logger;
79
+ this.onReady = onReady;
302
80
  }
303
- async register(parser) {
304
- this.parser = parser;
305
- this.parser.addOnMessageCallback((message) => {
306
- this.parser?.logger.log({
307
- level: "info",
308
- message: `MCP Server received message: ${message.messageType}: ${message.description}`
309
- });
310
- const msgType = message.messageType;
311
- if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport || msgType === import_fixparser.Messages.Reject || msgType === import_fixparser.Messages.MarketDataIncrementalRefresh) {
312
- this.parser?.logger.log({
313
- level: "info",
314
- message: `MCP Server handling message type: ${msgType}`
315
- });
316
- let id;
317
- if (msgType === import_fixparser.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
318
- const symbol = message.getField(import_fixparser.Fields.Symbol);
319
- const price = message.getField(import_fixparser.Fields.MDEntryPx);
320
- const timestamp = message.getField(import_fixparser.Fields.MDEntryTime)?.value || Date.now();
321
- if (symbol?.value && price?.value) {
322
- const symbolStr = String(symbol.value);
323
- const priceNum = Number(price.value);
324
- const priceHistory = this.marketDataPrices.get(symbolStr) || [];
325
- priceHistory.push({
326
- timestamp: Number(timestamp),
327
- price: priceNum
328
- });
329
- if (priceHistory.length > this.MAX_PRICE_HISTORY) {
330
- priceHistory.shift();
331
- }
332
- this.marketDataPrices.set(symbolStr, priceHistory);
333
- this.parser?.logger.log({
334
- level: "info",
335
- message: `MCP Server added ${symbol}: ${priceNum}`
336
- });
337
- this.server.notification({
338
- method: "priceUpdate",
339
- params: {
340
- symbol: symbolStr,
341
- price: priceNum,
342
- timestamp: Number(timestamp)
343
- }
344
- });
345
- }
81
+ };
82
+
83
+ // src/schemas/schemas.ts
84
+ var toolSchemas = {
85
+ parse: {
86
+ description: "Parses a FIX message and describes it in plain language",
87
+ schema: {
88
+ type: "object",
89
+ properties: {
90
+ fixString: { type: "string" }
91
+ },
92
+ required: ["fixString"]
93
+ }
94
+ },
95
+ parseToJSON: {
96
+ description: "Parses a FIX message into JSON",
97
+ schema: {
98
+ type: "object",
99
+ properties: {
100
+ fixString: { type: "string" }
101
+ },
102
+ required: ["fixString"]
103
+ }
104
+ },
105
+ verifyOrder: {
106
+ description: "Verifies order parameters before execution. verifyOrder must be called before executeOrder.",
107
+ schema: {
108
+ type: "object",
109
+ properties: {
110
+ clOrdID: { type: "string" },
111
+ handlInst: {
112
+ type: "string",
113
+ enum: ["1", "2", "3"],
114
+ description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
115
+ },
116
+ quantity: { type: "string" },
117
+ price: { type: "string" },
118
+ ordType: {
119
+ type: "string",
120
+ enum: [
121
+ "1",
122
+ "2",
123
+ "3",
124
+ "4",
125
+ "5",
126
+ "6",
127
+ "7",
128
+ "8",
129
+ "9",
130
+ "A",
131
+ "B",
132
+ "C",
133
+ "D",
134
+ "E",
135
+ "F",
136
+ "G",
137
+ "H",
138
+ "I",
139
+ "J",
140
+ "K",
141
+ "L",
142
+ "M",
143
+ "P",
144
+ "Q",
145
+ "R",
146
+ "S"
147
+ ],
148
+ 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"
149
+ },
150
+ side: {
151
+ type: "string",
152
+ enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
153
+ 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"
154
+ },
155
+ symbol: { type: "string" },
156
+ timeInForce: {
157
+ type: "string",
158
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
159
+ 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"
346
160
  }
347
- if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
348
- const mdReqID = message.getField(import_fixparser.Fields.MDReqID);
349
- if (mdReqID) id = String(mdReqID.value);
350
- } else if (msgType === import_fixparser.Messages.ExecutionReport) {
351
- const clOrdID = message.getField(import_fixparser.Fields.ClOrdID);
352
- if (clOrdID) id = String(clOrdID.value);
353
- } else if (msgType === import_fixparser.Messages.Reject) {
354
- const refSeqNum = message.getField(import_fixparser.Fields.RefSeqNum);
355
- if (refSeqNum) id = String(refSeqNum.value);
161
+ },
162
+ required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
163
+ }
164
+ },
165
+ executeOrder: {
166
+ description: "Executes a verified order. verifyOrder must be called before executeOrder.",
167
+ schema: {
168
+ type: "object",
169
+ properties: {
170
+ clOrdID: { type: "string" },
171
+ handlInst: {
172
+ type: "string",
173
+ enum: ["1", "2", "3"],
174
+ description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
175
+ },
176
+ quantity: { type: "string" },
177
+ price: { type: "string" },
178
+ ordType: {
179
+ type: "string",
180
+ enum: [
181
+ "1",
182
+ "2",
183
+ "3",
184
+ "4",
185
+ "5",
186
+ "6",
187
+ "7",
188
+ "8",
189
+ "9",
190
+ "A",
191
+ "B",
192
+ "C",
193
+ "D",
194
+ "E",
195
+ "F",
196
+ "G",
197
+ "H",
198
+ "I",
199
+ "J",
200
+ "K",
201
+ "L",
202
+ "M",
203
+ "P",
204
+ "Q",
205
+ "R",
206
+ "S"
207
+ ],
208
+ 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"
209
+ },
210
+ side: {
211
+ type: "string",
212
+ enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
213
+ 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"
214
+ },
215
+ symbol: { type: "string" },
216
+ timeInForce: {
217
+ type: "string",
218
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
219
+ 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"
356
220
  }
357
- if (id) {
358
- const callback = this.pendingRequests.get(id);
359
- if (callback) {
360
- callback(message);
361
- this.pendingRequests.delete(id);
362
- }
221
+ },
222
+ required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
223
+ }
224
+ },
225
+ marketDataRequest: {
226
+ description: "Requests market data for specified symbols",
227
+ schema: {
228
+ type: "object",
229
+ properties: {
230
+ mdUpdateType: {
231
+ type: "string",
232
+ enum: ["0", "1"],
233
+ description: "Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"
234
+ },
235
+ symbols: { type: "array", items: { type: "string" } },
236
+ mdReqID: { type: "string" },
237
+ subscriptionRequestType: {
238
+ type: "string",
239
+ enum: ["0", "1", "2"],
240
+ description: "Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"
241
+ },
242
+ mdEntryTypes: {
243
+ type: "array",
244
+ items: {
245
+ type: "string",
246
+ enum: [
247
+ "0",
248
+ "1",
249
+ "2",
250
+ "3",
251
+ "4",
252
+ "5",
253
+ "6",
254
+ "7",
255
+ "8",
256
+ "9",
257
+ "A",
258
+ "B",
259
+ "C",
260
+ "D",
261
+ "E",
262
+ "F",
263
+ "G",
264
+ "H",
265
+ "I",
266
+ "J",
267
+ "K",
268
+ "L",
269
+ "M",
270
+ "N",
271
+ "O",
272
+ "P",
273
+ "Q",
274
+ "R",
275
+ "S",
276
+ "T",
277
+ "U",
278
+ "V",
279
+ "W",
280
+ "X",
281
+ "Y",
282
+ "Z"
283
+ ]
284
+ },
285
+ 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"
363
286
  }
364
- }
365
- });
366
- this.addWorkflows();
367
- await this.server.connect(this.transport);
368
- if (this.onReady) {
369
- this.onReady();
287
+ },
288
+ required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType"]
370
289
  }
371
- }
372
- addWorkflows() {
373
- if (!this.parser) {
374
- return;
290
+ },
291
+ getStockGraph: {
292
+ description: "Generates a price chart for a given symbol",
293
+ schema: {
294
+ type: "object",
295
+ properties: {
296
+ symbol: { type: "string" }
297
+ },
298
+ required: ["symbol"]
375
299
  }
376
- if (!this.server) {
377
- return;
300
+ },
301
+ getStockPriceHistory: {
302
+ description: "Returns price history for a given symbol",
303
+ schema: {
304
+ type: "object",
305
+ properties: {
306
+ symbol: { type: "string" }
307
+ },
308
+ required: ["symbol"]
378
309
  }
379
- this.server.setRequestHandler(
380
- import_zod.z.object({ method: import_zod.z.literal("resources/list") }),
381
- async (request, extra) => {
310
+ }
311
+ };
312
+
313
+ // src/tools/marketData.ts
314
+ var import_fixparser = require("fixparser");
315
+ var import_quickchart_js = __toESM(require("quickchart-js"), 1);
316
+ var createMarketDataRequestHandler = (parser, pendingRequests) => {
317
+ return async (args) => {
318
+ try {
319
+ const response = new Promise((resolve) => {
320
+ pendingRequests.set(args.mdReqID, resolve);
321
+ });
322
+ const entryTypes = args.mdEntryTypes || [
323
+ import_fixparser.MDEntryType.Bid,
324
+ import_fixparser.MDEntryType.Offer,
325
+ import_fixparser.MDEntryType.Trade,
326
+ import_fixparser.MDEntryType.IndexValue,
327
+ import_fixparser.MDEntryType.OpeningPrice,
328
+ import_fixparser.MDEntryType.ClosingPrice,
329
+ import_fixparser.MDEntryType.SettlementPrice,
330
+ import_fixparser.MDEntryType.TradingSessionHighPrice,
331
+ import_fixparser.MDEntryType.TradingSessionLowPrice,
332
+ import_fixparser.MDEntryType.VWAP,
333
+ import_fixparser.MDEntryType.Imbalance,
334
+ import_fixparser.MDEntryType.TradeVolume,
335
+ import_fixparser.MDEntryType.OpenInterest,
336
+ import_fixparser.MDEntryType.CompositeUnderlyingPrice,
337
+ import_fixparser.MDEntryType.SimulatedSellPrice,
338
+ import_fixparser.MDEntryType.SimulatedBuyPrice,
339
+ import_fixparser.MDEntryType.MarginRate,
340
+ import_fixparser.MDEntryType.MidPrice,
341
+ import_fixparser.MDEntryType.EmptyBook,
342
+ import_fixparser.MDEntryType.SettleHighPrice,
343
+ import_fixparser.MDEntryType.SettleLowPrice,
344
+ import_fixparser.MDEntryType.PriorSettlePrice,
345
+ import_fixparser.MDEntryType.SessionHighBid,
346
+ import_fixparser.MDEntryType.SessionLowOffer,
347
+ import_fixparser.MDEntryType.EarlyPrices,
348
+ import_fixparser.MDEntryType.AuctionClearingPrice,
349
+ import_fixparser.MDEntryType.SwapValueFactor,
350
+ import_fixparser.MDEntryType.DailyValueAdjustmentForLongPositions,
351
+ import_fixparser.MDEntryType.CumulativeValueAdjustmentForLongPositions,
352
+ import_fixparser.MDEntryType.DailyValueAdjustmentForShortPositions,
353
+ import_fixparser.MDEntryType.CumulativeValueAdjustmentForShortPositions,
354
+ import_fixparser.MDEntryType.FixingPrice,
355
+ import_fixparser.MDEntryType.CashRate,
356
+ import_fixparser.MDEntryType.RecoveryRate,
357
+ import_fixparser.MDEntryType.RecoveryRateForLong,
358
+ import_fixparser.MDEntryType.RecoveryRateForShort,
359
+ import_fixparser.MDEntryType.MarketBid,
360
+ import_fixparser.MDEntryType.MarketOffer,
361
+ import_fixparser.MDEntryType.ShortSaleMinPrice,
362
+ import_fixparser.MDEntryType.PreviousClosingPrice,
363
+ import_fixparser.MDEntryType.ThresholdLimitPriceBanding,
364
+ import_fixparser.MDEntryType.DailyFinancingValue,
365
+ import_fixparser.MDEntryType.AccruedFinancingValue,
366
+ import_fixparser.MDEntryType.TWAP
367
+ ];
368
+ const messageFields = [
369
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
370
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
371
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
372
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
373
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
374
+ new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
375
+ new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
376
+ new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
377
+ new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
378
+ ];
379
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
380
+ args.symbols.forEach((symbol) => {
381
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
382
+ });
383
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, entryTypes.length));
384
+ entryTypes.forEach((entryType) => {
385
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
386
+ });
387
+ const mdr = parser.createMessage(...messageFields);
388
+ if (!parser.connected) {
382
389
  return {
383
- resources: [
390
+ content: [
384
391
  {
385
- name: "greeting",
386
- description: "A simple greeting resource",
387
- uri: "greeting-resource"
392
+ type: "text",
393
+ text: "Error: Not connected. Ignoring message.",
394
+ uri: "marketDataRequest"
388
395
  }
389
- ]
396
+ ],
397
+ isError: true
390
398
  };
391
399
  }
392
- );
393
- this.server.setRequestHandler(
394
- import_zod.z.object({ method: import_zod.z.literal("resources/templates/list") }),
395
- async (request, extra) => {
400
+ parser.send(mdr);
401
+ const fixData = await response;
402
+ return {
403
+ content: [
404
+ {
405
+ type: "text",
406
+ text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
407
+ uri: "marketDataRequest"
408
+ }
409
+ ]
410
+ };
411
+ } catch (error) {
412
+ return {
413
+ content: [
414
+ {
415
+ type: "text",
416
+ text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
417
+ uri: "marketDataRequest"
418
+ }
419
+ ],
420
+ isError: true
421
+ };
422
+ }
423
+ };
424
+ };
425
+ var createGetStockGraphHandler = (marketDataPrices) => {
426
+ return async (args) => {
427
+ try {
428
+ const symbol = args.symbol;
429
+ const priceHistory = marketDataPrices.get(symbol) || [];
430
+ if (priceHistory.length === 0) {
396
431
  return {
397
- resourceTemplates: [
398
- {
399
- name: "stockGraph",
400
- description: "Generates a price chart for a given symbol",
401
- uriTemplate: "stockGraph/{symbol}",
402
- parameters: {
403
- type: "object",
404
- properties: {
405
- symbol: { type: "string" }
406
- },
407
- required: ["symbol"]
408
- }
409
- },
432
+ content: [
410
433
  {
411
- name: "stockPriceHistory",
412
- description: "Returns price history for a given symbol",
413
- uriTemplate: "stockPriceHistory/{symbol}",
414
- parameters: {
415
- type: "object",
416
- properties: {
417
- symbol: { type: "string" }
418
- },
419
- required: ["symbol"]
420
- }
434
+ type: "text",
435
+ text: `No price data available for ${symbol}`,
436
+ uri: "getStockGraph"
421
437
  }
422
438
  ]
423
439
  };
424
440
  }
425
- );
426
- this.server.setRequestHandler(
427
- import_zod.z.object({ method: import_zod.z.literal("tools/list") }),
428
- async (request, extra) => {
429
- return {
430
- tools: [
431
- {
432
- name: "parse",
433
- description: "Parses a FIX message and describes it in plain language",
434
- inputSchema: {
435
- type: "object",
436
- properties: {
437
- fixString: { type: "string" }
438
- },
439
- required: ["fixString"]
440
- }
441
- },
441
+ const chart = new import_quickchart_js.default();
442
+ chart.setWidth(1200);
443
+ chart.setHeight(600);
444
+ chart.setBackgroundColor("transparent");
445
+ const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
446
+ const bidData = priceHistory.map((point) => point.bid);
447
+ const offerData = priceHistory.map((point) => point.offer);
448
+ const spreadData = priceHistory.map((point) => point.spread);
449
+ const volumeData = priceHistory.map((point) => point.volume);
450
+ const config = {
451
+ type: "line",
452
+ data: {
453
+ labels,
454
+ datasets: [
442
455
  {
443
- name: "parseToJSON",
444
- description: "Parses a FIX message into JSON",
445
- inputSchema: {
446
- type: "object",
447
- properties: {
448
- fixString: { type: "string" }
449
- },
450
- required: ["fixString"]
451
- }
456
+ label: "Bid",
457
+ data: bidData,
458
+ borderColor: "#28a745",
459
+ backgroundColor: "rgba(40, 167, 69, 0.1)",
460
+ fill: false,
461
+ tension: 0.4
452
462
  },
453
463
  {
454
- name: "verifyOrder",
455
- description: "Verifies order parameters before execution",
456
- inputSchema: {
457
- type: "object",
458
- properties: {
459
- clOrdID: { type: "string" },
460
- handlInst: { type: "string", enum: ["1", "2", "3"] },
461
- quantity: { type: "string" },
462
- price: { type: "string" },
463
- ordType: {
464
- type: "string",
465
- enum: [
466
- "1",
467
- "2",
468
- "3",
469
- "4",
470
- "5",
471
- "6",
472
- "7",
473
- "8",
474
- "9",
475
- "A",
476
- "B",
477
- "C",
478
- "D",
479
- "E",
480
- "F",
481
- "G",
482
- "H",
483
- "I",
484
- "J",
485
- "K",
486
- "L",
487
- "M",
488
- "P",
489
- "Q",
490
- "R",
491
- "S"
492
- ]
493
- },
494
- side: {
495
- type: "string",
496
- enum: [
497
- "1",
498
- "2",
499
- "3",
500
- "4",
501
- "5",
502
- "6",
503
- "7",
504
- "8",
505
- "9",
506
- "A",
507
- "B",
508
- "C",
509
- "D",
510
- "E",
511
- "F",
512
- "G",
513
- "H"
514
- ]
515
- },
516
- symbol: { type: "string" },
517
- timeInForce: {
518
- type: "string",
519
- enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
520
- }
521
- },
522
- required: [
523
- "clOrdID",
524
- "handlInst",
525
- "quantity",
526
- "price",
527
- "ordType",
528
- "side",
529
- "symbol",
530
- "timeInForce"
531
- ]
532
- }
464
+ label: "Offer",
465
+ data: offerData,
466
+ borderColor: "#dc3545",
467
+ backgroundColor: "rgba(220, 53, 69, 0.1)",
468
+ fill: false,
469
+ tension: 0.4
533
470
  },
534
471
  {
535
- name: "executeOrder",
536
- description: "Executes a verified order",
537
- inputSchema: {
538
- type: "object",
539
- properties: {
540
- clOrdID: { type: "string" },
541
- handlInst: { type: "string", enum: ["1", "2", "3"] },
542
- quantity: { type: "string" },
543
- price: { type: "string" },
544
- ordType: { type: "string" },
545
- side: { type: "string" },
546
- symbol: { type: "string" },
547
- timeInForce: { type: "string" }
548
- },
549
- required: [
550
- "clOrdID",
551
- "handlInst",
552
- "quantity",
553
- "price",
554
- "ordType",
555
- "side",
556
- "symbol",
557
- "timeInForce"
558
- ]
559
- }
472
+ label: "Spread",
473
+ data: spreadData,
474
+ borderColor: "#6c757d",
475
+ backgroundColor: "rgba(108, 117, 125, 0.1)",
476
+ fill: false,
477
+ tension: 0.4
560
478
  },
561
479
  {
562
- name: "marketDataRequest",
563
- description: "Requests market data for specified symbols",
564
- inputSchema: {
565
- type: "object",
566
- properties: {
567
- mdUpdateType: { type: "string", enum: ["0", "1"] },
568
- symbols: { type: "array", items: { type: "string" } },
569
- mdReqID: { type: "string" },
570
- subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
571
- mdEntryTypes: { type: "array", items: { type: "string" } }
572
- },
573
- required: [
574
- "mdUpdateType",
575
- "symbols",
576
- "mdReqID",
577
- "subscriptionRequestType",
578
- "mdEntryTypes"
579
- ]
580
- }
480
+ label: "Volume",
481
+ data: volumeData,
482
+ borderColor: "#007bff",
483
+ backgroundColor: "rgba(0, 123, 255, 0.1)",
484
+ fill: true,
485
+ tension: 0.4
581
486
  }
582
487
  ]
583
- };
584
- }
585
- );
586
- this.server.setRequestHandler(
587
- import_zod.z.object({
588
- method: import_zod.z.literal("resources/read"),
589
- params: import_zod.z.object({
590
- uri: import_zod.z.string()
591
- })
592
- }),
593
- async (request, extra) => {
594
- const { uri } = request.params;
595
- switch (uri) {
596
- case "greeting-resource":
597
- return {
598
- contents: [
599
- {
600
- type: "text",
601
- text: "Hello, world!",
602
- uri: "greeting-resource"
603
- }
604
- ]
605
- };
606
- case "stockGraph":
607
- return {
608
- contents: [
609
- {
610
- type: "text",
611
- text: "This resource requires a symbol parameter. Please use the stockGraph/{symbol} resource.",
612
- uri: "stockGraph"
613
- }
614
- ]
615
- };
616
- case "stockPriceHistory":
617
- return {
618
- contents: [
619
- {
620
- type: "text",
621
- text: "This resource requires a symbol parameter. Please use the stockPriceHistory/{symbol} resource.",
622
- uri: "stockPriceHistory"
623
- }
624
- ]
625
- };
626
- default:
627
- if (uri.startsWith("stockGraph/")) {
628
- const symbol = uri.split("/")[1];
629
- const priceHistory = this.marketDataPrices.get(symbol) || [];
630
- if (priceHistory.length === 0) {
631
- return {
632
- contents: [
633
- {
634
- type: "text",
635
- text: `No price data available for ${symbol}`
636
- }
637
- ]
638
- };
639
- }
640
- const width = 600;
641
- const height = 300;
642
- const padding = 40;
643
- const xScale = (width - 2 * padding) / (priceHistory.length - 1);
644
- const yMin = Math.min(...priceHistory.map((d) => d.price));
645
- const yMax = Math.max(...priceHistory.map((d) => d.price));
646
- const yScale = (height - 2 * padding) / (yMax - yMin);
647
- const points = priceHistory.map((d, i) => {
648
- const x = padding + i * xScale;
649
- const y = height - padding - (d.price - yMin) * yScale;
650
- return `${x},${y}`;
651
- }).join(" L ");
652
- const svg = `<?xml version="1.0" encoding="UTF-8"?>
653
- <svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
654
- <!-- Background -->
655
- <rect width="100%" height="100%" fill="#f8f9fa"/>
656
-
657
- <!-- Grid lines -->
658
- <g stroke="#e9ecef" stroke-width="1">
659
- ${Array.from({ length: 5 }, (_, i) => {
660
- const y = padding + (height - 2 * padding) * i / 4;
661
- return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
662
- }).join("\n")}
663
- </g>
664
-
665
- <!-- Price line -->
666
- <path d="M ${points}"
667
- fill="none"
668
- stroke="#007bff"
669
- stroke-width="2"/>
670
-
671
- <!-- Data points -->
672
- ${priceHistory.map((d, i) => {
673
- const x = padding + i * xScale;
674
- const y = height - padding - (d.price - yMin) * yScale;
675
- return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
676
- }).join("\n")}
677
-
678
- <!-- Labels -->
679
- <g font-family="Arial" font-size="12" fill="#495057">
680
- ${Array.from({ length: 5 }, (_, i) => {
681
- const x = padding + (width - 2 * padding) * i / 4;
682
- const index = Math.floor((priceHistory.length - 1) * i / 4);
683
- const timestamp = new Date(priceHistory[index].timestamp).toLocaleTimeString();
684
- return `<text x="${x + padding}" y="${height - padding + 20}" text-anchor="middle">${timestamp}</text>`;
685
- }).join("\n")}
686
- ${Array.from({ length: 5 }, (_, i) => {
687
- const y = padding + (height - 2 * padding) * i / 4;
688
- const price = yMax - (yMax - yMin) * i / 4;
689
- return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
690
- }).join("\n")}
691
- </g>
692
-
693
- <!-- Title -->
694
- <text x="${width / 2}" y="${padding / 2}"
695
- font-family="Arial" font-size="16" font-weight="bold"
696
- text-anchor="middle" fill="#212529">
697
- ${symbol} - Price Chart (${priceHistory.length} points)
698
- </text>
699
- </svg>`;
700
- return {
701
- contents: [
702
- {
703
- type: "text",
704
- text: svg
705
- }
706
- ]
707
- };
488
+ },
489
+ options: {
490
+ responsive: true,
491
+ plugins: {
492
+ title: {
493
+ display: true,
494
+ text: `${symbol} Market Data`
708
495
  }
709
- if (uri.startsWith("stockPriceHistory/")) {
710
- const symbol = uri.split("/")[1];
711
- const priceHistory = this.marketDataPrices.get(symbol) || [];
712
- if (priceHistory.length === 0) {
713
- return {
714
- contents: [
715
- {
716
- type: "text",
717
- text: `No price data available for ${symbol}`
718
- }
719
- ]
720
- };
721
- }
722
- return {
723
- contents: [
724
- {
725
- type: "text",
726
- text: JSON.stringify(
727
- {
728
- symbol,
729
- count: priceHistory.length,
730
- prices: priceHistory.map((point) => ({
731
- timestamp: new Date(point.timestamp).toISOString(),
732
- price: point.price
733
- }))
734
- },
735
- null,
736
- 2
737
- )
738
- }
739
- ]
740
- };
496
+ },
497
+ scales: {
498
+ y: {
499
+ beginAtZero: false
741
500
  }
742
- return {
743
- contents: [
744
- {
745
- type: "text",
746
- text: `Resource not found: ${uri}`,
747
- uri
748
- }
749
- ],
750
- isError: true
751
- };
752
- }
753
- }
754
- );
755
- this.server.setRequestHandler(
756
- import_zod.z.object({
757
- method: import_zod.z.literal("parse"),
758
- params: fixStringSchema
759
- }),
760
- async (request, extra) => {
761
- try {
762
- const args = request.params;
763
- const parsedMessage = this.parser?.parse(args.fixString);
764
- if (!parsedMessage || parsedMessage.length === 0) {
765
- return {
766
- contents: [{ type: "text", text: "Error: Failed to parse FIX string" }],
767
- isError: true
768
- };
769
501
  }
770
- return {
771
- contents: [
772
- {
773
- type: "text",
774
- text: `${parsedMessage[0].description}
775
- ${parsedMessage[0].messageTypeDescription}`
776
- }
777
- ]
778
- };
779
- } catch (error) {
780
- return {
781
- contents: [
782
- {
783
- type: "text",
784
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
785
- }
786
- ],
787
- isError: true
788
- };
789
502
  }
790
- }
791
- );
792
- this.server.setRequestHandler(
793
- import_zod.z.object({
794
- method: import_zod.z.literal("parseToJSON"),
795
- params: fixStringSchema
796
- }),
797
- async (request, extra) => {
798
- try {
799
- const args = request.params;
800
- const parsedMessage = this.parser?.parse(args.fixString);
801
- if (!parsedMessage || parsedMessage.length === 0) {
802
- return {
803
- contents: [{ type: "text", text: "Error: Failed to parse FIX string" }],
804
- isError: true
805
- };
503
+ };
504
+ chart.setConfig(config);
505
+ const imageBuffer = await chart.toBinary();
506
+ const base64 = imageBuffer.toString("base64");
507
+ return {
508
+ content: [
509
+ {
510
+ type: "resource",
511
+ resource: {
512
+ uri: "resource://graph",
513
+ mimeType: "image/png",
514
+ blob: base64
515
+ }
806
516
  }
807
- return {
808
- contents: [
809
- {
810
- type: "text",
811
- text: `${parsedMessage[0].toFIXJSON()}`
812
- }
813
- ]
814
- };
815
- } catch (error) {
816
- return {
817
- contents: [
818
- {
819
- type: "text",
820
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
821
- }
822
- ],
823
- isError: true
824
- };
825
- }
517
+ ]
518
+ };
519
+ } catch (error) {
520
+ return {
521
+ content: [
522
+ {
523
+ type: "text",
524
+ text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
525
+ uri: "getStockGraph"
526
+ }
527
+ ],
528
+ isError: true
529
+ };
530
+ }
531
+ };
532
+ };
533
+ var createGetStockPriceHistoryHandler = (marketDataPrices) => {
534
+ return async (args) => {
535
+ try {
536
+ const symbol = args.symbol;
537
+ const priceHistory = marketDataPrices.get(symbol) || [];
538
+ if (priceHistory.length === 0) {
539
+ return {
540
+ content: [
541
+ {
542
+ type: "text",
543
+ text: `No price data available for ${symbol}`,
544
+ uri: "getStockPriceHistory"
545
+ }
546
+ ]
547
+ };
826
548
  }
827
- );
828
- this.server.setRequestHandler(
829
- import_zod.z.object({
830
- method: import_zod.z.literal("verifyOrder"),
831
- params: orderSchema
832
- }),
833
- async (request, extra) => {
834
- try {
835
- const args = request.params;
836
- this.verifiedOrders.set(args.clOrdID, {
837
- clOrdID: args.clOrdID,
838
- handlInst: args.handlInst,
839
- quantity: Number.parseFloat(args.quantity),
840
- price: Number.parseFloat(args.price),
841
- ordType: args.ordType,
842
- side: args.side,
843
- symbol: args.symbol,
844
- timeInForce: args.timeInForce
845
- });
846
- const ordTypeNames = {
847
- "1": "Market",
848
- "2": "Limit",
849
- "3": "Stop",
850
- "4": "StopLimit",
851
- "5": "MarketOnClose",
852
- "6": "WithOrWithout",
853
- "7": "LimitOrBetter",
854
- "8": "LimitWithOrWithout",
855
- "9": "OnBasis",
856
- A: "OnClose",
857
- B: "LimitOnClose",
858
- C: "ForexMarket",
859
- D: "PreviouslyQuoted",
860
- E: "PreviouslyIndicated",
861
- F: "ForexLimit",
862
- G: "ForexSwap",
863
- H: "ForexPreviouslyQuoted",
864
- I: "Funari",
865
- J: "MarketIfTouched",
866
- K: "MarketWithLeftOverAsLimit",
867
- L: "PreviousFundValuationPoint",
868
- M: "NextFundValuationPoint",
869
- P: "Pegged",
870
- Q: "CounterOrderSelection",
871
- R: "StopOnBidOrOffer",
872
- S: "StopLimitOnBidOrOffer"
873
- };
874
- const sideNames = {
875
- "1": "Buy",
876
- "2": "Sell",
877
- "3": "BuyMinus",
878
- "4": "SellPlus",
879
- "5": "SellShort",
880
- "6": "SellShortExempt",
881
- "7": "Undisclosed",
882
- "8": "Cross",
883
- "9": "CrossShort",
884
- A: "CrossShortExempt",
885
- B: "AsDefined",
886
- C: "Opposite",
887
- D: "Subscribe",
888
- E: "Redeem",
889
- F: "Lend",
890
- G: "Borrow",
891
- H: "SellUndisclosed"
892
- };
893
- const timeInForceNames = {
894
- "0": "Day",
895
- "1": "GoodTillCancel",
896
- "2": "AtTheOpening",
897
- "3": "ImmediateOrCancel",
898
- "4": "FillOrKill",
899
- "5": "GoodTillCrossing",
900
- "6": "GoodTillDate",
901
- "7": "AtTheClose",
902
- "8": "GoodThroughCrossing",
903
- "9": "AtCrossing",
904
- A: "GoodForTime",
905
- B: "GoodForAuction",
906
- C: "GoodForMonth"
907
- };
908
- const handlInstNames = {
909
- "1": "AutomatedExecutionNoIntervention",
910
- "2": "AutomatedExecutionInterventionOK",
911
- "3": "ManualOrder"
912
- };
913
- return {
914
- contents: [
549
+ return {
550
+ content: [
551
+ {
552
+ type: "text",
553
+ text: JSON.stringify(
915
554
  {
916
- type: "text",
917
- text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
918
-
555
+ symbol,
556
+ count: priceHistory.length,
557
+ data: priceHistory.map((point) => ({
558
+ timestamp: new Date(point.timestamp).toISOString(),
559
+ bid: point.bid,
560
+ offer: point.offer,
561
+ spread: point.spread,
562
+ volume: point.volume
563
+ }))
564
+ },
565
+ null,
566
+ 2
567
+ ),
568
+ uri: "getStockPriceHistory"
569
+ }
570
+ ]
571
+ };
572
+ } catch (error) {
573
+ return {
574
+ content: [
575
+ {
576
+ type: "text",
577
+ text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
578
+ uri: "getStockPriceHistory"
579
+ }
580
+ ],
581
+ isError: true
582
+ };
583
+ }
584
+ };
585
+ };
586
+
587
+ // src/tools/order.ts
588
+ var import_fixparser2 = require("fixparser");
589
+ var ordTypeNames = {
590
+ "1": "Market",
591
+ "2": "Limit",
592
+ "3": "Stop",
593
+ "4": "StopLimit",
594
+ "5": "MarketOnClose",
595
+ "6": "WithOrWithout",
596
+ "7": "LimitOrBetter",
597
+ "8": "LimitWithOrWithout",
598
+ "9": "OnBasis",
599
+ A: "OnClose",
600
+ B: "LimitOnClose",
601
+ C: "ForexMarket",
602
+ D: "PreviouslyQuoted",
603
+ E: "PreviouslyIndicated",
604
+ F: "ForexLimit",
605
+ G: "ForexSwap",
606
+ H: "ForexPreviouslyQuoted",
607
+ I: "Funari",
608
+ J: "MarketIfTouched",
609
+ K: "MarketWithLeftOverAsLimit",
610
+ L: "PreviousFundValuationPoint",
611
+ M: "NextFundValuationPoint",
612
+ P: "Pegged",
613
+ Q: "CounterOrderSelection",
614
+ R: "StopOnBidOrOffer",
615
+ S: "StopLimitOnBidOrOffer"
616
+ };
617
+ var sideNames = {
618
+ "1": "Buy",
619
+ "2": "Sell",
620
+ "3": "BuyMinus",
621
+ "4": "SellPlus",
622
+ "5": "SellShort",
623
+ "6": "SellShortExempt",
624
+ "7": "Undisclosed",
625
+ "8": "Cross",
626
+ "9": "CrossShort",
627
+ A: "CrossShortExempt",
628
+ B: "AsDefined",
629
+ C: "Opposite",
630
+ D: "Subscribe",
631
+ E: "Redeem",
632
+ F: "Lend",
633
+ G: "Borrow",
634
+ H: "SellUndisclosed"
635
+ };
636
+ var timeInForceNames = {
637
+ "0": "Day",
638
+ "1": "GoodTillCancel",
639
+ "2": "AtTheOpening",
640
+ "3": "ImmediateOrCancel",
641
+ "4": "FillOrKill",
642
+ "5": "GoodTillCrossing",
643
+ "6": "GoodTillDate",
644
+ "7": "AtTheClose",
645
+ "8": "GoodThroughCrossing",
646
+ "9": "AtCrossing",
647
+ A: "GoodForTime",
648
+ B: "GoodForAuction",
649
+ C: "GoodForMonth"
650
+ };
651
+ var handlInstNames = {
652
+ "1": "AutomatedExecutionNoIntervention",
653
+ "2": "AutomatedExecutionInterventionOK",
654
+ "3": "ManualOrder"
655
+ };
656
+ var createVerifyOrderHandler = (parser, verifiedOrders) => {
657
+ return async (args) => {
658
+ try {
659
+ verifiedOrders.set(args.clOrdID, {
660
+ clOrdID: args.clOrdID,
661
+ handlInst: args.handlInst,
662
+ quantity: Number.parseFloat(String(args.quantity)),
663
+ price: Number.parseFloat(String(args.price)),
664
+ ordType: args.ordType,
665
+ side: args.side,
666
+ symbol: args.symbol,
667
+ timeInForce: args.timeInForce
668
+ });
669
+ return {
670
+ content: [
671
+ {
672
+ type: "text",
673
+ text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
674
+
919
675
  Parameters verified:
920
676
  - ClOrdID: ${args.clOrdID}
921
677
  - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
@@ -926,171 +682,542 @@ Parameters verified:
926
682
  - Symbol: ${args.symbol}
927
683
  - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
928
684
 
929
- To execute this order, call the executeOrder tool with these exact same parameters.`
930
- }
931
- ]
932
- };
933
- } catch (error) {
934
- return {
935
- contents: [
936
- {
937
- type: "text",
938
- text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
939
- }
940
- ],
941
- isError: true
942
- };
943
- }
685
+ To execute this order, call the executeOrder tool with these exact same parameters.`,
686
+ uri: "verifyOrder"
687
+ }
688
+ ]
689
+ };
690
+ } catch (error) {
691
+ return {
692
+ content: [
693
+ {
694
+ type: "text",
695
+ text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
696
+ uri: "verifyOrder"
697
+ }
698
+ ],
699
+ isError: true
700
+ };
701
+ }
702
+ };
703
+ };
704
+ var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
705
+ return async (args) => {
706
+ try {
707
+ const verifiedOrder = verifiedOrders.get(args.clOrdID);
708
+ if (!verifiedOrder) {
709
+ return {
710
+ content: [
711
+ {
712
+ type: "text",
713
+ text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
714
+ uri: "executeOrder"
715
+ }
716
+ ],
717
+ isError: true
718
+ };
944
719
  }
945
- );
946
- this.server.setRequestHandler(
947
- import_zod.z.object({
948
- method: import_zod.z.literal("executeOrder"),
949
- params: orderSchema
950
- }),
951
- async (request, extra) => {
952
- try {
953
- const args = request.params;
954
- const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
955
- if (!verifiedOrder) {
956
- return {
957
- contents: [
958
- {
959
- type: "text",
960
- text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
961
- }
962
- ],
963
- isError: true
964
- };
720
+ 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) {
721
+ return {
722
+ content: [
723
+ {
724
+ type: "text",
725
+ text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
726
+ uri: "executeOrder"
727
+ }
728
+ ],
729
+ isError: true
730
+ };
731
+ }
732
+ const response = new Promise((resolve) => {
733
+ pendingRequests.set(args.clOrdID, resolve);
734
+ });
735
+ const order = parser.createMessage(
736
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
737
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
738
+ new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
739
+ new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
740
+ new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
741
+ new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
742
+ new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
743
+ new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
744
+ new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
745
+ new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
746
+ new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
747
+ new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
748
+ new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
749
+ new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
750
+ );
751
+ if (!parser.connected) {
752
+ return {
753
+ content: [
754
+ {
755
+ type: "text",
756
+ text: "Error: Not connected. Ignoring message.",
757
+ uri: "executeOrder"
758
+ }
759
+ ],
760
+ isError: true
761
+ };
762
+ }
763
+ parser.send(order);
764
+ const fixData = await response;
765
+ verifiedOrders.delete(args.clOrdID);
766
+ return {
767
+ content: [
768
+ {
769
+ type: "text",
770
+ 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())}`,
771
+ uri: "executeOrder"
965
772
  }
966
- 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) {
967
- return {
968
- contents: [
969
- {
970
- type: "text",
971
- text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
972
- }
973
- ],
974
- isError: true
975
- };
773
+ ]
774
+ };
775
+ } catch (error) {
776
+ return {
777
+ content: [
778
+ {
779
+ type: "text",
780
+ text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
781
+ uri: "executeOrder"
976
782
  }
977
- const response = new Promise((resolve) => {
978
- this.pendingRequests.set(args.clOrdID, resolve);
979
- });
980
- const order = this.parser?.createMessage(
981
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
982
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
983
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
984
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
985
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
986
- new import_fixparser.Field(import_fixparser.Fields.ClOrdID, args.clOrdID),
987
- new import_fixparser.Field(import_fixparser.Fields.Side, args.side),
988
- new import_fixparser.Field(import_fixparser.Fields.Symbol, args.symbol),
989
- new import_fixparser.Field(import_fixparser.Fields.OrderQty, Number.parseFloat(args.quantity)),
990
- new import_fixparser.Field(import_fixparser.Fields.Price, Number.parseFloat(args.price)),
991
- new import_fixparser.Field(import_fixparser.Fields.OrdType, args.ordType),
992
- new import_fixparser.Field(import_fixparser.Fields.HandlInst, args.handlInst),
993
- new import_fixparser.Field(import_fixparser.Fields.TimeInForce, args.timeInForce),
994
- new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
995
- );
996
- if (!this.parser?.connected) {
997
- return {
998
- contents: [
999
- {
1000
- type: "text",
1001
- text: "Error: Not connected. Ignoring message."
1002
- }
1003
- ],
1004
- isError: true
1005
- };
783
+ ],
784
+ isError: true
785
+ };
786
+ }
787
+ };
788
+ };
789
+
790
+ // src/tools/parse.ts
791
+ var createParseHandler = (parser) => {
792
+ return async (args) => {
793
+ try {
794
+ const parsedMessage = parser.parse(args.fixString);
795
+ if (!parsedMessage || parsedMessage.length === 0) {
796
+ return {
797
+ content: [
798
+ {
799
+ type: "text",
800
+ text: "Error: Failed to parse FIX string",
801
+ uri: "parse"
802
+ }
803
+ ],
804
+ isError: true
805
+ };
806
+ }
807
+ return {
808
+ content: [
809
+ {
810
+ type: "text",
811
+ text: `${parsedMessage[0].description}
812
+ ${parsedMessage[0].messageTypeDescription}`,
813
+ uri: "parse"
1006
814
  }
1007
- this.parser?.send(order);
1008
- const fixData = await response;
1009
- this.verifiedOrders.delete(args.clOrdID);
1010
- return {
1011
- contents: [
1012
- {
1013
- type: "text",
1014
- 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())}`
1015
- }
1016
- ]
1017
- };
1018
- } catch (error) {
1019
- return {
1020
- contents: [
1021
- {
1022
- type: "text",
1023
- text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
1024
- }
1025
- ],
1026
- isError: true
1027
- };
1028
- }
815
+ ]
816
+ };
817
+ } catch (error) {
818
+ return {
819
+ content: [
820
+ {
821
+ type: "text",
822
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
823
+ uri: "parse"
824
+ }
825
+ ],
826
+ isError: true
827
+ };
828
+ }
829
+ };
830
+ };
831
+
832
+ // src/tools/parseToJSON.ts
833
+ var createParseToJSONHandler = (parser) => {
834
+ return async (args) => {
835
+ try {
836
+ const parsedMessage = parser.parse(args.fixString);
837
+ if (!parsedMessage || parsedMessage.length === 0) {
838
+ return {
839
+ content: [
840
+ {
841
+ type: "text",
842
+ text: "Error: Failed to parse FIX string",
843
+ uri: "parseToJSON"
844
+ }
845
+ ],
846
+ isError: true
847
+ };
1029
848
  }
1030
- );
849
+ return {
850
+ content: [
851
+ {
852
+ type: "text",
853
+ text: `${parsedMessage[0].toFIXJSON()}`,
854
+ uri: "parseToJSON"
855
+ }
856
+ ]
857
+ };
858
+ } catch (error) {
859
+ return {
860
+ content: [
861
+ {
862
+ type: "text",
863
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
864
+ uri: "parseToJSON"
865
+ }
866
+ ],
867
+ isError: true
868
+ };
869
+ }
870
+ };
871
+ };
872
+
873
+ // src/tools/index.ts
874
+ var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
875
+ parse: createParseHandler(parser),
876
+ parseToJSON: createParseToJSONHandler(parser),
877
+ verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
878
+ executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
879
+ marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
880
+ getStockGraph: createGetStockGraphHandler(marketDataPrices),
881
+ getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
882
+ });
883
+
884
+ // src/utils/messageHandler.ts
885
+ var import_fixparser3 = require("fixparser");
886
+ function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPriceHistory, onPriceUpdate) {
887
+ parser.logger.log({
888
+ level: "info",
889
+ message: `MCP Server received message: ${message.messageType}: ${message.description}`
890
+ });
891
+ const msgType = message.messageType;
892
+ if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
893
+ const symbol = message.getField(import_fixparser3.Fields.Symbol)?.value;
894
+ const fixJson = message.toFIXJSON();
895
+ const entries = fixJson.Body?.NoMDEntries || [];
896
+ const data = {
897
+ timestamp: Date.now(),
898
+ bid: 0,
899
+ offer: 0,
900
+ spread: 0,
901
+ volume: 0,
902
+ trade: 0,
903
+ indexValue: 0,
904
+ openingPrice: 0,
905
+ closingPrice: 0,
906
+ settlementPrice: 0,
907
+ tradingSessionHighPrice: 0,
908
+ tradingSessionLowPrice: 0,
909
+ vwap: 0,
910
+ imbalance: 0,
911
+ openInterest: 0,
912
+ compositeUnderlyingPrice: 0,
913
+ simulatedSellPrice: 0,
914
+ simulatedBuyPrice: 0,
915
+ marginRate: 0,
916
+ midPrice: 0,
917
+ emptyBook: 0,
918
+ settleHighPrice: 0,
919
+ settleLowPrice: 0,
920
+ priorSettlePrice: 0,
921
+ sessionHighBid: 0,
922
+ sessionLowOffer: 0,
923
+ earlyPrices: 0,
924
+ auctionClearingPrice: 0,
925
+ swapValueFactor: 0,
926
+ dailyValueAdjustmentForLongPositions: 0,
927
+ cumulativeValueAdjustmentForLongPositions: 0,
928
+ dailyValueAdjustmentForShortPositions: 0,
929
+ cumulativeValueAdjustmentForShortPositions: 0,
930
+ fixingPrice: 0,
931
+ cashRate: 0,
932
+ recoveryRate: 0,
933
+ recoveryRateForLong: 0,
934
+ recoveryRateForShort: 0,
935
+ marketBid: 0,
936
+ marketOffer: 0,
937
+ shortSaleMinPrice: 0,
938
+ previousClosingPrice: 0,
939
+ thresholdLimitPriceBanding: 0,
940
+ dailyFinancingValue: 0,
941
+ accruedFinancingValue: 0,
942
+ twap: 0
943
+ };
944
+ for (const entry of entries) {
945
+ const entryType = entry.MDEntryType;
946
+ const price = entry.MDEntryPx ? Number.parseFloat(entry.MDEntryPx) : 0;
947
+ const size = entry.MDEntrySize ? Number.parseFloat(entry.MDEntrySize) : 0;
948
+ switch (entryType) {
949
+ case import_fixparser3.MDEntryType.Bid:
950
+ data.bid = price;
951
+ break;
952
+ case import_fixparser3.MDEntryType.Offer:
953
+ data.offer = price;
954
+ break;
955
+ case import_fixparser3.MDEntryType.Trade:
956
+ data.trade = price;
957
+ break;
958
+ case import_fixparser3.MDEntryType.IndexValue:
959
+ data.indexValue = price;
960
+ break;
961
+ case import_fixparser3.MDEntryType.OpeningPrice:
962
+ data.openingPrice = price;
963
+ break;
964
+ case import_fixparser3.MDEntryType.ClosingPrice:
965
+ data.closingPrice = price;
966
+ break;
967
+ case import_fixparser3.MDEntryType.SettlementPrice:
968
+ data.settlementPrice = price;
969
+ break;
970
+ case import_fixparser3.MDEntryType.TradingSessionHighPrice:
971
+ data.tradingSessionHighPrice = price;
972
+ break;
973
+ case import_fixparser3.MDEntryType.TradingSessionLowPrice:
974
+ data.tradingSessionLowPrice = price;
975
+ break;
976
+ case import_fixparser3.MDEntryType.VWAP:
977
+ data.vwap = price;
978
+ break;
979
+ case import_fixparser3.MDEntryType.Imbalance:
980
+ data.imbalance = size;
981
+ break;
982
+ case import_fixparser3.MDEntryType.TradeVolume:
983
+ data.volume = size;
984
+ break;
985
+ case import_fixparser3.MDEntryType.OpenInterest:
986
+ data.openInterest = size;
987
+ break;
988
+ case import_fixparser3.MDEntryType.CompositeUnderlyingPrice:
989
+ data.compositeUnderlyingPrice = price;
990
+ break;
991
+ case import_fixparser3.MDEntryType.SimulatedSellPrice:
992
+ data.simulatedSellPrice = price;
993
+ break;
994
+ case import_fixparser3.MDEntryType.SimulatedBuyPrice:
995
+ data.simulatedBuyPrice = price;
996
+ break;
997
+ case import_fixparser3.MDEntryType.MarginRate:
998
+ data.marginRate = price;
999
+ break;
1000
+ case import_fixparser3.MDEntryType.MidPrice:
1001
+ data.midPrice = price;
1002
+ break;
1003
+ case import_fixparser3.MDEntryType.EmptyBook:
1004
+ data.emptyBook = 1;
1005
+ break;
1006
+ case import_fixparser3.MDEntryType.SettleHighPrice:
1007
+ data.settleHighPrice = price;
1008
+ break;
1009
+ case import_fixparser3.MDEntryType.SettleLowPrice:
1010
+ data.settleLowPrice = price;
1011
+ break;
1012
+ case import_fixparser3.MDEntryType.PriorSettlePrice:
1013
+ data.priorSettlePrice = price;
1014
+ break;
1015
+ case import_fixparser3.MDEntryType.SessionHighBid:
1016
+ data.sessionHighBid = price;
1017
+ break;
1018
+ case import_fixparser3.MDEntryType.SessionLowOffer:
1019
+ data.sessionLowOffer = price;
1020
+ break;
1021
+ case import_fixparser3.MDEntryType.EarlyPrices:
1022
+ data.earlyPrices = price;
1023
+ break;
1024
+ case import_fixparser3.MDEntryType.AuctionClearingPrice:
1025
+ data.auctionClearingPrice = price;
1026
+ break;
1027
+ case import_fixparser3.MDEntryType.SwapValueFactor:
1028
+ data.swapValueFactor = price;
1029
+ break;
1030
+ case import_fixparser3.MDEntryType.DailyValueAdjustmentForLongPositions:
1031
+ data.dailyValueAdjustmentForLongPositions = price;
1032
+ break;
1033
+ case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForLongPositions:
1034
+ data.cumulativeValueAdjustmentForLongPositions = price;
1035
+ break;
1036
+ case import_fixparser3.MDEntryType.DailyValueAdjustmentForShortPositions:
1037
+ data.dailyValueAdjustmentForShortPositions = price;
1038
+ break;
1039
+ case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForShortPositions:
1040
+ data.cumulativeValueAdjustmentForShortPositions = price;
1041
+ break;
1042
+ case import_fixparser3.MDEntryType.FixingPrice:
1043
+ data.fixingPrice = price;
1044
+ break;
1045
+ case import_fixparser3.MDEntryType.CashRate:
1046
+ data.cashRate = price;
1047
+ break;
1048
+ case import_fixparser3.MDEntryType.RecoveryRate:
1049
+ data.recoveryRate = price;
1050
+ break;
1051
+ case import_fixparser3.MDEntryType.RecoveryRateForLong:
1052
+ data.recoveryRateForLong = price;
1053
+ break;
1054
+ case import_fixparser3.MDEntryType.RecoveryRateForShort:
1055
+ data.recoveryRateForShort = price;
1056
+ break;
1057
+ case import_fixparser3.MDEntryType.MarketBid:
1058
+ data.marketBid = price;
1059
+ break;
1060
+ case import_fixparser3.MDEntryType.MarketOffer:
1061
+ data.marketOffer = price;
1062
+ break;
1063
+ case import_fixparser3.MDEntryType.ShortSaleMinPrice:
1064
+ data.shortSaleMinPrice = price;
1065
+ break;
1066
+ case import_fixparser3.MDEntryType.PreviousClosingPrice:
1067
+ data.previousClosingPrice = price;
1068
+ break;
1069
+ case import_fixparser3.MDEntryType.ThresholdLimitPriceBanding:
1070
+ data.thresholdLimitPriceBanding = price;
1071
+ break;
1072
+ case import_fixparser3.MDEntryType.DailyFinancingValue:
1073
+ data.dailyFinancingValue = price;
1074
+ break;
1075
+ case import_fixparser3.MDEntryType.AccruedFinancingValue:
1076
+ data.accruedFinancingValue = price;
1077
+ break;
1078
+ case import_fixparser3.MDEntryType.TWAP:
1079
+ data.twap = price;
1080
+ break;
1081
+ }
1082
+ }
1083
+ data.spread = data.offer - data.bid;
1084
+ if (!marketDataPrices.has(symbol)) {
1085
+ marketDataPrices.set(symbol, []);
1086
+ }
1087
+ const prices = marketDataPrices.get(symbol);
1088
+ prices.push(data);
1089
+ if (prices.length > maxPriceHistory) {
1090
+ prices.splice(0, prices.length - maxPriceHistory);
1091
+ }
1092
+ onPriceUpdate?.(symbol, data);
1093
+ const mdReqID = message.getField(import_fixparser3.Fields.MDReqID)?.value;
1094
+ if (mdReqID) {
1095
+ const callback = pendingRequests.get(mdReqID);
1096
+ if (callback) {
1097
+ callback(message);
1098
+ pendingRequests.delete(mdReqID);
1099
+ }
1100
+ }
1101
+ } else if (msgType === import_fixparser3.Messages.ExecutionReport) {
1102
+ const reqId = message.getField(import_fixparser3.Fields.ClOrdID)?.value;
1103
+ const callback = pendingRequests.get(reqId);
1104
+ if (callback) {
1105
+ callback(message);
1106
+ pendingRequests.delete(reqId);
1107
+ }
1108
+ }
1109
+ }
1110
+
1111
+ // src/MCPLocal.ts
1112
+ var MCPLocal = class extends MCPBase {
1113
+ /**
1114
+ * Map to store verified orders before execution
1115
+ * @private
1116
+ */
1117
+ verifiedOrders = /* @__PURE__ */ new Map();
1118
+ /**
1119
+ * Map to store pending requests and their callbacks
1120
+ * @private
1121
+ */
1122
+ pendingRequests = /* @__PURE__ */ new Map();
1123
+ /**
1124
+ * Map to store market data prices for each symbol
1125
+ * @private
1126
+ */
1127
+ marketDataPrices = /* @__PURE__ */ new Map();
1128
+ /**
1129
+ * Maximum number of price history entries to keep per symbol
1130
+ * @private
1131
+ */
1132
+ MAX_PRICE_HISTORY = 1e5;
1133
+ server = new import_server.Server(
1134
+ {
1135
+ name: "fixparser",
1136
+ version: "1.0.0"
1137
+ },
1138
+ {
1139
+ capabilities: {
1140
+ tools: Object.entries(toolSchemas).reduce(
1141
+ (acc, [name, { description, schema }]) => {
1142
+ acc[name] = {
1143
+ description,
1144
+ parameters: schema
1145
+ };
1146
+ return acc;
1147
+ },
1148
+ {}
1149
+ )
1150
+ }
1151
+ }
1152
+ );
1153
+ transport = new import_stdio.StdioServerTransport();
1154
+ constructor({ logger, onReady }) {
1155
+ super({ logger, onReady });
1156
+ }
1157
+ async register(parser) {
1158
+ this.parser = parser;
1159
+ this.parser.addOnMessageCallback((message) => {
1160
+ handleMessage(message, this.parser, this.pendingRequests, this.marketDataPrices, this.MAX_PRICE_HISTORY);
1161
+ });
1162
+ this.addWorkflows();
1163
+ await this.server.connect(this.transport);
1164
+ if (this.onReady) {
1165
+ this.onReady();
1166
+ }
1167
+ }
1168
+ addWorkflows() {
1169
+ if (!this.parser) {
1170
+ return;
1171
+ }
1172
+ if (!this.server) {
1173
+ return;
1174
+ }
1175
+ this.server.setRequestHandler(import_zod.z.object({ method: import_zod.z.literal("tools/list") }), async () => {
1176
+ return {
1177
+ tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
1178
+ name,
1179
+ description,
1180
+ inputSchema: schema
1181
+ }))
1182
+ };
1183
+ });
1031
1184
  this.server.setRequestHandler(
1032
1185
  import_zod.z.object({
1033
- method: import_zod.z.literal("marketDataRequest"),
1034
- params: marketDataRequestSchema
1186
+ method: import_zod.z.literal("tools/call"),
1187
+ params: import_zod.z.object({
1188
+ name: import_zod.z.string(),
1189
+ arguments: import_zod.z.any(),
1190
+ _meta: import_zod.z.object({
1191
+ progressToken: import_zod.z.number()
1192
+ }).optional()
1193
+ })
1035
1194
  }),
1036
- async (request, extra) => {
1037
- try {
1038
- const args = request.params;
1039
- const response = new Promise((resolve) => {
1040
- this.pendingRequests.set(args.mdReqID, resolve);
1041
- });
1042
- const messageFields = [
1043
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
1044
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
1045
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
1046
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
1047
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
1048
- new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
1049
- new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
1050
- new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
1051
- new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
1052
- ];
1053
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
1054
- args.symbols.forEach((symbol) => {
1055
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
1056
- });
1057
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, args.mdEntryTypes.length));
1058
- args.mdEntryTypes.forEach((entryType) => {
1059
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
1060
- });
1061
- const mdr = this.parser?.createMessage(...messageFields);
1062
- if (!this.parser?.connected) {
1063
- return {
1064
- contents: [
1065
- {
1066
- type: "text",
1067
- text: "Error: Not connected. Ignoring message."
1068
- }
1069
- ],
1070
- isError: true
1071
- };
1072
- }
1073
- this.parser?.send(mdr);
1074
- const fixData = await response;
1075
- return {
1076
- contents: [
1077
- {
1078
- type: "text",
1079
- text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`
1080
- }
1081
- ]
1082
- };
1083
- } catch (error) {
1195
+ async (request) => {
1196
+ const { name, arguments: args } = request.params;
1197
+ const toolHandlers = createToolHandlers(
1198
+ this.parser,
1199
+ this.verifiedOrders,
1200
+ this.pendingRequests,
1201
+ this.marketDataPrices
1202
+ );
1203
+ const handler = toolHandlers[name];
1204
+ if (!handler) {
1084
1205
  return {
1085
- contents: [
1206
+ content: [
1086
1207
  {
1087
1208
  type: "text",
1088
- text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
1209
+ text: `Tool not found: ${name}`,
1210
+ uri: name
1089
1211
  }
1090
1212
  ],
1091
1213
  isError: true
1092
1214
  };
1093
1215
  }
1216
+ const result = await handler(args);
1217
+ return {
1218
+ content: result.content,
1219
+ isError: result.isError
1220
+ };
1094
1221
  }
1095
1222
  );
1096
1223
  process.on("SIGINT", async () => {