European Parliament MCP Server API - v1.3.9
    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.

    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.

    EMPTY_JSONLD: Readonly<{ "@context": never[]; data: never[] }> = ...

    Empty JSON-LD shape returned for bodyless responses (HTTP 204, content-length: 0).

    Methods

    • Builds the full request URL from endpoint + optional params.

      Parameters

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

      Returns URL

    • Evicts a single cache entry matching the given endpoint and params. Sub-clients use this when they detect that a successfully-fetched payload is a content-pending sentinel that must not be served from cache for the remainder of the TTL — eviction lets availability recover as soon as the upstream document is enriched.

      Parameters

      • endpoint: string

        API endpoint path (same value passed to get)

      • Optionalparams: Record<string, unknown>

        Optional query parameters (same value passed to get)

      Returns void

    • Wraps a fetch call with the configured retry policy.

      Type Parameters

      • T

      Parameters

      • url: URL

        Fully resolved request URL

      • endpoint: string

        Relative endpoint path (for error messages)

      • OptionalminimumTimeoutMs: number

        Optional per-request minimum timeout (ms)

      Returns Promise<T>

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

      Type Parameters

      • T

      Parameters

      • url: URL

        Fully resolved request URL

      • endpoint: string

        Relative endpoint path (for error messages)

      • OptionalminimumTimeoutMs: number

        Optional per-request minimum timeout (ms). When provided, the effective timeout is Math.max(minimumTimeoutMs, this.timeoutMs), so it acts as a floor that the global timeout can still extend. Use for known slow EP API endpoints (e.g. procedures/feed).

      Returns Promise<T>

    • 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

      • OptionalminimumTimeoutMs: number

        Optional per-request minimum timeout in milliseconds. When provided, the effective timeout is Math.max(minimumTimeoutMs, this.timeoutMs), so the global timeout (set via --timeout or EP_REQUEST_TIMEOUT_MS) can still extend it beyond the per-endpoint minimum. Use for known slow EP API endpoints such as procedures/feed.

      Returns Promise<T>

      Promise resolving to the typed API response

      On HTTP errors, network failures, or parse failures

    • 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 }

    • Parses the response body based on content-length header. Returns undefined when content-length is absent or non-finite (caller should fall through to streamed-body parsing).

      Type Parameters

      • T

      Parameters

      • response: Response

      Returns Promise<T | undefined>

    • 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>

    • 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

    • Converts a caught error to a typed APIError. For timeout errors, the actual timeout value is read from the TimeoutError instance (which carries the effective value used by withTimeoutAndAbort), avoiding the need to re-validate or recompute the per-endpoint minimum here.

      Parameters

      • error: unknown

        The caught error

      • endpoint: string

        Relative endpoint path (for error messages)

      Returns APIError

    • Parses a byte buffer as JSON-LD. Returns an empty JSON-LD shape for zero-byte bodies (the EP API sends these for out-of-range offsets). Non-empty bodies must contain valid JSON; any SyntaxError is allowed to propagate so callers (including single-entity endpoints) fail fast instead of receiving a misleading empty-list shape.

      Parameters

      Returns JSONLDResponse

    • Treats a truly empty body as an empty JSON-LD shape; invalid JSON for non-empty bodies is surfaced as an error.

      Type Parameters

      • T

      Parameters

      • response: Response

      Returns Promise<T>

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

      Parameters

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

    • Validates the Content-Type header of an API response. Throws if the response is not JSON (e.g. HTML error pages from reverse proxies). Cancels the response body before throwing to allow connection reuse.

      A missing or empty Content-Type header is treated as acceptable because the EP API occasionally omits it on valid JSON responses, and rejecting those would cause false-negative failures.

      Parameters

      • response: Response

      Returns void