语义检索与知识库管理服务器

RAGFlow MCP Server 是一个全面的模型上下文协议服务器,提供语义检索和知识库管理的完整API访问。

  • by Juxsta
  • Python
  • 本地部署
  • 6 星标
  • 更新于
在 GitHub 查看 Juxsta/ragflow-mcp

使用说明

RAGFlow MCP服务器

一个全面的模型上下文协议(MCP)服务器 RAGFlow 的 为语义检索和知识库管理提供完整的API访问。

特性

  • 语义检索:使用自然语言查询跨数据集搜索
  • 数据集管理:创建、列出、更新和删除数据集
  • 文档管理:上传、解析、列出、下载和删除文档
  • 区块管理:添加、列出、更新和删除文档块
  • 聊天助理:创建和管理具有RAG功能的聊天助手
  • 会话管理:创建和管理聊天会话
  • GraphRAG&RAPTOR:构建和查询知识图(当您的RAGFlow实例支持时)

安装

先决条件

  • Python 3.10+
  • RAGFlow服务器正在运行且可访问(核心功能为v0.16.0+)
  • RAGFlow API键

注: GraphRAG和RAPTOR构建API需要RAGFlow v0.21.0或更高版本。

从源代码安装

git clone https://github.com/Juxsta/ragflow-mcp.git
cd ragflow-mcp
pip install -e .

配置Claude代码

添加到您的Claude Code MCP设置中:

claude mcp add ragflow -e RAGFLOW_API_KEY=your-api-key -e RAGFLOW_URL=http://localhost:9380/api/v1 -- python -m src.server

或手动添加到 ~/.claude/settings.json:

{
  "mcpServers": {
    "ragflow": {
      "command": "python",
      "args": ["-m", "src.server"],
      "cwd": "/path/to/ragflow-mcp",
      "env": {
        "RAGFLOW_API_KEY": "your-api-key",
        "RAGFLOW_URL": "http://localhost:9380/api/v1"
      }
    }
  }
}

环境变量

变量 必填 默认 描述
RAGFLOW_API_KEY 是 - 您的RAGFlow API密钥
RAGFLOW_URL 没有 http://localhost:9380/api/v1 RAGFlow API基础URL
RAGFLOW_TIMEOUT 没有 300 请求超时(秒)
RAGFLOW_LOG_LEVEL 没有 INFO 日志记录级别

可用工具

检索

  • ragflow_retrieval_tool -跨数据集的语义搜索

数据集管理

  • ragflow_list_datasets_tool -列出所有数据集
  • ragflow_create_dataset_tool -创建新数据集
  • ragflow_update_dataset_tool -更新数据集配置
  • ragflow_delete_dataset_tool -删除数据集(需要确认)

文档管理

  • ragflow_list_documents_tool -列出数据集中的文档
  • ragflow_upload_document_tool -上传文档(文件路径或base64)
  • ragflow_parse_document_tool -触发异步文档解析
  • ragflow_parse_document_sync_tool -解析并等待完成
  • ragflow_download_document_tool -下载文档内容
  • ragflow_delete_document_tool -删除文档(需要确认)
  • ragflow_stop_parsing_tool -取消活动的解析作业

区块管理

  • ragflow_list_chunks_tool -列出文档中的块
  • ragflow_add_chunk_tool -向文档中添加块
  • ragflow_update_chunk_tool -更新块内容/关键字
  • ragflow_delete_chunk_tool -删除块(需要确认)

聊天和会话

  • ragflow_list_chats_tool -列出聊天助手
  • ragflow_create_chat_tool -创建聊天助手
  • ragflow_update_chat_tool -更新聊天配置
  • ragflow_delete_chat_tool -删除聊天助手(需要确认)
  • ragflow_list_sessions_tool -列出聊天会话
  • ragflow_create_session_tool -创建新会话
  • ragflow_chat_tool -发送消息并获得响应

GraphRAG&RAPTOR

  • ragflow_build_graph_tool -为数据集构建知识图
  • ragflow_graph_status_tool -检查图形构造状态
  • ragflow_get_graph_tool -检索知识图
  • ragflow_delete_graph_tool -删除知识图(需要确认)
  • ragflow_build_raptor_tool -为数据集构建RAPTOR树
  • ragflow_raptor_status_tool -检查RAPTOR施工状态

使用示例

语义搜索

Query: "What is the main character's motivation?"
Dataset: your-dataset-id

上传和解析文档

1. Upload: ragflow_upload_document_tool(dataset_id, file_path="/path/to/doc.pdf")
2. Parse: ragflow_parse_document_sync_tool(document_id)
3. Search: ragflow_retrieval_tool(query="your question", dataset_ids=[dataset_id])

发展

运行测试

pip install -e ".[dev]"
pytest tests/ -v

项目结构

ragflow-mcp/
├── src/
│   ├── __init__.py
│   ├── server.py          # FastMCP server setup
│   ├── connector.py       # RAGFlow API client
│   ├── config.py          # Configuration management
│   ├── cache.py           # LRU cache implementation
│   └── tools/
│       ├── retrieval.py   # Semantic search
│       ├── datasets.py    # Dataset CRUD
│       ├── documents.py   # Document management
│       ├── chunks.py      # Chunk management
│       ├── chat.py        # Chat & sessions
│       └── graph.py       # GraphRAG & RAPTOR
├── tests/
│   └── ...
├── pyproject.toml
└── README.md

安全功能

所有删除操作都需要显式 confirm=True 防止意外数据丢失的参数。

许可证

MIT许可证

致谢

  • RAGFlow 的 -此MCP服务器集成的RAG引擎
  • FastMCP -用于构建此服务器的MCP框架