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
Visit Server

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

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