RAG and Memory tools exposed via Model Context Protocol (MCP)
Project description
rag-mem
RAG and Memory tools exposed via Model Context Protocol (MCP).
Features
- RAG (Retrieval-Augmented Generation): Semantic search over your documents
- Hybrid retrieval (vector + BM25)
- CrossEncoder reranking (optional)
- Support for PDF, Markdown, Python, JSON, Jupyter notebooks
- Memory System: Persistent fact/memory storage
- BM25-based fast search
- ChromaDB vector fallback
- Simple CRUD operations
- Multiple Embedding Providers:
- Ollama (local, default)
- SentenceTransformers (local, requires torch)
- OpenAI
- Anthropic/Voyage
- Cohere
- LLM-Agnostic: Works with any LLM client that supports MCP
Installation
# Basic install (includes SentenceTransformers - fast, local embeddings)
pip install rag-mem
# With Ollama support (for local LLM embeddings)
pip install rag-mem[ollama]
# With cloud providers
pip install rag-mem[openai]
# All providers
pip install rag-mem[all]
# Using uv (recommended - faster)
uv pip install rag-mem
Default: Uses sentence-transformers with all-MiniLM-L6-v2 (384-dim, 80MB, fast).
Quick Start
1. Initialize Configuration
memory-mcp init
This creates ~/.memory-mcp/config.toml with default settings.
2. Start the Server
# Basic server
memory-mcp serve
# With document paths for RAG
memory-mcp serve --docs ./documents ./notes
# With specific embedding provider
memory-mcp serve --embed-provider openai --embed-model text-embedding-3-small
3. Connect from Claude Desktop
Add to your Claude Desktop config (~/.config/claude/claude_desktop_config.json):
{
"mcpServers": {
"memory": {
"command": "memory-mcp",
"args": ["serve", "--docs", "/path/to/your/documents"]
}
}
}
Configuration
Configuration is loaded from (in order of precedence):
- Environment variables (prefixed with
MEMORY_MCP_) - Config file (
~/.memory-mcp/config.toml) - Default values
Environment Variables
export MEMORY_MCP_EMBED_PROVIDER=openai
export MEMORY_MCP_OPENAI_API_KEY=sk-...
export MEMORY_MCP_QDRANT_MODE=cloud
export MEMORY_MCP_QDRANT_URL=https://your-cluster.qdrant.io
export MEMORY_MCP_QDRANT_API_KEY=...
Config File Example
# ~/.memory-mcp/config.toml
# Embedding provider: ollama, sentence-transformers, openai, anthropic, cohere
embed_provider = "sentence-transformers"
embed_model = "all-MiniLM-L6-v2"
# API keys (for cloud providers)
# openai_api_key = "sk-..."
# Qdrant settings
qdrant_mode = "local" # local, cloud, or memory
# RAG settings
rag_chunk_size = 700
rag_top_k = 5
rag_rerank = true
Docker
# Build
docker build -t memory-mcp .
# Run with OpenAI embeddings
docker run -it --rm \
-v ./documents:/docs:ro \
-v ./data:/data \
-e MEMORY_MCP_EMBED_PROVIDER=openai \
-e MEMORY_MCP_OPENAI_API_KEY=sk-... \
memory-mcp serve --docs /docs
# Run with Ollama (requires host network for Ollama access)
docker run -it --rm \
--network host \
-v ./documents:/docs:ro \
-v ./data:/data \
memory-mcp serve --docs /docs
Available Tools
When connected via MCP, these tools are available:
RAG Tools
query_knowledge_base: Search indexed documentsquery: Search querydoc_path: Optional specific document pathtop_k: Number of results
Memory Tools
save_memory: Store text contentsave_fact: Store structured fact with metadatasearch_memories: Search stored memoriesdelete_memory: Delete by IDlist_all_memories: List all stored memories
CLI Commands
# Initialize config
memory-mcp init
# Show current config
memory-mcp config
# Start MCP server
memory-mcp serve [--docs PATH...] [--embed-provider PROVIDER]
# Index documents (without starting server)
memory-mcp index PATH... [--force]
Python API
from memory_mcp import Settings, create_server
from memory_mcp.rag import RAGPipeline
from memory_mcp.memory import MemoryStore
# Custom settings
settings = Settings(
embed_provider="openai",
openai_api_key="sk-...",
)
# Use RAG directly
pipeline = RAGPipeline(
settings=settings,
document_paths=["./docs"],
)
pipeline.index()
results = pipeline.search("How does authentication work?")
# Use memory directly
memory = MemoryStore(settings)
memory.add("User prefers dark mode")
memories = memory.search("preferences")
Custom Embedding Providers
Implement the EmbeddingProvider interface:
from memory_mcp.embeddings.base import EmbeddingProvider
class MyEmbeddings(EmbeddingProvider):
@property
def dimension(self) -> int:
return 768
def embed_documents(self, texts: list[str]) -> list[list[float]]:
# Your implementation
pass
def embed_query(self, text: str) -> list[float]:
# Your implementation
pass
Architecture
memory-mcp/
├── embeddings/ # Pluggable embedding providers
├── rag/ # RAG pipeline (Qdrant + BM25 + reranking)
├── memory/ # Memory store (ChromaDB + BM25)
├── server.py # FastMCP server
├── config.py # Pydantic settings
└── cli.py # CLI entry point
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rag_mem-0.1.0.tar.gz.
File metadata
- Download URL: rag_mem-0.1.0.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae977ecf06184708105939fd007572ad5050a40b63a63693ff0235a5c6928580
|
|
| MD5 |
a78278140cf7be6fd2c2ca9324f1e9ed
|
|
| BLAKE2b-256 |
c1240fde47347f42fc20b8226be67bfd5c302c693d7ad79a9a2d6c663f56de3a
|
Provenance
The following attestation bundles were made for rag_mem-0.1.0.tar.gz:
Publisher:
memory-mcp-publish.yml on MasihMoafi/A-Modular-Kingdom
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rag_mem-0.1.0.tar.gz -
Subject digest:
ae977ecf06184708105939fd007572ad5050a40b63a63693ff0235a5c6928580 - Sigstore transparency entry: 715900198
- Sigstore integration time:
-
Permalink:
MasihMoafi/A-Modular-Kingdom@4d4051f8fdab820458fd1711b502b15571107aee -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MasihMoafi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
memory-mcp-publish.yml@4d4051f8fdab820458fd1711b502b15571107aee -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file rag_mem-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rag_mem-0.1.0-py3-none-any.whl
- Upload date:
- Size: 24.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d45d17e13b0a2fb8f19fab05abd04d00b1970e160c428338f19bd33090e141e
|
|
| MD5 |
ba44f22922174962337333ac8e96a704
|
|
| BLAKE2b-256 |
5c1f5063176d7aa8dab10e70e5eb07ca7a43b5f81e1074d187187c5434412712
|
Provenance
The following attestation bundles were made for rag_mem-0.1.0-py3-none-any.whl:
Publisher:
memory-mcp-publish.yml on MasihMoafi/A-Modular-Kingdom
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rag_mem-0.1.0-py3-none-any.whl -
Subject digest:
0d45d17e13b0a2fb8f19fab05abd04d00b1970e160c428338f19bd33090e141e - Sigstore transparency entry: 715900199
- Sigstore integration time:
-
Permalink:
MasihMoafi/A-Modular-Kingdom@4d4051f8fdab820458fd1711b502b15571107aee -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MasihMoafi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
memory-mcp-publish.yml@4d4051f8fdab820458fd1711b502b15571107aee -
Trigger Event:
workflow_dispatch
-
Statement type: