fixparser-plugin-mcp 9.1.7-555b7cf3 → 9.1.7-57d70bb1

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.
@@ -166,7 +166,7 @@ var toolSchemas = {
166
166
  }
167
167
  },
168
168
  executeOrder: {
169
- description: "Executes a verified order. verifyOrder must be called before executeOrder.",
169
+ description: "Executes a verified order. verifyOrder must be called before executeOrder. user has to explicitly allow executeOrder.",
170
170
  schema: {
171
171
  type: "object",
172
172
  properties: {
@@ -847,7 +847,7 @@ function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPr
847
847
  message: `MCP Server received message: ${message.messageType}: ${message.description}`
848
848
  });
849
849
  const msgType = message.messageType;
850
- if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh || msgType === import_fixparser3.Messages.MarketDataIncrementalRefresh) {
850
+ if (msgType === import_fixparser3.Messages.MarketDataSnapshotFullRefresh) {
851
851
  const symbol = message.getField(import_fixparser3.Fields.Symbol)?.value;
852
852
  const entries = message.getField(import_fixparser3.Fields.NoMDEntries)?.value;
853
853
  let bid = 0;
@@ -899,39 +899,6 @@ function handleMessage(message, parser, pendingRequests, marketDataPrices, maxPr
899
899
 
900
900
  // src/MCPRemote.ts
901
901
  var transports = {};
902
- function jsonSchemaToZod(schema) {
903
- if (schema.type === "object") {
904
- const shape = {};
905
- for (const [key, prop] of Object.entries(schema.properties || {})) {
906
- const propSchema = prop;
907
- if (propSchema.type === "string") {
908
- if (propSchema.enum) {
909
- shape[key] = import_zod.z.enum(propSchema.enum);
910
- } else {
911
- shape[key] = import_zod.z.string();
912
- }
913
- } else if (propSchema.type === "number") {
914
- shape[key] = import_zod.z.number();
915
- } else if (propSchema.type === "boolean") {
916
- shape[key] = import_zod.z.boolean();
917
- } else if (propSchema.type === "array") {
918
- if (propSchema.items.type === "string") {
919
- shape[key] = import_zod.z.array(import_zod.z.string());
920
- } else if (propSchema.items.type === "number") {
921
- shape[key] = import_zod.z.array(import_zod.z.number());
922
- } else if (propSchema.items.type === "boolean") {
923
- shape[key] = import_zod.z.array(import_zod.z.boolean());
924
- } else {
925
- shape[key] = import_zod.z.array(import_zod.z.any());
926
- }
927
- } else {
928
- shape[key] = import_zod.z.any();
929
- }
930
- }
931
- return shape;
932
- }
933
- return {};
934
- }
935
902
  var MCPRemote = class extends MCPBase {
936
903
  /**
937
904
  * Port number the server will listen on.
@@ -996,30 +963,42 @@ var MCPRemote = class extends MCPBase {
996
963
  this.parser,
997
964
  this.pendingRequests,
998
965
  this.marketDataPrices,
999
- this.MAX_PRICE_HISTORY
966
+ this.MAX_PRICE_HISTORY,
967
+ (symbol, data) => {
968
+ this.mcpServer?.tool(
969
+ "priceUpdate",
970
+ {
971
+ description: "Price update notification",
972
+ schema: import_zod.z.object({
973
+ symbol: import_zod.z.string(),
974
+ timestamp: import_zod.z.number(),
975
+ bid: import_zod.z.number(),
976
+ offer: import_zod.z.number(),
977
+ spread: import_zod.z.number(),
978
+ volume: import_zod.z.number()
979
+ })
980
+ },
981
+ () => ({
982
+ content: [
983
+ {
984
+ type: "text",
985
+ text: JSON.stringify({ symbol, ...data })
986
+ }
987
+ ]
988
+ })
989
+ );
990
+ }
1000
991
  );
1001
992
  }
1002
993
  });
1003
994
  this.httpServer = (0, import_node_http.createServer)(async (req, res) => {
1004
- this.logger?.log({
1005
- level: "info",
1006
- message: `Incoming request: ${req.method} ${req.url}`
1007
- });
1008
995
  if (!req.url || !req.method) {
1009
- this.logger?.log({
1010
- level: "error",
1011
- message: "Invalid request: missing URL or method"
1012
- });
1013
996
  res.writeHead(400);
1014
997
  res.end("Bad Request");
1015
998
  return;
1016
999
  }
1017
1000
  if (req.url === "/mcp") {
1018
1001
  const sessionId = req.headers["mcp-session-id"];
1019
- this.logger?.log({
1020
- level: "info",
1021
- message: `MCP request received. Session ID: ${sessionId || "none"}, headers: ${req.headers}`
1022
- });
1023
1002
  if (req.method === "POST") {
1024
1003
  const bodyChunks = [];
1025
1004
  req.on("data", (chunk) => {
@@ -1030,47 +1009,23 @@ var MCPRemote = class extends MCPBase {
1030
1009
  const body = Buffer.concat(bodyChunks).toString();
1031
1010
  try {
1032
1011
  parsed = JSON.parse(body);
1033
- this.logger?.log({
1034
- level: "info",
1035
- message: `Parsed request body: ${JSON.stringify(parsed)}`
1036
- });
1037
1012
  } catch (err) {
1038
- this.logger?.log({
1039
- level: "error",
1040
- message: `Failed to parse JSON body: ${err}`
1041
- });
1042
1013
  res.writeHead(400);
1043
1014
  res.end(JSON.stringify({ error: "Invalid JSON" }));
1044
1015
  return;
1045
1016
  }
1046
1017
  let transport;
1047
1018
  if (sessionId && transports[sessionId]) {
1048
- this.logger?.log({
1049
- level: "info",
1050
- message: `Using existing transport for session: ${sessionId}`
1051
- });
1052
1019
  transport = transports[sessionId];
1053
1020
  } else if (!sessionId && req.method === "POST" && (0, import_types.isInitializeRequest)(parsed)) {
1054
- this.logger?.log({
1055
- level: "info",
1056
- message: "Creating new transport for initialization request"
1057
- });
1058
1021
  transport = new import_streamableHttp.StreamableHTTPServerTransport({
1059
1022
  sessionIdGenerator: () => (0, import_node_crypto.randomUUID)(),
1060
1023
  onsessioninitialized: (sessionId2) => {
1061
- this.logger?.log({
1062
- level: "info",
1063
- message: `New session initialized: ${sessionId2}`
1064
- });
1065
1024
  transports[sessionId2] = transport;
1066
1025
  }
1067
1026
  });
1068
1027
  transport.onclose = () => {
1069
1028
  if (transport.sessionId) {
1070
- this.logger?.log({
1071
- level: "info",
1072
- message: `Session closed: ${transport.sessionId}`
1073
- });
1074
1029
  delete transports[transport.sessionId];
1075
1030
  }
1076
1031
  };
@@ -1081,10 +1036,6 @@ var MCPRemote = class extends MCPBase {
1081
1036
  this.setupTools();
1082
1037
  await this.mcpServer.connect(transport);
1083
1038
  } else {
1084
- this.logger?.log({
1085
- level: "error",
1086
- message: "Invalid request: No valid session ID provided"
1087
- });
1088
1039
  res.writeHead(400, { "Content-Type": "application/json" });
1089
1040
  res.end(
1090
1041
  JSON.stringify({
@@ -1098,57 +1049,21 @@ var MCPRemote = class extends MCPBase {
1098
1049
  );
1099
1050
  return;
1100
1051
  }
1101
- try {
1102
- await transport.handleRequest(req, res, parsed);
1103
- this.logger?.log({
1104
- level: "info",
1105
- message: "Request handled successfully"
1106
- });
1107
- } catch (error) {
1108
- this.logger?.log({
1109
- level: "error",
1110
- message: `Error handling request: ${error}`
1111
- });
1112
- throw error;
1113
- }
1052
+ await transport.handleRequest(req, res, parsed);
1114
1053
  });
1115
1054
  } else if (req.method === "GET" || req.method === "DELETE") {
1116
1055
  if (!sessionId || !transports[sessionId]) {
1117
- this.logger?.log({
1118
- level: "error",
1119
- message: `Invalid session ID for ${req.method} request: ${sessionId}`
1120
- });
1121
1056
  res.writeHead(400);
1122
1057
  res.end("Invalid or missing session ID");
1123
1058
  return;
1124
1059
  }
1125
1060
  const transport = transports[sessionId];
1126
- try {
1127
- await transport.handleRequest(req, res);
1128
- this.logger?.log({
1129
- level: "info",
1130
- message: `${req.method} request handled successfully for session: ${sessionId}`
1131
- });
1132
- } catch (error) {
1133
- this.logger?.log({
1134
- level: "error",
1135
- message: `Error handling ${req.method} request: ${error}`
1136
- });
1137
- throw error;
1138
- }
1061
+ await transport.handleRequest(req, res);
1139
1062
  } else {
1140
- this.logger?.log({
1141
- level: "error",
1142
- message: `Method not allowed: ${req.method}`
1143
- });
1144
1063
  res.writeHead(405);
1145
1064
  res.end("Method Not Allowed");
1146
1065
  }
1147
1066
  } else {
1148
- this.logger?.log({
1149
- level: "error",
1150
- message: `Not found: ${req.url}`
1151
- });
1152
1067
  res.writeHead(404);
1153
1068
  res.end("Not Found");
1154
1069
  }
@@ -1178,40 +1093,69 @@ var MCPRemote = class extends MCPBase {
1178
1093
  });
1179
1094
  return;
1180
1095
  }
1181
- const toolHandlers = createToolHandlers(
1182
- this.parser,
1183
- this.verifiedOrders,
1184
- this.pendingRequests,
1185
- this.marketDataPrices
1096
+ this.mcpServer.tool(
1097
+ "tools/list",
1098
+ {
1099
+ description: "List available tools",
1100
+ schema: import_zod.z.object({})
1101
+ },
1102
+ async () => {
1103
+ return {
1104
+ content: [
1105
+ {
1106
+ type: "text",
1107
+ text: JSON.stringify(
1108
+ Object.entries(toolSchemas).map(([name, { description, schema }]) => ({
1109
+ name,
1110
+ description,
1111
+ inputSchema: schema
1112
+ }))
1113
+ )
1114
+ }
1115
+ ]
1116
+ };
1117
+ }
1186
1118
  );
1187
- Object.entries(toolSchemas).forEach(([name, { description, schema }]) => {
1188
- this.mcpServer?.registerTool(
1189
- name,
1190
- {
1191
- description,
1192
- inputSchema: jsonSchemaToZod(schema)
1193
- },
1194
- async (args) => {
1195
- const handler = toolHandlers[name];
1196
- if (!handler) {
1197
- return {
1198
- content: [
1199
- {
1200
- type: "text",
1201
- text: `Tool not found: ${name}`
1202
- }
1203
- ],
1204
- isError: true
1205
- };
1206
- }
1207
- const result = await handler(args);
1119
+ this.mcpServer.tool(
1120
+ "tools/call",
1121
+ {
1122
+ description: "Call a tool",
1123
+ schema: import_zod.z.object({
1124
+ name: import_zod.z.string(),
1125
+ arguments: import_zod.z.any(),
1126
+ _meta: import_zod.z.object({
1127
+ progressToken: import_zod.z.number()
1128
+ }).optional()
1129
+ })
1130
+ },
1131
+ async (request) => {
1132
+ const { name, arguments: args } = request;
1133
+ const toolHandlers = createToolHandlers(
1134
+ this.parser,
1135
+ this.verifiedOrders,
1136
+ this.pendingRequests,
1137
+ this.marketDataPrices
1138
+ );
1139
+ const handler = toolHandlers[name];
1140
+ if (!handler) {
1208
1141
  return {
1209
- content: result.content,
1210
- isError: result.isError
1142
+ content: [
1143
+ {
1144
+ type: "text",
1145
+ text: `Tool not found: ${name}`,
1146
+ uri: name
1147
+ }
1148
+ ],
1149
+ isError: true
1211
1150
  };
1212
1151
  }
1213
- );
1214
- });
1152
+ const result = await handler(args);
1153
+ return {
1154
+ content: result.content,
1155
+ isError: result.isError
1156
+ };
1157
+ }
1158
+ );
1215
1159
  }
1216
1160
  };
1217
1161
  // Annotate the CommonJS export names for ESM import in node: