llms.txt 是一个针对LLMs的网站索引,提供背景信息、指导以及指向详细markdown文件的链接。IDE如Cursor和Windsurf或应用程序如Claude Code/Desktop可以使用llms.txt来检索任务上下文。然而,这些应用程序使用不同的内置工具来读取和处理像llms.txt这样的文件。检索过程可能是不透明的,并且并不总是有办法审计工具调用或返回的上下文。
MCP 提供了一种方法,让开发者对这些应用程序使用的工具拥有完全控制权。这里,我们创建了一个开源的MCP服务器,以向MCP主机应用(例如Cursor、Windsurf、Claude Code/Desktop)提供(1)用户定义的llms.txt文件列表和(2)一个简单的fetch_docs工具,用于读取提供的任何llms.txt文件中的URL。这允许用户审计每个工具调用以及返回的上下文。
您可以在以下位置找到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的方法。curl -LsSf https://astral.sh/uv/install.sh | sh
llms.txt文件。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
npx @modelcontextprotocol/inspector
tool调用。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标签中运行。设置/规则并更新用户规则如下(或类似):对于关于LangGraph的任何问题,使用langgraph-docs-mcp服务器帮助回答 --
+ 调用list_doc_sources工具以获取可用的llms.txt文件
+ 调用fetch_docs工具以读取它
+ 反思llms.txt中的url
+ 反思输入的问题
+ 对于与问题相关的任何url调用fetch_docs
+ 使用此信息回答问题
CMD+L打开聊天。agent。然后,尝试一个示例提示,例如:
LangGraph有哪些类型的内存?
CMD+L(在Mac上)打开Cascade。配置MCP以打开配置文件~/.codeium/windsurf/mcp_config.json。langgraph-docs-mcp。Windsurf规则/全局规则如下(或类似):对于关于LangGraph的任何问题,使用langgraph-docs-mcp服务器帮助回答 --
+ 调用list_doc_sources工具以获取可用的llms.txt文件
+ 调用fetch_docs工具以读取它
+ 反思llms.txt中的url
+ 反思输入的问题
+ 对于与问题相关的任何url调用fetch_docs
然后,尝试示例提示:
设置/开发者以更新~/Library/Application\ Support/Claude/claude_desktop_config.json。langgraph-docs-mcp。[!注意] 如果您在尝试将MCPDoc工具添加到Claude Desktop时遇到Python版本不兼容的问题,您可以在
<details> <summary>示例配置</summary>uvx命令中显式指定python可执行文件的路径。</details>{ "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" ] } } }
[!注意] 目前(2025年3月21日)似乎Claude Desktop不支持全局规则的
rules,因此需要将以下内容附加到您的提示中。
<rules>
对于关于LangGraph的任何问题,使用langgraph-docs-mcp服务器帮助回答 --
+ 调用list_doc_sources工具以获取可用的llms.txt文件
+ 调用fetch_docs工具以读取它
+ 反思llms.txt中的url
+ 反思输入的问题
+ 对于与问题相关的任何url调用fetch_docs
</rules>
然后,尝试示例提示:
claude mcp add-json langgraph-docs '{"type":"stdio","command":"uvx" ,"args":["--from", "mcpdoc", "mcpdoc", "--urls", "langgraph:https://langchain-ai.github.io/langgraph/llms.txt", "LangChain:https://python.langchain.com/llms.txt"]}' -s local
~/.claude.json被更新。$ Claude
$ /mcp
[!注意] 目前(2025年3月21日)似乎Claude Code不支持全局规则的
rules,因此需要将以下内容附加到您的提示中。
<rules>
对于关于LangGraph的任何问题,使用langgraph-docs-mcp服务器帮助回答 --
+ 调用list_doc_sources工具以获取可用的llms.txt文件
+ 调用fetch_docs工具以读取它
+ 反思llms.txt中的url
+ 反思输入的问题
+ 对于与问题相关的任何url调用fetch_docs
</rules>
然后,尝试示例提示:
mcpdoc命令提供了一个简单的CLI来启动文档服务器。
您可以使用三种方式指定文档源,并且这些方式可以组合使用:
sample_config.yaml文件加载LangGraph Python文档。mcpdoc --yaml sample_config.yaml
sample_config.json文件加载LangGraph Python文档。mcpdoc --json sample_config.json
name:url格式指定可选名称。--urls参数来指定多个URL。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:
# mcp-mcpdoc服务器的示例配置
# 每个条目必须有一个llms_txt URL,并可选地有一个名称
- name: LangGraph Python
llms_txt: https://langchain-ai.github.io/langgraph/llms.txt
[
{
"name": "LangGraph Python",
"llms_txt": "https://langchain-ai.github.io/langgraph/llms.txt"
}
]
from mcpdoc.main import create_server
# 创建具有文档源的服务器
server = create_server(
[
{
"name": "LangGraph Python",
"llms_txt": "https://langchain-ai.github.io/langgraph/llms.txt",
},
# 您可以添加多个文档源
# {
# "name": "另一个文档",
# "llms_txt": "https://example.com/llms.txt",
# },
],