fixparser-plugin-mcp 9.1.7-bfcb9d6f → 9.1.7-c213f7c6

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,711 @@ __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: [
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 tradeData = priceHistory.map((point) => point.trade);
451
+ const vwapData = priceHistory.map((point) => point.vwap);
452
+ const twapData = priceHistory.map((point) => point.twap);
453
+ const config = {
454
+ type: "line",
455
+ data: {
456
+ labels,
457
+ datasets: [
431
458
  {
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
- }
459
+ label: "Bid",
460
+ data: bidData,
461
+ borderColor: "#28a745",
462
+ backgroundColor: "rgba(40, 167, 69, 0.1)",
463
+ fill: false,
464
+ tension: 0.4
441
465
  },
442
466
  {
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
- }
467
+ label: "Offer",
468
+ data: offerData,
469
+ borderColor: "#dc3545",
470
+ backgroundColor: "rgba(220, 53, 69, 0.1)",
471
+ fill: false,
472
+ tension: 0.4
452
473
  },
453
474
  {
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
- }
475
+ label: "Spread",
476
+ data: spreadData,
477
+ borderColor: "#6c757d",
478
+ backgroundColor: "rgba(108, 117, 125, 0.1)",
479
+ fill: false,
480
+ tension: 0.4
533
481
  },
534
482
  {
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
- }
483
+ label: "Trade",
484
+ data: tradeData,
485
+ borderColor: "#ffc107",
486
+ backgroundColor: "rgba(255, 193, 7, 0.1)",
487
+ fill: false,
488
+ tension: 0.4
560
489
  },
561
490
  {
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
- }
491
+ label: "VWAP",
492
+ data: vwapData,
493
+ borderColor: "#17a2b8",
494
+ backgroundColor: "rgba(23, 162, 184, 0.1)",
495
+ fill: false,
496
+ tension: 0.4
497
+ },
498
+ {
499
+ label: "TWAP",
500
+ data: twapData,
501
+ borderColor: "#6610f2",
502
+ backgroundColor: "rgba(102, 16, 242, 0.1)",
503
+ fill: false,
504
+ tension: 0.4
505
+ },
506
+ {
507
+ label: "Volume",
508
+ data: volumeData,
509
+ borderColor: "#007bff",
510
+ backgroundColor: "rgba(0, 123, 255, 0.1)",
511
+ fill: true,
512
+ tension: 0.4
581
513
  }
582
514
  ]
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
- };
515
+ },
516
+ options: {
517
+ responsive: true,
518
+ plugins: {
519
+ title: {
520
+ display: true,
521
+ text: `${symbol} Market Data`
708
522
  }
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
- };
523
+ },
524
+ scales: {
525
+ y: {
526
+ beginAtZero: false
741
527
  }
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
528
  }
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
529
  }
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
- };
530
+ };
531
+ chart.setConfig(config);
532
+ const imageBuffer = await chart.toBinary();
533
+ const base64 = imageBuffer.toString("base64");
534
+ return {
535
+ content: [
536
+ {
537
+ type: "resource",
538
+ resource: {
539
+ uri: "resource://graph",
540
+ mimeType: "image/png",
541
+ blob: base64
542
+ }
806
543
  }
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
- }
544
+ ]
545
+ };
546
+ } catch (error) {
547
+ return {
548
+ content: [
549
+ {
550
+ type: "text",
551
+ text: `Error: ${error instanceof Error ? error.message : "Failed to generate graph"}`,
552
+ uri: "getStockGraph"
553
+ }
554
+ ],
555
+ isError: true
556
+ };
557
+ }
558
+ };
559
+ };
560
+ var createGetStockPriceHistoryHandler = (marketDataPrices) => {
561
+ return async (args) => {
562
+ try {
563
+ const symbol = args.symbol;
564
+ const priceHistory = marketDataPrices.get(symbol) || [];
565
+ if (priceHistory.length === 0) {
566
+ return {
567
+ content: [
568
+ {
569
+ type: "text",
570
+ text: `No price data available for ${symbol}`,
571
+ uri: "getStockPriceHistory"
572
+ }
573
+ ]
574
+ };
826
575
  }
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: [
576
+ return {
577
+ content: [
578
+ {
579
+ type: "text",
580
+ text: JSON.stringify(
915
581
  {
916
- type: "text",
917
- text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
918
-
582
+ symbol,
583
+ count: priceHistory.length,
584
+ data: priceHistory.map((point) => ({
585
+ timestamp: new Date(point.timestamp).toISOString(),
586
+ bid: point.bid,
587
+ offer: point.offer,
588
+ spread: point.spread,
589
+ volume: point.volume,
590
+ trade: point.trade,
591
+ indexValue: point.indexValue,
592
+ openingPrice: point.openingPrice,
593
+ closingPrice: point.closingPrice,
594
+ settlementPrice: point.settlementPrice,
595
+ tradingSessionHighPrice: point.tradingSessionHighPrice,
596
+ tradingSessionLowPrice: point.tradingSessionLowPrice,
597
+ vwap: point.vwap,
598
+ imbalance: point.imbalance,
599
+ openInterest: point.openInterest,
600
+ compositeUnderlyingPrice: point.compositeUnderlyingPrice,
601
+ simulatedSellPrice: point.simulatedSellPrice,
602
+ simulatedBuyPrice: point.simulatedBuyPrice,
603
+ marginRate: point.marginRate,
604
+ midPrice: point.midPrice,
605
+ emptyBook: point.emptyBook,
606
+ settleHighPrice: point.settleHighPrice,
607
+ settleLowPrice: point.settleLowPrice,
608
+ priorSettlePrice: point.priorSettlePrice,
609
+ sessionHighBid: point.sessionHighBid,
610
+ sessionLowOffer: point.sessionLowOffer,
611
+ earlyPrices: point.earlyPrices,
612
+ auctionClearingPrice: point.auctionClearingPrice,
613
+ swapValueFactor: point.swapValueFactor,
614
+ dailyValueAdjustmentForLongPositions: point.dailyValueAdjustmentForLongPositions,
615
+ cumulativeValueAdjustmentForLongPositions: point.cumulativeValueAdjustmentForLongPositions,
616
+ dailyValueAdjustmentForShortPositions: point.dailyValueAdjustmentForShortPositions,
617
+ cumulativeValueAdjustmentForShortPositions: point.cumulativeValueAdjustmentForShortPositions,
618
+ fixingPrice: point.fixingPrice,
619
+ cashRate: point.cashRate,
620
+ recoveryRate: point.recoveryRate,
621
+ recoveryRateForLong: point.recoveryRateForLong,
622
+ recoveryRateForShort: point.recoveryRateForShort,
623
+ marketBid: point.marketBid,
624
+ marketOffer: point.marketOffer,
625
+ shortSaleMinPrice: point.shortSaleMinPrice,
626
+ previousClosingPrice: point.previousClosingPrice,
627
+ thresholdLimitPriceBanding: point.thresholdLimitPriceBanding,
628
+ dailyFinancingValue: point.dailyFinancingValue,
629
+ accruedFinancingValue: point.accruedFinancingValue,
630
+ twap: point.twap
631
+ }))
632
+ },
633
+ null,
634
+ 2
635
+ ),
636
+ uri: "getStockPriceHistory"
637
+ }
638
+ ]
639
+ };
640
+ } catch (error) {
641
+ return {
642
+ content: [
643
+ {
644
+ type: "text",
645
+ text: `Error: ${error instanceof Error ? error.message : "Failed to get price history"}`,
646
+ uri: "getStockPriceHistory"
647
+ }
648
+ ],
649
+ isError: true
650
+ };
651
+ }
652
+ };
653
+ };
654
+
655
+ // src/tools/order.ts
656
+ var import_fixparser2 = require("fixparser");
657
+ var ordTypeNames = {
658
+ "1": "Market",
659
+ "2": "Limit",
660
+ "3": "Stop",
661
+ "4": "StopLimit",
662
+ "5": "MarketOnClose",
663
+ "6": "WithOrWithout",
664
+ "7": "LimitOrBetter",
665
+ "8": "LimitWithOrWithout",
666
+ "9": "OnBasis",
667
+ A: "OnClose",
668
+ B: "LimitOnClose",
669
+ C: "ForexMarket",
670
+ D: "PreviouslyQuoted",
671
+ E: "PreviouslyIndicated",
672
+ F: "ForexLimit",
673
+ G: "ForexSwap",
674
+ H: "ForexPreviouslyQuoted",
675
+ I: "Funari",
676
+ J: "MarketIfTouched",
677
+ K: "MarketWithLeftOverAsLimit",
678
+ L: "PreviousFundValuationPoint",
679
+ M: "NextFundValuationPoint",
680
+ P: "Pegged",
681
+ Q: "CounterOrderSelection",
682
+ R: "StopOnBidOrOffer",
683
+ S: "StopLimitOnBidOrOffer"
684
+ };
685
+ var sideNames = {
686
+ "1": "Buy",
687
+ "2": "Sell",
688
+ "3": "BuyMinus",
689
+ "4": "SellPlus",
690
+ "5": "SellShort",
691
+ "6": "SellShortExempt",
692
+ "7": "Undisclosed",
693
+ "8": "Cross",
694
+ "9": "CrossShort",
695
+ A: "CrossShortExempt",
696
+ B: "AsDefined",
697
+ C: "Opposite",
698
+ D: "Subscribe",
699
+ E: "Redeem",
700
+ F: "Lend",
701
+ G: "Borrow",
702
+ H: "SellUndisclosed"
703
+ };
704
+ var timeInForceNames = {
705
+ "0": "Day",
706
+ "1": "GoodTillCancel",
707
+ "2": "AtTheOpening",
708
+ "3": "ImmediateOrCancel",
709
+ "4": "FillOrKill",
710
+ "5": "GoodTillCrossing",
711
+ "6": "GoodTillDate",
712
+ "7": "AtTheClose",
713
+ "8": "GoodThroughCrossing",
714
+ "9": "AtCrossing",
715
+ A: "GoodForTime",
716
+ B: "GoodForAuction",
717
+ C: "GoodForMonth"
718
+ };
719
+ var handlInstNames = {
720
+ "1": "AutomatedExecutionNoIntervention",
721
+ "2": "AutomatedExecutionInterventionOK",
722
+ "3": "ManualOrder"
723
+ };
724
+ var createVerifyOrderHandler = (parser, verifiedOrders) => {
725
+ return async (args) => {
726
+ try {
727
+ verifiedOrders.set(args.clOrdID, {
728
+ clOrdID: args.clOrdID,
729
+ handlInst: args.handlInst,
730
+ quantity: Number.parseFloat(String(args.quantity)),
731
+ price: Number.parseFloat(String(args.price)),
732
+ ordType: args.ordType,
733
+ side: args.side,
734
+ symbol: args.symbol,
735
+ timeInForce: args.timeInForce
736
+ });
737
+ return {
738
+ content: [
739
+ {
740
+ type: "text",
741
+ text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
742
+
919
743
  Parameters verified:
920
744
  - ClOrdID: ${args.clOrdID}
921
745
  - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
@@ -926,171 +750,548 @@ Parameters verified:
926
750
  - Symbol: ${args.symbol}
927
751
  - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
928
752
 
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
- }
753
+ To execute this order, call the executeOrder tool with these exact same parameters. Important: The user has to explicitly confirm before executeOrder is called!`,
754
+ uri: "verifyOrder"
755
+ }
756
+ ]
757
+ };
758
+ } catch (error) {
759
+ return {
760
+ content: [
761
+ {
762
+ type: "text",
763
+ text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
764
+ uri: "verifyOrder"
765
+ }
766
+ ],
767
+ isError: true
768
+ };
769
+ }
770
+ };
771
+ };
772
+ var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
773
+ return async (args) => {
774
+ try {
775
+ const verifiedOrder = verifiedOrders.get(args.clOrdID);
776
+ if (!verifiedOrder) {
777
+ return {
778
+ content: [
779
+ {
780
+ type: "text",
781
+ text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
782
+ uri: "executeOrder"
783
+ }
784
+ ],
785
+ isError: true
786
+ };
944
787
  }
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
- };
788
+ 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) {
789
+ return {
790
+ content: [
791
+ {
792
+ type: "text",
793
+ text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
794
+ uri: "executeOrder"
795
+ }
796
+ ],
797
+ isError: true
798
+ };
799
+ }
800
+ const response = new Promise((resolve) => {
801
+ pendingRequests.set(args.clOrdID, resolve);
802
+ });
803
+ const order = parser.createMessage(
804
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
805
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
806
+ new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
807
+ new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
808
+ new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
809
+ new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
810
+ new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
811
+ new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
812
+ new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
813
+ new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
814
+ new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
815
+ new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
816
+ new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
817
+ new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
818
+ );
819
+ if (!parser.connected) {
820
+ return {
821
+ content: [
822
+ {
823
+ type: "text",
824
+ text: "Error: Not connected. Ignoring message.",
825
+ uri: "executeOrder"
826
+ }
827
+ ],
828
+ isError: true
829
+ };
830
+ }
831
+ parser.send(order);
832
+ const fixData = await response;
833
+ verifiedOrders.delete(args.clOrdID);
834
+ return {
835
+ content: [
836
+ {
837
+ type: "text",
838
+ 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())}`,
839
+ uri: "executeOrder"
965
840
  }
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
- };
841
+ ]
842
+ };
843
+ } catch (error) {
844
+ return {
845
+ content: [
846
+ {
847
+ type: "text",
848
+ text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
849
+ uri: "executeOrder"
976
850
  }
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
- };
851
+ ],
852
+ isError: true
853
+ };
854
+ }
855
+ };
856
+ };
857
+
858
+ // src/tools/parse.ts
859
+ var createParseHandler = (parser) => {
860
+ return async (args) => {
861
+ try {
862
+ const parsedMessage = parser.parse(args.fixString);
863
+ if (!parsedMessage || parsedMessage.length === 0) {
864
+ return {
865
+ content: [
866
+ {
867
+ type: "text",
868
+ text: "Error: Failed to parse FIX string",
869
+ uri: "parse"
870
+ }
871
+ ],
872
+ isError: true
873
+ };
874
+ }
875
+ return {
876
+ content: [
877
+ {
878
+ type: "text",
879
+ text: `${parsedMessage[0].description}
880
+ ${parsedMessage[0].messageTypeDescription}`,
881
+ uri: "parse"
1006
882
  }
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
- }
883
+ ]
884
+ };
885
+ } catch (error) {
886
+ return {
887
+ content: [
888
+ {
889
+ type: "text",
890
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
891
+ uri: "parse"
892
+ }
893
+ ],
894
+ isError: true
895
+ };
896
+ }
897
+ };
898
+ };
899
+
900
+ // src/tools/parseToJSON.ts
901
+ var createParseToJSONHandler = (parser) => {
902
+ return async (args) => {
903
+ try {
904
+ const parsedMessage = parser.parse(args.fixString);
905
+ if (!parsedMessage || parsedMessage.length === 0) {
906
+ return {
907
+ content: [
908
+ {
909
+ type: "text",
910
+ text: "Error: Failed to parse FIX string",
911
+ uri: "parseToJSON"
912
+ }
913
+ ],
914
+ isError: true
915
+ };
1029
916
  }
1030
- );
917
+ return {
918
+ content: [
919
+ {
920
+ type: "text",
921
+ text: `${parsedMessage[0].toFIXJSON()}`,
922
+ uri: "parseToJSON"
923
+ }
924
+ ]
925
+ };
926
+ } catch (error) {
927
+ return {
928
+ content: [
929
+ {
930
+ type: "text",
931
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
932
+ uri: "parseToJSON"
933
+ }
934
+ ],
935
+ isError: true
936
+ };
937
+ }
938
+ };
939
+ };
940
+
941
+ // src/tools/index.ts
942
+ var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
943
+ parse: createParseHandler(parser),
944
+ parseToJSON: createParseToJSONHandler(parser),
945
+ verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
946
+ executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
947
+ marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
948
+ getStockGraph: createGetStockGraphHandler(marketDataPrices),
949
+ getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
950
+ });
951
+
952
+ // src/utils/messageHandler.ts
953
+ var import_fixparser3 = require("fixparser");
954
+ function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPriceHistory, onPriceUpdate) {
955
+ parser.logger.log({
956
+ level: "info",
957
+ message: `MCP Server received message: ${message.messageType}: ${message.description}`
958
+ });
959
+ const msgType = message.messageType;
960
+ if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
961
+ const symbol = message.getField(import_fixparser3.Fields.Symbol)?.value;
962
+ const fixJson = message.toFIXJSON();
963
+ const entries = fixJson.Body?.NoMDEntries || [];
964
+ const data = {
965
+ timestamp: Date.now(),
966
+ bid: 0,
967
+ offer: 0,
968
+ spread: 0,
969
+ volume: 0,
970
+ trade: 0,
971
+ indexValue: 0,
972
+ openingPrice: 0,
973
+ closingPrice: 0,
974
+ settlementPrice: 0,
975
+ tradingSessionHighPrice: 0,
976
+ tradingSessionLowPrice: 0,
977
+ vwap: 0,
978
+ imbalance: 0,
979
+ openInterest: 0,
980
+ compositeUnderlyingPrice: 0,
981
+ simulatedSellPrice: 0,
982
+ simulatedBuyPrice: 0,
983
+ marginRate: 0,
984
+ midPrice: 0,
985
+ emptyBook: 0,
986
+ settleHighPrice: 0,
987
+ settleLowPrice: 0,
988
+ priorSettlePrice: 0,
989
+ sessionHighBid: 0,
990
+ sessionLowOffer: 0,
991
+ earlyPrices: 0,
992
+ auctionClearingPrice: 0,
993
+ swapValueFactor: 0,
994
+ dailyValueAdjustmentForLongPositions: 0,
995
+ cumulativeValueAdjustmentForLongPositions: 0,
996
+ dailyValueAdjustmentForShortPositions: 0,
997
+ cumulativeValueAdjustmentForShortPositions: 0,
998
+ fixingPrice: 0,
999
+ cashRate: 0,
1000
+ recoveryRate: 0,
1001
+ recoveryRateForLong: 0,
1002
+ recoveryRateForShort: 0,
1003
+ marketBid: 0,
1004
+ marketOffer: 0,
1005
+ shortSaleMinPrice: 0,
1006
+ previousClosingPrice: 0,
1007
+ thresholdLimitPriceBanding: 0,
1008
+ dailyFinancingValue: 0,
1009
+ accruedFinancingValue: 0,
1010
+ twap: 0
1011
+ };
1012
+ for (const entry of entries) {
1013
+ const entryType = entry.MDEntryType;
1014
+ const price = entry.MDEntryPx ? Number.parseFloat(entry.MDEntryPx) : 0;
1015
+ const size = entry.MDEntrySize ? Number.parseFloat(entry.MDEntrySize) : 0;
1016
+ if (entryType === import_fixparser3.MDEntryType.Bid || entryType === import_fixparser3.MDEntryType.Offer || entryType === import_fixparser3.MDEntryType.TradeVolume) {
1017
+ parser.logger.log({
1018
+ level: "info",
1019
+ message: `Market Data Entry - Type: ${entryType}, Price: ${price}, Size: ${size}`
1020
+ });
1021
+ }
1022
+ switch (entryType) {
1023
+ case import_fixparser3.MDEntryType.Bid:
1024
+ data.bid = price;
1025
+ break;
1026
+ case import_fixparser3.MDEntryType.Offer:
1027
+ data.offer = price;
1028
+ break;
1029
+ case import_fixparser3.MDEntryType.Trade:
1030
+ data.trade = price;
1031
+ break;
1032
+ case import_fixparser3.MDEntryType.IndexValue:
1033
+ data.indexValue = price;
1034
+ break;
1035
+ case import_fixparser3.MDEntryType.OpeningPrice:
1036
+ data.openingPrice = price;
1037
+ break;
1038
+ case import_fixparser3.MDEntryType.ClosingPrice:
1039
+ data.closingPrice = price;
1040
+ break;
1041
+ case import_fixparser3.MDEntryType.SettlementPrice:
1042
+ data.settlementPrice = price;
1043
+ break;
1044
+ case import_fixparser3.MDEntryType.TradingSessionHighPrice:
1045
+ data.tradingSessionHighPrice = price;
1046
+ break;
1047
+ case import_fixparser3.MDEntryType.TradingSessionLowPrice:
1048
+ data.tradingSessionLowPrice = price;
1049
+ break;
1050
+ case import_fixparser3.MDEntryType.VWAP:
1051
+ data.vwap = price;
1052
+ break;
1053
+ case import_fixparser3.MDEntryType.Imbalance:
1054
+ data.imbalance = size;
1055
+ break;
1056
+ case import_fixparser3.MDEntryType.TradeVolume:
1057
+ data.volume = size;
1058
+ break;
1059
+ case import_fixparser3.MDEntryType.OpenInterest:
1060
+ data.openInterest = size;
1061
+ break;
1062
+ case import_fixparser3.MDEntryType.CompositeUnderlyingPrice:
1063
+ data.compositeUnderlyingPrice = price;
1064
+ break;
1065
+ case import_fixparser3.MDEntryType.SimulatedSellPrice:
1066
+ data.simulatedSellPrice = price;
1067
+ break;
1068
+ case import_fixparser3.MDEntryType.SimulatedBuyPrice:
1069
+ data.simulatedBuyPrice = price;
1070
+ break;
1071
+ case import_fixparser3.MDEntryType.MarginRate:
1072
+ data.marginRate = price;
1073
+ break;
1074
+ case import_fixparser3.MDEntryType.MidPrice:
1075
+ data.midPrice = price;
1076
+ break;
1077
+ case import_fixparser3.MDEntryType.EmptyBook:
1078
+ data.emptyBook = 1;
1079
+ break;
1080
+ case import_fixparser3.MDEntryType.SettleHighPrice:
1081
+ data.settleHighPrice = price;
1082
+ break;
1083
+ case import_fixparser3.MDEntryType.SettleLowPrice:
1084
+ data.settleLowPrice = price;
1085
+ break;
1086
+ case import_fixparser3.MDEntryType.PriorSettlePrice:
1087
+ data.priorSettlePrice = price;
1088
+ break;
1089
+ case import_fixparser3.MDEntryType.SessionHighBid:
1090
+ data.sessionHighBid = price;
1091
+ break;
1092
+ case import_fixparser3.MDEntryType.SessionLowOffer:
1093
+ data.sessionLowOffer = price;
1094
+ break;
1095
+ case import_fixparser3.MDEntryType.EarlyPrices:
1096
+ data.earlyPrices = price;
1097
+ break;
1098
+ case import_fixparser3.MDEntryType.AuctionClearingPrice:
1099
+ data.auctionClearingPrice = price;
1100
+ break;
1101
+ case import_fixparser3.MDEntryType.SwapValueFactor:
1102
+ data.swapValueFactor = price;
1103
+ break;
1104
+ case import_fixparser3.MDEntryType.DailyValueAdjustmentForLongPositions:
1105
+ data.dailyValueAdjustmentForLongPositions = price;
1106
+ break;
1107
+ case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForLongPositions:
1108
+ data.cumulativeValueAdjustmentForLongPositions = price;
1109
+ break;
1110
+ case import_fixparser3.MDEntryType.DailyValueAdjustmentForShortPositions:
1111
+ data.dailyValueAdjustmentForShortPositions = price;
1112
+ break;
1113
+ case import_fixparser3.MDEntryType.CumulativeValueAdjustmentForShortPositions:
1114
+ data.cumulativeValueAdjustmentForShortPositions = price;
1115
+ break;
1116
+ case import_fixparser3.MDEntryType.FixingPrice:
1117
+ data.fixingPrice = price;
1118
+ break;
1119
+ case import_fixparser3.MDEntryType.CashRate:
1120
+ data.cashRate = price;
1121
+ break;
1122
+ case import_fixparser3.MDEntryType.RecoveryRate:
1123
+ data.recoveryRate = price;
1124
+ break;
1125
+ case import_fixparser3.MDEntryType.RecoveryRateForLong:
1126
+ data.recoveryRateForLong = price;
1127
+ break;
1128
+ case import_fixparser3.MDEntryType.RecoveryRateForShort:
1129
+ data.recoveryRateForShort = price;
1130
+ break;
1131
+ case import_fixparser3.MDEntryType.MarketBid:
1132
+ data.marketBid = price;
1133
+ break;
1134
+ case import_fixparser3.MDEntryType.MarketOffer:
1135
+ data.marketOffer = price;
1136
+ break;
1137
+ case import_fixparser3.MDEntryType.ShortSaleMinPrice:
1138
+ data.shortSaleMinPrice = price;
1139
+ break;
1140
+ case import_fixparser3.MDEntryType.PreviousClosingPrice:
1141
+ data.previousClosingPrice = price;
1142
+ break;
1143
+ case import_fixparser3.MDEntryType.ThresholdLimitPriceBanding:
1144
+ data.thresholdLimitPriceBanding = price;
1145
+ break;
1146
+ case import_fixparser3.MDEntryType.DailyFinancingValue:
1147
+ data.dailyFinancingValue = price;
1148
+ break;
1149
+ case import_fixparser3.MDEntryType.AccruedFinancingValue:
1150
+ data.accruedFinancingValue = price;
1151
+ break;
1152
+ case import_fixparser3.MDEntryType.TWAP:
1153
+ data.twap = price;
1154
+ break;
1155
+ }
1156
+ }
1157
+ data.spread = data.offer - data.bid;
1158
+ if (!marketDataPrices.has(symbol)) {
1159
+ marketDataPrices.set(symbol, []);
1160
+ }
1161
+ const prices = marketDataPrices.get(symbol);
1162
+ prices.push(data);
1163
+ if (prices.length > maxPriceHistory) {
1164
+ prices.splice(0, prices.length - maxPriceHistory);
1165
+ }
1166
+ onPriceUpdate?.(symbol, data);
1167
+ const mdReqID = message.getField(import_fixparser3.Fields.MDReqID)?.value;
1168
+ if (mdReqID) {
1169
+ const callback = pendingRequests.get(mdReqID);
1170
+ if (callback) {
1171
+ callback(message);
1172
+ pendingRequests.delete(mdReqID);
1173
+ }
1174
+ }
1175
+ } else if (msgType === import_fixparser3.Messages.ExecutionReport) {
1176
+ const reqId = message.getField(import_fixparser3.Fields.ClOrdID)?.value;
1177
+ const callback = pendingRequests.get(reqId);
1178
+ if (callback) {
1179
+ callback(message);
1180
+ pendingRequests.delete(reqId);
1181
+ }
1182
+ }
1183
+ }
1184
+
1185
+ // src/MCPLocal.ts
1186
+ var MCPLocal = class extends MCPBase {
1187
+ /**
1188
+ * Map to store verified orders before execution
1189
+ * @private
1190
+ */
1191
+ verifiedOrders = /* @__PURE__ */ new Map();
1192
+ /**
1193
+ * Map to store pending requests and their callbacks
1194
+ * @private
1195
+ */
1196
+ pendingRequests = /* @__PURE__ */ new Map();
1197
+ /**
1198
+ * Map to store market data prices for each symbol
1199
+ * @private
1200
+ */
1201
+ marketDataPrices = /* @__PURE__ */ new Map();
1202
+ /**
1203
+ * Maximum number of price history entries to keep per symbol
1204
+ * @private
1205
+ */
1206
+ MAX_PRICE_HISTORY = 1e5;
1207
+ server = new import_server.Server(
1208
+ {
1209
+ name: "fixparser",
1210
+ version: "1.0.0"
1211
+ },
1212
+ {
1213
+ capabilities: {
1214
+ tools: Object.entries(toolSchemas).reduce(
1215
+ (acc, [name, { description, schema }]) => {
1216
+ acc[name] = {
1217
+ description,
1218
+ parameters: schema
1219
+ };
1220
+ return acc;
1221
+ },
1222
+ {}
1223
+ )
1224
+ }
1225
+ }
1226
+ );
1227
+ transport = new import_stdio.StdioServerTransport();
1228
+ constructor({ logger, onReady }) {
1229
+ super({ logger, onReady });
1230
+ }
1231
+ async register(parser) {
1232
+ this.parser = parser;
1233
+ this.parser.addOnMessageCallback((message) => {
1234
+ handleMessage(message, this.parser, this.pendingRequests, this.marketDataPrices, this.MAX_PRICE_HISTORY);
1235
+ });
1236
+ this.addWorkflows();
1237
+ await this.server.connect(this.transport);
1238
+ if (this.onReady) {
1239
+ this.onReady();
1240
+ }
1241
+ }
1242
+ addWorkflows() {
1243
+ if (!this.parser) {
1244
+ return;
1245
+ }
1246
+ if (!this.server) {
1247
+ return;
1248
+ }
1249
+ this.server.setRequestHandler(import_zod.z.object({ method: import_zod.z.literal("tools/list") }), async () => {
1250
+ return {
1251
+ tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
1252
+ name,
1253
+ description,
1254
+ inputSchema: schema
1255
+ }))
1256
+ };
1257
+ });
1031
1258
  this.server.setRequestHandler(
1032
1259
  import_zod.z.object({
1033
- method: import_zod.z.literal("marketDataRequest"),
1034
- params: marketDataRequestSchema
1260
+ method: import_zod.z.literal("tools/call"),
1261
+ params: import_zod.z.object({
1262
+ name: import_zod.z.string(),
1263
+ arguments: import_zod.z.any(),
1264
+ _meta: import_zod.z.object({
1265
+ progressToken: import_zod.z.number()
1266
+ }).optional()
1267
+ })
1035
1268
  }),
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) {
1269
+ async (request) => {
1270
+ const { name, arguments: args } = request.params;
1271
+ const toolHandlers = createToolHandlers(
1272
+ this.parser,
1273
+ this.verifiedOrders,
1274
+ this.pendingRequests,
1275
+ this.marketDataPrices
1276
+ );
1277
+ const handler = toolHandlers[name];
1278
+ if (!handler) {
1084
1279
  return {
1085
- contents: [
1280
+ content: [
1086
1281
  {
1087
1282
  type: "text",
1088
- text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
1283
+ text: `Tool not found: ${name}`,
1284
+ uri: name
1089
1285
  }
1090
1286
  ],
1091
1287
  isError: true
1092
1288
  };
1093
1289
  }
1290
+ const result = await handler(args);
1291
+ return {
1292
+ content: result.content,
1293
+ isError: result.isError
1294
+ };
1094
1295
  }
1095
1296
  );
1096
1297
  process.on("SIGINT", async () => {