fixparser-plugin-mcp 9.1.7-b2f9f891 → 9.1.7-b6430f19

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.
@@ -1,960 +0,0 @@
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_fixparser = require("fixparser");
29
- var import_zod = require("zod");
30
- var MCPLocal = class {
31
- parser;
32
- server = new import_server.Server(
33
- {
34
- name: "fixparser",
35
- version: "1.0.0"
36
- },
37
- {
38
- capabilities: {
39
- tools: {
40
- parse: {
41
- description: "Parses a FIX message and describes it in plain language",
42
- parameters: {
43
- type: "object",
44
- properties: {
45
- fixString: { type: "string" }
46
- },
47
- required: ["fixString"]
48
- }
49
- },
50
- parseToJSON: {
51
- description: "Parses a FIX message into JSON",
52
- parameters: {
53
- type: "object",
54
- properties: {
55
- fixString: { type: "string" }
56
- },
57
- required: ["fixString"]
58
- }
59
- },
60
- verifyOrder: {
61
- description: "Verifies order parameters before execution",
62
- parameters: {
63
- type: "object",
64
- properties: {
65
- clOrdID: { type: "string" },
66
- handlInst: { type: "string", enum: ["1", "2", "3"] },
67
- quantity: { type: "string" },
68
- price: { type: "string" },
69
- ordType: {
70
- type: "string",
71
- enum: [
72
- "1",
73
- "2",
74
- "3",
75
- "4",
76
- "5",
77
- "6",
78
- "7",
79
- "8",
80
- "9",
81
- "A",
82
- "B",
83
- "C",
84
- "D",
85
- "E",
86
- "F",
87
- "G",
88
- "H",
89
- "I",
90
- "J",
91
- "K",
92
- "L",
93
- "M",
94
- "P",
95
- "Q",
96
- "R",
97
- "S"
98
- ]
99
- },
100
- side: {
101
- type: "string",
102
- enum: [
103
- "1",
104
- "2",
105
- "3",
106
- "4",
107
- "5",
108
- "6",
109
- "7",
110
- "8",
111
- "9",
112
- "A",
113
- "B",
114
- "C",
115
- "D",
116
- "E",
117
- "F",
118
- "G",
119
- "H"
120
- ]
121
- },
122
- symbol: { type: "string" },
123
- timeInForce: {
124
- type: "string",
125
- enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
126
- }
127
- },
128
- required: [
129
- "clOrdID",
130
- "handlInst",
131
- "quantity",
132
- "price",
133
- "ordType",
134
- "side",
135
- "symbol",
136
- "timeInForce"
137
- ]
138
- }
139
- },
140
- executeOrder: {
141
- description: "Executes a verified order",
142
- parameters: {
143
- type: "object",
144
- properties: {
145
- clOrdID: { type: "string" },
146
- handlInst: { type: "string", enum: ["1", "2", "3"] },
147
- quantity: { type: "string" },
148
- price: { type: "string" },
149
- ordType: { type: "string" },
150
- side: { type: "string" },
151
- symbol: { type: "string" },
152
- timeInForce: { type: "string" }
153
- },
154
- required: [
155
- "clOrdID",
156
- "handlInst",
157
- "quantity",
158
- "price",
159
- "ordType",
160
- "side",
161
- "symbol",
162
- "timeInForce"
163
- ]
164
- }
165
- },
166
- marketDataRequest: {
167
- description: "Requests market data for specified symbols",
168
- parameters: {
169
- type: "object",
170
- properties: {
171
- mdUpdateType: { type: "string", enum: ["0", "1"] },
172
- symbols: { type: "array", items: { type: "string" } },
173
- mdReqID: { type: "string" },
174
- subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
175
- mdEntryTypes: { type: "array", items: { type: "string" } }
176
- },
177
- required: ["mdUpdateType", "symbols", "mdReqID", "subscriptionRequestType", "mdEntryTypes"]
178
- }
179
- }
180
- },
181
- resources: {
182
- greeting: {
183
- description: "A simple greeting resource",
184
- uri: "greeting-resource"
185
- },
186
- stockGraph: {
187
- description: "Generates a price chart for a given symbol",
188
- uri: "stockGraph",
189
- parameters: {
190
- type: "object",
191
- properties: {
192
- symbol: { type: "string" }
193
- },
194
- required: ["symbol"]
195
- }
196
- },
197
- stockPriceHistory: {
198
- description: "Returns price history for a given symbol",
199
- uri: "stockPriceHistory",
200
- parameters: {
201
- type: "object",
202
- properties: {
203
- symbol: { type: "string" }
204
- },
205
- required: ["symbol"]
206
- }
207
- }
208
- }
209
- }
210
- }
211
- );
212
- transport = new import_stdio.StdioServerTransport();
213
- onReady = void 0;
214
- pendingRequests = /* @__PURE__ */ new Map();
215
- verifiedOrders = /* @__PURE__ */ new Map();
216
- // Store market data prices with timestamps
217
- marketDataPrices = /* @__PURE__ */ new Map();
218
- MAX_PRICE_HISTORY = 1e5;
219
- // Maximum number of price points to store per symbol
220
- constructor({ logger, onReady }) {
221
- if (onReady) this.onReady = onReady;
222
- }
223
- async register(parser) {
224
- this.parser = parser;
225
- this.parser.addOnMessageCallback((message) => {
226
- this.parser?.logger.log({
227
- level: "info",
228
- message: `MCP Server received message: ${message.messageType}: ${message.description}`
229
- });
230
- const msgType = message.messageType;
231
- if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser.Messages.ExecutionReport || msgType === import_fixparser.Messages.Reject || msgType === import_fixparser.Messages.MarketDataIncrementalRefresh) {
232
- this.parser?.logger.log({
233
- level: "info",
234
- message: `MCP Server handling message type: ${msgType}`
235
- });
236
- let id;
237
- if (msgType === import_fixparser.Messages.MarketDataIncrementalRefresh || msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
238
- const symbol = message.getField(import_fixparser.Fields.Symbol);
239
- const price = message.getField(import_fixparser.Fields.MDEntryPx);
240
- const timestamp = message.getField(import_fixparser.Fields.MDEntryTime)?.value || Date.now();
241
- if (symbol?.value && price?.value) {
242
- const symbolStr = String(symbol.value);
243
- const priceNum = Number(price.value);
244
- const priceHistory = this.marketDataPrices.get(symbolStr) || [];
245
- priceHistory.push({
246
- timestamp: Number(timestamp),
247
- price: priceNum
248
- });
249
- if (priceHistory.length > this.MAX_PRICE_HISTORY) {
250
- priceHistory.shift();
251
- }
252
- this.marketDataPrices.set(symbolStr, priceHistory);
253
- this.parser?.logger.log({
254
- level: "info",
255
- message: `MCP Server added ${symbol}: ${priceNum}`
256
- });
257
- }
258
- }
259
- if (msgType === import_fixparser.Messages.MarketDataSnapshotFullRefresh) {
260
- const mdReqID = message.getField(import_fixparser.Fields.MDReqID);
261
- if (mdReqID) id = String(mdReqID.value);
262
- } else if (msgType === import_fixparser.Messages.ExecutionReport) {
263
- const clOrdID = message.getField(import_fixparser.Fields.ClOrdID);
264
- if (clOrdID) id = String(clOrdID.value);
265
- } else if (msgType === import_fixparser.Messages.Reject) {
266
- const refSeqNum = message.getField(import_fixparser.Fields.RefSeqNum);
267
- if (refSeqNum) id = String(refSeqNum.value);
268
- }
269
- if (id) {
270
- const callback = this.pendingRequests.get(id);
271
- if (callback) {
272
- callback(message);
273
- this.pendingRequests.delete(id);
274
- }
275
- }
276
- }
277
- });
278
- this.addWorkflows();
279
- await this.server.connect(this.transport);
280
- if (this.onReady) {
281
- this.onReady();
282
- }
283
- }
284
- addWorkflows() {
285
- if (!this.parser) {
286
- return;
287
- }
288
- if (!this.server) {
289
- return;
290
- }
291
- this.server.setRequestHandler(
292
- import_zod.z.object({ method: import_zod.z.literal("resources/list") }),
293
- async (request, extra) => {
294
- return {
295
- resources: [
296
- {
297
- name: "greeting",
298
- description: "A simple greeting resource",
299
- uri: "greeting-resource"
300
- },
301
- {
302
- name: "stockGraph",
303
- description: "Generates a price chart for a given symbol",
304
- uri: "stockGraph",
305
- parameters: {
306
- type: "object",
307
- properties: {
308
- symbol: { type: "string" }
309
- },
310
- required: ["symbol"]
311
- }
312
- },
313
- {
314
- name: "stockPriceHistory",
315
- description: "Returns price history for a given symbol",
316
- uri: "stockPriceHistory",
317
- parameters: {
318
- type: "object",
319
- properties: {
320
- symbol: { type: "string" }
321
- },
322
- required: ["symbol"]
323
- }
324
- }
325
- ]
326
- };
327
- }
328
- );
329
- this.server.setRequestHandler(
330
- import_zod.z.object({ method: import_zod.z.literal("tools/list") }),
331
- async (request, extra) => {
332
- return {
333
- tools: [
334
- {
335
- name: "parse",
336
- description: "Parses a FIX message and describes it in plain language",
337
- parameters: {
338
- type: "object",
339
- properties: {
340
- fixString: { type: "string" }
341
- },
342
- required: ["fixString"]
343
- }
344
- },
345
- {
346
- name: "parseToJSON",
347
- description: "Parses a FIX message into JSON",
348
- parameters: {
349
- type: "object",
350
- properties: {
351
- fixString: { type: "string" }
352
- },
353
- required: ["fixString"]
354
- }
355
- },
356
- {
357
- name: "verifyOrder",
358
- description: "Verifies order parameters before execution",
359
- parameters: {
360
- type: "object",
361
- properties: {
362
- clOrdID: { type: "string" },
363
- handlInst: { type: "string", enum: ["1", "2", "3"] },
364
- quantity: { type: "string" },
365
- price: { type: "string" },
366
- ordType: {
367
- type: "string",
368
- enum: [
369
- "1",
370
- "2",
371
- "3",
372
- "4",
373
- "5",
374
- "6",
375
- "7",
376
- "8",
377
- "9",
378
- "A",
379
- "B",
380
- "C",
381
- "D",
382
- "E",
383
- "F",
384
- "G",
385
- "H",
386
- "I",
387
- "J",
388
- "K",
389
- "L",
390
- "M",
391
- "P",
392
- "Q",
393
- "R",
394
- "S"
395
- ]
396
- },
397
- side: {
398
- type: "string",
399
- enum: [
400
- "1",
401
- "2",
402
- "3",
403
- "4",
404
- "5",
405
- "6",
406
- "7",
407
- "8",
408
- "9",
409
- "A",
410
- "B",
411
- "C",
412
- "D",
413
- "E",
414
- "F",
415
- "G",
416
- "H"
417
- ]
418
- },
419
- symbol: { type: "string" },
420
- timeInForce: {
421
- type: "string",
422
- enum: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
423
- }
424
- },
425
- required: [
426
- "clOrdID",
427
- "handlInst",
428
- "quantity",
429
- "price",
430
- "ordType",
431
- "side",
432
- "symbol",
433
- "timeInForce"
434
- ]
435
- }
436
- },
437
- {
438
- name: "executeOrder",
439
- description: "Executes a verified order",
440
- parameters: {
441
- type: "object",
442
- properties: {
443
- clOrdID: { type: "string" },
444
- handlInst: { type: "string", enum: ["1", "2", "3"] },
445
- quantity: { type: "string" },
446
- price: { type: "string" },
447
- ordType: { type: "string" },
448
- side: { type: "string" },
449
- symbol: { type: "string" },
450
- timeInForce: { type: "string" }
451
- },
452
- required: [
453
- "clOrdID",
454
- "handlInst",
455
- "quantity",
456
- "price",
457
- "ordType",
458
- "side",
459
- "symbol",
460
- "timeInForce"
461
- ]
462
- }
463
- },
464
- {
465
- name: "marketDataRequest",
466
- description: "Requests market data for specified symbols",
467
- parameters: {
468
- type: "object",
469
- properties: {
470
- mdUpdateType: { type: "string", enum: ["0", "1"] },
471
- symbols: { type: "array", items: { type: "string" } },
472
- mdReqID: { type: "string" },
473
- subscriptionRequestType: { type: "string", enum: ["0", "1", "2"] },
474
- mdEntryTypes: { type: "array", items: { type: "string" } }
475
- },
476
- required: [
477
- "mdUpdateType",
478
- "symbols",
479
- "mdReqID",
480
- "subscriptionRequestType",
481
- "mdEntryTypes"
482
- ]
483
- }
484
- }
485
- ]
486
- };
487
- }
488
- );
489
- this.server.setRequestHandler(import_zod.z.object({ method: import_zod.z.literal("parse") }), async (request, extra) => {
490
- try {
491
- const args = request.params;
492
- const parsedMessage = this.parser?.parse(args.fixString);
493
- if (!parsedMessage || parsedMessage.length === 0) {
494
- return {
495
- content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
496
- isError: true
497
- };
498
- }
499
- return {
500
- content: [
501
- {
502
- type: "text",
503
- text: `${parsedMessage[0].description}
504
- ${parsedMessage[0].messageTypeDescription}`
505
- }
506
- ]
507
- };
508
- } catch (error) {
509
- return {
510
- content: [
511
- {
512
- type: "text",
513
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
514
- }
515
- ],
516
- isError: true
517
- };
518
- }
519
- });
520
- this.server.setRequestHandler(
521
- import_zod.z.object({ method: import_zod.z.literal("parseToJSON") }),
522
- async (request, extra) => {
523
- try {
524
- const args = request.params;
525
- const parsedMessage = this.parser?.parse(args.fixString);
526
- if (!parsedMessage || parsedMessage.length === 0) {
527
- return {
528
- content: [{ type: "text", text: "Error: Failed to parse FIX string" }],
529
- isError: true
530
- };
531
- }
532
- return {
533
- content: [
534
- {
535
- type: "text",
536
- text: `${parsedMessage[0].toFIXJSON()}`
537
- }
538
- ]
539
- };
540
- } catch (error) {
541
- return {
542
- content: [
543
- {
544
- type: "text",
545
- text: `Error: ${error instanceof Error ? error.message : "Failed to parse FIX string"}`
546
- }
547
- ],
548
- isError: true
549
- };
550
- }
551
- }
552
- );
553
- this.server.setRequestHandler(
554
- import_zod.z.object({ method: import_zod.z.literal("verifyOrder") }),
555
- async (request, extra) => {
556
- try {
557
- const args = request.params;
558
- this.verifiedOrders.set(args.clOrdID, {
559
- clOrdID: args.clOrdID,
560
- handlInst: args.handlInst,
561
- quantity: Number.parseFloat(args.quantity),
562
- price: Number.parseFloat(args.price),
563
- ordType: args.ordType,
564
- side: args.side,
565
- symbol: args.symbol,
566
- timeInForce: args.timeInForce
567
- });
568
- const ordTypeNames = {
569
- "1": "Market",
570
- "2": "Limit",
571
- "3": "Stop",
572
- "4": "StopLimit",
573
- "5": "MarketOnClose",
574
- "6": "WithOrWithout",
575
- "7": "LimitOrBetter",
576
- "8": "LimitWithOrWithout",
577
- "9": "OnBasis",
578
- A: "OnClose",
579
- B: "LimitOnClose",
580
- C: "ForexMarket",
581
- D: "PreviouslyQuoted",
582
- E: "PreviouslyIndicated",
583
- F: "ForexLimit",
584
- G: "ForexSwap",
585
- H: "ForexPreviouslyQuoted",
586
- I: "Funari",
587
- J: "MarketIfTouched",
588
- K: "MarketWithLeftOverAsLimit",
589
- L: "PreviousFundValuationPoint",
590
- M: "NextFundValuationPoint",
591
- P: "Pegged",
592
- Q: "CounterOrderSelection",
593
- R: "StopOnBidOrOffer",
594
- S: "StopLimitOnBidOrOffer"
595
- };
596
- const sideNames = {
597
- "1": "Buy",
598
- "2": "Sell",
599
- "3": "BuyMinus",
600
- "4": "SellPlus",
601
- "5": "SellShort",
602
- "6": "SellShortExempt",
603
- "7": "Undisclosed",
604
- "8": "Cross",
605
- "9": "CrossShort",
606
- A: "CrossShortExempt",
607
- B: "AsDefined",
608
- C: "Opposite",
609
- D: "Subscribe",
610
- E: "Redeem",
611
- F: "Lend",
612
- G: "Borrow",
613
- H: "SellUndisclosed"
614
- };
615
- const timeInForceNames = {
616
- "0": "Day",
617
- "1": "GoodTillCancel",
618
- "2": "AtTheOpening",
619
- "3": "ImmediateOrCancel",
620
- "4": "FillOrKill",
621
- "5": "GoodTillCrossing",
622
- "6": "GoodTillDate",
623
- "7": "AtTheClose",
624
- "8": "GoodThroughCrossing",
625
- "9": "AtCrossing",
626
- A: "GoodForTime",
627
- B: "GoodForAuction",
628
- C: "GoodForMonth"
629
- };
630
- const handlInstNames = {
631
- "1": "AutomatedExecutionNoIntervention",
632
- "2": "AutomatedExecutionInterventionOK",
633
- "3": "ManualOrder"
634
- };
635
- return {
636
- content: [
637
- {
638
- type: "text",
639
- text: `VERIFICATION: All parameters valid. Ready to proceed with order execution.
640
-
641
- Parameters verified:
642
- - ClOrdID: ${args.clOrdID}
643
- - HandlInst: ${args.handlInst} (${handlInstNames[args.handlInst]})
644
- - Quantity: ${args.quantity}
645
- - Price: ${args.price}
646
- - OrdType: ${args.ordType} (${ordTypeNames[args.ordType]})
647
- - Side: ${args.side} (${sideNames[args.side]})
648
- - Symbol: ${args.symbol}
649
- - TimeInForce: ${args.timeInForce} (${timeInForceNames[args.timeInForce]})
650
-
651
- To execute this order, call the executeOrder tool with these exact same parameters.`
652
- }
653
- ]
654
- };
655
- } catch (error) {
656
- return {
657
- content: [
658
- {
659
- type: "text",
660
- text: `Error: ${error instanceof Error ? error.message : "Failed to verify order parameters"}`
661
- }
662
- ],
663
- isError: true
664
- };
665
- }
666
- }
667
- );
668
- this.server.setRequestHandler(
669
- import_zod.z.object({ method: import_zod.z.literal("executeOrder") }),
670
- async (request, extra) => {
671
- try {
672
- const args = request.params;
673
- const verifiedOrder = this.verifiedOrders.get(args.clOrdID);
674
- if (!verifiedOrder) {
675
- return {
676
- content: [
677
- {
678
- type: "text",
679
- text: `Error: Order ${args.clOrdID} has not been verified. Please call verifyOrder first.`
680
- }
681
- ],
682
- isError: true
683
- };
684
- }
685
- 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) {
686
- return {
687
- content: [
688
- {
689
- type: "text",
690
- text: "Error: Order parameters do not match the verified order. Please use the exact same parameters that were verified."
691
- }
692
- ],
693
- isError: true
694
- };
695
- }
696
- const response = new Promise((resolve) => {
697
- this.pendingRequests.set(args.clOrdID, resolve);
698
- });
699
- const order = this.parser?.createMessage(
700
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.NewOrderSingle),
701
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
702
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
703
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
704
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
705
- new import_fixparser.Field(import_fixparser.Fields.ClOrdID, args.clOrdID),
706
- new import_fixparser.Field(import_fixparser.Fields.Side, args.side),
707
- new import_fixparser.Field(import_fixparser.Fields.Symbol, args.symbol),
708
- new import_fixparser.Field(import_fixparser.Fields.OrderQty, Number.parseFloat(args.quantity)),
709
- new import_fixparser.Field(import_fixparser.Fields.Price, Number.parseFloat(args.price)),
710
- new import_fixparser.Field(import_fixparser.Fields.OrdType, args.ordType),
711
- new import_fixparser.Field(import_fixparser.Fields.HandlInst, args.handlInst),
712
- new import_fixparser.Field(import_fixparser.Fields.TimeInForce, args.timeInForce),
713
- new import_fixparser.Field(import_fixparser.Fields.TransactTime, this.parser?.getTimestamp())
714
- );
715
- if (!this.parser?.connected) {
716
- return {
717
- content: [
718
- {
719
- type: "text",
720
- text: "Error: Not connected. Ignoring message."
721
- }
722
- ],
723
- isError: true
724
- };
725
- }
726
- this.parser?.send(order);
727
- const fixData = await response;
728
- this.verifiedOrders.delete(args.clOrdID);
729
- return {
730
- content: [
731
- {
732
- type: "text",
733
- 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())}`
734
- }
735
- ]
736
- };
737
- } catch (error) {
738
- return {
739
- content: [
740
- {
741
- type: "text",
742
- text: `Error: ${error instanceof Error ? error.message : "Failed to execute order"}`
743
- }
744
- ],
745
- isError: true
746
- };
747
- }
748
- }
749
- );
750
- this.server.setRequestHandler(
751
- import_zod.z.object({ method: import_zod.z.literal("marketDataRequest") }),
752
- async (request, extra) => {
753
- try {
754
- const args = request.params;
755
- const response = new Promise((resolve) => {
756
- this.pendingRequests.set(args.mdReqID, resolve);
757
- });
758
- const messageFields = [
759
- new import_fixparser.Field(import_fixparser.Fields.MsgType, import_fixparser.Messages.MarketDataRequest),
760
- new import_fixparser.Field(import_fixparser.Fields.SenderCompID, this.parser?.sender),
761
- new import_fixparser.Field(import_fixparser.Fields.MsgSeqNum, this.parser?.getNextTargetMsgSeqNum()),
762
- new import_fixparser.Field(import_fixparser.Fields.TargetCompID, this.parser?.target),
763
- new import_fixparser.Field(import_fixparser.Fields.SendingTime, this.parser?.getTimestamp()),
764
- new import_fixparser.Field(import_fixparser.Fields.MDReqID, args.mdReqID),
765
- new import_fixparser.Field(import_fixparser.Fields.SubscriptionRequestType, args.subscriptionRequestType),
766
- new import_fixparser.Field(import_fixparser.Fields.MarketDepth, 0),
767
- new import_fixparser.Field(import_fixparser.Fields.MDUpdateType, args.mdUpdateType)
768
- ];
769
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoRelatedSym, args.symbols.length));
770
- args.symbols.forEach((symbol) => {
771
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.Symbol, symbol));
772
- });
773
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.NoMDEntryTypes, args.mdEntryTypes.length));
774
- args.mdEntryTypes.forEach((entryType) => {
775
- messageFields.push(new import_fixparser.Field(import_fixparser.Fields.MDEntryType, entryType));
776
- });
777
- const mdr = this.parser?.createMessage(...messageFields);
778
- if (!this.parser?.connected) {
779
- return {
780
- content: [
781
- {
782
- type: "text",
783
- text: "Error: Not connected. Ignoring message."
784
- }
785
- ],
786
- isError: true
787
- };
788
- }
789
- this.parser?.send(mdr);
790
- const fixData = await response;
791
- return {
792
- content: [
793
- {
794
- type: "text",
795
- text: `Market data for ${args.symbols.join(", ")}: ${JSON.stringify(fixData.toFIXJSON())}`
796
- }
797
- ]
798
- };
799
- } catch (error) {
800
- return {
801
- content: [
802
- {
803
- type: "text",
804
- text: `Error: ${error instanceof Error ? error.message : "Failed to request market data"}`
805
- }
806
- ],
807
- isError: true
808
- };
809
- }
810
- }
811
- );
812
- this.server.setRequestHandler(
813
- import_zod.z.object({ method: import_zod.z.literal("greeting-resource") }),
814
- async (request, extra) => {
815
- this.parser?.logger.log({
816
- level: "info",
817
- message: "MCP Server Resource called: greeting-resource"
818
- });
819
- return {
820
- content: [
821
- {
822
- type: "text",
823
- text: "Hello, world!"
824
- }
825
- ]
826
- };
827
- }
828
- );
829
- this.server.setRequestHandler(
830
- import_zod.z.object({ method: import_zod.z.literal("stockGraph") }),
831
- async (request, extra) => {
832
- this.parser?.logger.log({
833
- level: "info",
834
- message: "MCP Server Resource called: stockGraph"
835
- });
836
- const args = request.params;
837
- const symbol = args.symbol;
838
- const priceHistory = this.marketDataPrices.get(symbol) || [];
839
- if (priceHistory.length === 0) {
840
- return {
841
- content: [
842
- {
843
- type: "text",
844
- text: `No price data available for ${symbol}`
845
- }
846
- ]
847
- };
848
- }
849
- const width = 600;
850
- const height = 300;
851
- const padding = 40;
852
- const xScale = (width - 2 * padding) / (priceHistory.length - 1);
853
- const yMin = Math.min(...priceHistory.map((d) => d.price));
854
- const yMax = Math.max(...priceHistory.map((d) => d.price));
855
- const yScale = (height - 2 * padding) / (yMax - yMin);
856
- const points = priceHistory.map((d, i) => {
857
- const x = padding + i * xScale;
858
- const y = height - padding - (d.price - yMin) * yScale;
859
- return `${x},${y}`;
860
- }).join(" L ");
861
- const svg = `<?xml version="1.0" encoding="UTF-8"?>
862
- <svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
863
- <!-- Background -->
864
- <rect width="100%" height="100%" fill="#f8f9fa"/>
865
-
866
- <!-- Grid lines -->
867
- <g stroke="#e9ecef" stroke-width="1">
868
- ${Array.from({ length: 5 }, (_, i) => {
869
- const y = padding + (height - 2 * padding) * i / 4;
870
- return `<line x1="${padding}" y1="${y}" x2="${width - padding}" y2="${y}"/>`;
871
- }).join("\n")}
872
- </g>
873
-
874
- <!-- Price line -->
875
- <path d="M ${points}"
876
- fill="none"
877
- stroke="#007bff"
878
- stroke-width="2"/>
879
-
880
- <!-- Data points -->
881
- ${priceHistory.map((d, i) => {
882
- const x = padding + i * xScale;
883
- const y = height - padding - (d.price - yMin) * yScale;
884
- return `<circle cx="${x}" cy="${y}" r="3" fill="#007bff"/>`;
885
- }).join("\n")}
886
-
887
- <!-- Labels -->
888
- <g font-family="Arial" font-size="12" fill="#495057">
889
- ${Array.from({ length: 5 }, (_, i) => {
890
- const x = padding + (width - 2 * padding) * i / 4;
891
- const index = Math.floor((priceHistory.length - 1) * i / 4);
892
- const timestamp = new Date(priceHistory[index].timestamp).toLocaleTimeString();
893
- return `<text x="${x + padding}" y="${height - padding + 20}" text-anchor="middle">${timestamp}</text>`;
894
- }).join("\n")}
895
- ${Array.from({ length: 5 }, (_, i) => {
896
- const y = padding + (height - 2 * padding) * i / 4;
897
- const price = yMax - (yMax - yMin) * i / 4;
898
- return `<text x="${padding - 5}" y="${y + 4}" text-anchor="end">$${price.toFixed(2)}</text>`;
899
- }).join("\n")}
900
- </g>
901
-
902
- <!-- Title -->
903
- <text x="${width / 2}" y="${padding / 2}"
904
- font-family="Arial" font-size="16" font-weight="bold"
905
- text-anchor="middle" fill="#212529">
906
- ${symbol} - Price Chart (${priceHistory.length} points)
907
- </text>
908
- </svg>`;
909
- return {
910
- content: [
911
- {
912
- type: "text",
913
- text: svg
914
- }
915
- ]
916
- };
917
- }
918
- );
919
- this.server.setRequestHandler(
920
- import_zod.z.object({ method: import_zod.z.literal("stockPriceHistory") }),
921
- async (request, extra) => {
922
- this.parser?.logger.log({
923
- level: "info",
924
- message: "MCP Server Resource called: stockPriceHistory"
925
- });
926
- const args = request.params;
927
- const symbol = args.symbol;
928
- const priceHistory = this.marketDataPrices.get(symbol) || [];
929
- return {
930
- content: [
931
- {
932
- type: "text",
933
- text: JSON.stringify(
934
- {
935
- symbol,
936
- count: priceHistory.length,
937
- prices: priceHistory.map((point) => ({
938
- timestamp: new Date(point.timestamp).toISOString(),
939
- price: point.price
940
- }))
941
- },
942
- null,
943
- 2
944
- )
945
- }
946
- ]
947
- };
948
- }
949
- );
950
- process.on("SIGINT", async () => {
951
- await this.server.close();
952
- process.exit(0);
953
- });
954
- }
955
- };
956
- // Annotate the CommonJS export names for ESM import in node:
957
- 0 && (module.exports = {
958
- MCPLocal
959
- });
960
- //# sourceMappingURL=MCPLocal.js.map