rag-mcp

rag-mcp

Provides read-only MCP tools for hybrid semantic and keyword search over locally indexed PDF documentation, with citations and context retrieval for LLM agents.

Category
访问服务器

README

RAG System

Local Retrieval-Augmented Generation system for PDF documentation. Provides offline document ingestion with hybrid vector search and an MCP server for LLM agents to query indexed documentation.

Architecture

                 Offline / manual
PDFs and docs -> Ingestion CLI -> Local Qdrant (Docker)
                                      |
                 During questions     |
LLM agent -> MCP retrieval tools -----+
          -> grounded answer with citations

Two executables share a common codebase:

  • rag - Ingestion CLI for parsing, chunking, embedding, and storing PDFs
  • rag-mcp - Read-only MCP stdio server exposing search and retrieval tools

Prerequisites

  • Python 3.11+
  • uv package manager
  • Docker (for Qdrant)

Setup

1. Start Qdrant

cd rag-system
docker compose up -d

Qdrant will be available at http://localhost:6333.

2. Install Python dependencies

uv sync

This creates a virtual environment and installs all dependencies including local embedding models.

3. Copy environment configuration

cp .env.example .env

Edit .env if you need to change Qdrant URL, collection name, or model settings.

Ingesting Documents

Place PDF files in the documents/ directory (or reference them by path).

# Ingest a single file
uv run rag ingest ./documents/manual.pdf

# Ingest with a custom document ID
uv run rag ingest ./documents/manual.pdf --id product-manual

# Force re-ingestion (replaces existing version)
uv run rag ingest ./documents/manual.pdf --force

# Ingest all PDFs in a directory
uv run rag ingest-directory ./documents

# List indexed documents
uv run rag list

# Inspect a document's metadata and sample chunks
uv run rag inspect product-manual

# Delete a document
uv run rag delete product-manual

Embedding models (BAAI/bge-small-en-v1.5 for dense, Qdrant/bm25 for sparse) are downloaded on first use and cached locally.

MCP Server Configuration

Add the RAG MCP server to your agent's MCP configuration:

opencode (opencode.json or ~/.config/opencode/opencode.json)

{
  "mcp": {
    "servers": {
      "rag-documentation": {
        "type": "local",
        "command": ["uv", "run", "--directory", "/absolute/path/to/rag-system", "rag-mcp"],
        "enabled": true
      }
    }
  }
}

Claude Desktop (claude_desktop_config.json)

{
  "mcpServers": {
    "rag-documentation": {
      "command": "uv",
      "args": ["run", "--directory", "/absolute/path/to/rag-system", "rag-mcp"]
    }
  }
}

MCP Tools

The server exposes four read-only tools:

Tool Description
search_documentation Hybrid semantic + keyword search with page citations
get_document_context Retrieve surrounding chunks for more context
list_documents List all indexed documents
get_document_metadata Get metadata for a specific document

Configuration

All settings are read from environment variables (or .env file):

Variable Default Description
QDRANT_URL http://localhost:6333 Qdrant REST API URL
QDRANT_COLLECTION documentation Qdrant collection name
DENSE_EMBEDDING_MODEL BAAI/bge-small-en-v1.5 Dense embedding model
SPARSE_EMBEDDING_MODEL Qdrant/bm25 Sparse/BM25 embedding model
CHUNK_TARGET_TOKENS 700 Target tokens per chunk
CHUNK_OVERLAP_TOKENS 100 Token overlap between chunks
DEFAULT_SEARCH_LIMIT 8 Default results per search
MAX_SEARCH_LIMIT 20 Maximum results per search

Development

# Run tests (unit tests run without Qdrant)
uv run pytest tests/unit

# Run all tests (requires Qdrant running)
docker compose up -d
uv run pytest

# Lint
uv run ruff check src tests

# Type check
uv run mypy src

How Retrieval Works

  1. Hybrid search: Dense vector search (semantic similarity) and sparse BM25 search (keyword matching) run in parallel against Qdrant.
  2. Reciprocal Rank Fusion (RRF): Qdrant fuses dense and sparse results using RRF.
  3. Citations: Every result includes the document title, section path, and page range.
  4. Context expansion: The get_document_context tool retrieves neighboring chunks when a search result needs more surrounding text.

All processing is local. No document content is sent to external services.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选