RAG Anything MCP服务器
🚀 基于知识图的高级RAG模型上下文协议服务器
  
知识图谱+文档处理+多模态人工智能
📋 概述
RAG Anything MCP Server是一个生产就绪的模型上下文协议(MCP)服务器,它结合了:
- 🧠 知识图查询 -多种查询模式(简单、本地、全局、混合、混合、绕过)
- 📄 文件摄入 -多模式内容提取的文本和PDF处理
- 🔍 实体提取 -从文档中自动提取实体和关系
- 💾 混合存储 -Neo4j(图)+带pgvector的PostgreSQL(向量)
- 🖼️ 多模式支持 -处理PDF中的图像、表格和方程式
- 📡 符合MCP标准 -标准模型上下文协议实现
✨ 特性
核心能力
| 特性 | 描述 |
|---|---|
| 📄 文件摄入 | 多模式内容提取的文本和PDF处理 |
| 🧠 知识图查询 | 多种查询模式(简单、本地、全局、混合、混合、绕过) |
| 🔍 实体提取 | 从文档中自动提取实体和关系 |
| 💾 混合存储 | Neo4j(图)+带pgvector的PostgreSQL(向量) |
| 📡 符合MCP标准 | 标准模型上下文协议实现 |
| 🖼️ 多模式支持 | 处理PDF中的图像、表格和方程式 |
查询模式
- 天真 -简单关键字搜索
- 本地 -基于本地实体的搜索
- 全球 -全球社区搜索
- 混合 -结合本地和全球(推荐)
- 混合 -混合多种策略
- 绕过 -无图直接LLM查询
______________________________________________________________________
🚀 快速开始
先决条件
- 码头工人 &Docker Compose(用于数据库服务)
- Python 3.13+
- OpenAI API密钥
选项1:多功能Docker(推荐)
使用Docker Compose开始一切:
# Clone the repository
git clone https://github.com/serkanyasr/rag-anythink-mcp.git
cd rag-anythink-mcp
# Copy environment template
cp .env.example .env
# Edit .env and set your OpenAI API key
# OPENAI_API_KEY=sk-...
# Start all services (Neo4j + PostgreSQL + MCP Server)
docker-compose up -d
# View logs
docker-compose logs -f rag-mcp
# Stop services
docker-compose down这将开始:
- Neo4j 5.23 上
bolt://localhost:7687(HTTP用户界面打开http://localhost:7474) - PostgreSQL 16+pgvector 上
localhost:5432 - MCP服务器 上
http://localhost:8000
选项2:开发模式
当数据库在Docker中运行时,在本地运行MCP服务器:
窗户:
# One-click startup - handles everything automatically
start-dev.batLinux/Mac:
# Make executable and run
chmod +x start-dev.sh
./start-dev.sh选项3:手动设置
# 1. Start Docker services (databases only)
docker-compose up -d neo4j postgres
# 2. Create virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# 3. Install dependencies
pip install -e .
# 4. Run the server
python main.py______________________________________________________________________
⚙️ 配置
创建一个 .env 项目根目录中的文件:
# =====================
# Neo4j Configuration
# =====================
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=your_neo4j_password
# =====================
# PostgreSQL Configuration (for RAG)
# =====================
RAG_DB_HOST=localhost
RAG_DB_PORT=5432
RAG_DB_NAME=rag_anythink
RAG_DB_USER=postgres
RAG_DB_PASSWORD=your_postgres_password
# =====================
# OpenAI Configuration
# =====================
OPENAI_API_KEY=your_openai_api_key
# =====================
# Document Processing
# =====================
# Parser: mineru, docling
KG_PARSER=mineru
# Parse method: auto, ocr, txt
KG_PARSE_METHOD=auto
# Enable image extraction from PDFs
KG_ENABLE_IMAGE=true
# Enable table extraction from PDFs
KG_ENABLE_TABLE=true
# Enable equation extraction from PDFs
KG_ENABLE_EQUATION=true
# =====================
# RAG Configuration
# =====================
# Working directory for RAG output
KG_WORKING_DIR=./rag_output
# Workspace name (production, development, etc.)
KG_WORKSPACE=production
# Context window for LLM (pages before/after for context)
KG_CONTEXT_WINDOW=1
# Maximum concurrent files for processing
KG_MAX_CONCURRENT_FILES=4
# Embedding dimension (depends on model)
KG_EMBEDDING_DIM=3072
# Maximum token size for embeddings
KG_MAX_TOKEN_SIZE=8192
# LLM model for knowledge graph operations
KG_LLM_MODEL=gpt-4o-mini
# Vision model for multimodal processing
KG_VISION_MODEL=gpt-4o
# Embedding model
KG_EMBEDDING_MODEL=text-embedding-3-large
# Default query mode (naive, local, global, hybrid, mix, bypass)
KG_DEFAULT_MODE=hybrid
# =====================
# MCP Configuration
# =====================
# MCP server name
RAG_MCP_NAME=rag-anything-mcp
# MCP server version
RAG_MCP_VERSION=1.0.0
# MCP server host
RAG_MCP_HOST=localhost
# MCP server port
RAG_MCP_PORT=8055
# MCP log level
RAG_MCP_LOG=info
# MCP transport protocol: stdio, http, sse, streamable-http
RAG_MCP_TRANSPORT=streamable-http
# Application log level: DEBUG, INFO, WARNING, ERROR, CRITICAL
LOG_LEVEL=INFO
# Application log format: json, text
LOG_FORMAT=json______________________________________________________________________
🔌 MCP工具
服务器提供以下MCP工具:
| 工具 | 说明 |
|---|---|
ingest_document | 摄取文本或PDF文档 |
query_knowledge_graph | 多种模式查询(朴素、本地、全局、混合) |
query_multimodal | 使用图像、表格、方程式进行查询 |
process_document_file | 使用多模式提取处理PDF文件 |
insert_content_list | 插入预解析的内容 |
delete_data | 按ID删除文档 |
get_graph_statistics | 获取图形统计信息 |
get_config_info | 获取配置信息 |
______________________________________________________________________
📚 用法示例
Python客户端
from src.services.kg_service import KGService
# Initialize service
service = KGService()
await service.initialize()
# Ingest a document
result = await service.ingest_text(
text="Your document text here...",
metadata={"title": "My Document"}
)
# Query the knowledge graph
response = await service.query(
query_text="What are the main topics?",
mode="hybrid"
)MCP客户端(克劳德桌面)
添加到您的Claude Desktop MCP配置中:
{
"mcpServers": {
"rag-anything": {
"command": "docker-compose",
"args": ["up", "rag-mcp"],
"env": {
"OPENAI_API_KEY": "your-api-key"
}
}
}
}______________________________________________________________________
🗂️ 项目结构
rag-anythink-mcp/
├── src/
│ ├── config/ # Pydantic configuration
│ ├── core/ # Interfaces and models
│ ├── database/ # Database connections (Neo4j, PostgreSQL)
│ │ └── kg/ # Knowledge Graph layer
│ ├── mcp/ # MCP servers
│ │ └── kg/ # RAG MCP server
│ ├── services/ # Business logic
│ ├── utils/ # Utilities
│ └── llm.py # LLM clients
├── main.py # Entry point
├── Dockerfile # Docker image for MCP server
├── docker-compose.yml # Multi-container orchestration
├── pyproject.toml # Dependencies (uv)
├── start-dev.bat # Windows dev startup
├── start-dev.sh # Linux/Mac dev startup
└── README.md______________________________________________________________________
🛠️ 发展
设置开发环境
# Clone repository
git clone https://github.com/serkanyasr/rag-anythink-mcp.git
cd rag-anythink-mcp
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install in development mode with all extras
pip install -e ".[full]"运行测试
# Run all tests
pytest
# Run with coverage
pytest --cov=src
# Run specific test file
pytest tests/test_kg_service.py代码质量
# Format code
ruff format src/
# Check linting
ruff check src/
# Type checking
pyright src/______________________________________________________________________
🐳 Docker部署
全栈部署
# Deploy all services
docker-compose up -d
# Check service health
docker-compose ps
# View logs
docker-compose logs -f
# Stop all services
docker-compose down
# Stop and remove volumes (clean slate)
docker-compose down -v个人服务
# Only databases (for local dev)
docker-compose up -d neo4j postgres
# Only MCP server (databases must be running)
docker-compose up -d rag-mcp健康检查
这些服务包括内置的健康检查:
- Neo4j:密码外壳连接测试
- PostgreSQL:
pg_isready检查 - MCP服务器:取决于健康的数据库
______________________________________________________________________
📖 建筑
系统组件
┌─────────────────┐
│ MCP Client │
│ (Claude, etc) │
└────────┬────────┘
│ MCP Protocol
▼
┌─────────────────┐
│ MCP Server │
│ (FastMCP) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ KG Service │
│ (RAG-Anything) │
└────────┬────────┘
│
┌────┴────┐
▼ ▼
┌──────┐ ┌─────────┐
│Neo4j│ │PostgreSQL│
│Graph│ │+ pgvector│
└──────┘ └─────────┘数据流
- 摄入:文件→ 实体提取→ Neo4j(图形)+PostgreSQL(向量)
- 查询:查询文本→ 嵌入→ 矢量搜索+图形遍历→ LLM合成
______________________________________________________________________
🤝 贡献
欢迎投稿!请按照以下步骤操作:
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 进行更改
- 运行测试(
pytest) - 提交您的更改(
git commit -m 'Add some amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
开发指南
- 为新功能编写测试
- 遵循PEP 8风格指南
- 根据需要更新文档
- 保持提交原子性和良好的描述
______________________________________________________________________
❓ 常见问题解答
How do I change the database passwords?
更新两个中的密码 .env 和 docker-compose.yml。确保它们匹配。
Can I use a different embedding model?
对!集 OPENAI_EMBEDDING_MODEL 并进行调整 RAG_EMBEDDING_DIM 在你的 .env 文件。
How do I backup my data?
# Neo4j backup
docker exec rag-neo4j neo4j-admin database dump neo4j --to-path=/backups
# PostgreSQL backup
docker exec rag-postgres pg_dump -U postgres rag_anythink > backup.sqlThe server won't start - what do I do?
- 检查Docker是否正在运行:
docker ps - 检查服务日志:
docker-compose logs - 验证中的环境变量
.env - 确保数据库健康:
docker-compose ps
______________________________________________________________________
📜 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
______________________________________________________________________
