A Model Context Protocol (MCP) server that provides persistent memory and codebase understanding for AI coding assistants like Claude Code and Cursor.
# Run directly without installation
npx memory-engineering
# Or install globally
npm install -g memory-engineering
memory-engineering
- Fixed Memory Slots: 20 memories per project (5 per type) to prevent infinite growth
- Smart Updates: Memories update based on similarity (>85% threshold) instead of creating duplicates
- Project Isolation: Each project has its own memory namespace using path hashing
- Hybrid Search: Combines vector embeddings with keyword search for better retrieval
- Codebase Understanding: Indexes and embeds your entire codebase for semantic search
- Automatic Relevance Decay: Memories become less relevant over time if not updated
- Node.js v18 or higher
- MongoDB (local or Atlas)
- Voyage AI API key (optional, fallback available)
npx memory-engineering
npm install -g memory-engineering
memory-engineering
git clone https://github.com/romiluz13/memory-engineering.git
cd memory-engineering
npm install
npm run build
npm start
Create .env
file in your project root:
MONGODB_URI=mongodb://localhost:27017/ai_memory
VOYAGE_API_KEY=your_voyage_api_key_here # Optional
MAX_MEMORIES_PER_TYPE=5
SIMILARITY_THRESHOLD=0.85
CHUNK_SIZE=500
CHUNK_OVERLAP=50
Add to your Claude Desktop configuration:
{
"mcpServers": {
"memory": {
"command": "npx",
"args": ["memory-engineering"],
"env": {
"MONGODB_URI": "mongodb://localhost:27017/ai_memory",
"VOYAGE_API_KEY": "your_api_key"
}
}
}
}
Add to your .cursor/mcp.json
:
{
"servers": {
"memory": {
"command": "npx",
"args": ["memory-engineering"],
"cwd": "${workspaceFolder}"
}
}
}
- Project structure and architecture
- Tech stack and dependencies
- Coding conventions
- Business logic
- Design decisions
- Recent implementations
- Problem-solving patterns
- Bug fixes
- Feature development
- Refactoring decisions
- Common code patterns
- API patterns
- Database queries
- Error handling
- Testing patterns
- Known issues and fixes
- Performance optimizations
- Security considerations
- Debugging insights
- Edge cases
Save or update a memory slot:
{
type: "context", // or "task", "pattern", "issue"
content: "Project uses React 18 with TypeScript...",
keywords: ["react", "typescript"],
files: ["src/App.tsx"]
}
Search memories using semantic + keyword search:
{
query: "authentication implementation",
type: "task", // optional filter
limit: 5
}
List all project memories:
{
type: "pattern" // optional filter
}
Semantic search through codebase:
{
query: "database connection",
filePattern: "*.ts", // optional
limit: 10
}
Index or re-index the codebase:
{
rescan: true // force full rescan
}
Get a summary of all project memories.
- New Memory Arrives → Embed it
- Find Similar Memories → Compare embeddings
-
Decision Logic:
- Similarity > 85%: Merge with existing
- Similarity 50-85%: Ask which slot to replace
- Similarity < 50%: Replace least relevant slot
- File Discovery: Scans for code files (ignores node_modules, dist, etc.)
- Chunking: Splits files into 500-line chunks with 50-line overlap
- Embedding: Uses Voyage AI's code model for embeddings
- Caching: Only re-indexes changed files (MD5 hash comparison)
projectId = SHA256(absolute_project_path).substring(0, 16)
Each project gets a unique ID based on its absolute path, ensuring complete isolation.
memory-mcp-server/
├── src/
│ ├── index.ts # MCP server implementation
│ ├── db/
│ │ └── connection.ts # MongoDB connection with retry
│ ├── services/
│ │ ├── memory.ts # Memory CRUD operations
│ │ ├── embedding.ts # Voyage AI integration
│ │ └── codebase.ts # Code indexing service
│ └── types/
│ └── memory.ts # TypeScript types
├── .env # Configuration
├── package.json
└── tsconfig.json
- Ensure MongoDB is running:
mongod
- Check connection string in
.env
- Verify network access for Atlas
- The server works without Voyage API key (uses fallback)
- Check API key validity
- Monitor rate limits
- Check similarity threshold (default 0.85)
- Verify project path consistency
- Look for MongoDB write errors
- Reduce
CHUNK_SIZE
for large codebases - Increase
CHUNK_OVERLAP
for better context - Clear old indexes:
db.codebase_chunks.drop()
Logs are written to stderr and include:
-
[MongoDB]
- Database operations -
[Embedding]
- Embedding service status -
[Memory]
- Memory operations -
[Codebase]
- Indexing progress -
[Memory MCP]
- Server status
- Project isolation via hashing
- No cross-project data leakage
- Credentials in environment variables
- MongoDB connection retry with backoff
- Graceful degradation on API failures
- Lazy Loading: Memories loaded on demand
- Batch Embeddings: Process multiple texts together
- Embedding Cache: In-memory cache for repeated queries
- Incremental Indexing: Only changed files re-indexed
- Connection Pooling: Reuses MongoDB connections
- Fork the repository
- Create your feature branch
- Test thoroughly with real projects
- Submit a pull request
MIT
- Built for Claude Code and Cursor
- Powered by Voyage AI embeddings
- Uses MongoDB for persistence
- Implements Model Context Protocol
- First Run: Will initialize 20 empty memory slots
-
Codebase Indexing: Run
codebase_index
on first use - Memory Lifecycle: Memories decay in relevance over time
- Project Switching: Each project maintains separate memories
- Backup: Regular MongoDB backups recommended
// 1. Save project context
await mcp.call('memory_save', {
type: 'context',
content: 'This is a Next.js 14 app with App Router...',
keywords: ['nextjs', 'react', 'typescript']
});
// 2. Index the codebase
await mcp.call('codebase_index', { rescan: true });
// 3. Search for patterns
await mcp.call('memory_search', {
query: 'authentication flow'
});
// 4. Search codebase
await mcp.call('codebase_search', {
query: 'API endpoints',
filePattern: '*.ts'
});