Sponsored by Deepsite.site

MCP Client Using LangChain / TypeScript

Created By
hideya10 months ago
Simple CLI MCP Client Implementation Using LangChain ReAct Agent / TypeScript
Content

MCP Client Using LangChain / TypeScript License: MIT

This simple Model Context Protocol (MCP) client demonstrates the use of MCP server tools by LangChain ReAct Agent.

It leverages a utility function convertMcpToLangchainTools() from @h1deya/langchain-mcp-tools.
This function handles parallel initialization of specified multiple MCP servers and converts their available tools into an array of LangChain-compatible tools (StructuredTool[]).

LLMs from Anthropic, OpenAI and Groq are currently supported.

A python version of this MCP client is available here

Prerequisites

  • Node.js 16+
  • npm 7+ (npx) to run Node.js-based MCP servers
  • [optional] uv (uvx) installed to run Python-based MCP servers
  • API keys from Anthropic, OpenAI, and/or Groq as needed.

Setup

  1. Install dependencies:

    npm install
    
  2. Setup API keys:

    cp .env.template .env
    
    • Update .env as needed.
    • .gitignore is configured to ignore .env to prevent accidental commits of the credentials.
  3. Configure LLM and MCP Servers settings llm_mcp_config.json5 as needed.

    • The configuration file format for MCP servers follows the same structure as Claude for Desktop, with one difference: the key name mcpServers has been changed to mcp_servers to follow the snake_case convention commonly used in JSON configuration files.
    • The file format is JSON5, where comments and trailing commas are allowed.
    • The format is further extended to replace ${...} notations with the values of corresponding environment variables.
    • Keep all the credentials and private info in the .env file and refer to them with ${...} notation as needed.

Usage

Run the app:

npm start

Run in verbose mode:

npm run start:v

See commandline options:

npm run start:h

At the prompt, you can simply press Enter to use example queries that perform MCP server tool invocations.

Example queries can be configured in llm_mcp_config.json5

Recommend Clients
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
LutraLutra is the first MCP compatible client built for everyone
WindsurfThe new purpose-built IDE to harness magic
MCP PlaygroundCall MCP Server Tools Online
Roo Code (prev. Roo Cline)Roo Code (prev. Roo Cline) gives you a whole dev team of AI agents in your code editor.
ZedCode at the speed of thought โ€“ Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Cherry Studio๐Ÿ’ Cherry Studio is a desktop client that supports for multiple LLM providers.
y-cli ๐Ÿš€A Tiny Terminal Chat App for AI Models with MCP Client Support
ChatWiseThe second fastest AI chatbotโ„ข
A Sleek AI Assistant & MCP Client5ire is a cross-platform desktop AI assistant, MCP client. It compatible with major service providers, supports local knowledge base and tools via model context protocol servers .
Cline โ€“ #1 on OpenRouterAutonomous coding agent right in your IDE, capable of creating/editing files, executing commands, using the browser, and more with your permission every step of the way.
DeepChatYour AI Partner on Desktop
Y GuiA web-based graphical interface for AI chat interactions with support for multiple AI models and MCP (Model Context Protocol) servers.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
chatmcpChatMCP is an AI chat client implementing the Model Context Protocol (MCP).
CursorThe AI Code Editor
Refact.aiOpen-source AI Agent for VS Code and JetBrains that autonomously solves coding tasks end-to-end.
Continueโฉ Create, share, and use custom AI code assistants with our open-source IDE extensions and hub of models, rules, prompts, docs, and other building blocks
BACHAI-TWITTER-API45Twitter็š„ไธ€ไบ›api mcp
MCP ConnectEnables cloud-based AI services to access local Stdio based MCP servers via HTTP requests
HyperChatHyperChat is a Chat client that strives for openness, utilizing APIs from various LLMs to achieve the best Chat experience, as well as implementing productivity tools through the MCP protocol.