get_health
Code-health scores and marker findings per file across three signals (defect risk, maintainability, performance), exposed to your agent so it can self-check a change before opening a PR.
get_health gives your agent the Code Health
layer directly: a 1 to 10 score per file across three signals (defect risk,
maintainability, performance), the marker findings behind it, repo-level
KPIs, refactoring targets, and trend alerts. Zero LLM calls; it reads
precomputed metrics.
When to call
- Self-check before a PR. Read the same signals a code-health merge-gate judges the change on. Pass the files you touched and confirm you are not regressing the worst files.
- Before a refactor. Find the lowest-scoring files and the specific markers dragging them down.
- Triage. Dashboard mode returns the repo's worst files ranked, plus the "does the score find the bugs?" stat so the agent knows the score is trustworthy on this repo before acting on it.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
targets | string[] | — | File paths, or a "module:foo" target that expands to the module's file set. Empty -> dashboard mode (repo KPIs + lowest-scoring files). |
include | string[] | — | Opt-in blocks (the default response stays lean): "biomarkers" (findings in dashboard mode), "refactoring" (structured, graph-aware refactoring plans (Extract Class / Extract Helper / Move Method / Break Cycle) ranked per finding), "trend" (snapshot diff + alerts), "coverage", "accuracy" (does-the-score-find-the-bugs stat, dashboard mode), "signals" (per-file process/people/topology, targeted mode), "churn_complexity" (churn × complexity points, dashboard mode), and a dimension name ("performance" / "defect" / "maintainability") to filter findings to that pillar. |
only | string[] | — | Keep just these top-level keys. include adds blocks, only subtracts them. mode, _meta, unresolved, known_modules, and each kept list's *_total sibling always survive. The include block names work as aliases: biomarkers -> findings, accuracy -> defect_accuracy, refactoring -> refactoring_plans. |
repo | string | — | Repository alias. Usually omitted. |
limit | number | 20 | Max rows in every ranked list (capped at 50). 0 means no rows; the *_total siblings still report the true counts. |
Returns
Dashboard mode (no targets) leads with a directive, then repo-level KPIs:
| Field | Meaning |
|---|---|
directive | The single file to fix first, its dominant finding, recovers_points / share_of_repo_gap_pct, and then (the next two by leverage). Read this first; rank by weighted_deficit, not score |
kpis.average_health | NLOC-weighted average over all files |
kpis.average_health_unweighted | The plain file mean, for comparison against the NLOC-weighted headline |
kpis.maintainability_average / kpis.performance_average | The maintainability and performance pillar headlines (null until measured) |
kpis.worst_performer_path / kpis.worst_performer_score | Single lowest-scoring file and its score |
gap_analysis | Net weighted points the average must recover to reach the Healthy floor (8.0), how many files sit below it, and files_to_reach_target / files_for_half_gap |
high_leverage_files | Top files ranked by weighted_deficit (score gap x NLOC), distinct from worst_files, which sorts by raw score alone |
worst_files | Ranked worst files by raw score |
modules | Per-module NLOC-weighted health rollup, worst-first, capped by limit; modules_total is the uncapped count |
unresolved | Any targets entry that matched nothing, with a reason (not_indexed, no_such_path, excluded, no_such_module) |
There is no kpis.hotspot_health on the dashboard KPIs; the hotspot-only
NLOC-weighted average only exists inside the opt-in trend block, as
current_hotspot_health / previous_hotspot_health (see below).
Targeted mode (targets given) returns mode, targets, metrics
(one row per file: file_path, score, maintainability_score,
performance_score, weighted_deficit, complexity/coverage stats, and
the dominant-finding lead), metrics_total, findings (type, severity,
line span, reason, and a dimension), and findings_total. Depending on
what matched, it also carries unresolved, known_modules (after an
unresolved module: target), trends (per-file score history, silent
when a file has fewer than 2 snapshots), and modules (when the target
list includes a module: target). There is no per-file "score breakdown
by category" field, and no defect_score field: it was set from the same
value as score on every row, so score is the one to read. The field to
rank files on is neither score nor maintainability_score /
performance_score, but weighted_deficit.
Opt-in enrichments
biomarkersreturns the full (uncapped) findings set in dashboard mode. Pair with a dimension name, e.g.include=["biomarkers", "performance"], to narrow to one pillar.trendadds atrendblock:current_hotspot_health/previous_hotspot_health(the NLOC-weighted average over hotspot files only),current_average_health/previous_average_health,hotspot_delta,average_delta,alerts, andrecent(up to 10 past snapshots).accuracyadds adefect_accuracyblock: of the K least-healthy files, how many were recently bug-fixed vs the repo-wide base rate (precision@K +lift), with a per-K table and the flagged files.nullon repos with too little history to be honest.signalsadds asignalsobject on each targeted metric: prior-defect count, change scatter, 90-day churn, primary / recent owner, and graph in / out degree. Honestnullper field when the underlying row is absent.churn_complexityaddschurn_complexitypoints (one per recently-changed file: 90-day commits, max CCN, NLOC, score, churn percentile).- dimension filter narrows findings to one pillar; pair with
"biomarkers"for the full set, e.g.include=["biomarkers", "performance"].
Example
get_health(only=["directive"]) # cheapest useful call: what to fix first
get_health() # directive, kpis, gap_analysis, worst + high-leverage files
get_health(include=["accuracy", "churn_complexity"]) # is the score trustworthy + danger zone
get_health(include=["biomarkers", "performance"]) # only performance-pillar findings
get_health(targets=["src/api/server.py"], include=["signals"]) # self-check one file
get_health(targets=["module:src.api"], include=["trend", "refactoring"])Things worth knowing
- Deterministic and offline. The markers run off tree-sitter + git data with calibrated weights: no model calls, reproducible scores.
- Three signals, never blended.
scoreis the defect-calibrated headline; maintainability and performance are co-equal companion views with their own per-file scores anddimension-tagged findings. - Coverage is opt-in. The coverage markers
(
untested_hotspot,coverage_gap,coverage_gradient) only fire once you've ingested a report viarepowise coverage add. - Module targets (
module:foo) expand to every file under the module, so one call covers a whole package. - Refactoring plans carry an id.
include=["refactoring"]returns each plan with asuggestion_id. Pass that id togenerate_refactoring_codeto get refactored code and a unified diff for that one plan.
For the full marker reference, the three-signal model, the
defect-prediction benchmark, and the head-to-head against the leading
commercial tool, see the
Code Health layer page. For the structured
plans behind include=["refactoring"], see
Refactoring intelligence.
get_dead_code
Tiered refactor plan for unused code. High/medium/low confidence findings with per-directory rollups, ownership hotspots, and safe-to-delete impact estimates. Pure graph + SQL, no LLM calls.
list_repos
Lists the repos this MCP server can reach, and their aliases. On by default in both single-repo and workspace mode; one of the tools that takes no parameters.