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