Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ mcp-audit discovers the nearest one walking up from the working directory.
| `disabledRules` | Rule ids to skip entirely. |
| `enabledRules` | If set, run **only** these rule ids. |
| `severityOverrides` | Remap a rule's severity, e.g. downgrade a noisy check. |
| `ignore` | Substrings matched against a finding's location to suppress it. |
| `ignore` | Substrings matched against a finding's location or rule id to suppress it. |

Severities, lowest to highest: `info`, `low`, `medium`, `high`, `critical`.

Expand Down
7 changes: 5 additions & 2 deletions src/audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import { ALL_RULES } from "./rules/index.js";
import type { AuditTarget, Finding, Rule, Severity } from "./types.js";
import type { McpAuditConfig } from "./config.js";

/** Remove findings whose location matches any ignore substring. */
/** Remove findings whose location or rule id matches any ignore substring. */
export function applyIgnores(
findings: Finding[],
ignore: string[],
): Finding[] {
if (ignore.length === 0) return findings;
return findings.filter((f) => {
const loc = f.location ?? "";
return !ignore.some((pattern) => loc.includes(pattern));
const id = f.ruleId;
return !ignore.some(
(pattern) => loc.includes(pattern) || id.includes(pattern),
);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface McpAuditConfig {
severityOverrides: Record<string, Severity>;
/** Findings at or above this severity cause a non-zero exit. */
failOn: Severity;
/** Location globs/substrings to ignore in findings. */
/** Location or rule-id substrings to ignore in findings. */
ignore: string[];
}

Expand Down
48 changes: 48 additions & 0 deletions test/audit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, it, expect } from "vitest";
import { applyIgnores, runAudit } from "../src/audit.js";
import { normalizeConfig } from "../src/config.js";
import { ALL_RULES } from "../src/rules/index.js";
import { normalize } from "../src/static/manifest.js";
import { insecureSurface } from "../fixtures/surfaces.mjs";
import type { Finding } from "../src/types.js";

describe("applyIgnores", () => {
const sample: Finding[] = [
{
ruleId: "MCP001",
severity: "high",
title: "Destructive tool",
message: "no confirm",
remediation: "add confirm",
location: "delete_file",
},
{
ruleId: "MCP002",
severity: "critical",
title: "Exec",
message: "shell",
remediation: "scope",
location: "run_shell",
},
];

it("suppresses findings when ignore matches location", () => {
const filtered = applyIgnores(sample, ["delete_file"]);
expect(filtered.map((f) => f.ruleId)).toEqual(["MCP002"]);
});

it("suppresses findings when ignore matches rule id", () => {
const filtered = applyIgnores(sample, ["MCP001"]);
expect(filtered.map((f) => f.ruleId)).toEqual(["MCP002"]);
});
});

describe("runAudit ignore by rule id", () => {
it("suppresses MCP001 findings when ignore lists the rule id", () => {
const target = normalize(insecureSurface, "insecure");
const config = normalizeConfig({ ignore: ["MCP001"] });
const result = runAudit(target, config, ALL_RULES);
expect(result.findings.some((f) => f.ruleId === "MCP001")).toBe(false);
expect(result.findings.some((f) => f.ruleId === "MCP002")).toBe(true);
});
});
Loading