Cover image

MCP to Langchain Tools Conversion Utility / TypeScript

3 years

Works with Finder

2

Github Watches

6

Github Forks

18

Github Stars

MCP To LangChain Tools Conversion Utility / TypeScript License: MIT npm version

This package is intended to simplify the use of Model Context Protocol (MCP) server tools with LangChain / TypeScript.

Model Context Protocol (MCP), an open source technology announced by Anthropic, dramatically expands LLM’s scope by enabling external tool and resource integration, including Google Drive, Slack, Notion, Spotify, Docker, PostgreSQL, and more…

Over 2000 functional components available as MCP servers:

The goal of this utility is to make these 2000+ MCP servers readily accessible from LangChain.

It contains a utility function convertMcpToLangchainTools().
This async function handles parallel initialization of specified multiple MCP servers and converts their available tools into an array of LangChain-compatible tools.

For detailed information on how to use this library, please refer to the following document:

A python equivalent of this utility is available here

Prerequisites

  • Node.js 16+

Installation

npm i @h1deya/langchain-mcp-tools

Quick Start

A minimal but complete working usage example can be found in this example in the langchain-mcp-tools-ts-usage repo

convertMcpToLangchainTools() utility function accepts MCP server configurations that follow the same structure as Claude for Desktop, but only the contents of the mcpServers property, and is expressed as a JS Object, e.g.:

const mcpServers: McpServersConfig = {
  filesystem: {
    command: "npx",
    args: ["-y", "@modelcontextprotocol/server-filesystem", "."]
  },
  fetch: {
    command: "uvx",
    args: ["mcp-server-fetch"]
  }
};

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

This utility function initializes all specified MCP servers in parallel, and returns LangChain Tools (tools: StructuredTool[]) by gathering available MCP tools from the servers, and by wrapping them into LangChain tools. It also returns an async callback function (cleanup: McpServerCleanupFn) to be invoked to close all MCP server sessions when finished.

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

// import { ChatAnthropic } from "@langchain/anthropic";
const llm = new ChatAnthropic({ model: "claude-3-7-sonnet-latest" });

// import { createReactAgent } from "@langchain/langgraph/prebuilt";
const agent = createReactAgent({
  llm,
  tools
});

For hands-on experimentation with MCP server integration, try this LangChain application built with the utility

For detailed information on how to use this library, please refer to the following document:
"Supercharging LangChain: Integrating 2000+ MCP with ReAct"

Experimental Features

Remote MCP Server Support

mcp_servers configuration for SSE and Websocket servers are as follows:

    "sse-server-name": {
        url: `http://${sse_server_host}:${sse_server_port}/...`
    },

    "ws-server-name": {
        url: `ws://${ws_server_host}:${ws_server_port}/...`
    },

Note that the key "url" may be changed in the future to match the MCP server configurations used by Claude for Desktop once it introduces remote server support.

A usage example can be found here

Working Directory Configuration for Local MCP Servers

The working directory that is used when spawning a local (stdio) MCP server can be specified with the "cwd" key as follows:

    "local-server-name": {
      command: "...",
      args: [...],
      cwd: "/working/directory"  // the working dir to be use by the server
    },

The key name cwd is derived from TypeScript SDK's StdioServerParameters.

Configuration for Local MCP Server stderr Redirection

A new key "stderr" has been introduced to specify a file descriptor to which local (stdio) MCP server's stderr is redirected.
The key name stderr is derived from TypeScript SDK's StdioServerParameters.

    const logPath = `mcp-server-${serverName}.log`;
    const logFd = fs.openSync(logPath, "w");
    mcpServers[serverName].stderr = logFd;

A usage example can be found here

Limitations

  • Currently, only text results of tool calls are supported.
  • MCP features other than Tools are not supported.

Change Log

Can be found here

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • Andris Teikmanis
  • Latvian GPT assistant for developing GPT applications

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Callycode Limited
  • A geek-themed horoscope generator blending Bitcoin prices, tech jargon, and astrological whimsy.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Jan Meindl
  • Builds new GPTs

  • Khalid kalib
  • Write professional emails

  • XLwebDev.com
  • PR Professional: Guiding You to Get Media Placements and Publicity Quickly and Effectively

  • apappascs
  • Entdecken Sie die umfassendste und aktuellste Sammlung von MCP-Servern auf dem Markt. Dieses Repository dient als zentraler Hub und bietet einen umfangreichen Katalog von Open-Source- und Proprietary MCP-Servern mit Funktionen, Dokumentationslinks und Mitwirkenden.

  • OffchainLabs
  • GO -Umsetzung des Ethereum -Beweises des Anteils

  • huahuayu
  • Ein einheitliches API-Gateway zur Integration mehrerer Ethercan-ähnlicher Blockchain-Explorer-APIs mit Modellkontextprotokoll (MCP) für AI-Assistenten.

  • deemkeen
  • Steuern Sie Ihren MBOT2 mit einer Power Combo: MQTT+MCP+LLM

    Reviews

    3 (1)
    Avatar
    user_FNcsnqHS
    2025-04-15

    Filesystem MCP is an incredible tool for managing your filesystem efficiently. Created by the talented sebastianbachmaier, it offers seamless integration and a user-friendly interface. I've found it invaluable for organizing and maintaining my files with minimal effort. Highly recommend it! Check it out at https://mcp.so/server/save-filesystem-mcp/sebastianbachmaier.