
db-insight
β 1from EnclaveX-Labs
connect a read-only replica, analytics database, or staging database. Keep credentials on your machine while the tool discovers schema, generates safe SQL, previews it for approval, runs the query, and summarizes the result.
db-insight
Local-first SQL insight CLI and MCP server for Postgres and SQLite.
Positioning: connect a read-only replica, analytics database, or staging database. Keep credentials on your machine while the tool discovers schema, generates safe SQL, previews it for approval, runs the query, and summarizes the result.
Configure
Create .env:
Postgres:
DATABASE_URL=postgresql://readonly:password@localhost:5432/app_db
DB_INSIGHT_MODEL=gemma3:latest
DB_INSIGHT_OLLAMA_URL=http://localhost:11434SQLite:
DATABASE_URL=sqlite:///absolute/path/to/app.sqlite
DB_INSIGHT_MODEL=gemma3:latest
DB_INSIGHT_OLLAMA_URL=http://localhost:11434If your provider gives a URL with special characters, wrap it in quotes:
DATABASE_URL="postgresql://readonly:password@host.example.com:5432/app_db"DB_INSIGHT_MODEL is configurable so you can use the best Gemma/Ollama tag available on
your machine.
CLI
db-insight connect
db-insight schema --refresh
db-insight ask "Why did revenue drop last week?"By default, ask uses the same MCP-style flow as the server:
user question
β LLM plans tool calls
β discover_schema / schema memory
β generate_safe_sql
β preview SQL for approval
β run_approved_sql
β summarize_resultsThe user-facing CLI previews generated SQL and asks before running it.
db-insight schema --refresh stores a local schema memory snapshot in
.db-insight/schema_memory.json. Later questions reuse that schema picture so the model
does not need to rediscover the same database structure every time. The memory contains
metadata only, not table rows.
MCP stdio server
For Android health-ring chat architecture, see Android Health Chat Implementation.
db-insight mcpThis exposes safe local tools over stdio for MCP clients:
plan_tool_callsdiscover_schemarefresh_schema_memoryschema_memory_statuscatalog_overviewinspect_tableexplain_sqlgenerate_safe_sqlrun_approved_sqlask_database
In a full MCP client, the LLM decides which tools to call. ask_database is a
convenience tool that performs that decision loop inside this local server while
still requiring explicit approval before execution.
Remote MCP server
For team use, run the same server over HTTP:
DB_INSIGHT_MCP_HOST=0.0.0.0 \
DB_INSIGHT_MCP_PORT=8000 \
db-insight mcp --transport streamable-httpThe HTTP MCP endpoint is:
http://your-host:8000/mcpPut it behind your existing auth layer, VPN, or private network. Do not expose a database-backed MCP server directly to the public internet.
Docker
Build the image:
docker build -t db-insight:latest .Or use the published image:
docker pull ghcr.io/enclavex-labs/db-insight:latestInstall Gemma on the host Docker server:
ollama pull gemma3:latestConfigure your MCP client to launch the container over stdio.
Postgres:
{
"mcpServers": {
"db-insight": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--add-host=host.docker.internal:host-gateway",
"-e",
"DATABASE_URL",
"-e",
"DB_INSIGHT_MODEL",
"-e",
"DB_INSIGHT_OLLAMA_URL",
"ghcr.io/enclavex-labs/db-insight:latest"
],
"env": {
"DATABASE_URL": "postgresql://readonly:password@host.docker.internal:5432/app_db",
"DB_INSIGHT_MODEL": "gemma3:latest",
"DB_INSIGHT_OLLAMA_URL": "http://host.docker.internal:11434"
}
}
}
}SQLite:
{
"mcpServers": {
"db-insight": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--add-host=host.docker.internal:host-gateway",
"-v",
"/absolute/path/to/data:/data:ro",
"-e",
"DATABASE_URL",
"-e",
"DB_INSIGHT_MODEL",
"-e",
"DB_INSIGHT_OLLAMA_URL",
"ghcr.io/enclavex-labs/db-insight:latest"
],
"env": {
"DATABASE_URL": "sqlite:////data/app.sqlite",
"DB_INSIGHT_MODEL": "gemma3:latest",
"DB_INSIGHT_OLLAMA_URL": "http://host.docker.internal:11434"
}
}
}
}For VS Code/Copilot, use the same body under servers instead of mcpServers.
Each user fills DATABASE_URL with their own Postgres connection string or SQLite
file URL. For SQLite in Docker, mount the folder containing the database to /data
and use four slashes: sqlite:////data/app.sqlite.
For Postgres, if DATABASE_URL uses localhost or 127.0.0.1, the Docker image
remaps it to host.docker.internal automatically.
If you need a long-running shared HTTP endpoint instead, run:
docker run --rm -p 8000:8000 \
--add-host=host.docker.internal:host-gateway \
-e DATABASE_URL=postgresql://readonly:password@host.docker.internal:5432/app_db \
-e DB_INSIGHT_OLLAMA_URL=http://host.docker.internal:11434 \
ghcr.io/enclavex-labs/db-insight:latest db-insight mcp --transport streamable-httppython -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"Before it works, you'll need: DATABASE_URLDB_INSIGHT_MODELDB_INSIGHT_OLLAMA_URL
Install
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"No common issues documented yet. If you hit a problem, the repository's GitHub Issues page is the best place to look.