-
Notifications
You must be signed in to change notification settings - Fork 1
Database Encryption
This guide covers how to encrypt an existing db-mcp plaintext SQLite database for use with the DB_ENCRYPTION_KEY feature (Encryption at Rest).
Warning
Encryption is only supported when running the Native (better-sqlite3) backend. WASM (sql.js) is incompatible with SQLCipher.
You will need the sqlcipher command-line utility installed on your system.
-
macOS:
brew install sqlcipher -
Ubuntu/Debian:
sudo apt-get install sqlcipher - Windows: Download from zetetic.net/sqlcipher or use WSL.
If you have an existing database named data.db and you want to encrypt it:
-
Open your terminal and create a new encrypted database file:
sqlcipher encrypted_data.db
-
Set the encryption key for the new database (this must be done first):
sqlite> PRAGMA key = 'your-super-secret-key-here';
-
Attach your existing plaintext database:
sqlite> ATTACH DATABASE 'data.db' AS plaintext KEY '';
-
Export the plaintext data into the encrypted database:
sqlite> SELECT sqlcipher_export('main', 'plaintext');
-
Detach the plaintext database and exit:
sqlite> DETACH DATABASE plaintext; sqlite> .quit
Your encrypted_data.db is now fully encrypted.
To start db-mcp using your newly encrypted database, set the DB_ENCRYPTION_KEY environment variable or use the --encryption-key flag alongside --sqlite-native:
DB_ENCRYPTION_KEY="your-super-secret-key-here" \
db-mcp --sqlite-native ./encrypted_data.dbOr using CLI flags exclusively:
db-mcp --sqlite-native ./encrypted_data.db --encryption-key "your-super-secret-key-here"-
System Database: If you enable encryption, your sidecar
SystemDb(which contains audit logs and metrics) will also be encrypted using the same key automatically. This ensures sensitive queries recorded in the audit log are protected. - Performance: SQLCipher introduces a slight performance overhead (typically 5-15%) compared to plaintext SQLite due to page-level encryption and decryption.
-
Key Rotation: To change your encryption key, you must connect to the encrypted database using
sqlcipher, executePRAGMA key = 'old-key';followed byPRAGMA rekey = 'new-key';. You cannot rotate keys directly throughdb-mcp.