关于 langchain-mcp
langchain-mcp 是为 LangChain 提供 Model Context Protocol 工具调用支持的 Python 库。开发者可将 MCP 会话转换为 LangChain 的 BaseTool 列表,供 Agent 使用。README 提示 LangChain 已有更官方的 langchain-mcp-adapters 实现。
主要功能
- 01将 MCP 会话封装为 MCPToolkit
- 02通过 initialize 与 get_tools 获取工具
- 03输出 langchain_core 的 BaseTool 列表
- 04附带可运行的示例脚本
适用场景
- 01在 LangChain 应用中调用 MCP 服务提供的工具
- 02让 LLM 通过文件系统 MCP 服务读取和总结文件
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
暂未收录安装方式
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
还没有获取到工具列表
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
langchain-mcp
注意:langchain 现在有更官方的实现 langchain-mcp-adapters
在 LangChain 中支持调用 Model Context Protocol 工具。
创建一个 langchain_mcp.MCPToolkit,并传入一个 mcp.ClientSession,
然后执行 await toolkit.initialize() 和 toolkit.get_tools(),即可获取 langchain_core.tools.BaseTool 列表。
示例:
演示
你可以通过 Groq llama-3.1-8b-instant 运行演示:
$ export GROQ_API_KEY=xxx
$ uv run tests/demo.py "Read and summarize the file ./LICENSE"
Secure MCP Filesystem Server running on stdio
Allowed directories: [ '/users/aw/projects/rectalogic/langchain-mcp' ]
The file ./LICENSE is a MIT License agreement. It states that the software is provided "as is" without warranty and that the authors and copyright holders are not liable for any claims, damages, or other liability arising from the software or its use.
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。