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