# Function formatMCPError

- formatMCPError(
  error: unknown,
  ): { code: string; message: string; details?: unknown }

  Error formatter for MCP responses

  Formats errors for safe transmission to MCP clients. Internal errors are sanitized to prevent information leakage while preserving useful debugging information for expected error types.

  #### Parameters

  - error: unknown

    Error to format

  #### Returns { code: string; message: string; details?: unknown }

  Formatted error object safe for client transmission

  #### Example

      try {
        const result = await processMEPRequest(args);
        return { content: [{ type: 'text', text: JSON.stringify(result) }] };
      } catch (error) {
        const formatted = formatMCPError(error);
        return { content: [{ type: 'text', text: JSON.stringify(formatted) }] };
      }

  #### Security

  - Sanitizes internal errors to prevent information leakage
  - Preserves error codes and safe details for structured errors
  - Logs full error details internally for debugging
  - Defined in types/errors.ts:232