langchain mcp
*注意:langchain现在有一个更正式的实现 langchain mcp适配器*
模型上下文协议 LangChain中的工具调用支持。
创建一个 langchain_mcp.MCPToolkit 带着一个 mcp.ClientSession, 然后 await toolkit.initialize() 和 toolkit.get_tools() 获取以下列表 langchain_core.tools.BaseTools
例子:
https://github.com/rectalogic/langchain-mcp/blob/8fa8445a24755bf91789f52718c32361ed916f46/tests/demo.py#L34-143
演示
你可以运行演示 希腊 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.