better error handling in mcp
This commit is contained in:
+10
-30
@@ -594,44 +594,24 @@ server.tool(
|
|||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
const errorStack = error.stack || error.message
|
const errorStack = error.stack || error.message
|
||||||
console.error('Error in execute tool, attempting reset:', errorStack)
|
console.error('Error in execute tool:', errorStack)
|
||||||
|
|
||||||
const logsText = formatConsoleLogs(consoleLogs, 'Console output (before error)')
|
const logsText = formatConsoleLogs(consoleLogs, 'Console output (before error)')
|
||||||
|
|
||||||
if (error.message.includes('duplicate target')) {
|
const isTimeoutError = error.name === 'TimeoutError' || error.message.includes('Timeout')
|
||||||
await sendLogToRelayServer('error', '[MCP] CRITICAL ERROR - Connection reset triggered:', errorStack)
|
if (!isTimeoutError) {
|
||||||
try {
|
sendLogToRelayServer('error', '[MCP] Error:', errorStack)
|
||||||
await resetConnection()
|
|
||||||
return {
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
text: `${logsText}Connection was reset due to internal error. Please retry your command.\n\nError: ${error.message}`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
} catch (resetError: any) {
|
|
||||||
await sendLogToRelayServer(
|
|
||||||
'error',
|
|
||||||
'[MCP] CRITICAL ERROR - Reset failed:',
|
|
||||||
resetError.stack || resetError.message,
|
|
||||||
)
|
|
||||||
return {
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'text',
|
|
||||||
text: `${logsText}Connection was reset due to internal error. Error executing code: ${error.message}\n${errorStack}`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
isError: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resetHint = isTimeoutError
|
||||||
|
? ''
|
||||||
|
: '\n\n[HINT: If this is an internal Playwright error, page/browser closed, or connection issue, call the `reset` tool to reconnect. Do NOT reset for other non-connection non-internal errors.]'
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'text',
|
||||||
text: `${logsText}Error executing code: ${error.message}\n${errorStack}`,
|
text: `${logsText}\nError executing code: ${error.message}\n${errorStack}${resetHint}`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
isError: true,
|
isError: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user