0.0.17 • Published 10 months ago

@h1deya/mcp-langchain-tools v0.0.17

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

MCP Server To LangChain Tools Conversion Utility License: MIT npm version

This package is intended to simplify the use of MCP server tools within LangChain.

It contains a utility function convertMCPServersToLangChainTools() that initializes specified MCP servers, and returns LangChain Tools that wrap all the available MCP server tools.

Installation

npm i @h1deya/mcp-langchain-tool

Quick Start

convertMCPServersToLangChainTools() utility function accepts MCP server configuration in pretty much the same format as a JS Object interpretation of the JSON format used by Claude for Desktop (it just needs the contents of the mcpServers property). e.g.:

const mcpServers: MCPServersConfig = {
  filesystem: {
    command: 'npx',
    args: [
      '-y',
      '@modelcontextprotocol/server-filesystem',
      '/Users/username/Desktop'  // path to a directory to allow access to
    ]
  },
  fetch: {
    command: 'uvx',
    args: [
      'mcp-server-fetch'
    ]
  }
};

const { tools, cleanup } = await convertMCPServersToLangChainTools(mcpServers);

The utility functoin initializes all the MCP server connections concurrently, and returns LangChain Tools (tools: DynamicStructuredTool[]) by gathering all the available MCP server tools, and by wrapping them into LangChain Tools. It also returns cleanup callback function which is used to close all the connections to the MCP servers when finished.

The returned tools can be used with LangChain, e.g.:

const agent = createReactAgent({
  llm: llmModel,
  tools: tools,
  checkpointSaver: new MemorySaver()
});

A simple but complete usage example can be found in here

0.0.17

10 months ago

0.0.16

10 months ago

0.0.15

10 months ago

0.0.14

10 months ago

0.0.13

10 months ago

0.0.12

10 months ago

0.0.11

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago