LangChain团队试水 MCP:mcpdoc 文档工具服务助力
Vibe Coding mcpdoc 是一个通用的 MCP 服务,旨在通过解析给定 llms.txt 文件并提取相关信息,协助 AI Agent 理解和运用复杂的框架文档。
LangChain 团队同时为 LangGraph 和 LangChain 类库提供了官方的 llms.txt,便于大家马上试用。详见!
概览
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
- 请参阅官方 uv 文档以了解其他安装
uv
的方法。
arduino 代码解读复制代码curl -LsSf https://astral.sh/uv/install.sh | sh
选择一个 llms.txt
文件使用。
- 例如, 这里是 LangGraph 的
llms.txt
文件。
注意:安全和领域访问控制
由于安全原因,mcpdoc 实施了严格的域名访问控制:
远程 llms.txt 文件 : 当您指定远程 llms.txt URL(例如
https://langchain-ai.github.io/langgraph/llms.txt
)时,mcpdoc 会自动将该特定域名(langchain-ai.github.io
)添加到允许的域名列表中。这意味着该工具只能从该域名上的 URL 获取文档。本地 llms.txt 文件 : 使用本地文件时,不会自动将任何域名添加到允许的列表中。您必须使用
--allowed-domains
参数显式指定允许哪些域名。添加额外的域名 : 为了允许从超出自动包含的域名获取内容:
- 使用
--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
- 运行 MCP 检查器 并连接到运行中的服务器:
bash代码解读复制代码npx @modelcontextprotocol/inspector
- 在这里,您可以测试
工具
调用。
连接到光标
- 打开
光标设置
和MCP
选项卡。 - 这将打开
~/.cursor/mcp.json
文件。
- 将以下内容粘贴到文件中(我们使用
langgraph-docs-mcp
名称,并链接到 LangGraphllms.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 代码解读复制代码
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 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 代码解读复制代码
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
然后尝试一下示例提示:
- 它会要求你批准工具调用。
命令行界面
The mcpdoc
命令提供了一个简单的命令行界面,用于启动文档服务器。
您可以以三种方式指定文档来源,这些方式可以组合使用:
- 使用 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")
、
评论记录:
回复评论: