Handle a caught tool error, returning a safe MCP error response.
Never exposes raw stack traces to MCP clients.
If the error is a ToolError, its own toolName and isRetryable are
used so the originating tool and retryability are correctly surfaced to callers
even when the error crosses handler boundaries.
Parameters
error: unknown
Caught error value
toolName: string
Fallback tool name when error carries no tool identity
Handle a caught tool error, returning a safe MCP error response. Never exposes raw stack traces to MCP clients.
If the error is a ToolError, its own
toolNameandisRetryableare used so the originating tool and retryability are correctly surfaced to callers even when the error crosses handler boundaries.