fixparser-plugin-mcp 9.1.7-4423352c → 9.1.7-525accda
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 +353 -159
- package/build/cjs/MCPLocal.js.map +2 -2
- package/build/esm/MCPLocal.mjs +360 -160
- package/build/esm/MCPLocal.mjs.map +2 -2
- package/build-examples/cjs/example_mcp_local.js +4 -1
- package/build-examples/cjs/example_mcp_local.js.map +3 -3
- package/build-examples/esm/example_mcp_local.mjs +4 -1
- package/build-examples/esm/example_mcp_local.mjs.map +3 -3
- package/package.json +6 -5
package/build/cjs/MCPLocal.js
CHANGED
|
@@ -37,6 +37,16 @@ var parseInputSchema = {
|
|
|
37
37
|
},
|
|
38
38
|
required: ["fixString"]
|
|
39
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
|
+
};
|
|
40
50
|
var newOrderSingleInputSchema = {
|
|
41
51
|
type: "object",
|
|
42
52
|
properties: {
|
|
@@ -48,7 +58,7 @@ var newOrderSingleInputSchema = {
|
|
|
48
58
|
type: "string",
|
|
49
59
|
enum: ["1", "2", "3"],
|
|
50
60
|
default: import_fixparser.HandlInst.AutomatedExecutionNoIntervention,
|
|
51
|
-
description:
|
|
61
|
+
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)'
|
|
52
62
|
},
|
|
53
63
|
quantity: {
|
|
54
64
|
type: "number",
|
|
@@ -89,12 +99,12 @@ var newOrderSingleInputSchema = {
|
|
|
89
99
|
"S"
|
|
90
100
|
],
|
|
91
101
|
default: import_fixparser.OrdType.Market,
|
|
92
|
-
description:
|
|
102
|
+
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)'
|
|
93
103
|
},
|
|
94
104
|
side: {
|
|
95
105
|
type: "string",
|
|
96
106
|
enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
|
|
97
|
-
description:
|
|
107
|
+
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)'
|
|
98
108
|
},
|
|
99
109
|
symbol: {
|
|
100
110
|
type: "string",
|
|
@@ -104,7 +114,7 @@ var newOrderSingleInputSchema = {
|
|
|
104
114
|
type: "string",
|
|
105
115
|
enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
|
|
106
116
|
default: import_fixparser.TimeInForce.Day,
|
|
107
|
-
description:
|
|
117
|
+
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)'
|
|
108
118
|
}
|
|
109
119
|
},
|
|
110
120
|
required: ["clOrdID", "quantity", "price", "side", "symbol"]
|
|
@@ -116,7 +126,7 @@ var marketDataRequestInputSchema = {
|
|
|
116
126
|
type: "string",
|
|
117
127
|
enum: ["0", "1"],
|
|
118
128
|
default: "0",
|
|
119
|
-
description:
|
|
129
|
+
description: 'Market data update type (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use "0" for FullRefresh, "1" for IncrementalRefresh)'
|
|
120
130
|
},
|
|
121
131
|
symbol: {
|
|
122
132
|
type: "string",
|
|
@@ -130,7 +140,7 @@ var marketDataRequestInputSchema = {
|
|
|
130
140
|
type: "string",
|
|
131
141
|
enum: ["0", "1", "2"],
|
|
132
142
|
default: import_fixparser.SubscriptionRequestType.SnapshotAndUpdates,
|
|
133
|
-
description:
|
|
143
|
+
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)'
|
|
134
144
|
},
|
|
135
145
|
mdEntryType: {
|
|
136
146
|
type: "string",
|
|
@@ -181,7 +191,7 @@ var marketDataRequestInputSchema = {
|
|
|
181
191
|
"t"
|
|
182
192
|
],
|
|
183
193
|
default: import_fixparser.MDEntryType.Bid,
|
|
184
|
-
description:
|
|
194
|
+
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)'
|
|
185
195
|
}
|
|
186
196
|
},
|
|
187
197
|
required: ["symbol", "mdReqID"]
|
|
@@ -195,23 +205,28 @@ var MCPLocal = class {
|
|
|
195
205
|
version: "1.0.0"
|
|
196
206
|
},
|
|
197
207
|
{
|
|
198
|
-
capabilities: {
|
|
208
|
+
capabilities: {
|
|
209
|
+
tools: {},
|
|
210
|
+
prompts: {},
|
|
211
|
+
resources: {}
|
|
212
|
+
}
|
|
199
213
|
}
|
|
200
214
|
);
|
|
201
215
|
transport = new import_stdio.StdioServerTransport();
|
|
202
216
|
onReady = void 0;
|
|
203
217
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
204
218
|
constructor({ logger, onReady }) {
|
|
205
|
-
if (logger
|
|
219
|
+
if (logger && !logger.silent) {
|
|
220
|
+
this.logger = logger;
|
|
221
|
+
}
|
|
206
222
|
if (onReady) this.onReady = onReady;
|
|
207
223
|
}
|
|
208
224
|
async register(parser) {
|
|
209
225
|
this.parser = parser;
|
|
226
|
+
if (parser.logger && !parser.logger.silent) {
|
|
227
|
+
this.logger = parser.logger;
|
|
228
|
+
}
|
|
210
229
|
this.parser.addOnMessageCallback((message) => {
|
|
211
|
-
this.logger?.log({
|
|
212
|
-
level: "info",
|
|
213
|
-
message: `FIXParser (MCP): (${parser.protocol?.toUpperCase()}): << received ${message.description}`
|
|
214
|
-
});
|
|
215
230
|
const msgType = message.messageType;
|
|
216
231
|
if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport) {
|
|
217
232
|
const idField = msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh ? message.getField(import_fixparser.Fields.MDReqID) : message.getField(import_fixparser.Fields.ClOrdID);
|
|
@@ -227,7 +242,6 @@ var MCPLocal = class {
|
|
|
227
242
|
}
|
|
228
243
|
}
|
|
229
244
|
});
|
|
230
|
-
this.logger = parser.logger;
|
|
231
245
|
this.addWorkflows();
|
|
232
246
|
await this.server.connect(this.transport);
|
|
233
247
|
if (this.onReady) {
|
|
@@ -249,6 +263,27 @@ var MCPLocal = class {
|
|
|
249
263
|
});
|
|
250
264
|
return;
|
|
251
265
|
}
|
|
266
|
+
const validateArgs = (args, schema) => {
|
|
267
|
+
const result = {};
|
|
268
|
+
for (const [key, propSchema] of Object.entries(schema.properties || {})) {
|
|
269
|
+
const prop = propSchema;
|
|
270
|
+
const value = args?.[key];
|
|
271
|
+
if (prop.required && (value === void 0 || value === null)) {
|
|
272
|
+
throw new Error(`Required property '${key}' is missing`);
|
|
273
|
+
}
|
|
274
|
+
if (value !== void 0) {
|
|
275
|
+
result[key] = value;
|
|
276
|
+
} else if (prop.default !== void 0) {
|
|
277
|
+
result[key] = prop.default;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
281
|
+
};
|
|
282
|
+
this.server.setRequestHandler(import_types.ListResourcesRequestSchema, async () => {
|
|
283
|
+
return {
|
|
284
|
+
resources: []
|
|
285
|
+
};
|
|
286
|
+
});
|
|
252
287
|
this.server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
|
|
253
288
|
return {
|
|
254
289
|
tools: [
|
|
@@ -260,7 +295,7 @@ var MCPLocal = class {
|
|
|
260
295
|
{
|
|
261
296
|
name: "parseToJSON",
|
|
262
297
|
description: "Parses a FIX message into JSON",
|
|
263
|
-
inputSchema:
|
|
298
|
+
inputSchema: parseToJSONInputSchema
|
|
264
299
|
},
|
|
265
300
|
{
|
|
266
301
|
name: "newOrderSingle",
|
|
@@ -279,11 +314,8 @@ var MCPLocal = class {
|
|
|
279
314
|
const { name, arguments: args } = request.params;
|
|
280
315
|
switch (name) {
|
|
281
316
|
case "parse": {
|
|
282
|
-
const { fixString } = args || {};
|
|
283
|
-
if (!fixString || typeof fixString !== "string") {
|
|
284
|
-
throw new Error("Invalid arguments: fixString is required and must be a string");
|
|
285
|
-
}
|
|
286
317
|
try {
|
|
318
|
+
const { fixString } = validateArgs(args, parseInputSchema);
|
|
287
319
|
const parsedMessage = this.parser?.parse(fixString);
|
|
288
320
|
if (!parsedMessage || parsedMessage.length === 0) {
|
|
289
321
|
return {
|
|
@@ -295,7 +327,8 @@ var MCPLocal = class {
|
|
|
295
327
|
content: [
|
|
296
328
|
{
|
|
297
329
|
type: "text",
|
|
298
|
-
text:
|
|
330
|
+
text: `${parsedMessage[0].description}
|
|
331
|
+
${parsedMessage[0].messageTypeDescription}`
|
|
299
332
|
}
|
|
300
333
|
]
|
|
301
334
|
};
|
|
@@ -305,18 +338,15 @@ var MCPLocal = class {
|
|
|
305
338
|
content: [
|
|
306
339
|
{
|
|
307
340
|
type: "text",
|
|
308
|
-
text:
|
|
341
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
309
342
|
}
|
|
310
343
|
]
|
|
311
344
|
};
|
|
312
345
|
}
|
|
313
346
|
}
|
|
314
347
|
case "parseToJSON": {
|
|
315
|
-
const { fixString } = args || {};
|
|
316
|
-
if (!fixString || typeof fixString !== "string") {
|
|
317
|
-
throw new Error("Invalid arguments: fixString is required and must be a string");
|
|
318
|
-
}
|
|
319
348
|
try {
|
|
349
|
+
const { fixString } = validateArgs(args, parseToJSONInputSchema);
|
|
320
350
|
const parsedMessage = this.parser?.parse(fixString);
|
|
321
351
|
if (!parsedMessage || parsedMessage.length === 0) {
|
|
322
352
|
return {
|
|
@@ -328,7 +358,7 @@ var MCPLocal = class {
|
|
|
328
358
|
content: [
|
|
329
359
|
{
|
|
330
360
|
type: "text",
|
|
331
|
-
text:
|
|
361
|
+
text: `${parsedMessage[0].toFIXJSON()}`
|
|
332
362
|
}
|
|
333
363
|
]
|
|
334
364
|
};
|
|
@@ -338,176 +368,340 @@ var MCPLocal = class {
|
|
|
338
368
|
content: [
|
|
339
369
|
{
|
|
340
370
|
type: "text",
|
|
341
|
-
text:
|
|
371
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
|
|
342
372
|
}
|
|
343
373
|
]
|
|
344
374
|
};
|
|
345
375
|
}
|
|
346
376
|
}
|
|
347
377
|
case "newOrderSingle": {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
const order = this.parser?.createMessage(
|
|
386
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
|
|
387
|
-
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, msgSeqNum),
|
|
388
|
-
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, sender),
|
|
389
|
-
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, target),
|
|
390
|
-
new import_fixparser.Field(import_fixparser.Fields.SendingTime, timestamp),
|
|
391
|
-
new import_fixparser.Field(import_fixparser.Fields.ClOrdID, clOrdID),
|
|
392
|
-
new import_fixparser.Field(import_fixparser.Fields.Side, side),
|
|
393
|
-
new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
|
|
394
|
-
new import_fixparser.Field(import_fixparser.Fields.OrderQty, quantity),
|
|
395
|
-
new import_fixparser.Field(import_fixparser.Fields.Price, price),
|
|
396
|
-
new import_fixparser.Field(import_fixparser.Fields.OrdType, ordType || import_fixparser.OrdType.Market),
|
|
397
|
-
new import_fixparser.Field(
|
|
398
|
-
import_fixparser.Fields.HandlInst,
|
|
399
|
-
handlInst || import_fixparser.HandlInst.AutomatedExecutionNoIntervention
|
|
400
|
-
),
|
|
401
|
-
new import_fixparser.Field(import_fixparser.Fields.TimeInForce, timeInForce || import_fixparser.TimeInForce.Day),
|
|
402
|
-
new import_fixparser.Field(import_fixparser.Fields.TransactTime, timestamp)
|
|
403
|
-
);
|
|
404
|
-
if (!this.parser?.connected) {
|
|
378
|
+
try {
|
|
379
|
+
const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = validateArgs(args, newOrderSingleInputSchema);
|
|
380
|
+
const response = new Promise((resolve) => {
|
|
381
|
+
this.pendingRequests.set(clOrdID, resolve);
|
|
382
|
+
});
|
|
383
|
+
const order = this.parser?.createMessage(
|
|
384
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
|
|
385
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
386
|
+
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
|
|
387
|
+
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
388
|
+
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
389
|
+
new import_fixparser.Field(import_fixparser.Fields.ClOrdID, clOrdID),
|
|
390
|
+
new import_fixparser.Field(import_fixparser.Fields.Side, side),
|
|
391
|
+
new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
|
|
392
|
+
new import_fixparser.Field(import_fixparser.Fields.OrderQty, quantity),
|
|
393
|
+
new import_fixparser.Field(import_fixparser.Fields.Price, price),
|
|
394
|
+
new import_fixparser.Field(import_fixparser.Fields.OrdType, ordType),
|
|
395
|
+
new import_fixparser.Field(import_fixparser.Fields.HandlInst, handlInst),
|
|
396
|
+
new import_fixparser.Field(import_fixparser.Fields.TimeInForce, timeInForce),
|
|
397
|
+
new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
|
|
398
|
+
);
|
|
399
|
+
if (!this.parser?.connected) {
|
|
400
|
+
this.logger?.log({
|
|
401
|
+
level: "error",
|
|
402
|
+
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
403
|
+
});
|
|
404
|
+
return {
|
|
405
|
+
isError: true,
|
|
406
|
+
content: [
|
|
407
|
+
{
|
|
408
|
+
type: "text",
|
|
409
|
+
text: "Error: Not connected. Ignoring message."
|
|
410
|
+
}
|
|
411
|
+
]
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
this.parser?.send(order);
|
|
405
415
|
this.logger?.log({
|
|
406
|
-
level: "
|
|
407
|
-
message:
|
|
416
|
+
level: "info",
|
|
417
|
+
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${order?.description}`
|
|
408
418
|
});
|
|
419
|
+
const fixData = await response;
|
|
420
|
+
return {
|
|
421
|
+
content: [
|
|
422
|
+
{
|
|
423
|
+
type: "text",
|
|
424
|
+
text: `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
425
|
+
}
|
|
426
|
+
]
|
|
427
|
+
};
|
|
428
|
+
} catch (error) {
|
|
409
429
|
return {
|
|
410
430
|
isError: true,
|
|
411
431
|
content: [
|
|
412
432
|
{
|
|
413
433
|
type: "text",
|
|
414
|
-
text:
|
|
434
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to create order"}`
|
|
415
435
|
}
|
|
416
436
|
]
|
|
417
437
|
};
|
|
418
438
|
}
|
|
419
|
-
this.parser?.send(order);
|
|
420
|
-
this.logger?.log({
|
|
421
|
-
level: "info",
|
|
422
|
-
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${order?.description}`
|
|
423
|
-
});
|
|
424
|
-
const fixData = await response;
|
|
425
|
-
return {
|
|
426
|
-
content: [
|
|
427
|
-
{
|
|
428
|
-
type: "text",
|
|
429
|
-
text: `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
430
|
-
}
|
|
431
|
-
]
|
|
432
|
-
};
|
|
433
439
|
}
|
|
434
440
|
case "marketDataRequest": {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
subscriptionRequestType || import_fixparser.SubscriptionRequestType.SnapshotAndUpdates
|
|
475
|
-
),
|
|
476
|
-
new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
|
|
477
|
-
new import_fixparser.Field(import_fixparser.Fields.MDEntryType, mdEntryType || import_fixparser.MDEntryType.Bid)
|
|
478
|
-
);
|
|
479
|
-
if (!this.parser?.connected) {
|
|
441
|
+
try {
|
|
442
|
+
const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = validateArgs(
|
|
443
|
+
args,
|
|
444
|
+
marketDataRequestInputSchema
|
|
445
|
+
);
|
|
446
|
+
const response = new Promise((resolve) => {
|
|
447
|
+
this.pendingRequests.set(mdReqID, resolve);
|
|
448
|
+
});
|
|
449
|
+
const marketDataRequest = this.parser?.createMessage(
|
|
450
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
|
|
451
|
+
new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
|
|
452
|
+
new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
|
|
453
|
+
new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
|
|
454
|
+
new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
|
|
455
|
+
new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
|
|
456
|
+
new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, mdUpdateType),
|
|
457
|
+
new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, 1),
|
|
458
|
+
new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
|
|
459
|
+
new import_fixparser.Field(import_fixparser.Fields.MDReqID, mdReqID),
|
|
460
|
+
new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, subscriptionRequestType),
|
|
461
|
+
new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
|
|
462
|
+
new import_fixparser.Field(import_fixparser.Fields.MDEntryType, mdEntryType)
|
|
463
|
+
);
|
|
464
|
+
if (!this.parser?.connected) {
|
|
465
|
+
this.logger?.log({
|
|
466
|
+
level: "error",
|
|
467
|
+
message: "FIXParser (MCP): -- Not connected. Ignoring message."
|
|
468
|
+
});
|
|
469
|
+
return {
|
|
470
|
+
isError: true,
|
|
471
|
+
content: [
|
|
472
|
+
{
|
|
473
|
+
type: "text",
|
|
474
|
+
text: "Error: Not connected. Ignoring message."
|
|
475
|
+
}
|
|
476
|
+
]
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
this.parser?.send(marketDataRequest);
|
|
480
480
|
this.logger?.log({
|
|
481
|
-
level: "
|
|
482
|
-
message:
|
|
481
|
+
level: "info",
|
|
482
|
+
message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${marketDataRequest?.description}`
|
|
483
483
|
});
|
|
484
|
+
const fixData = await response;
|
|
485
|
+
return {
|
|
486
|
+
content: [
|
|
487
|
+
{
|
|
488
|
+
type: "text",
|
|
489
|
+
text: `Market data for ${symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
|
|
490
|
+
}
|
|
491
|
+
]
|
|
492
|
+
};
|
|
493
|
+
} catch (error) {
|
|
484
494
|
return {
|
|
485
495
|
isError: true,
|
|
486
496
|
content: [
|
|
487
497
|
{
|
|
488
498
|
type: "text",
|
|
489
|
-
text:
|
|
499
|
+
text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
|
|
490
500
|
}
|
|
491
501
|
]
|
|
492
502
|
};
|
|
493
503
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
504
|
+
}
|
|
505
|
+
default:
|
|
506
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
this.server.setRequestHandler(import_types.ListPromptsRequestSchema, async () => {
|
|
510
|
+
return {
|
|
511
|
+
prompts: [
|
|
512
|
+
{
|
|
513
|
+
name: "parse",
|
|
514
|
+
description: "Parses a FIX message and describes it in plain language",
|
|
515
|
+
arguments: [
|
|
516
|
+
{
|
|
517
|
+
name: "fixString",
|
|
518
|
+
description: "FIX message string to parse",
|
|
519
|
+
required: true
|
|
520
|
+
}
|
|
521
|
+
]
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
name: "parseToJSON",
|
|
525
|
+
description: "Parses a FIX message into JSON",
|
|
526
|
+
arguments: [
|
|
527
|
+
{
|
|
528
|
+
name: "fixString",
|
|
529
|
+
description: "FIX message string to parse",
|
|
530
|
+
required: true
|
|
531
|
+
}
|
|
532
|
+
]
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
name: "newOrderSingle",
|
|
536
|
+
description: "Creates and sends a New Order Single",
|
|
537
|
+
arguments: [
|
|
538
|
+
{
|
|
539
|
+
name: "clOrdID",
|
|
540
|
+
description: "Client Order ID",
|
|
541
|
+
required: true
|
|
542
|
+
},
|
|
543
|
+
{
|
|
544
|
+
name: "handlInst",
|
|
545
|
+
description: "Handling instruction",
|
|
546
|
+
required: false
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
name: "quantity",
|
|
550
|
+
description: "Order quantity",
|
|
551
|
+
required: true
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
name: "price",
|
|
555
|
+
description: "Order price",
|
|
556
|
+
required: true
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
name: "ordType",
|
|
560
|
+
description: "Order type",
|
|
561
|
+
required: false
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
name: "side",
|
|
565
|
+
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)",
|
|
566
|
+
required: true
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
name: "symbol",
|
|
570
|
+
description: "Trading symbol",
|
|
571
|
+
required: true
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
name: "timeInForce",
|
|
575
|
+
description: "Time in force",
|
|
576
|
+
required: false
|
|
577
|
+
}
|
|
578
|
+
]
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
name: "marketDataRequest",
|
|
582
|
+
description: "Sends a request for Market Data with the given symbol",
|
|
583
|
+
arguments: [
|
|
584
|
+
{
|
|
585
|
+
name: "mdUpdateType",
|
|
586
|
+
description: "Market data update type",
|
|
587
|
+
required: false
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
name: "symbol",
|
|
591
|
+
description: "Trading symbol",
|
|
592
|
+
required: true
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
name: "mdReqID",
|
|
596
|
+
description: "Market data request ID",
|
|
597
|
+
required: true
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
name: "subscriptionRequestType",
|
|
601
|
+
description: "Subscription request type",
|
|
602
|
+
required: false
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
name: "mdEntryType",
|
|
606
|
+
description: "Market data entry type",
|
|
607
|
+
required: false
|
|
608
|
+
}
|
|
609
|
+
]
|
|
610
|
+
}
|
|
611
|
+
]
|
|
612
|
+
};
|
|
613
|
+
});
|
|
614
|
+
this.server.setRequestHandler(import_types.GetPromptRequestSchema, async (request) => {
|
|
615
|
+
const { name, arguments: args } = request.params;
|
|
616
|
+
switch (name) {
|
|
617
|
+
case "parse": {
|
|
618
|
+
const fixString = args?.fixString || "";
|
|
619
|
+
return {
|
|
620
|
+
messages: [
|
|
621
|
+
{
|
|
622
|
+
role: "user",
|
|
623
|
+
content: {
|
|
624
|
+
type: "text",
|
|
625
|
+
text: `Please parse and explain this FIX message: ${fixString}`
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
]
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
case "parseToJSON": {
|
|
632
|
+
const fixString = args?.fixString || "";
|
|
500
633
|
return {
|
|
501
|
-
|
|
634
|
+
messages: [
|
|
502
635
|
{
|
|
503
|
-
|
|
504
|
-
|
|
636
|
+
role: "user",
|
|
637
|
+
content: {
|
|
638
|
+
type: "text",
|
|
639
|
+
text: `Please parse the FIX message to JSON: ${fixString}`
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
]
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
case "newOrderSingle": {
|
|
646
|
+
const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = args || {};
|
|
647
|
+
return {
|
|
648
|
+
messages: [
|
|
649
|
+
{
|
|
650
|
+
role: "user",
|
|
651
|
+
content: {
|
|
652
|
+
type: "text",
|
|
653
|
+
text: [
|
|
654
|
+
"Create a New Order Single FIX message with the following parameters:",
|
|
655
|
+
`- ClOrdID: ${clOrdID}`,
|
|
656
|
+
`- HandlInst: ${handlInst ?? "3"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Manual, '2' for Automated, '3' for AutomatedNoIntervention)`,
|
|
657
|
+
`- Quantity: ${quantity}`,
|
|
658
|
+
`- Price: ${price}`,
|
|
659
|
+
`- OrdType: ${ordType ?? "1"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Market, '2' for Limit, '3' for Stop)`,
|
|
660
|
+
`- Side: ${side} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '1' for Buy, '2' for Sell)`,
|
|
661
|
+
`- Symbol: ${symbol}`,
|
|
662
|
+
`- TimeInForce: ${timeInForce ?? "0"} (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)`,
|
|
663
|
+
"",
|
|
664
|
+
"Format the response as a JSON object with FIX tag numbers as keys and their corresponding values.",
|
|
665
|
+
"",
|
|
666
|
+
'Note: For the Side parameter, always use the numeric/alphabetic value (e.g., "1" for Buy, "2" for Sell) as defined in the FIX protocol, not the descriptive name.',
|
|
667
|
+
'Note: For the HandlInst parameter, always use the numeric/alphabetic value (e.g., "1" for Manual, "2" for Automated, "3" for AutomatedNoIntervention) as defined in the FIX protocol, not the descriptive name.',
|
|
668
|
+
'Note: For the OrdType parameter, always use the numeric/alphabetic value (e.g., "1" for Market, "2" for Limit, "3" for Stop) as defined in the FIX protocol, not the descriptive name.',
|
|
669
|
+
'Note: For the TimeInForce parameter, always use the numeric/alphabetic value (e.g., "0" for Day, "1" for Good Till Cancel, "2" for At Opening) as defined in the FIX protocol, not the descriptive name.'
|
|
670
|
+
].join("\n")
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
]
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
case "marketDataRequest": {
|
|
677
|
+
const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = args || {};
|
|
678
|
+
return {
|
|
679
|
+
messages: [
|
|
680
|
+
{
|
|
681
|
+
role: "user",
|
|
682
|
+
content: {
|
|
683
|
+
type: "text",
|
|
684
|
+
text: [
|
|
685
|
+
"Create a Market Data Request FIX message with the following parameters:",
|
|
686
|
+
`- MDUpdateType: ${mdUpdateType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for FullRefresh, '1' for IncrementalRefresh)`,
|
|
687
|
+
`- Symbol: ${symbol}`,
|
|
688
|
+
`- MDReqID: ${mdReqID}`,
|
|
689
|
+
`- SubscriptionRequestType: ${subscriptionRequestType ?? "0"} (IMPORTANT: Use the numeric/alphabetic value, not the descriptive name. For example, use '0' for Snapshot + Updates, '1' for Snapshot, '2' for Unsubscribe)`,
|
|
690
|
+
`- MDEntryType: ${mdEntryType ?? "0"} (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)`,
|
|
691
|
+
"",
|
|
692
|
+
"Format the response as a JSON object with FIX tag numbers as keys and their corresponding values.",
|
|
693
|
+
"",
|
|
694
|
+
'Note: For the MDUpdateType parameter, always use the numeric/alphabetic value (e.g., "0" for FullRefresh, "1" for IncrementalRefresh) as defined in the FIX protocol, not the descriptive name.',
|
|
695
|
+
'Note: For the SubscriptionRequestType parameter, always use the numeric/alphabetic value (e.g., "0" for Snapshot + Updates, "1" for Snapshot, "2" for Unsubscribe) as defined in the FIX protocol, not the descriptive name.',
|
|
696
|
+
'Note: For the MDEntryType parameter, always use the numeric/alphabetic value (e.g., "0" for Bid, "1" for Offer, "2" for Trade, "3" for Index Value, "4" for Opening Price) as defined in the FIX protocol, not the descriptive name.'
|
|
697
|
+
].join("\n")
|
|
698
|
+
}
|
|
505
699
|
}
|
|
506
700
|
]
|
|
507
701
|
};
|
|
508
702
|
}
|
|
509
703
|
default:
|
|
510
|
-
throw new Error(`Unknown
|
|
704
|
+
throw new Error(`Unknown prompt: ${name}`);
|
|
511
705
|
}
|
|
512
706
|
});
|
|
513
707
|
process.on("SIGINT", async () => {
|