fixparser-plugin-mcp 9.1.6-da9cb1d7 → 9.1.7-27ef5b7b

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.
@@ -0,0 +1,707 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/MCPLocal.ts
21
+ var MCPLocal_exports = {};
22
+ __export(MCPLocal_exports, {
23
+ MCPLocal: () => MCPLocal
24
+ });
25
+ module.exports = __toCommonJS(MCPLocal_exports);
26
+ var import_server = require("@modelcontextprotocol/sdk/server/index.js");
27
+ var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
28
+ var import_types = require("@modelcontextprotocol/sdk/types.js");
29
+ var import_fixparser = require("fixparser");
30
+ var parseInputSchema = {
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
+ default: import_fixparser.HandlInst.AutomatedExecutionNoIntervention,
61
+ description: "Handling instruction"
62
+ },
63
+ quantity: {
64
+ type: "number",
65
+ description: "Order quantity"
66
+ },
67
+ price: {
68
+ type: "number",
69
+ description: "Order price"
70
+ },
71
+ ordType: {
72
+ type: "string",
73
+ enum: [
74
+ "1",
75
+ "2",
76
+ "3",
77
+ "4",
78
+ "5",
79
+ "6",
80
+ "7",
81
+ "8",
82
+ "9",
83
+ "A",
84
+ "B",
85
+ "C",
86
+ "D",
87
+ "E",
88
+ "F",
89
+ "G",
90
+ "H",
91
+ "I",
92
+ "J",
93
+ "K",
94
+ "L",
95
+ "M",
96
+ "P",
97
+ "Q",
98
+ "R",
99
+ "S"
100
+ ],
101
+ default: import_fixparser.OrdType.Market,
102
+ description: "Order type"
103
+ },
104
+ side: {
105
+ type: "string",
106
+ enum: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H"],
107
+ description: "Order side (1=Buy, 2=Sell)"
108
+ },
109
+ symbol: {
110
+ type: "string",
111
+ description: "Trading symbol"
112
+ },
113
+ timeInForce: {
114
+ type: "string",
115
+ enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"],
116
+ default: import_fixparser.TimeInForce.Day,
117
+ description: "Time in force"
118
+ }
119
+ },
120
+ required: ["clOrdID", "quantity", "price", "side", "symbol"]
121
+ };
122
+ var marketDataRequestInputSchema = {
123
+ type: "object",
124
+ properties: {
125
+ mdUpdateType: {
126
+ type: "string",
127
+ enum: ["0", "1"],
128
+ default: "0",
129
+ description: "Market data update type"
130
+ },
131
+ symbol: {
132
+ type: "string",
133
+ description: "Trading symbol"
134
+ },
135
+ mdReqID: {
136
+ type: "string",
137
+ description: "Market data request ID"
138
+ },
139
+ subscriptionRequestType: {
140
+ type: "string",
141
+ enum: ["0", "1", "2"],
142
+ default: import_fixparser.SubscriptionRequestType.SnapshotAndUpdates,
143
+ description: "Subscription request type"
144
+ },
145
+ mdEntryType: {
146
+ type: "string",
147
+ enum: [
148
+ "0",
149
+ "1",
150
+ "2",
151
+ "3",
152
+ "4",
153
+ "5",
154
+ "6",
155
+ "7",
156
+ "8",
157
+ "9",
158
+ "A",
159
+ "B",
160
+ "C",
161
+ "D",
162
+ "E",
163
+ "F",
164
+ "G",
165
+ "H",
166
+ "J",
167
+ "K",
168
+ "L",
169
+ "M",
170
+ "N",
171
+ "O",
172
+ "P",
173
+ "Q",
174
+ "S",
175
+ "R",
176
+ "T",
177
+ "U",
178
+ "V",
179
+ "W",
180
+ "X",
181
+ "Y",
182
+ "Z",
183
+ "a",
184
+ "b",
185
+ "c",
186
+ "d",
187
+ "e",
188
+ "g",
189
+ "h",
190
+ "i",
191
+ "t"
192
+ ],
193
+ default: import_fixparser.MDEntryType.Bid,
194
+ description: "Market data entry type"
195
+ }
196
+ },
197
+ required: ["symbol", "mdReqID"]
198
+ };
199
+ var MCPLocal = class {
200
+ logger;
201
+ parser;
202
+ server = new import_server.Server(
203
+ {
204
+ name: "fixparser",
205
+ version: "1.0.0"
206
+ },
207
+ {
208
+ capabilities: {
209
+ tools: {},
210
+ prompts: {},
211
+ resources: {}
212
+ }
213
+ }
214
+ );
215
+ transport = new import_stdio.StdioServerTransport();
216
+ onReady = void 0;
217
+ pendingRequests = /* @__PURE__ */ new Map();
218
+ constructor({ logger, onReady }) {
219
+ if (logger) this.logger = logger;
220
+ if (onReady) this.onReady = onReady;
221
+ }
222
+ async register(parser) {
223
+ this.parser = parser;
224
+ this.parser.addOnMessageCallback((message) => {
225
+ this.logger?.log({
226
+ level: "info",
227
+ message: `FIXParser (MCP): (${parser.protocol?.toUpperCase()}): << received ${message.description}`
228
+ });
229
+ const msgType = message.messageType;
230
+ if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport) {
231
+ const idField = msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh ? message.getField(import_fixparser.Fields.MDReqID) : message.getField(import_fixparser.Fields.ClOrdID);
232
+ if (idField) {
233
+ const id = idField.value;
234
+ if (typeof id === "string" || typeof id === "number") {
235
+ const callback = this.pendingRequests.get(String(id));
236
+ if (callback) {
237
+ callback(message);
238
+ this.pendingRequests.delete(String(id));
239
+ }
240
+ }
241
+ }
242
+ }
243
+ });
244
+ this.logger = parser.logger;
245
+ this.addWorkflows();
246
+ await this.server.connect(this.transport);
247
+ if (this.onReady) {
248
+ this.onReady();
249
+ }
250
+ }
251
+ addWorkflows() {
252
+ if (!this.parser) {
253
+ this.logger?.log({
254
+ level: "error",
255
+ message: "FIXParser (MCP): -- FIXParser instance not initialized. Ignoring setup of workflows..."
256
+ });
257
+ return;
258
+ }
259
+ if (!this.server) {
260
+ this.logger?.log({
261
+ level: "error",
262
+ message: "FIXParser (MCP): -- MCP Server not initialized. Ignoring setup of workflows..."
263
+ });
264
+ return;
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
+ });
287
+ this.server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
288
+ return {
289
+ tools: [
290
+ {
291
+ name: "parse",
292
+ description: "Parses a FIX message and describes it in plain language",
293
+ inputSchema: parseInputSchema
294
+ },
295
+ {
296
+ name: "parseToJSON",
297
+ description: "Parses a FIX message into JSON",
298
+ inputSchema: parseToJSONInputSchema
299
+ },
300
+ {
301
+ name: "newOrderSingle",
302
+ description: "Creates and sends a New Order Single",
303
+ inputSchema: newOrderSingleInputSchema
304
+ },
305
+ {
306
+ name: "marketDataRequest",
307
+ description: "Sends a request for Market Data with the given symbol",
308
+ inputSchema: marketDataRequestInputSchema
309
+ }
310
+ ]
311
+ };
312
+ });
313
+ this.server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
314
+ const { name, arguments: args } = request.params;
315
+ switch (name) {
316
+ case "parse": {
317
+ try {
318
+ const { fixString } = validateArgs(args, parseInputSchema);
319
+ const parsedMessage = this.parser?.parse(fixString);
320
+ if (!parsedMessage || parsedMessage.length === 0) {
321
+ return {
322
+ isError: true,
323
+ content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
324
+ };
325
+ }
326
+ return {
327
+ content: [
328
+ {
329
+ type: "text",
330
+ text: `Parsed FIX message: ${fixString} (placeholder implementation)`
331
+ }
332
+ ]
333
+ };
334
+ } catch (error) {
335
+ return {
336
+ isError: true,
337
+ content: [
338
+ {
339
+ type: "text",
340
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
341
+ }
342
+ ]
343
+ };
344
+ }
345
+ }
346
+ case "parseToJSON": {
347
+ try {
348
+ const { fixString } = validateArgs(args, parseToJSONInputSchema);
349
+ const parsedMessage = this.parser?.parse(fixString);
350
+ if (!parsedMessage || parsedMessage.length === 0) {
351
+ return {
352
+ isError: true,
353
+ content: [{ type: "text", text: "Error: Failed to parse FIX string" }]
354
+ };
355
+ }
356
+ return {
357
+ content: [
358
+ {
359
+ type: "text",
360
+ text: JSON.stringify({ fixString, parsed: "placeholder" })
361
+ }
362
+ ]
363
+ };
364
+ } catch (error) {
365
+ return {
366
+ isError: true,
367
+ content: [
368
+ {
369
+ type: "text",
370
+ text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
371
+ }
372
+ ]
373
+ };
374
+ }
375
+ }
376
+ case "newOrderSingle": {
377
+ try {
378
+ const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = validateArgs(args, newOrderSingleInputSchema);
379
+ const response = new Promise((resolve) => {
380
+ this.pendingRequests.set(clOrdID, resolve);
381
+ });
382
+ const order = this.parser?.createMessage(
383
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
384
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
385
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
386
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
387
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
388
+ new import_fixparser.Field(import_fixparser.Fields.ClOrdID, clOrdID),
389
+ new import_fixparser.Field(import_fixparser.Fields.Side, side),
390
+ new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
391
+ new import_fixparser.Field(import_fixparser.Fields.OrderQty, quantity),
392
+ new import_fixparser.Field(import_fixparser.Fields.Price, price),
393
+ new import_fixparser.Field(import_fixparser.Fields.OrdType, ordType),
394
+ new import_fixparser.Field(import_fixparser.Fields.HandlInst, handlInst),
395
+ new import_fixparser.Field(import_fixparser.Fields.TimeInForce, timeInForce),
396
+ new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
397
+ );
398
+ if (!this.parser?.connected) {
399
+ this.logger?.log({
400
+ level: "error",
401
+ message: "FIXParser (MCP): -- Not connected. Ignoring message."
402
+ });
403
+ return {
404
+ isError: true,
405
+ content: [
406
+ {
407
+ type: "text",
408
+ text: "Error: Not connected. Ignoring message."
409
+ }
410
+ ]
411
+ };
412
+ }
413
+ this.parser?.send(order);
414
+ this.logger?.log({
415
+ level: "info",
416
+ message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${order?.description}`
417
+ });
418
+ const fixData = await response;
419
+ return {
420
+ content: [
421
+ {
422
+ type: "text",
423
+ text: `Execution Report for order ${clOrdID}: ${JSON.stringify(fixData.toFIXJSON())}`
424
+ }
425
+ ]
426
+ };
427
+ } catch (error) {
428
+ return {
429
+ isError: true,
430
+ content: [
431
+ {
432
+ type: "text",
433
+ text: `Error: ${error instanceof Error ? error.message : "Failed to create order"}`
434
+ }
435
+ ]
436
+ };
437
+ }
438
+ }
439
+ case "marketDataRequest": {
440
+ try {
441
+ const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = validateArgs(
442
+ args,
443
+ marketDataRequestInputSchema
444
+ );
445
+ const response = new Promise((resolve) => {
446
+ this.pendingRequests.set(mdReqID, resolve);
447
+ });
448
+ const marketDataRequest = this.parser?.createMessage(
449
+ new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
450
+ new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
451
+ new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
452
+ new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
453
+ new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
454
+ new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
455
+ new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, mdUpdateType),
456
+ new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, 1),
457
+ new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol),
458
+ new import_fixparser.Field(import_fixparser.Fields.MDReqID, mdReqID),
459
+ new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, subscriptionRequestType),
460
+ new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, 1),
461
+ new import_fixparser.Field(import_fixparser.Fields.MDEntryType, mdEntryType)
462
+ );
463
+ if (!this.parser?.connected) {
464
+ this.logger?.log({
465
+ level: "error",
466
+ message: "FIXParser (MCP): -- Not connected. Ignoring message."
467
+ });
468
+ return {
469
+ isError: true,
470
+ content: [
471
+ {
472
+ type: "text",
473
+ text: "Error: Not connected. Ignoring message."
474
+ }
475
+ ]
476
+ };
477
+ }
478
+ this.parser?.send(marketDataRequest);
479
+ this.logger?.log({
480
+ level: "info",
481
+ message: `FIXParser (MCP): (${this.parser?.protocol?.toUpperCase()}): >> sent ${marketDataRequest?.description}`
482
+ });
483
+ const fixData = await response;
484
+ return {
485
+ content: [
486
+ {
487
+ type: "text",
488
+ text: `Market data for ${symbol}: ${JSON.stringify(fixData.toFIXJSON())}`
489
+ }
490
+ ]
491
+ };
492
+ } catch (error) {
493
+ return {
494
+ isError: true,
495
+ content: [
496
+ {
497
+ type: "text",
498
+ text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
499
+ }
500
+ ]
501
+ };
502
+ }
503
+ }
504
+ default:
505
+ throw new Error(`Unknown tool: ${name}`);
506
+ }
507
+ });
508
+ this.server.setRequestHandler(import_types.ListPromptsRequestSchema, async () => {
509
+ return {
510
+ prompts: [
511
+ {
512
+ name: "parse",
513
+ description: "Parses a FIX message and describes it in plain language",
514
+ arguments: [
515
+ {
516
+ name: "fixString",
517
+ description: "FIX message string to parse",
518
+ required: true
519
+ }
520
+ ]
521
+ },
522
+ {
523
+ name: "parseToJSON",
524
+ description: "Parses a FIX message into JSON",
525
+ arguments: [
526
+ {
527
+ name: "fixString",
528
+ description: "FIX message string to parse",
529
+ required: true
530
+ }
531
+ ]
532
+ },
533
+ {
534
+ name: "newOrderSingle",
535
+ description: "Creates and sends a New Order Single",
536
+ arguments: [
537
+ {
538
+ name: "clOrdID",
539
+ description: "Client Order ID",
540
+ required: true
541
+ },
542
+ {
543
+ name: "handlInst",
544
+ description: "Handling instruction",
545
+ required: false
546
+ },
547
+ {
548
+ name: "quantity",
549
+ description: "Order quantity",
550
+ required: true
551
+ },
552
+ {
553
+ name: "price",
554
+ description: "Order price",
555
+ required: true
556
+ },
557
+ {
558
+ name: "ordType",
559
+ description: "Order type",
560
+ required: false
561
+ },
562
+ {
563
+ name: "side",
564
+ description: "Order side (1=Buy, 2=Sell)",
565
+ required: true
566
+ },
567
+ {
568
+ name: "symbol",
569
+ description: "Trading symbol",
570
+ required: true
571
+ },
572
+ {
573
+ name: "timeInForce",
574
+ description: "Time in force",
575
+ required: false
576
+ }
577
+ ]
578
+ },
579
+ {
580
+ name: "marketDataRequest",
581
+ description: "Sends a request for Market Data with the given symbol",
582
+ arguments: [
583
+ {
584
+ name: "mdUpdateType",
585
+ description: "Market data update type",
586
+ required: false
587
+ },
588
+ {
589
+ name: "symbol",
590
+ description: "Trading symbol",
591
+ required: true
592
+ },
593
+ {
594
+ name: "mdReqID",
595
+ description: "Market data request ID",
596
+ required: true
597
+ },
598
+ {
599
+ name: "subscriptionRequestType",
600
+ description: "Subscription request type",
601
+ required: false
602
+ },
603
+ {
604
+ name: "mdEntryType",
605
+ description: "Market data entry type",
606
+ required: false
607
+ }
608
+ ]
609
+ }
610
+ ]
611
+ };
612
+ });
613
+ this.server.setRequestHandler(import_types.GetPromptRequestSchema, async (request) => {
614
+ const { name, arguments: args } = request.params;
615
+ switch (name) {
616
+ case "parse": {
617
+ const fixString = args?.fixString || "";
618
+ return {
619
+ messages: [
620
+ {
621
+ role: "user",
622
+ content: {
623
+ type: "text",
624
+ text: `Please parse and explain this FIX message: ${fixString}`
625
+ }
626
+ }
627
+ ]
628
+ };
629
+ }
630
+ case "parseToJSON": {
631
+ const fixString = args?.fixString || "";
632
+ return {
633
+ messages: [
634
+ {
635
+ role: "user",
636
+ content: {
637
+ type: "text",
638
+ text: `Please parse the FIX message to JSON: ${fixString}`
639
+ }
640
+ }
641
+ ]
642
+ };
643
+ }
644
+ case "newOrderSingle": {
645
+ const { clOrdID, handlInst, quantity, price, ordType, side, symbol, timeInForce } = args || {};
646
+ return {
647
+ messages: [
648
+ {
649
+ role: "user",
650
+ content: {
651
+ type: "text",
652
+ text: [
653
+ "Create a New Order Single FIX message with the following parameters:",
654
+ `- ClOrdID: ${clOrdID}`,
655
+ `- HandlInst: ${handlInst ?? "default"}`,
656
+ `- Quantity: ${quantity}`,
657
+ `- Price: ${price}`,
658
+ `- OrdType: ${ordType ?? "default (Market)"}`,
659
+ `- Side: ${side}`,
660
+ `- Symbol: ${symbol}`,
661
+ `- TimeInForce: ${timeInForce ?? "default (Day)"}`,
662
+ "",
663
+ "Format the response as a JSON object with FIX tag numbers as keys and their corresponding values."
664
+ ].join("\n")
665
+ }
666
+ }
667
+ ]
668
+ };
669
+ }
670
+ case "marketDataRequest": {
671
+ const { mdUpdateType, symbol, mdReqID, subscriptionRequestType, mdEntryType } = args || {};
672
+ return {
673
+ messages: [
674
+ {
675
+ role: "user",
676
+ content: {
677
+ type: "text",
678
+ text: [
679
+ "Create a Market Data Request FIX message with the following parameters:",
680
+ `- MDUpdateType: ${mdUpdateType ?? "default (0 = FullRefresh)"}`,
681
+ `- Symbol: ${symbol}`,
682
+ `- MDReqID: ${mdReqID}`,
683
+ `- SubscriptionRequestType: ${subscriptionRequestType ?? "default (0 = Snapshot + Updates)"}`,
684
+ `- MDEntryType: ${mdEntryType ?? "default (0 = Bid)"}`,
685
+ "",
686
+ "Format the response as a JSON object with FIX tag numbers as keys and their corresponding values."
687
+ ].join("\n")
688
+ }
689
+ }
690
+ ]
691
+ };
692
+ }
693
+ default:
694
+ throw new Error(`Unknown prompt: ${name}`);
695
+ }
696
+ });
697
+ process.on("SIGINT", async () => {
698
+ await this.server.close();
699
+ process.exit(0);
700
+ });
701
+ }
702
+ };
703
+ // Annotate the CommonJS export names for ESM import in node:
704
+ 0 && (module.exports = {
705
+ MCPLocal
706
+ });
707
+ //# sourceMappingURL=MCPLocal.js.map