rag-mcp

rag-mcp

An MCP knowledge server that enables saving and retrieving memory across sessions, with tools to ingest text, URLs, YouTube, and files, and perform semantic search.

Category
访问服务器

README

⚡ RAG-MCP

Persistent memory for MCP clients, powered by retrieval-augmented generation.

RAG-MCP turns documents, notes, web pages, transcripts, and local files into a searchable knowledge layer that MCP-compatible clients can ingest, retrieve, and manage over time. It is designed for assistants that need memory beyond a single chat session.


Overview

RAG-MCP is an MCP server that provides a practical memory and retrieval layer for AI clients.

It supports:

  • ingestion from raw text
  • ingestion from URLs
  • ingestion from YouTube transcripts
  • ingestion from local files
  • semantic retrieval with optional source metadata
  • document listing, searching, deletion, and status inspection
  • browser-based secure upload sessions for document ingestion
  • Prometheus-compatible metrics for runtime visibility

At a high level, the system parses content, chunks it, embeds it, stores vectors in ChromaDB, stores metadata in SQLite, and exposes the entire workflow through MCP tools.


Why this exists

Most MCP clients are excellent at reasoning in the moment, but weak at remembering useful context across sessions.

RAG-MCP solves that by giving clients a persistent, queryable memory layer.

Use it when you want to:

  • give an assistant long-term memory across conversations
  • search documentation, notes, transcripts, or uploaded files semantically
  • attach citations and source metadata to retrieval results
  • keep knowledge isolated by namespace for teams, projects, or environments
  • support both direct ingestion and user-friendly browser uploads

Core capabilities

Ingestion

Store knowledge from:

  • Text via ingest_text
  • Web pages via ingest_url
  • YouTube transcripts via ingest_youtube
  • Local files via ingest_file
  • Browser upload sessions via create_upload_session + upload UI

Supported local file types:

  • .txt
  • .md
  • .markdown
  • .pdf
  • .docx
  • .doc

Retrieval

Query stored knowledge using:

  • retrieve for compact semantic matches
  • retrieve_with_sources for source-aware responses with document and chunk metadata

Document management

Manage the knowledge base with:

  • list_documents
  • search_documents
  • delete_document
  • get_ingestion_status
  • check_upload_status

Runtime features

  • Streamable HTTP MCP transport at /mcp
  • SSE MCP transport at /sse / /messages
  • Upload UI under /upload
  • Metrics endpoint at /metrics

Architecture-level mental model

Think of RAG-MCP as a dedicated memory service for MCP clients:

  1. Ingest content from text, files, URLs, or YouTube
  2. Parse and normalize the content into plain text
  3. Chunk the text into retrievable segments
  4. Embed the chunks into vector representations
  5. Store vectors in ChromaDB
  6. Store metadata in SQLite
  7. Query semantically and return either compact or citation-rich results

This makes the system practical for assistants that need to remember information across time without relying on chat history alone.


Quick start

Local development

python -m venv .venv
. .venv/bin/activate
pip install -e "[dev]"
cp .env.example .env
python -m rag_mcp.main

Verify the server:

curl -i http://127.0.0.1:8080/mcp
curl -i http://127.0.0.1:8080/sse
curl -i http://127.0.0.1:8080/metrics

Optional extras

Install optional parsing extras when needed:

pip install -e ".[pdf]"
pip install -e ".[docx]"

Docker usage

Run with Docker Compose

docker compose up --build -d
docker compose ps

Check the running service

curl -i http://127.0.0.1:8080/metrics
curl -i http://127.0.0.1:8080/mcp

Stop the stack

docker compose down

The Compose setup mounts persistent storage for:

  • ChromaDB vectors
  • SQLite metadata database

Configuration

Configuration is managed through environment variables and loaded by Settings.

Start by copying the sample file:

cp .env.example .env

Common settings

RAG_MCP_CHROMA_PATH=/data/chroma
RAG_MCP_METADATA_DB_PATH=/data/metadata.db
RAG_MCP_LOG_LEVEL=INFO
RAG_MCP_EMBEDDING_MODEL=all-MiniLM-L6-v2
RAG_MCP_METRICS_ENABLED=true
RAG_MCP_METRICS_PATH=/metrics
RAG_MCP_METRICS_REQUIRE_AUTH=false
RAG_MCP_UPLOAD_SESSION_SECRET=change-me-in-production

Important notes

  • RAG_MCP_UPLOAD_SESSION_SECRET should always be set explicitly in real deployments.
  • If metrics auth is enabled, configure the metrics token as well.
  • Chroma and SQLite paths should point to persistent storage in containerized environments.

Upload Documents (UI)

RAG-MCP includes a browser-based upload flow for cases where direct local file ingestion is not convenient.

The flow is:

  1. Call create_upload_session
  2. Open the returned secure upload URL in a browser
  3. Upload supported files
  4. Poll check_upload_status if needed

Upload documents example

This is especially useful when:

  • the MCP client cannot directly access a file path
  • the user wants a friendlier document upload flow
  • files need to be uploaded from another machine or browser session

Upload behavior

  • invalid or expired session token returns an error
  • unsupported files are rejected during parsing
  • upload limits are enforced for file count and size
  • indexed files are written into the target namespace

MCP tool usage patterns

1. Ingest text directly

{
  "name": "ingest_text",
  "arguments": {
    "title": "Team Notes",
    "namespace": "default",
    "text": "Release checklist: create tag, run tests, publish image"
  }
}

2. Ingest a web page

{
  "name": "ingest_url",
  "arguments": {
    "url": "https://example.com/docs",
    "namespace": "docs"
  }
}

3. Retrieve compact results

{
  "name": "retrieve",
  "arguments": {
    "query": "How does release publishing work?",
    "namespace": "default",
    "top_k": 5
  }
}

4. Retrieve with sources

{
  "name": "retrieve_with_sources",
  "arguments": {
    "query": "What are the deployment steps?",
    "namespace": "docs",
    "top_k": 5
  }
}

5. List stored documents

{
  "name": "list_documents",
  "arguments": {
    "namespace": "docs",
    "limit": 20
  }
}

6. Create an upload session

{
  "name": "create_upload_session",
  "arguments": {
    "namespace": "project-x"
  }
}

Recommended usage pattern

A common lifecycle looks like this:

  1. ingest into a namespace
  2. retrieve against the same namespace
  3. inspect with list_documents
  4. delete or re-ingest as documents change

Observability / metrics

The service exposes Prometheus-compatible metrics at /metrics.

Current instrumentation includes request-level visibility such as:

  • total HTTP requests
  • request latency histogram
  • in-flight requests
  • exception counters
  • default Python/process metrics from the Prometheus client runtime

Example:

curl -i http://127.0.0.1:8080/metrics

This makes it straightforward to plug RAG-MCP into:

  • Prometheus
  • Grafana
  • container monitoring dashboards
  • local ops/debugging workflows

Security notes

RAG-MCP includes practical safeguards for production-style deployments:

  • SSRF protection for URL ingestion
  • signed upload session tokens with expiry
  • upload file count and size limits
  • optional metrics authentication and CIDR controls
  • request rate limiting for sensitive paths like upload and metrics

Operational recommendations:

  • set a strong RAG_MCP_UPLOAD_SESSION_SECRET
  • keep metrics private or authenticated in shared environments
  • use persistent storage for /data
  • run behind a reverse proxy when exposing publicly

Troubleshooting

Upload UI says static files are missing

If the upload page does not render correctly, rebuild and restart after updating the image:

docker compose build
docker compose up -d --force-recreate

/metrics returns 503

If metrics auth is enabled without the required token configuration, the endpoint can fail closed. Check your .env values.

/mcp returns a redirect

That is expected. The server supports transport-specific behavior and may redirect to the canonical mounted route.

URL ingestion fails

Private IPs, loopback targets, metadata endpoints, and blocked schemes are intentionally rejected by SSRF validation.

Retrieval returns empty results

Check these in order:

  1. confirm ingestion completed successfully
  2. confirm you are querying the correct namespace
  3. broaden the query wording
  4. increase top_k
  5. verify the document exists with list_documents

Repository structure

Useful entry points:


Contributing

Contributions are welcome.

A solid contribution workflow is:

python -m venv .venv
. .venv/bin/activate
pip install -e "[dev]"
pytest

Before opening a PR:

  • keep changes focused
  • verify the local server still starts
  • run tests
  • update docs when behavior changes

License

MIT — see LICENSE.

推荐服务器

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

官方
精选