fixparser-plugin-mcp 9.1.7-a0e655a2 → 9.1.7-a9d84740

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