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