Fix error en sendNotification al notificar MCP client

- Envolver notificacion al MCP en try-catch para que fallos no
  se propaguen al handler del browser como "Invalid message format"
- Cambiar .values().forEach() por for...of (mas robusto)
- Mejorar catch block: incluir error.message real en la respuesta
  al browser y preview del mensaje raw en el log del servidor
This commit is contained in:
2026-02-13 02:46:43 -06:00
parent 8b2253355f
commit 4fa3ba9517
3 changed files with 38 additions and 28 deletions

View File

@@ -25601,18 +25601,22 @@ function sendNotification(clientWs, channelPath, notificationType, data, mcpOnly
}
}
if (channels[MCP_PATH2] && channels[MCP_PATH2].size > 0) {
channels[MCP_PATH2].values().forEach((mcpClient) => {
if (mcpClient && mcpClient.readyState === import_websocket.default.OPEN) {
const mcpData = { ...data };
if (mcpData.name && channelPath) {
mcpData.name = `${channelPath.slice(1)}-${mcpData.name}`;
try {
for (const mcpClient of channels[MCP_PATH2]) {
if (mcpClient && mcpClient.readyState === import_websocket.default.OPEN) {
const mcpData = { ...data };
if (mcpData.name && channelPath) {
mcpData.name = `${channelPath.slice(1)}-${mcpData.name}`;
}
mcpClient.send(JSON.stringify({
type: notificationType,
...mcpData
}));
}
mcpClient.send(JSON.stringify({
type: notificationType,
...mcpData
}));
}
});
} catch (e) {
console.error("Error sending notification to MCP:", e.message);
}
}
}
var toolsRegistry = {};
@@ -25833,11 +25837,12 @@ wss.on("connection", (ws, req) => {
}));
}
} catch (error2) {
console.error("Error processing WebSocket message:", error2);
const msgPreview = typeof message === "string" ? message.slice(0, 200) : String(message).slice(0, 200);
console.error(`Error processing WebSocket message on ${clientChannel}:`, error2.message, "\nRaw message preview:", msgPreview);
try {
ws.send(JSON.stringify({
type: "error",
message: "Invalid message format"
message: `Error: ${error2.message}`
}));
} catch (sendError) {
console.error("Error sending error response:", sendError);

File diff suppressed because one or more lines are too long