返回市场
麦普文档

麦普文档

作者:teddylee7778 星标更新:2025-03-22

项目介绍

MCP LLMS-TXT 文档服务器

概述

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。这允许用户审计每个工具调用以及返回的上下文。

mcpdoc

快速开始

安装 uv

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

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

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

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

截图 2025-03-18 下午 3:29:30

npx @modelcontextprotocol/inspector

截图 2025-03-18 下午 3:30:30

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

连接到 Cursor

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

截图 2025-03-19 上午 11:01:31

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

截图 2025-03-18 下午 1:56:54

然后,尝试示例提示,例如:

使用 langgraph-docs-mcp 服务器回答任何关于 LangGraph 的问题 --
+ 调用 list_doc_sources 工具获取可用的 llms.txt 文件
+ 调用 fetch_docs 工具读取它
+ 反思 llms.txt 中的 URL
+ 反思输入的问题
+ 对于与问题相关的任何 URL 调用 fetch_docs
+ 使用此信息回答问题

什么是 LangGraph 中的记忆类型?

截图 2025-03-18 下午 1:58:38

连接到 Windsurf

  • 使用 CMD+L(Mac)打开 Cascade。
  • 单击 Configure MCP 打开配置文件 ~/.codeium/windsurf/mcp_config.json
  • 更新为 langgraph-docs-mcp,如上所述。

截图 2025-03-19 上午 11:02:52

  • 使用 CMD+L(Mac)打开 Cascade 并刷新 MCP 服务器。
  • 列出可用的 MCP 服务器,显示 langgraph-docs-mcp 已连接。

截图 2025-03-18 下午 2:02:12

然后,尝试示例提示:

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

截图 2025-03-18 下午 2:03:07

连接到 Claude Desktop

  • 打开 设置/开发者 更新 ~/Library/Application\ Support/Claude/claude_desktop_config.json
  • 更新为 langgraph-docs-mcp,如上所述。
  • 重启 Claude Desktop 应用程序。

截图 2025-03-18 下午 2:05:54

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

截图 2025-03-18 下午 2:05:39

然后,尝试示例提示:

  • 它将请求批准工具调用,因为它处理您的请求。

截图 2025-03-18 下午 2:06:54

连接到 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"]}' -s local
  • 您将看到 ~/.claude.json 已更新。
  • 通过启动 Claude Code 并运行以下命令来测试,查看您的工具:
$ Claude
$ /mcp 

截图 2025-03-18 下午 2:13:49

然后,尝试示例提示:

  • 它将请求批准工具调用。

截图 2025-03-18 下午 2:14:37

命令行界面

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

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

  1. 使用 YAML 配置文件:
  • 这将从本仓库中的 sample_config.yaml 文件加载 LangGraph Python 文档。
mcpdoc --yaml sample_config.yaml
  1. 使用 JSON 配置文件:
  • 这将从本仓库中的 sample_config.json 文件加载 LangGraph Python 文档。
mcpdoc --json sample_config.json
  1. 直接指定 llms.txt URL,可选名称:
  • URL 可以作为纯 URL 指定,也可以使用 name:url 格式指定可选名称。
  • 这就是我们上面加载 MCP 服务器的 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

YAML 配置示例(sample_config.yaml)

# mcp-mcpdoc 服务器的示例配置
# 每个条目必须有一个 llms_txt URL,并可选地有一个名称
- 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

# 创建一个具有文档来源的服务器
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")