fixparser-plugin-mcp 9.1.7-8db521e7 → 9.1.7-9a071f36
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 +530 -587
- package/build/cjs/MCPLocal.js.map +2 -2
- package/build/esm/MCPLocal.mjs +530 -593
- package/build/esm/MCPLocal.mjs.map +2 -2
- package/build-examples/cjs/example_mcp_local.js +52 -4
- package/build-examples/cjs/example_mcp_local.js.map +3 -3
- package/build-examples/esm/example_mcp_local.mjs +52 -4
- package/build-examples/esm/example_mcp_local.mjs.map +3 -3
- package/package.json +4 -5
- package/types/MCPLocal.d.ts +1 -0
package/build/cjs/MCPLocal.js
CHANGED
|
@@ -23,177 +23,13 @@ __export(MCPLocal_exports, {
|
|
|
23
23
|
MCPLocal: () => MCPLocal
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(MCPLocal_exports);
|
|
26
|
-
var
|
|
26
|
+
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
27
27
|
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
28
|
-
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
29
28
|
var import_fixparser = require("fixparser");
|
|
30
|
-
var
|
|
31
|
-
type: "object",
|
|
32
|
-
properties: {
|
|
33
|
-
fixString: {
|
|
34
|
-
type: "string",
|
|
35
|
-
description: "FIX message string to parse"
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
required: ["fixString"]
|
|
39
|
-
};
|
|
40
|
-
var parseToJSONInputSchema = {
|
|
41
|
-
type: "object",
|
|
42
|
-
properties: {
|
|
43
|
-
fixString: {
|
|
44
|
-
type: "string",
|
|
45
|
-
description: "FIX message string to parse"
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
required: ["fixString"]
|
|
49
|
-
};
|
|
50
|
-
var newOrderSingleInputSchema = {
|
|
51
|
-
type: "object",
|
|
52
|
-
properties: {
|
|
53
|
-
clOrdID: {
|
|
54
|
-
type: "string",
|
|
55
|
-
description: "Client Order ID"
|
|
56
|
-
},
|
|
57
|
-
handlInst: {
|
|
58
|
-
type: "string",
|
|
59
|
-
enum: ["1", "2", "3"],
|
|
60
|
-
description: 'Handling instruction (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Manual, "2" for Automated, "3" for AutomatedNoIntervention)'
|
|
61
|
-
},
|
|
62
|
-
quantity: {
|
|
63
|
-
type: "number",
|
|
64
|
-
description: "Order quantity"
|
|
65
|
-
},
|
|
66
|
-
price: {
|
|
67
|
-
type: "number",
|
|
68
|
-
description: "Order price"
|
|
69
|
-
},
|
|
70
|
-
ordType: {
|
|
71
|
-
type: "string",
|
|
72
|
-
enum: [
|
|
73
|
-
"1",
|
|
74
|
-
"2",
|
|
75
|
-
"3",
|
|
76
|
-
"4",
|
|
77
|
-
"5",
|
|
78
|
-
"6",
|
|
79
|
-
"7",
|
|
80
|
-
"8",
|
|
81
|
-
"9",
|
|
82
|
-
"A",
|
|
83
|
-
"B",
|
|
84
|
-
"C",
|
|
85
|
-
"D",
|
|
86
|
-
"E",
|
|
87
|
-
"F",
|
|
88
|
-
"G",
|
|
89
|
-
"H",
|
|
90
|
-
"I",
|
|
91
|
-
"J",
|
|
92
|
-
"K",
|
|
93
|
-
"L",
|
|
94
|
-
"M",
|
|
95
|
-
"P",
|
|
96
|
-
"Q",
|
|
97
|
-
"R",
|
|
98
|
-
"S"
|
|
99
|
-
],
|
|
100
|
-
description: 'Order type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Market, "2" for Limit, "3" for Stop)'
|
|
101
|
-
},
|
|
102
|
-
side: {
|
|
103
|
-
type: "string",
|
|
104
|
-
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
105
|
-
description: 'Order side (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "1" for Buy, "2" for Sell, "3" for BuyMinus, "4" for SellPlus, "5" for SellShort, "6" for SellShortExempt, "7" for Undisclosed, "8" for Cross, "9" for CrossShort, "A" for CrossShortExempt, "B" for AsDefined, "C" for Opposite, "D" for Subscribe, "E" for Redeem, "F" for Lend, "G" for Borrow, "H" for SellUndisclosed)'
|
|
106
|
-
},
|
|
107
|
-
symbol: {
|
|
108
|
-
type: "string",
|
|
109
|
-
description: "Trading symbol"
|
|
110
|
-
},
|
|
111
|
-
timeInForce: {
|
|
112
|
-
type: "string",
|
|
113
|
-
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
114
|
-
description: 'Time in force (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Day, "1" for Good Till Cancel, "2" for At Opening, "3" for Immediate or Cancel, "4" for Fill or Kill, "5" for Good Till Crossing, "6" for Good Till Date)'
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
required: ["clOrdID", "quantity", "price", "side", "symbol", "handlInst", "ordType", "timeInForce"]
|
|
118
|
-
};
|
|
119
|
-
var marketDataRequestInputSchema = {
|
|
120
|
-
type: "object",
|
|
121
|
-
properties: {
|
|
122
|
-
mdUpdateType: {
|
|
123
|
-
type: "string",
|
|
124
|
-
enum: ["0", "1"],
|
|
125
|
-
description: 'Market data update type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for FullRefresh, "1" for IncrementalRefresh)'
|
|
126
|
-
},
|
|
127
|
-
symbol: {
|
|
128
|
-
type: "string",
|
|
129
|
-
description: "Trading symbol"
|
|
130
|
-
},
|
|
131
|
-
mdReqID: {
|
|
132
|
-
type: "string",
|
|
133
|
-
description: "Market data request ID"
|
|
134
|
-
},
|
|
135
|
-
subscriptionRequestType: {
|
|
136
|
-
type: "string",
|
|
137
|
-
enum: ["0", "1", "2"],
|
|
138
|
-
description: 'Subscription request type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Snapshot + Updates, "1" for Snapshot, "2" for Unsubscribe)'
|
|
139
|
-
},
|
|
140
|
-
mdEntryType: {
|
|
141
|
-
type: "string",
|
|
142
|
-
enum: [
|
|
143
|
-
"0",
|
|
144
|
-
"1",
|
|
145
|
-
"2",
|
|
146
|
-
"3",
|
|
147
|
-
"4",
|
|
148
|
-
"5",
|
|
149
|
-
"6",
|
|
150
|
-
"7",
|
|
151
|
-
"8",
|
|
152
|
-
"9",
|
|
153
|
-
"A",
|
|
154
|
-
"B",
|
|
155
|
-
"C",
|
|
156
|
-
"D",
|
|
157
|
-
"E",
|
|
158
|
-
"F",
|
|
159
|
-
"G",
|
|
160
|
-
"H",
|
|
161
|
-
"J",
|
|
162
|
-
"K",
|
|
163
|
-
"L",
|
|
164
|
-
"M",
|
|
165
|
-
"N",
|
|
166
|
-
"O",
|
|
167
|
-
"P",
|
|
168
|
-
"Q",
|
|
169
|
-
"S",
|
|
170
|
-
"R",
|
|
171
|
-
"T",
|
|
172
|
-
"U",
|
|
173
|
-
"V",
|
|
174
|
-
"W",
|
|
175
|
-
"X",
|
|
176
|
-
"Y",
|
|
177
|
-
"Z",
|
|
178
|
-
"a",
|
|
179
|
-
"b",
|
|
180
|
-
"c",
|
|
181
|
-
"d",
|
|
182
|
-
"e",
|
|
183
|
-
"g",
|
|
184
|
-
"h",
|
|
185
|
-
"i",
|
|
186
|
-
"t"
|
|
187
|
-
],
|
|
188
|
-
description: 'Market data entry type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for Bid, "1" for Offer, "2" for Trade, "3" for Index Value, "4" for Opening Price)'
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
required: ["symbol", "mdReqID"]
|
|
192
|
-
};
|
|
29
|
+
var import_zod = require("zod");
|
|
193
30
|
var MCPLocal = class {
|
|
194
|
-
// private logger: Logger | undefined;
|
|
195
31
|
parser;
|
|
196
|
-
server = new
|
|
32
|
+
server = new import_mcp.McpServer(
|
|
197
33
|
{
|
|
198
34
|
name: "fixparser",
|
|
199
35
|
version: "1.0.0"
|
|
@@ -209,6 +45,7 @@ var MCPLocal = class {
|
|
|
209
45
|
transport = new import_stdio.StdioServerTransport();
|
|
210
46
|
onReady = void 0;
|
|
211
47
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
48
|
+
verifiedOrders = /* @__PURE__ */ new Map();
|
|
212
49
|
constructor({ logger, onReady }) {
|
|
213
50
|
if (onReady) this.onReady = onReady;
|
|
214
51
|
}
|
|
@@ -217,26 +54,22 @@ var MCPLocal = class {
|
|
|
217
54
|
this.parser.addOnMessageCallback((message) => {
|
|
218
55
|
const msgType = message.messageType;
|
|
219
56
|
if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport || msgType === import_fixparser.Messages.Reject) {
|
|
220
|
-
|
|
221
|
-
if (
|
|
222
|
-
const
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
callback(message);
|
|
237
|
-
this.pendingRequests.delete(String(id));
|
|
238
|
-
}
|
|
239
|
-
}
|
|
57
|
+
let id;
|
|
58
|
+
if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
|
|
59
|
+
const mdReqID = message.getField(import_fixparser.Fields.MDReqID);
|
|
60
|
+
if (mdReqID) id = String(mdReqID.value);
|
|
61
|
+
} else if (msgType === import_fixparser.Messages.ExecutionReport) {
|
|
62
|
+
const clOrdID = message.getField(import_fixparser.Fields.ClOrdID);
|
|
63
|
+
if (clOrdID) id = String(clOrdID.value);
|
|
64
|
+
} else if (msgType === import_fixparser.Messages.Reject) {
|
|
65
|
+
const refSeqNum = message.getField(import_fixparser.Fields.RefSeqNum);
|
|
66
|
+
if (refSeqNum) id = String(refSeqNum.value);
|
|
67
|
+
}
|
|
68
|
+
if (id) {
|
|
69
|
+
const callback = this.pendingRequests.get(id);
|
|
70
|
+
if (callback) {
|
|
71
|
+
callback(message);
|
|
72
|
+
this.pendingRequests.delete(id);
|
|
240
73
|
}
|
|
241
74
|
}
|
|
242
75
|
}
|
|
@@ -254,455 +87,565 @@ var MCPLocal = class {
|
|
|
254
87
|
if (!this.server) {
|
|
255
88
|
return;
|
|
256
89
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
} else if (prop.default !== void 0) {
|
|
268
|
-
result[key] = prop.default;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return result;
|
|
272
|
-
};
|
|
273
|
-
this.server.setRequestHandler(import_types.ListResourcesRequestSchema, async () => {
|
|
274
|
-
return {
|
|
275
|
-
resources: []
|
|
276
|
-
};
|
|
277
|
-
});
|
|
278
|
-
this.server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
|
|
279
|
-
return {
|
|
280
|
-
tools: [
|
|
281
|
-
{
|
|
282
|
-
name: "parse",
|
|
283
|
-
description: "Parses a FIX message and describes it in plain language",
|
|
284
|
-
inputSchema: parseInputSchema
|
|
285
|
-
},
|
|
286
|
-
{
|
|
287
|
-
name: "parseToJSON",
|
|
288
|
-
description: "Parses a FIX message into JSON",
|
|
289
|
-
inputSchema: parseToJSONInputSchema
|
|
290
|
-
},
|
|
291
|
-
{
|
|
292
|
-
name: "newOrderSingle",
|
|
293
|
-
description: "Creates and sends a New Order Single",
|
|
294
|
-
inputSchema: newOrderSingleInputSchema
|
|
295
|
-
},
|
|
296
|
-
{
|
|
297
|
-
name: "marketDataRequest",
|
|
298
|
-
description: "Sends a request for Market Data with the given symbol",
|
|
299
|
-
inputSchema: marketDataRequestInputSchema
|
|
300
|
-
}
|
|
301
|
-
]
|
|
302
|
-
};
|
|
303
|
-
});
|
|
304
|
-
this.server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
|
|
305
|
-
const { name, arguments: args } = request.params;
|
|
306
|
-
switch (name) {
|
|
307
|
-
case "parse": {
|
|
308
|
-
try {
|
|
309
|
-
const { fixString } = validateArgs(args, parseInputSchema);
|
|
310
|
-
const parsedMessage = this.parser?.parse(fixString);
|
|
311
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
312
|
-
return {
|
|
313
|
-
isError: true,
|
|
314
|
-
content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
|
|
315
|
-
};
|
|
316
|
-
}
|
|
90
|
+
this.server.tool(
|
|
91
|
+
"parse",
|
|
92
|
+
"Parses a FIX message and describes it in plain language",
|
|
93
|
+
{
|
|
94
|
+
fixString: import_zod.z.string().describe("FIX message string to parse")
|
|
95
|
+
},
|
|
96
|
+
async (args) => {
|
|
97
|
+
try {
|
|
98
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
99
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
317
100
|
return {
|
|
318
|
-
content: [
|
|
319
|
-
|
|
320
|
-
type: "text",
|
|
321
|
-
text: `${parsedMessage[0].description}
|
|
322
|
-
${parsedMessage[0].messageTypeDescription}`
|
|
323
|
-
}
|
|
324
|
-
]
|
|
325
|
-
};
|
|
326
|
-
} catch (error) {
|
|
327
|
-
return {
|
|
328
|
-
isError: true,
|
|
329
|
-
content: [
|
|
330
|
-
{
|
|
331
|
-
type: "text",
|
|
332
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
333
|
-
}
|
|
334
|
-
]
|
|
101
|
+
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
102
|
+
isError: true
|
|
335
103
|
};
|
|
336
104
|
}
|
|
105
|
+
return {
|
|
106
|
+
content: [
|
|
107
|
+
{
|
|
108
|
+
type: "text",
|
|
109
|
+
text: `${parsedMessage[0].description}
|
|
110
|
+
${parsedMessage[0].messageTypeDescription}`
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
};
|
|
114
|
+
} catch (error) {
|
|
115
|
+
return {
|
|
116
|
+
content: [
|
|
117
|
+
{
|
|
118
|
+
type: "text",
|
|
119
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
isError: true
|
|
123
|
+
};
|
|
337
124
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
{
|
|
351
|
-
type: "text",
|
|
352
|
-
text: `${parsedMessage[0].toFIXJSON()}`
|
|
353
|
-
}
|
|
354
|
-
]
|
|
355
|
-
};
|
|
356
|
-
} catch (error) {
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
this.server.tool(
|
|
128
|
+
"parseToJSON",
|
|
129
|
+
"Parses a FIX message into JSON",
|
|
130
|
+
{
|
|
131
|
+
fixString: import_zod.z.string().describe("FIX message string to parse")
|
|
132
|
+
},
|
|
133
|
+
async (args) => {
|
|
134
|
+
try {
|
|
135
|
+
const parsedMessage = this.parser?.parse(args.fixString);
|
|
136
|
+
if (!parsedMessage || parsedMessage.length === 0) {
|
|
357
137
|
return {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
{
|
|
361
|
-
type: "text",
|
|
362
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
363
|
-
}
|
|
364
|
-
]
|
|
138
|
+
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
139
|
+
isError: true
|
|
365
140
|
};
|
|
366
141
|
}
|
|
142
|
+
return {
|
|
143
|
+
content: [
|
|
144
|
+
{
|
|
145
|
+
type: "text",
|
|
146
|
+
text: `${parsedMessage[0].toFIXJSON()}`
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
};
|
|
150
|
+
} catch (error) {
|
|
151
|
+
return {
|
|
152
|
+
content: [
|
|
153
|
+
{
|
|
154
|
+
type: "text",
|
|
155
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
isError: true
|
|
159
|
+
};
|
|
367
160
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
)
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
this.server.tool(
|
|
164
|
+
"verifyOrder",
|
|
165
|
+
"Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
|
|
166
|
+
{
|
|
167
|
+
clOrdID: import_zod.z.string().describe("Client Order ID"),
|
|
168
|
+
handlInst: import_zod.z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
169
|
+
quantity: import_zod.z.string().describe("Order quantity"),
|
|
170
|
+
price: import_zod.z.string().describe("Order price"),
|
|
171
|
+
ordType: import_zod.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
172
|
+
side: import_zod.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
173
|
+
symbol: import_zod.z.string().describe("Trading symbol"),
|
|
174
|
+
timeInForce: import_zod.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
175
|
+
},
|
|
176
|
+
async (args) => {
|
|
177
|
+
try {
|
|
178
|
+
this.verifiedOrders.set(args.clOrdID, {
|
|
179
|
+
clOrdID: args.clOrdID,
|
|
180
|
+
handlInst: args.handlInst,
|
|
181
|
+
quantity: Number.parseFloat(args.quantity),
|
|
182
|
+
price: Number.parseFloat(args.price),
|
|
183
|
+
ordType: args.ordType,
|
|
184
|
+
side: args.side,
|
|
185
|
+
symbol: args.symbol,
|
|
186
|
+
timeInForce: args.timeInForce
|
|
187
|
+
});
|
|
188
|
+
return {
|
|
189
|
+
content: [
|
|
190
|
+
{
|
|
191
|
+
type: "text",
|
|
192
|
+
text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
|
|
193
|
+
|
|
194
|
+
Parameters verified:
|
|
195
|
+
- ClOrdID: ${args.clOrdID}
|
|
196
|
+
- HandlInst: ${args.handlInst}
|
|
197
|
+
- Quantity: ${args.quantity}
|
|
198
|
+
- Price: ${args.price}
|
|
199
|
+
- OrdType: ${args.ordType}
|
|
200
|
+
- Side: ${args.side}
|
|
201
|
+
- Symbol: ${args.symbol}
|
|
202
|
+
- TimeInForce: ${args.timeInForce}
|
|
203
|
+
|
|
204
|
+
To execute this order, call the executeOrder tool with these exact same parameters.`
|
|
205
|
+
}
|
|
206
|
+
]
|
|
207
|
+
};
|
|
208
|
+
} catch (error) {
|
|
209
|
+
return {
|
|
210
|
+
content: [
|
|
211
|
+
{
|
|
212
|
+
type: "text",
|
|
213
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
|
|
214
|
+
}
|
|
215
|
+
],
|
|
216
|
+
isError: true
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
this.server.tool(
|
|
222
|
+
"executeOrder",
|
|
223
|
+
"Executes a New Order Single after verification. This is the second step - only call after successful verification.",
|
|
224
|
+
{
|
|
225
|
+
clOrdID: import_zod.z.string().describe("Client Order ID"),
|
|
226
|
+
handlInst: import_zod.z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
227
|
+
quantity: import_zod.z.string().describe("Order quantity"),
|
|
228
|
+
price: import_zod.z.string().describe("Order price"),
|
|
229
|
+
ordType: import_zod.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
230
|
+
side: import_zod.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
231
|
+
symbol: import_zod.z.string().describe("Trading symbol"),
|
|
232
|
+
timeInForce: import_zod.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
233
|
+
},
|
|
234
|
+
async (args) => {
|
|
235
|
+
try {
|
|
236
|
+
const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
|
|
237
|
+
if (!verifiedOrder) {
|
|
412
238
|
return {
|
|
413
|
-
isError: true,
|
|
414
239
|
content: [
|
|
415
240
|
{
|
|
416
241
|
type: "text",
|
|
417
|
-
text: `Error: ${
|
|
242
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
|
|
418
243
|
}
|
|
419
|
-
]
|
|
244
|
+
],
|
|
245
|
+
isError: true
|
|
420
246
|
};
|
|
421
247
|
}
|
|
422
|
-
|
|
423
|
-
case "marketDataRequest": {
|
|
424
|
-
try {
|
|
425
|
-
const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = validateArgs(
|
|
426
|
-
args,
|
|
427
|
-
marketDataRequestInputSchema
|
|
428
|
-
);
|
|
429
|
-
const response = new Promise((resolve) => {
|
|
430
|
-
this.pendingRequests.set(mdReqID, resolve);
|
|
431
|
-
});
|
|
432
|
-
const marketDataRequest = this.parser?.createMessage(
|
|
433
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
434
|
-
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
|
|
435
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
436
|
-
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
437
|
-
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
438
|
-
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
439
|
-
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, mdUpdateType),
|
|
440
|
-
new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, 1),
|
|
441
|
-
new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
|
|
442
|
-
new import_fixparser.Field(import_fixparser.Fields.MDReqID, mdReqID),
|
|
443
|
-
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, subscriptionRequestType),
|
|
444
|
-
new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
|
|
445
|
-
new import_fixparser.Field(import_fixparser.Fields.MDEntryType, mdEntryType)
|
|
446
|
-
);
|
|
447
|
-
if (!this.parser?.connected) {
|
|
448
|
-
return {
|
|
449
|
-
isError: true,
|
|
450
|
-
content: [
|
|
451
|
-
{
|
|
452
|
-
type: "text",
|
|
453
|
-
text: "Error: Not connected. Ignoring message."
|
|
454
|
-
}
|
|
455
|
-
]
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
this.parser?.send(marketDataRequest);
|
|
459
|
-
const fixData = await response;
|
|
248
|
+
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) {
|
|
460
249
|
return {
|
|
461
250
|
content: [
|
|
462
251
|
{
|
|
463
252
|
type: "text",
|
|
464
|
-
text:
|
|
253
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
|
|
465
254
|
}
|
|
466
|
-
]
|
|
255
|
+
],
|
|
256
|
+
isError: true
|
|
467
257
|
};
|
|
468
|
-
}
|
|
258
|
+
}
|
|
259
|
+
const response = new Promise((resolve) => {
|
|
260
|
+
this.pendingRequests.set(args.clOrdID, resolve);
|
|
261
|
+
});
|
|
262
|
+
const order = this.parser?.createMessage(
|
|
263
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
|
|
264
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
265
|
+
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
|
|
266
|
+
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
267
|
+
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
268
|
+
new import_fixparser.Field(import_fixparser.Fields.ClOrdID, args.clOrdID),
|
|
269
|
+
new import_fixparser.Field(import_fixparser.Fields.Side, args.side),
|
|
270
|
+
new import_fixparser.Field(import_fixparser.Fields.Symbol, args.symbol),
|
|
271
|
+
new import_fixparser.Field(import_fixparser.Fields.OrderQty, Number.parseFloat(args.quantity)),
|
|
272
|
+
new import_fixparser.Field(import_fixparser.Fields.Price, Number.parseFloat(args.price)),
|
|
273
|
+
new import_fixparser.Field(import_fixparser.Fields.OrdType, args.ordType),
|
|
274
|
+
new import_fixparser.Field(import_fixparser.Fields.HandlInst, args.handlInst),
|
|
275
|
+
new import_fixparser.Field(import_fixparser.Fields.TimeInForce, args.timeInForce),
|
|
276
|
+
new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
|
|
277
|
+
);
|
|
278
|
+
if (!this.parser?.connected) {
|
|
469
279
|
return {
|
|
470
|
-
isError: true,
|
|
471
280
|
content: [
|
|
472
281
|
{
|
|
473
282
|
type: "text",
|
|
474
|
-
text:
|
|
283
|
+
text: "Error: Not connected. Ignoring message."
|
|
475
284
|
}
|
|
476
|
-
]
|
|
285
|
+
],
|
|
286
|
+
isError: true
|
|
477
287
|
};
|
|
478
288
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
});
|
|
484
|
-
this.server.setRequestHandler(import_types.ListPromptsRequestSchema, async () => {
|
|
485
|
-
return {
|
|
486
|
-
prompts: [
|
|
487
|
-
{
|
|
488
|
-
name: "parse",
|
|
489
|
-
description: "Parses a FIX message and describes it in plain language",
|
|
490
|
-
arguments: [
|
|
491
|
-
{
|
|
492
|
-
name: "fixString",
|
|
493
|
-
description: "FIX message string to parse",
|
|
494
|
-
required: true
|
|
495
|
-
}
|
|
496
|
-
]
|
|
497
|
-
},
|
|
498
|
-
{
|
|
499
|
-
name: "parseToJSON",
|
|
500
|
-
description: "Parses a FIX message into JSON",
|
|
501
|
-
arguments: [
|
|
502
|
-
{
|
|
503
|
-
name: "fixString",
|
|
504
|
-
description: "FIX message string to parse",
|
|
505
|
-
required: true
|
|
506
|
-
}
|
|
507
|
-
]
|
|
508
|
-
},
|
|
509
|
-
{
|
|
510
|
-
name: "newOrderSingle",
|
|
511
|
-
description: "Creates and sends a New Order Single. IMPORTANT: All parameters must be explicitly provided by the user - no assumptions will be made.",
|
|
512
|
-
arguments: [
|
|
513
|
-
{
|
|
514
|
-
name: "clOrdID",
|
|
515
|
-
description: "Client Order ID",
|
|
516
|
-
required: true
|
|
517
|
-
},
|
|
518
|
-
{
|
|
519
|
-
name: "handlInst",
|
|
520
|
-
description: "Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)",
|
|
521
|
-
required: true
|
|
522
|
-
},
|
|
523
|
-
{
|
|
524
|
-
name: "quantity",
|
|
525
|
-
description: "Order quantity",
|
|
526
|
-
required: true
|
|
527
|
-
},
|
|
528
|
-
{
|
|
529
|
-
name: "price",
|
|
530
|
-
description: "Order price",
|
|
531
|
-
required: true
|
|
532
|
-
},
|
|
533
|
-
{
|
|
534
|
-
name: "ordType",
|
|
535
|
-
description: "Order type (1=Market, 2=Limit, 3=Stop)",
|
|
536
|
-
required: true
|
|
537
|
-
},
|
|
538
|
-
{
|
|
539
|
-
name: "side",
|
|
540
|
-
description: "Order 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)",
|
|
541
|
-
required: true
|
|
542
|
-
},
|
|
543
|
-
{
|
|
544
|
-
name: "symbol",
|
|
545
|
-
description: "Trading symbol",
|
|
546
|
-
required: true
|
|
547
|
-
},
|
|
548
|
-
{
|
|
549
|
-
name: "timeInForce",
|
|
550
|
-
description: "Time in force (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)",
|
|
551
|
-
required: true
|
|
552
|
-
}
|
|
553
|
-
]
|
|
554
|
-
},
|
|
555
|
-
{
|
|
556
|
-
name: "marketDataRequest",
|
|
557
|
-
description: "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.",
|
|
558
|
-
arguments: [
|
|
559
|
-
{
|
|
560
|
-
name: "mdUpdateType",
|
|
561
|
-
description: "Market data update type (0=FullRefresh, 1=IncrementalRefresh)",
|
|
562
|
-
required: true
|
|
563
|
-
},
|
|
564
|
-
{
|
|
565
|
-
name: "symbol",
|
|
566
|
-
description: "Trading symbol",
|
|
567
|
-
required: true
|
|
568
|
-
},
|
|
569
|
-
{
|
|
570
|
-
name: "mdReqID",
|
|
571
|
-
description: "Market data request ID",
|
|
572
|
-
required: true
|
|
573
|
-
},
|
|
574
|
-
{
|
|
575
|
-
name: "subscriptionRequestType",
|
|
576
|
-
description: "Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)",
|
|
577
|
-
required: true
|
|
578
|
-
},
|
|
579
|
-
{
|
|
580
|
-
name: "mdEntryType",
|
|
581
|
-
description: "Market data entry type (0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price)",
|
|
582
|
-
required: true
|
|
583
|
-
}
|
|
584
|
-
]
|
|
585
|
-
}
|
|
586
|
-
]
|
|
587
|
-
};
|
|
588
|
-
});
|
|
589
|
-
this.server.setRequestHandler(import_types.GetPromptRequestSchema, async (request) => {
|
|
590
|
-
const { name, arguments: args } = request.params;
|
|
591
|
-
switch (name) {
|
|
592
|
-
case "parse": {
|
|
593
|
-
const fixString = args?.fixString || "";
|
|
289
|
+
this.parser?.send(order);
|
|
290
|
+
const fixData = await response;
|
|
291
|
+
this.verifiedOrders.delete(args.clOrdID);
|
|
594
292
|
return {
|
|
595
|
-
|
|
293
|
+
content: [
|
|
596
294
|
{
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
type: "text",
|
|
600
|
-
text: `Please parse and explain this FIX message: ${fixString}`
|
|
601
|
-
}
|
|
295
|
+
type: "text",
|
|
296
|
+
text: fixData.messageType === import_fixparser.Messages.Reject ? `Reject message for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${args.clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
602
297
|
}
|
|
603
298
|
]
|
|
604
299
|
};
|
|
605
|
-
}
|
|
606
|
-
case "parseToJSON": {
|
|
607
|
-
const fixString = args?.fixString || "";
|
|
300
|
+
} catch (error) {
|
|
608
301
|
return {
|
|
609
|
-
|
|
302
|
+
content: [
|
|
610
303
|
{
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
type: "text",
|
|
614
|
-
text: `Please parse the FIX message to JSON: ${fixString}`
|
|
615
|
-
}
|
|
304
|
+
type: "text",
|
|
305
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
|
|
616
306
|
}
|
|
617
|
-
]
|
|
307
|
+
],
|
|
308
|
+
isError: true
|
|
618
309
|
};
|
|
619
310
|
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
311
|
+
}
|
|
312
|
+
);
|
|
313
|
+
this.server.tool(
|
|
314
|
+
"marketDataRequest",
|
|
315
|
+
"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.",
|
|
316
|
+
{
|
|
317
|
+
mdUpdateType: import_zod.z.enum(["0", "1"]).describe("Market data update type (0=FullRefresh, 1=IncrementalRefresh)"),
|
|
318
|
+
symbol: import_zod.z.string().describe("Trading symbol"),
|
|
319
|
+
mdReqID: import_zod.z.string().describe("Market data request ID"),
|
|
320
|
+
subscriptionRequestType: import_zod.z.enum(["0", "1", "2"]).describe("Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)"),
|
|
321
|
+
mdEntryType: import_zod.z.string().describe("Market data entry type (0=Bid, 1=Offer, 2=Trade, etc.)")
|
|
322
|
+
},
|
|
323
|
+
async (args) => {
|
|
324
|
+
try {
|
|
325
|
+
const response = new Promise((resolve) => {
|
|
326
|
+
this.pendingRequests.set(args.mdReqID, resolve);
|
|
327
|
+
});
|
|
328
|
+
const marketDataRequest = this.parser?.createMessage(
|
|
329
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
330
|
+
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
|
|
331
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
332
|
+
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
333
|
+
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
334
|
+
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
335
|
+
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType),
|
|
336
|
+
new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, 1),
|
|
337
|
+
new import_fixparser.Field(import_fixparser.Fields.Symbol, args.symbol),
|
|
338
|
+
new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
|
|
339
|
+
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
|
|
340
|
+
new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
|
|
341
|
+
new import_fixparser.Field(import_fixparser.Fields.MDEntryType, args.mdEntryType)
|
|
342
|
+
);
|
|
343
|
+
if (!this.parser?.connected) {
|
|
344
|
+
return {
|
|
345
|
+
content: [
|
|
346
|
+
{
|
|
627
347
|
type: "text",
|
|
628
|
-
text:
|
|
629
|
-
"You are an AI assistant that helps users create FIX New Order Single messages.",
|
|
630
|
-
"You must **first verify** that all required fields are provided:",
|
|
631
|
-
"- ClOrdID (Client Order ID)",
|
|
632
|
-
"- HandlInst (1=Manual, 2=Automated, 3=AutomatedNoIntervention)",
|
|
633
|
-
"- Quantity (Order quantity)",
|
|
634
|
-
"- Price (Order price)",
|
|
635
|
-
"- OrdType (1=Market, 2=Limit, 3=Stop)",
|
|
636
|
-
"- 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)",
|
|
637
|
-
"- Symbol (Trading symbol)",
|
|
638
|
-
"- 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)",
|
|
639
|
-
"",
|
|
640
|
-
"Only when all fields are present and valid, respond with:",
|
|
641
|
-
"`VERIFICATION: All parameters valid. Ready to proceed.`",
|
|
642
|
-
"",
|
|
643
|
-
"Otherwise, list the missing or invalid ones.",
|
|
644
|
-
"",
|
|
645
|
-
"Do not create the FIX message until verification is complete.",
|
|
646
|
-
"",
|
|
647
|
-
"Current parameters:",
|
|
648
|
-
`- ClOrdID: ${clOrdID}`,
|
|
649
|
-
`- HandlInst: ${handlInst}`,
|
|
650
|
-
`- Quantity: ${quantity}`,
|
|
651
|
-
`- Price: ${price}`,
|
|
652
|
-
`- OrdType: ${ordType}`,
|
|
653
|
-
`- Side: ${side}`,
|
|
654
|
-
`- Symbol: ${symbol}`,
|
|
655
|
-
`- TimeInForce: ${timeInForce}`,
|
|
656
|
-
"",
|
|
657
|
-
"IMPORTANT: The response will be either:",
|
|
658
|
-
"1. An Execution Report (MsgType=8) if the order was successfully placed",
|
|
659
|
-
"2. A Reject message (MsgType=3) if the order failed to execute (e.g., due to missing or invalid parameters)"
|
|
660
|
-
].join("\n")
|
|
348
|
+
text: "Error: Not connected. Ignoring message."
|
|
661
349
|
}
|
|
350
|
+
],
|
|
351
|
+
isError: true
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
this.parser?.send(marketDataRequest);
|
|
355
|
+
const fixData = await response;
|
|
356
|
+
return {
|
|
357
|
+
content: [
|
|
358
|
+
{
|
|
359
|
+
type: "text",
|
|
360
|
+
text: `Market data for ${args.symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
662
361
|
}
|
|
663
362
|
]
|
|
664
363
|
};
|
|
665
|
-
}
|
|
666
|
-
case "marketDataRequest": {
|
|
667
|
-
const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = args || {};
|
|
364
|
+
} catch (error) {
|
|
668
365
|
return {
|
|
669
|
-
|
|
366
|
+
content: [
|
|
670
367
|
{
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
type: "text",
|
|
674
|
-
text: [
|
|
675
|
-
"You are an AI assistant that helps users create FIX Market Data Request messages.",
|
|
676
|
-
"You must **first verify** that all required fields are provided:",
|
|
677
|
-
"- MDUpdateType (0=FullRefresh, 1=IncrementalRefresh)",
|
|
678
|
-
"- Symbol (Trading symbol)",
|
|
679
|
-
"- MDReqID (Market data request ID)",
|
|
680
|
-
"- SubscriptionRequestType (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)",
|
|
681
|
-
"- MDEntryType (0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price)",
|
|
682
|
-
"",
|
|
683
|
-
"Only when all fields are present and valid, respond with:",
|
|
684
|
-
"`VERIFICATION: All parameters valid. Ready to proceed.`",
|
|
685
|
-
"",
|
|
686
|
-
"Otherwise, list the missing or invalid ones.",
|
|
687
|
-
"",
|
|
688
|
-
"Do not create the FIX message until verification is complete.",
|
|
689
|
-
"",
|
|
690
|
-
"Current parameters:",
|
|
691
|
-
`- MDUpdateType: ${mdUpdateType}`,
|
|
692
|
-
`- Symbol: ${symbol}`,
|
|
693
|
-
`- MDReqID: ${mdReqID}`,
|
|
694
|
-
`- SubscriptionRequestType: ${subscriptionRequestType}`,
|
|
695
|
-
`- MDEntryType: ${mdEntryType}`
|
|
696
|
-
].join("\n")
|
|
697
|
-
}
|
|
368
|
+
type: "text",
|
|
369
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
698
370
|
}
|
|
699
|
-
]
|
|
371
|
+
],
|
|
372
|
+
isError: true
|
|
700
373
|
};
|
|
701
374
|
}
|
|
702
|
-
default:
|
|
703
|
-
throw new Error(`Unknown prompt: ${name}`);
|
|
704
375
|
}
|
|
705
|
-
|
|
376
|
+
);
|
|
377
|
+
this.server.prompt(
|
|
378
|
+
"parse",
|
|
379
|
+
"Parses a FIX message and describes it in plain language",
|
|
380
|
+
{
|
|
381
|
+
fixString: import_zod.z.string().describe("FIX message string to parse")
|
|
382
|
+
},
|
|
383
|
+
async (args) => {
|
|
384
|
+
return {
|
|
385
|
+
messages: [
|
|
386
|
+
{
|
|
387
|
+
role: "user",
|
|
388
|
+
content: {
|
|
389
|
+
type: "text",
|
|
390
|
+
text: `Please parse and explain this FIX message: ${args.fixString}`
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
]
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
);
|
|
397
|
+
this.server.prompt(
|
|
398
|
+
"parseToJSON",
|
|
399
|
+
"Parses a FIX message into JSON",
|
|
400
|
+
{
|
|
401
|
+
fixString: import_zod.z.string().describe("FIX message string to parse")
|
|
402
|
+
},
|
|
403
|
+
async (args) => {
|
|
404
|
+
return {
|
|
405
|
+
messages: [
|
|
406
|
+
{
|
|
407
|
+
role: "user",
|
|
408
|
+
content: {
|
|
409
|
+
type: "text",
|
|
410
|
+
text: `Please parse the FIX message to JSON: ${args.fixString}`
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
]
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
);
|
|
417
|
+
this.server.prompt(
|
|
418
|
+
"verifyOrder",
|
|
419
|
+
"Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
|
|
420
|
+
{
|
|
421
|
+
clOrdID: import_zod.z.string().describe("Client Order ID"),
|
|
422
|
+
handlInst: import_zod.z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
423
|
+
quantity: import_zod.z.string().describe("Order quantity"),
|
|
424
|
+
price: import_zod.z.string().describe("Order price"),
|
|
425
|
+
ordType: import_zod.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
426
|
+
side: import_zod.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
427
|
+
symbol: import_zod.z.string().describe("Trading symbol"),
|
|
428
|
+
timeInForce: import_zod.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
429
|
+
},
|
|
430
|
+
async (args) => {
|
|
431
|
+
return {
|
|
432
|
+
messages: [
|
|
433
|
+
{
|
|
434
|
+
role: "user",
|
|
435
|
+
content: {
|
|
436
|
+
type: "text",
|
|
437
|
+
text: [
|
|
438
|
+
"You are an AI assistant that helps users verify FIX New Order Single parameters.",
|
|
439
|
+
"This is STEP 1 of 2 - VERIFICATION ONLY. No order will be sent at this stage.",
|
|
440
|
+
"",
|
|
441
|
+
"You must verify that all required fields are provided and valid:",
|
|
442
|
+
"- ClOrdID (Client Order ID)",
|
|
443
|
+
"- HandlInst (1=Manual, 2=Automated, 3=AutomatedNoIntervention)",
|
|
444
|
+
"- Quantity (Order quantity)",
|
|
445
|
+
"- Price (Order price)",
|
|
446
|
+
"- OrdType (1=Market, 2=Limit, 3=Stop)",
|
|
447
|
+
"- 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)",
|
|
448
|
+
"- Symbol (Trading symbol)",
|
|
449
|
+
"- 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)",
|
|
450
|
+
"",
|
|
451
|
+
"Current parameters to verify:",
|
|
452
|
+
`- ClOrdID: ${args.clOrdID}`,
|
|
453
|
+
`- HandlInst: ${args.handlInst}`,
|
|
454
|
+
`- Quantity: ${args.quantity}`,
|
|
455
|
+
`- Price: ${args.price}`,
|
|
456
|
+
`- OrdType: ${args.ordType}`,
|
|
457
|
+
`- Side: ${args.side}`,
|
|
458
|
+
`- Symbol: ${args.symbol}`,
|
|
459
|
+
`- TimeInForce: ${args.timeInForce}`,
|
|
460
|
+
"",
|
|
461
|
+
"If all parameters are valid, respond with:",
|
|
462
|
+
"`VERIFICATION: All parameters valid. Ready to proceed.`",
|
|
463
|
+
"",
|
|
464
|
+
"Otherwise, list the missing or invalid ones.",
|
|
465
|
+
"",
|
|
466
|
+
"IMPORTANT: This is only verification. To actually send the order, the user must call the executeOrder tool with the same parameters."
|
|
467
|
+
].join("\n")
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
]
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
);
|
|
474
|
+
this.server.prompt(
|
|
475
|
+
"executeOrder",
|
|
476
|
+
"Executes a New Order Single after verification. This is the second step - only call after successful verification.",
|
|
477
|
+
{
|
|
478
|
+
clOrdID: import_zod.z.string().describe("Client Order ID"),
|
|
479
|
+
handlInst: import_zod.z.enum(["1", "2", "3"]).describe("Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)"),
|
|
480
|
+
quantity: import_zod.z.string().describe("Order quantity"),
|
|
481
|
+
price: import_zod.z.string().describe("Order price"),
|
|
482
|
+
ordType: import_zod.z.string().describe("Order type (1=Market, 2=Limit, 3=Stop)"),
|
|
483
|
+
side: import_zod.z.string().describe("Order side (1=Buy, 2=Sell, etc.)"),
|
|
484
|
+
symbol: import_zod.z.string().describe("Trading symbol"),
|
|
485
|
+
timeInForce: import_zod.z.string().describe("Time in force (0=Day, 1=Good Till Cancel, etc.)")
|
|
486
|
+
},
|
|
487
|
+
async (args) => {
|
|
488
|
+
return {
|
|
489
|
+
messages: [
|
|
490
|
+
{
|
|
491
|
+
role: "user",
|
|
492
|
+
content: {
|
|
493
|
+
type: "text",
|
|
494
|
+
text: [
|
|
495
|
+
"You are an AI assistant that helps users execute FIX New Order Single messages.",
|
|
496
|
+
"This is STEP 2 of 2 - EXECUTION. This will send the order to the market.",
|
|
497
|
+
"",
|
|
498
|
+
"IMPORTANT: This tool should only be called after successful verification of all parameters.",
|
|
499
|
+
"",
|
|
500
|
+
"Parameters to execute:",
|
|
501
|
+
`- ClOrdID: ${args.clOrdID}`,
|
|
502
|
+
`- HandlInst: ${args.handlInst}`,
|
|
503
|
+
`- Quantity: ${args.quantity}`,
|
|
504
|
+
`- Price: ${args.price}`,
|
|
505
|
+
`- OrdType: ${args.ordType}`,
|
|
506
|
+
`- Side: ${args.side}`,
|
|
507
|
+
`- Symbol: ${args.symbol}`,
|
|
508
|
+
`- TimeInForce: ${args.timeInForce}`,
|
|
509
|
+
"",
|
|
510
|
+
"IMPORTANT: The response will be either:",
|
|
511
|
+
"1. An Execution Report (MsgType=8) if the order was successfully placed",
|
|
512
|
+
"2. A Reject message (MsgType=3) if the order failed to execute (e.g., due to missing or invalid parameters)"
|
|
513
|
+
].join("\n")
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
]
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
);
|
|
520
|
+
this.server.prompt(
|
|
521
|
+
"marketDataRequest",
|
|
522
|
+
"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.",
|
|
523
|
+
{
|
|
524
|
+
mdUpdateType: import_zod.z.enum(["0", "1"]).describe("Market data update type (0=FullRefresh, 1=IncrementalRefresh)"),
|
|
525
|
+
symbol: import_zod.z.string().describe("Trading symbol"),
|
|
526
|
+
mdReqID: import_zod.z.string().describe("Market data request ID"),
|
|
527
|
+
subscriptionRequestType: import_zod.z.enum(["0", "1", "2"]).describe("Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)"),
|
|
528
|
+
mdEntryType: import_zod.z.string().describe("Market data entry type (0=Bid, 1=Offer, 2=Trade, etc.)")
|
|
529
|
+
},
|
|
530
|
+
async (args) => {
|
|
531
|
+
return {
|
|
532
|
+
messages: [
|
|
533
|
+
{
|
|
534
|
+
role: "user",
|
|
535
|
+
content: {
|
|
536
|
+
type: "text",
|
|
537
|
+
text: [
|
|
538
|
+
"You are an AI assistant that helps users create FIX Market Data Request messages.",
|
|
539
|
+
"You must **first verify** that all required fields are provided:",
|
|
540
|
+
"- MDUpdateType (0=FullRefresh, 1=IncrementalRefresh)",
|
|
541
|
+
"- Symbol (Trading symbol)",
|
|
542
|
+
"- MDReqID (Market data request ID)",
|
|
543
|
+
"- SubscriptionRequestType (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)",
|
|
544
|
+
"- MDEntryType (0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price)",
|
|
545
|
+
"",
|
|
546
|
+
"Only when all fields are present and valid, respond with:",
|
|
547
|
+
"`VERIFICATION: All parameters valid. Ready to proceed.`",
|
|
548
|
+
"",
|
|
549
|
+
"Otherwise, list the missing or invalid ones.",
|
|
550
|
+
"",
|
|
551
|
+
"Do not create the FIX message until verification is complete.",
|
|
552
|
+
"",
|
|
553
|
+
"Current parameters:",
|
|
554
|
+
`- MDUpdateType: ${args.mdUpdateType}`,
|
|
555
|
+
`- Symbol: ${args.symbol}`,
|
|
556
|
+
`- MDReqID: ${args.mdReqID}`,
|
|
557
|
+
`- SubscriptionRequestType: ${args.subscriptionRequestType}`,
|
|
558
|
+
`- MDEntryType: ${args.mdEntryType}`
|
|
559
|
+
].join("\n")
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
]
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
);
|
|
566
|
+
this.server.resource(
|
|
567
|
+
"stockGraph",
|
|
568
|
+
new import_mcp.ResourceTemplate("stock://{symbol}", { list: void 0 }),
|
|
569
|
+
async (uri, variables) => {
|
|
570
|
+
const symbol = variables.symbol;
|
|
571
|
+
const data = [
|
|
572
|
+
{ time: "09:30", price: 150 },
|
|
573
|
+
{ time: "10:30", price: 152.5 },
|
|
574
|
+
{ time: "11:30", price: 151.75 },
|
|
575
|
+
{ time: "12:30", price: 153.25 },
|
|
576
|
+
{ time: "13:30", price: 154 },
|
|
577
|
+
{ time: "14:30", price: 153.5 },
|
|
578
|
+
{ time: "15:30", price: 155 },
|
|
579
|
+
{ time: "16:00", price: 154.75 }
|
|
580
|
+
];
|
|
581
|
+
const width = 600;
|
|
582
|
+
const height = 300;
|
|
583
|
+
const padding = 40;
|
|
584
|
+
const xScale = (width - 2 * padding) / (data.length - 1);
|
|
585
|
+
const yMin = Math.min(...data.map((d) => d.price));
|
|
586
|
+
const yMax = Math.max(...data.map((d) => d.price));
|
|
587
|
+
const yScale = (height - 2 * padding) / (yMax - yMin);
|
|
588
|
+
const points = data.map((d, i) => {
|
|
589
|
+
const x = padding + i * xScale;
|
|
590
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
591
|
+
return `${x},${y}`;
|
|
592
|
+
}).join(" L ");
|
|
593
|
+
const svg = `<?xml version="1.0" encoding="UTF-8"?>
|
|
594
|
+
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
|
595
|
+
<!-- Background -->
|
|
596
|
+
<rect width="100%" height="100%" fill="#f8f9fa"/>
|
|
597
|
+
|
|
598
|
+
<!-- Grid lines -->
|
|
599
|
+
<g stroke="#e9ecef" stroke-width="1">
|
|
600
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
601
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
602
|
+
return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
|
|
603
|
+
}).join("\n")}
|
|
604
|
+
</g>
|
|
605
|
+
|
|
606
|
+
<!-- Price line -->
|
|
607
|
+
<path d="M ${points}"
|
|
608
|
+
fill="none"
|
|
609
|
+
stroke="#007bff"
|
|
610
|
+
stroke-width="2"/>
|
|
611
|
+
|
|
612
|
+
<!-- Data points -->
|
|
613
|
+
${data.map((d, i) => {
|
|
614
|
+
const x = padding + i * xScale;
|
|
615
|
+
const y = height - padding - (d.price - yMin) * yScale;
|
|
616
|
+
return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
|
|
617
|
+
}).join("\n")}
|
|
618
|
+
|
|
619
|
+
<!-- Labels -->
|
|
620
|
+
<g font-family="Arial" font-size="12" fill="#495057">
|
|
621
|
+
${data.map((d, i) => {
|
|
622
|
+
const x = padding + i * xScale;
|
|
623
|
+
return `<text x="${x}" y="${height - padding + 20}" text-anchor="middle">${d.time}</text>`;
|
|
624
|
+
}).join("\n")}
|
|
625
|
+
${Array.from({ length: 5 }, (_, i) => {
|
|
626
|
+
const y = padding + (height - 2 * padding) * i / 4;
|
|
627
|
+
const price = yMax - (yMax - yMin) * i / 4;
|
|
628
|
+
return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
|
|
629
|
+
}).join("\n")}
|
|
630
|
+
</g>
|
|
631
|
+
|
|
632
|
+
<!-- Title -->
|
|
633
|
+
<text x="${width / 2}" y="${padding / 2}"
|
|
634
|
+
font-family="Arial" font-size="16" font-weight="bold"
|
|
635
|
+
text-anchor="middle" fill="#212529">
|
|
636
|
+
${symbol} - 1 Day Price Chart
|
|
637
|
+
</text>
|
|
638
|
+
</svg>`;
|
|
639
|
+
return {
|
|
640
|
+
contents: [
|
|
641
|
+
{
|
|
642
|
+
uri: uri.href,
|
|
643
|
+
text: svg
|
|
644
|
+
}
|
|
645
|
+
]
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
);
|
|
706
649
|
process.on("SIGINT", async () => {
|
|
707
650
|
await this.server.close();
|
|
708
651
|
process.exit(0);
|