Skip to main content

AI Assumption Firewall โ€” MCP server that catches assumptions, checks past decisions, detects contradictions, and gates human approval.

Project description

๐Ÿ”ฅ Kontrol Freek

AI assumption firewall โ€” an MCP server that catches AI assumptions, verifies them against a project decision log, detects contradictions, scores risk, and gates human approval before the AI proceeds.

What It Does

AI: "I'll use PostgreSQL" (assumption!)
     โ†“
check_assumption("Use PostgreSQL", risk="medium", category="architecture")
     โ†“
Kontrol Freek: Check past decisions โ†’ Contradictions? โ†’ Risk score
     โ†“
โ”œโ”€ Low risk + past approval โ†’ โœ… Auto-approve
โ”œโ”€ Medium risk โ†’ ๐Ÿ” Ask human (Telegram/Slack/Web/Terminal)
โ””โ”€ Contradiction or critical โ†’ โ›” Block + notify human

Beyond Existing MCP Servers

Feature clarify-mcp CONTINUITY mcp-human-loop VantaGate Kontrol Freek
ctx.elicit() support โœ… โŒ โŒ โŒ โœ…
SQLite decision log โŒ โœ… โŒ โŒ โœ…
Risk scoring โŒ โŒ โœ… โŒ โœ…
Semantic similarity โŒ โŒ โŒ โŒ โœ…
Contradiction detection โŒ โŒ โŒ โŒ โœ…
Cryptographic audit โŒ โŒ โŒ โœ… โœ…
Time-based decay โŒ โŒ โŒ โŒ โœ…
Multi-channel โŒ โŒ โŒ โœ… โœ…
Project context analysis โŒ โœ… โŒ โŒ โœ…
Adaptive policy engine โŒ โŒ Basic Static Adaptive

Installation

One-Command Setup (Mac / Linux / Windows)

git clone https://github.com/berkbayri/kontrol-freek-mcp.git
cd kontrol-freek-mcp
python install.py

This will:

  1. Install the Python package
  2. Generate a .env with a random HMAC secret
  3. Register a system service (auto-starts on boot, auto-restarts on crash)
  4. Configure Claude Code and Claude Desktop

Manual Install

pip install -e ".[full]"     # Full: Telegram + Web + Embeddings
# or
pip install -e ".[lite]"     # Lite: Telegram + Web (no embeddings)
# or
pip install -e .             # Minimal: stdio only

Claude Code Config

The installer uses the Claude Code CLI to register the server globally (works across all projects):

claude mcp add kontrol-freek /path/to/kontrol-freek \
  -e KF_HMAC_SECRET=your-secret \
  -e KF_DB_PATH=/home/you/.kontrol-freek/decisions.db \
  -e KF_AUDIT_PATH=/home/you/.kontrol-freek/audit.jsonl \
  -e KF_TELEGRAM_TOKEN=BOT_TOKEN \
  -e KF_TELEGRAM_CHAT_ID=CHAT_ID \
  --scope user

This writes to ~/.claude.json (the correct global config file). The old ~/.claude/claude_code_config.json path is not read by Claude Code and should not be used.

Claude Desktop Config

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "kontrol-freek": {
      "command": "python",
      "args": ["-m", "kontrol_freek_mcp"],
      "env": { "KF_HMAC_SECRET": "your-secret" }
    }
  }
}

HTTP Server Mode (remote access)

kontrol-freek --transport streamable-http --port 8765
{
  "mcpServers": {
    "kontrol-freek": {
      "transport": "streamable-http",
      "url": "http://localhost:8765/mcp"
    }
  }
}

Telegram Bot Setup

  1. Message @BotFather โ†’ /newbot โ†’ get token
  2. Add bot to a group or DM it
  3. Get chat ID: https://api.telegram.org/bot<TOKEN>/getUpdates
  4. Set in .env:
    KF_TELEGRAM_TOKEN=123456:ABC-DEF...
    KF_TELEGRAM_CHAT_ID=987654321
    

Bot Commands

/kf approve abc123         โ†’ Approve assumption
/kf reject abc123 Wrong    โ†’ Reject with reason
/kf answer abc123 Yes      โ†’ Answer a question
/kf stats                  โ†’ Show statistics
/kf recent                 โ†’ Recent decisions

How It Works

Decision Flow

AI โ†’ check_assumption(assumption, risk, category)
         โ”‚
         โ”œโ”€โ”€ Query past decisions (SQLite)
         โ”œโ”€โ”€ Compute semantic similarity (TF-IDF or sentence-transformers)
         โ”œโ”€โ”€ Contradiction analysis
         โ”œโ”€โ”€ Policy engine โ†’ auto_approve / review / block
         โ”‚
         โ”œโ”€โ”€ auto_approve โ†’ Log, continue
         โ”œโ”€โ”€ review โ†’ Ask human โ†’ Wait โ†’ Log
         โ””โ”€โ”€ block โ†’ Notify human โ†’ Wait for approval/rejection โ†’ Log
                         โ”‚
                         โ”œโ”€โ”€ ctx.elicit() (native MCP)
                         โ”œโ”€โ”€ Telegram bot
                         โ”œโ”€โ”€ Slack webhook
                         โ”œโ”€โ”€ Web dashboard
                         โ””โ”€โ”€ Terminal input (fallback)

Policy Rules

Condition Verdict
Critical risk โ›” Block โ€” always requires human approval
Contradiction with past decision โ›” Block
security/architecture/deployment category ๐Ÿ” Review
Low risk + โ‰ฅ78% similarity + past approval โœ… Auto-approve
High risk ๐Ÿ” Review
Default ๐Ÿ” Review

Time Decay

Older decisions carry less weight:

  • 0 days โ†’ 1.0 (fully valid)
  • 30 days โ†’ 0.72
  • 90 days โ†’ 0.37
  • 180 days โ†’ 0.14

This prevents stale approvals from auto-approving new assumptions.

Audit Chain

Every action is logged to an HMAC-SHA256 signed, hash-chained JSONL file:

{"action": "human_approve", "text": "Use PostgreSQL", "detail": "Go ahead",
 "decision_id": 42, "ts": "2025-01-15T14:30:00Z", "prev": "a1b2...", "hash": "d4e5..."}

Verify chain integrity:

from kontrol_freek_mcp.audit import AuditTrail
trail = AuditTrail("./audit.jsonl", "your-secret")
valid, count = trail.verify_chain()
print(f"Valid: {valid}, Entries: {count}")

Auto-Start & Crash Recovery

python install.py sets up:

Platform Mechanism Details
macOS LaunchAgent ~/Library/LaunchAgents/com.kontrol-freek.mcp.plist โ€” runs at login, KeepAlive on crash
Linux systemd user service ~/.config/systemd/user/kontrol-freek.service โ€” Restart=on-failure, survives logout via linger
Windows Task Scheduler schtasks โ€” runs at logon

The wrapper script includes exponential backoff crash recovery (5s โ†’ 10s โ†’ 20s โ†’ ..., max 10 restarts).

python install.py --status     # Health check
python install.py --uninstall  # Clean removal

Project Structure

kontrol-freek-mcp/
โ”œโ”€โ”€ src/kontrol_freek_mcp/
โ”‚   โ”œโ”€โ”€ __init__.py          # Package
โ”‚   โ”œโ”€โ”€ __main__.py          # python -m support
โ”‚   โ”œโ”€โ”€ server.py            # Main MCP server โ€” 7 tools + 2 resources + 1 prompt
โ”‚   โ”œโ”€โ”€ db.py                # SQLite decision database
โ”‚   โ”œโ”€โ”€ policy.py            # Policy engine (risk, decay, rules)
โ”‚   โ”œโ”€โ”€ similarity.py        # Semantic similarity (embeddings + TF-IDF)
โ”‚   โ”œโ”€โ”€ notifier.py          # Multi-channel notification routing
โ”‚   โ”œโ”€โ”€ audit.py             # HMAC-SHA256 hash-chain audit trail
โ”‚   โ”œโ”€โ”€ web.py               # FastAPI approval dashboard
โ”‚   โ””โ”€โ”€ telegram_bot.py      # Telegram bot handler
โ”œโ”€โ”€ tests/test_core.py
โ”œโ”€โ”€ install.py               # One-command installer (Mac/Linux/Windows)
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ CLAUDE.md
โ”œโ”€โ”€ .env.example
โ””โ”€โ”€ README.md

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kontrol_freek_mcp-1.0.0.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kontrol_freek_mcp-1.0.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file kontrol_freek_mcp-1.0.0.tar.gz.

File metadata

  • Download URL: kontrol_freek_mcp-1.0.0.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for kontrol_freek_mcp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d8fca7fda50fc135f11cf0ef99abcd7f4f5cf868009bd6f1261ac8b5cc953fd7
MD5 aa7440da4f0eb55a3f796e50a82dd029
BLAKE2b-256 13993f40fd1f0dcc745f644aca671643f9ffa8d4542d72992f24812685e43e7a

See more details on using hashes here.

File details

Details for the file kontrol_freek_mcp-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for kontrol_freek_mcp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98945c7a2e6f3754f432668cf12805bdb13bf6c10b66abd03dacb18b350b3df8
MD5 8ba6dc3ae2921224b5379b19e3240eb5
BLAKE2b-256 11bee8a6e4c86f669b0a6596a4ec2939c01fd0d86b494ede89c45ca11be559e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page