Memory Engineering MCP

Memory Engineering MCP

Provides persistent memory and semantic code understanding for AI assistants using MongoDB Atlas Vector Search. Enables intelligent code search, memory management, and pattern detection across codebases with complete semantic context preservation.

Category
访问服务器

README

🧠 Memory Engineering MCP

npm version License: MIT

Persistent memory and semantic code understanding for AI assistants. Built on MongoDB Atlas Vector Search and Voyage AI embeddings.

🔥 The Game Changer: Code Embeddings

This is what makes Memory Engineering different from everything else:

Revolutionary Code Chunking

  • Smart Semantic Boundaries: Tracks braces, parentheses, and indentation to capture COMPLETE functions (up to 200 lines) and classes (up to 300 lines)
  • Context-Aware: Every chunk includes its imports, dependencies, and surrounding context
  • Pattern Detection: Automatically identifies 20+ code patterns (error-handling, async, authentication, etc.)

Why This Matters

// Traditional chunking BREAKS this function in half:
function processPayment(order) {  // <- Chunk 1 ends here
  validateOrder(order);           // <- Chunk 2 starts here, loses context!
  // ... 50 more lines
}

// Our chunking keeps it COMPLETE:
function processPayment(order) {  // <- Full function preserved
  validateOrder(order);           
  // ... entire function included
}                                 // <- Chunk ends at semantic boundary

Semantic Code Search That Actually Works

# Find similar implementations
search --query "JWT refresh" --codeSearch "similar"

# Find who implements an interface
search --query "AuthProvider" --codeSearch "implements"  

# Find usage patterns
search --query "error handling" --codeSearch "pattern"

# Natural language → Code
search --query "how do we validate users"
# Automatically searches: authenticate, verify, check, validate patterns

🧠 The 7 Core Memories

Inspired by Cline, but enhanced with MongoDB persistence:

  1. activeContext - What you're doing RIGHT NOW (update every 3-5 min!)
  2. projectbrief - Core requirements and features
  3. systemPatterns - Architecture decisions and patterns
  4. techContext - Stack, dependencies, constraints
  5. progress - What's done, in-progress, and next
  6. productContext - Why this exists, user needs
  7. codebaseMap - File structure with embedded statistics

💪 Technical Architecture

MongoDB Atlas Integration

  • Vector Search: 1024-dimensional embeddings with cosine similarity
  • Hybrid Search: Combines semantic + keyword search
  • Auto-indexing: Manages compound, text, and vector indexes automatically
  • Connection pooling: 5-100 connections with retry logic

Voyage AI Embeddings

  • Model: voyage-3 (1024 dimensions)
  • Contextualized: Each chunk knows about surrounding code
  • Batch processing: 100 chunks at a time for efficiency
  • Smart caching: Only re-embeds changed files

Code Intelligence

// What gets captured in each chunk:
interface CodeChunk {
  chunk: {
    type: 'function' | 'class' | 'method' | 'module';
    signature: string;      // Full signature with params
    content: string;        // Complete code
    context: string;        // Imports and dependencies
    startLine: number;
    endLine: number;
  };
  contentVector: number[];  // 1024-dim embedding
  metadata: {
    patterns: string[];     // Detected patterns
    dependencies: string[]; // What it imports
    exports: string[];      // What it exports
  };
}

⚡ Quick Start

Installation

npm install -g memory-engineering-mcp

Configure Cursor/.cursor/mcp.json

{
  "mcpServers": {
    "memory-engineering-mcp": {
      "command": "npx",
      "args": ["memory-engineering-mcp"],
      "env": {
        "MONGODB_URI": "your-mongodb-atlas-uri",
        "VOYAGE_API_KEY": "your-voyage-api-key"
      }
    }
  }
}

First Run

# Initialize (scans entire codebase, generates embeddings)
memory_engineering_init

# Now search your code semantically!
memory_engineering_search --query "authentication flow" --codeSearch "pattern"

# Update memories as you work
memory_engineering_memory --name activeContext --content "Fixed JWT expiry..."

🎯 Real Power Examples

Finding Code You Forgot Exists

search --query "payment processing"
# Finds: processPayment(), handleStripeWebhook(), validateCard()
# Even if you never used the word "payment" in those functions!

Understanding Patterns Across Codebase

search --query "error" --codeSearch "pattern"
# Returns ALL error handling patterns:
# - try/catch blocks
# - .catch() handlers  
# - error middleware
# - validation errors

Tracking Decisions

search --query "why Redis"
# Finds the exact activeContext entry where you decided to use Redis
# "Chose Redis for session storage because: 1) Fast lookups 2) TTL support..."

📊 Performance Metrics

  • Code sync: Processes files with embeddings in batches of 100
  • Search latency: <500ms for 100k chunks
  • Memory operations: <100ms
  • Embedding dimensions: 1024 (voyage-3 model)
  • Chunk sizes: 80-300 lines (adaptive, default 80)
  • Pattern detection: 27 patterns recognized

🔧 Advanced Features

Smart Pattern Aliasing

The system understands natural language variations:

  • "auth" → searches: authentication, authorization, login, JWT, token
  • "db" → searches: database, MongoDB, schema, model, collection
  • "error handling" → searches: try-catch, exception, error-handler

Incremental Sync

Only changed files are re-embedded:

// Detects changes via:
- File modification time
- Content hash comparison  
- Git diff integration
- Automatic after 24h gap

Context Preservation

Every code chunk maintains context:

// Original file:
import { User } from './models';
import bcrypt from 'bcrypt';

class AuthService {
  async validateUser(email: string, password: string) {
    // ... implementation
  }
}

// Chunk includes:
- Imports (User, bcrypt)
- Class context (AuthService)
- Full method implementation
- Patterns detected: ["authentication", "async", "validation"]

🛠️ Tools Reference

Tool Purpose Key Features
memory_engineering_init Initialize project Scans code, creates memories, generates embeddings
memory_engineering_memory Read/Update memories Unified interface for all 7 memories
memory_engineering_search Semantic search Memory + code search with patterns
memory_engineering_sync Sync code embeddings Smart chunking, incremental updates
memory_engineering_system Health & diagnostics Status, environment, doctor mode

🚀 Why This Works

  1. Complete Code Understanding: Unlike other systems that break functions arbitrarily, we preserve semantic units
  2. Rich Embeddings: Each chunk has context, patterns, and relationships
  3. Behavioral Prompting: Dramatic prompts ensure AI assistants take memory seriously
  4. MongoDB Scale: Handles millions of chunks with millisecond queries
  5. Voyage AI Quality: State-of-the-art embeddings optimized for code

📄 License

MIT - See LICENSE file

🔗 Links


Built with Model Context Protocol (MCP) by Anthropic

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选