Skip to content

Commit 311827c

Browse files
waleedlatif1claude
andcommitted
fix(mcp): clear execution timeout to avoid timer leak; redact callback error
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 23266fe commit 311827c

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

apps/sim/app/api/mcp/oauth/callback/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,6 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
106106
return htmlClose('Connected. You can close this window.', true)
107107
} catch (error) {
108108
logger.error('MCP OAuth callback failed', error)
109-
return htmlClose(`Authorization failed: ${toError(error).message}`, false)
109+
return htmlClose('Authorization failed. Please try again.', false)
110110
}
111111
})

apps/sim/app/api/mcp/tools/execute/route.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,18 @@ export const POST = withRouteHandler(
193193
extraHeaders[SIM_VIA_HEADER] = simViaHeader
194194
}
195195

196+
let timeoutHandle: ReturnType<typeof setTimeout> | undefined
196197
const result = await Promise.race([
197198
mcpService.executeTool(userId, serverId, toolCall, workspaceId, extraHeaders),
198-
new Promise<never>((_, reject) =>
199-
setTimeout(() => reject(new Error('Tool execution timeout')), executionTimeout)
200-
),
201-
])
199+
new Promise<never>((_, reject) => {
200+
timeoutHandle = setTimeout(
201+
() => reject(new Error('Tool execution timeout')),
202+
executionTimeout
203+
)
204+
}),
205+
]).finally(() => {
206+
if (timeoutHandle !== undefined) clearTimeout(timeoutHandle)
207+
})
202208

203209
const transformedResult = transformToolResult(result)
204210

0 commit comments

Comments
 (0)