querydig
v0.10.0Find, fix and verify N+1 and slow MongoDB/SQL queries in JS/TS, Python, Go, Java, Ruby and PHP.
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
scan_queries Scan for slow queries
Statically scan a project for slow, N+1 and unoptimized MongoDB/SQL queries (JS/TS, Python, Go, Java, Ruby, PHP). Returns findings sorted by severity with location, explanation and fix advice. Pass `files` to re-check specific files after editing them. If QUERYDIG_DB_URI is set (or `uri` is given), it also connects read-only to MongoDB/Postgres for live evidence: full scans, missing indexes, slow queries.
| Parameter | Type | Description |
|---|---|---|
db | string | MongoDB database name when the URI has none. |
diff | string | Only scan files changed since this git ref, e.g. "origin/main". |
files | array | Only scan these files (relative to path). Use to verify a fix. |
includeTests | boolean | Also scan tests, fixtures, migrations and seeds. |
maxFindings | integer | Maximum findings returned (default 50). |
minSeverity | string | Hide findings below this severity. |
path | string | Project root to scan. Defaults to the directory the MCP server was started in. |
rules | array | Only report these rule ids, e.g. ["QD001","QD002"]. |
uri | string | Read-only MongoDB/Postgres URI for live evidence. Prefer setting QUERYDIG_DB_URI in the server env so the secret stays out of the chat. |
get_finding_context Get code context for a finding
Return the code around a line (with line numbers), every querydig finding in that file near the line, and the matching rule docs with a before/after example. Use this before rewriting a slow query so the fix fits the surrounding code (variables, loop bounds, ORM in use).
| Parameter | Type | Description |
|---|---|---|
file * | string | File relative to the project root, as reported in a finding location. |
line * | integer | 1-based line of the finding. |
contextLines | integer | Lines of context above and below (default 25). |
path | string | Project root to scan. Defaults to the directory the MCP server was started in. |
analyze_snippet Check a code snippet
Run querydig on code that is not saved yet, e.g. a proposed rewrite, and return any slow query patterns still present. Use it to check an optimized version before writing it to disk.
| Parameter | Type | Description |
|---|---|---|
code * | string | Source code to analyze. |
filename * | string | A file name whose extension picks the language, e.g. "orders.service.ts", "views.py", "repo.go", "UserService.java", "user.rb", "UserController.php". |
explain_rule Explain a rule
Why a querydig rule is slow, how to fix it, and a before/after example. Accepts an id (QD001) or name (n-plus-one).
| Parameter | Type | Description |
|---|---|---|
rule * | string | Rule id or name. |
list_rules List rules
All querydig rules with id, default severity, database and title.
apply_safe_fixes Apply safe automatic fixes
Apply querydig's mechanical, behavior-preserving fixes (.lean() on read-only Mongoose queries, limit 1 on existence counts, Django .exists(), and similar). Defaults to a dry run that only shows the diff; pass dryRun=false to write files. N+1 rewrites, limits and projections are never changed here.
| Parameter | Type | Description |
|---|---|---|
dryRun | boolean | Show changes without writing (default true). |
files | array | Only fix these files. |
path | string | Project root to scan. Defaults to the directory the MCP server was started in. |
suggest_indexes Suggest missing indexes
Connect read-only to MongoDB or Postgres (QUERYDIG_DB_URI or `uri`), explain the queries found in the code, and return a de-duplicated script of indexes that would fix full scans and in-memory sorts. Nothing is created on the database.
| Parameter | Type | Description |
|---|---|---|
db | string | MongoDB database name when the URI has none. |
path | string | Project root to scan. Defaults to the directory the MCP server was started in. |
uri | string | Read-only connection string. Prefer QUERYDIG_DB_URI in the server env. |