t

teddylee777

documentation-accessrag-systemsknowledge-and-memory

404 查看 · 2026-07-07 更新

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。这使得用户能够审计每个工具调用及返回的上下文。

mcpdoc

快速开始

安装 uv

bash curl -LsSf https://astral.sh/uv/install.sh | sh

选择一个要使用的 llms.txt 文件。

(可选)使用您选择的 llms.txt 文件在本地测试 MCP 服务器:

bash uvx --from mcpdoc mcpdoc --urls LangGraph:https://langchain-ai.github.io/langgraph/llms.txt --transport sse --port 8082 --host localhost

Screenshot 2025-03-18 at 3 29 30 PM

  • 运行 MCP 检查器 并连接到正在运行的服务器: bash npx @modelcontextprotocol/inspector

Screenshot 2025-03-18 at 3 30 30 PM

  • 在这里,您可以测试 tool 调用。

连接到 Cursor

  • 打开 Cursor 设置MCP 标签页。
  • 这将打开 ~/.cursor/mcp.json 文件。

Screenshot 2025-03-19 at 11 01 31 AM

  • 将以下内容粘贴到文件中(我们使用 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

Screenshot 2025-03-18 at 1 56 54 PM

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

使用 langgraph-docs-mcp 服务器回答任何关于 LangGraph 的问题 --

  • 调用 list_doc_sources 工具获取可用的 llms.txt 文件
  • 调用 fetch_docs 工具读取它
  • 反思 llms.txt 中的 URL
  • 反思输入的问题
  • 对与问题相关的任何 URL 调用 fetch_docs
  • 使用此信息回答问题

LangGraph 中有哪些类型的内存?

Screenshot 2025-03-18 at 1 58 38 PM

连接到 Windsurf

  • 使用 CMD+L(在 Mac 上)打开 Cascade。

  • 单击 Configure MCP 以打开配置文件 ~/.codeium/windsurf/mcp_config.json

  • 如上所述更新 langgraph-docs-mcpScreenshot 2025-03-19 at 11:02:52 AM

  • CMD+L(在Mac上)打开Cascade并刷新MCP服务器。

  • 可用的MCP服务器将被列出,显示langgraph-docs-mcp为已连接。

Screenshot 2025-03-18 at 2:02:12 PM

然后,尝试示例提示:

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

Screenshot 2025-03-18 at 2:03:07 PM

连接到Claude桌面版

  • 打开设置/开发者以更新~/Library/Application Support/Claude/claude_desktop_config.json
  • 按照上述说明更新为langgraph-docs-mcp
  • 重启Claude桌面应用程序。

Screenshot 2025-03-18 at 2:05:54 PM

  • 您将在聊天输入框的右下角看到您的工具。

Screenshot 2025-03-18 at 2:05:39 PM

然后,尝试示例提示:

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

Screenshot 2025-03-18 at 2:06:54 PM

连接到Claude Code

  • 在安装Claude Code后,在终端中运行以下命令将MCP服务器添加到您的项目中: bash 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 Code并运行以下命令来测试您的工具: bash $ Claude $ /mcp

Screenshot 2025-03-18 at 2:13:49 PM

然后,尝试示例提示:

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

Screenshot 2025-03-18 at 2:14:37 PM

命令行界面

mcpdoc命令提供了一个简单的CLI用于启动文档服务器。

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

  1. 使用YAML配置文件:
  • 这将从本仓库中的sample_config.yaml文件加载LangGraph Python文档。

bash mcpdoc --yaml sample_config.yaml

  1. 使用JSON配置文件:
  • 这将从本仓库中的sample_config.json文件加载LangGraph Python文档。

bash mcpdoc --json sample_config.json

  1. 直接指定带有可选名称的llms.txt URL:
  • URL可以指定为纯URL或使用name:url格式指定带名称的URL。
  • 这是我们上面为MCP服务器加载llms.txt的方式。

bash mcpdoc --urls LangGraph:https://langchain-ai.github.io/langgraph/llms.txt

您还可以结合这些方法来合并文档源:

bash 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)

带有其他选项的示例:

bash mcpdoc --yaml sample_config.yaml --follow-redirects --timeout 15

这将以15秒的超时时间加载LangGraph Python文档,并在必要时跟随任何HTTP重定向。

配置格式

YAML和JSON配置文件都应包含一个文档源列表。

每个源必须包括一个llms_txt URL,并且可以可选地包括一个name

YAML配置示例 (sample_config.yaml)

yaml

mcp-mcpdoc服务器的示例配置

每个条目必须有一个llms_txt URL,并且可以可选地有一个name

json [ { "name": "LangGraph Python", "llms_txt": "https://langchain-ai.github.io/langgraph/llms.txt" } ]

程序化使用

python 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", # }, ], follow_redirects=True, timeout=15.0, )

运行服务器

server.run(transport="stdio")

工具列表

  • list_doc_sources: List all available documentation sources.This is the first tool you should call in the documentation workflow.It provides URLs to llms.txt files or local file paths that the user has made available.Returns: A string containing a formatted list of documentation sources with their URLs or file paths

  • fetch_docs: Fetch and parse documentation from a given URL or local file.Use this tool after list_doc_sources to:1. First fetch the llms.txt file from a documentation source2. Analyze the URLs listed in the llms.txt file3. Then fetch specific documentation pages relevant to the user s questionArgs: url: The URL to fetch documentation from.Returns: The fetched documentation content converted to markdown, or an error message if the request fails or the URL is not from an allowed domain.

服务配置

[{'mcpServers': {'langgraph-docs-mcp': {'args': ['--from', 'mcpdoc', 'mcpdoc', '--urls', 'LangGraph:https://langchain-ai.github.io/langgraph/llms.txt', '--transport', 'stdio', '--port', '8081', '--host', 'localhost'], 'command': 'uvx'}}}]

来源