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
访问服务器

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

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选