|
| 1 | +# MCP Memory SQLite |
| 2 | + |
| 3 | +A high-performance [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) memory server using SQLite with WAL mode for concurrent access. |
| 4 | + |
| 5 | +**Drop-in replacement for `@modelcontextprotocol/server-memory` with better concurrency support.** |
| 6 | + |
| 7 | +## Why This Package? |
| 8 | + |
| 9 | +The official `@modelcontextprotocol/server-memory` uses JSONL files without file locking, which can lead to: |
| 10 | + |
| 11 | +- **Race conditions** when multiple sessions access the same memory file |
| 12 | +- **Data corruption** under concurrent write operations |
| 13 | +- **Lost updates** when parallel agents write simultaneously |
| 14 | + |
| 15 | +This package solves these issues by using **SQLite with WAL (Write-Ahead Logging)** mode: |
| 16 | + |
| 17 | +| Feature | server-memory | mcp-memory-sqlite | |
| 18 | +|---------|---------------|-------------------| |
| 19 | +| Storage | JSONL (text file) | SQLite database | |
| 20 | +| Concurrent reads | Limited | Unlimited | |
| 21 | +| Concurrent writes | Race conditions | Safe (WAL mode) | |
| 22 | +| Lock contention | No handling | 5s timeout with retry | |
| 23 | +| Data integrity | No guarantees | ACID transactions | |
| 24 | +| Multiple sessions | Problematic | Fully supported | |
| 25 | + |
| 26 | +## Installation |
| 27 | + |
| 28 | +```bash |
| 29 | +npm install @daichi-kudo/mcp-memory-sqlite |
| 30 | +``` |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +### With Claude Code |
| 35 | + |
| 36 | +Add to your `~/.claude.json`: |
| 37 | + |
| 38 | +```json |
| 39 | +{ |
| 40 | + "mcpServers": { |
| 41 | + "memory": { |
| 42 | + "type": "stdio", |
| 43 | + "command": "npx", |
| 44 | + "args": ["@daichi-kudo/mcp-memory-sqlite"], |
| 45 | + "env": { |
| 46 | + "MEMORY_DB_PATH": "./.claude/memory.db" |
| 47 | + } |
| 48 | + } |
| 49 | + } |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +### With Claude Desktop |
| 54 | + |
| 55 | +Add to your Claude Desktop configuration: |
| 56 | + |
| 57 | +```json |
| 58 | +{ |
| 59 | + "mcpServers": { |
| 60 | + "memory": { |
| 61 | + "command": "npx", |
| 62 | + "args": ["@daichi-kudo/mcp-memory-sqlite"], |
| 63 | + "env": { |
| 64 | + "MEMORY_DB_PATH": "/path/to/your/memory.db" |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +### Environment Variables |
| 72 | + |
| 73 | +| Variable | Description | Default | |
| 74 | +|----------|-------------|---------| |
| 75 | +| `MEMORY_DB_PATH` | Path to SQLite database file | `./memory.db` in package directory | |
| 76 | + |
| 77 | +## Available Tools |
| 78 | + |
| 79 | +This server provides the same Knowledge Graph API as the official memory server: |
| 80 | + |
| 81 | +### Entity Management |
| 82 | + |
| 83 | +- **`create_entities`** - Create multiple new entities |
| 84 | +- **`delete_entities`** - Delete entities and their relations |
| 85 | +- **`open_nodes`** - Retrieve specific entities by name |
| 86 | + |
| 87 | +### Observation Management |
| 88 | + |
| 89 | +- **`add_observations`** - Add observations to existing entities |
| 90 | +- **`delete_observations`** - Remove specific observations |
| 91 | + |
| 92 | +### Relation Management |
| 93 | + |
| 94 | +- **`create_relations`** - Create relations between entities |
| 95 | +- **`delete_relations`** - Remove relations |
| 96 | + |
| 97 | +### Query Operations |
| 98 | + |
| 99 | +- **`read_graph`** - Read the entire knowledge graph |
| 100 | +- **`search_nodes`** - Search entities by name, type, or observation content |
| 101 | + |
| 102 | +## Data Model |
| 103 | + |
| 104 | +``` |
| 105 | +Entity |
| 106 | +├── name (unique identifier) |
| 107 | +├── entityType (category) |
| 108 | +└── observations[] (facts about the entity) |
| 109 | +
|
| 110 | +Relation |
| 111 | +├── from (source entity name) |
| 112 | +├── to (target entity name) |
| 113 | +└── relationType (relationship description) |
| 114 | +``` |
| 115 | + |
| 116 | +### Example |
| 117 | + |
| 118 | +```typescript |
| 119 | +// Create entities |
| 120 | +await create_entities({ |
| 121 | + entities: [ |
| 122 | + { |
| 123 | + name: "TypeScript", |
| 124 | + entityType: "Language", |
| 125 | + observations: [ |
| 126 | + "Superset of JavaScript", |
| 127 | + "Adds static typing" |
| 128 | + ] |
| 129 | + } |
| 130 | + ] |
| 131 | +}); |
| 132 | + |
| 133 | +// Create relations |
| 134 | +await create_relations({ |
| 135 | + relations: [ |
| 136 | + { |
| 137 | + from: "TypeScript", |
| 138 | + to: "JavaScript", |
| 139 | + relationType: "compiles_to" |
| 140 | + } |
| 141 | + ] |
| 142 | +}); |
| 143 | + |
| 144 | +// Search |
| 145 | +await search_nodes({ query: "typing" }); |
| 146 | +``` |
| 147 | + |
| 148 | +## Technical Details |
| 149 | + |
| 150 | +### SQLite Configuration |
| 151 | + |
| 152 | +- **WAL Mode**: Enables concurrent reads while writing |
| 153 | +- **Busy Timeout**: 5 seconds (prevents immediate lock failures) |
| 154 | +- **Foreign Keys**: Cascade deletes for data integrity |
| 155 | + |
| 156 | +### Schema |
| 157 | + |
| 158 | +```sql |
| 159 | +CREATE TABLE entities ( |
| 160 | + name TEXT PRIMARY KEY, |
| 161 | + entity_type TEXT NOT NULL |
| 162 | +); |
| 163 | + |
| 164 | +CREATE TABLE observations ( |
| 165 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 166 | + entity_name TEXT NOT NULL, |
| 167 | + content TEXT NOT NULL, |
| 168 | + FOREIGN KEY (entity_name) REFERENCES entities(name) ON DELETE CASCADE, |
| 169 | + UNIQUE(entity_name, content) |
| 170 | +); |
| 171 | + |
| 172 | +CREATE TABLE relations ( |
| 173 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 174 | + from_entity TEXT NOT NULL, |
| 175 | + to_entity TEXT NOT NULL, |
| 176 | + relation_type TEXT NOT NULL, |
| 177 | + FOREIGN KEY (from_entity) REFERENCES entities(name) ON DELETE CASCADE, |
| 178 | + FOREIGN KEY (to_entity) REFERENCES entities(name) ON DELETE CASCADE, |
| 179 | + UNIQUE(from_entity, to_entity, relation_type) |
| 180 | +); |
| 181 | +``` |
| 182 | + |
| 183 | +## Migration from server-memory |
| 184 | + |
| 185 | +This package is API-compatible with `@modelcontextprotocol/server-memory`. Simply: |
| 186 | + |
| 187 | +1. Install this package |
| 188 | +2. Update your MCP configuration to use `@daichi-kudo/mcp-memory-sqlite` |
| 189 | +3. Set `MEMORY_DB_PATH` to your preferred location |
| 190 | + |
| 191 | +Note: This package uses SQLite instead of JSONL, so existing JSONL data won't be automatically migrated. |
| 192 | + |
| 193 | +## Development |
| 194 | + |
| 195 | +```bash |
| 196 | +# Install dependencies |
| 197 | +npm install |
| 198 | + |
| 199 | +# Build |
| 200 | +npm run build |
| 201 | + |
| 202 | +# Run in development mode |
| 203 | +npm run dev |
| 204 | +``` |
| 205 | + |
| 206 | +## License |
| 207 | + |
| 208 | +MIT |
| 209 | + |
| 210 | +## Contributing |
| 211 | + |
| 212 | +Issues and pull requests are welcome at [GitHub](https://github.com/Daichi-Kudo/mcp-memory-sqlite). |
0 commit comments