European Parliament MCP Server API - v1.0.1
    Preparing search index...

    Function formatMCPError

    • 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

      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) }] };
      }
      • Sanitizes internal errors to prevent information leakage
      • Preserves error codes and safe details for structured errors
      • Logs full error details internally for debugging