Sign inSign up

writenotenow/db-mcp

By writenotenow

•Updated 4 months ago

Secure SQLite MCP: 181+ Tools via V8 Code Mode. Dual-Transport HTTP/SSE, OAuth 2.1 & Audit Logging.

Image
Developer tools
Data science
Databases & storage
1

8.1K

writenotenow/db-mcp repository overview

⁠db-mcp (SQLite MCP Server)

Production-ready SQLite MCP server with 170+ tools, audit logging, OAuth 2.1, and Code Mode.

GitHub GitHub Release npm Docker Pulls License: MIT Status MCP Security TypeScript E2E Tests Coverage

GitHub⁠ • Wiki⁠ • Changelog⁠


⁠🎯 What Sets Us Apart

FeatureDescription
181+ Specialized ToolsThe most comprehensive SQLite MCP server available — core CRUD, JSON/JSONB, FTS5 full-text search, statistical analysis, vector search, geospatial/SpatiaLite, introspection, migration, and admin
Deep ObservabilityBuilt-in Prometheus /metrics export, real-time sqlite://metrics MCP resource, historical persistence to a SystemDb sidecar, and a granular sqlite_audit_search tool for compliance and investigation
Dynamic ConfigurationFull YAML/JSON config file support (--config) with precedence rules, plus a sqlite_server_config tool for live runtime config updates (e.g., log levels) without server restarts
Advanced Query & SearchO(1) cursor-based keyset pagination, faceted search aggregation, and sqlite_hybrid_search orchestrating FTS5 + Vector similarity with Reciprocal Rank Fusion (RRF) in a single tool call
AI Index Recommendationssqlite_index_audit automatically analyzes EXPLAIN QUERY PLAN responses to suggest optimized composite and partial indexes based on workload patterns
Real-time SubscriptionsNative resources/subscribe support pushing event-driven notifications for sqlite://schema DDL changes and periodic sqlite://health updates directly to clients
22 Resources11 data resources (schema, tables, table_schema, indexes, views, health, meta, audit, metrics, compile_options, pragma) + 11 help resources (sqlite://help + per-group reference) — filtered by --tool-filter
10 AI-Powered PromptsGuided workflows for schema exploration, query building, data analysis, optimization, migration, debugging, and hybrid FTS5 + vector search
Code ModeMassive Token Savings: Execute complex, multi-step operations inside a V8 isolate sandbox with process-level isolation and hard timeouts. Instead of spending thousands of tokens on back-and-forth tool calls, Code Mode exposes all 181+ capabilities locally, reducing token overhead by 70–90% and supercharging AI agent reasoning
Token-Optimized PayloadsEvery tool response is designed for minimal token footprint with compact, nodesOnly, maxOutliers, minSeverity, and maxInvalid parameters — letting agents control response size without losing data access. Every response includes _meta.tokenEstimate so agents know their token cost
Dual SQLite BackendsWASM (sql.js) for zero-compilation portability, Native (better-sqlite3) for full features including transactions, window functions, and SpatiaLite GIS
OAuth 2.1 + Access ControlEnterprise-ready security with RFC 9728/8414 compliance, granular scopes (full, read, write, admin, db:*, table:*:*), and Keycloak integration
Smart Tool Filtering10 tool groups + 7 shortcuts let you stay within IDE limits while exposing exactly what you need
HTTP Streaming TransportStreamable HTTP (/mcp) + legacy SSE (/sse) with auth, security headers, rate limiting, health check, and stateless mode for serverless
Production-Ready SecuritySQL injection protection (parameterized queries + Unicode-normalized WHERE clause validation), sandboxed code execution (V8 codeGeneration restrictions, frozen prototypes, 29 blocked patterns, Proxy nullified, RPC allowlist), CORS deny-all default, fail-closed scope enforcement, JWT claims sanitization, 7 security headers, body size limits, rate limiting, slowloris timeouts, opt-in HSTS, non-root Docker, and build provenance
Encryption at RestNative SQLCipher support via --encryption-key or DB_ENCRYPTION_KEY. Dynamically loads better-sqlite3-multiple-ciphers and automatically encrypts the sidecar SystemDb audit logs to prevent sensitive queries from leaking
Deterministic Error HandlingEvery tool returns structured {success, error, code, category, suggestion, recoverable} responses — no raw exceptions. Agents get enriched error context with actionable suggestions instead of cryptic SQLite codes
⁠Backend Options
FeatureWASM (sql.js)Native (better-sqlite3)
Group Tools143170
Transactions❌✅ 8 tools
Window Functions❌✅ 6 tools
SpatiaLite GIS❌✅ 7 tools
Cross-platform✅ Pure JavaScriptCompiled natively in image
Performance⚠️ Synchronous execution (Blocks Node Event Loop on heavy loads)🚀 High-performance, concurrent

⚠️ WASM Note: The WASM backend blocks the Node.js event loop during intensive workloads. sqlite_read_query limits unbounded queries to 1,000 rows. For production, use Native (--sqlite-native).

⁠🚀 Quick Start

⁠1. Pull the Image
docker pull writenotenow/db-mcp:latest
⁠2. Run with MCP Client

Add to your ~/.cursor/mcp.json or Claude Desktop config:

{
  "mcpServers": {
    "db-mcp-sqlite": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-v",
        "./data:/app/data",
        "writenotenow/db-mcp:latest",
        "--sqlite-native",
        "/app/data/database.db",
        "--tool-filter",
        "codemode"
      ]
    }
  }
}

⭐ Code Mode (--tool-filter codemode) is the recommended configuration — it exposes sqlite_execute_code, a V8 isolate sandbox with process-level isolation providing access to all 170+ tools' worth of capability with 70–90% token savings. See Tool Filtering⁠ for alternatives.

Tip

**Switching backends:** The config above uses the **Native** backend (better-sqlite3, 181 MCP tools / 170 group tools). To use the **WASM** backend (sql.js, 154 MCP tools / 143 group tools, zero native dependencies), change `--sqlite-native` to `--sqlite` in the args array. See the [Backend Options](#backend-options) table for feature differences.
⁠3. Restart & Query!

Restart Cursor or your MCP client and start querying SQLite databases!

⁠Prerequisites
  • ✅ Docker installed and running
  • ✅ ~200MB disk space available

⁠🎛️ Tool Filtering

Important

**AI-enabled IDEs like Cursor have tool limits.** With 170+ tools in the native backend, you must use tool filtering to stay within limits. Use **shortcuts** or specify **groups** to enable only what you need.

The Quick Start above uses Code Mode (--tool-filter codemode) — the recommended default. If you prefer individual tool calls instead:

⁠Starter (core + json + text)

starter provides Core + JSON + Text:

{
  "args": ["--tool-filter", "starter"]
}
⁠Custom Groups

Specify exactly the groups you need:

{
  "args": ["--tool-filter", "core,json,stats"]
}
⁠Shortcuts (Predefined Bundles)
ShortcutWASMNative+ Built-inWhat's Included
starter6570+4Core, JSON, Text
analytics6773+4Core, JSON, Stats
search5156+4Core, Text, Vector
spatial4047+4Core, Geo, Vector
dev-schema4141+4Core, Introspection, Migration
minimal2525+4Core only
full143170+4Everything enabled
⁠Tool Groups (10 Available)

10 granular tool groups (e.g., core, json, text, stats, vector, admin) let you precisely control exposed capabilities. For advanced syntax (whitelisting individual tools, additive + and subtractive - filters) and the complete tool group list, refer to the GitHub Repository⁠.

⁠🛡️ Supply Chain Security

For enhanced security, use SHA-pinned multi-arch manifests (docker pull writenotenow/db-mcp:sha256-<digest>). Our images feature cryptographic build provenance, SBOMs, non-root execution, and zero critical/high CVEs (Docker Scout scanned). Find exact tags on Docker Hub⁠.

⁠📁 Resources & Prompts

db-mcp exposes 22 resources (including dynamic sqlite://help documentation) and 10 AI-powered prompts (for schema exploration, query building, data analysis, optimization, and migration). See the GitHub README⁠ for the complete list.

⁠SQLite Extensions

The Docker image includes FTS5, JSON1, and R-Tree built-in. Enable loadable extensions via CLI flags:

ExtensionPurposeToolsCLI FlagNotes
CSVCSV virtual tables2--csvRequires CSV_EXTENSION_PATH env var
SpatiaLiteAdvanced GIS7--spatialitePre-installed (AMD64 only)

⁠🔧 Configuration

⁠Environment Variables
VariableDefaultDescription
MCP_HOST127.0.0.1Host/IP to bind to (0.0.0.0 in Docker) (--server-host)
SQLITE_DATABASE—SQLite database path (--sqlite / --sqlite-native)
DB_ENCRYPTION_KEY—SQLCipher encryption key (Native only) (--encryption-key)
DB_MCP_TOOL_FILTER—Tool filter string (--tool-filter)
METRICS_EXPORT—Export metrics at HTTP /metrics (e.g., prometheus) (--metrics-export)
OAUTH_ENABLEDfalseEnable OAuth 2.1 (--oauth-enabled)
OAUTH_ISSUER—Authorization server URL (--oauth-issuer)
OAUTH_AUDIENCE—Expected token audience (--oauth-audience)
OAUTH_JWKS_URI—JWKS URI, auto-discovered if omitted (--oauth-jwks-uri)
OAUTH_CLOCK_TOLERANCE60Clock tolerance in seconds (--oauth-clock-tolerance)
MCP_ENABLE_HSTSfalseEnable HSTS header (--enable-hsts)
NO_AUTH_ENFORCEMENTfalseExplicitly bypass auth enforcement for HTTP (--no-auth-enforcement)
ALLOWED_IO_ROOTS—JSON array or comma-separated list of absolute paths allowed for IO operations
LOG_LEVELinfoLog verbosity: debug, info, warning, error
METADATA_CACHE_TTL_MS5000Schema cache TTL in ms (auto-invalidated on DDL)
CODEMODE_ISOLATIONisolateCode Mode sandbox: isolate (isolated-vm native) or worker
CODE_MODE_MAX_RESULT_SIZE102400Max Code Mode result payload in bytes (default 100KB, cap 50MB)
MCP_RATE_LIMIT_MAX100Max requests/minute per IP (HTTP transport)
CSV_EXTENSION_PATH—Path to CSV extension binary (native only)
SPATIALITE_PATH—Path to SpatiaLite extension binary (native only)
MCP_AUTH_TOKEN—Simple bearer token for HTTP auth (--auth-token)
AUDIT_LOG—Audit log file path, or stderr (--audit-log)
AUDIT_REDACTtrueRedact tool arguments from audit entries (--audit-no-redact to disable)
AUDIT_READSfalseAlso log read-scoped tool invocations (--audit-reads)
AUDIT_BACKUPfalseEnable pre-mutation DDL snapshots (--audit-backup)
AUDIT_BACKUP_DATAfalseInclude sample data rows in snapshots (--audit-backup-data)
⁠HTTP/SSE Transport

For remote access or web-based clients:

docker run --rm -p 3000:3000 \
  -v ./data:/app/data \
  writenotenow/db-mcp:latest \
  --transport http --port 3000 --server-host 0.0.0.0 --sqlite-native /app/data/database.db --allowed-io-roots /app/data

Important

Use `--server-host 0.0.0.0` to bind to all interfaces. Without this, the server may only listen on `localhost` inside the container. Add `--stateless` for serverless deployments (disables SSE and progress notifications).

Endpoints:

EndpointDescriptionMode
POST /mcpJSON-RPC requests (initialize, tools/call, etc.)Both
GET /mcpSSE stream for server-to-client notificationsStateful
DELETE /mcpSession terminationStateful
GET /sseLegacy SSE connection (MCP 2024-11-05)Stateful
POST /messagesLegacy SSE message endpointStateful
GET /healthHealth check (always public)Both
GET /Server info and available endpointsBoth

Security: 7 security headers, server timeouts (slowloris protection), rate limiting (100/min, 429 + Retry-After), CORS deny-all default (explicit corsOrigins config required), trust proxy (trustedProxyIps), body size limit (--max-body-bytes, default 1MB), opt-in HSTS, cross-protocol session guard.

⁠🔐 Authentication

Full OAuth 2.1 with RFC 9728/8414 compliance:

docker run --rm -p 3000:3000 \
  -v ./data:/app/data \
  writenotenow/db-mcp:latest \
  --transport http --port 3000 --server-host 0.0.0.0 \
  --oauth-enabled --oauth-issuer http://keycloak:8080/realms/db-mcp --oauth-audience db-mcp-server \
  --sqlite-native /app/data/database.db \
  --allowed-io-roots /app/data

Scopes: full, read, write, admin, db:{name}, table:{db}:{table}. See Keycloak Setup⁠ for provider configuration.

Audit identity: When OAuth is enabled with audit logging (--audit-log), write/admin audit entries capture the authenticated user (claims.sub) and granted scopes.

⁠🔐 Encryption at Rest (Native Only)

db-mcp supports transparent database encryption using SQLCipher via the --encryption-key CLI flag or DB_ENCRYPTION_KEY environment variable.

For advanced configuration (raw hex keys vs passphrases, dual-backend audit log encryption rules, and migration steps), please see the full Security Documentation⁠.

⁠📦 Image Details

PlatformFeatures
AMD64 (x86_64)Full: 170 tools, native, SpatiaLite
ARM64 (Apple Silicon)Full: 170 tools, native

Node.js 24 on Alpine Linux • Multi-stage build • Non-root user • better-sqlite3 native

Available Tags:

  • v5.0.1 - Specific version (recommended for production)
  • latest - Always the newest version
  • sha-<commit> - Git commit pinned

⁠📚 Documentation & Resources

⁠📄 License

MIT License - See LICENSE⁠

Tag summary

Content type

Image

Digest

sha256:e7d5ec7e3…

Size

113.8 MB

Last updated

4 months ago

docker pull writenotenow/db-mcp