icon for mcp server

LangChain MCP适配器

在LangChain中支持MCP工具调用

langchain-mcp

Note: langchain now has a more official implementation langchain-mcp-adapters

PyPI - Version

Model Context Protocol tool calling support in LangChain.

Create a langchain_mcp.MCPToolkit with an mcp.ClientSession, then await toolkit.initialize() and toolkit.get_tools() to get the list of langchain_core.tools.BaseTools.

Example:

https://github.com/rectalogic/langchain-mcp/blob/8fa8445a24755bf91789f52718c32361ed916f46/tests/demo.py#L34-L43

Demo

You can run the demo against 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.

为你推荐的相关 MCP 服务器

MCP Now 重磅来袭,抢先一步体验