A sophisticated Model Context Protocol (MCP) server that provides Claude Code with persistent semantic memory capabilities, enabling long-term information storage and retrieval across sessions. This system allows Claude to remember context, preferences, and important information between conversations.
- π§ Persistent Memory: Information survives across Claude Code sessions
- π Semantic Search: Retrieve memories based on meaning, not just keywords
- π Project Namespaces: Organize memories into separate contexts/projects
- π Local Embeddings: Works offline without external API dependencies
- π Memory Relations: Create knowledge graphs with connected memories
- π Intent-Based Activation: Natural language triggers automatic tool invocation
- π Full CRUD Operations: Create, read, update, and delete memories
- π Privacy-First: All data stored in your own PostgreSQL database
agentic-memory/
βββ src/
β βββ index.ts # MCP server entry point
β βββ db/
β β βββ client.ts # Database connection (Neon PostgreSQL)
β β βββ schema.ts # Drizzle ORM schema (memories, relations)
β βββ tools/
β βββ createMemory.ts # Store new memories
β βββ searchMemory.ts # Semantic search
β βββ listMemories.ts # List and filter memories
β βββ deleteMemory.ts # Remove memories
β βββ updateMemory.ts # Modify existing memories
β βββ manageProjects.ts # Project namespace management
β βββ simpleEmbedding.ts # Local embedding generation
βββ run-server.sh # Server startup script
βββ .env # Environment configuration
- Claude Code sends requests to the MCP server via stdio
- MCP Server processes tool requests (create, search, delete memories)
- Embeddings are generated locally using mathematical algorithms
- PostgreSQL (Neon) stores memories with pgvector for semantic search
- Drizzle ORM manages database operations and migrations
- Node.js 18+
- PostgreSQL database with pgvector extension (Neon recommended)
- Claude Code CLI installed
- Clone or copy this MCP server to your project:
cp -r /path/to/agentic-memory /your/project/.claude/mcp-servers/- Install dependencies:
cd /your/project/.claude/mcp-servers/agentic-memory
npm install- Configure environment variables:
cp .env.example .env
# Edit .env with your database URL- Run database migrations:
npm run db:migrate- Add to Claude Code:
claude mcp add agentic-memory ./run-server.sh- Verify connection:
claude mcp list
# Should show: agentic-memory - β Connected| Tool | Description | Example Use |
|---|---|---|
create_memory |
Store new information | "Remember that the user prefers TypeScript" |
search_memory |
Find relevant memories | "What do we know about the user's preferences?" |
list_memories |
View all memories | "Show all memories in current project" |
delete_memory |
Remove specific memory | "Delete memory with ID xyz" |
update_memory |
Modify existing memory | "Update the location information" |
switch_project |
Change memory namespace | "Switch to project 'work'" |
list_projects |
Show all projects | "What projects exist?" |
delete_project |
Remove entire project | "Delete the 'test' project" |
The CLAUDE.md file acts as a quasi-orchestrator, providing:
- Context Instructions: High-level rules for memory usage
- Specialist Agents: Memory agents that Claude Code can invoke
- Immutability Principles: Memories should be append-only
- Quality Guidelines: Only store high-signal, reusable information
Example CLAUDE.md pattern:
# Project Context: [Your Project Name]
This project uses an advanced semantic memory system to learn and improve over time.
## Key Capabilities
- **Semantic Memory**: Long-term memory storage and retrieval
- **Specialist Agents**: Dedicated agents for memory operations
## Core Principles
- **Immutable Memories**: Once created, memories should not be altered
- **High-Signal Only**: Store only reusable, non-obvious information
- **No Secrets**: Never store API keys, passwords, or PIICreate .env file:
# PostgreSQL connection (required)
DATABASE_URL=postgresql://user:pass@host/db?sslmode=require
# Optional: Embedding configuration
EMBEDDING_MODEL=simple # or 'llama' for advanced
EMBEDDING_DIMENSIONS=1536
# Optional: Default project
DEFAULT_PROJECT=defaultThe system uses two main tables:
memories: Stores content, embeddings, metadata, and timestampsmemory_relations: Links related memories (parent-child relationships)
- Pros: No external dependencies, works offline, fast
- Cons: Less semantic accuracy
- Use Case: Development, restricted networks, testing
- Pros: Higher semantic accuracy
- Cons: Requires model download, more resources
- Use Case: Production environments with good connectivity
β Memory CRUD Agents: Create, read, update, delete operations β Project Management Agents: Namespace organization β Search Agent: Semantic similarity search
-
Memory Relations Agent
- Create parent-child relationships
- Build knowledge graphs
- Track memory evolution
-
Memory Analytics Agent
- Usage statistics
- Memory patterns
- Optimization recommendations
-
Export/Import Agent
- Backup memories
- Transfer between projects
- Migration tools
-
Deduplication Agent
- Detect similar memories
- Merge duplicates
- Maintain consistency
Solution: Check .env file exists and DATABASE_URL is correct
Solution: Ensure EMBEDDING_DIMENSIONS matches your database vector size
Solution: Verify database connection and that migrations have run
npm run devnpm run buildnpm testTo replicate this setup in another codebase:
- Copy the MCP server directory
- Set up a PostgreSQL database with pgvector
- Configure environment variables
- Run migrations
- Add to Claude Code configuration
- Create a CLAUDE.md file with memory instructions
- Test with simple memory operations
- Database Scaling: Consider connection pooling for heavy usage
- Embedding Cache: Implement caching for frequently accessed memories
- Backup Strategy: Regular database backups are essential
- Security: Never store sensitive information in memories
- Monitoring: Track memory usage and search performance
This is a custom MCP implementation. To contribute:
- Improve embedding algorithms
- Add new memory management tools
- Enhance search capabilities
- Optimize database queries
Contributions are welcome! Please feel free to submit a Pull Request.
- Improve embedding algorithms
- Add new memory management tools
- Enhance search capabilities
- Create visualization tools
- Optimize database queries
- Add support for more embedding models
This project is licensed under the MIT License - see the LICENSE file for details.
- Anthropic for Claude and the MCP protocol
- Neon for serverless PostgreSQL
- Drizzle ORM for database management
- The Claude Code community for feedback and suggestions
Tristan McInnis
- GitHub: @tristan-mcinnis
- Project: claude-code-agentic-semantic-memory-system-mcp
Built for Claude Code - Enabling persistent, semantic memory across AI coding sessions.
β If you find this project useful, please consider giving it a star on GitHub!