adk-typescript
Version:
TypeScript port of Google's Agent Development Kit (ADK)
96 lines (95 loc) • 2.79 kB
TypeScript
import { AsyncExitStack, ClientSession, StdioServerParameters, SseServerParams } from './MCPSessionManager';
import { MCPTool } from './MCPTool';
/**
* Connects to a MCP Server, and retrieves MCP Tools into ADK Tools.
*
* Example 1 (using fromServer helper):
* ```typescript
* async function loadTools() {
* const [tools, exitStack] = await MCPToolset.fromServer({
* connectionParams: {
* command: 'npx',
* args: ["-y", "@modelcontextprotocol/server-filesystem"]
* }
* });
*
* // Use the tools in an agent
* const agent = new Agent({
* tools
* });
*
* // Later, close the connection
* await exitStack.aclose();
* }
* ```
*
* Example 2 (using async/await with closure):
* ```typescript
* async function loadTools() {
* let toolset: MCPToolset | null = null;
* try {
* toolset = new MCPToolset({
* connectionParams: new SseServerParams({
* url: "http://0.0.0.0:8090/sse"
* })
* });
*
* await toolset.initialize();
* const tools = await toolset.loadTools();
*
* const agent = new Agent({
* tools
* });
*
* // Use the agent...
* } finally {
* if (toolset) {
* await toolset.exit();
* }
* }
* }
*/
export declare class MCPToolset {
private connectionParams;
private exitStack;
private errlog?;
private sessionManager;
private session?;
/**
* Initializes the MCPToolset.
* @param options Configuration options
* @param options.connectionParams The connection parameters to the MCP server
* @param options.errlog Optional error logging stream
*/
constructor({ connectionParams, errlog, }: {
connectionParams: StdioServerParameters | SseServerParams;
errlog?: any;
});
/**
* Retrieve all tools from the MCP server.
*
* @param options Configuration options
* @param options.connectionParams The connection parameters to the MCP server
* @param options.asyncExitStack Optional AsyncExitStack to use
* @param options.errlog Optional error logging stream
* @returns A tuple containing the list of MCPTools and the AsyncExitStack
*/
static fromServer({ connectionParams, asyncExitStack, errlog, }: {
connectionParams: StdioServerParameters | SseServerParams;
asyncExitStack?: AsyncExitStack;
errlog?: any;
}): Promise<[MCPTool[], AsyncExitStack]>;
/**
* Initializes the connection to the MCP Server.
*/
initialize(): Promise<ClientSession>;
/**
* Closes the connection to the MCP Server.
*/
exit(): Promise<void>;
/**
* Loads all tools from the MCP Server.
* @returns Array of MCPTool instances
*/
loadTools(): Promise<MCPTool[]>;
}