ragatanga-mcp-sdk
Version:
SDK for integrating with the Ragatanga Management Control Plane (MCP) with Next.js 15, React 19, WebSocket and Arrow IPC support
179 lines (176 loc) • 4.31 kB
text/typescript
import { M as MCPOptions } from '../types-CmbeEBKR.mjs';
/**
* WebSocket message interface
*/
interface WebSocketMessage {
id?: string;
type?: string;
payload?: any;
uri?: string;
depth?: number;
[key: string]: any;
}
/**
* WebSocket event handlers
*/
interface WebSocketEventHandlers {
onOpen?: (event: Event) => void;
onMessage?: (data: string, messageType?: string) => void;
onError?: (event: Event) => void;
onClose?: (event: CloseEvent) => void;
onMessageType?: Record<string, (data: any) => void>;
onHeartbeat?: (latency: number) => void;
onStatusChange?: (status: WebSocketStatus) => void;
}
/**
* WebSocket connection status
*/
declare enum WebSocketStatus {
CONNECTING = 0,
CONNECTED = 1,
CLOSING = 2,
CLOSED = 3,
RECONNECTING = 4,
ERROR = 5
}
/**
* WebSocket subscription
*/
interface WebSocketSubscription {
id: string;
type: string;
callback: (data: any) => void;
unsubscribe: () => void;
}
/**
* Enhanced WebSocket client with advanced features
*/
declare class MCPWebSocket {
private ws;
private baseUrl;
private apiKey?;
private token?;
private tenantId?;
private reconnectAttempts;
private maxReconnectAttempts;
private reconnectDelay;
private handlers;
private status;
private messageQueue;
private subscriptions;
private heartbeatInterval?;
private heartbeatTimeout?;
private lastHeartbeatTime?;
private heartbeatDelay;
private connectionId;
private binarySupport;
private connectionPath;
private autoReconnect;
private lastConnectionTime;
private connectionRetryTimer;
private manualClose;
/**
* Creates a new WebSocket client
*/
constructor(options: MCPOptions & {
autoReconnect?: boolean;
maxReconnectAttempts?: number;
});
/**
* Connects to the MCP WebSocket endpoint
*/
connect(path?: string, handlers?: WebSocketEventHandlers): void;
/**
* Update and notify about status changes
*/
private setStatus;
/**
* Handle WebSocket open event
*/
private handleOpen;
/**
* Handle WebSocket message event
*/
private handleMessage;
/**
* Handle WebSocket error event
*/
private handleError;
/**
* Handle WebSocket close event
*/
private handleClose;
/**
* Handle connection initialization error
*/
private handleConnectionError;
/**
* Send a message over the WebSocket connection
*/
send(message: WebSocketMessage): boolean;
/**
* Queue a message for later sending
*/
private queueMessage;
/**
* Process the message queue
*/
private processQueue;
/**
* Subscribe to a specific message type
*/
subscribe<T = any>(type: string, callback: (data: T) => void): WebSocketSubscription;
/**
* Send a request to resolve a URI
*/
resolveUri(uri: string, depth?: number): boolean;
/**
* Close the WebSocket connection
*/
disconnect(): void;
/**
* Get the current WebSocket state
*/
getState(): WebSocketStatus;
/**
* Attempt to reconnect with exponential backoff
*/
private attemptReconnect;
/**
* Start the heartbeat timer
*/
private startHeartbeat;
/**
* Stop the heartbeat timer
*/
private stopHeartbeat;
/**
* Set the heartbeat interval
*/
setHeartbeatInterval(intervalMs: number): void;
/**
* Set the maximum number of reconnect attempts
*/
setMaxReconnectAttempts(attempts: number): void;
/**
* Set the reconnect delay
*/
setReconnectDelay(delayMs: number): void;
/**
* Generate a unique subscription ID
*/
private generateSubscriptionId;
/**
* Generate a unique message ID
*/
private generateMessageId;
/**
* Generate a unique connection ID
*/
private generateConnectionId;
}
/**
* Create a WebSocket client with the given options
*/
declare function createWebSocketClient(options: MCPOptions): MCPWebSocket;
export { MCPWebSocket, type WebSocketEventHandlers, type WebSocketMessage, WebSocketStatus, type WebSocketSubscription, createWebSocketClient };