RAG-Anything MCP Server

RAG-Anything MCP Server

Enables advanced RAG with knowledge graphs, supporting document ingestion, multimodal extraction, and multiple query modes (naive, local, global, hybrid) via the Model Context Protocol.

Category
访问服务器

README

<div align="center">

RAG-Anything MCP Server

🚀 Model Context Protocol server for advanced RAG with Knowledge Graphs

License: MIT Python 3.13+ MCP

Knowledge Graph + Document Processing + Multimodal AI

</div>

📋 Overview

RAG-Anything MCP Server is a production-ready Model Context Protocol (MCP) server that combines:

  • 🧠 Knowledge Graph Queries - Multiple query modes (naive, local, global, hybrid, mix, bypass)
  • 📄 Document Ingestion - Text and PDF processing with multimodal content extraction
  • 🔍 Entity Extraction - Automatic entity and relationship extraction from documents
  • 💾 Hybrid Storage - Neo4j (graph) + PostgreSQL with pgvector (vectors)
  • 🖼️ Multimodal Support - Process images, tables, and equations from PDFs
  • 📡 MCP Compliant - Standard Model Context Protocol implementation

✨ Features

Core Capabilities

Feature Description
📄 Document Ingestion Text and PDF processing with multimodal content extraction
🧠 Knowledge Graph Queries Multiple query modes (naive, local, global, hybrid, mix, bypass)
🔍 Entity Extraction Automatic entity and relationship extraction from documents
💾 Hybrid Storage Neo4j (graph) + PostgreSQL with pgvector (vectors)
📡 MCP Compliant Standard Model Context Protocol implementation
🖼️ Multimodal Support Process images, tables, and equations from PDFs

Query Modes

  • naive - Simple keyword search
  • local - Local entity-based search
  • global - Global community-based search
  • hybrid - Combines local and global (recommended)
  • mix - Mixes multiple strategies
  • bypass - Direct LLM query without graph

🚀 Quick Start

Prerequisites

  • Docker & Docker Compose (for database services)
  • Python 3.13+
  • OpenAI API Key

Option 1: All-in-One Docker (Recommended)

Start everything with 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

This will start:

  • Neo4j 5.23 on bolt://localhost:7687 (HTTP UI on http://localhost:7474)
  • PostgreSQL 16 + pgvector on localhost:5432
  • MCP Server on http://localhost:8000

Option 2: Development Mode

Run the MCP server locally while databases run in Docker:

Windows:

# One-click startup - handles everything automatically
start-dev.bat

Linux/Mac:

# Make executable and run
chmod +x start-dev.sh
./start-dev.sh

Option 3: Manual Setup

# 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

⚙️ Configuration

Create a .env file in the project root:

# =====================
# 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 Tools

The server provides the following MCP tools:

Tool Description
ingest_document Ingest text or PDF documents
query_knowledge_graph Query with multiple modes (naive, local, global, hybrid)
query_multimodal Query with images, tables, equations
process_document_file Process PDF files with multimodal extraction
insert_content_list Insert pre-parsed content
delete_data Delete documents by ID
get_graph_statistics Get graph statistics
get_config_info Get configuration info

📚 Usage Examples

Python Client

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 Client (Claude Desktop)

Add to your Claude Desktop MCP config:

{
  "mcpServers": {
    "rag-anything": {
      "command": "docker-compose",
      "args": ["up", "rag-mcp"],
      "env": {
        "OPENAI_API_KEY": "your-api-key"
      }
    }
  }
}

🗂️ Project Structure

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

🛠️ Development

Setup Development Environment

# 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]"

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=src

# Run specific test file
pytest tests/test_kg_service.py

Code Quality

# Format code
ruff format src/

# Check linting
ruff check src/

# Type checking
pyright src/

🐳 Docker Deployment

Full Stack Deployment

# 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

Individual Services

# Only databases (for local dev)
docker-compose up -d neo4j postgres

# Only MCP server (databases must be running)
docker-compose up -d rag-mcp

Health Checks

The services include built-in health checks:

  • Neo4j: Cypher-shell connectivity test
  • PostgreSQL: pg_isready checks
  • MCP Server: Depends on healthy databases

📖 Architecture

System Components

┌─────────────────┐
│   MCP Client    │
│  (Claude, etc)  │
└────────┬────────┘
         │ MCP Protocol
         ▼
┌─────────────────┐
│  MCP Server     │
│  (FastMCP)      │
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│  KG Service     │
│  (RAG-Anything) │
└────────┬────────┘
         │
    ┌────┴────┐
    ▼         ▼
┌──────┐  ┌─────────┐
│Neo4j│  │PostgreSQL│
│Graph│  │+ pgvector│
└──────┘  └─────────┘

Data Flow

  1. Ingestion: Documents → Entity Extraction → Neo4j (graph) + PostgreSQL (vectors)
  2. Query: Query Text → Embedding → Vector Search + Graph Traversal → LLM Synthesis

🤝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (pytest)
  5. Commit your changes (git commit -m 'Add some amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Development Guidelines

  • Write tests for new features
  • Follow PEP 8 style guidelines
  • Update documentation as needed
  • Keep commits atomic and well-described

❓ FAQ

<details> <summary><b>How do I change the database passwords?</b></summary>

Update the passwords in both .env and docker-compose.yml. Make sure they match. </details>

<details> <summary><b>Can I use a different embedding model?</b></summary>

Yes! Set OPENAI_EMBEDDING_MODEL and adjust RAG_EMBEDDING_DIM in your .env file. </details>

<details> <summary><b>How do I backup my data?</b></summary>

# 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.sql

</details>

<details> <summary><b>The server won't start - what do I do?</b></summary>

  1. Check Docker is running: docker ps
  2. Check service logs: docker-compose logs
  3. Verify environment variables in .env
  4. Ensure databases are healthy: docker-compose ps </details>

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.


推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选