RAG Context MCP Server

RAG Context MCP Server

A lightweight server that provides persistent memory and context management for AI assistants using local vector storage and database, enabling efficient storage and retrieval of contextual information through semantic search and indexed retrieval.

Category
Visit Server

README

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 and getContext
  • 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

  1. Be Selective: Store important, reusable information, not every detail
  2. Use Clear Keys: Make keys descriptive and searchable
  3. Add Metadata: Include project names, categories, and dates
  4. Update Existing: Use the same key to update information rather than creating duplicates
  5. 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

  1. "VectorStore not initialized" error

    • Ensure the data directory exists and has write permissions
    • Check that the RAG_CONTEXT_DATA_DIR path is valid
  2. Slow first startup

    • The embedding model is downloaded on first use (~30MB)
    • Subsequent starts will be much faster
  3. 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

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured