@langchain/mcp-adapters
Version:
LangChain.js adapters for Model Context Protocol (MCP)
49 lines (48 loc) • 1.94 kB
TypeScript
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import type { CallToolResult, TextContent, ImageContent, EmbeddedResource } from "@modelcontextprotocol/sdk/types.js";
import { type StructuredToolInterface } from "@langchain/core/tools";
export type CallToolResultContentType = CallToolResult["content"][number]["type"];
export type CallToolResultContent = TextContent | ImageContent | EmbeddedResource;
/**
* Custom error class for tool exceptions
*/
export declare class ToolException extends Error {
constructor(message: string);
}
export type LoadMcpToolsOptions = {
/**
* If true, throw an error if a tool fails to load.
*
* @default true
*/
throwOnLoadError?: boolean;
/**
* If true, the tool name will be prefixed with the server name followed by a double underscore.
* This is useful if you want to avoid tool name collisions across servers.
*
* @default false
*/
prefixToolNameWithServerName?: boolean;
/**
* An additional prefix to add to the tool name. Will be added at the very beginning of the tool
* name, separated by a double underscore.
*
* For example, if `additionalToolNamePrefix` is `"mcp"`, and `prefixToolNameWithServerName` is
* `true`, the tool name `"my-tool"` provided by server `"my-server"` will become
* `"mcp__my-server__my-tool"`.
*
* Similarly, if `additionalToolNamePrefix` is `mcp` and `prefixToolNameWithServerName` is false,
* the tool name would be `"mcp__my-tool"`.
*
* @default ""
*/
additionalToolNamePrefix?: string;
};
/**
* Load all tools from an MCP client.
*
* @param serverName - The name of the server to load tools from
* @param client - The MCP client
* @returns A list of LangChain tools
*/
export declare function loadMcpTools(serverName: string, client: Client, options?: LoadMcpToolsOptions): Promise<StructuredToolInterface[]>;