Skip to content

Reference

Architecture

Derived from PRD §11 and §12. Scan is a local Python CLI. Nothing leaves the user’s machine except traffic to the target and to the attacker and judge models the user configures. The hosted tier is out of scope until after validation.

Data flow

scan.yaml ──► CLI ──► authorization check ──► Runner ──► Connector ──► Target (chat API / agent / MCP)
 (target,          (refuses if field     (scenarios ×          │  ▲
  packs, seed,      missing; AC-11)       variants ×           │  │ indirect input (form, doc, email)
  budget)                                 repeats)             ▼  │
                                              │           Canary sink (local HTTP, logs canary hits)
                                              ▼                │
                                         Detectors ◄───────────┘  (canary match, forbidden tool call,
                                              │                    secret pattern, LLM judge last)
                                              ▼
                                         Scorer ──► report.json (canonical) ──► report.html, CI exit code

Components

Component Responsibility Decided by Milestone
CLI scan, demo, list-packs, report. Exit codes: 0 ok, 2 not available, 3 unauthorized, 4 config, 5 target ADR-0001 (Typer) M1 (built)
Config Pydantic v2 from yaml.safe_load, unknown keys rejected; keys only as api_key_env ADR-0007 M1 (built)
Authorization authz.authorize() is the only issuer of AuthorizedTarget; connectors require it; only connectors/ may import network clients ADR-0007 M1 (built)
Secrets Secret wrapper, Redactor (registered values plus credential patterns), RedactingFilter on logs; all CLI output redacted Plan M1 M1 (built)
Seed seed.derive(seed, label) via sha256; per-consumer rng() streams Plan M1 M1 (built)
Scenario format Versioned YAML: goal, turns, injection channel, success conditions, tags, variants ADR-0002 M2
Runner Orders scenarios, manages turns, repeats (default 3), rate limits, backoff, call budget, seeded randomness Proposed: asyncio M1–M2
Variant generator en → hi, hi-Latn, Hinglish templates; misspelling mutator; optional attacker model for drafts ADR-0006 M3
Connectors (plugin) OpenAI-compatible, generic HTTP (request and response mapping), MCP stdio and HTTP, indirect-input channel Proposed: entry-point plugin interface M1, M4
Canary sink stdlib ThreadingHTTPServer on 127.0.0.1, ephemeral port, 204 for everything; records hits on tokens or canary emails Plan M1 M1 (built)
Detectors (plugin) Canary match, forbidden tool call, secret pattern, LLM judge ADR-0003 M2
MCP static checks Hidden instructions, invisible Unicode, over-broad permissions, known vulnerable versions, lethal trifecta Proposed: rules plus a pinned version list M4
Scorer Severity, versioned grade rule (PRD §10), language gap PRD §10 M5b
Reports JSON canonical, HTML rendered from JSON (Jinja), SARIF later ADR-0004 M5a, M5b
Design tokens src/agentkavach/reports/static/tokens.css, the single source docs/design/brief.md M5a
CI GitHub Action wrapping the CLI with a fail threshold Plan M5b M5b
LeadBot Deliberately vulnerable CRM agent: web form plus email tool, canary leads Plan M0 M0, M1

Boundaries and invariants

  • Authorization: one function gates every outbound send to a target. Connectors cannot be called without a validated authorization object (AC-11).
  • Secrets: keys are read from the environment into a redacting wrapper. The report and log writers run a final redaction pass (AC-12).
  • Determinism: one seed per run; every source of randomness comes from it. Model name, version and temperature are recorded (AC-13).
  • Untrusted input: target responses, MCP tool descriptions and community packs are data. They are never executed or rendered as HTML without escaping. See threat-model.md.
  • Canary sink binds to localhost only, and canary values are random per run.

What is built (as of M5)

scan runs scenarios x languages x repeats against one authorized target and writes results.json, then report.json and a self-contained report.html. mcp-scan inspects MCP servers statically. demo scans LeadBot offline. report re-renders from a results file. --fail-on-severity and --fail-on-grade exit 6 for CI (action.yml). Grading is ADR-0009; canary salt is ADR-0008.

Added since: target applicability (scenarios whose signals cannot be observed are skipped with a reason), abstract tool aliases (target.tools), per-attempt canaries, a real-model LeadBot (demo --model-url), the review ledger (ADR-0006 amendment), the misspelling mutator (mutations: [misspell]), SARIF export, compare, the MCP recording proxy (mcp-proxy, target.tool_log_file), a Docker image, the pre-registered benchmark, parallel tests for stateless targets (concurrency), Promptfoo export and a release workflow with Sigstore provenance.

Frontend (planned, M7)

A public static site and a local app (agentkavach ui), React and TypeScript over a local FastAPI /api/v1. They are built with seams (identity, storage, jobs, secrets, tenant ids) for a later hosted tier: see ADR-0010 and the M7 plan.

Planned package layout

src/agentkavach/
  cli.py  config.py  authz.py  runner/  connectors/  canary/
  detectors/  scenarios/  variants/  mcp_static/  scoring/  reports/{templates,static}/
packs/            # versioned YAML attack packs
benchmarks/m0/    # throwaway validation harness (M0 only)
demo/leadbot/     # LeadBot demo agent

Anything marked “Proposed” is confirmed or replaced in that milestone’s plan or an ADR.