@ahmedshaikh/db-query-mcp
v0.1.0
Published
Query SQLite database files as an MCP server — structured rows, table/schema introspection, read-only by default. No more sqlite3 shell escaping.
Maintainers
Readme
db-query
Query SQLite .db files and get structured rows — instead of shelling out to
sqlite3 with awkward escaping and re-parsing tabular text. Read-only by
default for safety.
query({ db_path: "app.db", sql: "SELECT type, count(*) n FROM events WHERE ts > ? GROUP BY type", params: [cutoff] })
→ { columns: ["type", "n"], row_count: 4, rows: [ { type: "click", n: 812 }, … ] }Tools
query(db_path, sql, params?)— structured{ columns, rows, row_count, truncated }. Use?placeholders +params. Writes are blocked unless the server runs withDB_QUERY_WRITE=1.tables(db_path)— every table + its columns (name/type).schema(db_path, table?)— theCREATEDDL.
db_path can be omitted if the server is started with a DB_QUERY_DB default.
Safety
Read-only by default: only SELECT / EXPLAIN / read PRAGMA / WITH …-select
statements run; anything mutating is rejected with a clear message. Set
DB_QUERY_WRITE=1 to allow writes. Rows are capped at 1000 (with truncated flagged).
Setup
npm install # Node 22+ (uses the built-in node:sqlite — no native build)
npm testclaude mcp add db-query -- node /abs/path/db-query/dist/server.js
# CLI: agent-db tables app.db
# agent-db query app.db "SELECT * FROM users LIMIT 5"Honest limits
- SQLite only (it's what
node:sqlitespeaks). - Read-only is enforced by statement inspection, not a sandbox — robust for the
common cases, but
DB_QUERY_WRITE=1is the real boundary if you need writes. - 1000-row cap per query (use
LIMIT/WHEREto scope;truncatedtells you).
