MCP文档管理与控制
一个MCP服务器,提供从任何llms.txt来源加载和获取文档的工具,让用户在IDE代理和应用程序中对LLM的情境检索拥有完全的控制权。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"langgraph-docs-mcp": {
"args": [
"--from",
"mcpdoc",
"mcpdoc",
"--urls",
"LangGraph:https://langchain-ai.github.io/langgraph/llms.txt LangChain:https://python.langchain.com/llms.txt",
"--transport",
"stdio"
],
"command": "uvx"
}
}
}
服务介绍
MCP LLMS-TXT 文档服务器
概述
llms.txt 是一个针对 LLMs 的网站索引,提供背景信息、指南以及指向详细 markdown 文件的链接。像 Cursor 和 Windsurf 这样的 IDE 或者像 Claude Code/Desktop 这样的应用程序可以使用 llms.txt 来为任务检索上下文。然而,这些应用程序使用不同的内置工具来读取和处理像 llms.txt 这样的文件。检索过程可能是不透明的,并且并不总是有办法审核工具调用或返回的上下文。
MCP 为开发者提供了对这些应用程序所使用的工具的完全控制。在这里,我们创建了一个开源的 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 | https://langchain-ai.github.io/langgraph/llms.txt |
| LangGraph JS | https://langchain-ai.github.io/langgraphjs/llms.txt |
| LangChain Python | https://python.langchain.com/llms.txt |
| LangChain JS | https://js.langchain.com/llms.txt |
快速开始
安装 uv
- 请参阅 官方 uv 文档 了解其他安装
uv的方法。
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 服务器:
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 检查器 并连接到正在运行的服务器:
npx @modelcontextprotocol/inspector
- 在这里,您可以测试
tool调用。
连接到 Cursor
- 打开
Cursor 设置和MCP标签页。 - 这将打开
~/.cursor/mcp.json文件。
- 将以下内容粘贴到文件中(我们使用
langgraph-docs-mcp名称并链接到 LangGraph 的llms.txt)。
{
"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"
]
}
}
}
- 确认服务器正在
Cursor 设置/MCP标签页中运行。 - 最佳实践是随后更新 Cursor 全局(用户)规则。
- 打开 Cursor
设置/规则并使用以下内容(或类似内容)更新用户规则:
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。
然后,尝试一个示例提示,如:
what are types of memory in LangGraph?
连接到 Windsurf
- 通过
CMD+L(在 Mac 上)打开 Cascade。 - 单击
配置 MCP以打开配置文件~/.codeium/windsurf/mcp_config.json。 - 如上所述更新为
langgraph-docs-mcp。
- 使用以下内容(或类似内容)更新
Windsurf 规则/全局规则:
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 应用程序。
[!注意]
如果在尝试向 Claude Desktop 添加 MCPDoc 工具时遇到 Python 版本不兼容的问题,您可以在uvx命令中明确指定python可执行文件的路径。{ "mcpServers": { "langgraph-docs-mcp": { "command": "uvx", "args": [ "--python", "/path/to/python", "--from", "mcpdoc", "mcpdoc", "--urls", "LangGraph:https://langchain-ai.github.io/langgraph/llms.txt", "--transport", "stdio" ] } } }
[!注意]
目前(3/21/25)看来 Claude Desktop 不支持全局规则的rules,因此请在提示中追加以下内容。
<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 服务器添加到您的项目中:
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 并运行来测试您的工具:
$ Claude
$ /mcp
[!注意]
目前(3/21/25)看来 Claude Code 不支持全局规则的rules,因此请在提示中追加以下内容。
<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>
然后,尝试示例提示:
- 它将要求批准工具调用。
命令行界面
mcpdoc 命令提供了一个简单的 CLI 来启动文档服务器。
您可以以三种方式指定文档源,并且这些方式可以组合使用:
- 使用 YAML 配置文件:
- 这将从本仓库中的
sample_config.yaml文件加载 LangGraph Python 文档。
mcpdoc --yaml sample_config.yaml
- 使用 JSON 配置文件:
- 这将从本仓库中的
sample_config.json文件加载 LangGraph Python 文档。
mcpdoc --json sample_config.json
- 直接指定带有可选名称的 llms.txt URL:
- URL 可以指定为纯 URL,也可以使用
name:url格式带可选名称。 - 你可以通过多次使用
--urls参数来指定多个 URL。 - 这是我们上面为 MCP 服务器加载
llms.txt的方法。
mcpdoc --urls LangGraph:https://langchain-ai.github.io/langgraph/llms.txt --urls LangChain:https://python.langchain.com/llms.txt
你还可以结合这些方法来合并文档源:
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)
带有其他选项的示例:
mcpdoc --yaml sample_config.yaml --follow-redirects --timeout 15
这将以 15 秒的超时时间加载 LangGraph Python 文档,并在必要时跟随任何 HTTP 重定向。
配置格式
YAML 和 JSON 配置文件都应包含一个文档源列表。
每个源必须包含一个 llms_txt URL,并且可以可选地包含一个 name:
YAML 配置示例 (sample_config.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)
[
{
"name": "LangGraph Python",
"llms_txt": "https://langchain-ai.github.io/langgraph/llms.txt"
}
]
程序化使用
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")