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