UNPKG

@webdevtoday/grok-cli

Version:

A sophisticated CLI tool for interacting with xAI Grok 4, featuring conversation history, file reference, custom commands, memory system, and genetic development workflows

238 lines 5.76 kB
/** * MCP (Model Context Protocol) Client Implementation * Provides integration with MCP servers using Node.js native capabilities */ import { EventEmitter } from 'events'; import type { McpServerConfig, McpServer } from '../types'; export interface McpMessage { jsonrpc: '2.0'; id?: string | number; method?: string; params?: any; result?: any; error?: { code: number; message: string; data?: any; }; } export interface McpRequest extends McpMessage { method: string; params?: any; } export interface McpResponse extends McpMessage { id: string | number; result?: any; error?: { code: number; message: string; data?: any; }; } export interface McpNotification extends McpMessage { method: string; params?: any; } export interface McpTool { name: string; description: string; inputSchema: any; } export interface McpPrompt { name: string; description: string; arguments?: any[]; } export interface McpResource { uri: string; name: string; description?: string; mimeType?: string; } export interface McpCapabilities { prompts?: { listChanged?: boolean; }; resources?: { subscribe?: boolean; listChanged?: boolean; }; tools?: { listChanged?: boolean; }; logging?: { level?: 'debug' | 'info' | 'notice' | 'warning' | 'error' | 'critical' | 'alert' | 'emergency'; }; } /** * MCP Server Connection Manager */ export declare class McpServerConnection extends EventEmitter { private process; private messageBuffer; private pendingRequests; readonly name: string; readonly config: McpServerConfig; status: 'disconnected' | 'connecting' | 'connected' | 'error'; capabilities: McpCapabilities; tools: McpTool[]; prompts: McpPrompt[]; resources: McpResource[]; constructor(name: string, config: McpServerConfig); /** * Connect to the MCP server */ connect(): Promise<void>; /** * Disconnect from the MCP server */ disconnect(): Promise<void>; /** * Send a request to the MCP server */ sendRequest(method: string, params?: any, timeout?: number): Promise<any>; /** * Send a notification to the MCP server */ sendNotification(method: string, params?: any): void; /** * Call a tool on the MCP server */ callTool(name: string, arguments_?: any): Promise<any>; /** * Get a prompt from the MCP server */ getPrompt(name: string, arguments_?: any): Promise<any>; /** * Read a resource from the MCP server */ readResource(uri: string): Promise<any>; /** * List available tools */ listTools(): Promise<McpTool[]>; /** * List available prompts */ listPrompts(): Promise<McpPrompt[]>; /** * List available resources */ listResources(): Promise<McpResource[]>; /** * Initialize the MCP connection */ private initialize; /** * Load server capabilities and available features */ private loadCapabilities; /** * Send a message to the server */ private sendMessage; /** * Handle raw message data from server */ private handleRawMessage; /** * Handle a parsed message from the server */ private handleMessage; /** * Handle notifications from the server */ private handleNotification; /** * Handle connection errors */ private handleError; /** * Handle disconnection */ private handleDisconnect; } /** * MCP Client Manager */ export declare class McpClient extends EventEmitter { private servers; private autoReconnect; private reconnectDelay; /** * Add a new MCP server */ addServer(name: string, config: McpServerConfig): void; /** * Remove an MCP server */ removeServer(name: string): Promise<void>; /** * Connect to a specific server */ connectServer(name: string): Promise<void>; /** * Connect to all configured servers */ connectAll(): Promise<void>; /** * Disconnect from all servers */ disconnectAll(): Promise<void>; /** * Get a server by name */ getServer(name: string): McpServerConnection | undefined; /** * Get all servers */ getAllServers(): McpServer[]; /** * Get all available tools from all connected servers */ getAllTools(): Array<{ server: string; tool: McpTool; }>; /** * Get all available prompts from all connected servers */ getAllPrompts(): Array<{ server: string; prompt: McpPrompt; }>; /** * Get all available resources from all connected servers */ getAllResources(): Array<{ server: string; resource: McpResource; }>; /** * Call a tool on a specific server */ callTool(serverName: string, toolName: string, arguments_?: any): Promise<any>; /** * Get a prompt from a specific server */ getPrompt(serverName: string, promptName: string, arguments_?: any): Promise<any>; /** * Read a resource from a specific server */ readResource(serverName: string, uri: string): Promise<any>; /** * Set auto-reconnect behavior */ setAutoReconnect(enabled: boolean, delay?: number): void; /** * Get connection statistics */ getStats(): { totalServers: number; connectedServers: number; totalTools: number; totalPrompts: number; totalResources: number; }; } //# sourceMappingURL=mcp-client.d.ts.map