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) {
|
if (channels[MCP_PATH2] && channels[MCP_PATH2].size > 0) {
|
||||||
channels[MCP_PATH2].values().forEach((mcpClient) => {
|
try {
|
||||||
if (mcpClient && mcpClient.readyState === import_websocket.default.OPEN) {
|
for (const mcpClient of channels[MCP_PATH2]) {
|
||||||
const mcpData = { ...data };
|
if (mcpClient && mcpClient.readyState === import_websocket.default.OPEN) {
|
||||||
if (mcpData.name && channelPath) {
|
const mcpData = { ...data };
|
||||||
mcpData.name = `${channelPath.slice(1)}-${mcpData.name}`;
|
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 = {};
|
var toolsRegistry = {};
|
||||||
@@ -25833,11 +25837,12 @@ wss.on("connection", (ws, req) => {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
} catch (error2) {
|
} 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 {
|
try {
|
||||||
ws.send(JSON.stringify({
|
ws.send(JSON.stringify({
|
||||||
type: "error",
|
type: "error",
|
||||||
message: "Invalid message format"
|
message: `Error: ${error2.message}`
|
||||||
}));
|
}));
|
||||||
} catch (sendError) {
|
} catch (sendError) {
|
||||||
console.error("Error sending error response:", 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
|
// Also send to MCP if connected
|
||||||
if (channels[MCP_PATH] && channels[MCP_PATH].size > 0) {
|
if (channels[MCP_PATH] && channels[MCP_PATH].size > 0) {
|
||||||
channels[MCP_PATH].values().forEach((mcpClient) => {
|
try {
|
||||||
if (mcpClient && mcpClient.readyState === WebSocket.OPEN) {
|
for (const mcpClient of channels[MCP_PATH]) {
|
||||||
// For MCP, prefix names with the channel path
|
if (mcpClient && mcpClient.readyState === WebSocket.OPEN) {
|
||||||
const mcpData = {...data};
|
// For MCP, prefix names with the channel path
|
||||||
if (mcpData.name && channelPath) {
|
const mcpData = {...data};
|
||||||
mcpData.name = `${channelPath.slice(1)}-${mcpData.name}`;
|
if (mcpData.name && channelPath) {
|
||||||
}
|
mcpData.name = `${channelPath.slice(1)}-${mcpData.name}`;
|
||||||
|
}
|
||||||
|
|
||||||
mcpClient.send(JSON.stringify({
|
mcpClient.send(JSON.stringify({
|
||||||
type: notificationType,
|
type: notificationType,
|
||||||
...mcpData
|
...mcpData
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
} catch (e) {
|
||||||
|
console.error('Error sending notification to MCP:', e.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,11 +409,12 @@ wss.on('connection', (ws, req) => {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} 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 {
|
try {
|
||||||
ws.send(JSON.stringify({
|
ws.send(JSON.stringify({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: 'Invalid message format'
|
message: `Error: ${error.message}`
|
||||||
}));
|
}));
|
||||||
} catch (sendError) {
|
} catch (sendError) {
|
||||||
console.error('Error sending error response:', sendError);
|
console.error('Error sending error response:', sendError);
|
||||||
|
|||||||
Reference in New Issue
Block a user