/** * Leaper Agent – MCP Client (tools/mcp-client.ts) * * Lightweight Model Context Protocol client. * Translates Python tools/mcp_tool.py. * * Supports two transports: * • stdio – spawns the server as a child process; communicates via JSON-RPC 2.0 * line-delimited messages over stdin/stdout. * • HTTP – sends JSON-RPC 2.0 POST requests to the server's URL. * * Because the official @modelcontextprotocol/sdk may not be installed, this is * a self-contained implementation using node:child_process, node:readline, and * the global proxyFetch(). */ export interface MCPServerConfig { /** Display name for this server. */ name: string; /** Executable to launch (stdio transport). */ command?: string; /** Arguments for the executable (stdio transport). */ args?: string[]; /** Extra environment variables injected into the child process. */ env?: Record; /** Base URL of the MCP server (HTTP transport). */ url?: string; /** Extra HTTP headers sent with every request (HTTP transport). */ headers?: Record; /** Per-call timeout in ms. Default: 120 000. */ timeout?: number; /** Connection / initialisation timeout in ms. Default: 60 000. */ connectTimeout?: number; } export interface MCPTool { name: string; description: string; inputSchema: Record; } export interface MCPCallResult { content: Array<{ type: string; text?: string; [key: string]: unknown; }>; isError?: boolean; } export declare class MCPClient { private config; private tools; private connected; private rateLimiter; private child; private rl; private pendingRequests; private nextId; constructor(config: MCPServerConfig); getName(): string; isConnected(): boolean; listTools(): MCPTool[]; /** * Connect to the MCP server and fetch the tool list. * For stdio: spawns the process, sends initialize + tools/list. * For HTTP: sends a tools/list POST. */ connect(): Promise; /** * Call a tool by name with the given arguments. * Enforces rate limiting and per-call timeout. */ callTool(name: string, args: Record): Promise; /** Disconnect / clean up resources. */ disconnect(): Promise; private connectHttp; private callToolHttp; private httpPost; private connectStdio; private callToolStdio; private stdioRpc; private handleStdioLine; private enforceRateLimit; } export declare class MCPManager { private clients; /** Add and connect a new server. */ addServer(config: MCPServerConfig): Promise; /** Disconnect and remove a server by name. */ removeServer(name: string): Promise; /** Retrieve a connected client by name. */ getClient(name: string): MCPClient | undefined; /** Return all tools from all connected servers, tagged with their server name. */ getAllTools(): Array; /** Call a specific tool on a named server. */ callTool(serverName: string, toolName: string, args: Record): Promise; /** Disconnect all servers. */ disconnectAll(): Promise; } //# sourceMappingURL=mcp-client.d.ts.map