fixparser-plugin-mcp 9.1.7-4423352c → 9.1.7-46844c62
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 +863 -429
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/esm/MCPLocal.mjs +854 -439
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +49 -1
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +49 -1
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +12 -11
- package/types/MCPLocal.d.ts +3 -1
- package/types/schemas/index.d.ts +27 -0
- package/types/schemas/schemas.d.ts +168 -0
- package/types/tools/index.d.ts +14 -0
- package/types/tools/marketData.d.ts +34 -0
- package/types/tools/order.d.ts +11 -0
- package/types/tools/parse.d.ts +5 -0
- package/types/tools/parseToJSON.d.ts +5 -0
package/build/cjs/MCPLocal.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/MCPLocal.ts
|
|
@@ -25,169 +35,757 @@ __export(MCPLocal_exports, {
|
|
|
25
35
|
module.exports = __toCommonJS(MCPLocal_exports);
|
|
26
36
|
var import_server = require("@modelcontextprotocol/sdk/server/index.js");
|
|
27
37
|
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
28
|
-
var
|
|
38
|
+
var import_fixparser3 = require("fixparser");
|
|
39
|
+
var import_zod = require("zod");
|
|
40
|
+
|
|
41
|
+
// src/tools/marketData.ts
|
|
29
42
|
var import_fixparser = require("fixparser");
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
var import_sharp = __toESM(require("sharp"), 1);
|
|
44
|
+
var createMarketDataRequestHandler = (parser, pendingRequests) => {
|
|
45
|
+
return async (args) => {
|
|
46
|
+
try {
|
|
47
|
+
const response = new Promise((resolve) => {
|
|
48
|
+
pendingRequests.set(args.mdReqID, resolve);
|
|
49
|
+
});
|
|
50
|
+
const messageFields = [
|
|
51
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
52
|
+
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, parser.sender),
|
|
53
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
54
|
+
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, parser.target),
|
|
55
|
+
new import_fixparser.Field(import_fixparser.Fields.SendingTime, parser.getTimestamp()),
|
|
56
|
+
new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
|
|
57
|
+
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
58
|
+
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
59
|
+
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
|
|
60
|
+
];
|
|
61
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
|
|
62
|
+
args.symbols.forEach((symbol) => {
|
|
63
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
|
|
64
|
+
});
|
|
65
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, args.mdEntryTypes.length));
|
|
66
|
+
args.mdEntryTypes.forEach((entryType) => {
|
|
67
|
+
messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
|
|
68
|
+
});
|
|
69
|
+
const mdr = parser.createMessage(...messageFields);
|
|
70
|
+
if (!parser.connected) {
|
|
71
|
+
return {
|
|
72
|
+
content: [
|
|
73
|
+
{
|
|
74
|
+
type: "text",
|
|
75
|
+
text: "Error: Not connected. Ignoring message.",
|
|
76
|
+
uri: "marketDataRequest"
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
isError: true
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
parser.send(mdr);
|
|
83
|
+
const fixData = await response;
|
|
84
|
+
return {
|
|
85
|
+
content: [
|
|
86
|
+
{
|
|
87
|
+
type: "text",
|
|
88
|
+
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`,
|
|
89
|
+
uri: "marketDataRequest"
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
};
|
|
93
|
+
} catch (error) {
|
|
94
|
+
return {
|
|
95
|
+
content: [
|
|
96
|
+
{
|
|
97
|
+
type: "text",
|
|
98
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`,
|
|
99
|
+
uri: "marketDataRequest"
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
isError: true
|
|
103
|
+
};
|
|
36
104
|
}
|
|
37
|
-
}
|
|
38
|
-
required: ["fixString"]
|
|
105
|
+
};
|
|
39
106
|
};
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
107
|
+
var createGetStockGraphHandler = (marketDataPrices) => {
|
|
108
|
+
return async (args) => {
|
|
109
|
+
try {
|
|
110
|
+
const symbol = args.symbol;
|
|
111
|
+
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
112
|
+
if (priceHistory.length === 0) {
|
|
113
|
+
return {
|
|
114
|
+
content: [
|
|
115
|
+
{
|
|
116
|
+
type: "text",
|
|
117
|
+
text: `No price data available for ${symbol}`,
|
|
118
|
+
uri: "getStockGraph"
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const width = 600;
|
|
124
|
+
const height = 300;
|
|
125
|
+
const padding = 40;
|
|
126
|
+
const xScale = (width - 2 * padding) / (priceHistory.length - 1);
|
|
127
|
+
const yMin = Math.min(...priceHistory.map((d) => d.price));
|
|
128
|
+
const yMax = Math.max(...priceHistory.map((d) => d.price));
|
|
129
|
+
const yScale = (height - 2 * padding) / (yMax - yMin);
|
|
130
|
+
const points = priceHistory.map((d, i) => {
|
|
131
|
+
const x = padding + i * xScale;
|
|
132
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
133
|
+
return `${x},${y}`;
|
|
134
|
+
}).join(" L ");
|
|
135
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
136
|
+
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
|
137
|
+
<!-- Background -->
|
|
138
|
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
|
139
|
+
|
|
140
|
+
<!-- Grid lines -->
|
|
141
|
+
<g stroke="#e9ecef" stroke-width="1">
|
|
142
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
143
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
144
|
+
return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
|
|
145
|
+
}).join("\n")}
|
|
146
|
+
</g>
|
|
147
|
+
|
|
148
|
+
<!-- Price line -->
|
|
149
|
+
<path d="M ${points}"
|
|
150
|
+
fill="none"
|
|
151
|
+
stroke="#007bff"
|
|
152
|
+
stroke-width="2"/>
|
|
153
|
+
|
|
154
|
+
<!-- Data points -->
|
|
155
|
+
${priceHistory.map((d, i) => {
|
|
156
|
+
const x = padding + i * xScale;
|
|
157
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
158
|
+
return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
|
|
159
|
+
}).join("\n")}
|
|
160
|
+
|
|
161
|
+
<!-- Labels -->
|
|
162
|
+
<g font-family="Arial" font-size="12" fill="#495057">
|
|
163
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
164
|
+
const x = padding + (width - 2 * padding) * i / 4;
|
|
165
|
+
const index = Math.floor((priceHistory.length - 1) * i / 4);
|
|
166
|
+
const timestamp = new Date(priceHistory[index].timestamp).toLocaleTimeString();
|
|
167
|
+
return `<text x="${x + padding}" y="${height - padding + 20}" text-anchor="middle">${timestamp}</text>`;
|
|
168
|
+
}).join("\n")}
|
|
169
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
170
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
171
|
+
const price = yMax - (yMax - yMin) * i / 4;
|
|
172
|
+
return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
|
|
173
|
+
}).join("\n")}
|
|
174
|
+
</g>
|
|
175
|
+
|
|
176
|
+
<!-- Title -->
|
|
177
|
+
<text x="${width / 2}" y="${padding / 2}"
|
|
178
|
+
font-family="Arial" font-size="16" font-weight="bold"
|
|
179
|
+
text-anchor="middle" fill="#212529">
|
|
180
|
+
${symbol} - Price Chart (${priceHistory.length} points)
|
|
181
|
+
</text>
|
|
182
|
+
</svg>`;
|
|
183
|
+
const pngBuffer = await (0, import_sharp.default)(Buffer.from(svg)).png().toBuffer();
|
|
184
|
+
const base64Png = pngBuffer.toString("base64");
|
|
185
|
+
return {
|
|
186
|
+
content: [
|
|
187
|
+
{
|
|
188
|
+
type: "image",
|
|
189
|
+
text: base64Png,
|
|
190
|
+
uri: "getStockGraph",
|
|
191
|
+
mimeType: "image/png"
|
|
192
|
+
}
|
|
193
|
+
]
|
|
194
|
+
};
|
|
195
|
+
} catch (error) {
|
|
196
|
+
return {
|
|
197
|
+
content: [
|
|
198
|
+
{
|
|
199
|
+
type: "text",
|
|
200
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to generate stock graph"}`,
|
|
201
|
+
uri: "getStockGraph"
|
|
202
|
+
}
|
|
203
|
+
],
|
|
204
|
+
isError: true
|
|
205
|
+
};
|
|
108
206
|
}
|
|
109
|
-
}
|
|
110
|
-
required: ["clOrdID", "quantity", "price", "side", "symbol"]
|
|
207
|
+
};
|
|
111
208
|
};
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
209
|
+
var createGetStockPriceHistoryHandler = (marketDataPrices) => {
|
|
210
|
+
return async (args) => {
|
|
211
|
+
try {
|
|
212
|
+
const symbol = args.symbol;
|
|
213
|
+
const priceHistory = marketDataPrices.get(symbol) || [];
|
|
214
|
+
if (priceHistory.length === 0) {
|
|
215
|
+
return {
|
|
216
|
+
content: [
|
|
217
|
+
{
|
|
218
|
+
type: "text",
|
|
219
|
+
text: `No price data available for ${symbol}`,
|
|
220
|
+
uri: "getStockPriceHistory"
|
|
221
|
+
}
|
|
222
|
+
]
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
content: [
|
|
227
|
+
{
|
|
228
|
+
type: "text",
|
|
229
|
+
text: JSON.stringify(
|
|
230
|
+
{
|
|
231
|
+
symbol,
|
|
232
|
+
count: priceHistory.length,
|
|
233
|
+
prices: priceHistory.map((point) => ({
|
|
234
|
+
timestamp: new Date(point.timestamp).toISOString(),
|
|
235
|
+
price: point.price
|
|
236
|
+
}))
|
|
237
|
+
},
|
|
238
|
+
null,
|
|
239
|
+
2
|
|
240
|
+
),
|
|
241
|
+
uri: "getStockPriceHistory"
|
|
242
|
+
}
|
|
243
|
+
]
|
|
244
|
+
};
|
|
245
|
+
} catch (error) {
|
|
246
|
+
return {
|
|
247
|
+
content: [
|
|
248
|
+
{
|
|
249
|
+
type: "text",
|
|
250
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to get stock price history"}`,
|
|
251
|
+
uri: "getStockPriceHistory"
|
|
252
|
+
}
|
|
253
|
+
],
|
|
254
|
+
isError: true
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// src/tools/order.ts
|
|
261
|
+
var import_fixparser2 = require("fixparser");
|
|
262
|
+
var ordTypeNames = {
|
|
263
|
+
"1": "Market",
|
|
264
|
+
"2": "Limit",
|
|
265
|
+
"3": "Stop",
|
|
266
|
+
"4": "StopLimit",
|
|
267
|
+
"5": "MarketOnClose",
|
|
268
|
+
"6": "WithOrWithout",
|
|
269
|
+
"7": "LimitOrBetter",
|
|
270
|
+
"8": "LimitWithOrWithout",
|
|
271
|
+
"9": "OnBasis",
|
|
272
|
+
A: "OnClose",
|
|
273
|
+
B: "LimitOnClose",
|
|
274
|
+
C: "ForexMarket",
|
|
275
|
+
D: "PreviouslyQuoted",
|
|
276
|
+
E: "PreviouslyIndicated",
|
|
277
|
+
F: "ForexLimit",
|
|
278
|
+
G: "ForexSwap",
|
|
279
|
+
H: "ForexPreviouslyQuoted",
|
|
280
|
+
I: "Funari",
|
|
281
|
+
J: "MarketIfTouched",
|
|
282
|
+
K: "MarketWithLeftOverAsLimit",
|
|
283
|
+
L: "PreviousFundValuationPoint",
|
|
284
|
+
M: "NextFundValuationPoint",
|
|
285
|
+
P: "Pegged",
|
|
286
|
+
Q: "CounterOrderSelection",
|
|
287
|
+
R: "StopOnBidOrOffer",
|
|
288
|
+
S: "StopLimitOnBidOrOffer"
|
|
289
|
+
};
|
|
290
|
+
var sideNames = {
|
|
291
|
+
"1": "Buy",
|
|
292
|
+
"2": "Sell",
|
|
293
|
+
"3": "BuyMinus",
|
|
294
|
+
"4": "SellPlus",
|
|
295
|
+
"5": "SellShort",
|
|
296
|
+
"6": "SellShortExempt",
|
|
297
|
+
"7": "Undisclosed",
|
|
298
|
+
"8": "Cross",
|
|
299
|
+
"9": "CrossShort",
|
|
300
|
+
A: "CrossShortExempt",
|
|
301
|
+
B: "AsDefined",
|
|
302
|
+
C: "Opposite",
|
|
303
|
+
D: "Subscribe",
|
|
304
|
+
E: "Redeem",
|
|
305
|
+
F: "Lend",
|
|
306
|
+
G: "Borrow",
|
|
307
|
+
H: "SellUndisclosed"
|
|
308
|
+
};
|
|
309
|
+
var timeInForceNames = {
|
|
310
|
+
"0": "Day",
|
|
311
|
+
"1": "GoodTillCancel",
|
|
312
|
+
"2": "AtTheOpening",
|
|
313
|
+
"3": "ImmediateOrCancel",
|
|
314
|
+
"4": "FillOrKill",
|
|
315
|
+
"5": "GoodTillCrossing",
|
|
316
|
+
"6": "GoodTillDate",
|
|
317
|
+
"7": "AtTheClose",
|
|
318
|
+
"8": "GoodThroughCrossing",
|
|
319
|
+
"9": "AtCrossing",
|
|
320
|
+
A: "GoodForTime",
|
|
321
|
+
B: "GoodForAuction",
|
|
322
|
+
C: "GoodForMonth"
|
|
323
|
+
};
|
|
324
|
+
var handlInstNames = {
|
|
325
|
+
"1": "AutomatedExecutionNoIntervention",
|
|
326
|
+
"2": "AutomatedExecutionInterventionOK",
|
|
327
|
+
"3": "ManualOrder"
|
|
328
|
+
};
|
|
329
|
+
var createVerifyOrderHandler = (parser, verifiedOrders) => {
|
|
330
|
+
return async (args) => {
|
|
331
|
+
try {
|
|
332
|
+
verifiedOrders.set(args.clOrdID, {
|
|
333
|
+
clOrdID: args.clOrdID,
|
|
334
|
+
handlInst: args.handlInst,
|
|
335
|
+
quantity: Number.parseFloat(String(args.quantity)),
|
|
336
|
+
price: Number.parseFloat(String(args.price)),
|
|
337
|
+
ordType: args.ordType,
|
|
338
|
+
side: args.side,
|
|
339
|
+
symbol: args.symbol,
|
|
340
|
+
timeInForce: args.timeInForce
|
|
341
|
+
});
|
|
342
|
+
return {
|
|
343
|
+
content: [
|
|
344
|
+
{
|
|
345
|
+
type: "text",
|
|
346
|
+
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
347
|
+
|
|
348
|
+
Parameters verified:
|
|
349
|
+
- ClOrdID: ${args.clOrdID}
|
|
350
|
+
- HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
|
|
351
|
+
- Quantity: ${args.quantity}
|
|
352
|
+
- Price: ${args.price}
|
|
353
|
+
- OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
|
|
354
|
+
- Side: ${args.side} (${sideNames[args.side]})
|
|
355
|
+
- Symbol: ${args.symbol}
|
|
356
|
+
- TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
|
|
357
|
+
|
|
358
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`,
|
|
359
|
+
uri: "verifyOrder"
|
|
360
|
+
}
|
|
361
|
+
]
|
|
362
|
+
};
|
|
363
|
+
} catch (error) {
|
|
364
|
+
return {
|
|
365
|
+
content: [
|
|
366
|
+
{
|
|
367
|
+
type: "text",
|
|
368
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`,
|
|
369
|
+
uri: "verifyOrder"
|
|
370
|
+
}
|
|
371
|
+
],
|
|
372
|
+
isError: true
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
var createExecuteOrderHandler = (parser, verifiedOrders, pendingRequests) => {
|
|
378
|
+
return async (args) => {
|
|
379
|
+
try {
|
|
380
|
+
const verifiedOrder = verifiedOrders.get(args.clOrdID);
|
|
381
|
+
if (!verifiedOrder) {
|
|
382
|
+
return {
|
|
383
|
+
content: [
|
|
384
|
+
{
|
|
385
|
+
type: "text",
|
|
386
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`,
|
|
387
|
+
uri: "executeOrder"
|
|
388
|
+
}
|
|
389
|
+
],
|
|
390
|
+
isError: true
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
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) {
|
|
394
|
+
return {
|
|
395
|
+
content: [
|
|
396
|
+
{
|
|
397
|
+
type: "text",
|
|
398
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified.",
|
|
399
|
+
uri: "executeOrder"
|
|
400
|
+
}
|
|
401
|
+
],
|
|
402
|
+
isError: true
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
const response = new Promise((resolve) => {
|
|
406
|
+
pendingRequests.set(args.clOrdID, resolve);
|
|
407
|
+
});
|
|
408
|
+
const order = parser.createMessage(
|
|
409
|
+
new import_fixparser2.Field(import_fixparser2.Fields.MsgType, import_fixparser2.Messages.NewOrderSingle),
|
|
410
|
+
new import_fixparser2.Field(import_fixparser2.Fields.MsgSeqNum, parser.getNextTargetMsgSeqNum()),
|
|
411
|
+
new import_fixparser2.Field(import_fixparser2.Fields.SenderCompID, parser.sender),
|
|
412
|
+
new import_fixparser2.Field(import_fixparser2.Fields.TargetCompID, parser.target),
|
|
413
|
+
new import_fixparser2.Field(import_fixparser2.Fields.SendingTime, parser.getTimestamp()),
|
|
414
|
+
new import_fixparser2.Field(import_fixparser2.Fields.ClOrdID, args.clOrdID),
|
|
415
|
+
new import_fixparser2.Field(import_fixparser2.Fields.Side, args.side),
|
|
416
|
+
new import_fixparser2.Field(import_fixparser2.Fields.Symbol, args.symbol),
|
|
417
|
+
new import_fixparser2.Field(import_fixparser2.Fields.OrderQty, Number.parseFloat(String(args.quantity))),
|
|
418
|
+
new import_fixparser2.Field(import_fixparser2.Fields.Price, Number.parseFloat(String(args.price))),
|
|
419
|
+
new import_fixparser2.Field(import_fixparser2.Fields.OrdType, args.ordType),
|
|
420
|
+
new import_fixparser2.Field(import_fixparser2.Fields.HandlInst, args.handlInst),
|
|
421
|
+
new import_fixparser2.Field(import_fixparser2.Fields.TimeInForce, args.timeInForce),
|
|
422
|
+
new import_fixparser2.Field(import_fixparser2.Fields.TransactTime, parser.getTimestamp())
|
|
423
|
+
);
|
|
424
|
+
if (!parser.connected) {
|
|
425
|
+
return {
|
|
426
|
+
content: [
|
|
427
|
+
{
|
|
428
|
+
type: "text",
|
|
429
|
+
text: "Error: Not connected. Ignoring message.",
|
|
430
|
+
uri: "executeOrder"
|
|
431
|
+
}
|
|
432
|
+
],
|
|
433
|
+
isError: true
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
parser.send(order);
|
|
437
|
+
const fixData = await response;
|
|
438
|
+
verifiedOrders.delete(args.clOrdID);
|
|
439
|
+
return {
|
|
440
|
+
content: [
|
|
441
|
+
{
|
|
442
|
+
type: "text",
|
|
443
|
+
text: fixData.messageType === import_fixparser2.Messages.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`,
|
|
444
|
+
uri: "executeOrder"
|
|
445
|
+
}
|
|
446
|
+
]
|
|
447
|
+
};
|
|
448
|
+
} catch (error) {
|
|
449
|
+
return {
|
|
450
|
+
content: [
|
|
451
|
+
{
|
|
452
|
+
type: "text",
|
|
453
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`,
|
|
454
|
+
uri: "executeOrder"
|
|
455
|
+
}
|
|
456
|
+
],
|
|
457
|
+
isError: true
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
// src/tools/parse.ts
|
|
464
|
+
var createParseHandler = (parser) => {
|
|
465
|
+
return async (args) => {
|
|
466
|
+
try {
|
|
467
|
+
const parsedMessage = parser.parse(args.fixString);
|
|
468
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
469
|
+
return {
|
|
470
|
+
content: [
|
|
471
|
+
{
|
|
472
|
+
type: "text",
|
|
473
|
+
text: "Error: Failed to parse FIX string",
|
|
474
|
+
uri: "parse"
|
|
475
|
+
}
|
|
476
|
+
],
|
|
477
|
+
isError: true
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
return {
|
|
481
|
+
content: [
|
|
482
|
+
{
|
|
483
|
+
type: "text",
|
|
484
|
+
text: `${parsedMessage[0].description}
|
|
485
|
+
${parsedMessage[0].messageTypeDescription}`,
|
|
486
|
+
uri: "parse"
|
|
487
|
+
}
|
|
488
|
+
]
|
|
489
|
+
};
|
|
490
|
+
} catch (error) {
|
|
491
|
+
return {
|
|
492
|
+
content: [
|
|
493
|
+
{
|
|
494
|
+
type: "text",
|
|
495
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
496
|
+
uri: "parse"
|
|
497
|
+
}
|
|
498
|
+
],
|
|
499
|
+
isError: true
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
// src/tools/parseToJSON.ts
|
|
506
|
+
var createParseToJSONHandler = (parser) => {
|
|
507
|
+
return async (args) => {
|
|
508
|
+
try {
|
|
509
|
+
const parsedMessage = parser.parse(args.fixString);
|
|
510
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
511
|
+
return {
|
|
512
|
+
content: [
|
|
513
|
+
{
|
|
514
|
+
type: "text",
|
|
515
|
+
text: "Error: Failed to parse FIX string",
|
|
516
|
+
uri: "parseToJSON"
|
|
517
|
+
}
|
|
518
|
+
],
|
|
519
|
+
isError: true
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
return {
|
|
523
|
+
content: [
|
|
524
|
+
{
|
|
525
|
+
type: "text",
|
|
526
|
+
text: `${parsedMessage[0].toFIXJSON()}`,
|
|
527
|
+
uri: "parseToJSON"
|
|
528
|
+
}
|
|
529
|
+
]
|
|
530
|
+
};
|
|
531
|
+
} catch (error) {
|
|
532
|
+
return {
|
|
533
|
+
content: [
|
|
534
|
+
{
|
|
535
|
+
type: "text",
|
|
536
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`,
|
|
537
|
+
uri: "parseToJSON"
|
|
538
|
+
}
|
|
539
|
+
],
|
|
540
|
+
isError: true
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
// src/tools/index.ts
|
|
547
|
+
var createToolHandlers = (parser, verifiedOrders, pendingRequests, marketDataPrices) => ({
|
|
548
|
+
parse: createParseHandler(parser),
|
|
549
|
+
parseToJSON: createParseToJSONHandler(parser),
|
|
550
|
+
verifyOrder: createVerifyOrderHandler(parser, verifiedOrders),
|
|
551
|
+
executeOrder: createExecuteOrderHandler(parser, verifiedOrders, pendingRequests),
|
|
552
|
+
marketDataRequest: createMarketDataRequestHandler(parser, pendingRequests),
|
|
553
|
+
getStockGraph: createGetStockGraphHandler(marketDataPrices),
|
|
554
|
+
getStockPriceHistory: createGetStockPriceHistoryHandler(marketDataPrices)
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
// src/schemas/schemas.ts
|
|
558
|
+
var toolSchemas = {
|
|
559
|
+
parse: {
|
|
560
|
+
description: "Parses a FIX message and describes it in plain language",
|
|
561
|
+
schema: {
|
|
562
|
+
type: "object",
|
|
563
|
+
properties: {
|
|
564
|
+
fixString: { type: "string" }
|
|
565
|
+
},
|
|
566
|
+
required: ["fixString"]
|
|
567
|
+
}
|
|
568
|
+
},
|
|
569
|
+
parseToJSON: {
|
|
570
|
+
description: "Parses a FIX message into JSON",
|
|
571
|
+
schema: {
|
|
572
|
+
type: "object",
|
|
573
|
+
properties: {
|
|
574
|
+
fixString: { type: "string" }
|
|
575
|
+
},
|
|
576
|
+
required: ["fixString"]
|
|
577
|
+
}
|
|
578
|
+
},
|
|
579
|
+
verifyOrder: {
|
|
580
|
+
description: "Verifies order parameters before execution. verifyOrder must be called before executeOrder.",
|
|
581
|
+
schema: {
|
|
582
|
+
type: "object",
|
|
583
|
+
properties: {
|
|
584
|
+
clOrdID: { type: "string" },
|
|
585
|
+
handlInst: {
|
|
586
|
+
type: "string",
|
|
587
|
+
enum: ["1", "2", "3"],
|
|
588
|
+
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
589
|
+
},
|
|
590
|
+
quantity: { type: "string" },
|
|
591
|
+
price: { type: "string" },
|
|
592
|
+
ordType: {
|
|
593
|
+
type: "string",
|
|
594
|
+
enum: [
|
|
595
|
+
"1",
|
|
596
|
+
"2",
|
|
597
|
+
"3",
|
|
598
|
+
"4",
|
|
599
|
+
"5",
|
|
600
|
+
"6",
|
|
601
|
+
"7",
|
|
602
|
+
"8",
|
|
603
|
+
"9",
|
|
604
|
+
"A",
|
|
605
|
+
"B",
|
|
606
|
+
"C",
|
|
607
|
+
"D",
|
|
608
|
+
"E",
|
|
609
|
+
"F",
|
|
610
|
+
"G",
|
|
611
|
+
"H",
|
|
612
|
+
"I",
|
|
613
|
+
"J",
|
|
614
|
+
"K",
|
|
615
|
+
"L",
|
|
616
|
+
"M",
|
|
617
|
+
"P",
|
|
618
|
+
"Q",
|
|
619
|
+
"R",
|
|
620
|
+
"S"
|
|
621
|
+
],
|
|
622
|
+
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"
|
|
623
|
+
},
|
|
624
|
+
side: {
|
|
625
|
+
type: "string",
|
|
626
|
+
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
627
|
+
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"
|
|
628
|
+
},
|
|
629
|
+
symbol: { type: "string" },
|
|
630
|
+
timeInForce: {
|
|
631
|
+
type: "string",
|
|
632
|
+
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
633
|
+
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"
|
|
634
|
+
}
|
|
635
|
+
},
|
|
636
|
+
required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
|
|
637
|
+
}
|
|
638
|
+
},
|
|
639
|
+
executeOrder: {
|
|
640
|
+
description: "Executes a verified order. verifyOrder must be called before executeOrder. user has to explicitly allow executeOrder.",
|
|
641
|
+
schema: {
|
|
642
|
+
type: "object",
|
|
643
|
+
properties: {
|
|
644
|
+
clOrdID: { type: "string" },
|
|
645
|
+
handlInst: {
|
|
646
|
+
type: "string",
|
|
647
|
+
enum: ["1", "2", "3"],
|
|
648
|
+
description: "Handling Instructions: 1=Automated Execution No Intervention, 2=Automated Execution Intervention OK, 3=Manual Order"
|
|
649
|
+
},
|
|
650
|
+
quantity: { type: "string" },
|
|
651
|
+
price: { type: "string" },
|
|
652
|
+
ordType: {
|
|
653
|
+
type: "string",
|
|
654
|
+
enum: [
|
|
655
|
+
"1",
|
|
656
|
+
"2",
|
|
657
|
+
"3",
|
|
658
|
+
"4",
|
|
659
|
+
"5",
|
|
660
|
+
"6",
|
|
661
|
+
"7",
|
|
662
|
+
"8",
|
|
663
|
+
"9",
|
|
664
|
+
"A",
|
|
665
|
+
"B",
|
|
666
|
+
"C",
|
|
667
|
+
"D",
|
|
668
|
+
"E",
|
|
669
|
+
"F",
|
|
670
|
+
"G",
|
|
671
|
+
"H",
|
|
672
|
+
"I",
|
|
673
|
+
"J",
|
|
674
|
+
"K",
|
|
675
|
+
"L",
|
|
676
|
+
"M",
|
|
677
|
+
"P",
|
|
678
|
+
"Q",
|
|
679
|
+
"R",
|
|
680
|
+
"S"
|
|
681
|
+
],
|
|
682
|
+
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"
|
|
683
|
+
},
|
|
684
|
+
side: {
|
|
685
|
+
type: "string",
|
|
686
|
+
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
687
|
+
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"
|
|
688
|
+
},
|
|
689
|
+
symbol: { type: "string" },
|
|
690
|
+
timeInForce: {
|
|
691
|
+
type: "string",
|
|
692
|
+
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
693
|
+
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"
|
|
694
|
+
}
|
|
695
|
+
},
|
|
696
|
+
required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "timeInForce"]
|
|
697
|
+
}
|
|
698
|
+
},
|
|
699
|
+
marketDataRequest: {
|
|
700
|
+
description: "Requests market data for specified symbols",
|
|
701
|
+
schema: {
|
|
702
|
+
type: "object",
|
|
703
|
+
properties: {
|
|
704
|
+
mdUpdateType: {
|
|
705
|
+
type: "string",
|
|
706
|
+
enum: ["0", "1"],
|
|
707
|
+
description: "Market Data Update Type: 0=Full Refresh, 1=Incremental Refresh"
|
|
708
|
+
},
|
|
709
|
+
symbols: { type: "array", items: { type: "string" } },
|
|
710
|
+
mdReqID: { type: "string" },
|
|
711
|
+
subscriptionRequestType: {
|
|
712
|
+
type: "string",
|
|
713
|
+
enum: ["0", "1", "2"],
|
|
714
|
+
description: "Subscription Request Type: 0=Snapshot, 1=Snapshot + Updates, 2=Disable Previous Snapshot + Update Request"
|
|
715
|
+
},
|
|
716
|
+
mdEntryTypes: {
|
|
717
|
+
type: "array",
|
|
718
|
+
items: {
|
|
719
|
+
type: "string",
|
|
720
|
+
enum: [
|
|
721
|
+
"0",
|
|
722
|
+
"1",
|
|
723
|
+
"2",
|
|
724
|
+
"3",
|
|
725
|
+
"4",
|
|
726
|
+
"5",
|
|
727
|
+
"6",
|
|
728
|
+
"7",
|
|
729
|
+
"8",
|
|
730
|
+
"9",
|
|
731
|
+
"A",
|
|
732
|
+
"B",
|
|
733
|
+
"C",
|
|
734
|
+
"D",
|
|
735
|
+
"E",
|
|
736
|
+
"F",
|
|
737
|
+
"G",
|
|
738
|
+
"H",
|
|
739
|
+
"I",
|
|
740
|
+
"J",
|
|
741
|
+
"K",
|
|
742
|
+
"L",
|
|
743
|
+
"M",
|
|
744
|
+
"N",
|
|
745
|
+
"O",
|
|
746
|
+
"P",
|
|
747
|
+
"Q",
|
|
748
|
+
"R",
|
|
749
|
+
"S",
|
|
750
|
+
"T",
|
|
751
|
+
"U",
|
|
752
|
+
"V",
|
|
753
|
+
"W",
|
|
754
|
+
"X",
|
|
755
|
+
"Y",
|
|
756
|
+
"Z"
|
|
757
|
+
],
|
|
758
|
+
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"
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
},
|
|
762
|
+
required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType", "mdEntryTypes"]
|
|
185
763
|
}
|
|
186
764
|
},
|
|
187
|
-
|
|
765
|
+
getStockGraph: {
|
|
766
|
+
description: "Generates a price chart for a given symbol",
|
|
767
|
+
schema: {
|
|
768
|
+
type: "object",
|
|
769
|
+
properties: {
|
|
770
|
+
symbol: { type: "string" }
|
|
771
|
+
},
|
|
772
|
+
required: ["symbol"]
|
|
773
|
+
}
|
|
774
|
+
},
|
|
775
|
+
getStockPriceHistory: {
|
|
776
|
+
description: "Returns price history for a given symbol",
|
|
777
|
+
schema: {
|
|
778
|
+
type: "object",
|
|
779
|
+
properties: {
|
|
780
|
+
symbol: { type: "string" }
|
|
781
|
+
},
|
|
782
|
+
required: ["symbol"]
|
|
783
|
+
}
|
|
784
|
+
}
|
|
188
785
|
};
|
|
786
|
+
|
|
787
|
+
// src/MCPLocal.ts
|
|
189
788
|
var MCPLocal = class {
|
|
190
|
-
logger;
|
|
191
789
|
parser;
|
|
192
790
|
server = new import_server.Server(
|
|
193
791
|
{
|
|
@@ -195,39 +793,93 @@ var MCPLocal = class {
|
|
|
195
793
|
version: "1.0.0"
|
|
196
794
|
},
|
|
197
795
|
{
|
|
198
|
-
capabilities: {
|
|
796
|
+
capabilities: {
|
|
797
|
+
tools: Object.entries(toolSchemas).reduce(
|
|
798
|
+
(acc, [name, { description, schema }]) => {
|
|
799
|
+
acc[name] = {
|
|
800
|
+
description,
|
|
801
|
+
parameters: schema
|
|
802
|
+
};
|
|
803
|
+
return acc;
|
|
804
|
+
},
|
|
805
|
+
{}
|
|
806
|
+
)
|
|
807
|
+
}
|
|
199
808
|
}
|
|
200
809
|
);
|
|
201
810
|
transport = new import_stdio.StdioServerTransport();
|
|
202
811
|
onReady = void 0;
|
|
203
812
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
813
|
+
verifiedOrders = /* @__PURE__ */ new Map();
|
|
814
|
+
marketDataPrices = /* @__PURE__ */ new Map();
|
|
815
|
+
MAX_PRICE_HISTORY = 1e5;
|
|
816
|
+
// Maximum number of price points to store per symbol
|
|
204
817
|
constructor({ logger, onReady }) {
|
|
205
|
-
if (logger) this.logger = logger;
|
|
206
818
|
if (onReady) this.onReady = onReady;
|
|
207
819
|
}
|
|
208
820
|
async register(parser) {
|
|
209
821
|
this.parser = parser;
|
|
210
822
|
this.parser.addOnMessageCallback((message) => {
|
|
211
|
-
this.logger
|
|
823
|
+
this.parser?.logger.log({
|
|
212
824
|
level: "info",
|
|
213
|
-
message: `
|
|
825
|
+
message: `MCP Server received message: ${message.messageType}: ${message.description}`
|
|
214
826
|
});
|
|
215
827
|
const msgType = message.messageType;
|
|
216
|
-
if (msgType ===
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
828
|
+
if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.ExecutionReport || msgType === import_fixparser3.Messages.Reject || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
|
|
829
|
+
this.parser?.logger.log({
|
|
830
|
+
level: "info",
|
|
831
|
+
message: `MCP Server handling message type: ${msgType}`
|
|
832
|
+
});
|
|
833
|
+
let id;
|
|
834
|
+
if (msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
|
|
835
|
+
const symbol = message.getField(import_fixparser3.Fields.Symbol);
|
|
836
|
+
const price = message.getField(import_fixparser3.Fields.MDEntryPx);
|
|
837
|
+
const timestamp = message.getField(import_fixparser3.Fields.MDEntryTime)?.value || Date.now();
|
|
838
|
+
if (symbol?.value && price?.value) {
|
|
839
|
+
const symbolStr = String(symbol.value);
|
|
840
|
+
const priceNum = Number(price.value);
|
|
841
|
+
const priceHistory = this.marketDataPrices.get(symbolStr) || [];
|
|
842
|
+
priceHistory.push({
|
|
843
|
+
timestamp: Number(timestamp),
|
|
844
|
+
price: priceNum
|
|
845
|
+
});
|
|
846
|
+
if (priceHistory.length > this.MAX_PRICE_HISTORY) {
|
|
847
|
+
priceHistory.shift();
|
|
225
848
|
}
|
|
849
|
+
this.marketDataPrices.set(symbolStr, priceHistory);
|
|
850
|
+
this.parser?.logger.log({
|
|
851
|
+
level: "info",
|
|
852
|
+
message: `MCP Server added ${symbol}: ${priceNum}`
|
|
853
|
+
});
|
|
854
|
+
this.server.notification({
|
|
855
|
+
method: "priceUpdate",
|
|
856
|
+
params: {
|
|
857
|
+
symbol: symbolStr,
|
|
858
|
+
price: priceNum,
|
|
859
|
+
timestamp: Number(timestamp)
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
|
|
865
|
+
const mdReqID = message.getField(import_fixparser3.Fields.MDReqID);
|
|
866
|
+
if (mdReqID) id = String(mdReqID.value);
|
|
867
|
+
} else if (msgType === import_fixparser3.Messages.ExecutionReport) {
|
|
868
|
+
const clOrdID = message.getField(import_fixparser3.Fields.ClOrdID);
|
|
869
|
+
if (clOrdID) id = String(clOrdID.value);
|
|
870
|
+
} else if (msgType === import_fixparser3.Messages.Reject) {
|
|
871
|
+
const refSeqNum = message.getField(import_fixparser3.Fields.RefSeqNum);
|
|
872
|
+
if (refSeqNum) id = String(refSeqNum.value);
|
|
873
|
+
}
|
|
874
|
+
if (id) {
|
|
875
|
+
const callback = this.pendingRequests.get(id);
|
|
876
|
+
if (callback) {
|
|
877
|
+
callback(message);
|
|
878
|
+
this.pendingRequests.delete(id);
|
|
226
879
|
}
|
|
227
880
|
}
|
|
228
881
|
}
|
|
229
882
|
});
|
|
230
|
-
this.logger = parser.logger;
|
|
231
883
|
this.addWorkflows();
|
|
232
884
|
await this.server.connect(this.transport);
|
|
233
885
|
if (this.onReady) {
|
|
@@ -236,280 +888,62 @@ var MCPLocal = class {
|
|
|
236
888
|
}
|
|
237
889
|
addWorkflows() {
|
|
238
890
|
if (!this.parser) {
|
|
239
|
-
this.logger?.log({
|
|
240
|
-
level: "error",
|
|
241
|
-
message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of workflows..."
|
|
242
|
-
});
|
|
243
891
|
return;
|
|
244
892
|
}
|
|
245
893
|
if (!this.server) {
|
|
246
|
-
this.logger?.log({
|
|
247
|
-
level: "error",
|
|
248
|
-
message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of workflows..."
|
|
249
|
-
});
|
|
250
894
|
return;
|
|
251
895
|
}
|
|
252
|
-
this.server.setRequestHandler(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
{
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
try {
|
|
287
|
-
const parsedMessage = this.parser?.parse(fixString);
|
|
288
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
289
|
-
return {
|
|
290
|
-
isError: true,
|
|
291
|
-
content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
return {
|
|
295
|
-
content: [
|
|
296
|
-
{
|
|
297
|
-
type: "text",
|
|
298
|
-
text: `Parsed FIX message: ${fixString} (placeholder implementation)`
|
|
299
|
-
}
|
|
300
|
-
]
|
|
301
|
-
};
|
|
302
|
-
} catch (error) {
|
|
303
|
-
return {
|
|
304
|
-
isError: true,
|
|
305
|
-
content: [
|
|
306
|
-
{
|
|
307
|
-
type: "text",
|
|
308
|
-
text: "Error: Failed to parse FIX string"
|
|
309
|
-
}
|
|
310
|
-
]
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
case "parseToJSON": {
|
|
315
|
-
const { fixString } = args || {};
|
|
316
|
-
if (!fixString || typeof fixString !== "string") {
|
|
317
|
-
throw new Error("Invalid arguments: fixString is required and must be a string");
|
|
318
|
-
}
|
|
319
|
-
try {
|
|
320
|
-
const parsedMessage = this.parser?.parse(fixString);
|
|
321
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
322
|
-
return {
|
|
323
|
-
isError: true,
|
|
324
|
-
content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
return {
|
|
328
|
-
content: [
|
|
329
|
-
{
|
|
330
|
-
type: "text",
|
|
331
|
-
text: JSON.stringify({ fixString, parsed: "placeholder" })
|
|
332
|
-
}
|
|
333
|
-
]
|
|
334
|
-
};
|
|
335
|
-
} catch (error) {
|
|
336
|
-
return {
|
|
337
|
-
isError: true,
|
|
338
|
-
content: [
|
|
339
|
-
{
|
|
340
|
-
type: "text",
|
|
341
|
-
text: "Error: Failed to parse FIX string"
|
|
342
|
-
}
|
|
343
|
-
]
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
case "newOrderSingle": {
|
|
348
|
-
const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = args || {};
|
|
349
|
-
if (!clOrdID || typeof clOrdID !== "string") {
|
|
350
|
-
throw new Error("Invalid arguments: clOrdID is required and must be a string");
|
|
351
|
-
}
|
|
352
|
-
if (ordType && typeof ordType !== "string") {
|
|
353
|
-
throw new Error("Invalid arguments: ordType is required and must be a string");
|
|
354
|
-
}
|
|
355
|
-
if (handlInst && typeof handlInst !== "string") {
|
|
356
|
-
throw new Error("Invalid arguments: handlInst is required and must be a string");
|
|
357
|
-
}
|
|
358
|
-
if (timeInForce && typeof timeInForce !== "string") {
|
|
359
|
-
throw new Error("Invalid arguments: timeInForce is required and must be a string");
|
|
360
|
-
}
|
|
361
|
-
if (typeof quantity !== "number") {
|
|
362
|
-
throw new Error("Invalid arguments: quantity is required and must be a number");
|
|
363
|
-
}
|
|
364
|
-
if (typeof price !== "number") {
|
|
365
|
-
throw new Error("Invalid arguments: price is required and must be a number");
|
|
366
|
-
}
|
|
367
|
-
if (!side || typeof side !== "string" || !["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"].includes(
|
|
368
|
-
side
|
|
369
|
-
)) {
|
|
370
|
-
throw new Error("Invalid arguments: side is required and must be a valid order side");
|
|
371
|
-
}
|
|
372
|
-
if (!symbol || typeof symbol !== "string") {
|
|
373
|
-
throw new Error("Invalid arguments: symbol is required and must be a string");
|
|
374
|
-
}
|
|
375
|
-
const response = new Promise((resolve) => {
|
|
376
|
-
this.pendingRequests.set(clOrdID, resolve);
|
|
377
|
-
});
|
|
378
|
-
const msgSeqNum = this.parser?.getNextTargetMsgSeqNum();
|
|
379
|
-
const sender = this.parser?.sender;
|
|
380
|
-
const target = this.parser?.target;
|
|
381
|
-
const timestamp = this.parser?.getTimestamp();
|
|
382
|
-
if (!msgSeqNum || !sender || !target || !timestamp) {
|
|
383
|
-
throw new Error("Parser not properly initialized");
|
|
384
|
-
}
|
|
385
|
-
const order = this.parser?.createMessage(
|
|
386
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
|
|
387
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, msgSeqNum),
|
|
388
|
-
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, sender),
|
|
389
|
-
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, target),
|
|
390
|
-
new import_fixparser.Field(import_fixparser.Fields.SendingTime, timestamp),
|
|
391
|
-
new import_fixparser.Field(import_fixparser.Fields.ClOrdID, clOrdID),
|
|
392
|
-
new import_fixparser.Field(import_fixparser.Fields.Side, side),
|
|
393
|
-
new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
|
|
394
|
-
new import_fixparser.Field(import_fixparser.Fields.OrderQty, quantity),
|
|
395
|
-
new import_fixparser.Field(import_fixparser.Fields.Price, price),
|
|
396
|
-
new import_fixparser.Field(import_fixparser.Fields.OrdType, ordType || import_fixparser.OrdType.Market),
|
|
397
|
-
new import_fixparser.Field(
|
|
398
|
-
import_fixparser.Fields.HandlInst,
|
|
399
|
-
handlInst || import_fixparser.HandlInst.AutomatedExecutionNoIntervention
|
|
400
|
-
),
|
|
401
|
-
new import_fixparser.Field(import_fixparser.Fields.TimeInForce, timeInForce || import_fixparser.TimeInForce.Day),
|
|
402
|
-
new import_fixparser.Field(import_fixparser.Fields.TransactTime, timestamp)
|
|
403
|
-
);
|
|
404
|
-
if (!this.parser?.connected) {
|
|
405
|
-
this.logger?.log({
|
|
406
|
-
level: "error",
|
|
407
|
-
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
408
|
-
});
|
|
409
|
-
return {
|
|
410
|
-
isError: true,
|
|
411
|
-
content: [
|
|
412
|
-
{
|
|
413
|
-
type: "text",
|
|
414
|
-
text: "Error: Not connected. Ignoring message."
|
|
415
|
-
}
|
|
416
|
-
]
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
this.parser?.send(order);
|
|
420
|
-
this.logger?.log({
|
|
421
|
-
level: "info",
|
|
422
|
-
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${order?.description}`
|
|
423
|
-
});
|
|
424
|
-
const fixData = await response;
|
|
425
|
-
return {
|
|
426
|
-
content: [
|
|
427
|
-
{
|
|
428
|
-
type: "text",
|
|
429
|
-
text: `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
430
|
-
}
|
|
431
|
-
]
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
case "marketDataRequest": {
|
|
435
|
-
const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = args || {};
|
|
436
|
-
if (!symbol || typeof symbol !== "string") {
|
|
437
|
-
throw new Error("Invalid arguments: symbol is required and must be a string");
|
|
438
|
-
}
|
|
439
|
-
if (!mdReqID || typeof mdReqID !== "string") {
|
|
440
|
-
throw new Error("Invalid arguments: mdReqID is required and must be a string");
|
|
441
|
-
}
|
|
442
|
-
if (mdUpdateType && typeof mdUpdateType !== "string") {
|
|
443
|
-
throw new Error("Invalid arguments: mdUpdateType is required and must be a string");
|
|
444
|
-
}
|
|
445
|
-
if (subscriptionRequestType && typeof subscriptionRequestType !== "string") {
|
|
446
|
-
throw new Error("Invalid arguments: subscriptionRequestType is required and must be a string");
|
|
447
|
-
}
|
|
448
|
-
if (mdEntryType && typeof mdEntryType !== "string") {
|
|
449
|
-
throw new Error("Invalid arguments: mdEntryType is required and must be a string");
|
|
450
|
-
}
|
|
451
|
-
const response = new Promise((resolve) => {
|
|
452
|
-
this.pendingRequests.set(mdReqID, resolve);
|
|
453
|
-
});
|
|
454
|
-
const msgSeqNum = this.parser?.getNextTargetMsgSeqNum();
|
|
455
|
-
const sender = this.parser?.sender;
|
|
456
|
-
const target = this.parser?.target;
|
|
457
|
-
const timestamp = this.parser?.getTimestamp();
|
|
458
|
-
if (!msgSeqNum || !sender || !target || !timestamp) {
|
|
459
|
-
throw new Error("Parser not properly initialized");
|
|
460
|
-
}
|
|
461
|
-
const marketDataRequest = this.parser?.createMessage(
|
|
462
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
463
|
-
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, sender),
|
|
464
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, msgSeqNum),
|
|
465
|
-
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, target),
|
|
466
|
-
new import_fixparser.Field(import_fixparser.Fields.SendingTime, timestamp),
|
|
467
|
-
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
468
|
-
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, mdUpdateType || "0"),
|
|
469
|
-
new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, 1),
|
|
470
|
-
new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
|
|
471
|
-
new import_fixparser.Field(import_fixparser.Fields.MDReqID, mdReqID),
|
|
472
|
-
new import_fixparser.Field(
|
|
473
|
-
import_fixparser.Fields.SubscriptionRequestType,
|
|
474
|
-
subscriptionRequestType || import_fixparser.SubscriptionRequestType.SnapshotAndUpdates
|
|
475
|
-
),
|
|
476
|
-
new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
|
|
477
|
-
new import_fixparser.Field(import_fixparser.Fields.MDEntryType, mdEntryType || import_fixparser.MDEntryType.Bid)
|
|
478
|
-
);
|
|
479
|
-
if (!this.parser?.connected) {
|
|
480
|
-
this.logger?.log({
|
|
481
|
-
level: "error",
|
|
482
|
-
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
483
|
-
});
|
|
484
|
-
return {
|
|
485
|
-
isError: true,
|
|
486
|
-
content: [
|
|
487
|
-
{
|
|
488
|
-
type: "text",
|
|
489
|
-
text: "Error: Not connected. Ignoring message."
|
|
490
|
-
}
|
|
491
|
-
]
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
this.parser?.send(marketDataRequest);
|
|
495
|
-
this.logger?.log({
|
|
496
|
-
level: "info",
|
|
497
|
-
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${marketDataRequest?.description}`
|
|
498
|
-
});
|
|
499
|
-
const fixData = await response;
|
|
896
|
+
this.server.setRequestHandler(
|
|
897
|
+
import_zod.z.object({ method: import_zod.z.literal("tools/list") }),
|
|
898
|
+
async (request, extra) => {
|
|
899
|
+
return {
|
|
900
|
+
tools: Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
|
|
901
|
+
name,
|
|
902
|
+
description,
|
|
903
|
+
inputSchema: schema
|
|
904
|
+
}))
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
);
|
|
908
|
+
this.server.setRequestHandler(
|
|
909
|
+
import_zod.z.object({
|
|
910
|
+
method: import_zod.z.literal("tools/call"),
|
|
911
|
+
params: import_zod.z.object({
|
|
912
|
+
name: import_zod.z.string(),
|
|
913
|
+
arguments: import_zod.z.any(),
|
|
914
|
+
_meta: import_zod.z.object({
|
|
915
|
+
progressToken: import_zod.z.number()
|
|
916
|
+
}).optional()
|
|
917
|
+
})
|
|
918
|
+
}),
|
|
919
|
+
async (request, extra) => {
|
|
920
|
+
const { name, arguments: args } = request.params;
|
|
921
|
+
const toolHandlers = createToolHandlers(
|
|
922
|
+
this.parser,
|
|
923
|
+
this.verifiedOrders,
|
|
924
|
+
this.pendingRequests,
|
|
925
|
+
this.marketDataPrices
|
|
926
|
+
);
|
|
927
|
+
const handler = toolHandlers[name];
|
|
928
|
+
if (!handler) {
|
|
500
929
|
return {
|
|
501
930
|
content: [
|
|
502
931
|
{
|
|
503
932
|
type: "text",
|
|
504
|
-
text: `
|
|
933
|
+
text: `Tool not found: ${name}`,
|
|
934
|
+
uri: name
|
|
505
935
|
}
|
|
506
|
-
]
|
|
936
|
+
],
|
|
937
|
+
isError: true
|
|
507
938
|
};
|
|
508
939
|
}
|
|
509
|
-
|
|
510
|
-
|
|
940
|
+
const result = await handler(args);
|
|
941
|
+
return {
|
|
942
|
+
content: result.content,
|
|
943
|
+
isError: result.isError
|
|
944
|
+
};
|
|
511
945
|
}
|
|
512
|
-
|
|
946
|
+
);
|
|
513
947
|
process.on("SIGINT", async () => {
|
|
514
948
|
await this.server.close();
|
|
515
949
|
process.exit(0);
|