@h1deya/langchain-mcp-tools - v0.2.8
    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: LogOptions & { logger?: McpToolsLogger }

        Optional configuration settings

        Options for configuring logging behavior.

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

          Custom logger implementation that follows the McpToolsLogger interface. If provided, overrides the default Logger instance.

      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)
      • 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"] }
      });