Back to MCP Catalog

LangChain.js Client MCP Server

Developer ToolsTypeScript
A TypeScript client for integrating LangChain.js with Model Context Protocol

This package provides a seamless bridge between LangChain.js and Model Context Protocol (MCP), allowing developers to easily incorporate MCP tools into their LangChain workflows. It serves as a TypeScript port of the Python-based langchain-mcp library, making MCP functionality accessible within JavaScript and TypeScript applications. With this client, you can initialize an MCP server, extract LangChain-compatible tools, and integrate them directly into agents and other LangChain constructs. This enables powerful AI applications that can leverage both LangChain's flexibility and MCP's standardized tool interfaces.

Overview

The mcp-langchain-ts-client package allows you to use Model Context Protocol (MCP) tools within your LangChain.js applications. This client bridges the gap between these two ecosystems, enabling you to build more powerful AI applications.

Installation

You can install the package via npm:

npm install mcp-langchain-ts-client

Basic Usage

To use the MCP client with LangChain.js, follow these steps:

  1. First, import the MCPToolkit class from the package:
import { MCPToolkit } from "mcp-langchain-ts-client";
  1. Initialize the toolkit with server parameters:
const serverParams = {
  command: "npx",
  args: [
    "-y",
    "@modelcontextprotocol/server-everything"
  ]
};

const toolkit = new MCPToolkit(serverParams);
await toolkit.initialize();
  1. Extract LangChain.js compatible tools:
const tools = toolkit.tools;
  1. Use the tools with a LangChain agent:
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { ChatAnthropic } from "@langchain/anthropic";

const llm = new ChatAnthropic({ model: 'claude-3-5-sonnet-20241022' });
const agent = createReactAgent({ llm, tools });

// Now you can use the agent with MCP tools
const result = await agent.invoke({ input: "Your query here" });

Advanced Configuration

You can customize the MCP server configuration by modifying the server parameters. For example, you might want to use a different MCP server package or specify additional arguments:

const serverParams = {
  command: "npx",
  args: [
    "-y",
    "@modelcontextprotocol/server-custom",
    "--some-option=value"
  ]
};

Error Handling

The toolkit provides error handling for common issues. If the MCP server fails to start or respond, the initialize() method will throw an error with details about what went wrong.

Cleanup

When you're done using the MCP toolkit, it's good practice to clean up resources:

await toolkit.cleanup();

This will properly shut down the MCP server process.

Related MCPs

Apple Shortcuts
Developer ToolsJavaScript

Control Apple Shortcuts automations from AI assistants

Clojars Dependency Lookup
Developer ToolsJavaScript

Fetch dependency information from Clojars, the Clojure community's artifact repository

Simple Timeserver
Developer ToolsPython

Provides Claude with current time and timezone information

About Model Context Protocol

Model Context Protocol (MCP) allows AI models to access external tools and services, extending their capabilities beyond their training data.

Generate Cursor Documentation

Save time on coding by generating custom documentation and prompts for Cursor IDE.