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:
@@ -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
@@ -75,20 +75,24 @@ function sendNotification(clientWs, channelPath, notificationType, data, mcpOnly
|
||||
|
||||
// Also send to MCP if connected
|
||||
if (channels[MCP_PATH] && channels[MCP_PATH].size > 0) {
|
||||
channels[MCP_PATH].values().forEach((mcpClient) => {
|
||||
if (mcpClient && mcpClient.readyState === WebSocket.OPEN) {
|
||||
// For MCP, prefix names with the channel path
|
||||
const mcpData = {...data};
|
||||
if (mcpData.name && channelPath) {
|
||||
mcpData.name = `${channelPath.slice(1)}-${mcpData.name}`;
|
||||
}
|
||||
try {
|
||||
for (const mcpClient of channels[MCP_PATH]) {
|
||||
if (mcpClient && mcpClient.readyState === WebSocket.OPEN) {
|
||||
// For MCP, prefix names with the channel path
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,11 +409,12 @@ wss.on('connection', (ws, req) => {
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error processing WebSocket message:', error);
|
||||
const msgPreview = typeof message === 'string' ? message.slice(0, 200) : String(message).slice(0, 200);
|
||||
console.error(`Error processing WebSocket message on ${clientChannel}:`, error.message, '\nRaw message preview:', msgPreview);
|
||||
try {
|
||||
ws.send(JSON.stringify({
|
||||
type: 'error',
|
||||
message: 'Invalid message format'
|
||||
message: `Error: ${error.message}`
|
||||
}));
|
||||
} catch (sendError) {
|
||||
console.error('Error sending error response:', sendError);
|
||||
|
||||
Reference in New Issue
Block a user