Skip to main content
Glama

RAG Context MCP Server

by notbnull
MIT License
1

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:

/ ├── 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
-
security - not tested
A
license - permissive license
-
quality - not tested

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.

  1. Features
    1. Installation
      1. Using npm
      2. Using npx (no installation required)
    2. Configuration
      1. For Claude Desktop
      2. For Cursor
      3. Environment Variables
    3. Usage
      1. setContext
      2. getContext
    4. System Prompt for AI Assistants
      1. When to Retrieve Context
      2. How to Retrieve Context
      3. Best Practices
    5. Clone the repository
      1. Install dependencies
        1. Build the project
          1. Run in development mode
            1. Privacy and Security
            2. Troubleshooting
            3. Contributing
            4. License
            5. Acknowledgments

          Related MCP Servers

          • -
            security
            F
            license
            -
            quality
            A server that enables AI assistants to execute JavaScript code with persistent context through stateful REPL sessions, file operations, and package management features.
            Last updated -
            TypeScript
            • Linux
            • Apple
          • -
            security
            F
            license
            -
            quality
            A Model Context Protocol server that provides persistent task management capabilities for AI assistants, allowing them to create, update, and track tasks beyond their usual context limitations.
            Last updated -
            1
            TypeScript
          • -
            security
            F
            license
            -
            quality
            Implements long-term memory capabilities for AI assistants using PostgreSQL with pgvector for efficient vector similarity search, enabling semantic retrieval of stored information.
            Last updated -
            1
            JavaScript
            • Apple
            • Linux
          • -
            security
            A
            license
            -
            quality
            A Model Context Protocol server that provides AI agents with persistent memory capabilities through Mem0, allowing them to store, retrieve, and semantically search memories.
            Last updated -
            2
            Python
            MIT License

          View all related MCP servers

          MCP directory API

          We provide all the information about MCP servers via our MCP API.

          curl -X GET 'https://glama.ai/api/mcp/v1/servers/notbnull/mcp-rag-context'

          If you have feedback or need assistance with the MCP directory API, please join our Discord server