fixparser-plugin-mcp 9.1.7-8fdb1e41 → 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 +506 -711
- package/build/cjs/MCPLocal.js.map +2 -2
- package/build/esm/MCPLocal.mjs +506 -717
- package/build/esm/MCPLocal.mjs.map +2 -2
- package/build-examples/cjs/example_mcp_local.js +49 -14
- package/build-examples/cjs/example_mcp_local.js.map +3 -3
- package/build-examples/esm/example_mcp_local.mjs +49 -14
- package/build-examples/esm/example_mcp_local.mjs.map +3 -3
- package/package.json +4 -5
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 orderSchema = {
|
|
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 (1=Manual, 2=Automated, 3=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 (1=Market, 2=Limit, 3=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 (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)"
|
|
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 (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)"
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
required: ["clOrdID", "handlInst", "quantity", "price", "ordType", "side", "symbol", "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"
|
|
@@ -251,606 +87,565 @@ var MCPLocal = class {
|
|
|
251
87
|
if (!this.server) {
|
|
252
88
|
return;
|
|
253
89
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
} else if (prop.default !== void 0) {
|
|
265
|
-
result[key] = prop.default;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return result;
|
|
269
|
-
};
|
|
270
|
-
this.server.setRequestHandler(import_types.ListResourcesRequestSchema, async () => {
|
|
271
|
-
return {
|
|
272
|
-
resources: []
|
|
273
|
-
};
|
|
274
|
-
});
|
|
275
|
-
this.server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
|
|
276
|
-
return {
|
|
277
|
-
tools: [
|
|
278
|
-
{
|
|
279
|
-
name: "parse",
|
|
280
|
-
description: "Parses a FIX message and describes it in plain language",
|
|
281
|
-
inputSchema: parseInputSchema
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
name: "parseToJSON",
|
|
285
|
-
description: "Parses a FIX message into JSON",
|
|
286
|
-
inputSchema: parseToJSONInputSchema
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
name: "verifyOrder",
|
|
290
|
-
description: "Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
|
|
291
|
-
inputSchema: orderSchema
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
name: "executeOrder",
|
|
295
|
-
description: "Executes a New Order Single after verification. This is the second step - only call after successful verification.",
|
|
296
|
-
inputSchema: orderSchema
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
name: "marketDataRequest",
|
|
300
|
-
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.",
|
|
301
|
-
inputSchema: marketDataRequestInputSchema
|
|
302
|
-
}
|
|
303
|
-
]
|
|
304
|
-
};
|
|
305
|
-
});
|
|
306
|
-
this.server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
|
|
307
|
-
const { name, arguments: args } = request.params;
|
|
308
|
-
switch (name) {
|
|
309
|
-
case "parse": {
|
|
310
|
-
try {
|
|
311
|
-
const { fixString } = validateArgs(args, parseInputSchema);
|
|
312
|
-
const parsedMessage = this.parser?.parse(fixString);
|
|
313
|
-
if (!parsedMessage || parsedMessage.length === 0) {
|
|
314
|
-
return {
|
|
315
|
-
isError: true,
|
|
316
|
-
content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
|
|
317
|
-
};
|
|
318
|
-
}
|
|
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) {
|
|
319
100
|
return {
|
|
320
|
-
content: [
|
|
321
|
-
|
|
322
|
-
type: "text",
|
|
323
|
-
text: `${parsedMessage[0].description}
|
|
324
|
-
${parsedMessage[0].messageTypeDescription}`
|
|
325
|
-
}
|
|
326
|
-
]
|
|
327
|
-
};
|
|
328
|
-
} catch (error) {
|
|
329
|
-
return {
|
|
330
|
-
isError: true,
|
|
331
|
-
content: [
|
|
332
|
-
{
|
|
333
|
-
type: "text",
|
|
334
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
335
|
-
}
|
|
336
|
-
]
|
|
101
|
+
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
102
|
+
isError: true
|
|
337
103
|
};
|
|
338
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
|
+
};
|
|
339
124
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
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) {
|
|
350
137
|
return {
|
|
351
|
-
content: [
|
|
352
|
-
|
|
353
|
-
type: "text",
|
|
354
|
-
text: `${parsedMessage[0].toFIXJSON()}`
|
|
355
|
-
}
|
|
356
|
-
]
|
|
357
|
-
};
|
|
358
|
-
} catch (error) {
|
|
359
|
-
return {
|
|
360
|
-
isError: true,
|
|
361
|
-
content: [
|
|
362
|
-
{
|
|
363
|
-
type: "text",
|
|
364
|
-
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
365
|
-
}
|
|
366
|
-
]
|
|
138
|
+
content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
|
|
139
|
+
isError: true
|
|
367
140
|
};
|
|
368
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
|
+
};
|
|
369
160
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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.
|
|
388
193
|
|
|
389
194
|
Parameters verified:
|
|
390
|
-
- ClOrdID: ${clOrdID}
|
|
391
|
-
- HandlInst: ${handlInst}
|
|
392
|
-
- Quantity: ${quantity}
|
|
393
|
-
- Price: ${price}
|
|
394
|
-
- OrdType: ${ordType}
|
|
395
|
-
- Side: ${side}
|
|
396
|
-
- Symbol: ${symbol}
|
|
397
|
-
- TimeInForce: ${timeInForce}
|
|
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}
|
|
398
203
|
|
|
399
204
|
To execute this order, call the executeOrder tool with these exact same parameters.`
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
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
|
+
};
|
|
414
218
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
{
|
|
435
|
-
type: "text",
|
|
436
|
-
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
|
|
437
|
-
}
|
|
438
|
-
]
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
const response = new Promise((resolve) => {
|
|
442
|
-
this.pendingRequests.set(clOrdID, resolve);
|
|
443
|
-
});
|
|
444
|
-
const order = this.parser?.createMessage(
|
|
445
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
|
|
446
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
447
|
-
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
|
|
448
|
-
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
449
|
-
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
450
|
-
new import_fixparser.Field(import_fixparser.Fields.ClOrdID, clOrdID),
|
|
451
|
-
new import_fixparser.Field(import_fixparser.Fields.Side, side),
|
|
452
|
-
new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
|
|
453
|
-
new import_fixparser.Field(import_fixparser.Fields.OrderQty, quantity),
|
|
454
|
-
new import_fixparser.Field(import_fixparser.Fields.Price, price),
|
|
455
|
-
new import_fixparser.Field(import_fixparser.Fields.OrdType, ordType),
|
|
456
|
-
new import_fixparser.Field(import_fixparser.Fields.HandlInst, handlInst),
|
|
457
|
-
new import_fixparser.Field(import_fixparser.Fields.TimeInForce, timeInForce),
|
|
458
|
-
new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
|
|
459
|
-
);
|
|
460
|
-
if (!this.parser?.connected) {
|
|
461
|
-
return {
|
|
462
|
-
isError: true,
|
|
463
|
-
content: [
|
|
464
|
-
{
|
|
465
|
-
type: "text",
|
|
466
|
-
text: "Error: Not connected. Ignoring message."
|
|
467
|
-
}
|
|
468
|
-
]
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
this.parser?.send(order);
|
|
472
|
-
const fixData = await response;
|
|
473
|
-
this.verifiedOrders.delete(clOrdID);
|
|
474
|
-
return {
|
|
475
|
-
content: [
|
|
476
|
-
{
|
|
477
|
-
type: "text",
|
|
478
|
-
text: fixData.messageType === import_fixparser.Messages.Reject ? `Reject message for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}` : `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
479
|
-
}
|
|
480
|
-
]
|
|
481
|
-
};
|
|
482
|
-
} catch (error) {
|
|
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) {
|
|
483
238
|
return {
|
|
484
|
-
isError: true,
|
|
485
239
|
content: [
|
|
486
240
|
{
|
|
487
241
|
type: "text",
|
|
488
|
-
text: `Error: ${
|
|
242
|
+
text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
|
|
489
243
|
}
|
|
490
|
-
]
|
|
244
|
+
],
|
|
245
|
+
isError: true
|
|
491
246
|
};
|
|
492
247
|
}
|
|
493
|
-
|
|
494
|
-
case "marketDataRequest": {
|
|
495
|
-
try {
|
|
496
|
-
const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = validateArgs(
|
|
497
|
-
args,
|
|
498
|
-
marketDataRequestInputSchema
|
|
499
|
-
);
|
|
500
|
-
const response = new Promise((resolve) => {
|
|
501
|
-
this.pendingRequests.set(mdReqID, resolve);
|
|
502
|
-
});
|
|
503
|
-
const marketDataRequest = this.parser?.createMessage(
|
|
504
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
505
|
-
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
|
|
506
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
507
|
-
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
508
|
-
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
509
|
-
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
510
|
-
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, mdUpdateType),
|
|
511
|
-
new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, 1),
|
|
512
|
-
new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
|
|
513
|
-
new import_fixparser.Field(import_fixparser.Fields.MDReqID, mdReqID),
|
|
514
|
-
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, subscriptionRequestType),
|
|
515
|
-
new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
|
|
516
|
-
new import_fixparser.Field(import_fixparser.Fields.MDEntryType, mdEntryType)
|
|
517
|
-
);
|
|
518
|
-
if (!this.parser?.connected) {
|
|
519
|
-
return {
|
|
520
|
-
isError: true,
|
|
521
|
-
content: [
|
|
522
|
-
{
|
|
523
|
-
type: "text",
|
|
524
|
-
text: "Error: Not connected. Ignoring message."
|
|
525
|
-
}
|
|
526
|
-
]
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
this.parser?.send(marketDataRequest);
|
|
530
|
-
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) {
|
|
531
249
|
return {
|
|
532
250
|
content: [
|
|
533
251
|
{
|
|
534
252
|
type: "text",
|
|
535
|
-
text:
|
|
253
|
+
text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
|
|
536
254
|
}
|
|
537
|
-
]
|
|
255
|
+
],
|
|
256
|
+
isError: true
|
|
538
257
|
};
|
|
539
|
-
}
|
|
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) {
|
|
540
279
|
return {
|
|
541
|
-
isError: true,
|
|
542
280
|
content: [
|
|
543
281
|
{
|
|
544
282
|
type: "text",
|
|
545
|
-
text:
|
|
283
|
+
text: "Error: Not connected. Ignoring message."
|
|
546
284
|
}
|
|
547
|
-
]
|
|
285
|
+
],
|
|
286
|
+
isError: true
|
|
548
287
|
};
|
|
549
288
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}
|
|
554
|
-
});
|
|
555
|
-
this.server.setRequestHandler(import_types.ListPromptsRequestSchema, async () => {
|
|
556
|
-
return {
|
|
557
|
-
prompts: [
|
|
558
|
-
{
|
|
559
|
-
name: "parse",
|
|
560
|
-
description: "Parses a FIX message and describes it in plain language",
|
|
561
|
-
arguments: [
|
|
562
|
-
{
|
|
563
|
-
name: "fixString",
|
|
564
|
-
description: "FIX message string to parse",
|
|
565
|
-
required: true
|
|
566
|
-
}
|
|
567
|
-
]
|
|
568
|
-
},
|
|
569
|
-
{
|
|
570
|
-
name: "parseToJSON",
|
|
571
|
-
description: "Parses a FIX message into JSON",
|
|
572
|
-
arguments: [
|
|
573
|
-
{
|
|
574
|
-
name: "fixString",
|
|
575
|
-
description: "FIX message string to parse",
|
|
576
|
-
required: true
|
|
577
|
-
}
|
|
578
|
-
]
|
|
579
|
-
},
|
|
580
|
-
{
|
|
581
|
-
name: "verifyOrder",
|
|
582
|
-
description: "Verifies all parameters for a New Order Single. This is the first step - verification only, no order is sent.",
|
|
583
|
-
arguments: [
|
|
584
|
-
{
|
|
585
|
-
name: "clOrdID",
|
|
586
|
-
description: "Client Order ID",
|
|
587
|
-
required: true
|
|
588
|
-
},
|
|
589
|
-
{
|
|
590
|
-
name: "handlInst",
|
|
591
|
-
description: "Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)",
|
|
592
|
-
required: true
|
|
593
|
-
},
|
|
594
|
-
{
|
|
595
|
-
name: "quantity",
|
|
596
|
-
description: "Order quantity",
|
|
597
|
-
required: true
|
|
598
|
-
},
|
|
599
|
-
{
|
|
600
|
-
name: "price",
|
|
601
|
-
description: "Order price",
|
|
602
|
-
required: true
|
|
603
|
-
},
|
|
604
|
-
{
|
|
605
|
-
name: "ordType",
|
|
606
|
-
description: "Order type (1=Market, 2=Limit, 3=Stop)",
|
|
607
|
-
required: true
|
|
608
|
-
},
|
|
609
|
-
{
|
|
610
|
-
name: "side",
|
|
611
|
-
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)",
|
|
612
|
-
required: true
|
|
613
|
-
},
|
|
614
|
-
{
|
|
615
|
-
name: "symbol",
|
|
616
|
-
description: "Trading symbol",
|
|
617
|
-
required: true
|
|
618
|
-
},
|
|
619
|
-
{
|
|
620
|
-
name: "timeInForce",
|
|
621
|
-
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)",
|
|
622
|
-
required: true
|
|
623
|
-
}
|
|
624
|
-
]
|
|
625
|
-
},
|
|
626
|
-
{
|
|
627
|
-
name: "executeOrder",
|
|
628
|
-
description: "Executes a New Order Single after verification. This is the second step - only call after successful verification.",
|
|
629
|
-
arguments: [
|
|
630
|
-
{
|
|
631
|
-
name: "clOrdID",
|
|
632
|
-
description: "Client Order ID",
|
|
633
|
-
required: true
|
|
634
|
-
},
|
|
635
|
-
{
|
|
636
|
-
name: "handlInst",
|
|
637
|
-
description: "Handling instruction (1=Manual, 2=Automated, 3=AutomatedNoIntervention)",
|
|
638
|
-
required: true
|
|
639
|
-
},
|
|
640
|
-
{
|
|
641
|
-
name: "quantity",
|
|
642
|
-
description: "Order quantity",
|
|
643
|
-
required: true
|
|
644
|
-
},
|
|
645
|
-
{
|
|
646
|
-
name: "price",
|
|
647
|
-
description: "Order price",
|
|
648
|
-
required: true
|
|
649
|
-
},
|
|
650
|
-
{
|
|
651
|
-
name: "ordType",
|
|
652
|
-
description: "Order type (1=Market, 2=Limit, 3=Stop)",
|
|
653
|
-
required: true
|
|
654
|
-
},
|
|
655
|
-
{
|
|
656
|
-
name: "side",
|
|
657
|
-
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)",
|
|
658
|
-
required: true
|
|
659
|
-
},
|
|
660
|
-
{
|
|
661
|
-
name: "symbol",
|
|
662
|
-
description: "Trading symbol",
|
|
663
|
-
required: true
|
|
664
|
-
},
|
|
665
|
-
{
|
|
666
|
-
name: "timeInForce",
|
|
667
|
-
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)",
|
|
668
|
-
required: true
|
|
669
|
-
}
|
|
670
|
-
]
|
|
671
|
-
},
|
|
672
|
-
{
|
|
673
|
-
name: "marketDataRequest",
|
|
674
|
-
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.",
|
|
675
|
-
arguments: [
|
|
676
|
-
{
|
|
677
|
-
name: "mdUpdateType",
|
|
678
|
-
description: "Market data update type (0=FullRefresh, 1=IncrementalRefresh)",
|
|
679
|
-
required: true
|
|
680
|
-
},
|
|
681
|
-
{
|
|
682
|
-
name: "symbol",
|
|
683
|
-
description: "Trading symbol",
|
|
684
|
-
required: true
|
|
685
|
-
},
|
|
686
|
-
{
|
|
687
|
-
name: "mdReqID",
|
|
688
|
-
description: "Market data request ID",
|
|
689
|
-
required: true
|
|
690
|
-
},
|
|
691
|
-
{
|
|
692
|
-
name: "subscriptionRequestType",
|
|
693
|
-
description: "Subscription request type (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)",
|
|
694
|
-
required: true
|
|
695
|
-
},
|
|
696
|
-
{
|
|
697
|
-
name: "mdEntryType",
|
|
698
|
-
description: "Market data entry type (0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price)",
|
|
699
|
-
required: true
|
|
700
|
-
}
|
|
701
|
-
]
|
|
702
|
-
}
|
|
703
|
-
]
|
|
704
|
-
};
|
|
705
|
-
});
|
|
706
|
-
this.server.setRequestHandler(import_types.GetPromptRequestSchema, async (request) => {
|
|
707
|
-
const { name, arguments: args } = request.params;
|
|
708
|
-
switch (name) {
|
|
709
|
-
case "parse": {
|
|
710
|
-
const fixString = args?.fixString || "";
|
|
289
|
+
this.parser?.send(order);
|
|
290
|
+
const fixData = await response;
|
|
291
|
+
this.verifiedOrders.delete(args.clOrdID);
|
|
711
292
|
return {
|
|
712
|
-
|
|
293
|
+
content: [
|
|
713
294
|
{
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
type: "text",
|
|
717
|
-
text: `Please parse and explain this FIX message: ${fixString}`
|
|
718
|
-
}
|
|
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())}`
|
|
719
297
|
}
|
|
720
298
|
]
|
|
721
299
|
};
|
|
722
|
-
}
|
|
723
|
-
case "parseToJSON": {
|
|
724
|
-
const fixString = args?.fixString || "";
|
|
300
|
+
} catch (error) {
|
|
725
301
|
return {
|
|
726
|
-
|
|
302
|
+
content: [
|
|
727
303
|
{
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
type: "text",
|
|
731
|
-
text: `Please parse the FIX message to JSON: ${fixString}`
|
|
732
|
-
}
|
|
304
|
+
type: "text",
|
|
305
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
|
|
733
306
|
}
|
|
734
|
-
]
|
|
307
|
+
],
|
|
308
|
+
isError: true
|
|
735
309
|
};
|
|
736
310
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
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
|
+
{
|
|
744
347
|
type: "text",
|
|
745
|
-
text:
|
|
746
|
-
"You are an AI assistant that helps users verify FIX New Order Single parameters.",
|
|
747
|
-
"This is STEP 1 of 2 - VERIFICATION ONLY. No order will be sent at this stage.",
|
|
748
|
-
"",
|
|
749
|
-
"You must verify that all required fields are provided and valid:",
|
|
750
|
-
"- ClOrdID (Client Order ID)",
|
|
751
|
-
"- HandlInst (1=Manual, 2=Automated, 3=AutomatedNoIntervention)",
|
|
752
|
-
"- Quantity (Order quantity)",
|
|
753
|
-
"- Price (Order price)",
|
|
754
|
-
"- OrdType (1=Market, 2=Limit, 3=Stop)",
|
|
755
|
-
"- 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)",
|
|
756
|
-
"- Symbol (Trading symbol)",
|
|
757
|
-
"- 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)",
|
|
758
|
-
"",
|
|
759
|
-
"Current parameters to verify:",
|
|
760
|
-
`- ClOrdID: ${clOrdID}`,
|
|
761
|
-
`- HandlInst: ${handlInst}`,
|
|
762
|
-
`- Quantity: ${quantity}`,
|
|
763
|
-
`- Price: ${price}`,
|
|
764
|
-
`- OrdType: ${ordType}`,
|
|
765
|
-
`- Side: ${side}`,
|
|
766
|
-
`- Symbol: ${symbol}`,
|
|
767
|
-
`- TimeInForce: ${timeInForce}`,
|
|
768
|
-
"",
|
|
769
|
-
"If all parameters are valid, respond with:",
|
|
770
|
-
"`VERIFICATION: All parameters valid. Ready to proceed.`",
|
|
771
|
-
"",
|
|
772
|
-
"Otherwise, list the missing or invalid ones.",
|
|
773
|
-
"",
|
|
774
|
-
"IMPORTANT: This is only verification. To actually send the order, the user must call the executeOrder tool with the same parameters."
|
|
775
|
-
].join("\n")
|
|
348
|
+
text: "Error: Not connected. Ignoring message."
|
|
776
349
|
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
const
|
|
350
|
+
],
|
|
351
|
+
isError: true
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
this.parser?.send(marketDataRequest);
|
|
355
|
+
const fixData = await response;
|
|
783
356
|
return {
|
|
784
|
-
|
|
357
|
+
content: [
|
|
785
358
|
{
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
type: "text",
|
|
789
|
-
text: [
|
|
790
|
-
"You are an AI assistant that helps users execute FIX New Order Single messages.",
|
|
791
|
-
"This is STEP 2 of 2 - EXECUTION. This will send the order to the market.",
|
|
792
|
-
"",
|
|
793
|
-
"IMPORTANT: This tool should only be called after successful verification of all parameters.",
|
|
794
|
-
"",
|
|
795
|
-
"Parameters to execute:",
|
|
796
|
-
`- ClOrdID: ${clOrdID}`,
|
|
797
|
-
`- HandlInst: ${handlInst}`,
|
|
798
|
-
`- Quantity: ${quantity}`,
|
|
799
|
-
`- Price: ${price}`,
|
|
800
|
-
`- OrdType: ${ordType}`,
|
|
801
|
-
`- Side: ${side}`,
|
|
802
|
-
`- Symbol: ${symbol}`,
|
|
803
|
-
`- TimeInForce: ${timeInForce}`,
|
|
804
|
-
"",
|
|
805
|
-
"IMPORTANT: The response will be either:",
|
|
806
|
-
"1. An Execution Report (MsgType=8) if the order was successfully placed",
|
|
807
|
-
"2. A Reject message (MsgType=3) if the order failed to execute (e.g., due to missing or invalid parameters)"
|
|
808
|
-
].join("\n")
|
|
809
|
-
}
|
|
359
|
+
type: "text",
|
|
360
|
+
text: `Market data for ${args.symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
810
361
|
}
|
|
811
362
|
]
|
|
812
363
|
};
|
|
813
|
-
}
|
|
814
|
-
case "marketDataRequest": {
|
|
815
|
-
const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = args || {};
|
|
364
|
+
} catch (error) {
|
|
816
365
|
return {
|
|
817
|
-
|
|
366
|
+
content: [
|
|
818
367
|
{
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
type: "text",
|
|
822
|
-
text: [
|
|
823
|
-
"You are an AI assistant that helps users create FIX Market Data Request messages.",
|
|
824
|
-
"You must **first verify** that all required fields are provided:",
|
|
825
|
-
"- MDUpdateType (0=FullRefresh, 1=IncrementalRefresh)",
|
|
826
|
-
"- Symbol (Trading symbol)",
|
|
827
|
-
"- MDReqID (Market data request ID)",
|
|
828
|
-
"- SubscriptionRequestType (0=Snapshot + Updates, 1=Snapshot, 2=Unsubscribe)",
|
|
829
|
-
"- MDEntryType (0=Bid, 1=Offer, 2=Trade, 3=Index Value, 4=Opening Price)",
|
|
830
|
-
"",
|
|
831
|
-
"Only when all fields are present and valid, respond with:",
|
|
832
|
-
"`VERIFICATION: All parameters valid. Ready to proceed.`",
|
|
833
|
-
"",
|
|
834
|
-
"Otherwise, list the missing or invalid ones.",
|
|
835
|
-
"",
|
|
836
|
-
"Do not create the FIX message until verification is complete.",
|
|
837
|
-
"",
|
|
838
|
-
"Current parameters:",
|
|
839
|
-
`- MDUpdateType: ${mdUpdateType}`,
|
|
840
|
-
`- Symbol: ${symbol}`,
|
|
841
|
-
`- MDReqID: ${mdReqID}`,
|
|
842
|
-
`- SubscriptionRequestType: ${subscriptionRequestType}`,
|
|
843
|
-
`- MDEntryType: ${mdEntryType}`
|
|
844
|
-
].join("\n")
|
|
845
|
-
}
|
|
368
|
+
type: "text",
|
|
369
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
846
370
|
}
|
|
847
|
-
]
|
|
371
|
+
],
|
|
372
|
+
isError: true
|
|
848
373
|
};
|
|
849
374
|
}
|
|
850
|
-
default:
|
|
851
|
-
throw new Error(`Unknown prompt: ${name}`);
|
|
852
375
|
}
|
|
853
|
-
|
|
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
|
+
);
|
|
854
649
|
process.on("SIGINT", async () => {
|
|
855
650
|
await this.server.close();
|
|
856
651
|
process.exit(0);
|