fixparser-plugin-mcp 9.1.7-46844c62 → 9.1.7-4a3d3ac7
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 +434 -826
- package/build/cjs/MCPLocal.js.map +4 -4
- package/build/esm/MCPLocal.mjs +434 -816
- package/build/esm/MCPLocal.mjs.map +4 -4
- package/build-examples/cjs/example_mcp_local.js +23 -23
- package/build-examples/cjs/example_mcp_local.js.map +4 -4
- package/build-examples/esm/example_mcp_local.mjs +23 -23
- package/build-examples/esm/example_mcp_local.mjs.map +4 -4
- package/package.json +2 -3
- package/types/schemas/index.d.ts +0 -27
- package/types/schemas/schemas.d.ts +0 -168
- package/types/tools/index.d.ts +0 -14
- package/types/tools/marketData.d.ts +0 -34
- package/types/tools/order.d.ts +0 -11
- package/types/tools/parse.d.ts +0 -5
- package/types/tools/parseToJSON.d.ts +0 -5
package/build/esm/MCPLocal.mjs
CHANGED
|
@@ -1,775 +1,19 @@
|
|
|
1
1
|
// src/MCPLocal.ts
|
|
2
|
-
import {
|
|
2
|
+
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
-
import { Fields as Fields3, Messages as Messages3 } from "fixparser";
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
|
|
7
|
-
// src/tools/marketData.ts
|
|
8
4
|
import { Field, Fields, Messages } from "fixparser";
|
|
9
|
-
import
|
|
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
|
-
};
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
};
|
|
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
|
-
};
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
};
|
|
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"]
|
|
739
|
-
}
|
|
740
|
-
},
|
|
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
|
-
}
|
|
751
|
-
};
|
|
752
|
-
|
|
753
|
-
// src/MCPLocal.ts
|
|
5
|
+
import { z } from "zod";
|
|
754
6
|
var MCPLocal = class {
|
|
755
7
|
parser;
|
|
756
|
-
server = new
|
|
8
|
+
server = new McpServer(
|
|
757
9
|
{
|
|
758
10
|
name: "fixparser",
|
|
759
11
|
version: "1.0.0"
|
|
760
12
|
},
|
|
761
13
|
{
|
|
762
14
|
capabilities: {
|
|
763
|
-
tools:
|
|
764
|
-
|
|
765
|
-
acc[name] = {
|
|
766
|
-
description,
|
|
767
|
-
parameters: schema
|
|
768
|
-
};
|
|
769
|
-
return acc;
|
|
770
|
-
},
|
|
771
|
-
{}
|
|
772
|
-
)
|
|
15
|
+
tools: {},
|
|
16
|
+
resources: {}
|
|
773
17
|
}
|
|
774
18
|
}
|
|
775
19
|
);
|
|
@@ -777,6 +21,7 @@ var MCPLocal = class {
|
|
|
777
21
|
onReady = void 0;
|
|
778
22
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
779
23
|
verifiedOrders = /* @__PURE__ */ new Map();
|
|
24
|
+
// Store market data prices with timestamps
|
|
780
25
|
marketDataPrices = /* @__PURE__ */ new Map();
|
|
781
26
|
MAX_PRICE_HISTORY = 1e5;
|
|
782
27
|
// Maximum number of price points to store per symbol
|
|
@@ -791,16 +36,16 @@ var MCPLocal = class {
|
|
|
791
36
|
message: `MCP Server received message: ${message.messageType}: ${message.description}`
|
|
792
37
|
});
|
|
793
38
|
const msgType = message.messageType;
|
|
794
|
-
if (msgType ===
|
|
39
|
+
if (msgType === Messages.MarketDataSnapshotFullRefresh || msgType === Messages.ExecutionReport || msgType === Messages.Reject || msgType === Messages.MarketDataIncrementalRefresh) {
|
|
795
40
|
this.parser?.logger.log({
|
|
796
41
|
level: "info",
|
|
797
42
|
message: `MCP Server handling message type: ${msgType}`
|
|
798
43
|
});
|
|
799
44
|
let id;
|
|
800
|
-
if (msgType ===
|
|
801
|
-
const symbol = message.getField(
|
|
802
|
-
const price = message.getField(
|
|
803
|
-
const timestamp = message.getField(
|
|
45
|
+
if (msgType === Messages.MarketDataIncrementalRefresh || msgType === Messages.MarketDataSnapshotFullRefresh) {
|
|
46
|
+
const symbol = message.getField(Fields.Symbol);
|
|
47
|
+
const price = message.getField(Fields.MDEntryPx);
|
|
48
|
+
const timestamp = message.getField(Fields.MDEntryTime)?.value || Date.now();
|
|
804
49
|
if (symbol?.value && price?.value) {
|
|
805
50
|
const symbolStr = String(symbol.value);
|
|
806
51
|
const priceNum = Number(price.value);
|
|
@@ -817,24 +62,16 @@ var MCPLocal = class {
|
|
|
817
62
|
level: "info",
|
|
818
63
|
message: `MCP Server added ${symbol}: ${priceNum}`
|
|
819
64
|
});
|
|
820
|
-
this.server.notification({
|
|
821
|
-
method: "priceUpdate",
|
|
822
|
-
params: {
|
|
823
|
-
symbol: symbolStr,
|
|
824
|
-
price: priceNum,
|
|
825
|
-
timestamp: Number(timestamp)
|
|
826
|
-
}
|
|
827
|
-
});
|
|
828
65
|
}
|
|
829
66
|
}
|
|
830
|
-
if (msgType ===
|
|
831
|
-
const mdReqID = message.getField(
|
|
67
|
+
if (msgType === Messages.MarketDataSnapshotFullRefresh) {
|
|
68
|
+
const mdReqID = message.getField(Fields.MDReqID);
|
|
832
69
|
if (mdReqID) id = String(mdReqID.value);
|
|
833
|
-
} else if (msgType ===
|
|
834
|
-
const clOrdID = message.getField(
|
|
70
|
+
} else if (msgType === Messages.ExecutionReport) {
|
|
71
|
+
const clOrdID = message.getField(Fields.ClOrdID);
|
|
835
72
|
if (clOrdID) id = String(clOrdID.value);
|
|
836
|
-
} else if (msgType ===
|
|
837
|
-
const refSeqNum = message.getField(
|
|
73
|
+
} else if (msgType === Messages.Reject) {
|
|
74
|
+
const refSeqNum = message.getField(Fields.RefSeqNum);
|
|
838
75
|
if (refSeqNum) id = String(refSeqNum.value);
|
|
839
76
|
}
|
|
840
77
|
if (id) {
|
|
@@ -859,54 +96,435 @@ var MCPLocal = class {
|
|
|
859
96
|
if (!this.server) {
|
|
860
97
|
return;
|
|
861
98
|
}
|
|
862
|
-
this.server.
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
99
|
+
this.server.tool(
|
|
100
|
+
"parse",
|
|
101
|
+
"Parses a FIX message and describes it in plain language",
|
|
102
|
+
{
|
|
103
|
+
fixString: z.string().describe("FIX message string to parse")
|
|
104
|
+
},
|
|
105
|
+
async (args) => {
|
|
106
|
+
try {
|
|
107
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
108
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
109
|
+
return {
|
|
110
|
+
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
111
|
+
isError: true
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
content: [
|
|
116
|
+
{
|
|
117
|
+
type: "text",
|
|
118
|
+
text: `${parsedMessage[0].description}
|
|
119
|
+
${parsedMessage[0].messageTypeDescription}`
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
};
|
|
123
|
+
} catch (error) {
|
|
124
|
+
return {
|
|
125
|
+
content: [
|
|
126
|
+
{
|
|
127
|
+
type: "text",
|
|
128
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
isError: true
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
this.server.tool(
|
|
137
|
+
"parseToJSON",
|
|
138
|
+
"Parses a FIX message into JSON",
|
|
139
|
+
{
|
|
140
|
+
fixString: z.string().describe("FIX message string to parse")
|
|
141
|
+
},
|
|
142
|
+
async (args) => {
|
|
143
|
+
try {
|
|
144
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
145
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
146
|
+
return {
|
|
147
|
+
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
148
|
+
isError: true
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
return {
|
|
152
|
+
content: [
|
|
153
|
+
{
|
|
154
|
+
type: "text",
|
|
155
|
+
text: `${parsedMessage[0].toFIXJSON()}`
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
};
|
|
159
|
+
} catch (error) {
|
|
160
|
+
return {
|
|
161
|
+
content: [
|
|
162
|
+
{
|
|
163
|
+
type: "text",
|
|
164
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
165
|
+
}
|
|
166
|
+
],
|
|
167
|
+
isError: true
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
this.server.tool(
|
|
173
|
+
"verifyOrder",
|
|
174
|
+
"Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
|
|
175
|
+
{
|
|
176
|
+
clOrdID: z.string().describe("Client Order ID"),
|
|
177
|
+
handlInst: z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
178
|
+
quantity: z.string().describe("Order quantity"),
|
|
179
|
+
price: z.string().describe("Order price"),
|
|
180
|
+
ordType: z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
181
|
+
side: z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
182
|
+
symbol: z.string().describe("Trading symbol"),
|
|
183
|
+
timeInForce: z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
184
|
+
},
|
|
185
|
+
async (args) => {
|
|
186
|
+
try {
|
|
187
|
+
this.verifiedOrders.set(args.clOrdID, {
|
|
188
|
+
clOrdID: args.clOrdID,
|
|
189
|
+
handlInst: args.handlInst,
|
|
190
|
+
quantity: Number.parseFloat(args.quantity),
|
|
191
|
+
price: Number.parseFloat(args.price),
|
|
192
|
+
ordType: args.ordType,
|
|
193
|
+
side: args.side,
|
|
194
|
+
symbol: args.symbol,
|
|
195
|
+
timeInForce: args.timeInForce
|
|
196
|
+
});
|
|
197
|
+
return {
|
|
198
|
+
content: [
|
|
199
|
+
{
|
|
200
|
+
type: "text",
|
|
201
|
+
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
202
|
+
|
|
203
|
+
Parameters verified:
|
|
204
|
+
- ClOrdID: ${args.clOrdID}
|
|
205
|
+
- HandlInst: ${args.handlInst}
|
|
206
|
+
- Quantity: ${args.quantity}
|
|
207
|
+
- Price: ${args.price}
|
|
208
|
+
- OrdType: ${args.ordType}
|
|
209
|
+
- Side: ${args.side}
|
|
210
|
+
- Symbol: ${args.symbol}
|
|
211
|
+
- TimeInForce: ${args.timeInForce}
|
|
212
|
+
|
|
213
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`
|
|
214
|
+
}
|
|
215
|
+
]
|
|
216
|
+
};
|
|
217
|
+
} catch (error) {
|
|
218
|
+
return {
|
|
219
|
+
content: [
|
|
220
|
+
{
|
|
221
|
+
type: "text",
|
|
222
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
|
|
223
|
+
}
|
|
224
|
+
],
|
|
225
|
+
isError: true
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
this.server.tool(
|
|
231
|
+
"executeOrder",
|
|
232
|
+
"Executes a New Order Single after verification. This is the second step - only call after successful verification.",
|
|
233
|
+
{
|
|
234
|
+
clOrdID: z.string().describe("Client Order ID"),
|
|
235
|
+
handlInst: z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
236
|
+
quantity: z.string().describe("Order quantity"),
|
|
237
|
+
price: z.string().describe("Order price"),
|
|
238
|
+
ordType: z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
239
|
+
side: z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
240
|
+
symbol: z.string().describe("Trading symbol"),
|
|
241
|
+
timeInForce: z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
242
|
+
},
|
|
243
|
+
async (args) => {
|
|
244
|
+
try {
|
|
245
|
+
const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
|
|
246
|
+
if (!verifiedOrder) {
|
|
247
|
+
return {
|
|
248
|
+
content: [
|
|
249
|
+
{
|
|
250
|
+
type: "text",
|
|
251
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
|
|
252
|
+
}
|
|
253
|
+
],
|
|
254
|
+
isError: true
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
if (verifiedOrder.handlInst !== args.handlInst || verifiedOrder.quantity !== Number.parseFloat(args.quantity) || verifiedOrder.price !== Number.parseFloat(args.price) || verifiedOrder.ordType !== args.ordType || verifiedOrder.side !== args.side || verifiedOrder.symbol !== args.symbol || verifiedOrder.timeInForce !== args.timeInForce) {
|
|
258
|
+
return {
|
|
259
|
+
content: [
|
|
260
|
+
{
|
|
261
|
+
type: "text",
|
|
262
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
|
|
263
|
+
}
|
|
264
|
+
],
|
|
265
|
+
isError: true
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
const response = new Promise((resolve) => {
|
|
269
|
+
this.pendingRequests.set(args.clOrdID, resolve);
|
|
270
|
+
});
|
|
271
|
+
const order = this.parser?.createMessage(
|
|
272
|
+
new Field(Fields.MsgType, Messages.NewOrderSingle),
|
|
273
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
274
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
275
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
276
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
277
|
+
new Field(Fields.ClOrdID, args.clOrdID),
|
|
278
|
+
new Field(Fields.Side, args.side),
|
|
279
|
+
new Field(Fields.Symbol, args.symbol),
|
|
280
|
+
new Field(Fields.OrderQty, Number.parseFloat(args.quantity)),
|
|
281
|
+
new Field(Fields.Price, Number.parseFloat(args.price)),
|
|
282
|
+
new Field(Fields.OrdType, args.ordType),
|
|
283
|
+
new Field(Fields.HandlInst, args.handlInst),
|
|
284
|
+
new Field(Fields.TimeInForce, args.timeInForce),
|
|
285
|
+
new Field(Fields.TransactTime, this.parser?.getTimestamp())
|
|
286
|
+
);
|
|
287
|
+
if (!this.parser?.connected) {
|
|
288
|
+
return {
|
|
289
|
+
content: [
|
|
290
|
+
{
|
|
291
|
+
type: "text",
|
|
292
|
+
text: "Error: Not connected. Ignoring message."
|
|
293
|
+
}
|
|
294
|
+
],
|
|
295
|
+
isError: true
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
this.parser?.send(order);
|
|
299
|
+
const fixData = await response;
|
|
300
|
+
this.verifiedOrders.delete(args.clOrdID);
|
|
301
|
+
return {
|
|
302
|
+
content: [
|
|
303
|
+
{
|
|
304
|
+
type: "text",
|
|
305
|
+
text: fixData.messageType === Messages.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
};
|
|
309
|
+
} catch (error) {
|
|
310
|
+
return {
|
|
311
|
+
content: [
|
|
312
|
+
{
|
|
313
|
+
type: "text",
|
|
314
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
|
|
315
|
+
}
|
|
316
|
+
],
|
|
317
|
+
isError: true
|
|
318
|
+
};
|
|
319
|
+
}
|
|
872
320
|
}
|
|
873
321
|
);
|
|
874
|
-
this.server.
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
322
|
+
this.server.tool(
|
|
323
|
+
"marketDataRequest",
|
|
324
|
+
"Sends a request for Market Data with the given symbol. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",
|
|
325
|
+
{
|
|
326
|
+
mdUpdateType: z.enum(["0", "1"]).describe("Market data update type (0=FullRefresh, 1=IncrementalRefresh)"),
|
|
327
|
+
symbols: z.array(z.string()).min(1).describe("Array of trading symbols"),
|
|
328
|
+
mdReqID: z.string().describe("Market data request ID"),
|
|
329
|
+
subscriptionRequestType: z.enum(["0", "1", "2"]).describe("Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)"),
|
|
330
|
+
mdEntryTypes: z.array(z.string()).min(1).describe("Array of market data entry types (0=Bid, 1=Offer, 2=Trade, etc.)")
|
|
331
|
+
},
|
|
332
|
+
async (args) => {
|
|
333
|
+
try {
|
|
334
|
+
const response = new Promise((resolve) => {
|
|
335
|
+
this.pendingRequests.set(args.mdReqID, resolve);
|
|
336
|
+
});
|
|
337
|
+
const messageFields = [
|
|
338
|
+
new Field(Fields.MsgType, Messages.MarketDataRequest),
|
|
339
|
+
new Field(Fields.SenderCompID, this.parser?.sender),
|
|
340
|
+
new Field(Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
341
|
+
new Field(Fields.TargetCompID, this.parser?.target),
|
|
342
|
+
new Field(Fields.SendingTime, this.parser?.getTimestamp()),
|
|
343
|
+
new Field(Fields.MDReqID, args.mdReqID),
|
|
344
|
+
new Field(Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
345
|
+
new Field(Fields.MarketDepth, 0),
|
|
346
|
+
new Field(Fields.MDUpdateType, args.mdUpdateType)
|
|
347
|
+
];
|
|
348
|
+
messageFields.push(new Field(Fields.NoRelatedSym, args.symbols.length));
|
|
349
|
+
args.symbols.forEach((symbol) => {
|
|
350
|
+
messageFields.push(new Field(Fields.Symbol, symbol));
|
|
351
|
+
});
|
|
352
|
+
messageFields.push(new Field(Fields.NoMDEntryTypes, args.mdEntryTypes.length));
|
|
353
|
+
args.mdEntryTypes.forEach((entryType) => {
|
|
354
|
+
messageFields.push(new Field(Fields.MDEntryType, entryType));
|
|
355
|
+
});
|
|
356
|
+
const mdr = this.parser?.createMessage(...messageFields);
|
|
357
|
+
if (!this.parser?.connected) {
|
|
358
|
+
return {
|
|
359
|
+
content: [
|
|
360
|
+
{
|
|
361
|
+
type: "text",
|
|
362
|
+
text: "Error: Not connected. Ignoring message."
|
|
363
|
+
}
|
|
364
|
+
],
|
|
365
|
+
isError: true
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
this.parser?.send(mdr);
|
|
369
|
+
const fixData = await response;
|
|
370
|
+
return {
|
|
371
|
+
content: [
|
|
372
|
+
{
|
|
373
|
+
type: "text",
|
|
374
|
+
text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
375
|
+
}
|
|
376
|
+
]
|
|
377
|
+
};
|
|
378
|
+
} catch (error) {
|
|
895
379
|
return {
|
|
896
380
|
content: [
|
|
897
381
|
{
|
|
898
382
|
type: "text",
|
|
899
|
-
text: `
|
|
900
|
-
uri: name
|
|
383
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
901
384
|
}
|
|
902
385
|
],
|
|
903
386
|
isError: true
|
|
904
387
|
};
|
|
905
388
|
}
|
|
906
|
-
|
|
389
|
+
}
|
|
390
|
+
);
|
|
391
|
+
this.server.resource(
|
|
392
|
+
"greeting-resource",
|
|
393
|
+
"https://example.com/greetings/default",
|
|
394
|
+
{ mimeType: "text/plain" },
|
|
395
|
+
async () => {
|
|
396
|
+
this.parser?.logger.log({
|
|
397
|
+
level: "info",
|
|
398
|
+
message: "MCP Server Resource called: greeting-resource"
|
|
399
|
+
});
|
|
400
|
+
return {
|
|
401
|
+
contents: [
|
|
402
|
+
{
|
|
403
|
+
uri: "https://example.com/greetings/default",
|
|
404
|
+
text: "Hello, world!"
|
|
405
|
+
}
|
|
406
|
+
]
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
);
|
|
410
|
+
this.server.resource(
|
|
411
|
+
"stockGraph",
|
|
412
|
+
new ResourceTemplate("stock://{symbol}", { list: void 0 }),
|
|
413
|
+
async (uri, variables) => {
|
|
414
|
+
this.parser?.logger.log({
|
|
415
|
+
level: "info",
|
|
416
|
+
message: "MCP Server Resource called: stockGraph"
|
|
417
|
+
});
|
|
418
|
+
const symbol = String(variables.symbol);
|
|
419
|
+
const priceHistory = this.marketDataPrices.get(symbol) || [];
|
|
420
|
+
if (priceHistory.length === 0) {
|
|
421
|
+
return {
|
|
422
|
+
contents: [
|
|
423
|
+
{
|
|
424
|
+
uri: uri.href,
|
|
425
|
+
text: `No price data available for ${symbol}`
|
|
426
|
+
}
|
|
427
|
+
]
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
const width = 600;
|
|
431
|
+
const height = 300;
|
|
432
|
+
const padding = 40;
|
|
433
|
+
const xScale = (width - 2 * padding) / (priceHistory.length - 1);
|
|
434
|
+
const yMin = Math.min(...priceHistory.map((d) => d.price));
|
|
435
|
+
const yMax = Math.max(...priceHistory.map((d) => d.price));
|
|
436
|
+
const yScale = (height - 2 * padding) / (yMax - yMin);
|
|
437
|
+
const points = priceHistory.map((d, i) => {
|
|
438
|
+
const x = padding + i * xScale;
|
|
439
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
440
|
+
return `${x},${y}`;
|
|
441
|
+
}).join(" L ");
|
|
442
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
443
|
+
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
|
444
|
+
<!-- Background -->
|
|
445
|
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
|
446
|
+
|
|
447
|
+
<!-- Grid lines -->
|
|
448
|
+
<g stroke="#e9ecef" stroke-width="1">
|
|
449
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
450
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
451
|
+
return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
|
|
452
|
+
}).join("\n")}
|
|
453
|
+
</g>
|
|
454
|
+
|
|
455
|
+
<!-- Price line -->
|
|
456
|
+
<path d="M ${points}"
|
|
457
|
+
fill="none"
|
|
458
|
+
stroke="#007bff"
|
|
459
|
+
stroke-width="2"/>
|
|
460
|
+
|
|
461
|
+
<!-- Data points -->
|
|
462
|
+
${priceHistory.map((d, i) => {
|
|
463
|
+
const x = padding + i * xScale;
|
|
464
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
465
|
+
return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
|
|
466
|
+
}).join("\n")}
|
|
467
|
+
|
|
468
|
+
<!-- Labels -->
|
|
469
|
+
<g font-family="Arial" font-size="12" fill="#495057">
|
|
470
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
471
|
+
const x = padding + (width - 2 * padding) * i / 4;
|
|
472
|
+
const index = Math.floor((priceHistory.length - 1) * i / 4);
|
|
473
|
+
const timestamp = new Date(priceHistory[index].timestamp).toLocaleTimeString();
|
|
474
|
+
return `<text x="${x + padding}" y="${height - padding + 20}" text-anchor="middle">${timestamp}</text>`;
|
|
475
|
+
}).join("\n")}
|
|
476
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
477
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
478
|
+
const price = yMax - (yMax - yMin) * i / 4;
|
|
479
|
+
return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
|
|
480
|
+
}).join("\n")}
|
|
481
|
+
</g>
|
|
482
|
+
|
|
483
|
+
<!-- Title -->
|
|
484
|
+
<text x="${width / 2}" y="${padding / 2}"
|
|
485
|
+
font-family="Arial" font-size="16" font-weight="bold"
|
|
486
|
+
text-anchor="middle" fill="#212529">
|
|
487
|
+
${symbol} - Price Chart (${priceHistory.length} points)
|
|
488
|
+
</text>
|
|
489
|
+
</svg>`;
|
|
907
490
|
return {
|
|
908
|
-
|
|
909
|
-
|
|
491
|
+
contents: [
|
|
492
|
+
{
|
|
493
|
+
uri: uri.href,
|
|
494
|
+
text: svg
|
|
495
|
+
}
|
|
496
|
+
]
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
);
|
|
500
|
+
this.server.resource(
|
|
501
|
+
"stockPriceHistory",
|
|
502
|
+
new ResourceTemplate("price-history://{symbol}", { list: void 0 }),
|
|
503
|
+
async (uri, variables) => {
|
|
504
|
+
this.parser?.logger.log({
|
|
505
|
+
level: "info",
|
|
506
|
+
message: "MCP Server Resource called: stockPriceHistory"
|
|
507
|
+
});
|
|
508
|
+
const symbol = String(variables.symbol);
|
|
509
|
+
const priceHistory = this.marketDataPrices.get(symbol) || [];
|
|
510
|
+
return {
|
|
511
|
+
contents: [
|
|
512
|
+
{
|
|
513
|
+
uri: uri.href,
|
|
514
|
+
text: JSON.stringify(
|
|
515
|
+
{
|
|
516
|
+
symbol,
|
|
517
|
+
count: priceHistory.length,
|
|
518
|
+
prices: priceHistory.map((point) => ({
|
|
519
|
+
timestamp: new Date(point.timestamp).toISOString(),
|
|
520
|
+
price: point.price
|
|
521
|
+
}))
|
|
522
|
+
},
|
|
523
|
+
null,
|
|
524
|
+
2
|
|
525
|
+
)
|
|
526
|
+
}
|
|
527
|
+
]
|
|
910
528
|
};
|
|
911
529
|
}
|
|
912
530
|
);
|