- Explore MCP Servers
- mcp-rag-context
Mcp Rag Context
What is Mcp Rag Context
mcp-rag-context is a lightweight Model Context Protocol (MCP) server designed for persistent memory and context management using local vector storage and a database. It allows AI assistants to efficiently store and retrieve contextual information through semantic search and indexed retrieval.
Use cases
Use cases for mcp-rag-context include storing user preferences for personalized experiences, managing conversational context in chatbots, and enabling AI assistants to remember past interactions for improved user engagement.
How to use
To use mcp-rag-context, you can install it via npm or use npx without installation. After installation, configure it in your application settings by specifying the data directory and run the server using the provided commands. Use the setContext
and getContext
tools to manage contextual data.
Key features
Key features include local vector storage for efficient similarity search, persistent memory with SQLite for data reliability, automatic semantic search using a text embedding model, hybrid retrieval combining semantic and indexed queries, a simple API with minimal dependencies, and a privacy-first approach with all data stored locally.
Where to use
mcp-rag-context can be used in various fields such as AI development, personal assistants, chatbots, and any application requiring efficient context management and retrieval of information.
Overview
What is Mcp Rag Context
mcp-rag-context is a lightweight Model Context Protocol (MCP) server designed for persistent memory and context management using local vector storage and a database. It allows AI assistants to efficiently store and retrieve contextual information through semantic search and indexed retrieval.
Use cases
Use cases for mcp-rag-context include storing user preferences for personalized experiences, managing conversational context in chatbots, and enabling AI assistants to remember past interactions for improved user engagement.
How to use
To use mcp-rag-context, you can install it via npm or use npx without installation. After installation, configure it in your application settings by specifying the data directory and run the server using the provided commands. Use the setContext
and getContext
tools to manage contextual data.
Key features
Key features include local vector storage for efficient similarity search, persistent memory with SQLite for data reliability, automatic semantic search using a text embedding model, hybrid retrieval combining semantic and indexed queries, a simple API with minimal dependencies, and a privacy-first approach with all data stored locally.
Where to use
mcp-rag-context can be used in various fields such as AI development, personal assistants, chatbots, and any application requiring efficient context management and retrieval of information.
Content
RAG Context MCP Server
A lightweight Model Context Protocol (MCP) server that provides persistent memory and context management using local vector storage and database. This server enables AI assistants to store and retrieve contextual information efficiently using both semantic search and indexed retrieval.
Features
- Local Vector Storage: Uses Vectra for efficient vector similarity search
- Persistent Memory: SQLite database for reliable data persistence
- Semantic Search: Automatic text embedding using Xenova/all-MiniLM-L6-v2 model
- Hybrid Retrieval: Combines semantic search with indexed database queries
- Simple API: Just two tools -
setContext
andgetContext
- Lightweight: Minimal dependencies, runs entirely locally
- Privacy-First: All data stored locally, no external API calls
Installation
Using npm
npm install -g @rag-context/mcp-server
Using npx (no installation required)
npx @rag-context/mcp-server
Configuration
For Claude Desktop
Add the following to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"rag-context": {
"command": "npx",
"args": [
"@rag-context/mcp-server"
],
"env": {
"RAG_CONTEXT_DATA_DIR": "/path/to/your/data/directory"
}
}
}
}
For Cursor
In Cursor settings, add the MCP server:
env RAG_CONTEXT_DATA_DIR=/path/to/your/data/directory npx @rag-context/mcp-server
Environment Variables
RAG_CONTEXT_DATA_DIR
: Directory where the database and vector index will be stored (default:~/.rag-context-mcp
)
Usage
The server exposes two main tools:
setContext
Store information in memory with automatic vectorization:
{
"tool": "setContext",
"arguments": {
"key": "user_preferences",
"content": "The user prefers dark mode and uses VS Code as their primary editor",
"metadata": {
"category": "preferences",
"timestamp": "2024-01-15"
}
}
}
getContext
Retrieve relevant context using semantic search:
{
"tool": "getContext",
"arguments": {
"query": "What are the user's editor preferences?",
"limit": 5,
"threshold": 0.7
}
}
System Prompt for AI Assistants
To effectively use this MCP server, add the following to your AI assistant’s system prompt:
## Memory and Context Management
You have access to a persistent memory system through the RAG Context MCP server. This allows you to store and retrieve information across conversations.
### When to Store Context
Store information when:
- Users share preferences, settings, or personal information
- Important project details or configurations are discussed
- Key decisions or agreements are made
- Useful code snippets or solutions are created
- Learning about user's workflow, tools, or environment
### How to Store Context
Use the `setContext` tool with:
- A descriptive, unique key (e.g., "project_setup_nextjs", "user_pref_editor")
- Clear, concise content that captures the essential information
- Relevant metadata (category, project, date, etc.)
Example:
```json
{
"key": "project_api_structure",
"content": "The project uses a REST API with /api/v1 prefix. Authentication is handled via JWT tokens in the Authorization header. Main endpoints: /users, /posts, /comments",
"metadata": {
"project": "blog-platform",
"type": "architecture",
"date": "2024-01-15"
}
}
```
When to Retrieve Context
Retrieve context when:
- Starting a new conversation about a previously discussed topic
- Users reference past discussions or decisions
- You need to recall specific technical details or preferences
- Building upon previous work or solutions
How to Retrieve Context
Use the getContext
tool with:
- A natural language query describing what you’re looking for
- Appropriate limit (usually 3-5 results)
- Threshold of 0.7 for balanced precision/recall
Example:
{
"query": "API authentication setup for the blog project",
"limit": 3,
"threshold": 0.7
}
Best Practices
- Be Selective: Store important, reusable information, not every detail
- Use Clear Keys: Make keys descriptive and searchable
- Add Metadata: Include project names, categories, and dates
- Update Existing: Use the same key to update information rather than creating duplicates
- Query Naturally: Write queries as you would ask a colleague
Remember: This memory persists across all conversations, making you more helpful over time by remembering important context and user preferences.
## Architecture The server uses a hybrid approach for optimal performance: 1. **SQLite Database**: Stores the actual content with metadata, provides fast key-based lookups 2. **Vector Index**: Enables semantic search using embeddings 3. **Local Embeddings**: Uses Xenova/transformers for privacy-preserving, local text embedding ## Data Storage All data is stored locally in the specified data directory:
<RAG_CONTEXT_DATA_DIR>/
├── memories.db # SQLite database
└── vectors.index # Vectra vector index
## Development ### Building from Source ```bash # Clone the repository git clone https://github.com/yourusername/rag-context-mcp.git cd rag-context-mcp # Install dependencies npm install # Build the project npm run build # Run in development mode npm run dev
Running Tests
npm test
Privacy and Security
- All data is stored locally on your machine
- No external API calls for embeddings (uses local model)
- No telemetry or data collection
- You control where data is stored via
RAG_CONTEXT_DATA_DIR
Troubleshooting
Common Issues
-
“VectorStore not initialized” error
- Ensure the data directory exists and has write permissions
- Check that the
RAG_CONTEXT_DATA_DIR
path is valid
-
Slow first startup
- The embedding model is downloaded on first use (~30MB)
- Subsequent starts will be much faster
-
High memory usage
- The embedding model requires ~200MB RAM
- Consider limiting the number of stored contexts
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details
Acknowledgments
Inspired by the MCP memory server example from Anthropic, but enhanced with:
- Local vector storage for better retrieval
- SQLite for reliable persistence
- Hybrid search capabilities
- Privacy-focused design