Skip to content

Add JSON and SARIF output for lint and diff - #30

Merged
ShmueLior merged 4 commits into
mainfrom
feat/json-sarif-output
Dec 4, 2026
Merged

ShmueLior merged 4 commits into
mainfrom
feat/json-sarif-output

Conversation

@ShmueLior

Copy link
Copy Markdown
Owner

Add JSON and SARIF output for lint and diff

mcpprobe lint and mcpprobe diff can now write machine-readable output. --format json prints the McpProbe report format, and --format sarif prints SARIF 2.1.0, for example for GitHub code scanning. The default is still --format text, so existing scripts and the Action get the same stdout as before.

--sarif <file> works like --report: it writes a SARIF file and leaves stdout and the exit code alone. You can use it together with --format and --report.

mcpprobe lint --stdio "dotnet run --project src/MyServer" --format json
mcpprobe diff --stdio "dotnet run --project src/MyServer" --baseline mcp-tools.json --sarif mcp-diff.sarif

JSON

One document per run, format version 1, described in docs/mcpprobe-report.schema.json. It has kind (lint or diff), the McpProbe version, result (pass or fail, same as exit 0 or 1), a summary with counts, and the findings or changes. Diff changes for title and description also have before and after. There are no timestamps, so the output is stable between runs.

With --format json or --format sarif, stdout is exactly one document. The diff hint ("If the change is intended...") and the lint --write-baseline line ("Wrote N finding(s)...") go to stderr instead. Exit codes don't change, and on exit 2 (usage or connection error) nothing is written to stdout or to the --sarif file.

SARIF

  • Lint rules keep their MCPP0xx ids. Diff change kinds use kebab-case ids like tool-removed or description-changed.
  • Levels: lint error is error, warning is warning, info is note. Diff breaking is error, non-breaking is note.
  • Each result points at a file, because GitHub doesn't show results without one. diff uses --baseline, lint uses --from-file, relative to the working directory. If the path is outside it, only the file name is used. When lint checks a live server, the default is mcp-tools.json. Run lint and diff from the repo root so those artifact paths are relative to the repository root (GitHub resolves them from there).
  • Each result has a partialFingerprints.primaryLocationLineHash from the rule id, tool and path, so the same alert is matched across runs. If several results share the same rule, tool and path, they get :1, :2 and so on.

One thing to know about GitHub: PR annotations only show up for alerts whose file lines changed in that PR. Other findings still appear in the code scanning alerts list. The README says this. Uploading SARIF from the Action is left for a follow-up.

Library

LintReport.ToJson(), LintReport.ToSarif(artifactUri), ToolSurfaceDiff.ToJson(failOnNonBreakingChanges) and ToolSurfaceDiff.ToSarif(artifactUri).

Tests

Golden files for lint and diff in JSON and SARIF, schema validation against the report schema and the SARIF 2.1.0 schema, CLI tests for the new flags (stdout vs stderr, exit codes, no files on exit 2, --write-baseline, artifact paths), hostile text, and non-invariant culture.

lint and diff take --format text|json|sarif for stdout, and --sarif <file> writes a SARIF 2.1.0 file like --report. The library gets LintReport.ToJson/ToSarif and ToolSurfaceDiff.ToJson/ToSarif. The JSON report format (1) is described in docs/mcpprobe-report.schema.json. SARIF results point at the baseline or --from-file snapshot (default mcp-tools.json) and carry a stable fingerprint for GitHub code scanning.
A diff can report several changes with the same change kind, tool and path, for example allowed values removed and added on one parameter, or two constraints on one parameter. Those results got the same primaryLocationLineHash. Repeats now get :2, :3 and so on in order of appearance, the way GitHub numbers identical fingerprints. Also loads test schemas under a lock with a private registry, and compares goldens from the source tree so MCPPROBE_UPDATE_GOLDENS=1 works in the same run.
GitHub resolves those URIs from the repository root, so lint and diff should both be run from there.
@ShmueLior
ShmueLior merged commit c4485b3 into main Dec 4, 2026
3 checks passed
@ShmueLior
ShmueLior deleted the feat/json-sarif-output branch December 4, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant