EU Parliament Monitor — API Documentation - v0.9.24
    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

    • Create a new MCP connection.

      Resolves the server binary path, gateway URL, and authentication options from the explicit options, then from environment variables, and finally module-level defaults. The connection is not opened until connect is called.

      Parameters

      • options: MCPClientOptions = {}

        Connection options including server path, gateway URL, API key, retry policy, and human-readable server label for log messages.

      Returns MCPConnection

    Methods

    • 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

    • Advance the attempt counter and compute the next retry delay. Throws immediately for non-retriable errors or when exhausted.

      Parameters

      • error: unknown

        The error from the failed attempt

      Returns number

      Delay in milliseconds to wait before the next attempt

    • Attempt a single connection via stdio (spawns server binary). Delegates to attemptStdioConnection in process.ts.

      Returns Promise<void>

      Resolves when the spawn has completed (or rejects on spawn failure)

    • 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

    • 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. Deduplicates concurrent calls — only one reconnect runs at a time.

      Returns Promise<void>

      Resolves when reconnect succeeds or all attempts are exhausted

    • 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