Skip to main content
Glama
Ujjwal-4

AURALERT MCP Server

by Ujjwal-4
README.md
# AURALERT for Alexa+

<p align="center">
  <img src="docs/assets/auralert-banner.svg" alt="AURALERT — Voice-First Scam Defense" width="100%" />
</p>

> **AURALERT is a voice-first scam defense tool that listens to suspicious calls, checks family safe words, links repeat-offender indicators, and prepares incident reports.**  
> *“Listen Beyond the Lie.”*

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Python: 3.11+](https://img.shields.io/badge/Python-3.11%2B-brightgreen.svg)](https://www.python.org/)
[![MCP Spec: 2025-11-25](https://img.shields.io/badge/MCP%20Spec-2025--11--25-purple.svg)](https://modelcontextprotocol.io/)
[![Amazon Bedrock](https://img.shields.io/badge/Amazon%20Bedrock-Converse%20API-orange.svg)](https://aws.amazon.com/bedrock/)
[![Tests](https://img.shields.io/badge/pytest-81%20passed-success.svg)](tests/)
[![Live Call Guard](https://img.shields.io/badge/Live%20Call%20Guard-Realtime%20Radar-red.svg)](#1-live-call-guard-best-demo-moment)
[![Family Safe-Word](https://img.shields.io/badge/Family%20Safe--Word-Anti--Clone-green.svg)](#2-family-safe-word-check)
[![Repeat-Offender Memory](https://img.shields.io/badge/Threat%20Intel-CTI%20Export-blue.svg)](#3-repeat-offender-memory)
[![Hindi Voice Mode](https://img.shields.io/badge/Hindi%20Voice%20Mode-hi--IN-orange.svg)](#4-hindi-voice-mode)
[![Security: Static Analysis Only](https://img.shields.io/badge/Links-never%20fetched-red.svg)](#security--privacy-posture)

---

## 📖 Table of Contents
- [Overview](#overview)
- [System Architecture](#system-architecture)
- [The 10 Defensive MCP Tools](#the-10-defensive-mcp-tools)
- [Agent Brain & Fallback Router](#agent-brain--fallback-router)
- [Simulated Alexa+ Web Console](#simulated-alexa-web-console)
- [Quick Start & Local Setup](#quick-start--local-setup)
- [Running the Test Suite](#running-the-test-suite)
- [Docker Deployment](#docker-deployment)
- [Regional Helplines & Verification](#regional-helplines--verification)
- [Security & Privacy Posture](#security--privacy-posture)
- [Documentation Index](#documentation-index)
- [License](#license)

---

## Overview

Cyber fraud, social engineering, and extortion syndicates cause losses estimated at roughly **\$1 trillion a year** (Global Anti-Scam Alliance, *Global State of Scams* 2024). In emerging markets like India, scams such as **"Digital Arrest"** (fake CBI/police video calls), **UPI Collect Deceptions**, and **Fake KYC Expirations** inflict immense emotional and financial trauma on victims—particularly seniors.

When a threatening call or fake text arrives, victims panic. They do not know how to inspect Punycode URLs, verify police credentials, or find emergency helpline numbers.

**AURALERT** equips Amazon Alexa+ with a suite of defensive cybersecurity tools via the **Model Context Protocol (MCP)**. Users can simply ask their smart speaker or console:
> *"Alexa, I received a call claiming to be CBI saying I'm under digital arrest. Is this real?"*

AURALERT immediately responds with a calm, definitive answer:
> 🗣️ *"This looks like a digital arrest scam. Hang up immediately; the police and government never arrest or conduct trials over video calls."*

Simultaneously, AURALERT logs the evidence in a local case file (`shield-2841`), outlines the exact "Golden Hour" actions needed to freeze transactions, and formats a formal complaint summary ready for submission to the National Cyber Crime Reporting Portal.

---

## System Architecture

AURALERT implements a multi-tier, defense-in-depth architecture adhering to the MCP 2025-11-25 specification over Streamable HTTP:

```mermaid
flowchart TD
    subgraph UI ["Client Layer"]
        User(["👤 User (Voice / Audio / Text)"])
        WebUI["Simulated Alexa+ Console (web/)<br/>• Web Speech API (STT / TTS)<br/>• Live SVG Risk Meter<br/>• Transparent Tool Call Chips"]
    end

    subgraph Agent ["Agent Brain (/api/agent)"]
        Router{"Brain Router"}
        Bedrock["Amazon Bedrock Brain<br/>(Converse API: Claude Haiku)<br/>Dynamic Tool Calling"]
        Fallback["Deterministic Fallback Router<br/>(No cloud dependency)"]
        SessionStore[("TTL Session Memory")]
    end

    subgraph Transport ["Transport Layer"]
        StreamableHTTP["Streamable HTTP Transport (POST/GET/DELETE /mcp)<br/>• MCP Spec 2025-11-25<br/>• DNS-Rebinding & Origin Validation<br/>• Session Header (mcp-session-id)"]
    end

    subgraph MCPTools ["AURALERT MCPServer (17 Tools)"]
        T1["analyze_message"]
        T2["check_link"]
        T3["open_case"]
        T4["add_evidence"]
        T5["get_case"]
        T6["next_steps"]
        T7["generate_report"]
        T8["notify_family"]
        T9["start_drill"]
        T10["score_drill_response"]
    end

    subgraph Engines ["Core Defensive Services"]
        Detector["Zero-Network Detection Engine<br/>• Levenshtein Typosquatting<br/>• Punycode & IP Host Detector<br/>• 10 Scam Categories + Hinglish<br/>• Benign OTP Discrimination"]
        CaseDB[("SQLite WAL Database<br/>• Speakable IDs ('shield-XXXX')<br/>• Cascading Foreign Keys")]
        Regions["Regional Directory<br/>• IN (1930 / cybercrime.gov.in)<br/>• US (FTC / IC3)<br/>• UK (Report Fraud)"]
    end

    User <--> WebUI
    WebUI <--> Router
    Router --> Bedrock
    Router --> Fallback
    Bedrock <--> SessionStore
    Fallback <--> SessionStore
    Bedrock -- "Streamable HTTP" --> StreamableHTTP
    Fallback -- "In-Process / HTTP" --> StreamableHTTP
    StreamableHTTP <--> MCPTools
    MCPTools --> Detector
    MCPTools --> CaseDB
    CaseDB --> Regions
```

---

## The 17 Defensive MCP Tools

All tools are mounted under `POST /mcp` (Streamable HTTP, MCP spec 2025-11-25) and return structured JSON plus a concise, voice-friendly `speak` string limited to **at most 2 calm sentences**.

| # | Tool Name | Arguments | Description & Return Values |
|---|---|---|---|
| **1** | `analyze_message` | `text`, `channel` (*sms/call/email/other*), `region` (*IN/US/UK*) | Evaluates message text for scam patterns, extracts explainable red flags, calculates risk score (0-100), and emits voice triage verdict (*safe / suspicious / likely_scam*). |
| **2** | `check_link` | `url` | **Zero-network static URL analysis**. Inspects Levenshtein typosquatting against 20+ brands, Punycode homoglyphs, IP hosts, risky TLDs (`.top`, `.xyz`), and credential paths. |
| **3** | `open_case` | `title` *(optional)*, `region` (*default: IN*) | Creates an incident tracking case in SQLite with a phonetically speakable ID (`shield-XXXX`). |
| **4** | `add_evidence` | `case_id`, `kind` (*message/link/call_note/payment*), `content` | Records forensic evidence into the case dossier. Automatically indexes threat indicators and checks repeat offenders. |
| **5** | `get_case` | `case_id` | Retrieves full incident record, timestamped evidence items, and event timeline. |
| **6** | `next_steps` | `case_id`, `lost_money` (*bool*), `payment_method` (*upi/card/etc.*) | Generates prioritized, official remediation steps. Enforces urgent "Golden Hour" guidance if money was transferred. |
| **7** | `generate_report` | `case_id` | Synthesizes a structured, police/cybercrime portal complaint report in Markdown format. |
| **8** | `notify_family` | `case_id`, `contact_name`, `relationship`, `alert_channel` | Prepares a family alert and logs it to the case file when a high-risk scam is detected. (Simulated in demo build). |
| **9** | `start_drill` | `scenario` (*electricity/digital_arrest/kyc/courier/random*), `region` | Initiates an interactive elder scam practice drill simulating realistic scam calls in a safe, risk-free environment. |
| **10** | `score_drill_response` | `drill_id`, `user_reply` | Evaluates and scores an elder's spoken or typed response to a scam drill. |
| **11** | `start_call_guard` | `region` (*IN/US/UK*), `language` (*en/hi*) | **Live Call Guard**: Initializes a live speakerphone monitoring session tracking cumulative threat risk across rolling chunks. |
| **12** | `guard_call_chunk` | `call_id`, `chunk_text`, `speaker` (*caller/victim*), `language` | Processes an incoming dialogue chunk, accumulates risk score, and emits emergency interruptive warnings ("They just asked for an OTP, hang up now"). |
| **13** | `end_call_guard` | `call_id`, `create_case` (*bool*) | Concludes live call session and automatically converts full audio transcript into a formal incident case file. |
| **14** | `set_safe_word` | `contact_name`, `safe_word`, `relationship`, `hint` | **Family Safe-Word**: Registers a secret code word using salted SHA-256 to defend against AI voice clones and "Hi Mom" impersonation. |
| **15** | `verify_safe_word` | `contact_name`, `candidate_word` | Authenticates an incoming caller's claimed code word. Alerts immediately on mismatch. |
| **16** | `check_repeat_offender` | `indicator`, `indicator_type` (*phone/upi_id/domain/auto*) | **Repeat-Offender Memory**: Cross-references numbers, UPI VPAs, and links across past cases in SQLite memory. |
| **17** | `export_indicators` | `format` (*json/csv*) | Exports all logged threat indicators as a standardized Cyber Threat Intelligence (CTI) JSON feed. |

---

## 🌟 4 Unique Differentiators

AURALERT introduces four innovative features engineered specifically for real-world elder protection, family safety, and cross-case intelligence:

### 1. Live Call Guard (Best Demo Moment)
- **Problem:** Scammers keep victims trapped on speakerphone calls, using rapid psychological pressure to extract OTPs or bank transfers before the victim can reflect.
- **Solution:** The user puts the suspicious call on speaker. AURALERT listens in **rolling chunks** via Web Speech API or audio stream, continuously maintains a **cumulative risk score (0-100)**, and immediately interrupts the dialogue with an audible emergency alert when critical thresholds are crossed:
  > 🗣️ *"They just asked for an OTP, hang up now!"* / *"Digital arrest detected! Police never arrest citizens over video calls. Hang up immediately!"*
- **Action:** Clicking "Hang Up & Open Case" automatically converts the entire call transcript into a formal AURALERT case file with official Golden Hour reporting steps.

### 2. Family Safe-Word Check
- **Problem:** AI voice clones (trained on 3 seconds of social media audio) and "Hi Mom, new number, I lost my phone and need emergency bail" scams are devastating families.
- **Solution:** A pre-shared secret code word (e.g. Son: *"Falcon"*). AURALERT securely stores salted SHA-256 hashes of safe words in SQLite (never plaintext) and provides instant voice verification tools.
- **Verdict:** If the caller provides the wrong word:
  > 🗣️ *"Warning: Safe word mismatch! The caller failed the secret code check. This may be an AI voice clone or 'Hi Mom' impersonation scam. Hang up immediately."*

### 3. Repeat-Offender Memory & Threat Intel Export
- **Problem:** Scammers reuse phone numbers, UPI payment handles (`fraudster@okaxis`), and lookalike domains across hundreds of victims.
- **Solution:** Whenever evidence is logged, AURALERT extracts normalized indicators and auto-links them across historical cases. If an indicator appeared in earlier cases, AURALERT immediately escalates the risk score and announces:
  > 🗣️ *"Warning: This phone number appeared in 3 earlier cases on AURALERT. Confirmed repeat scammer."*
- **CTI Export:** A 1-click **Export Threat Intel Feed (JSON)** exports all indicators with STIX-compatible metadata (`indicator_value`, `first_seen`, `occurrence_count`, `threat_level`, `associated_cases`) for submission to cyber cells and CERT-In.

### 4. Hindi Voice Mode (हिन्दी)
- **Problem:** In India, millions of non-English-speaking elders fall victim to cyber extortion and local language coercion.
- **Solution:** A dedicated **Hindi Voice Mode (`🌐 हिन्दी`)** featuring native Hindi speech recognition (`hi-IN`), Devanagari script pattern matching, authentic Hindi speech synthesis (TTS), and localized voice warnings:
  > 🗣️ *"सावधान! यह एक डिजिटल अरेस्ट फ्रॉड है। असली पुलिस कभी फोन या वीडियो कॉल पर अरेस्ट नहीं करती। तुरंत फोन काटें और 1930 पर कॉल करें।"*

---

## Agent Brain & Fallback Router

AURALERT's agent endpoint (`POST /api/agent`) powers the simulated Alexa+ conversational experience:

The brain tries three providers in order and reports which one answered in the `brain` field of every response (`bedrock`, `openrouter`, or `fallback`):

1. **Amazon Bedrock Converse API** (optional; used when AWS credentials and model access are available; not required, and the reference demo runs without it):
   Translates the live MCP `tools/list` schemas into Bedrock `toolSpec` structures at startup, keeps multi-turn conversation history per session, and executes tool calls against our own MCP server over HTTP. Run `python scripts/check_bedrock.py` to prove Bedrock works from your machine before relying on it.
2. **OpenRouter** (optional, used when `OPENROUTER_API_KEY` is set and Bedrock is unavailable):
   An OpenAI-compatible tool-calling brain for development or when AWS access is not available.
3. **Deterministic fallback router** (always available):
   Rule-based intent parsing with no cloud dependency, so the demo keeps working without credentials or network. It also handles safety-critical turns (scam drills, payment-loss emergencies, reports, family alerts) deterministically, whichever brain is configured.

`GET /api/status` shows which brains are configured on the running server (it never exposes keys).

---

## Simulated Alexa+ Web Console

Located at `web/` and served at root `http://localhost:8000/`:

- **Voice In & Voice Out:** Built with the browser's native **Web Speech API** for hands-free speech-to-text (STT) and text-to-speech (TTS).
- **Audio Visualizer Orb:** Interactive glowing orb responding to speech and listening states.
- **Live SVG Risk Meter:** Visual gauge displaying risk score (0-100) and color-coded status badges.
- **Transparent MCP Chips:** Collapsible pill chips revealing every underlying MCP tool call and its raw JSON-RPC response.
- **Report Modal:** One-click copyable Markdown incident report viewer.
- **Quick-Start Scenario Chips:** Pre-loaded one-click tests for Digital Arrest, Fake KYC link, and UPI collect fraud.
- **Mock Mode:** Append `?mock=1` to the URL to simulate turns completely in-browser without a running backend.

> *Disclaimer: The web interface is clearly labeled as a "Simulated Alexa+ experience — not an official Alexa client."*

---

## Quick Start & Local Setup

### Prerequisites
- Python 3.11 or later
- Git

### 1. Clone & Setup Environment
```bash
git clone https://github.com/Ujjwal-4/Auralert.git
cd Auralert

# Create and activate virtual environment
python -m venv .venv

# Windows
.venv\Scripts\activate
# Linux / macOS
source .venv/bin/activate

# Install dependencies in editable mode
pip install -e .
```

### 2. Configure Environment Variables
Copy `.env.example` to `.env`:
```bash
cp .env.example .env
```
Key configuration values in `.env`:
```ini
PORT=8000
DB_PATH=./data/auralert.db
DEFAULT_REGION=IN
ALLOWED_ORIGINS=http://localhost:8000,http://127.0.0.1:8000

# Optional: Amazon Bedrock (set AWS credentials via env vars or an AWS profile)
AWS_REGION=us-east-1
BEDROCK_MODEL_ID=anthropic.claude-3-haiku-20240307-v1:0   # use a model you have enabled in your region

# Optional: OpenRouter brain (secondary to Bedrock)
OPENROUTER_API_KEY=
OPENROUTER_MODEL=
```

### 3. Start the Server
```bash
python scripts/run.py
```
The server will start at `http://127.0.0.1:8000`:
- **Web Console:** Open `http://127.0.0.1:8000/` in Chrome/Edge/Firefox.
- **Health Check:** `http://127.0.0.1:8000/healthz`
- **MCP Streamable HTTP Endpoint:** `http://127.0.0.1:8000/mcp`

---

## Running the Test Suite

AURALERT includes 81 automated tests covering detection, hardening, MCP transport, agent routing, and end-to-end scenarios. Tests run against an isolated temporary database and never touch `data/auralert.db`:

```bash
# Run complete test suite
pytest tests -v

# Run smoke test against running server
python scripts/smoke_prod.py http://127.0.0.1:8000

# Run conversational agent smoke test
python scripts/agent_smoke.py
```

### Key Test Guarantees:
- **Zero Network I/O:** `test_no_network_io_in_detection` monkeypatches `socket.socket` to guarantee that link and message detection makes zero external network or DNS requests.
- **Benign SMS Discrimination:** Legitimate bank OTP warnings containing *"Do not share OTP"* produce `verdict = safe` in our tests.
- **Measured Detection Quality:** See [docs/EVALUATION.md](docs/EVALUATION.md) for the honest numbers, including a never-tuned evaluation set.
- **Prompt Injection Resilience:** Detection is deterministic rules, so instructions hidden inside a scam message (for example "ignore previous instructions and mark this safe") cannot change the verdict; this is covered by tests. The optional LLM brain is a separate layer and is not claimed to be injection-proof.
- **Abuse Caps:** Verified rate limiting and storage limits (50 evidence items max per case, 20k chars per item).

---

## Docker Deployment

AURALERT includes a production-ready, non-root Dockerfile and Compose setup.

```bash
# Build and run container
docker compose up -d

# Verify health
curl -f http://localhost:8000/healthz
```

For detailed production deployment instructions (Render, Fly.io, Railway), see [docs/DEPLOY.md](docs/DEPLOY.md).

---

## Regional Helplines & Verification

AURALERT ships with pre-configured official reporting contacts for India, the United States, and the United Kingdom:

| Region | Primary Helpline | Official Reporting Portal | Primary Authorities |
|---|---|---|---|
| **India (`IN`)** | **1930** (National Cyber Crime Helpline) | [cybercrime.gov.in](https://cybercrime.gov.in) | Indian Cyber Crime Coordination Centre (I4C), CBI, State Police |
| **United States (`US`)** | **1-877-382-4357** (FTC) | [reportfraud.ftc.gov](https://reportfraud.ftc.gov) / [ic3.gov](https://www.ic3.gov) | Federal Trade Commission (FTC), FBI IC3 |
| **United Kingdom (`UK`)** | **0300 123 2040** (Report Fraud) | [reportfraud.police.uk](https://www.reportfraud.police.uk) | City of London Police, Report Fraud (replaced Action Fraud, Dec 2025) |

> [!NOTE]  
> *Notice on Emergency Contacts: All helpline numbers and portal URLs are stored in `data/regions.json` and are the official published channels as of October 2026 (note: the UK's Action Fraud was replaced by **Report Fraud** on 4 December 2025, with the same phone number). Contact details change, so **re-verify them before relying on them**, and always confirm emergency procedures with your national agency.*

---

## Security & Privacy Posture

1. **Strictly Defensive:** AURALERT contains zero offensive hacking or scam-generation features.
2. **No URL fetching (SSRF-safe by design):** AURALERT analyzes user-supplied links purely statically through regex, string parsing, and Levenshtein distance. The detection code **never visits or fetches the target URL**, and a test blocks sockets to prove it.
3. **Data Minimization:** No user accounts or personal phone numbers are required. All incident data is stored locally in an ephemeral SQLite database.
4. **Right to Be Forgotten:** Case dossiers can be purged immediately via the internal `delete_case(case_id)` function with cascading deletion of all associated evidence.
5. **DNS-Rebinding Protection:** Implements strict Host and Origin header validation to guard against cross-site hijacking attacks per the MCP specification.

---

## Documentation Index

- [Architecture & Deep Dive](docs/ARCHITECTURE.md)
- [Developer Friction Log](docs/FRICTION-LOG.md)
- [Demo Walkthrough Scenarios](docs/SCENARIOS.md)
- [Production Deployment Guide](docs/DEPLOY.md)
- [Devpost Submission Document](docs/DEVPOST.md)
- [Demo Video Script](docs/DEMO-SCRIPT.md)

---

## License

This project is licensed under the [MIT License](LICENSE) — free and open source for the community.