import type { MCPClient, MCPServerConfig } from './types.js'; import type { ToolDefinition } from '../tool/types.js'; import type { AgentDebugTraceHandler } from '../a2a/client.js'; /** JSON-RPC 请求 */ interface JsonRpcRequest { jsonrpc: '2.0'; id: number; method: string; params?: Record; } /** JSON-RPC 响应 */ interface JsonRpcResponse { jsonrpc: '2.0'; id: number; result?: unknown; error?: { code: number; message: string; data?: unknown; }; } /** * MCPClient 抽象基类 * 子类只需实现 send() 和 doConnect() / doDisconnect() */ export declare abstract class MCPClientBase implements MCPClient { protected config: MCPServerConfig; /** 默认运行时变量(来自 config.vars) */ protected contextVars?: Record; /** 实际使用的代理地址(由子类在 connect 时解析并写入;stdio 不设置则为 undefined) */ protected proxyUrl?: string; protected connected: boolean; private requestId; /** 调试 trace 回调 */ protected onDebugTrace?: AgentDebugTraceHandler; /** 等待响应的 Promise 队列:id → { resolve, reject, timer, method, startTime } */ private pending; /** 建立物理连接 */ protected abstract doConnect(config: MCPServerConfig): Promise; /** 断开物理连接 */ protected abstract doDisconnect(): void; /** * 发送 JSON-RPC 消息到 MCP 服务端 * @param vars 本次请求生效的运行时变量(contextVars + 调用时传入的 vars 合并),随请求显式传递, * 不作为实例共享状态,从而消除同一客户端并发调用时的 vars race。 */ protected abstract send(request: JsonRpcRequest, vars?: Record): void; connect(config: MCPServerConfig): Promise; listTools(): Promise; callTool(name: string, args: Record, vars?: Record): Promise; disconnect(): void; isConnected(): boolean; /** * 更新运行时变量(如 userId / userMail)。 * 后续请求(含 callTool 时未单独传入 vars 的情况)将使用更新后的值, * 用于注入到 headers / auth 的 ${vars.x} 占位符。 */ setContextVars(vars: Record): void; /** 发送 JSON-RPC 请求并等待响应 */ protected call(method: string, params?: Record, vars?: Record): Promise; /** 发送 JSON-RPC 通知(无 id,无响应) */ protected notify(method: string, params?: Record): void; /** 子类收到 JSON-RPC 响应时调用此方法 */ protected handleResponse(data: JsonRpcResponse): void; private buildDebugRequest; protected emitDebugTrace(trace: { step: string; title: string; duration?: string; request?: any; response?: any; payload?: any; error?: string; exception?: any; proxy?: string; }): void; } export {}; //# sourceMappingURL=base-client.d.ts.map