@h1deya/langchain-mcp-tools - v0.3.5
    Preparing search index...

    Function convertMcpToLangchainTools

    • Initializes multiple MCP (Model Context Protocol) servers and converts them into LangChain tools. This function concurrently sets up all specified servers and aggregates their tools.

      Parameters

      • configs: McpServersConfig

        A mapping of server names to their respective configurations

      • Optionaloptions: ConvertMcpToLangchainOptions

        Optional configuration settings

        Configuration options for converting MCP servers to LangChain tools. Extends LogOptions to include provider-specific schema transformations and custom logging.

        • OptionallogLevel?: "trace" | "debug" | "info" | "warn" | "error" | "fatal"

          Log verbosity level. Higher levels include all lower levels (e.g., "debug" includes "info", "warn", "error", "fatal")

        • Optionallogger?: McpToolsLogger

          Custom logger implementation. If not provided, uses default Logger with specified logLevel

        • OptionalllmProvider?: LlmProvider

          LLM provider for schema compatibility transformations. Performs provider-specific JSON schema modifications to prevent compatibility issues

      Returns Promise<
          {
              tools: StructuredTool<ToolInputSchemaBase, any, any, any>[];
              cleanup: McpServerCleanupFn;
          },
      >

      A promise that resolves to: - tools: Array of StructuredTool instances ready for use with LangChain - cleanup: Function to properly terminate all server connections

      McpInitializationError if any server fails to initialize (includes connection errors, tool listing failures, configuration validation errors)

      • Servers are initialized concurrently for better performance
      • Configuration is validated and will throw errors for conflicts (e.g., both url and command specified)
      • Schema transformations are applied based on llmProvider to ensure compatibility
      • The cleanup function continues with remaining servers even if some cleanup operations fail
      const { tools, cleanup } = await convertMcpToLangchainTools({
      filesystem: { command: "npx", args: ["-y", "@modelcontextprotocol/server-filesystem", "."] },
      fetch: { command: "uvx", args: ["mcp-server-fetch"] }
      }, {
      llmProvider: "openai",
      logLevel: "debug"
      });