文档检索服务器

一个基于向量存储的LangGraph文档检索系统,提供工具查询和完整文档访问功能。

  • by jvelilla
  • Jupyter Notebook
  • 本地部署
  • 更新于
在 GitHub 查看 jvelilla/langgraph_mcp

使用说明

LangGraph文档MCP服务器

该项目实现了一个Mod控制协议(MCP)服务器,该服务器通过基于矢量存储的检索系统提供对LangGraph文档的访问。实施基于 MCP从头开始教程 并已更新为使用Ollama进行嵌入。

特性

  • 使用SKLearnVectorStore进行基于矢量存储的文档检索
  • 用于文档矢量化的Ollama嵌入
  • 使用FastMCP实现MCP服务器
  • 从LangGraph文档加载和处理文档
  • 支持基于工具的查询和完整的文档访问

先决条件

  • Python 3.12+
  • Ollama已在本地安装并运行(默认端口:11434)
  • 必需的Python包
    • langchain_community langchain anthropic langchain_ollama scikit learn bs4 pandas pyarrow matplotlib lxml langgraph tiktoken“mcp[cli]

安装

  1. 克隆存储库
  2. 创建并激活虚拟环境:
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. 安装依赖项:
pip install langchain_community langchain-anthropic langchain_ollama scikit-learn bs4 pandas pyarrow matplotlib lxml langgraph tiktoken "mcp[cli]"

项目结构

  • langgraph_mcp.py:主MCP服务器实现
  • build-tool.ipynb:用于构建和测试矢量存储的Jupyter笔记本
  • llms_full.txt:生成的文档文件
  • sklearn_vectorstore.parquet:矢量存储文件

用法

  1. 首先,使用Jupyter记事本构建向量存储:
jupyter notebook build-tool.ipynb
  1. 运行MCP服务器:
python langgraph_mcp.py

可用工具

langgraph_query_tool

使用语义搜索查询LangGraph文档的工具:

@mcp.tool()
def langgraph_query_tool(query: str):
    """
    Query the LangGraph documentation using a retriever.
    
    Args:
        query (str): The query to search the documentation with

    Returns:
        str: A str of the retrieved documents
    """

完整文档访问权限

通过资源端点访问完整的LangGraph文档:

@mcp.resource("docs://langgraph/full")
def get_all_langgraph_docs() -> str:
    """
    Get all the LangGraph documentation.
    """

实现细节

该项目使用:

  • Ollama嵌入 nomic-embed-text 模型
  • SKLearnVectorStore用于文档存储和检索
  • 用于HTML解析的BeautifulSoup
  • 用于文档抓取的RecursiveurlLoader
  • 用于文档分块的RecursiveCharacterTextSplitter

鸣谢

该实施基于:

许可证

这个项目是开源的,可以在MIT许可证下使用。