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