适用于模型上下文协议(Model Context Protocol)的LangChain.js客户端。
这是rectalogic/langchain-mcp到JS/TS LangChain和MCP API的移植。
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 });