@toolprint/hypertool-mcp
Version:
HyperTool MCP proxy server for routing requests between clients and multiple underlying MCP servers
88 lines • 2.86 kB
TypeScript
/**
* Base connection implementation with common functionality
*/
import { EventEmitter } from "events";
import { ServerConfig } from "../../types/config.js";
import { Connection, ConnectionState, ConnectionStatus, ConnectionOptions, ConnectionEventType, ConnectionEventCallback, ConnectionEvent } from "../types.js";
/**
* Base connection implementation providing common functionality
*/
export declare abstract class BaseConnection<T = any> extends EventEmitter implements Connection<T> {
readonly id: string;
readonly serverName: string;
readonly config: ServerConfig;
protected options: Required<ConnectionOptions>;
protected connectionStatus: ConnectionStatus;
protected retryTimer?: NodeJS.Timeout;
protected pingTimer?: NodeJS.Timeout;
protected abstract _client: T | null;
constructor(serverName: string, config: ServerConfig, options?: ConnectionOptions);
/**
* Get the current connection status
*/
get status(): ConnectionStatus;
/**
* Get the underlying client instance
*/
get client(): T;
/**
* Check if the connection is active
*/
isConnected(): boolean;
/**
* Connect to the MCP server
*/
connect(): Promise<void>;
/**
* Disconnect from the MCP server
*/
disconnect(): Promise<void>;
/**
* Ping the server to check if it's still responsive
*/
ping(): Promise<boolean>;
/**
* Abstract methods to be implemented by transport-specific classes
*/
protected abstract doConnect(): Promise<void>;
protected abstract doDisconnect(): Promise<void>;
protected abstract doPing(): Promise<boolean>;
/**
* Update connection status
*/
protected updateStatus(state: ConnectionState, updates?: Partial<ConnectionStatus>): void;
/**
* Create a connection event
*/
protected createEvent(type: ConnectionEventType, overrides?: Partial<ConnectionEvent>): ConnectionEvent;
/**
* Schedule a reconnection attempt
*/
private scheduleReconnect;
/**
* Start periodic ping checks
*/
private startPing;
/**
* Stop periodic ping checks
*/
private stopPing;
/**
* Clear retry timer
*/
private clearRetryTimer;
/**
* Handle ping errors
*/
private handlePingError;
/**
* Override EventEmitter methods for type safety
*/
on(event: ConnectionEventType, listener: ConnectionEventCallback): this;
on(event: string, listener: (...args: any[]) => void): this;
off(event: ConnectionEventType, listener: ConnectionEventCallback): this;
off(event: string, listener: (...args: any[]) => void): this;
emit(event: ConnectionEventType, payload: ConnectionEvent): boolean;
emit(event: string, ...args: any[]): boolean;
}
//# sourceMappingURL=base.d.ts.map