Back to MCP directory
publicPublicdnsLocal runtime

langchain-mcp

该项目为LangChain提供Model Context Protocol(MCP)工具调用支持,通过MCP工具包实现与AI模型的交互,如文件读取和摘要生成。

article

README

🚀 langchain-mcp

langchain-mcp 是一个支持在 LangChain 中实现模型上下文协议工具调用的项目,为相关开发提供便利。

⚠️ 重要提示

LangChain 现在有一个更官方的实现 langchain-mcp-adapters

![PyPI - 版本](https://img Shields.io/pypi/v/langchain-mcp)

🚀 快速开始

本项目提供了 模型上下文协议 工具调用在 LangChain 中的支持。你可以通过创建一个 langchain_mcp.MCPToolkitmcp.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"
安全的 MCP 文件系统服务器在 stdio 上运行
允许的目录:[ '/users/aw/projects/rectalogic/langchain-mcp' ]
文件 ./LICENSE 是一个 MIT 许可证协议。它指出软件“按原样”提供,不作任何担保,并且作者和版权持有者不对因软件或其使用而产生的任何主张、损害或其他责任负责。
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