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