Create a new AppError
Error code from ErrorCode enum
Human-readable error message
Optionaldetails: Record<string, unknown>Optional additional error details
Optionalcause: ErrorOptional underlying error
Optional ReadonlycauseOptional underlying error
ReadonlycodeError code from ErrorCode enum
Optional ReadonlydetailsOptional additional error details
Convert to JSON for logging/serialization
JSON representation of the error
Format error for MCP protocol response
MCP-compatible error response
Format error for OpenAI protocol response
OpenAI-compatible error response
Custom error class for the SDK
Provides structured error information that can be formatted for different protocols (MCP Apps, ChatGPT).
Example