RAG Local MCP Server for Semantic Passage Retrieval
Store and retrieve text passages locally with an MCP server that uses semantic passage retrieval for fast, accurate RAG-based results.
npx -y @renl/mcp-rag-localOverview
This MCP (Model Context Protocol) server provides a lightweight, local way to store and retrieve text passages using semantic passage retrieval. It is designed to act as a fast, private retrieval layer for Retrieval-Augmented Generation (RAG) workflows: you index passages (documents split into passages), and at query time you retrieve the most semantically relevant passages to provide context for a language model.
Running the server locally keeps data private, reduces latency compared to remote services, and makes it easy to integrate passage retrieval into development, evaluation, and production RAG pipelines. The server exposes a simple HTTP API and a small client surface so you can add passages, build indexes, and perform nearest-neighbor semantic queries from your applications.
Features
- Local storage of passage text + metadata for private RAG workflows
- Semantic retrieval via vector embeddings and nearest-neighbor index
- Simple HTTP API compatible with Model Context Protocol patterns
- Configurable embedding provider and model (supports local or remote encoders)
- Configurable index type (in-memory vs persistent index)
- Fast top-k retrieval for providing context to LLM prompts
- Minimal dependencies for easy deployment and development
Installation / Configuration
Clone the repository and install Python dependencies (example):
Start the server with Uvicorn (example):
# development
Configuration is handled primarily via environment variables. Example env file (.env):
MCP_HOST=
MCP_PORT=8080
DATA_DIR=./data
EMBEDDING_PROVIDER=localEMBEDDING_MODEL=all-MiniLM-L6-v2
INDEX_TYPE=faissTOP_K=5
Common commands for index management:
# add passages (example script included)
# build or rebuild index from stored passages
# run a health check
Available Resources
The server exposes a small set of HTTP endpoints for managing and querying passages. Example endpoints (conceptual — refer to the repository for exact paths):
- POST /passages
- Add one or more passages (text + optional metadata)
- POST /query
- Submit a natural language query and return top-k semantically similar passages with scores
- GET /passages/{id}
- Retrieve a stored passage by id
- DELETE /passages/{id}
- Remove a passage from storage
- GET /health
- Service health and status
Client examples are included in the repo: a simple Python client and shell curl snippets. The server persists raw passages and the vector index in the configured DATA_DIR so you can back up, inspect, or migrate stored content.
Configuration table
| Env var | Purpose | Example |
|---|---|---|
| MCP_HOST | Host to bind the server | 0.0.0.0 |
| MCP_PORT | Port to listen on | 8080 |
| DATA_DIR | Local storage for passages and index | ./data |
| EMBEDDING_PROVIDER | Which embedding backend to use | openai, huggingface, local |
| EMBEDDING_MODEL | Embedding model identifier | all-MiniLM-L6-v2 |
| INDEX_TYPE | Index backend for vectors | faiss, hnsw, annoy, memory |
| TOP_K | Default number of results per query | 5 |
Quick Examples
Add passages (curl):
Query for relevant passages:
Python client usage (requests):
=
=
=
Use Cases
- RAG for chatbots: Retrieve a small set of high-quality passages to prepend to prompts, improving factuality and grounding for LLM responses.
- Private knowledge bases: Keep internal documents on-premises while enabling semantic search and retrieval without cloud storage.
- Offline or low-latency retrieval: Run the index locally inside a microservice to avoid network round-trips for embeddings + retrieval.
- Evaluation and development: Quickly iterate on passage-splitting, embedding models, and prompt templates in local development environments.
- Document augmentation: Enrich user queries with contextual passages for downstream processing (summarization, classification, answer extraction).
This MCP server is intended as a compact, developer-friendly component for building RAG systems. Refer to the repository examples and scripts to seed passages, configure embedding backends, and integrate retrieval results into your prompt pipelines.