fixparser-plugin-mcp 9.1.7-8fdb1e41 → 9.1.7-945d3edd

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,832 +35,973 @@ __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_types = require("@modelcontextprotocol/sdk/types.js");
29
- var import_fixparser = require("fixparser");
30
- var parseInputSchema = {
31
- type: "object",
32
- properties: {
33
- fixString: {
34
- type: "string",
35
- description: "FIX message string to parse"
36
- }
37
- },
38
- required: ["fixString"]
38
+ var import_zod = require("zod");
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
+ */
51
+ parser;
52
+ /**
53
+ * Called when server is setup and listening.
54
+ * @protected
55
+ */
56
+ onReady = void 0;
57
+ /**
58
+ * Map to store verified orders before execution
59
+ * @protected
60
+ */
61
+ verifiedOrders = /* @__PURE__ */ new Map();
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
+ */
71
+ marketDataPrices = /* @__PURE__ */ new Map();
72
+ /**
73
+ * Maximum number of price history entries to keep per symbol
74
+ * @protected
75
+ */
76
+ MAX_PRICE_HISTORY = 1e5;
77
+ constructor({ logger, onReady }) {
78
+ this.logger = logger;
79
+ this.onReady = onReady;
80
+ }
39
81
  };
40
- var parseToJSONInputSchema = {
41
- type: "object",
42
- properties: {
43
- fixString: {
44
- type: "string",
45
- description: "FIX message string to parse"
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"]
46
93
  }
47
94
  },
48
- required: ["fixString"]
49
- };
50
- var orderSchema = {
51
- type: "object",
52
- properties: {
53
- clOrdID: {
54
- type: "string",
55
- description: "Client Order ID"
56
- },
57
- handlInst: {
58
- type: "string",
59
- enum: ["1", "2", "3"],
60
- description: "Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"
61
- },
62
- quantity: {
63
- type: "number",
64
- description: "Order quantity"
65
- },
66
- price: {
67
- type: "number",
68
- description: "Order price"
69
- },
70
- ordType: {
71
- type: "string",
72
- enum: [
73
- "1",
74
- "2",
75
- "3",
76
- "4",
77
- "5",
78
- "6",
79
- "7",
80
- "8",
81
- "9",
82
- "A",
83
- "B",
84
- "C",
85
- "D",
86
- "E",
87
- "F",
88
- "G",
89
- "H",
90
- "I",
91
- "J",
92
- "K",
93
- "L",
94
- "M",
95
- "P",
96
- "Q",
97
- "R",
98
- "S"
99
- ],
100
- description: "Order type (1=Market, 2=Limit, 3=Stop)"
101
- },
102
- side: {
103
- type: "string",
104
- enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
105
- description: "Order 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)"
106
- },
107
- symbol: {
108
- type: "string",
109
- description: "Trading symbol"
110
- },
111
- timeInForce: {
112
- type: "string",
113
- enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
114
- description: "Time in force (0=Day, 1=Good Till Cancel, 2=At Opening, 3=Immediate or Cancel, 4=Fill or Kill, 5=Good Till Crossing, 6=Good Till Date)"
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"]
115
103
  }
116
104
  },
117
- required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
118
- };
119
- var marketDataRequestInputSchema = {
120
- type: "object",
121
- properties: {
122
- mdUpdateType: {
123
- type: "string",
124
- enum: ["0", "1"],
125
- description: 'Market data update type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for FullRefresh, "1" for IncrementalRefresh)'
126
- },
127
- symbol: {
128
- type: "string",
129
- description: "Trading symbol"
130
- },
131
- mdReqID: {
132
- type: "string",
133
- description: "Market data request ID"
134
- },
135
- subscriptionRequestType: {
136
- type: "string",
137
- enum: ["0", "1", "2"],
138
- description: 'Subscription request type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Snapshot + Updates, "1" for Snapshot, "2" for Unsubscribe)'
139
- },
140
- mdEntryType: {
141
- type: "string",
142
- enum: [
143
- "0",
144
- "1",
145
- "2",
146
- "3",
147
- "4",
148
- "5",
149
- "6",
150
- "7",
151
- "8",
152
- "9",
153
- "A",
154
- "B",
155
- "C",
156
- "D",
157
- "E",
158
- "F",
159
- "G",
160
- "H",
161
- "J",
162
- "K",
163
- "L",
164
- "M",
165
- "N",
166
- "O",
167
- "P",
168
- "Q",
169
- "S",
170
- "R",
171
- "T",
172
- "U",
173
- "V",
174
- "W",
175
- "X",
176
- "Y",
177
- "Z",
178
- "a",
179
- "b",
180
- "c",
181
- "d",
182
- "e",
183
- "g",
184
- "h",
185
- "i",
186
- "t"
187
- ],
188
- description: 'Market data entry type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Bid, "1" for Offer, "2" for Trade, "3" for Index Value, "4" for Opening Price)'
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"
160
+ }
161
+ },
162
+ required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
189
163
  }
190
164
  },
191
- required: ["symbol", "mdReqID"]
192
- };
193
- var MCPLocal = class {
194
- // private logger: Logger | undefined;
195
- parser;
196
- server = new import_server.Server(
197
- {
198
- name: "fixparser",
199
- version: "1.0.0"
200
- },
201
- {
202
- capabilities: {
203
- tools: {},
204
- prompts: {},
205
- resources: {}
206
- }
207
- }
208
- );
209
- transport = new import_stdio.StdioServerTransport();
210
- onReady = void 0;
211
- pendingRequests = /* @__PURE__ */ new Map();
212
- verifiedOrders = /* @__PURE__ */ new Map();
213
- constructor({ logger, onReady }) {
214
- if (onReady) this.onReady = onReady;
215
- }
216
- async register(parser) {
217
- this.parser = parser;
218
- this.parser.addOnMessageCallback((message) => {
219
- const msgType = message.messageType;
220
- if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport || msgType === import_fixparser.Messages.Reject) {
221
- let id;
222
- if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
223
- const mdReqID = message.getField(import_fixparser.Fields.MDReqID);
224
- if (mdReqID) id = String(mdReqID.value);
225
- } else if (msgType === import_fixparser.Messages.ExecutionReport) {
226
- const clOrdID = message.getField(import_fixparser.Fields.ClOrdID);
227
- if (clOrdID) id = String(clOrdID.value);
228
- } else if (msgType === import_fixparser.Messages.Reject) {
229
- const refSeqNum = message.getField(import_fixparser.Fields.RefSeqNum);
230
- if (refSeqNum) id = String(refSeqNum.value);
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"
231
220
  }
232
- if (id) {
233
- const callback = this.pendingRequests.get(id);
234
- if (callback) {
235
- callback(message);
236
- this.pendingRequests.delete(id);
237
- }
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"
238
286
  }
239
- }
240
- });
241
- this.addWorkflows();
242
- await this.server.connect(this.transport);
243
- if (this.onReady) {
244
- this.onReady();
287
+ },
288
+ required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType"]
245
289
  }
246
- }
247
- addWorkflows() {
248
- if (!this.parser) {
249
- 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"]
250
299
  }
251
- if (!this.server) {
252
- 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"]
253
309
  }
254
- const validateArgs = (args, schema) => {
255
- const result = {};
256
- for (const [key, propSchema] of Object.entries(schema.properties || {})) {
257
- const prop = propSchema;
258
- const value = args?.[key];
259
- if (prop.required && (value === void 0 || value === null)) {
260
- throw new Error(`Required property '${key}' is missing`);
261
- }
262
- if (value !== void 0) {
263
- result[key] = value;
264
- } else if (prop.default !== void 0) {
265
- result[key] = prop.default;
266
- }
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 entryTypes = args.mdEntryTypes || [import_fixparser.MDEntryType.Bid, import_fixparser.MDEntryType.Offer, import_fixparser.MDEntryType.TradeVolume];
320
+ const messageFields = [
321
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
322
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
323
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
324
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
325
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
326
+ new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
327
+ new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
328
+ new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
329
+ new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
330
+ ];
331
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
332
+ args.symbols.forEach((symbol) => {
333
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
334
+ });
335
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, entryTypes.length));
336
+ entryTypes.forEach((entryType) => {
337
+ messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
338
+ });
339
+ const mdr = parser.createMessage(...messageFields);
340
+ if (!parser.connected) {
341
+ return {
342
+ content: [
343
+ {
344
+ type: "text",
345
+ text: "Error: Not connected. Ignoring message.",
346
+ uri: "marketDataRequest"
347
+ }
348
+ ],
349
+ isError: true
350
+ };
267
351
  }
268
- return result;
269
- };
270
- this.server.setRequestHandler(import_types.ListResourcesRequestSchema, async () => {
352
+ parser.send(mdr);
271
353
  return {
272
- resources: []
354
+ content: [
355
+ {
356
+ type: "text",
357
+ text: "Subscription to Market Data successful",
358
+ uri: "marketDataRequest"
359
+ }
360
+ ]
273
361
  };
274
- });
275
- this.server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
362
+ } catch (error) {
276
363
  return {
277
- tools: [
278
- {
279
- name: "parse",
280
- description: "Parses a FIX message and describes it in plain language",
281
- inputSchema: parseInputSchema
282
- },
364
+ content: [
283
365
  {
284
- name: "parseToJSON",
285
- description: "Parses a FIX message into JSON",
286
- inputSchema: parseToJSONInputSchema
287
- },
288
- {
289
- name: "verifyOrder",
290
- description: "Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
291
- inputSchema: orderSchema
292
- },
293
- {
294
- name: "executeOrder",
295
- description: "Executes a New Order Single after verification. This is the second step - only call after successful verification.",
296
- inputSchema: orderSchema
366
+ type: "text",
367
+ text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
368
+ uri: "marketDataRequest"
369
+ }
370
+ ],
371
+ isError: true
372
+ };
373
+ }
374
+ };
375
+ };
376
+ var createGetStockGraphHandler = (marketDataPrices) => {
377
+ return async (args) => {
378
+ try {
379
+ const symbol = args.symbol;
380
+ const priceHistory = marketDataPrices.get(symbol) || [];
381
+ if (priceHistory.length === 0) {
382
+ return {
383
+ content: [
384
+ {
385
+ type: "text",
386
+ text: `No price data available for ${symbol}`,
387
+ uri: "getStockGraph"
388
+ }
389
+ ]
390
+ };
391
+ }
392
+ const chart = new import_quickchart_js.default();
393
+ chart.setWidth(1200);
394
+ chart.setHeight(600);
395
+ chart.setBackgroundColor("transparent");
396
+ const labels = priceHistory.map((point) => new Date(point.timestamp).toLocaleTimeString());
397
+ const bidData = priceHistory.map((point) => point.bid);
398
+ const offerData = priceHistory.map((point) => point.offer);
399
+ const spreadData = priceHistory.map((point) => point.spread);
400
+ const volumeData = priceHistory.map((point) => point.volume);
401
+ const config = {
402
+ type: "line",
403
+ data: {
404
+ labels,
405
+ datasets: [
406
+ {
407
+ label: "Bid",
408
+ data: bidData,
409
+ borderColor: "#28a745",
410
+ backgroundColor: "rgba(40, 167, 69, 0.1)",
411
+ fill: false,
412
+ tension: 0.4
413
+ },
414
+ {
415
+ label: "Offer",
416
+ data: offerData,
417
+ borderColor: "#dc3545",
418
+ backgroundColor: "rgba(220, 53, 69, 0.1)",
419
+ fill: false,
420
+ tension: 0.4
421
+ },
422
+ {
423
+ label: "Spread",
424
+ data: spreadData,
425
+ borderColor: "#6c757d",
426
+ backgroundColor: "rgba(108, 117, 125, 0.1)",
427
+ fill: false,
428
+ tension: 0.4
429
+ },
430
+ {
431
+ label: "Volume",
432
+ data: volumeData,
433
+ borderColor: "#007bff",
434
+ backgroundColor: "rgba(0, 123, 255, 0.1)",
435
+ fill: true,
436
+ tension: 0.4
437
+ }
438
+ ]
439
+ },
440
+ options: {
441
+ responsive: true,
442
+ plugins: {
443
+ title: {
444
+ display: true,
445
+ text: `${symbol} Market Data`
446
+ }
297
447
  },
448
+ scales: {
449
+ y: {
450
+ beginAtZero: false
451
+ }
452
+ }
453
+ }
454
+ };
455
+ chart.setConfig(config);
456
+ const imageBuffer = await chart.toBinary();
457
+ const base64 = imageBuffer.toString("base64");
458
+ return {
459
+ content: [
298
460
  {
299
- name: "marketDataRequest",
300
- description: "Sends a request for Market Data with the given symbol. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",
301
- inputSchema: marketDataRequestInputSchema
461
+ type: "resource",
462
+ resource: {
463
+ uri: "resource://graph",
464
+ mimeType: "image/png",
465
+ blob: base64
466
+ }
302
467
  }
303
468
  ]
304
469
  };
305
- });
306
- this.server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
307
- const { name, arguments: args } = request.params;
308
- switch (name) {
309
- case "parse": {
310
- try {
311
- const { fixString } = validateArgs(args, parseInputSchema);
312
- const parsedMessage = this.parser?.parse(fixString);
313
- if (!parsedMessage || parsedMessage.length === 0) {
314
- return {
315
- isError: true,
316
- content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
317
- };
318
- }
319
- return {
320
- content: [
321
- {
322
- type: "text",
323
- text: `${parsedMessage[0].description}
324
- ${parsedMessage[0].messageTypeDescription}`
325
- }
326
- ]
327
- };
328
- } catch (error) {
329
- return {
330
- isError: true,
331
- content: [
332
- {
333
- type: "text",
334
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
335
- }
336
- ]
337
- };
470
+ } catch (error) {
471
+ return {
472
+ content: [
473
+ {
474
+ type: "text",
475
+ text: `Error: ${error instanceof Error ? error.message : "Failed to generate chart"}`,
476
+ uri: "getStockGraph"
338
477
  }
339
- }
340
- case "parseToJSON": {
341
- try {
342
- const { fixString } = validateArgs(args, parseToJSONInputSchema);
343
- const parsedMessage = this.parser?.parse(fixString);
344
- if (!parsedMessage || parsedMessage.length === 0) {
345
- return {
346
- isError: true,
347
- content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
348
- };
478
+ ],
479
+ isError: true
480
+ };
481
+ }
482
+ };
483
+ };
484
+ var createGetStockPriceHistoryHandler = (marketDataPrices) => {
485
+ return async (args) => {
486
+ try {
487
+ const symbol = args.symbol;
488
+ const priceHistory = marketDataPrices.get(symbol) || [];
489
+ if (priceHistory.length === 0) {
490
+ return {
491
+ content: [
492
+ {
493
+ type: "text",
494
+ text: `No price data available for ${symbol}`,
495
+ uri: "getStockPriceHistory"
349
496
  }
350
- return {
351
- content: [
352
- {
353
- type: "text",
354
- text: `${parsedMessage[0].toFIXJSON()}`
355
- }
356
- ]
357
- };
358
- } catch (error) {
359
- return {
360
- isError: true,
361
- content: [
362
- {
363
- type: "text",
364
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
365
- }
366
- ]
367
- };
497
+ ]
498
+ };
499
+ }
500
+ return {
501
+ content: [
502
+ {
503
+ type: "text",
504
+ text: JSON.stringify(
505
+ {
506
+ symbol,
507
+ count: priceHistory.length,
508
+ data: priceHistory.map((point) => ({
509
+ timestamp: new Date(point.timestamp).toISOString(),
510
+ bid: point.bid,
511
+ offer: point.offer,
512
+ spread: point.spread,
513
+ volume: point.volume
514
+ }))
515
+ },
516
+ null,
517
+ 2
518
+ ),
519
+ uri: "getStockPriceHistory"
368
520
  }
369
- }
370
- case "verifyOrder": {
371
- try {
372
- const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = validateArgs(args, orderSchema);
373
- this.verifiedOrders.set(clOrdID, {
374
- clOrdID,
375
- handlInst,
376
- quantity,
377
- price,
378
- ordType,
379
- side,
380
- symbol,
381
- timeInForce
382
- });
383
- return {
384
- content: [
385
- {
386
- type: "text",
387
- text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
388
-
521
+ ]
522
+ };
523
+ } catch (error) {
524
+ return {
525
+ content: [
526
+ {
527
+ type: "text",
528
+ text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
529
+ uri: "getStockPriceHistory"
530
+ }
531
+ ],
532
+ isError: true
533
+ };
534
+ }
535
+ };
536
+ };
537
+
538
+ // src/tools/order.ts
539
+ var import_fixparser2 = require("fixparser");
540
+ var ordTypeNames = {
541
+ "1": "Market",
542
+ "2": "Limit",
543
+ "3": "Stop",
544
+ "4": "StopLimit",
545
+ "5": "MarketOnClose",
546
+ "6": "WithOrWithout",
547
+ "7": "LimitOrBetter",
548
+ "8": "LimitWithOrWithout",
549
+ "9": "OnBasis",
550
+ A: "OnClose",
551
+ B: "LimitOnClose",
552
+ C: "ForexMarket",
553
+ D: "PreviouslyQuoted",
554
+ E: "PreviouslyIndicated",
555
+ F: "ForexLimit",
556
+ G: "ForexSwap",
557
+ H: "ForexPreviouslyQuoted",
558
+ I: "Funari",
559
+ J: "MarketIfTouched",
560
+ K: "MarketWithLeftOverAsLimit",
561
+ L: "PreviousFundValuationPoint",
562
+ M: "NextFundValuationPoint",
563
+ P: "Pegged",
564
+ Q: "CounterOrderSelection",
565
+ R: "StopOnBidOrOffer",
566
+ S: "StopLimitOnBidOrOffer"
567
+ };
568
+ var sideNames = {
569
+ "1": "Buy",
570
+ "2": "Sell",
571
+ "3": "BuyMinus",
572
+ "4": "SellPlus",
573
+ "5": "SellShort",
574
+ "6": "SellShortExempt",
575
+ "7": "Undisclosed",
576
+ "8": "Cross",
577
+ "9": "CrossShort",
578
+ A: "CrossShortExempt",
579
+ B: "AsDefined",
580
+ C: "Opposite",
581
+ D: "Subscribe",
582
+ E: "Redeem",
583
+ F: "Lend",
584
+ G: "Borrow",
585
+ H: "SellUndisclosed"
586
+ };
587
+ var timeInForceNames = {
588
+ "0": "Day",
589
+ "1": "GoodTillCancel",
590
+ "2": "AtTheOpening",
591
+ "3": "ImmediateOrCancel",
592
+ "4": "FillOrKill",
593
+ "5": "GoodTillCrossing",
594
+ "6": "GoodTillDate",
595
+ "7": "AtTheClose",
596
+ "8": "GoodThroughCrossing",
597
+ "9": "AtCrossing",
598
+ A: "GoodForTime",
599
+ B: "GoodForAuction",
600
+ C: "GoodForMonth"
601
+ };
602
+ var handlInstNames = {
603
+ "1": "AutomatedExecutionNoIntervention",
604
+ "2": "AutomatedExecutionInterventionOK",
605
+ "3": "ManualOrder"
606
+ };
607
+ var createVerifyOrderHandler = (parser, verifiedOrders) => {
608
+ return async (args) => {
609
+ try {
610
+ verifiedOrders.set(args.clOrdID, {
611
+ clOrdID: args.clOrdID,
612
+ handlInst: args.handlInst,
613
+ quantity: Number.parseFloat(String(args.quantity)),
614
+ price: Number.parseFloat(String(args.price)),
615
+ ordType: args.ordType,
616
+ side: args.side,
617
+ symbol: args.symbol,
618
+ timeInForce: args.timeInForce
619
+ });
620
+ return {
621
+ content: [
622
+ {
623
+ type: "text",
624
+ text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
625
+
389
626
  Parameters verified:
390
- - ClOrdID: ${clOrdID}
391
- - HandlInst: ${handlInst}
392
- - Quantity: ${quantity}
393
- - Price: ${price}
394
- - OrdType: ${ordType}
395
- - Side: ${side}
396
- - Symbol: ${symbol}
397
- - TimeInForce: ${timeInForce}
627
+ - ClOrdID: ${args.clOrdID}
628
+ - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
629
+ - Quantity: ${args.quantity}
630
+ - Price: ${args.price}
631
+ - OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
632
+ - Side: ${args.side} (${sideNames[args.side]})
633
+ - Symbol: ${args.symbol}
634
+ - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
398
635
 
399
- To execute this order, call the executeOrder tool with these exact same parameters.`
400
- }
401
- ]
402
- };
403
- } catch (error) {
404
- return {
405
- isError: true,
406
- content: [
407
- {
408
- type: "text",
409
- text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
410
- }
411
- ]
412
- };
636
+ To execute this order, call the executeOrder tool with these exact same parameters.`,
637
+ uri: "verifyOrder"
413
638
  }
414
- }
415
- case "executeOrder": {
416
- try {
417
- const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = validateArgs(args, orderSchema);
418
- const verifiedOrder = this.verifiedOrders.get(clOrdID);
419
- if (!verifiedOrder) {
420
- return {
421
- isError: true,
422
- content: [
423
- {
424
- type: "text",
425
- text: `Error: Order ${clOrdID} has not been verified. Please call verifyOrder first.`
426
- }
427
- ]
428
- };
429
- }
430
- if (verifiedOrder.handlInst !== handlInst || verifiedOrder.quantity !== quantity || verifiedOrder.price !== price || verifiedOrder.ordType !== ordType || verifiedOrder.side !== side || verifiedOrder.symbol !== symbol || verifiedOrder.timeInForce !== timeInForce) {
431
- return {
432
- isError: true,
433
- content: [
434
- {
435
- type: "text",
436
- text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
437
- }
438
- ]
439
- };
639
+ ]
640
+ };
641
+ } catch (error) {
642
+ return {
643
+ content: [
644
+ {
645
+ type: "text",
646
+ text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
647
+ uri: "verifyOrder"
648
+ }
649
+ ],
650
+ isError: true
651
+ };
652
+ }
653
+ };
654
+ };
655
+ var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
656
+ return async (args) => {
657
+ try {
658
+ const verifiedOrder = verifiedOrders.get(args.clOrdID);
659
+ if (!verifiedOrder) {
660
+ return {
661
+ content: [
662
+ {
663
+ type: "text",
664
+ text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
665
+ uri: "executeOrder"
440
666
  }
441
- const response = new Promise((resolve) => {
442
- this.pendingRequests.set(clOrdID, resolve);
443
- });
444
- const order = this.parser?.createMessage(
445
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
446
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
447
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
448
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
449
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
450
- new import_fixparser.Field(import_fixparser.Fields.ClOrdID, clOrdID),
451
- new import_fixparser.Field(import_fixparser.Fields.Side, side),
452
- new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
453
- new import_fixparser.Field(import_fixparser.Fields.OrderQty, quantity),
454
- new import_fixparser.Field(import_fixparser.Fields.Price, price),
455
- new import_fixparser.Field(import_fixparser.Fields.OrdType, ordType),
456
- new import_fixparser.Field(import_fixparser.Fields.HandlInst, handlInst),
457
- new import_fixparser.Field(import_fixparser.Fields.TimeInForce, timeInForce),
458
- new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
459
- );
460
- if (!this.parser?.connected) {
461
- return {
462
- isError: true,
463
- content: [
464
- {
465
- type: "text",
466
- text: "Error: Not connected. Ignoring message."
467
- }
468
- ]
469
- };
667
+ ],
668
+ isError: true
669
+ };
670
+ }
671
+ 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) {
672
+ return {
673
+ content: [
674
+ {
675
+ type: "text",
676
+ text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
677
+ uri: "executeOrder"
470
678
  }
471
- this.parser?.send(order);
472
- const fixData = await response;
473
- this.verifiedOrders.delete(clOrdID);
474
- return {
475
- content: [
476
- {
477
- type: "text",
478
- text: fixData.messageType === import_fixparser.Messages.Reject ? `Reject message for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
479
- }
480
- ]
481
- };
482
- } catch (error) {
483
- return {
484
- isError: true,
485
- content: [
486
- {
487
- type: "text",
488
- text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
489
- }
490
- ]
491
- };
492
- }
493
- }
494
- case "marketDataRequest": {
495
- try {
496
- const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = validateArgs(
497
- args,
498
- marketDataRequestInputSchema
499
- );
500
- const response = new Promise((resolve) => {
501
- this.pendingRequests.set(mdReqID, resolve);
502
- });
503
- const marketDataRequest = this.parser?.createMessage(
504
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
505
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
506
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
507
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
508
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
509
- new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
510
- new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, mdUpdateType),
511
- new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, 1),
512
- new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
513
- new import_fixparser.Field(import_fixparser.Fields.MDReqID, mdReqID),
514
- new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, subscriptionRequestType),
515
- new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
516
- new import_fixparser.Field(import_fixparser.Fields.MDEntryType, mdEntryType)
517
- );
518
- if (!this.parser?.connected) {
519
- return {
520
- isError: true,
521
- content: [
522
- {
523
- type: "text",
524
- text: "Error: Not connected. Ignoring message."
525
- }
526
- ]
527
- };
679
+ ],
680
+ isError: true
681
+ };
682
+ }
683
+ const response = new Promise((resolve) => {
684
+ pendingRequests.set(args.clOrdID, resolve);
685
+ });
686
+ const order = parser.createMessage(
687
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
688
+ new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
689
+ new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
690
+ new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
691
+ new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
692
+ new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
693
+ new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
694
+ new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
695
+ new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
696
+ new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
697
+ new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
698
+ new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
699
+ new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
700
+ new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
701
+ );
702
+ if (!parser.connected) {
703
+ return {
704
+ content: [
705
+ {
706
+ type: "text",
707
+ text: "Error: Not connected. Ignoring message.",
708
+ uri: "executeOrder"
528
709
  }
529
- this.parser?.send(marketDataRequest);
530
- const fixData = await response;
531
- return {
532
- content: [
533
- {
534
- type: "text",
535
- text: `Market data for ${symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
536
- }
537
- ]
538
- };
539
- } catch (error) {
540
- return {
541
- isError: true,
542
- content: [
543
- {
544
- type: "text",
545
- text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
546
- }
547
- ]
548
- };
549
- }
550
- }
551
- default:
552
- throw new Error(`Unknown tool: ${name}`);
710
+ ],
711
+ isError: true
712
+ };
553
713
  }
554
- });
555
- this.server.setRequestHandler(import_types.ListPromptsRequestSchema, async () => {
714
+ parser.send(order);
715
+ const fixData = await response;
716
+ verifiedOrders.delete(args.clOrdID);
556
717
  return {
557
- prompts: [
718
+ content: [
558
719
  {
559
- name: "parse",
560
- description: "Parses a FIX message and describes it in plain language",
561
- arguments: [
562
- {
563
- name: "fixString",
564
- description: "FIX message string to parse",
565
- required: true
566
- }
567
- ]
568
- },
720
+ type: "text",
721
+ 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())}`,
722
+ uri: "executeOrder"
723
+ }
724
+ ]
725
+ };
726
+ } catch (error) {
727
+ return {
728
+ content: [
569
729
  {
570
- name: "parseToJSON",
571
- description: "Parses a FIX message into JSON",
572
- arguments: [
573
- {
574
- name: "fixString",
575
- description: "FIX message string to parse",
576
- required: true
577
- }
578
- ]
579
- },
730
+ type: "text",
731
+ text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
732
+ uri: "executeOrder"
733
+ }
734
+ ],
735
+ isError: true
736
+ };
737
+ }
738
+ };
739
+ };
740
+
741
+ // src/tools/parse.ts
742
+ var createParseHandler = (parser) => {
743
+ return async (args) => {
744
+ try {
745
+ const parsedMessage = parser.parse(args.fixString);
746
+ if (!parsedMessage || parsedMessage.length === 0) {
747
+ return {
748
+ content: [
749
+ {
750
+ type: "text",
751
+ text: "Error: Failed to parse FIX string",
752
+ uri: "parse"
753
+ }
754
+ ],
755
+ isError: true
756
+ };
757
+ }
758
+ return {
759
+ content: [
580
760
  {
581
- name: "verifyOrder",
582
- description: "Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
583
- arguments: [
584
- {
585
- name: "clOrdID",
586
- description: "Client Order ID",
587
- required: true
588
- },
589
- {
590
- name: "handlInst",
591
- description: "Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)",
592
- required: true
593
- },
594
- {
595
- name: "quantity",
596
- description: "Order quantity",
597
- required: true
598
- },
599
- {
600
- name: "price",
601
- description: "Order price",
602
- required: true
603
- },
604
- {
605
- name: "ordType",
606
- description: "Order type (1=Market, 2=Limit, 3=Stop)",
607
- required: true
608
- },
609
- {
610
- name: "side",
611
- description: "Order 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)",
612
- required: true
613
- },
614
- {
615
- name: "symbol",
616
- description: "Trading symbol",
617
- required: true
618
- },
619
- {
620
- name: "timeInForce",
621
- description: "Time in force (0=Day, 1=Good Till Cancel, 2=At Opening, 3=Immediate or Cancel, 4=Fill or Kill, 5=Good Till Crossing, 6=Good Till Date)",
622
- required: true
623
- }
624
- ]
625
- },
761
+ type: "text",
762
+ text: `${parsedMessage[0].description}
763
+ ${parsedMessage[0].messageTypeDescription}`,
764
+ uri: "parse"
765
+ }
766
+ ]
767
+ };
768
+ } catch (error) {
769
+ return {
770
+ content: [
626
771
  {
627
- name: "executeOrder",
628
- description: "Executes a New Order Single after verification. This is the second step - only call after successful verification.",
629
- arguments: [
630
- {
631
- name: "clOrdID",
632
- description: "Client Order ID",
633
- required: true
634
- },
635
- {
636
- name: "handlInst",
637
- description: "Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)",
638
- required: true
639
- },
640
- {
641
- name: "quantity",
642
- description: "Order quantity",
643
- required: true
644
- },
645
- {
646
- name: "price",
647
- description: "Order price",
648
- required: true
649
- },
650
- {
651
- name: "ordType",
652
- description: "Order type (1=Market, 2=Limit, 3=Stop)",
653
- required: true
654
- },
655
- {
656
- name: "side",
657
- description: "Order 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)",
658
- required: true
659
- },
660
- {
661
- name: "symbol",
662
- description: "Trading symbol",
663
- required: true
664
- },
665
- {
666
- name: "timeInForce",
667
- description: "Time in force (0=Day, 1=Good Till Cancel, 2=At Opening, 3=Immediate or Cancel, 4=Fill or Kill, 5=Good Till Crossing, 6=Good Till Date)",
668
- required: true
669
- }
670
- ]
671
- },
772
+ type: "text",
773
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
774
+ uri: "parse"
775
+ }
776
+ ],
777
+ isError: true
778
+ };
779
+ }
780
+ };
781
+ };
782
+
783
+ // src/tools/parseToJSON.ts
784
+ var createParseToJSONHandler = (parser) => {
785
+ return async (args) => {
786
+ try {
787
+ const parsedMessage = parser.parse(args.fixString);
788
+ if (!parsedMessage || parsedMessage.length === 0) {
789
+ return {
790
+ content: [
791
+ {
792
+ type: "text",
793
+ text: "Error: Failed to parse FIX string",
794
+ uri: "parseToJSON"
795
+ }
796
+ ],
797
+ isError: true
798
+ };
799
+ }
800
+ return {
801
+ content: [
672
802
  {
673
- name: "marketDataRequest",
674
- description: "Sends a request for Market Data with the given symbol. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",
675
- arguments: [
676
- {
677
- name: "mdUpdateType",
678
- description: "Market data update type (0=FullRefresh, 1=IncrementalRefresh)",
679
- required: true
680
- },
681
- {
682
- name: "symbol",
683
- description: "Trading symbol",
684
- required: true
685
- },
686
- {
687
- name: "mdReqID",
688
- description: "Market data request ID",
689
- required: true
690
- },
691
- {
692
- name: "subscriptionRequestType",
693
- description: "Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)",
694
- required: true
695
- },
696
- {
697
- name: "mdEntryType",
698
- description: "Market data entry type (0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price)",
699
- required: true
700
- }
701
- ]
803
+ type: "text",
804
+ text: `${parsedMessage[0].toFIXJSON()}`,
805
+ uri: "parseToJSON"
702
806
  }
703
807
  ]
704
808
  };
705
- });
706
- this.server.setRequestHandler(import_types.GetPromptRequestSchema, async (request) => {
707
- const { name, arguments: args } = request.params;
708
- switch (name) {
709
- case "parse": {
710
- const fixString = args?.fixString || "";
711
- return {
712
- messages: [
713
- {
714
- role: "user",
715
- content: {
716
- type: "text",
717
- text: `Please parse and explain this FIX message: ${fixString}`
718
- }
719
- }
720
- ]
721
- };
722
- }
723
- case "parseToJSON": {
724
- const fixString = args?.fixString || "";
725
- return {
726
- messages: [
727
- {
728
- role: "user",
729
- content: {
730
- type: "text",
731
- text: `Please parse the FIX message to JSON: ${fixString}`
732
- }
733
- }
734
- ]
735
- };
736
- }
737
- case "verifyOrder": {
738
- const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = args || {};
739
- return {
740
- messages: [
741
- {
742
- role: "user",
743
- content: {
744
- type: "text",
745
- text: [
746
- "You are an AI assistant that helps users verify FIX New Order Single parameters.",
747
- "This is STEP 1 of 2 - VERIFICATION ONLY. No order will be sent at this stage.",
748
- "",
749
- "You must verify that all required fields are provided and valid:",
750
- "- ClOrdID (Client Order ID)",
751
- "- HandlInst (1=Manual, 2=Automated, 3=AutomatedNoIntervention)",
752
- "- Quantity (Order quantity)",
753
- "- Price (Order price)",
754
- "- OrdType (1=Market, 2=Limit, 3=Stop)",
755
- "- 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)",
756
- "- Symbol (Trading symbol)",
757
- "- TimeInForce (0=Day, 1=Good Till Cancel, 2=At Opening, 3=Immediate or Cancel, 4=Fill or Kill, 5=Good Till Crossing, 6=Good Till Date)",
758
- "",
759
- "Current parameters to verify:",
760
- `- ClOrdID: ${clOrdID}`,
761
- `- HandlInst: ${handlInst}`,
762
- `- Quantity: ${quantity}`,
763
- `- Price: ${price}`,
764
- `- OrdType: ${ordType}`,
765
- `- Side: ${side}`,
766
- `- Symbol: ${symbol}`,
767
- `- TimeInForce: ${timeInForce}`,
768
- "",
769
- "If all parameters are valid, respond with:",
770
- "`VERIFICATION: All parameters valid. Ready to proceed.`",
771
- "",
772
- "Otherwise, list the missing or invalid ones.",
773
- "",
774
- "IMPORTANT: This is only verification. To actually send the order, the user must call the executeOrder tool with the same parameters."
775
- ].join("\n")
776
- }
777
- }
778
- ]
779
- };
780
- }
781
- case "executeOrder": {
782
- const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = args || {};
783
- return {
784
- messages: [
785
- {
786
- role: "user",
787
- content: {
788
- type: "text",
789
- text: [
790
- "You are an AI assistant that helps users execute FIX New Order Single messages.",
791
- "This is STEP 2 of 2 - EXECUTION. This will send the order to the market.",
792
- "",
793
- "IMPORTANT: This tool should only be called after successful verification of all parameters.",
794
- "",
795
- "Parameters to execute:",
796
- `- ClOrdID: ${clOrdID}`,
797
- `- HandlInst: ${handlInst}`,
798
- `- Quantity: ${quantity}`,
799
- `- Price: ${price}`,
800
- `- OrdType: ${ordType}`,
801
- `- Side: ${side}`,
802
- `- Symbol: ${symbol}`,
803
- `- TimeInForce: ${timeInForce}`,
804
- "",
805
- "IMPORTANT: The response will be either:",
806
- "1. An Execution Report (MsgType=8) if the order was successfully placed",
807
- "2. A Reject message (MsgType=3) if the order failed to execute (e.g., due to missing or invalid parameters)"
808
- ].join("\n")
809
- }
810
- }
811
- ]
812
- };
809
+ } catch (error) {
810
+ return {
811
+ content: [
812
+ {
813
+ type: "text",
814
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
815
+ uri: "parseToJSON"
816
+ }
817
+ ],
818
+ isError: true
819
+ };
820
+ }
821
+ };
822
+ };
823
+
824
+ // src/tools/index.ts
825
+ var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
826
+ parse: createParseHandler(parser),
827
+ parseToJSON: createParseToJSONHandler(parser),
828
+ verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
829
+ executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
830
+ marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
831
+ getStockGraph: createGetStockGraphHandler(marketDataPrices),
832
+ getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
833
+ });
834
+
835
+ // src/utils/messageHandler.ts
836
+ var import_fixparser3 = require("fixparser");
837
+ function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPriceHistory, onPriceUpdate) {
838
+ parser.logger.log({
839
+ level: "info",
840
+ message: `MCP Server received message: ${message.messageType}: ${message.description}`
841
+ });
842
+ const msgType = message.messageType;
843
+ if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
844
+ const symbol = message.getField(import_fixparser3.Fields.Symbol)?.value;
845
+ const entries = message.getField(import_fixparser3.Fields.NoMDEntries)?.value;
846
+ let bid = 0;
847
+ let offer = 0;
848
+ let volume = 0;
849
+ const entryTypes = message.getFields(import_fixparser3.Fields.MDEntryType);
850
+ const entryPrices = message.getFields(import_fixparser3.Fields.MDEntryPx);
851
+ const entrySizes = message.getFields(import_fixparser3.Fields.MDEntrySize);
852
+ if (entryTypes && entryPrices && entrySizes) {
853
+ for (let i = 0; i < entries; i++) {
854
+ const entryType = entryTypes[i]?.value;
855
+ const entryPrice = Number.parseFloat(entryPrices[i]?.value);
856
+ const entrySize = Number.parseFloat(entrySizes[i]?.value);
857
+ if (entryType === import_fixparser3.MDEntryType.Bid) {
858
+ bid = entryPrice;
859
+ } else if (entryType === import_fixparser3.MDEntryType.Offer) {
860
+ offer = entryPrice;
813
861
  }
814
- case "marketDataRequest": {
815
- const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = args || {};
862
+ volume += entrySize;
863
+ }
864
+ }
865
+ const spread = offer - bid;
866
+ const timestamp = Date.now();
867
+ const data = {
868
+ timestamp,
869
+ bid,
870
+ offer,
871
+ spread,
872
+ volume
873
+ };
874
+ if (!marketDataPrices.has(symbol)) {
875
+ marketDataPrices.set(symbol, []);
876
+ }
877
+ const prices = marketDataPrices.get(symbol);
878
+ prices.push(data);
879
+ if (prices.length > maxPriceHistory) {
880
+ prices.splice(0, prices.length - maxPriceHistory);
881
+ }
882
+ onPriceUpdate?.(symbol, data);
883
+ } else if (msgType === import_fixparser3.Messages.ExecutionReport) {
884
+ const reqId = message.getField(import_fixparser3.Fields.ClOrdID)?.value;
885
+ const callback = pendingRequests.get(reqId);
886
+ if (callback) {
887
+ callback(message);
888
+ pendingRequests.delete(reqId);
889
+ }
890
+ }
891
+ }
892
+
893
+ // src/MCPLocal.ts
894
+ var MCPLocal = class extends MCPBase {
895
+ /**
896
+ * Map to store verified orders before execution
897
+ * @private
898
+ */
899
+ verifiedOrders = /* @__PURE__ */ new Map();
900
+ /**
901
+ * Map to store pending requests and their callbacks
902
+ * @private
903
+ */
904
+ pendingRequests = /* @__PURE__ */ new Map();
905
+ /**
906
+ * Map to store market data prices for each symbol
907
+ * @private
908
+ */
909
+ marketDataPrices = /* @__PURE__ */ new Map();
910
+ /**
911
+ * Maximum number of price points to store per symbol
912
+ * @private
913
+ */
914
+ MAX_PRICE_HISTORY = 1e5;
915
+ server = new import_server.Server(
916
+ {
917
+ name: "fixparser",
918
+ version: "1.0.0"
919
+ },
920
+ {
921
+ capabilities: {
922
+ tools: Object.entries(toolSchemas).reduce(
923
+ (acc, [name, { description, schema }]) => {
924
+ acc[name] = {
925
+ description,
926
+ parameters: schema
927
+ };
928
+ return acc;
929
+ },
930
+ {}
931
+ )
932
+ }
933
+ }
934
+ );
935
+ transport = new import_stdio.StdioServerTransport();
936
+ constructor({ logger, onReady }) {
937
+ super({ logger, onReady });
938
+ }
939
+ async register(parser) {
940
+ this.parser = parser;
941
+ this.parser.addOnMessageCallback((message) => {
942
+ handleMessage(message, this.parser, this.pendingRequests, this.marketDataPrices, this.MAX_PRICE_HISTORY);
943
+ });
944
+ this.addWorkflows();
945
+ await this.server.connect(this.transport);
946
+ if (this.onReady) {
947
+ this.onReady();
948
+ }
949
+ }
950
+ addWorkflows() {
951
+ if (!this.parser) {
952
+ return;
953
+ }
954
+ if (!this.server) {
955
+ return;
956
+ }
957
+ this.server.setRequestHandler(import_zod.z.object({ method: import_zod.z.literal("tools/list") }), async () => {
958
+ return {
959
+ tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
960
+ name,
961
+ description,
962
+ inputSchema: schema
963
+ }))
964
+ };
965
+ });
966
+ this.server.setRequestHandler(
967
+ import_zod.z.object({
968
+ method: import_zod.z.literal("tools/call"),
969
+ params: import_zod.z.object({
970
+ name: import_zod.z.string(),
971
+ arguments: import_zod.z.any(),
972
+ _meta: import_zod.z.object({
973
+ progressToken: import_zod.z.number()
974
+ }).optional()
975
+ })
976
+ }),
977
+ async (request) => {
978
+ const { name, arguments: args } = request.params;
979
+ const toolHandlers = createToolHandlers(
980
+ this.parser,
981
+ this.verifiedOrders,
982
+ this.pendingRequests,
983
+ this.marketDataPrices
984
+ );
985
+ const handler = toolHandlers[name];
986
+ if (!handler) {
816
987
  return {
817
- messages: [
988
+ content: [
818
989
  {
819
- role: "user",
820
- content: {
821
- type: "text",
822
- text: [
823
- "You are an AI assistant that helps users create FIX Market Data Request messages.",
824
- "You must **first verify** that all required fields are provided:",
825
- "- MDUpdateType (0=FullRefresh, 1=IncrementalRefresh)",
826
- "- Symbol (Trading symbol)",
827
- "- MDReqID (Market data request ID)",
828
- "- SubscriptionRequestType (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)",
829
- "- MDEntryType (0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price)",
830
- "",
831
- "Only when all fields are present and valid, respond with:",
832
- "`VERIFICATION: All parameters valid. Ready to proceed.`",
833
- "",
834
- "Otherwise, list the missing or invalid ones.",
835
- "",
836
- "Do not create the FIX message until verification is complete.",
837
- "",
838
- "Current parameters:",
839
- `- MDUpdateType: ${mdUpdateType}`,
840
- `- Symbol: ${symbol}`,
841
- `- MDReqID: ${mdReqID}`,
842
- `- SubscriptionRequestType: ${subscriptionRequestType}`,
843
- `- MDEntryType: ${mdEntryType}`
844
- ].join("\n")
845
- }
990
+ type: "text",
991
+ text: `Tool not found: ${name}`,
992
+ uri: name
846
993
  }
847
- ]
994
+ ],
995
+ isError: true
848
996
  };
849
997
  }
850
- default:
851
- throw new Error(`Unknown prompt: ${name}`);
998
+ const result = await handler(args);
999
+ return {
1000
+ content: result.content,
1001
+ isError: result.isError
1002
+ };
852
1003
  }
853
- });
1004
+ );
854
1005
  process.on("SIGINT", async () => {
855
1006
  await this.server.close();
856
1007
  process.exit(0);