Skip to content

160-tool MCP server for real-time global intelligence from free public APIs: markets, liquidity, prediction markets, SEC filings, conflict, military, aircraft-cohort early warning, migration and border flows, cyber, climate, news and more. Dated observation history, 29 research prompts, cited briefs, geofences, SSE dashboard. MIT, no paid API keys.

AOI change notifications: sweep POSTs non-quiet digests to a webhook

Phoenix Agent (Marcs-Mac-Studio)ced9d86be0bb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bb5c6e2..c2c298a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,18 @@
domain group for `--sources aoi`. No push notification sink yet
(tracked in ROADMAP); digests land in the collector log and the
vector store.
+- AOI change notifications: set `WORLD_INTEL_AOI_WEBHOOK` and the
+ sweep POSTs every non-quiet digest (something entered or left a
+ geofence) to that URL - `json` payload by default
+ (title/totals/markdown/timestamp), or raw markdown with a `Title`
+ header via `WORLD_INTEL_AOI_WEBHOOK_FORMAT=text` for ntfy-style
+ sinks. Quiet sweeps never fire; an unreachable sink or non-2xx
+ response never fails the sweep (snapshots already advanced) but is
+ recorded honestly in the digest's `notification` field. New
+ `Fetcher.post()` carries the delivery - deliberately outside the
+ caching/retry/breaker machinery, since the target is the operator's
+ own endpoint. Live-verified end-to-end against a local sink: a real
+ sweep detected a change and the sink received the JSON payload.
- Per-source collector timeout overrides (`SOURCE_TIMEOUTS`): a live
smoke caught a single 50 km AOI sweep on a cold cache blowing the
flat 45 s budget (the digest fans out to ~8 domains per AOI, several
diff --git a/CLAUDE.md b/CLAUDE.md
index aa881ef..212beab 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -88,6 +88,7 @@ Only these unlock additional data sources (everything else works unauthenticated
- `FRED_API_KEY` — macro economic data
- `OPENSKY_CLIENT_ID` / `OPENSKY_CLIENT_SECRET` — military flight fallback
- `OLLAMA_API_URL` / `OLLAMA_MODEL`: Ollama server and model for AI-generated briefs (default `http://localhost:11434` / `llama3.2`)
+- `WORLD_INTEL_AOI_WEBHOOK` / `WORLD_INTEL_AOI_WEBHOOK_FORMAT` — AOI sweep change notifications (collector daemon): POST on non-quiet sweeps; format `json` (default) or `text` (raw markdown + `Title` header for ntfy-style sinks). Delivery record in the digest's `notification` field; a dead sink never fails the sweep.
## Testing
diff --git a/README.md b/README.md
index b8653af..dd66e0d 100644
--- a/README.md
+++ b/README.md
@@ -541,8 +541,11 @@ intel-collector --daemon --sources aoi --interval 900 # AOI watch only: sweep e
The `aoi` group runs `intel_aoi_digest` as a sweep: each cycle diffs every
defined AOI against its stored snapshot and advances it, so the daemon
interval is your geofence watch cadence. Change digests are logged and
-(when the vector store is enabled) stored for semantic search. There is no
-push notification sink yet — see ROADMAP.
+(when the vector store is enabled) stored for semantic search. Set
+`WORLD_INTEL_AOI_WEBHOOK` to get a POST whenever a sweep finds something
+entered or left a geofence (quiet sweeps never fire); with
+`WORLD_INTEL_AOI_WEBHOOK_FORMAT=text` the body is raw markdown with a
+`Title` header, which ntfy-style sinks render directly.
### Running as a macOS launchd Service
@@ -587,6 +590,8 @@ The vector store uses FastEmbed (ONNX-based, BAAI/bge-small-en-v1.5) for embeddi
| `OLLAMA_API_URL` | No | Ollama server for AI-generated briefs (default: `http://localhost:11434`) |
| `OLLAMA_MODEL` | No | Ollama model for AI-generated briefs (default: `llama3.2`) |
| `WORLD_INTEL_LOG_LEVEL` | No | Logging level (default: INFO) |
+| `WORLD_INTEL_AOI_WEBHOOK` | No | URL POSTed when an AOI sweep finds changes (collector daemon); quiet sweeps don't fire |
+| `WORLD_INTEL_AOI_WEBHOOK_FORMAT` | No | `json` (default: title/totals/markdown payload) or `text` (raw markdown body + `Title` header, ntfy-style) |
Everything else uses free, unauthenticated public APIs.
diff --git a/ROADMAP.md b/ROADMAP.md
index 4cf3e8a..9ed4736 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -535,7 +535,7 @@ Ordered by value; numbers are proposals, not commitments.
| CLI parity | `intel aoi` group with all 9 subcommands, shared store semantics, live-smoked | :white_check_mark: Shipped in 0.8.0 |
| Dashboard AOI layer | Draw defined AOIs on the Leaflet map; show per-AOI counts | :red_circle: |
| Scheduled AOI sweeps | `aoi_digest` is a collector source (`fetch_aoi_sweep`, 240 s budget): every daemon cycle advances all AOI snapshots, so `--daemon` + the launchd wrapper IS the schedule. Change digests land in the collector log and vector store | :white_check_mark: Shipped (unreleased) |
-| AOI change notifications | A push sink for non-empty sweeps (webhook/ntfy/email) — today the digest is pulled from the log or vector store, nothing pushes | :red_circle: |
+| AOI change notifications | `WORLD_INTEL_AOI_WEBHOOK` (+ `_FORMAT=json\|text`): the sweep POSTs non-quiet digests; quiet sweeps and dead sinks are honest `notification` records, never silent or fatal. Live-verified against a local sink. Email is out of scope (bring a webhook bridge) | :white_check_mark: Shipped (unreleased) |
### Phase 24 (planned): Test Coverage Gate
Measured 2026-09-01 (before the current test push): 59% statement
diff --git a/src/world_intel_mcp/analysis/aoi.py b/src/world_intel_mcp/analysis/aoi.py
index c157e82..ba2fade 100644
--- a/src/world_intel_mcp/analysis/aoi.py
+++ b/src/world_intel_mcp/analysis/aoi.py
@@ -34,6 +34,7 @@ import asyncio
import json
import logging
import math
+import os
import sqlite3
import time
from datetime import datetime, timezone
@@ -1877,6 +1878,59 @@ async def fetch_aoi_digest(fetcher, store: AOIStore, names: Any = None) -> dict:
}
+async def _notify_aoi_changes(fetcher, digest: dict) -> dict:
+ """POST a non-quiet sweep digest to the operator's webhook.
+
+ Returns the honest delivery record attached to the digest as
+ ``notification``: unconfigured, skipped (quiet sweep), sent with
+ the status code, or failed with the error. Never raises — the
+ sweep already advanced its snapshots and must not fail because a
+ sink is down; but the failure is recorded, never swallowed.
+ """
+ url = os.environ.get("WORLD_INTEL_AOI_WEBHOOK", "").strip()
+ if not url:
+ return {"configured": False}
+ fmt = os.environ.get("WORLD_INTEL_AOI_WEBHOOK_FORMAT", "json").strip().lower()
+ if fmt not in ("json", "text"):
+ return {
+ "configured": True,
+ "sent": False,
+ "error": (
+ f"Unknown WORLD_INTEL_AOI_WEBHOOK_FORMAT {fmt!r}; use 'json' or 'text'."
+ ),
+ }
+ totals = digest.get("totals") or {}
+ new_items = totals.get("new_items") or 0
+ departed = totals.get("departed_items") or 0
+ if new_items + departed == 0:
+ return {"configured": True, "sent": False, "reason": "no changes this sweep"}
+ title = f"AOI sweep: {new_items} new, {departed} departed"
+ try:
+ if fmt == "text":
+ resp = await fetcher.post(
+ url,
+ content=digest.get("markdown", ""),
+ headers={"Title": title, "Content-Type": "text/markdown"},
+ )
+ else:
+ resp = await fetcher.post(
+ url,
+ json={
+ "title": title,
+ "totals": totals,
+ "markdown": digest.get("markdown", ""),
+ "timestamp": digest.get("timestamp"),
+ },
+ )
+ except Exception as exc:
+ return {"configured": True, "sent": False, "error": str(exc)[:200]}
+ return {
+ "configured": True,
+ "sent": 200 <= resp.status_code < 300,
+ "status_code": resp.status_code,
+ }
+
+
async def fetch_aoi_sweep(fetcher) -> dict:
"""Collector-daemon entry point for the AOI change sweep.
@@ -1884,10 +1938,14 @@ async def fetch_aoi_sweep(fetcher) -> dict:
supply the store ``fetch_aoi_digest`` needs, so this wrapper opens
the AOI store on the fetcher's own cache database — the same SQLite
file the MCP server and CLI write AOIs to — runs the digest (every
- AOI's snapshot advances), and closes the store handle.
+ AOI's snapshot advances), and closes the store handle. If
+ ``WORLD_INTEL_AOI_WEBHOOK`` is set, a non-quiet digest is POSTed
+ there and the delivery record lands in ``notification``.
"""
store = AOIStore(fetcher.cache.db_path)
try:
- return await fetch_aoi_digest(fetcher, store)
+ digest = await fetch_aoi_digest(fetcher, store)
finally:
store.close()
+ digest["notification"] = await _notify_aoi_changes(fetcher, digest)
+ return digest
diff --git a/src/world_intel_mcp/fetcher.py b/src/world_intel_mcp/fetcher.py
index c6774d3..b4c992f 100644
--- a/src/world_intel_mcp/fetcher.py
+++ b/src/world_intel_mcp/fetcher.py
@@ -79,6 +79,27 @@ class Fetcher:
await self._client.aclose()
self._client = None
+ async def post(
+ self,
+ url: str,
+ *,
+ json: Any = None,
+ content: str | bytes | None = None,
+ headers: dict[str, str] | None = None,
+ timeout: float = 15.0,
+ ) -> httpx.Response:
+ """Outbound POST for operator-configured sinks (webhooks).
+
+ Deliberately outside the get_json machinery: no caching, no
+ retries, no circuit breaking, no rate floor — the target is the
+ operator's own endpoint and delivery/failure semantics belong
+ to the caller. Raises whatever httpx raises.
+ """
+ client = await self._get_client()
+ return await client.post(
+ url, json=json, content=content, headers=headers, timeout=timeout
+ )
+
async def get_json(
self,
url: str,
diff --git a/src/world_intel_mcp/tests/conftest.py b/src/world_intel_mcp/tests/conftest.py
index 289d07a..6b84666 100644
--- a/src/world_intel_mcp/tests/conftest.py
+++ b/src/world_intel_mcp/tests/conftest.py
@@ -30,6 +30,14 @@ def _strip_proxy_env(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv(var, raising=False)
[email protected](autouse=True)
+def _strip_aoi_webhook_env(monkeypatch: pytest.MonkeyPatch) -> None:
+ """A developer's real WORLD_INTEL_AOI_WEBHOOK must never receive
+ POSTs from tests that run the real sweep path."""
+ monkeypatch.delenv("WORLD_INTEL_AOI_WEBHOOK", raising=False)
+ monkeypatch.delenv("WORLD_INTEL_AOI_WEBHOOK_FORMAT", raising=False)
+
+
@pytest.fixture(autouse=True)
def _reset_fetcher_locks() -> None:
"""Reset global asyncio locks between tests to avoid cross-loop binding."""
diff --git a/src/world_intel_mcp/tests/test_aoi.py b/src/world_intel_mcp/tests/test_aoi.py
index ca4f853..5b31989 100644
--- a/src/world_intel_mcp/tests/test_aoi.py
+++ b/src/world_intel_mcp/tests/test_aoi.py
@@ -10,9 +10,12 @@ making HTTP calls itself, so there is no network edge for respx to sit at.
"""
import inspect
+import json
from pathlib import Path
+import httpx
import pytest
+import respx
from world_intel_mcp.analysis import aoi
from world_intel_mcp.analysis.aoi import AOIAlreadyExists, AOIStore
@@ -1793,7 +1796,8 @@ async def test_aoi_sweep_derives_store_from_fetcher_cache(
monkeypatch.setattr(aoi, "fetch_aoi_digest", _fake_digest)
result = await aoi.fetch_aoi_sweep(fetcher)
- assert result == {"marker": "digest"}
+ assert result["marker"] == "digest"
+ assert result["notification"] == {"configured": False}
assert seen["db"] == Path(fetcher.cache.db_path)
@@ -1822,3 +1826,150 @@ async def test_aoi_sweep_sees_aois_defined_via_cache_db(
assert result["count"] == 1
assert result["aois"][0]["name"] == "Pittsburgh"
assert result["aois"][0]["baseline"] is True
+
+
+# ---------------------------------------------------------------------------
+# Sweep webhook notifications (WORLD_INTEL_AOI_WEBHOOK)
+# ---------------------------------------------------------------------------
+
+_HOOK = "https://hooks.example.test/aoi"
+
+
+def _digest_result(new: int, departed: int) -> dict:
+ return {
+ "aois": [{"name": "Pittsburgh"}],
+ "count": 1,
+ "totals": {"new_items": new, "departed_items": departed},
+ "markdown": "# AOI digest\n- M4.9 earthquake entered Pittsburgh",
+ "source": "aoi-digest",
+ "timestamp": "2026-09-01T00:00:00+00:00",
+ }
+
+
+def _patch_digest(monkeypatch: pytest.MonkeyPatch, digest: dict) -> None:
+ async def _fake(fetcher_, store, names=None):
+ return dict(digest)
+
+ monkeypatch.setattr(aoi, "fetch_aoi_digest", _fake)
+
+
+async def test_sweep_notification_unconfigured(
+ fetcher, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ monkeypatch.delenv("WORLD_INTEL_AOI_WEBHOOK", raising=False)
+ _patch_digest(monkeypatch, _digest_result(2, 1))
+ result = await aoi.fetch_aoi_sweep(fetcher)
+ assert result["notification"] == {"configured": False}
+
+
+async def test_sweep_notification_skips_quiet_sweep(
+ fetcher, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """A sweep with zero changes must not POST — the sink is for
+ departures/arrivals, not a heartbeat."""
+ monkeypatch.setenv("WORLD_INTEL_AOI_WEBHOOK", _HOOK)
+ route = respx.post(_HOOK).mock(return_value=httpx.Response(200))
+ _patch_digest(monkeypatch, _digest_result(0, 0))
+ result = await aoi.fetch_aoi_sweep(fetcher)
+ note = result["notification"]
+ assert note["configured"] is True
+ assert note["sent"] is False
+ assert "no changes" in note["reason"]
+ assert not route.called
+
+
+async def test_sweep_notification_posts_json(
+ fetcher, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ monkeypatch.setenv("WORLD_INTEL_AOI_WEBHOOK", _HOOK)
+ monkeypatch.delenv("WORLD_INTEL_AOI_WEBHOOK_FORMAT", raising=False)
+ route = respx.post(_HOOK).mock(return_value=httpx.Response(200))
+ _patch_digest(monkeypatch, _digest_result(2, 1))
+
+ result = await aoi.fetch_aoi_sweep(fetcher)
+
+ note = result["notification"]
+ assert note["sent"] is True
+ assert note["status_code"] == 200
+ body = json.loads(route.calls.last.request.content)
+ assert "2 new" in body["title"] and "1 departed" in body["title"]
+ assert body["totals"] == {"new_items": 2, "departed_items": 1}
+ assert "earthquake entered Pittsburgh" in body["markdown"]
+
+
+async def test_sweep_notification_text_format(
+ fetcher, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """format=text posts the raw markdown body with a Title header —
+ the shape ntfy-style sinks consume directly."""
+ monkeypatch.setenv("WORLD_INTEL_AOI_WEBHOOK", _HOOK)
+ monkeypatch.setenv("WORLD_INTEL_AOI_WEBHOOK_FORMAT", "text")
+ route = respx.post(_HOOK).mock(return_value=httpx.Response(200))
+ _patch_digest(monkeypatch, _digest_result(1, 0))
+
+ result = await aoi.fetch_aoi_sweep(fetcher)
+
+ assert result["notification"]["sent"] is True
+ req = route.calls.last.request
+ assert b"earthquake entered Pittsburgh" in req.content
+ assert "Title" in req.headers
+
+
+async def test_sweep_notification_failure_is_honest(
+ fetcher, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """A dead sink must not fail the sweep (snapshots already advanced)
+ but must not be silent either."""
+ monkeypatch.setenv("WORLD_INTEL_AOI_WEBHOOK", _HOOK)
+ respx.post(_HOOK).mock(side_effect=httpx.ConnectError("refused"))
+ _patch_digest(monkeypatch, _digest_result(1, 0))
+
+ result = await aoi.fetch_aoi_sweep(fetcher)
+
+ assert result["count"] == 1 # sweep itself succeeded
+ note = result["notification"]
+ assert note["sent"] is False
+ assert "refused" in note["error"]
+
+
+async def test_sweep_notification_non_2xx_is_not_sent(
+ fetcher, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ monkeypatch.setenv("WORLD_INTEL_AOI_WEBHOOK", _HOOK)
+ respx.post(_HOOK).mock(return_value=httpx.Response(500))
+ _patch_digest(monkeypatch, _digest_result(1, 0))
+
+ result = await aoi.fetch_aoi_sweep(fetcher)
+
+ note = result["notification"]
+ assert note["sent"] is False
+ assert note["status_code"] == 500
+
+
+async def test_sweep_notification_unknown_format_rejected(
+ fetcher, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ monkeypatch.setenv("WORLD_INTEL_AOI_WEBHOOK", _HOOK)
+ monkeypatch.setenv("WORLD_INTEL_AOI_WEBHOOK_FORMAT", "xml")
+ route = respx.post(_HOOK).mock(return_value=httpx.Response(200))
+ _patch_digest(monkeypatch, _digest_result(1, 0))
+
+ result = await aoi.fetch_aoi_sweep(fetcher)
+
+ note = result["notification"]
+ assert note["sent"] is False
+ assert "xml" in note["error"] and "json" in note["error"]
+ assert not route.called