import type { AgentTool } from "@kenkaiiii/gg-agent"; import { MCPClientManager, type MCPElicitHandler } from "../mcp/index.js"; import type { MCPServerConfig } from "../mcp/types.js"; import type { ContextLimits } from "../context-limits.js"; /** * MCP tool wiring for one session: the client manager, the deferred * `tool_search` catalog (shared with deferred built-ins), cached-catalog stubs * and the live/cached reconcile maps. * * Never owns the tool array — it reads the session's CURRENT array through * `getTools` (the session may filter-replace it) and only appends to it or * swaps same-named entries in place, so the cached tool prefix stays stable. */ export declare class McpToolRegistry { private readonly getTools; private readonly getContextLimits; manager?: MCPClientManager; /** Deferred MCP tools awaiting discovery via tool_search. */ private catalog?; /** Live (connected) MCP tools by name — the reconcile target for cached stubs. */ private readonly liveTools; /** Server name for each cached-only tool, so a stub knows what to wait on. */ private readonly cachedToolServers; private readonly catalogCache; constructor(getTools: () => AgentTool[], getContextLimits: () => ContextLimits); createManager(options: { modernProtocol: boolean; onElicit: MCPElicitHandler | undefined; }): void; private ensureCatalog; /** Hold tools in the tool_search catalog and make sure tool_search exists. */ addDeferred(tools: AgentTool[]): void; /** Pull named entries out of the catalog (empty when no catalog exists). */ promote(names: string[]): AgentTool[]; /** Forget every MCP tool before a provider-switch reconnect re-adds them. */ clearMcpTools(): void; /** * Route freshly connected MCP tools: deferred into the tool_search catalog * (default — keeps ~8k tokens of schema out of every cache-miss turn) or * pushed eagerly when `defer` is false. * Promotion pushes onto the live tools array the running agent loop * re-reads every turn, so promoted tools are callable on the next step. */ addMcpTools(mcpTools: AgentTool[], defer: boolean): void; /** * Register `tool_search` once. Promotion of a cached-only entry waits for its * server so the model is told immediately when that capability turns out to * be unreachable, instead of promoting a tool that fails on first call. * * The catalog is created on demand rather than required up front: deferred * built-in tools populate it with zero MCP servers connected, so gating * registration on an existing catalog would leave those tools unreachable. */ ensureToolSearchTool(): void; /** Append tools, replacing any same-named entry (cached stub → live tool). */ private replaceOrPushTools; /** Swap already-promoted cached stubs for their live equivalents, in place. */ private replaceLivePromotedTools; /** * Publish cached tool definitions into the deferred catalog so `tool_search` * answers correctly on turn 1. A cached stub carries the real name, one-line * description and input schema; calling it waits for the live connection and * then dispatches against the real client, or returns a clear error when that * server ultimately failed. Live tools replace stubs on connect. */ seedFromCache(servers: MCPServerConfig[]): Promise; private buildCachedMcpTool; }