Skip to content

How It Works

Saeed Yari edited this page Nov 28, 2026 · 2 revisions

How It Works

Architecture

flowchart LR
    subgraph build["Build once, on your machine"]
        pdf["PCI DSS v4.0.1 PDF<br/>data/raw/"] --> extract["extract_pci.py"] --> enrich["enrich_pci.py"] --> validate["validate_dataset.py"]
        xlsx["Prioritized Approach .xlsx"] -. cross-check .-> enrich
        validate --> dataset[("pci_dss_v4_0_1.json")]
        dataset --> embed["build_embeddings.py<br/>(optional)"] --> vectors[("embeddings.npy<br/>+ local model")]
    end
    subgraph server["pci-dss-mcp server: read-only, offline"]
        tools["server.py<br/>11 tools, 2 resources, 2 prompts"]
        loader["data_loader.py"] --> search["search_engine.py<br/>BM25 + embeddings, RRF"]
        tools --> loader
        tools --> scanners["scanners/<br/>code, infra, payment page,<br/>repository"]
        tools --> security["security.py<br/>input caps, masking,<br/>untrusted tags, audit log"]
    end
    dataset --> loader
    vectors --> search
    client["MCP client"] <-- "stdio" --> tools
Loading

The local dataset

The build scripts turn your PDF into data/processed/pci_dss_v4_0_1.json, one record per control (249 for Requirements 1-12). The format is defined in data/processed/schema.json. Each record has:

Field What it holds
id, parent_id, requirement_number The control ID (e.g. 6.4.3), its parent (6.4) and principal requirement (6)
requirement_title, section_title The headings the control sits under
defined_approach_requirement The requirement text
customized_approach_objective, is_customized_approach_allowed The customized-approach objective, if the control allows that approach
effective_date_status immediate, or post_march_2025 for the 46 controls in Requirements 1-12 that were future-dated until 31 March 2025
applicability_notes, guidance Notes and guidance from the standard
testing_procedures Each procedure's ID, its action verb (Examine, Interview, Observe, Test) and text
related_requirements Other control IDs the text refers to
evidence_types, frequency, applicable_components, data_elements_in_scope, automation_potential, keywords, saq_applicability Classification added by keyword rules: useful for search and triage, but approximate

The extraction is checked against the PCI SSC Prioritized Approach workbook (all 249 IDs match), and validate_dataset.py checks the schema, duplicate IDs, completeness and leftover page headers or footers.

Search

search_pci_controls ranks controls two ways and fuses the rankings with Reciprocal Rank Fusion before applying filters:

  1. BM25 over IDs, titles, requirement text, guidance, keywords and SAQ tags. Acronyms such as PAN, SAD, SRI, CSP, HSM, TLS, AES, MFA and WAF are expanded with the words the standard uses, at half weight so they never drown out your own terms.
  2. Semantic similarity with sentence-transformers/all-MiniLM-L6-v2 (ONNX via fastembed, CPU only). Control embeddings are precomputed by scripts/build_embeddings.py; the server loads the model with downloads disabled.

If the embeddings are missing, or stale because the dataset changed, search falls back to BM25 and reports "search_mode": "lexical". The server is ready about 0.5 s after launch; the first semantic query loads the model (about 0.3 s), later ones take a few milliseconds.

Security model

  • Read-only and offline. No file writes, network calls or subprocesses. Tests enforce this, including one that blocks sockets during semantic search.
  • Input caps. Code, config and HTML up to 500,000 characters, directory paths 4,096, queries 500, other text parameters 100.
  • No card data or secrets in output. Every result passes through a sanitizer that masks Luhn-valid card numbers (first 6 / last 4) and redacts track data and well-known secret formats. Scanners also hide secret values they find.
  • Untrusted content is marked. Anything quoted from scanned input is wrapped in <scanned_artifact> tags, and look-alike tags inside it are neutralized, so a malicious comment cannot pose as instructions to the assistant.
  • Contained directory audits. audit_directory resolves paths first, refuses system and home roots, never follows symlinks and opens files with O_NOFOLLOW.
  • Opt-in audit log. PCI_MCP_AUDIT_LOG=1 writes one metadata-only JSON line per tool call to stderr (tool, status, latency, finding count; never inputs).

Configuration

Variable Default Purpose
PCI_DSS_DATA_PATH data/processed/pci_dss_v4_0_1.json (Docker: /app/data/processed/pci_dss_v4_0_1.json) Dataset file to load
PCI_MCP_AUDIT_LOG off 1 turns on the audit log

Clone this wiki locally