From 7a9b08b78f063df5196434ce97a588edb20a90d7 Mon Sep 17 00:00:00 2001 From: Viswamedha Nalabotu Date: Sat, 21 Mar 2026 00:03:55 +0000 Subject: [PATCH] Added try catch for mcp tool call --- apps/onboarding/mcp.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/onboarding/mcp.py b/apps/onboarding/mcp.py index 8438fa0..a6c56ab 100644 --- a/apps/onboarding/mcp.py +++ b/apps/onboarding/mcp.py @@ -52,9 +52,13 @@ class MCPRouter: if method_name: method = getattr(self, method_name, None) if method: - result = await method(arguments) - logger.info('MCP tool call completed: tool=%s result=%s', name, result) - return result + try: + result = await method(arguments) + logger.info('MCP tool call completed: tool=%s result=%s', name, result) + return result + except Exception as exc: + logger.exception('MCP tool call failed: tool=%s error=%s', name, exc) + return {'error': f'Tool {name} failed: {exc}'} logger.warning('MCP tool call rejected: unknown tool=%s', name) return {'error': f'Tool {name} not found'}