querydig

v0.10.0
io.github.milankatira/querydig Checked 5 hours ago Published 1 day ago

Find, 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.

ParameterTypeDescription
dbstringMongoDB database name when the URI has none.
diffstringOnly scan files changed since this git ref, e.g. "origin/main".
filesarrayOnly scan these files (relative to path). Use to verify a fix.
includeTestsbooleanAlso scan tests, fixtures, migrations and seeds.
maxFindingsintegerMaximum findings returned (default 50).
minSeveritystringHide findings below this severity.
pathstringProject root to scan. Defaults to the directory the MCP server was started in.
rulesarrayOnly report these rule ids, e.g. ["QD001","QD002"].
uristringRead-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).

ParameterTypeDescription
file *stringFile relative to the project root, as reported in a finding location.
line *integer1-based line of the finding.
contextLinesintegerLines of context above and below (default 25).
pathstringProject 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.

ParameterTypeDescription
code *stringSource code to analyze.
filename *stringA 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).

ParameterTypeDescription
rule *stringRule 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.

ParameterTypeDescription
dryRunbooleanShow changes without writing (default true).
filesarrayOnly fix these files.
pathstringProject 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.

ParameterTypeDescription
dbstringMongoDB database name when the URI has none.
pathstringProject root to scan. Defaults to the directory the MCP server was started in.
uristringRead-only connection string. Prefer QUERYDIG_DB_URI in the server env.