# Function buildErrorResponse

- buildErrorResponse(
  error: unknown,
  toolName: string,
  classification?: ErrorClassification,
  ): ToolResult

  Build an error response from an error value or message string. Never exposes raw stack traces to MCP clients.

  When no explicit classification is provided, the error is automatically classified via classifyError so all error responses — whether routed through `handleToolError` or built directly by tool handlers — include consistent `errorCode`, `errorCategory`, and `retryable` metadata.

  #### Parameters

  - error: unknown

    Error instance or message string

  - toolName: string

    Name of the tool that produced the error

  - `Optional` classification: ErrorClassification

    Optional pre-computed classification (auto-classified if omitted)

  #### Returns ToolResult

  MCP-compliant ToolResult with isError flag set

  - Defined in tools/shared/responseBuilder.ts:37