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

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

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

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

复刻画布 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 Python langchain-ai.github.io/langgraph/l...
LangGraph JS langchain-ai.github.io/langgraphjs...
LangChain Python python.langchain.com/llms.txt
LangChain JS js.langchain.com/llms.txt

快速入门

安装 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
bash 复制代码
npx @modelcontextprotocol/inspector
  • 在这里,您可以测试 工具 调用。

连接到光标

  • 打开 光标设置MCP 选项卡。
  • 这将打开 ~/.cursor/mcp.json 文件。
  • 将以下内容粘贴到文件中(我们使用 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 被选中。

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

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

连接到风帆

  • 使用 Cmd+L (在 Mac 上)。
  • 点击 配置 MCP 打开配置文件, ~/.codeium/windsurf/mcp_config.json
  • 更新为 langgraph-docs-mcp,如上所示。
  • 更新 帆板规则/全球规则 为以下内容(或类似内容):
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

然后尝试一下示例提示:

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

连接到 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 复制代码
<rules>
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
</rules>
  • 您将在聊天输入的右下角看到您的工具。

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

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

连接到 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 

注意

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

vbscript 复制代码
<rules>
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
</rules>

然后尝试一下示例提示:

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

命令行界面

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

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

  1. 使用 YAML 配置文件:
  • 这将从本仓库中的 sample_config.yaml 文件加载 LangGraph Python 文档。
css 复制代码
mcpdoc --yaml sample_config.yaml
  1. 使用 JSON 配置文件:
  • 这将从本仓库中的 sample_config.json 文件加载 LangGraph Python 文档。
css 复制代码
mcpdoc --json sample_config.json
  1. 可以直接指定 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")

相关推荐
掘我的金8 小时前
MCP生产部署实战:从开发到上线的完整指南
llm·mcp
bytebeats9 小时前
在本地 LLM 上运行MCP
mcp
bytebeats10 小时前
MCP + A2A 可能是自互联网以来软件领域最大的变革
mcp
bytebeats11 小时前
强大的代理通信其实是 A2A + MCP + LangChain
langchain·mcp
掘我的金15 小时前
MCP 学习系列②:理解 MCP 的核心结构与思维模型
llm·mcp
前端搬砖小助手17 小时前
从 Stdio 到 HTTP SSE,在 APIPark 托管 MCP Server
mcp·apipark·ai网关·ai gateway
小奏技术1 天前
基于 Spring AI 和 MCP:用自然语言查询 RocketMQ 消息
后端·aigc·mcp
柒崽1 天前
如何搭建一个MCP服务,然后在Cursor中调用,半小时,彻底掌握MCP
mcp
波点兔2 天前
【亲测有效 | Cursor Pro每月500次快速请求扩5倍】(Windows版)Cursor中集成interactive-feedback-mcp
windows·mcp·cursor pro
CodeAgent2 天前
【MCP 第二篇】实现一个简易的MCP
ai编程·mcp