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