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