Skip to main content
Glama
Jaynt27

langgraph-mcp

by Jaynt27

LangGraph RAG MCP

一个通过 Model Context Protocol(MCP)提供 LangGraph 文档的检索增强生成(RAG)系统。

概述

本项目构建了一个文档检索系统,它可以:

  1. 从官方网址收集并处理 LangGraph 文档

  2. 根据这些文档创建用于语义搜索的向量数据库

  3. 通过 Model Context Protocol(MCP)对外提供这些知识

  4. 与 VS Code、Cursor、Claude Desktop 或 Windsurf 等兼容 MCP 的主机集成

Related MCP server: AI Research Assistant MCP Server

工作原理

1. 文档收集与处理(上下文)

  • 递归爬取并清理 来自多个网站 URL 的 LangGraph 文档,使用 RecursiveUrlLoader 和 BeautifulSoup。

  • 将文本拆分 为更易管理的块,使用 RecursiveCharacterTextSplitter 结合 tiktoken 实现精确的 token 计数。

  • 将文本块进行向量化嵌入,使用 BAAI/bge-large-en-v1.5 嵌入模型。

  • 将向量存储SKLearnVectorStore 中,以便高效检索。

2. 检索系统(工具)

  • 实现一个检索函数,为给定查询找到最相关的文档块。

  • 将该函数与语言模型(如 Claude)集成,提供具备上下文感知的响应。

  • 返回格式化后的响应,其中包含来源说明和相关上下文。

3. MCP 服务器集成

  • 使用 fastmcp 库将检索工具包装成 MCP 服务器。

  • 将检索函数暴露为工具,供兼容 MCP 的主机使用。

  • 提供对检索系统以及其他资源(如完整文档文件)的访问。

环境要求

  • Python 3.10+

  • Docker 和 Docker Compose(推荐)

  • Anthropic API 密钥(用于 Claude 模型)

安装与设置

你可以使用 Docker(推荐)在本地 Python 环境中运行此项目,也可以不在容器中运行。

使用 Docker(推荐)

  1. 克隆此仓库:

    git clone https://github.com/yourusername/langraph-rag-mcp.git
    cd langraph-rag-mcp
  2. .env 文件中设置你的 API 密钥: 在项目根目录创建 .env 文件,并添加你的 Anthropic API 密钥:

    echo "ANTHROPIC_API_KEY=your_api_key_here" > .env

    docker-compose.yml 文件会自动加载此环境变量。

本地环境(不使用 Docker)

  1. 克隆此仓库:

    git clone https://github.com/yourusername/langraph-rag-mcp.git
    cd langraph-rag-mcp
  2. 创建并激活虚拟环境:

    conda create -n mcp python=3.13
    conda activate mcp
  3. 安装所需的包:

    pip install -r requirements.txt
  4. .env 文件中设置你的 API 密钥:

    echo "ANTHROPIC_API_KEY=your_api_key_here" > .env

使用方式

整个过程包含两个主要步骤:一是生成向量存储,二是运行 MCP 服务器。

第 1 步:生成向量存储

你只需要执行一次此操作,或者在需要更新文档时执行。

  1. 在 Jupyter 环境中打开并运行 rag-tool.ipynb 笔记本。

  2. 该操作会:

    • 下载最新的 LangGraph 文档。

    • 将完整文档保存到 llms_full.txt

    • 将文档拆分为多个块。

    • sklearn_vectorstore.parquet 中创建并持久化向量存储。

第 2 步:运行 MCP 服务器

使用 Docker

运行此服务器最简单的方法是使用随附的 shell 脚本,该脚本对 Docker Compose 进行了封装。

bash run-mcp-docker.sh

该脚本会在 Docker 镜像不存在时进行构建,启动容器,然后在容器内运行 MCP 服务器,并正确处理 MCP 通信的标准 I/O。

不使用 Docker

如果你不使用 Docker,可以通过以下命令以开发模式直接运行 MCP 服务器:

mcp dev langgraph-mcp.py

配置 MCP 主机

在兼容的编辑器中使用此 MCP 服务器时,需要对其进行配置。

VS Code

  1. 打开 VS Code 的 settings.json 文件。(可以通过命令面板打开:Preferences: Open User Settings (JSON)。)

  2. 将以下配置添加到文件中。请务必将 <path-to-your-project> 替换为你机器上 langgraph-rag-mcp 目录的绝对路径。

"mcp.servers": [
    {
        "name": "langgraph-mcp",
        "command": [
            "/bin/bash",
            "<path-to-your-project>/run-mcp-docker.sh"
        ],
        "env": {
            "ANTHROPIC_API_KEY": "<your-anthropic-api-key>"
        }
    }
]

如果未使用 Docker,请将 command 改为:

"command": [
    "<path-to-your-conda-env>/bin/python",
    "<path-to-your-project>/langgraph-mcp.py"
]

系统架构

(Phase 1: Data Ingestion - Performed once on Host Machine)
┌─────────────┐      ┌──────────────────┐      ┌───────────────────────────────┐
│ LangGraph   │      │ Jupyter Notebook │      │ Vector Store & Full Docs      │
│ Docs (Web)  │───▶  │ (rag-tool.ipynb) │───▶  │ (.parquet & .txt files)       │
└─────────────┘      └──────────────────┘      └───────────────────────────────┘


(Phase 2: Live RAG System - Request/Response Flow)
┌──────────────┐                             ┌─────────────┐
│   VS Code    │                             │  .env file  │
│(User Interface)│                             │ (API KEY)   │
└──────┬───────┘                             └──────┬──────┘
       │ 1. User Query                             │ (provides)
       ▼                                           │
┌──────┴───────────────────────────────────────────┴───────────────────────────────┐
│ Host Machine Boundary                                                            │
│                                                                                  │
│      ┌────────────────────┐          ┌─────────────────────────────────────────┐ │
│      │ run-mcp-docker.sh  │ 2. Execs │  🐳 Docker Container                      │ │
│      │ (Entrypoint Script)│────▶     │                                         │ │
│      └────────────────────┘          │  ┌───────────────────────────────────┐  │ │
│                                      │  │   🐍 Python MCP Server              │  │ │
│      ▲                             ◀─┼──│   (langgraph-mcp.py)              │  │ │
│      │ 7. Final Response             │  └───────────────┬───────────────────┘  │ │
│      │                               │                  │ 3. Reads Data From  │ │
│      └───────────────────────────────│──────────────────│─────────────────────┘ │
│                                      │                  │                       │
│                                      │                  ▼                       │
│                                      │  ┌───────────────────────────────────┐  │
│ (files mounted from Host) ············  │   Mounted Vector Store & Docs     │  │
│                                      │  └───────────────────────────────────┘  │
│                                      └─────────────────────────────────────────┘ │
│                                                                                  │
└──────────────────────────────────────────────────────────────────────────────────┘
                                                        │ 4. API Call
                                                        │    (sends augmented prompt)
                                                        ▼
                                             ┌────────────────────┐
                                             │ ☁️ Anthropic API   │
                                             │   (Claude LLM)     │
                                             └──────────┬─────────┘
                                                        │ 5. Generation
                                                        │
                                                        ◀························
                                                          6. Returns Response
                                                          (to MCP Server)

资源

MCP From Scratch

F
license - not found
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • Query any docs site via MCP. Submit a URL, ask questions, get cited answers.

  • Agent-native MCP server over the public saagarpatel.dev corpus. Read-only, stateless.

  • Turn a GitHub repo or docs site into agent-ready context: pack it or search it, over MCP.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Jaynt27/langgraph-rag-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server