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
223 lines (220 loc) • 8.14 kB
TypeScript
import { M as MCPOptions, a as MCPRequestParams, b as MCPResponse, O as OntologySummary, c as OntologyMetadata, d as MCPCacheOptions } from '../types-CmbeEBKR.js';
import { F as FetchOptions } from '../fetcher-B6k3kybO.js';
import { MCPWebSocket } from './websocket.js';
import { MCPError } from '../errors/index.js';
import { z } from 'zod';
import MCPArrowClient from './arrow-ipc.js';
type ErrorHandler = (error: MCPError, requestInfo?: {
method: string;
url: string;
options?: FetchOptions;
}) => void | Promise<void>;
/**
* MCP Client
* Handles communication with the MCP API
*/
declare class MCPClient {
private baseUrl;
private tenantId?;
private apiKey?;
private token?;
private defaultOptions;
private globalErrorHandlers;
private defaultTimeout;
private _activeTransport;
private _arrowClient;
/**
* Creates a new MCP Client
* @param options - Client options
*/
constructor(options?: MCPOptions);
/**
* Add a global error handler for all requests
* @param handler - Function to handle errors
*/
onError(handler: ErrorHandler): void;
/**
* Remove a global error handler
* @param handler - Handler to remove
*/
removeErrorHandler(handler: ErrorHandler): void;
/**
* Handles an error by calling all registered error handlers
*/
private handleError;
/**
* Creates a full URL from a path
*/
private createUrl;
/**
* Creates auth headers for a request
*/
private createHeaders;
/**
* Makes an HTTP request to the MCP API
* @param url - URL to request
* @param options - Fetch options
* @returns Promise with the response data
*/
request<T = any>(params: MCPRequestParams & {
path: string;
}, validateFn?: (data: any) => T): Promise<MCPResponse<T>>;
/**
* Makes a GET request with schema validation
* @param path - API endpoint path
* @param schema - Zod schema for response validation
* @param params - Request parameters
* @returns Validated response data
*/
/**
* Makes a simple GET request without schema validation
* @param path - API endpoint path
* @param params - Request parameters
* @returns Response data
*/
get<T = any>(path: string, params?: Omit<MCPRequestParams, 'method'>): Promise<T>;
/**
* Makes a GET request with schema validation
* @param path - API endpoint path
* @param schema - Zod schema for response validation
* @param params - Request parameters
* @returns Validated response data
*/
getTyped<T>(path: string, schema: z.ZodType<T>, params?: Omit<MCPRequestParams, 'method'>): Promise<MCPResponse<T>>;
/**
* Makes a POST request with schema validation
* @param path - API endpoint path
* @param schema - Zod schema for response validation
* @param body - Request body
* @param params - Request parameters
* @returns Validated response data
*/
/**
* Makes a simple POST request without schema validation
* @param path - API endpoint path
* @param body - Request body
* @param params - Request parameters
* @returns Response data
*/
post<T = any>(path: string, body?: any, params?: Omit<MCPRequestParams, 'method' | 'body'>): Promise<T>;
/**
* Makes a POST request with schema validation
* @param path - API endpoint path
* @param schema - Zod schema for response validation
* @param body - Request body
* @param params - Request parameters
* @returns Validated response data
*/
postTyped<T>(path: string, schema: z.ZodType<T>, body?: any, params?: Omit<MCPRequestParams, 'method' | 'body'>): Promise<MCPResponse<T>>;
/**
* Makes a PUT request with schema validation
* @param path - API endpoint path
* @param schema - Zod schema for response validation
* @param body - Request body
* @param params - Request parameters
* @returns Validated response data
*/
putTyped<T>(path: string, schema: z.ZodType<T>, body?: any, params?: Omit<MCPRequestParams, 'method' | 'body'>): Promise<MCPResponse<T>>;
/**
* Gets all ontologies
* @param options - Request parameters
*/
getOntologies(params?: Omit<MCPRequestParams, 'method'>): Promise<MCPResponse<OntologySummary[]>>;
/**
* Gets ontology by ID
* @param id - Ontology ID
* @param params - Request parameters
*/
getOntology(id: string, params?: Omit<MCPRequestParams, 'method'>): Promise<MCPResponse<OntologyMetadata>>;
/**
* Gets current user details
* @param params - Request parameters
*/
getCurrentUser(params?: Omit<MCPRequestParams, 'method'>): Promise<MCPResponse<any>>;
/**
* Gets user by ID
* @param id - User ID
* @param params - Request parameters
*/
getUser(id: string, params?: Omit<MCPRequestParams, 'method'>): Promise<MCPResponse<any>>;
/**
* Gets current tenant details
* @param params - Request parameters
*/
getCurrentTenant(params?: Omit<MCPRequestParams, 'method'>): Promise<MCPResponse<any>>;
/**
* Gets tenant by ID
* @param id - Tenant ID
* @param params - Request parameters
*/
getTenant(id: string, params?: Omit<MCPRequestParams, 'method'>): Promise<MCPResponse<any>>;
/**
* Connect to MCP using the specified transport
* @param transportOptions - Transport-specific options
*/
connect(transportOptions: any): Promise<void>;
/**
* Disconnect from MCP
*/
disconnect(): Promise<void>;
/**
* Upload an ontology file for the tenant
* @param file - OWL ontology file to upload
* @param name - Optional name for the ontology
* @param options - Additional fetch options
*/
uploadOntology(file: File | Blob, name?: string, options?: FetchOptions): Promise<MCPResponse<OntologyMetadata>>;
/**
* Creates a WebSocket client with the same configuration as this client
*/
createWebSocketClient(): MCPWebSocket;
/**
* Set cache options for all requests
* @param cache - Cache options to use
*/
setCacheOptions(cache: MCPCacheOptions): void;
/**
* Fetches the list of available tools
* @param params Optional request parameters
* @returns Promise with the list of available tools
*/
getTools(params?: Omit<MCPRequestParams, 'method'>): Promise<MCPResponse<any[]>>;
/**
* Executes a tool with parameters
* @param toolName Name of the tool to execute
* @param parameters Parameters for the tool
* @param params Optional request parameters
* @returns Promise with the tool execution result
*/
executeTool(toolName: string, parameters: Record<string, any>, params?: Omit<MCPRequestParams, 'method' | 'body'>): Promise<MCPResponse<any>>;
/**
* Streams a tool execution with parameters
* @param toolName Name of the tool to execute
* @param parameters Parameters for the tool
* @param onChunk Callback for each chunk of streamed data
* @param params Optional request parameters
* @returns Promise that resolves when streaming completes
*/
streamTool(toolName: string, parameters: Record<string, any>, onChunk: (chunk: any) => void, params?: Omit<MCPRequestParams, 'method' | 'body'>): Promise<void>;
/**
* Get the current active transport type
*/
getActiveTransport(): 'standard' | 'websocket' | 'sse' | 'arrow' | 'none';
/**
* Set the active transport type
*/
setActiveTransport(transport: 'standard' | 'websocket' | 'sse' | 'arrow' | 'none'): void;
/**
* Create an Arrow IPC client
*/
createArrowClient(options?: MCPOptions): MCPArrowClient;
/**
* Get the Arrow IPC client, creating one if it doesn't exist
*/
getArrowClient(options?: MCPOptions): MCPArrowClient;
/**
* Get standard options for transport clients
*/
private getStandardOptions;
}
export { type ErrorHandler, MCPClient, MCPWebSocket };