UNPKG

mcp-use

Version:

Opinionated MCP Framework for TypeScript (@modelcontextprotocol/sdk compatible) - Build MCP Agents, Clients and Servers with support for ChatGPT Apps, Code Mode, OAuth, Notifications, Sampling, Observability and more.

112 lines 5.05 kB
import type { MCPClient } from "../client.js"; import type { BaseConnector } from "../connectors/base.js"; /** * Abstract base class for converting MCP tools to other framework formats. * * This class defines the common interface that all adapter implementations * should follow to ensure consistency across different frameworks. */ export declare abstract class BaseAdapter<T> { /** * List of tool names that should not be available. */ protected readonly disallowedTools: string[]; /** * Internal cache that maps a connector instance to the list of tools * generated for it. */ private readonly connectorToolMap; constructor(disallowedTools?: string[]); /** * Create tools from an MCPClient instance. * * This is the recommended way to create tools from an MCPClient, as it handles * session creation and connector extraction automatically. * * @param client The MCPClient to extract tools from. * @param disallowedTools Optional list of tool names to exclude. * @returns A promise that resolves with a list of converted tools. */ static createTools<TTool, TAdapter extends BaseAdapter<TTool>>(this: new (disallowedTools?: string[]) => TAdapter, client: MCPClient, disallowedTools?: string[]): Promise<TTool[]>; /** * Dynamically load tools for a specific connector. * * @param connector The connector to load tools for. * @returns The list of tools that were loaded in the target framework's format. */ loadToolsForConnector(connector: BaseConnector): Promise<T[]>; /** * Convert an MCP tool to the target framework's tool format. * * @param mcpTool The MCP tool definition to convert. * @param connector The connector that provides this tool. * @returns The converted tool, or null / undefined if no tool should be produced. */ protected abstract convertTool(mcpTool: Record<string, any>, connector: BaseConnector): T | null | undefined; /** * Convert an MCP resource to the target framework's tool format. * * @param mcpResource The MCP resource definition to convert. * @param connector The connector that provides this resource. * @returns The converted resource as a tool, or null / undefined if no tool should be produced. */ protected abstract convertResource?(mcpResource: Record<string, any>, connector: BaseConnector): T | null | undefined; /** * Convert an MCP prompt to the target framework's tool format. * * @param mcpPrompt The MCP prompt definition to convert. * @param connector The connector that provides this prompt. * @returns The converted prompt as a tool, or null / undefined if no tool should be produced. */ protected abstract convertPrompt?(mcpPrompt: Record<string, any>, connector: BaseConnector): T | null | undefined; /** * Create tools from MCP tools in all provided connectors. * * @param connectors List of MCP connectors to create tools from. * @returns A promise that resolves with all converted tools. */ createToolsFromConnectors(connectors: BaseConnector[]): Promise<T[]>; /** * Dynamically load resources for a specific connector. * * @param connector The connector to load resources for. * @returns The list of resources that were loaded in the target framework's format. */ loadResourcesForConnector(connector: BaseConnector): Promise<T[]>; /** * Dynamically load prompts for a specific connector. * * @param connector The connector to load prompts for. * @returns The list of prompts that were loaded in the target framework's format. */ loadPromptsForConnector(connector: BaseConnector): Promise<T[]>; /** * Create resources from MCP resources in all provided connectors. * * @param connectors List of MCP connectors to create resources from. * @returns A promise that resolves with all converted resources. */ createResourcesFromConnectors(connectors: BaseConnector[]): Promise<T[]>; /** * Create prompts from MCP prompts in all provided connectors. * * @param connectors List of MCP connectors to create prompts from. * @returns A promise that resolves with all converted prompts. */ createPromptsFromConnectors(connectors: BaseConnector[]): Promise<T[]>; /** * Check if a connector is initialized and has tools. * * @param connector The connector to check. * @returns True if the connector is initialized and has tools, false otherwise. */ private checkConnectorInitialized; /** * Ensure a connector is initialized. * * @param connector The connector to initialize. * @returns True if initialization succeeded, false otherwise. */ private ensureConnectorInitialized; } //# sourceMappingURL=base.d.ts.map