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