首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

LangChain团队试水 MCP:mcpdoc 文档工具服务助力

  • 25-04-18 20:21
  • 3293
  • 10690
juejin.cn

LangChain团队试水 MCP:mcpdoc 文档工具服务助力

Vibe Coding mcpdoc 是一个通用的 MCP 服务,旨在通过解析给定 llms.txt 文件并提取相关信息,协助 AI Agent 理解和运用复杂的框架文档。

LangChain 团队同时为 LangGraph 和 LangChain 类库提供了官方的 llms.txt,便于大家马上试用。详见!

image.png

复刻画布 refly.ai/share/canva…

概览

llms.txt 是 LLMs 的网站索引,提供背景信息、指导和链接到详细的 markdown 文件。像 Cursor 和 Windsurf 这样的 IDE 或像 Claude Code/Desktop 这样的应用程序可以使用 llms.txt 获取任务的上下文。然而,这些应用程序使用不同的内置工具来读取和处理类似于 llms.txt 的文件。检索过程可能不透明,通常没有审计工具调用或返回的上下文的方法。

提供了一种方式,让开发者能够对这些应用程序使用的工具拥有 完全控制 。在这里,我们创建了一个开源的 MCP 服务器 ,以向 MCP 主机应用程序(例如 Cursor、Windsurf、Claude Code/Desktop)提供(1)用户定义的 llms.txt 文件列表以及(2)一个简单的 fetch_docs 工具来读取所提供 llms.txt 文件内的 URL。这使得用户能够审计每次工具调用以及返回的上下文。

llms-txt

您可以在这里找到 langgraph 和 langchain 的 llms.txt 文件:

库llms.txt
LangGraph Pythonlangchain-ai.github.io/langgraph/l…
LangGraph JSlangchain-ai.github.io/langgraphjs…
LangChain Pythonpython.langchain.com/llms.txt
LangChain JSjs.langchain.com/llms.txt

快速入门

安装 uv

  • 请参阅官方 uv 文档以了解其他安装 uv 的方法。
arduino
代码解读
复制代码
curl -LsSf https://astral.sh/uv/install.sh | sh

选择一个 llms.txt 文件使用。

  • 例如, 这里是 LangGraph 的 llms.txt 文件。

注意:安全和领域访问控制

由于安全原因,mcpdoc 实施了严格的域名访问控制:

  1. 远程 llms.txt 文件 : 当您指定远程 llms.txt URL(例如 https://langchain-ai.github.io/langgraph/llms.txt )时,mcpdoc 会自动将该特定域名(langchain-ai.github.io)添加到允许的域名列表中。这意味着该工具只能从该域名上的 URL 获取文档。

  2. 本地 llms.txt 文件 : 使用本地文件时,不会自动将任何域名添加到允许的列表中。您必须使用 --allowed-domains 参数显式指定允许哪些域名。

  3. 添加额外的域名 : 为了允许从超出自动包含的域名获取内容:

    • 使用 --allowed-domains domain1.com domain2.com 添加特定域
    • 使用 --allowed-domains '*' 允许所有域(谨慎使用)

这种安全措施防止未经授权访问未被用户明确批准的域,确保文档只能从受信任的来源检索。

(可选) 使用您选择的 llms.txt 文件在本地测试 MCP 服务器:

lua
代码解读
复制代码
uvx --from mcpdoc mcpdoc \ --urls "LangGraph:https://langchain-ai.github.io/langgraph/llms.txt" "LangChain:https://python.langchain.com/llms.txt" \ --transport sse \ --port 8082 \ --host localhost
  • 这应该运行在:http://localhost:8082

Screenshot 2025-03-18 at 3 29 30 PM

  • 运行 MCP 检查器 并连接到运行中的服务器:
bash
代码解读
复制代码
npx @modelcontextprotocol/inspector

Screenshot 2025-03-18 at 3 30 30 PM

  • 在这里,您可以测试  工具  调用。

连接到光标

  • 打开  光标设置  和 MCP 选项卡。
  • 这将打开 ~/.cursor/mcp.json 文件。

Screenshot 2025-03-19 at 11 01 31 AM

  • 将以下内容粘贴到文件中(我们使用 langgraph-docs-mcp 名称,并链接到 LangGraph llms.txt)。
json
代码解读
复制代码
{ "mcpServers": { "langgraph-docs-mcp": { "command": "uvx", "args": [ "--from", "mcpdoc", "mcpdoc", "--urls", "LangGraph:https://langchain-ai.github.io/langgraph/llms.txt LangChain:https://python.langchain.com/llms.txt", "--transport", "stdio" ] } } }
  • 确认服务器正在  光标设置/MCP 选项卡中运行。
  • 最佳实践是随后更新 Cursor 全局 (用户) 规则。
  • 打开 Cursor  设置/规则 ,并更新  用户规则  为以下内容(或类似内容):
vbscript
代码解读
复制代码
for ANY question about LangGraph, use the langgraph-docs-mcp server to help answer -- + call list_doc_sources tool to get the available llms.txt file + call fetch_docs tool to read it + reflect on the urls in llms.txt + reflect on the input question + call fetch_docs on any urls relevant to the question + use this to answer the question
  • 使用 Cmd+L (在 Mac 上) 打开聊天。
  • 确保 agent 被选中。

Screenshot 2025-03-18 at 1 56 54 PM

然后,尝试一个示例提示,例如:

sql
代码解读
复制代码
what are types of memory in LangGraph?

Screenshot 2025-03-18 at 1 58 38 PM

连接到风帆

  • 使用 Cmd+L (在 Mac 上)。
  • 点击  配置 MCP 打开配置文件, ~/.codeium/windsurf/mcp_config.json 。
  • 更新为 langgraph-docs-mcp,如上所示。

Screenshot 2025-03-19 at 11 02 52 AM

  • 更新  帆板规则/全球规则  为以下内容(或类似内容):
vbscript
代码解读
复制代码
for ANY question about LangGraph, use the langgraph-docs-mcp server to help answer -- + call list_doc_sources tool to get the available llms.txt file + call fetch_docs tool to read it + reflect on the urls in llms.txt + reflect on the input question + call fetch_docs on any urls relevant to the question

Screenshot 2025-03-18 at 2 02 12 PM

然后尝试一下示例提示:

  • 它将执行你的工具调用。

Screenshot 2025-03-18 at 2 03 07 PM

连接到 Claude Desktop

  • 打开  设置/开发者  以更新 ~/Library/Application\ Support/Claude/claude_desktop_config.json 。
  • 更新为 langgraph-docs-mcp,如上所示。
  • 重启 Claude Desktop 应用。

注意

如果在尝试将 MCPDoc 工具添加到 Claude Desktop 时遇到 Python 版本不兼容的问题,可以在 uvx 命令中显式指定 python 可执行文件的路径。

示例配置

代码解读
复制代码

注意

目前(3/21/25),Claude Desktop 不支持  规则  作为全局规则,因此在你的提示中添加以下内容。

vbscript
代码解读
复制代码
for ANY question about LangGraph, use the langgraph-docs-mcp server to help answer -- + call list_doc_sources tool to get the available llms.txt file + call fetch_docs tool to read it + reflect on the urls in llms.txt + reflect on the input question + call fetch_docs on any urls relevant to the question

Screenshot 2025-03-18 at 2 05 54 PM

  • 您将在聊天输入的右下角看到您的工具。

Screenshot 2025-03-18 at 2 05 39 PM

然后,尝试一下示例提示:

  • 它会在处理您的请求时要求批准工具调用。

Screenshot 2025-03-18 at 2 06 54 PM

连接到 Claude Code

  • 在安装了 Claude Code 的终端中,运行此命令将 MCP 服务器添加到你的项目中:
json
代码解读
复制代码
claude mcp add-json langgraph-docs '{"type":"stdio","command":"uvx" ,"args":["--from", "mcpdoc", "mcpdoc", "--urls", "langgraph:https://langchain-ai.github.io/langgraph/llms.txt", "--urls", "LangChain:https://python.langchain.com/llms.txt"]}' -s local
  • 你会看到 ~/.claude.json 被更新。
  • 测试方法是启动 Claude Code 并运行以查看你的工具:
shell
代码解读
复制代码
$ Claude $ /mcp

Screenshot 2025-03-18 at 2 13 49 PM

注意

目前(3/21/25)看来,Claude Code 不支持  规则  作为全局规则,因此请将以下内容添加到你的提示中。

vbscript
代码解读
复制代码
for ANY question about LangGraph, use the langgraph-docs-mcp server to help answer -- + call list_doc_sources tool to get the available llms.txt file + call fetch_docs tool to read it + reflect on the urls in llms.txt + reflect on the input question + call fetch_docs on any urls relevant to the question

然后尝试一下示例提示:

  • 它会要求你批准工具调用。

Screenshot 2025-03-18 at 2 14 37 PM

命令行界面

The mcpdoc 命令提供了一个简单的命令行界面,用于启动文档服务器。

您可以以三种方式指定文档来源,这些方式可以组合使用:

  1. 使用 YAML 配置文件:
  • 这将从本仓库中的 sample_config.yaml 文件加载 LangGraph Python 文档。
css
代码解读
复制代码
mcpdoc --yaml sample_config.yaml

2. 使用 JSON 配置文件:

  • 这将从本仓库中的 sample_config.json 文件加载 LangGraph Python 文档。
css
代码解读
复制代码
mcpdoc --json sample_config.json

3. 可以直接指定 llms.txt URL,带有可选名称:

  • URL 可以以纯文本形式指定,或者使用可选名称,格式为 name:url。
  • 可以通过多次使用 --urls 参数来指定多个 URL。
  • 这是我们上面为 MCP 服务器加载 llms.txt 的方式。
ruby
代码解读
复制代码
mcpdoc --urls LangGraph:https://langchain-ai.github.io/langgraph/llms.txt --urls LangChain:https://python.langchain.com/llms.txt

你也可以将这些方法结合起来合并文档来源:

ruby
代码解读
复制代码
mcpdoc --yaml sample_config.yaml --json sample_config.json --urls LangGraph:https://langchain-ai.github.io/langgraph/llms.txt --urls LangChain:https://python.langchain.com/llms.txt

额外选项

  • --follow-redirects: 跟随 HTTP 重定向(默认为 False)
  • --timeout SECONDS:HTTP 请求超时时间(默认为 10.0 秒)

示例,包含额外选项:

css
代码解读
复制代码
mcpdoc --yaml sample_config.yaml --follow-redirects --timeout 15

这将加载带有 15 秒超时的 LangGraph Python 文档,并在必要时跟随任何 HTTP 重定向。

配置格式

Both YAML 和 JSON 配置文件应该包含一个文档来源列表。

每条源代码必须包含一个 llms_txt URL,并可选地包含一个 name

YAML 配置示例 (sample_config.yaml)

yaml
代码解读
复制代码
# Sample configuration for mcp-mcpdoc server # Each entry must have a llms_txt URL and optionally a name - name: LangGraph Python llms_txt: https://langchain-ai.github.io/langgraph/llms.txt

JSON 配置示例 (sample_config.json)

css
代码解读
复制代码
[ { "name": "LangGraph Python", "llms_txt": "https://langchain-ai.github.io/langgraph/llms.txt" }]

程序化使用

python
代码解读
复制代码
from mcpdoc.main import create_server # Create a server with documentation sources server = create_server( [ { "name": "LangGraph Python", "llms_txt": "https://langchain-ai.github.io/langgraph/llms.txt", }, # You can add multiple documentation sources # { # "name": "Another Documentation", # "llms_txt": "https://example.com/llms.txt", # }, ], follow_redirects=True, timeout=15.0, ) # Run the server server.run(transport="stdio")

、

注:本文转载自juejin.cn的Captaincc的文章"https://juejin.cn/post/7491234023739932709"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

133
开发工具
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2024 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top