llms.txt 是一个针对大型语言模型(LLMs)的网站索引,提供背景信息、指导以及链接到详细的 Markdown 文件。IDE 如 Cursor 和 Windsurf 或者应用程序如 Claude Code/Desktop 可以使用 llms.txt 来检索任务上下文。然而,这些应用程序使用不同的内置工具来读取和处理像 llms.txt 这样的文件。检索过程可能是不透明的,并且通常没有方法来审计工具调用或返回的上下文。
MCP 提供了一种让开发者对这些应用程序使用的工具拥有完全控制权的方法。在这里,我们创建了一个开源的 MCP 服务器 MCP 服务器,为 MCP 主机应用(例如,Cursor、Windsurf、Claude Code/Desktop)提供(1)用户定义的 llms.txt 文件列表和(2)一个简单的 fetch_docs 工具,用于读取提供的任何 llms.txt 文件中的 URL。这允许用户审计每个工具调用以及返回的上下文。
uv 的方法。curl -LsSf https://astral.sh/uv/install.sh | sh
llms.txt 文件。llms.txt 文件。llms.txt 文件:uvx --from mcpdoc mcpdoc \
--urls LangGraph:https://langchain-ai.github.io/langgraph/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",
"--transport",
"stdio",
"--port",
"8081",
"--host",
"localhost"
]
}
}
}
Cursor 设置/MCP 标签页中服务器正在运行。CMD+L(Mac)打开聊天窗口。agent。然后,尝试示例提示,例如:
使用 langgraph-docs-mcp 服务器回答任何关于 LangGraph 的问题 --
+ 调用 list_doc_sources 工具获取可用的 llms.txt 文件
+ 调用 fetch_docs 工具读取它
+ 反思 llms.txt 中的 URL
+ 反思输入的问题
+ 对于与问题相关的任何 URL 调用 fetch_docs
+ 使用此信息回答问题
什么是 LangGraph 中的记忆类型?
CMD+L(Mac)打开 Cascade。Configure MCP 打开配置文件 ~/.codeium/windsurf/mcp_config.json。langgraph-docs-mcp,如上所述。CMD+L(Mac)打开 Cascade 并刷新 MCP 服务器。langgraph-docs-mcp 已连接。然后,尝试示例提示:
设置/开发者 更新 ~/Library/Application\ Support/Claude/claude_desktop_config.json。langgraph-docs-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"]}' -s local
~/.claude.json 已更新。$ Claude
$ /mcp
然后,尝试示例提示:
mcpdoc 命令提供了一个简单的 CLI 来启动文档服务器。
您可以使用三种方式指定文档来源,并且这些方式可以组合使用:
sample_config.yaml 文件加载 LangGraph Python 文档。mcpdoc --yaml sample_config.yaml
sample_config.json 文件加载 LangGraph Python 文档。mcpdoc --json sample_config.json
name:url 格式指定可选名称。llms.txt 的方式。mcpdoc --urls LangGraph:https://langchain-ai.github.io/langgraph/llms.txt
您还可以结合这些方法合并文档来源:
mcpdoc --yaml sample_config.yaml --json sample_config.json --urls https://langchain-ai.github.io/langgraph/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": "Another Documentation",
# "llms_txt": "https://example.com/llms.txt",
# },
],
follow_redirects=True,
timeout=15.0,
)
# 运行服务器
server.run(transport="stdio")