Cortex-mem cortex-mem-mcp
Persistent memory enhancement for AI agents. Store conversations, search memories with semantic retrieval, and recall context across sessions. Use this skill when you need to remember user preferences, past conversations, project context, or any information that should persist beyond the current session. Provides tiered access (abstract/overview/content) for efficient context management.
git clone https://github.com/sopaco/cortex-mem
T=$(mktemp -d) && git clone --depth=1 https://github.com/sopaco/cortex-mem "$T" && mkdir -p ~/.claude/skills && cp -r "$T/cortex-mem-mcp/skill" ~/.claude/skills/sopaco-cortex-mem-cortex-mem-mcp && rm -rf "$T"
cortex-mem-mcp/skill/SKILL.mdCortex Memory MCP Skill
This skill enables persistent memory capabilities for AI agents, allowing them to store, search, and recall information across sessions using semantic retrieval.
Prerequisites Check
Before configuring this skill, verify if
cortex-mem-mcp is available in your system:
# Check if cortex-mem-mcp is in PATH which cortex-mem-mcp || where cortex-mem-mcp # Linux/macOS || Windows
If the command returns a path, the binary is already installed. If not, proceed to the installation section below.
Installation
Option 1: Install from crates.io (Recommended)
cargo install cortex-mem-mcp
After installation, verify:
cortex-mem-mcp --version
Option 2: Build from Source
# Clone the repository git clone https://github.com/sopaco/cortex-mem.git cd cortex-mem # Build the release binary cargo build --release --bin cortex-mem-mcp # The binary will be at: # ./target/release/cortex-mem-mcp (Linux/macOS) # .\target\release\cortex-mem-mcp.exe (Windows)
Option 3: Download Pre-built Binary
Download the latest release from GitHub:
- GitHub Releases: https://github.com/sopaco/cortex-mem/releases
Choose the appropriate binary for your platform:
(Linux x64)cortex-mem-mcp-linux-x86_64
(macOS Apple Silicon)cortex-mem-mcp-darwin-arm64
(macOS Intel)cortex-mem-mcp-darwin-x86_64
(Windows x64)cortex-mem-mcp-windows-x86_64.exe
Configuration
Step 1: Create Configuration File
Create a
config.toml file (e.g., ~/.config/cortex-mem/config.toml):
[cortex] # Data directory for storing memories data_dir = "~/.cortex-data" [llm] # LLM API configuration api_base_url = "https://api.openai.com/v1" api_key = "your-api-key" model_efficient = "gpt-5-mini" temperature = 0.1 max_tokens = 65536 [embedding] # Embedding configuration api_base_url = "https://api.openai.com/v1" api_key = "your-embedding-api-key" model_name = "text-embedding-3-small" batch_size = 10 timeout_secs = 30 [qdrant] # Vector database configuration url = "http://localhost:6334" collection_name = "cortex_memories" embedding_dim = 1536 timeout_secs = 30
Step 2: Start Qdrant (Vector Database)
# Using Docker docker run -d -p 6333:6333 qdrant/qdrant # Verify Qdrant is running curl http://localhost:6333
Step 3: Configure MCP Client
Configure your MCP client (e.g., Claude Desktop, Cursor, etc.) to use cortex-mem-mcp.
Claude Desktop
Edit the configuration file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
Add the following configuration:
{ "mcpServers": { "cortex-memory": { "command": "cortex-mem-mcp", "args": [ "--config", "/path/to/config.toml", "--tenant", "default" ], "env": { "RUST_LOG": "info" } } } }
If you built from source, use the full path to the binary:
{ "mcpServers": { "cortex-memory": { "command": "/path/to/cortex-mem/target/release/cortex-mem-mcp", "args": [ "--config", "/path/to/config.toml", "--tenant", "default" ] } } }
Cursor IDE
Add to your Cursor MCP settings:
{ "mcpServers": { "cortex-memory": { "command": "cortex-mem-mcp", "args": ["--config", "/path/to/config.toml"] } } }
Step 4: Restart Your MCP Client
After configuration, restart Claude Desktop or your MCP client to load the new server.
Step 5: Verify Installation
Test the MCP server manually:
# Run with debug logging RUST_LOG=debug cortex-mem-mcp --config /path/to/config.toml --tenant default
Command-line Arguments
| Argument | Default | Description |
|---|---|---|
/ | | Path to configuration file |
| | Tenant ID for memory isolation |
| | Message count to auto-trigger memory extraction |
| | Min seconds between auto-trigger executions |
| | Inactivity timeout to trigger extraction |
| | Disable auto-trigger feature entirely |
Environment Variables
| Variable | Description |
|---|---|
| Override data directory path |
| Logging level (debug, info, warn, error) |
When to Use This Skill
Use this skill when you need to:
- Remember user preferences - Store and recall user-specific settings, preferences, and context
- Persist conversation context - Keep important information from past conversations accessible
- Build project knowledge - Accumulate and retrieve project-specific information over time
- Track user-agent interactions - Maintain a history of interactions for better personalization
- Search memories semantically - Find relevant information using natural language queries
Available Tools
Storage Tools
store
storeAdd a message to memory for a specific session.
{ "content": "The user prefers dark mode in all applications", "thread_id": "project-alpha", "role": "user" }
: The message content to storecontent
: Optional session/thread identifier (defaults to "default")thread_id
: Message role - "user", "assistant", or "system"role
commit
commitCommit accumulated conversation content and trigger memory extraction.
{ "thread_id": "project-alpha" }
This triggers:
- Memory extraction (session → user/agent memories)
- L0/L1 layer generation
- Vector indexing
Search Tools
search
searchLayered semantic search across memory using L0/L1/L2 tiered retrieval.
{ "query": "user preferences for UI", "scope": "project-alpha", "limit": 10, "min_score": 0.5, "return_layers": ["L0", "L1"] }
recall
recallRecall memories with full context (L0 snippet + L2 content).
{ "query": "what did we discuss about authentication", "scope": "project-alpha", "limit": 5 }
Navigation Tools
ls
lsList directory contents to browse the memory space.
{ "uri": "cortex://session", "recursive": true, "include_abstracts": true }
Common URIs:
- List all sessionscortex://session
- List user-level memoriescortex://user
- User preference memoriescortex://user/{user_id}/preferences
explore
exploreSmart exploration of memory space, combining search and browsing.
{ "query": "authentication implementation details", "start_uri": "cortex://session", "return_layers": ["L0"] }
Tiered Access Tools
Memory is organized in layers for efficient context management:
| Layer | Size | Purpose |
|---|---|---|
| L0 | ~100 tokens | Quick relevance checking (abstract) |
| L1 | ~2000 tokens | Understanding core information (overview) |
| L2 | Full content | Complete original content |
abstract
abstractGet L0 abstract layer for quick relevance checking.
{ "uri": "cortex://session/project-alpha/timeline/2024-03/15/10_30_45_abc123.md" }
overview
overviewGet L1 overview layer for understanding core information.
{ "uri": "cortex://session/project-alpha/timeline/2024-03/15/10_30_45_abc123.md" }
content
contentGet L2 full content layer - the complete original content.
{ "uri": "cortex://session/project-alpha/timeline/2024-03/15/10_30_45_abc123.md" }
Management Tools
delete
deleteDelete a memory by its URI.
{ "uri": "cortex://session/old-project/timeline/2024-03/15/10_30_45_xyz.md" }
layers
layersGenerate L0/L1 layer files for memories.
{ "thread_id": "project-alpha" }
index
indexIndex memory files for vector search.
{ "thread_id": "project-alpha" }
Memory URI Structure
Memories are organized using a URI scheme:
cortex://session/{thread_id}/timeline/{YYYY-MM}/{DD}/{HH_MM_SS}_{id}.md cortex://user/{user_id}/preferences/{topic}.md cortex://user/{user_id}/entities/{name}.md cortex://user/{user_id}/events/{name}.md cortex://agent/{agent_id}/cases/{name}.md cortex://agent/{agent_id}/skills/{name}.md
Note: Session dimension stores conversation timeline; extracted memories (preferences, entities, etc.) are stored in user/agent dimensions after
commit.
Best Practices
-
Use meaningful thread IDs - Use descriptive names like
orproject-alpha
instead of generic IDsuser-123-support -
Commit periodically - Call
after significant conversation milestones to ensure memory extractioncommit -
Start with search - Before storing new information, search to avoid duplication
-
Use tiered access - Start with
orabstract
to find relevant memories, then usesearch
oroverview
for detailscontent -
Scope your searches - Use the
parameter to limit searches to relevant sessionsscope
Example Workflow
Storing a User Preference
1. Store the preference: store(content="User prefers TypeScript over JavaScript for all new projects", role="user") 2. Commit to persist: commit()
Recalling Past Context
1. Search for relevant memories: search(query="TypeScript preferences", limit=5) 2. Get overview of most relevant result: overview(uri="cortex://user/default/preferences/typescript.md")
Building Project Knowledge
1. Store project decisions: store(content="Decided to use PostgreSQL for the main database", thread_id="project-x", role="assistant") 2. Later, recall project decisions: recall(query="database decisions", scope="project-x")
Auto-Trigger Feature
The MCP server supports automatic memory processing:
- Triggers after configurable message count threshold (default: 10)
- Triggers after inactivity timeout (default: 2 minutes)
- Can be disabled with
flag--no-auto-trigger
Configuration
The MCP server requires a
config.toml with:
[cortex] data_dir = "./cortex-data" [llm] api_base_url = "https://api.openai.com/v1" api_key = "your-api-key" model_efficient = "gpt-5-mini" [embedding] api_base_url = "https://api.openai.com/v1" api_key = "your-api-key" model_name = "text-embedding-3-small" [qdrant] url = "http://localhost:6333" collection_name = "cortex_mem" embedding_dim = 1536