Skip to content

Commit 6296329

Browse files
committed
fix(cli): gate MCP registry findings
Signed-off-by: Narendran Raghavan <[email protected]>
1 parent 7d78dc7 commit 6296329

3 files changed

Lines changed: 64 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,11 +655,11 @@ SkillSpector is built to be driven by other tools (CI pipelines, install gates,
655655

656656
| Code | Meaning |
657657
|------|---------|
658-
| `0` | Scan completed, `risk_score` ≤ 50 (recommendation `SAFE` or `CAUTION`) |
659-
| `1` | Scan completed, `risk_score` > 50 (recommendation `DO_NOT_INSTALL`) |
658+
| `0` | Scan completed, `risk_score` ≤ 50 (recommendation `SAFE` or `CAUTION`), and no enabled strict gate fired |
659+
| `1` | Scan completed and either `risk_score` > 50, `--fail-on-findings` found an active finding, or `--fail-on-incomplete` found partial/incomplete analysis |
660660
| `2` | Error (bad input, unreadable source, internal failure) |
661661

662-
> The exit code collapses `SAFE` and `CAUTION` into `0`. To act differently on them (e.g. *warn* on `CAUTION` but *block* on `DO_NOT_INSTALL`), read the `recommendation` field from the JSON output rather than relying on the exit code.
662+
> By default, the exit code collapses `SAFE` and `CAUTION` into `0`. Use `--fail-on-findings` to gate on any active finding, `--fail-on-incomplete` to gate on incomplete coverage, or read the JSON `recommendation` field for custom policy.
663663
664664
### Machine-readable output
665665

‎src/skillspector/cli.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ def scan(
578578
console.print(f"Report saved to: {output}")
579579
else:
580580
print(report)
581+
if fail_on_findings and result["findings"]:
582+
raise typer.Exit(code=1)
581583
if result["risk_score"] > RISK_THRESHOLD:
582584
raise typer.Exit(code=1)
583585
except typer.Exit:

‎tests/unit/test_cli.py‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,65 @@ def test_cli_mcp_registry_exits_1_when_aggregate_risk_crosses_threshold(tmp_path
520520
assert json.loads(result.output)["risk_score"] == 95
521521

522522

523+
def test_cli_mcp_registry_fail_on_findings_exits_1_below_risk_threshold(
524+
tmp_path: Path,
525+
) -> None:
526+
payload = tmp_path / "registry.json"
527+
payload.write_text(
528+
json.dumps(
529+
{
530+
"servers": [
531+
{
532+
"server": {
533+
"name": "mutable/example",
534+
"repository": {
535+
"url": "https://github.com/example/project",
536+
"source": "github",
537+
},
538+
"packages": [
539+
{
540+
"registryType": "npm",
541+
"identifier": "example",
542+
"version": "latest",
543+
"fileSha256": "a" * 64,
544+
"transport": {"type": "stdio"},
545+
}
546+
],
547+
"remotes": [
548+
{
549+
"type": "streamable-http",
550+
"url": "https://example.invalid/mcp",
551+
}
552+
],
553+
},
554+
"_meta": {
555+
"io.modelcontextprotocol.registry/official": {"status": "active"}
556+
},
557+
}
558+
]
559+
}
560+
),
561+
encoding="utf-8",
562+
)
563+
564+
result = runner.invoke(
565+
app,
566+
[
567+
"scan",
568+
str(payload),
569+
"--mcp-registry",
570+
"--format",
571+
"json",
572+
"--fail-on-findings",
573+
],
574+
)
575+
576+
assert result.exit_code == 1
577+
report = json.loads(result.output)
578+
assert report["risk_score"] == 30
579+
assert [finding["id"] for finding in report["findings"]] == ["MCP-PACKAGE-VERSION"]
580+
581+
523582
@pytest.mark.parametrize(
524583
"args", [[], ["--format", "terminal"], ["--format", "markdown"], ["--format", "sarif"]]
525584
)

0 commit comments

Comments
 (0)