Back to MCP directory
publicPublicdnsLocal runtime

mcp-langchain-ts-client

一个将LangChain.js与Model Context Protocol集成的TS客户端库

article

README

🚀 mcp-langchain-ts-client

这是一个用于 Model Context Protocol 的 LangChain.js 客户端,它将 rectalogic/langchain-mcp 迁移到了 JS/TS LangChain 和 MCP API。

🚀 快速开始

本项目是一个用于 Model Context Protocol 的 LangChain.js 客户端,能帮助开发者在 JS/TS 环境下使用相关功能。

📦 安装指南

使用以下命令进行安装:

npm install mcp-langchain-ts-client

💻 使用示例

基础用法

const serverParams = {
  command: "npx",
  args: [
    "-y",
    "@modelcontextprotocol/server-everything"
  ]
}

// 初始化工具包
const toolkit = new MCPToolkit(serverParams);
await toolkit.initialize();

// 提取 LangChain.js 兼容的工具
const tools = toolkit.tools;

// 使用工具
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 });
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client