Added try catch for mcp tool call

This commit is contained in:
Viswamedha Nalabotu 2026-03-21 00:03:55 +00:00
parent aee072b4a0
commit 7a9b08b78f

View file

@ -52,9 +52,13 @@ class MCPRouter:
if method_name: if method_name:
method = getattr(self, method_name, None) method = getattr(self, method_name, None)
if method: if method:
result = await method(arguments) try:
logger.info('MCP tool call completed: tool=%s result=%s', name, result) result = await method(arguments)
return result 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) logger.warning('MCP tool call rejected: unknown tool=%s', name)
return {'error': f'Tool {name} not found'} return {'error': f'Tool {name} not found'}