Skip to main content
Glama

Check changed C/C++ lines for coding-standard violations

check_diff
Read-onlyIdempotent

Run static analysis on added or modified C/C++ lines in a git diff or pasted patch for pull-request and pre-commit review, with findings mapped to SEI CERT, MISRA, or AUTOSAR.

Instructions

Run the check_files analyzers on the C/C++ files of a change and keep only findings on added or modified lines, mapped to the same standards (standards or the profile; SEI CERT by default). The change is base..head in the git repo at repo, base against the working tree when head is omitted, or a pasted unified diff (diff_text, paths relative to repo). Use for pull-request or pre-commit review; for whole files use check_files. Runs git diff and the analyzers locally; writes nothing. For git refs, files must exist at head or line numbers will not match. With diff_text, files are reconstructed in a private temporary tree (the repo on disk is never modified). Check tools[].status and warnings before trusting an empty result. baseline_path hides findings recorded in a baseline file (fixed is not computed in diff scope).

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "repo": "<repo>"
    },
    "name": "check_diff"
  }
}

Input Schema

NameRequiredDescriptionDefault
baseNoBase git ref (branch, tag or SHA). Required unless diff_text is given.
headNoHead git ref. Omit to compare base with the working tree (uncommitted changes included).
repoYesAbsolute path of the git checkout; diff paths are resolved against it.
toolsNoAnalyzers to run; omit for the default set: clang-tidy, clangsa and cppcheck plus semgrep and infer when installed. clang-tidy = cert-*/bugprone checks plus Clang Static Analyzer checks; clangsa = standalone `clang --analyze` (adds alpha checkers); cppcheck = cppcheck; semgrep = the bundled CERT pattern rules; infer = Infer (null, leak, use-after-free, overflow, race); codeql = the CodeQL CERT query packs, opt-in because each run builds a database (tens of seconds or more). A requested analyzer that is not installed is skipped and listed in `warnings`.
compdbNoAbsolute path of the directory that contains compile_commands.json. Strongly recommended: without it files are compiled with guessed flags and often fail to parse. Omitted: auto-detected in root, root/build or root/build-clang.
profileNoReview profile: 'default' (plain SEI CERT), 'ceph' (Ceph severities, suppressions and idioms), 'misra' (MISRA C:2012 + MISRA C++:2023), 'autosar' (AUTOSAR C++14) or an absolute path to a profile .yaml file.default
diff_textNoUnified diff text (git diff format, a/ b/ prefixes allowed). Overrides base and head.
standardsNoStandards to map findings to, overriding the profile's `standards` (default profile: cert). misra-c-2012 applies to .c files (adds the cppcheck MISRA addon); misra-cpp-2023 and autosar-cpp14 to C++ files. Example: ["cert", "misra"].
diff_contextNoAlso report findings within this many lines of a changed line (confidence scaled by 0.85).
baseline_pathNoAbsolute path of a baseline JSON written by `cert-review baseline create`. Findings recorded there are left out and counted in `baseline`; file paths in it are relative to its directory. Matching uses rule, file and hashes of the code line and its neighbours, so line shifts do not resurface old findings. Omit to report everything.
min_confidenceNoDrop findings below this confidence. Rule-specific checkers score 0.9, general checkers 0.3-0.65, +0.1 when two tools agree. 0.5 keeps most real hits.
include_suppressedNoAlso return findings hidden by the profile or by `// cert-review: ignore <RULE>` comments, each with its suppression reason (for audits).

Output Schema

NameRequiredDescriptionDefault
rootYesAbsolute repository root used to resolve diff paths.
filesYesFiles analysed (absolute paths).
notesYesEngine notes, e.g. 'no C/C++ files selected'.
toolsYesPer analyzer: tool, available, version, files, raw_findings, parse_errors, files_with_errors[], timed_out[], notes[], status ('ok' | 'partial' = some files did not compile or timed out | 'missing').
profileYesProfile used.
summaryYestotal, by_severity {error, warning, note}, top_rules [[rule_id, count], ...]. Counts only findings left after the baseline filter.
baselineNoPresent only with baseline_path: path, entries (in the file), new (findings returned), baselined (findings hidden because they match an entry), fixed (entries in analysed files with no matching finding; null for check_diff, which sees only changed lines), fixed_entries[] (up to 50 {rule_id, file, line, message}) and note.
findingsYesSorted by severity, priority, confidence. Each also has lang, col, priority, level, tool, checker, title, cert_severity, also_found_by[], note, url.
warningsYesOne line per analyzer that could not fully analyse its input (compile errors or timeouts); non-empty means the result is incomplete.
changed_filesYesEvery file in the diff, relative to root, including non-C/C++ files that were skipped.
suppressed_countYesFindings hidden by the profile or inline ignores.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.4.1

TDQS

A4.4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnly, non-destructive, idempotent and closed-world, so the safety profile is covered. The description still adds real context beyond that: local git diff plus analyzer execution, diff_text reconstructed in a private temp tree with the repo untouched, the requirement that files exist at head for line numbers to match, and the caveat to inspect tools[].status and warnings before trusting an empty result.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

It is a single dense paragraph but front-loads the core purpose and the sibling alternative before the mode and caveat details. Nearly every sentence carries information, though 'writes nothing' is partly redundant with the readOnly/destructive annotations and the paragraph is long for one block.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 12-parameter tool with an output schema and full schema coverage, the description covers the essential gotchas: mode selection, local execution, temp-tree isolation, head-ref existence, baseline suppression, and the warnings/status trust check. Nothing an agent needs to call it correctly is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% and every parameter already carries a detailed description, including diff_text overriding base and head. The description's summary of the base/head/diff_text relationship largely restates the schema, so the baseline 3 applies despite it being a useful synthesis.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource: it runs the check_files analyzers on C/C++ files of a change and keeps only findings on added or modified lines. It explicitly contrasts with the sibling 'check_files' for whole-file review, so an agent can pick between the two without opening a schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives explicit when-to-use ('pull-request or pre-commit review') and when-not ('for whole files use check_files'). It also enumerates the three input modes (base..head, base against working tree, pasted diff_text) so the agent knows which parameters select which path.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.