Cortex MCP — Persistent AI Memory
Give your AI coding assistant a brain that remembers across sessions.
Cortex is an MCP (Model Context Protocol) server that provides persistent, intelligent memory to any AI coding assistant — Cursor, Claude Code, Windsurf, Cline, or any MCP-compatible tool.
What's New in v1.2
- 3-5x faster
force_recall— Brain layers 6-12 now run in parallel (was 15-19s, now 3-5s) - Result caching — Repeated
force_recallcalls return instantly (30s TTL) - 7 SQL queries → 1 — Context builder consolidated for faster startup
- 17 fixes across performance, robustness, and code quality
- Shared tag utility — Cleaner codebase, single source of truth for tag extraction
See CHANGELOG.md for full details.
The Problem
Every time you start a new conversation, your AI assistant forgets everything:
- Coding conventions you already explained
- Bugs you already fixed
- Decisions you already made
- What files you were working on
Cortex solves this. It stores, ranks, and proactively recalls context so your AI never starts from zero.
Quick Start
Option 1: npm install (recommended)
npm install -g cortex-mcp
Then add to your MCP config:
{
"mcpServers": {
"cortex": {
"command": "cortex-mcp",
"transportType": "stdio"
}
}
}
Option 2: Clone from source
git clone https://github.com/jaswanthkumarj1234-beep/cortex-mcp.git
cd cognitive-memory
npm install
npm run build
Then add to your MCP config:
{
"mcpServers": {
"cortex": {
"command": "node",
"args": ["<path-to>/cognitive-memory/dist/mcp-stdio.js"],
"transportType": "stdio"
}
}
}
Restart your IDE and Cortex is active.
Option 3: Direct Download (Binaries)
No Node.js required. Download from the latest release:
Then configure your MCP client to run the executable directly.
Try the Demo
See Cortex in action without any AI client:
npm run demo # Interactive demo — store, search, dedup
npm run benchmark # Performance benchmark — write, read, FTS ops/sec
IDE-Specific Setup Guides
Step-by-step instructions for your IDE: Cursor · Claude Code · Windsurf · Cline · Copilot
Recipes & Use Cases
10 practical examples: docs/recipes.md — conventions, bug tracking, anti-hallucination, team onboarding, and more.
Features
Why Cortex?
| Feature | Cortex | Other MCP memory servers |
|---|---|---|
| Retrieval | Hybrid (FTS + Vector + Graph) | Usually FTS only |
| Auto-learning | Extracts memories from AI responses | Manual store only |
| Hallucination detection | verify_code + verify_files | No |
| Git integration | Auto-captures commits, diffs, branch context | No |
| Cognitive features | Decay, attention, contradiction detection, consolidation | No |
| Brain pipeline | 12+ layer context injection | Simple key-value recall |
| Setup | npm i -g cortex-mcp + 1 config line | Varies |
| Offline | 100% local SQLite (no API key needed) | Often requires API |
16 MCP Tools
| Tool | Purpose |
|---|---|
force_recall | Full brain dump at conversation start (12+ layer pipeline) |
recall_memory | Search memories by topic (FTS + vector + graph) |
store_memory | Store a decision, correction, convention, or bug fix |
quick_store | One-liner memory storage with auto-classification |
auto_learn | Extract memories from AI responses automatically |
scan_project | Scan project structure, stack, git, exports, architecture |
verify_code | Check if imports/exports/env vars actually exist |
verify_files | Check if file paths are real or hallucinated |
get_context | Get compressed context for current file |
get_stats | Memory database statistics |
list_memories | List all active memories |
update_memory | Update an existing memory |
delete_memory | Delete a memory |
export_memories | Export all memories to JSON |
import_memories | Import memories from JSON |
health_check | Server health check |
12+ Layer Brain Pipeline
Every conversation starts with force_recall, which runs 12+ layers (layers 6-12 run in parallel for speed):
| Layer | Feature | Parallel? |
|---|---|---|
| 0 | Session management — track what you're working on | — |
| 1 | Maintenance — decay, boost corrections, consolidate | — |
| 2 | Attention focus — detect debugging vs coding vs reviewing | — |
| 3 | Session continuity — resume where you left off | — |
| 4 | Hot corrections — frequently-corrected topics | — |
| 5 | Core context — corrections, decisions, conventions, bug fixes | — |
| 6 | Anticipation — proactive recall based on current file | ✅ |
| 7 | Temporal — what changed today, yesterday, this week | ✅ |
| 8 | Workspace git — branch, recent commits, diffs | ✅ |
| 8.5 | Git memory — auto-capture commits + file changes | ✅ |
| 9 | Topic search — FTS + decay + causal chain traversal | ✅ |
| 10 | Knowledge gaps — flag files with zero memories | ✅ |
| 11 | Export map — all functions/classes (anti-hallucination) | ✅ |
| 12 | Architecture graph — layers, circular deps, API endpoints | ✅ |
Cognitive Features
- Confidence decay — old unused memories fade, frequently accessed ones strengthen
- Attention ranking — debugging context boosts bug-fix memories, coding boosts conventions
- Contradiction detection — new memories automatically supersede conflicting old ones
- Memory consolidation — similar memories merge into higher-level insights
- Cross-session threading — related sessions link by topic overlap
- Learning rate — topics corrected 3+ times get CRITICAL priority
Performance & Reliability
force_recalllatency: ~3-5s first call, instant on cache hit (v1.2 — was 15-19s)recall_memorylatency: <1ms average (local SQLite + WAL)- Throughput: 1800+ ops/sec (verified via Soak Test)
- Stability: Zero memory leaks over sustained operation
- Protocol: Full JSON-RPC 2.0 compliance (passed E2E suite)
- CI: Tested on Node 18, 20, 22 with lint + build + E2E on every push
Anti-Hallucination
- Deep export map scans every source file for all exported functions, classes, types
- When AI references a function that doesn't exist,
verify_codesuggests the closest real match - Architecture graph shows actual project layers and dependencies
Optional: LLM Enhancement
Cortex works fully without any API key. Optionally, add an LLM key for smarter memory extraction:
# Option 1: OpenAI
set OPENAI_API_KEY=sk-your-key
# Option 2: Anthropic
set ANTHROPIC_API_KEY=sk-ant-your-key
# Option 3: Local (Ollama, free)
set CORTEX_LLM_KEY=ollama
set CORTEX_LLM_BASE_URL=http://localhost:11434
Memory Types
| Type | Use For |
|---|---|
CORRECTION | "Don't use var, use const" |
DECISION | "We chose PostgreSQL over MongoDB" |
CONVENTION | "All API routes start with /api/v1" |
BUG_FIX | "Fixed race condition in auth middleware" |
INSIGHT | "The codebase uses a layered architecture" |
FAILED_SUGGESTION | "Tried Redis caching, too complex for this project" |
PROVEN_PATTERN | "useDebounce hook works well for search inputs" |
Architecture
src/
├── server/ # MCP handler (12+ layer brain pipeline) + dashboard
├── memory/ # 17 cognitive modules (decay, attention, anticipation, etc.)
├── scanners/ # Project scanner, code verifier, export map, architecture graph
├── db/ # SQLite storage, event log
├── security/ # Rate limiter, encryption
├── hooks/ # Git capture
├── config/ # Configuration
└── cli/ # Setup wizard
Pricing & Features
Cortex is open core. The basic version is free forever. To unlock deep cognitive features, upgrade to PRO.
| Feature | FREE (npm install) | PRO ($9/mo) |
|---|---|---|
| Memory Capacity | ∞ Unlimited | ∞ Unlimited |
| Brain Layers | 12+ (Full) | 12+ (Full) |
| All 16 Tools | Yes | Yes |
| Auto-Learn | Yes | Yes |
| Export Map (Anti-Hallucination) | Yes | Yes |
| Architecture Graph | Yes | Yes |
| Git Memory | Yes | Yes |
| Confidence Decay | Yes | Yes |
| Contradiction Detection | Yes | Yes |
| Priority Support | — | Yes |
Launch Edition: All features are currently free. Get started now and lock in lifetime access.
Activate PRO
- Get a license key from your Cortex AI Dashboard
- Set it in your environment:
# Option A: Environment variable export CORTEX_LICENSE_KEY=CORTEX-XXXX-XXXX-XXXX-XXXX # Option B: License file echo CORTEX-XXXX-XXXX-XXXX-XXXX > ~/.cortex/license - Restart your IDE / MCP server.
Architecture
graph TB
AI["AI Client (Cursor, Claude, etc.)"]
MCP["MCP Server (stdio)"]
ML["Memory Layer"]
DB["SQLite Database"]
SEC["Security Layer"]
API["License API"]
AI -->|"JSON-RPC via stdio"| MCP
MCP --> ML
ML --> DB
MCP --> SEC
SEC -->|"verify license"| API
subgraph "Memory Layer"
ML --> EMB["Embedding Manager"]
ML --> AL["Auto-Learner"]
ML --> QG["Quality Gates"]
ML --> TD["Temporal Decay"]
end
subgraph "Retrieval"
ML --> HR["Hybrid Retriever"]
HR --> VS["Vector Search"]
HR --> FTS["Full-Text Search"]
HR --> RR["Recency Ranker"]
end
FAQ / Troubleshooting
Cortex doesn't start or my AI client can't connect
- Make sure Node.js >=18 is installed:
node --version - Try running manually:
npx cortex-mcp— check stderr for errors - Check if another Cortex instance is running on the same workspace
- Delete the cache and restart:
rm -rf .ai/brain-data
Memories aren't being recalled
- Confirm your AI client's system prompt includes the Cortex rules (run
cortex-setupto install them) - Check the dashboard at
http://localhost:3456to see stored memories - Verify memories exist: the AI should call
force_recallat conversation start
"better-sqlite3" build errors on install
better-sqlite3 requires a C++ compiler:
- Windows: Install Visual Studio Build Tools
- macOS: Run
xcode-select --install - Linux: Run
sudo apt-get install build-essential python3
License key not working
- Verify the key format:
CORTEX-XXXX-XXXX-XXXX-XXXX - Check your internet connection (license is verified online on first use)
- Clear the cache:
rm ~/.cortex/license-cache.json - Try setting it via environment variable:
export CORTEX_LICENSE_KEY=CORTEX-...
Dashboard not loading
- Default port is 3456. Check if something else is using it:
lsof -i :3456 - Set a custom port:
export CORTEX_PORT=4000 - The dashboard URL is shown in your AI client's stderr on startup
Contributing
See CONTRIBUTING.md for development setup, coding conventions, and the PR process.
License
MIT