Rag Server
БесплатноНе проверенLocal MCP server that provides a search_documents tool to query a RAG pipeline built with Ollama embeddings and ChromaDB, enabling Claude Desktop to retrieve re
Описание
Local MCP server that provides a search_documents tool to query a RAG pipeline built with Ollama embeddings and ChromaDB, enabling Claude Desktop to retrieve relevant document chunks.
README
Goal
Build a local RAG pipeline over a small document collection, then expose it through an MCP server so a connected AI client (Claude Desktop) can query it as a tool.
This mirrors the following architecture: licensed data prepared for AI use, served through a controlled, auditable interface.
Architecture Overview
Documents (PDF/text)
|
[Ingestion Script]
|
Chunk + Embed (Ollama embeddings)
|
ChromaDB (local vector store)
|
[MCP Server] <-- exposes a `search_documents` tool
|
Claude Desktop (MCP client)
Part 1: RAG Pipeline
Stack
- Ollama — local LLM and embedding model runner
- ChromaDB — local vector store, runs in-process, no server needed
- LangChain — orchestration: document loading, chunking, embedding, retrieval
- Python 3.11+
Models to use
- Embeddings:
nomic-embed-textvia Ollama (fast, good quality, runs well on Mac) - Generation:
qwen2.5:7bvia Ollama
Steps
1. Install dependencies
Libraries needed:
langchain-text-splitters— chunking documentslangchain-ollama— Ollama embeddings and LLM wrapperslangchain-chroma— Chroma vector store integrationlangchain-core— shared Document typechromadb— local vector store enginepypdf— PDF text extraction
pip install langchain-text-splitters langchain-ollama langchain-chroma langchain-core chromadb pypdf
ollama pull nomic-embed-text
ollama pull qwen2.5:7b
2. Prepare documents
Pick 5 to 10 PDFs or Markdown/text files.
Place them in a raw/ folder.
3. Ingest and embed (lc/ingest.py)
What the script does, in order:
- Clear out any existing
lc_chroma_db/directory so re-running the script doesn't duplicate chunks. - Load documents from
raw/: read.mdfiles as plain text, and extract text page-by-page from.pdffiles, tagging each chunk with its source filename (and page number for PDFs). - Split the loaded documents into overlapping chunks (~500 characters, 50 character overlap) so retrieval can return focused excerpts instead of whole documents.
- Create embeddings for each chunk using the
nomic-embed-textmodel via Ollama. - Create a vector store: persist the chunks and their embeddings to disk in
lc_chroma_db/using Chroma. - Print how many chunks were ingested.
Always resolve lc_chroma_db/ to an absolute path (relative to the script's own location), since this script and mcp_server.py may be launched from different working directories and must both point at the same store.
4. Query the RAG pipeline (lc/query.py)
What the script does, in order:
- Create the same embeddings model (
nomic-embed-text) used during ingestion — queries and documents must be embedded the same way to be comparable. The embeddings model is used to embed the query. - Open the existing vector store from
lc_chroma_db/. - Create a retriever from the vector store that, given a query, returns the top-k (e.g. 3) most similar chunks.
- Create the generation model:
qwen2.5:7bvia Ollama. - Build a chain: retriever fetches context for the question → a prompt template combines the question and retrieved context → the LLM generates an answer → the output is parsed to plain text.
- Invoke the chain with a question and print the answer.
Run lc/ingest.py once to build the vector store, then lc/query.py to test retrieval.
Part 2: MCP Server
Stack
- MCP Python SDK —
pip install mcp - ChromaDB — same vector store built in Part 1
- Transport — stdio (simplest for local development, works with Claude Desktop)
What the server exposes
One tool: search_documents
Input: a natural language query string. Output: the top 3 most relevant document chunks with their source filename and page number.
The MCP server does not call the LLM. It only handles retrieval. The connected AI client (Claude Desktop) does the reasoning over what is returned. This is the correct pattern for auditability and access control.
Steps
1. Install MCP SDK
pip install mcp
2. Build the server (mcp_server.py)
What the script does, in order:
- Create a FastMCP server instance named
rag-server. - Create the same embeddings model (
nomic-embed-text) used during ingestion. - Open the existing vector store from
lc_chroma_db/, resolved to an absolute path relative to the script's own location (Claude Desktop may launch this script from an arbitrary working directory, so a relative path would fail or point at the wrong — possibly read-only — location). - Register one tool,
search_documents, that takes a query string, retrieves the top 3 most similar chunks from the vector store, and returns them formatted with their source filename and page number. - Run the server over the
stdiotransport when executed directly, so Claude Desktop can spawn it as a subprocess and communicate over stdin/stdout.
Note: the server does not call the generation LLM (qwen2.5:7b). It only handles retrieval — the connected AI client (Claude Desktop) does the reasoning over what is returned.
3. Connect to Claude Desktop
Claude Desktop's own config file is at ~/Library/Application Support/Claude/claude_desktop_config.json. Don't hand-edit a copy elsewhere (e.g. under ~/.claude/) — that directory belongs to Claude Code, a separate tool, and is not read by Claude Desktop.
The easiest way to reach the correct file: open Claude Desktop → Settings → Developer → Local MCP servers → Edit Config. This opens the exact file the app reads, avoiding path mix-ups.
Add an mcpServers entry, using the Python interpreter from the project's virtualenv (not a bare python, which may not resolve correctly for a GUI-launched process) and an absolute path to mcp_server.py:
{
"mcpServers": {
"rag-server": {
"command": "/absolute/path/to/venv/bin/python",
"args": ["/absolute/path/to/mcp_server.py"]
}
}
}
Restart Claude Desktop, or restart just the server from Settings → Developer. The search_documents tool will appear and Claude can call it during a conversation.
Milestones
- Ollama running on local network with
nomic-embed-textandqwen2.5:7bpulled. ingest.pyruns cleanly and ChromaDB persists to disk.query.pyreturns sensible answers from your documents.mcp_server.pystarts without errors.- Claude Desktop connects and can call
search_documentsinteractively.
What to research next
- Chunking strategy: try different chunk sizes and overlaps, or a semantic/markdown-aware splitter instead of fixed character length. Does retrieval quality change?
- Embedding model choice: swap
nomic-embed-textfor another Ollama embedding model and compare retrieved chunks for the same queries. - Retrieval evaluation: build a small set of test questions with known expected chunks, and measure how often the retriever actually returns them (precision/recall at k).
- Multiple MCP tools: add a second tool beyond
search_documents— e.g. one that lists ingested sources, or one that filters by document/date. - Transport options:
mcp_server.pycurrently usesstdio. Look into thestreamable-httptransport and what changes to run the server as a standalone process reachable over the network. - Re-ranking: after the initial similarity search, add a re-ranking step (cross-encoder or LLM-based) before returning the top chunks.
- Incremental ingestion: right now
ingest.pywipes and rebuilds the whole store. Explore adding/updating only changed documents using stable chunk IDs. - Generation model comparison: swap
qwen2.5:7bfor other local models and compare answer quality/latency on the same retrieved context. - Trade-offs worth documenting: local inference latency vs. hosted API speed, chunk size vs. retrieval precision, retrieval-only MCP tool vs. one that also calls the LLM.
Установка Rag Server
У этого сервера нет опубликованного пакета — он собирается из исходников. Открой репозиторий и следуй инструкции в README.
▸ github.com/andreeagheorghe/rag-mcpFAQ
Rag Server MCP бесплатный?
Да, Rag Server MCP бесплатный — установка в пару кликов через Unyly без оплаты.
Нужен ли API-ключ для Rag Server?
Нет, Rag Server работает без API-ключей и переменных окружения.
Rag Server — hosted или self-hosted?
Self-hosted: сервер запускается локально на твоей машине командой из раздела установки.
Как установить Rag Server в Claude Desktop, Claude Code или Cursor?
Открой Rag Server на unyly.org, выбери вкладку своего клиента (Claude Desktop, Claude Code, Cursor) и нажми Install — конфиг сгенерируется автоматически, без правки JSON.
Похожие MCP
Fetch
Web content fetching and conversion for efficient LLM usage.
AWS KB Retrieval
Retrieval from AWS Knowledge Base using Bedrock Agent Runtime.
автор: modelcontextprotocolSpring AI MCP Server
Provides auto-configuration for setting up an MCP server in Spring Boot applications.
llm-analysis-assistant
A very streamlined mcp client that supports calling and monitoring stdio/sse/streamableHttp, and can also view request responses through the /logs page. It also
автор: xuzexin-hzCompare Rag Server with
Не уверен что выбрать?
Найди свой стек за 60 секунд
Автор?
Embed-бейдж для README
Похожее
Все в категории ai
