MCP Server Framework - v1.0.0
    Preparing search index...

    Class ConnectionStateManager<TService>

    Manages the connection state to a backend service.

    Generic implementation that works with any client implementing ServiceClient.

    Features:

    • Tracks connection state (disconnected, connecting, connected, error)
    • Notifies listeners when state changes
    • Provides current client instance
    • Supports health check validation
    • Uses circular buffer for efficient history management (O(1) operations)
    const manager = new ConnectionStateManager<MyServiceClient>();
    manager.onStateChange((state, client) => {
    if (state === 'connected') {
    console.log('Connected!');
    }
    });
    await manager.connect(serviceClient);

    // With any ServiceClient implementation
    const genericManager = new ConnectionStateManager<MyServiceClient>();

    Type Parameters

    Index

    Constructors

    Methods

    • Set the client and mark as connected. Validates the connection with a health check before completing. Includes OpenTelemetry tracing for the connection process.

      Parameters

      • client: TService

        The authenticated service client

      • skipHealthCheck: boolean = false

        Skip health check validation (for testing)

      Returns Promise<boolean>

      true if connection was successful

    • Enable automatic reconnection with exponential backoff.

      When the connection state transitions to 'error', the manager will automatically attempt to reconnect using the stored client instance. Subsequent attempts use exponential backoff up to maxDelayMs.

      This handles reconnection to the API backend, NOT MCP transport reconnection (which is client-side, handled by the SDK's StreamableHTTPReconnectionOptions).

      Parameters

      • Optionaloptions: ReconnectOptions

        Reconnect configuration (all fields optional with sensible defaults)

      Returns void