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.
Python ai-toolsai-watchanthropicclaudecybersecuritydashboardgeofencinggeopoliticalgeospatialintelligencemarketsmcpmigrationmilitarymodel-context-protocolnuclearosintreal-timespace-weatherthreat-intelligence
Fixes #17: GDELT fetch failures no longer read as a genuine zero-hit search
Phoenix Agent (Marcs-Mac-Studio)1481d6e08461
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1b16bd1..52a70d5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -53,6 +53,14 @@same field.- Test counts in the docs lagged the 0.2.0 regression tests (claimed 244total when 0.2.0 itself shipped 256). Corrected to the live count.+- `fetch_gdelt_search` returned a clean zero-article payload when the+ GDELT API call failed, byte-identical to a genuine zero-hit search:+ same class as the ACLED defect fixed in 0.2.0 (#3). Observed live as a+ 429: GDELT asks for one request per 5 seconds. Failure paths now carry+ `error`, `degraded`, and `reason` keys, keeping `articles`/`count` in+ their normal empty shape; `intel_aoi_brief`'s news domain now surfaces+ the failure as a `data_gap` instead of reading as "no news mentions"+ (#17).## 0.2.0 - 2026-08-16diff --git a/src/world_intel_mcp/analysis/aoi.py b/src/world_intel_mcp/analysis/aoi.pyindex e356951..f5f96d1 100644--- a/src/world_intel_mcp/analysis/aoi.py+++ b/src/world_intel_mcp/analysis/aoi.py@@ -717,8 +717,15 @@ async def fetch_aoi_brief(fetcher, store: AOIStore, name: Any) -> dict:)# News headline mentions ------------------------------------------------ articles = news_result.get("articles", []) if isinstance(news_result, dict) else []- counts["news"] = len(articles)+ if isinstance(news_result, dict) and news_result.get("error"):+ data_gaps.append(f"News: {news_result['error']}")+ counts["news"] = 0+ articles: list = []+ else:+ articles = (+ news_result.get("articles", []) if isinstance(news_result, dict) else []+ )+ counts["news"] = len(articles)for art in articles[:10]:title = art.get("title")if not title:diff --git a/src/world_intel_mcp/sources/news.py b/src/world_intel_mcp/sources/news.pyindex d627453..6ff549b 100644--- a/src/world_intel_mcp/sources/news.py+++ b/src/world_intel_mcp/sources/news.py@@ -762,7 +762,16 @@ async def fetch_gdelt_search(if data is None:logger.warning("GDELT API returned no data for query=%s mode=%s", query, mode)+ # A live fetch failure (GDELT rate limits at roughly one request per+ # 5 seconds, plus 500s and malformed payloads) must not be+ # byte-identical to a genuine zero-hit search, same class as the+ # ACLED defect fixed in #3. Keep articles/timeline/count in their+ # normal empty shape so existing callers that don't check "error"+ # or "degraded" still iterate an empty list rather than crashing.return {+ "error": "GDELT fetch failed (rate limited, API error, or malformed response)",+ "degraded": True,+ "reason": "gdelt_fetch_failed","articles": [] if mode == "artlist" else None,"timeline": None if mode == "artlist" else [],"count": 0,diff --git a/src/world_intel_mcp/tests/test_aoi.py b/src/world_intel_mcp/tests/test_aoi.pyindex c13e314..d209385 100644--- a/src/world_intel_mcp/tests/test_aoi.py+++ b/src/world_intel_mcp/tests/test_aoi.py@@ -492,6 +492,33 @@ async def test_fetch_aoi_brief_reports_data_gap_for_unscopable_domain(assert not any(s["domain"] == "conflict_events" for s in result["sources"])+async def test_fetch_aoi_brief_reports_data_gap_when_gdelt_fails(+ fetcher, aoi_store_with_pittsburgh: AOIStore, monkeypatch: pytest.MonkeyPatch+) -> None:+ """Issue #17: a GDELT fetch failure (rate limit, API error) must+ surface as a data_gap here, the same as every other domain in this+ brief, not read as "no news mentions" the way it silently did+ before fetch_gdelt_search() carried an honest error/degraded shape."""+ _patch_all_domains(monkeypatch)++ async def _broken_gdelt(fetcher, **kwargs):+ return {+ "error": "GDELT fetch failed (rate limited, API error, or malformed response)",+ "degraded": True,+ "reason": "gdelt_fetch_failed",+ "articles": [],+ "count": 0,+ }++ monkeypatch.setattr(news, "fetch_gdelt_search", _broken_gdelt)++ result = await aoi.fetch_aoi_brief(fetcher, aoi_store_with_pittsburgh, "Pittsburgh")++ assert any("News" in gap for gap in result["data_gaps"])+ assert not any(s["domain"] == "news" for s in result["sources"])++@pytest.mark.asyncioasync def test_fetch_aoi_brief_reports_data_gap_when_no_wildfire_region_overlaps(fetcher, tmp_path: Path, monkeypatch: pytest.MonkeyPatchdiff --git a/src/world_intel_mcp/tests/test_sources.py b/src/world_intel_mcp/tests/test_sources.pyindex fac26f0..051c757 100644--- a/src/world_intel_mcp/tests/test_sources.py+++ b/src/world_intel_mcp/tests/test_sources.py@@ -809,6 +809,72 @@ async def test_fetch_acled_events_genuine_zero_has_no_error(assert result["count"] == 0+# ---------------------------------------------------------------------------+# News (GDELT search)+# ---------------------------------------------------------------------------+++async def test_fetch_gdelt_search_distinguishes_rate_limit_from_zero_hits(+ fetcher: Fetcher, monkeypatch: pytest.MonkeyPatch+) -> None:+ """Issue #17: GDELT rate-limits at roughly one request per 5 seconds.+ A 429 that exhausts every retry must not be byte-identical to a+ genuine zero-hit search: same class as the ACLED defect fixed in #3.+ Exercises the real Fetcher retry path via respx (not a monkeypatched+ get_json) so the failure mode actually hit live (429) is what's under+ test. The exponential backoff sleep is stubbed to keep the test fast;+ that doesn't change what's exercised, only how long waiting for it+ takes."""+ import asyncio as asyncio_mod++ from world_intel_mcp.sources.news import fetch_gdelt_search++ async def _no_sleep(*args, **kwargs) -> None:+ return None++ monkeypatch.setattr(asyncio_mod, "sleep", _no_sleep)++ respx.get(url__regex=r".*api\.gdeltproject\.org.*").mock(+ return_value=httpx.Response(429, text="rate limited")+ )++ result = await fetch_gdelt_search(+ fetcher, query="Pittsburgh", mode="artlist", limit=10+ )++ assert result.get("error") is not None+ assert result.get("degraded") is True+ assert result.get("reason") == "gdelt_fetch_failed"+ # Additive-only: articles/count keep their normal shape (empty list / 0,+ # not None) so existing callers that don't check "error" or "degraded"+ # still iterate an empty list instead of crashing.+ assert result["articles"] == []+ assert result["count"] == 0+++async def test_fetch_gdelt_search_genuine_zero_has_no_error(fetcher: Fetcher) -> None:+ """A real zero-hit query (fetch succeeds, GDELT returns no articles)+ must NOT be flagged as degraded: only actual fetch failures are."""+ from world_intel_mcp.sources.news import fetch_gdelt_search++ respx.get(url__regex=r".*api\.gdeltproject\.org.*").mock(+ return_value=httpx.Response(200, json={"articles": []})+ )++ result = await fetch_gdelt_search(+ fetcher, query="zzzznohitszzzz", mode="artlist", limit=10+ )++ assert result.get("error") is None+ assert result.get("degraded") is None+ assert result["articles"] == []+ assert result["count"] == 0++# ---------------------------------------------------------------------------# Hacker News# ---------------------------------------------------------------------------