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

    Base class for European Parliament API sub-clients.

    Holds the shared HTTP machinery: LRU cache, token-bucket rate limiter, timeout/abort controller, and retry logic. Sub-clients extend this class and call the protected get() helper for all HTTP requests.

    BaseEPClient

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a BaseEPClient.

      When shared is provided the constructor reuses those pre-built resources instead of allocating new ones; this is the mechanism used by the facade to ensure all sub-clients share one cache and one rate-limiter.

      Parameters

      • config: EPClientConfig = {}

        Client configuration (used when shared is absent)

      • Optionalshared: EPSharedResources

        Pre-built shared resources (passed by facade to sub-clients)

      Returns BaseEPClient

    Properties

    baseURL: string

    European Parliament API base URL.

    cache: LRUCache<string, Record<string, unknown>>

    LRU cache for API responses.

    cacheCounters: { hits: number; misses: number }

    Shared cache hit/miss counters (shared via EPSharedResources when used as sub-client).

    enableRetry: boolean

    Enable automatic retry on transient failures.

    maxResponseBytes: number

    Maximum allowed response body size in bytes.

    maxRetries: number

    Maximum number of retry attempts.

    rateLimiter: RateLimiter

    Token bucket rate limiter.

    timeoutMs: number

    Request timeout in milliseconds.

    Methods

    • Private

      Builds the full request URL from endpoint + optional params.

      Parameters

      • endpoint: string
      • Optionalparams: Record<string, unknown>

      Returns URL

    • Private

      Executes the HTTP fetch with timeout/abort support and response size guard.

      Type Parameters

      • T

      Parameters

      • url: URL
      • endpoint: string

      Returns Promise<T>

    • Protected

      Executes a cached, rate-limited GET request to the EP API.

      Type Parameters

      • T extends Record<string, unknown>

        Expected response type (extends Record<string, unknown>)

      Parameters

      • endpoint: string

        API endpoint path (relative to baseURL)

      • Optionalparams: Record<string, unknown>

        Optional query parameters

      Returns Promise<T>

      Promise resolving to the typed API response

      On HTTP errors, network failures, or parse failures

    • Private

      Generates a deterministic cache key.

      Parameters

      • endpoint: string

        API endpoint path

      • Optionalparams: Record<string, unknown>

        Optional query parameters

      Returns string

      JSON string used as cache key

    • Returns cache statistics for monitoring and debugging.

      Returns { hitRate: number; hits: number; maxSize: number; misses: number; size: number }

      { size, maxSize, hitRate, hits, misses }

    • Private

      Reads the response body as a stream, enforcing the response size cap. Used as a fallback when the content-length header is absent (e.g. chunked transfer encoding). Accumulates all chunks and parses the result as JSON.

      Type Parameters

      • T

      Parameters

      • response: Response

      Returns Promise<T>

    • Private

      Returns true when an error should trigger a retry.

      Retries on:

      • 429 Too Many Requests (rate-limited by EP API; exponential backoff applied)
      • 5xx Server Errors (transient server failures)
      • Network / unknown errors

      Does NOT retry on 4xx client errors (except 429).

      Parameters

      • error: unknown

      Returns boolean

    • Private

      Resolves all EPClientConfig options to their final values with defaults applied. Extracted to keep constructor complexity within limits.

      Parameters

      • config: EPClientConfig

      Returns {
          baseURL: string;
          cacheTTL: number;
          enableRetry: boolean;
          maxCacheSize: number;
          maxResponseBytes: number;
          maxRetries: number;
          rateLimiter: RateLimiter;
          timeoutMs: number;
      }