UNPKG

adk-typescript

Version:

TypeScript port of Google's Agent Development Kit (ADK)

62 lines (61 loc) 2.35 kB
import { BaseTool, FunctionDeclaration } from '../BaseTool'; import { ToolContext } from '../toolContext'; import { ClientSession, McpBaseTool, MCPSessionManager } from './MCPSessionManager'; import { AuthCredential, AuthScheme } from '../../auth'; /** * Turns a MCP Tool into a Vertex Agent Framework Tool. * * Internally, the tool initializes from a MCP Tool, and uses the MCP Session to * call the tool. */ export declare class MCPTool extends BaseTool { private mcpTool; private mcpSession; private mcpSessionManager; private authScheme?; private authCredential?; /** * Initializes a MCPTool. * * This tool wraps a MCP Tool interface and an active MCP Session. It invokes * the MCP Tool through executing the tool from remote MCP Session. * * @param options Configuration options for the MCPTool * @param options.mcpTool The MCP tool to wrap * @param options.mcpSession The MCP session to use to call the tool * @param options.mcpSessionManager The session manager to reinitialize sessions if needed * @param options.authScheme Optional authentication scheme to use * @param options.authCredential Optional authentication credential to use * * @throws Error If mcpTool or mcpSession is null/undefined */ constructor({ mcpTool, mcpSession, mcpSessionManager, authScheme, authCredential, }: { mcpTool: McpBaseTool; mcpSession: ClientSession; mcpSessionManager: MCPSessionManager; authScheme?: AuthScheme; authCredential?: AuthCredential; }); /** * Private method to reinitialize the MCP session if it's closed */ private _reinitializeSession; /** * Get the function declaration for the tool * @returns The function declaration object */ protected _getDeclaration(): FunctionDeclaration | null; /** * Execute the tool asynchronously * @param args Arguments to pass to the tool * @param toolContext The tool context * @returns The result of executing the tool */ execute(args: any, toolContext: ToolContext): Promise<any>; /** * Execute with retry logic if the session is closed * @param args Arguments to pass to the tool * @returns The result of executing the tool */ private executeWithRetry; }