Detection Engineering

Detection engineering with an AI assistant and Scanner MCP transforms how you write, test, and validate security rules. Instead of manually writing YAML, testing against logs, and iterating through feedback, you collaborate with your AI assistant to rapidly develop detections that work for your environment.

Choosing Your Tool

Two tools are ideal for detection engineering: Claude Code and Cursor. Both let you work with detection rule files, validate them locally, and test them against your Scanner data.

Claude Code

  • Best for: Working in your terminal, scripting rule development, integrating detection engineering into automated pipelines

  • Strengths: Direct access to scanner-cli validate and scanner-cli run-tests commands, clean file management, easy to version control rules

  • Workflow: Write rules → validate → test → iterate in the terminal, with Claude helping at each step

Cursor (IDE)

  • Best for: Visual rule development, side-by-side code/schema reference, building rule libraries

  • Strengths: Full IDE context, syntax highlighting for YAML, easy project management, can reference schema files while editing

  • Workflow: Develop rules in the editor with Claude context, immediate feedback on structure, inline validation

Both tools seamlessly integrate Scanner MCP to test rules against your actual data without leaving your development environment. For help setting up either tool, see Getting Started.


When to Use Detection Engineering with AI

Detection engineering is the process of building permanent, tested detection rules that catch threats in your environment. Use this approach when you need to:

Build new rules from threats you've seen When your team discovers a real attack or suspicious pattern—either through incident response or threat hunting—capture it as a permanent detection rule. Instead of manually writing YAML and testing, describe the threat to your AI. It writes the rule, tests it against your data, and iterates based on results. What would take hours manually takes minutes with AI assistance.

Migrate rules from your current platform You have detection rules in Splunk, Datadog, Elastic, or SumoLogic, but want to move them to Scanner. Rather than manually translating each rule's logic, point your AI at the rule and ask it to convert it to Scanner syntax. Your AI translates the logic, tests it against your data to ensure equivalence, and adjusts for your environment.

Reduce false positives in existing rules A rule catches threats but also fires constantly on legitimate activity. Instead of manually tuning thresholds, exclusions, and filters, collaborate with your AI. Describe the false positive patterns you're seeing. Your AI analyzes the data, suggests refinements, tests them, and iterates until the rule is accurate.

Build test coverage for rules Detection rules should have unit tests. Your AI writes comprehensive test cases covering true positives, true negatives, and edge cases—then validates that your rules catch what they should and exclude what they shouldn't.

Analyze and improve your detection library You want to know: Do your detection rules actually catch real threats? Are there attack techniques you're not detecting? Your AI analyzes your entire rule library, maps coverage to MITRE ATT&CK, identifies gaps, and recommends new rules for high-risk areas.

Validate rules before deployment Before deploying new rules to production, ensure they're syntactically correct, logically sound, and actually work against your data. Your AI runs validation, testing, and validation checks—catching issues before rules reach production.

How It Works

Detection engineering with an AI assistant follows an interactive workflow:

  1. Describe what to detect — Tell your AI what threat or anomaly you want to catch

  2. AI generates YAML — Your AI writes Scanner detection rules in YAML format

  3. Test against your data — Run the rule against Scanner to see what it catches

  4. Iterate based on results — Adjust the rule to increase true positives or reduce false positives

  5. Validate with unit tests — Your AI writes tests to verify the rule works correctly

  6. Deploy — Save the validated rule to your detection library

See Writing Detection Rules for the complete schema and syntax reference.

The Role of MCP: From Intent to Query

The real power of detection engineering with AI comes from MCP. You describe what you want to catch, and your AI uses Scanner MCP to translate that into production-ready Scanner Query Language — without you needing to learn the syntax.

What You Normally Have to Do

Writing detection queries manually requires:

  • Learning Scanner's query syntax (%ingest.source_type, field names, aggregation functions)

  • Understanding your data model (what fields are available, their names, nesting structure)

  • Translating business logic ("detect failed login attempts") into query operators

  • Testing trial-and-error to get the syntax right

  • Debugging queries that don't work as expected

This takes hours even for experienced teams.

How MCP Changes This

With Scanner MCP, you describe the detection intent in plain language, and your AI:

  1. Translates intent to queries — "Flag users with 10+ failed logins in 1 hour" becomes a Scanner query with proper aggregations and thresholds

  2. Queries your actual data — Tests the query against your logs in real-time to validate it works and show results

  3. Iterates automatically — When you say "that's too many false positives," your AI refines the query based on actual data patterns it sees

  4. Learns your environment — The AI understands your field names, data structure, and what "normal" looks like by querying your data

Example: Intent to Query

You describe the detection:

Without MCP (manual):

  • You spend 30 minutes reading Scanner documentation

  • You learn the syntax: eventName=(PutRolePolicy AttachRolePolicy), errorCode=*, | stats count() by ...

  • You write a query, run it, get results you don't understand

  • You iterate multiple times to fix syntax errors and refine thresholds

With MCP:

  • Your AI immediately generates a query:

  • Your AI tests it: "Running query against last 30 days... Found 47 matches. Most look like developers testing permissions in non-prod."

  • You ask: "What if we exclude the dev team?"

  • Your AI refines in seconds and retests: "Better. 12 matches now. These look more suspicious."

Time saved: 30 minutes of documentation → 5 minutes of conversation.

What Makes MCP Powerful for Queries

1. Iterative refinement based on data

2. Learning from your data model The AI doesn't need you to provide field names. It queries your data to discover:

  • Which fields exist and what they contain

  • How data is nested (e.g., userIdentity.userName vs user.name)

  • Data patterns that affect thresholds (e.g., "normal users get 0-2 permission errors per day")

3. Bridging platform-specific syntax Coming from Splunk?

4. Building complex logic without syntax complexity Describe the attack pattern, MCP handles the query mechanics:

Best Practices for Working with MCP on Queries

  1. Start with clear intent — "Detect data exfiltration" is vague. Better: "Detect when a user downloads >1GB of data from sensitive S3 buckets in <1 hour"

  2. Let MCP see the data first — Before refining, ask: "Show me what a normal S3 download pattern looks like for our environment"

  3. Validate assumptions — When MCP suggests a threshold, ask: "Why 100 requests?" vs. just accepting it

  4. Ask for explanations — "Can you explain what this query does and why each part is necessary?" helps you understand and review

  5. Test against different time windows — Ask MCP to test the same query against:

    • Last 24 hours (recent activity)

    • Last 7 days (patterns, false positive patterns)

    • Last 30 days (realistic volume)

  6. Combine with data exploration — Before asking for a detection rule, explore your data:


Writing Detection Rules from Scratch

Start by describing the threat you want to detect in plain language.

Your prompt:

Your AI generates YAML:

Test it:

Iterate based on feedback:

Your AI updates the rule to focus on the most suspicious actions:


Migrating Rules from Other Platforms

Have detection rules in Splunk, Datadog Cloud SIEM, Elastic SIEM, SumoLogic, or another platform? Point your AI at the rule and ask it to translate:

Your workflow:

  1. Export your detection rule from your current platform (Splunk, Datadog, Elastic, SumoLogic)

  2. Save it to a file (e.g., splunk_rule.txt or datadog_rule.json)

  3. Ask your AI to translate it:

Your AI will:

  • Translate the rule logic to Scanner query syntax

  • Map fields from the source platform to Scanner's data model

  • Create a Scanner YAML file with proper schema and required fields

  • Use Scanner MCP to test the query against your actual data

  • Iterate on the query based on test results (tuning thresholds, filters, aggregations)

  • Suggest optimizations for Scanner's indexed query engine

  • Provide test cases that validate the migrated rule catches the same activity


Testing and Validation

Writing Unit Tests

After creating a rule, have your AI write test cases to verify it works correctly:

Your prompt:

Your AI generates tests:

Test your rules locally with: scanner-cli run-tests -f <filename> or for multiple rules: scanner-cli run-tests -r -d ./rules/

Validating Against Your Data

Test the rule against your actual logs to see real results:

Your prompt:

Your AI runs the queries against your actual data and provides analysis with specific recommendations for tuning.


Tuning for Your Environment

Detection rules need to be tuned for false positives. Your AI can help systematically reduce noise while maintaining detection:

Your prompt:

Your AI refines the rule and provides test queries to validate improvements.

Your AI's refined query:

Key changes:

  • Removed CreateAccessKey (too noisy—users get errors frequently)

  • Added additional service account exclusions (developer-test accounts)

  • Focus only on policy modification attempts (PutRolePolicy, AttachRolePolicy)

  • Aggregate by user only (not event type) to catch pattern of persistent attempts

Test queries to validate:


Example: Complete Detection Engineering Workflow

Here's how a detection might evolve through collaboration with your AI:

Step 1: Initial Idea

Step 2: AI Writes Initial Rule

Your AI generates a rule (with proper Scanner YAML format):

Key detection logic:

  • GetObject calls to S3 buckets

  • Flags users with 100+ requests AND 0.5GB+ transfer in a 1-hour window

  • High request volume + large transfer indicates automated data collection

  • Aggregates by user and bucket to identify scope of access

Step 3: Test Results

Step 4: Refine and Retest

You tell your AI:

Your AI updates the rule to:

  • Exclude known service accounts

  • Exclude users in specific departments with legitimate export jobs

  • Lower the threshold for sensitive buckets (customers, PII)

  • Keep higher threshold for general buckets

Step 5: Retest

Step 6: Validate and Deploy

Your AI provides:

  • Unit tests in Scanner YAML format (with tests:, dataset_inline:, expected_detection_result:)

  • Test scenarios covering: true positives, true negatives, edge cases, realistic attacks

  • A runbook explaining the threat, investigation steps, and remediation

Then you:

  1. Add the tests to the detection rule YAML

  2. Validate all rules: scanner-cli validate -r -d ./rules/ (validates all YAML files in directory recursively)

  3. Test all rules: scanner-cli run-tests -r -d ./rules/ (runs all tests recursively)

  4. Fix any failures and re-run validation/tests

  5. Deploy the validated rules to your Scanner instance


MITRE Coverage Analysis

Once you have a library of detection rules, analyze your coverage against the MITRE ATT&CK framework to identify gaps and prioritize new detections.

How It Works

  1. Export your rules — Save all detection rules from your GitHub repository or local directory

  2. Explore your data — Your AI uses Scanner MCP to:

    • Query your indexes to understand what log sources you have available

    • Discover the data types available (e.g., aws:cloudtrail, kubernetes:audit, proxy, dns, etc.)

    • Map available fields and their values to understand your data model

    • This gives the AI a concrete understanding of what's detectable in your environment

  3. Ask your AI to analyze coverage — Point your AI at the rules directory and ask it to:

    • Extract all MITRE tactics and techniques from rule tags

    • Count rules per tactic/technique

    • Identify which are well-covered and which have gaps

    • Map your coverage to your threat model and available data sources

  4. Test detection ideas — For gaps identified, your AI uses Scanner MCP to:

    • Run exploratory queries to test whether recommended detection patterns exist in your data

    • Validate that you have the necessary log sources and fields to detect proposed techniques

    • Confirm detection ideas are practical before recommending them

  5. Get recommendations — Your AI suggests new rules tailored to your environment, informed by what data you actually have

Example Workflow

Your prompt:

Your AI analyzes and provides:

First, the AI explores your data:

Then analyzes coverage with data awareness:

Tips for Coverage Analysis

  • Run monthly — Analyze coverage regularly (at least monthly) to stay aligned with threat landscape changes and ensure your detection library keeps pace with new attacks

  • Align with threat model — Prioritize gaps in tactics relevant to your organization (e.g., if you're a cloud provider, focus on cloud-specific techniques)

  • Share with stakeholders — Use the coverage matrix to show security posture to leadership

  • Track improvements — Keep baseline coverage metrics and track how they improve over time

References

For detailed information on Scanner detection rule syntax and schema:

For examples of production-ready detection rules, see the Scanner out-of-the-box detections repository. These rules demonstrate:

  • Effective query patterns for Scanner query syntax

  • Proper YAML structure with required fields

  • MITRE ATT&CK tag mapping

  • Real-world tuning for scale

You can use these as templates and adapt them with your AI's help for your specific needs.

Where to Go From Here

Detection engineering is one piece of a comprehensive security strategy. Use it alongside:

Interactive Investigations — Investigate security incidents in real-time. When you discover a new attack pattern during an investigation, document it and use detection engineering to build a permanent rule for it.

Autonomous Workflows — Scale detection and response. Once you have a library of detection rules, use autonomous workflows to hunt continuously, triage alerts, and respond automatically to threats 24/7.

The most effective teams use all three: interactive investigations for critical incidents and complex analysis, detection engineering to prevent the same attacks from recurring, and autonomous workflows to scale detection and response across your environment at scale.

Last updated

Was this helpful?