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