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