EU Parliament Monitor — API Documentation - v0.8.30
    Preparing search index...

    Base MCP connection managing JSON-RPC 2.0 transport over stdio or HTTP gateway. Extended by domain-specific clients to add tool wrapper methods.

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    • Check if using gateway HTTP transport

      Returns boolean

      True if gateway mode is active

    • Get the configured gateway URL

      Returns string | null

      Gateway URL or null if using stdio transport

    • Get the configured gateway API key

      Returns string | null

      Gateway API key or null if not set

    • Get the current MCP session ID

      Returns string | null

      Session ID returned by the gateway, or null if not yet connected

    • Get connection health metrics for telemetry

      Returns { timeoutCount: number; reconnectCount: number; connected: boolean }

      Object with timeout count, reconnection count, and current connection status

    • Compute the delay before the next connection attempt. Respects Retry-After carried by MCPRateLimitError; otherwise uses exponential back-off (connectionRetryDelay * 2^(attempt - 1)).

      Parameters

      • error: unknown

        The error from the failed attempt

      • attempt: number

        Number of attempts made so far (1-indexed)

      Returns number

      Delay in milliseconds

    • Handle a single connection attempt error: re-throw immediately for non-retriable errors (e.g. session expiry), increment the attempt counter, and return the delay to wait before the next attempt. Throws when the maximum attempts have been exhausted.

      Parameters

      • error: unknown

        The error from the failed attempt

      Returns number

      Delay in milliseconds to wait before the next attempt

    • Validate a gateway response body, throwing on JSON-RPC errors.

      Parameters

      • contentType: string

        Response content-type header

      • body: string

        Raw response body text

      Returns void

    • Build the Authorization header value for gateway requests. Keys that already contain a valid RFC 7235 scheme token followed by whitespace (e.g. "Bearer …", "Token …", "AWS4-HMAC-SHA256 …") are passed through unchanged. Otherwise the raw key is sent directly unless EP_MCP_GATEWAY_AUTH_SCHEME is set to a valid token, in which case that scheme prefix is prepended. The EP MCP gateway expects raw-token auth by default (no "Bearer " prefix).

      Parameters

      • apiKey: string

        Raw or pre-prefixed gateway API key

      Returns string

      The full Authorization header value, or empty string for empty keys

      When the API key contains CR or LF characters (header injection risk)

    • Attempt a single connection via MCP Gateway (HTTP transport)

      Returns Promise<void>

    • Attempt a single connection via stdio (spawns server binary)

      Returns Promise<void>

    • Handle incoming messages from MCP server (stdio mode only)

      Parameters

      • line: string

        JSON message line from server

      Returns void

    • Throw an appropriate error for a non-OK gateway response. Extracted to keep _sendGatewayRequest within cognitive-complexity limits.

      Parameters

      • response: Response

        The non-OK fetch Response

      Returns never

    • Send a request via MCP Gateway (HTTP transport)

      Parameters

      • method: string

        RPC method name

      • params: Record<string, unknown> = {}

        Method parameters

      Returns Promise<unknown>

      Server response

    • Send a request to the MCP server

      Type Parameters

      • T = unknown

      Parameters

      • method: string

        RPC method name

      • params: Record<string, unknown> = {}

        Method parameters

      Returns Promise<T>

      Server response

    • List available MCP tools

      Returns Promise<unknown>

      List of available tools

    • Call an MCP tool

      Parameters

      • name: string

        Tool name

      • args: object = {}

        Tool arguments (must be a plain object, non-null, not an array)

      Returns Promise<MCPToolResult>

      Tool execution result

    • Attempt to reconnect to the MCP server with exponential back-off. Concurrent callers await the same in-flight reconnect instead of no-oping, ensuring the connection is re-established before all waiting callers continue.

      Returns Promise<void>

      Promise that resolves when reconnection succeeds or all attempts are exhausted

    • Internal reconnect helper.

      Waits for an exponential back-off delay derived from the current reconnectCount, then delegates to connect() which handles its own retry loop. This avoids composing N×N attempts.

      Returns Promise<void>

      Promise that resolves when reconnection succeeds or logs on failure

    • Log a retry warning and, if disconnected, attempt to reconnect before waiting.

      Parameters

      • lastError: Error

        The error from the failed attempt

      • attempt: number

        Zero-based current attempt index

      • retries: number

        Total retry count

      Returns Promise<void>

      Promise that resolves after logging, optional reconnect, and inter-retry delay

    • Call an MCP tool with automatic retry on timeout or connection loss. Reconnects automatically if the connection was lost between attempts.

      Only transient failures are retried (see isRetriableError). Non-retriable errors — rate-limit (429), session-expired (401), and programmer errors such as TypeError — are re-thrown immediately without consuming any retry budget.

      Parameters

      • name: string

        Tool name

      • args: object = {}

        Tool arguments (plain object, non-null, not an array)

      • OptionalmaxRetries: number

        Override the default retry count from options

      Returns Promise<MCPToolResult>

      Tool execution result

    Properties

    serverPath: string
    connected: boolean
    process: ChildProcess | null
    requestId: number
    pendingRequests: Map<number, PendingRequest>
    connectionAttempts: number
    maxConnectionAttempts: number
    connectionRetryDelay: number
    maxRetries: number
    reconnectingPromise: Promise<void> | null
    timeoutCount: number
    reconnectCount: number
    gatewayUrl: string | null

    Gateway URL for HTTP transport mode

    gatewayApiKey: string | null

    API key for gateway authentication

    mcpSessionId: string | null

    MCP session ID returned by the gateway

    serverLabel: string

    Human-readable server name for log messages