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.

Fixes #22: UNHCR outage no longer reads as zero refugees worldwide

Phoenix Agent (Marcs-Mac-Studio)9a42f4db23ab
diff --git a/src/world_intel_mcp/sources/displacement.py b/src/world_intel_mcp/sources/displacement.py
index e41fd50..c74e48f 100644
--- a/src/world_intel_mcp/sources/displacement.py
+++ b/src/world_intel_mcp/sources/displacement.py
@@ -59,7 +59,16 @@ async def fetch_displacement_summary(
if data is None:
logger.warning("UNHCR API returned no data")
+ # Honest outage shape: without these markers this return was
+ # byte-shape identical to a world with zero displaced persons
+ # (the fail-reads-as-success class). The zeroed structure stays
+ # so field-reading consumers (cli.py reads global_totals
+ # directly) keep working; error/degraded/reason distinguish
+ # "UNHCR is down" from "zero refugees worldwide".
return {
+ "error": "UNHCR API unavailable (no live or cached data)",
+ "degraded": True,
+ "reason": "unhcr_fetch_failed",
"by_origin": [],
"global_totals": {
"total_refugees": 0,
@@ -115,15 +124,17 @@ async def fetch_displacement_summary(
+ totals["stateless"]
+ totals["ooc"]
)
- by_origin.append({
- "country": country,
- "refugees": totals["refugees"],
- "asylum_seekers": totals["asylum_seekers"],
- "internally_displaced": totals["idps"],
- "stateless": totals["stateless"],
- "others_of_concern": totals["ooc"],
- "total_displaced": total_displaced,
- })
+ by_origin.append(
+ {
+ "country": country,
+ "refugees": totals["refugees"],
+ "asylum_seekers": totals["asylum_seekers"],
+ "internally_displaced": totals["idps"],
+ "stateless": totals["stateless"],
+ "others_of_concern": totals["ooc"],
+ "total_displaced": total_displaced,
+ }
+ )
# Sort by total_displaced descending, take top 30
by_origin.sort(key=lambda e: e["total_displaced"], reverse=True)
diff --git a/src/world_intel_mcp/tests/test_sources_displacement.py b/src/world_intel_mcp/tests/test_sources_displacement.py
index 74a615f..013f98d 100644
--- a/src/world_intel_mcp/tests/test_sources_displacement.py
+++ b/src/world_intel_mcp/tests/test_sources_displacement.py
@@ -99,14 +99,15 @@ async def test_fetch_displacement_summary_year_coerced_from_string(
@respx.mock
@pytest.mark.asyncio
-async def test_fetch_displacement_summary_api_down_returns_zeroed_shape(
+async def test_fetch_displacement_summary_api_down_is_marked_degraded(
fetcher: Fetcher, monkeypatch: pytest.MonkeyPatch
) -> None:
- """Suspected bug (documented, not fixed): a UNHCR outage returns
- global_totals of all zeros with NO error/degraded key — byte-shape
- identical to a world with zero displaced persons. This is the
- fail-reads-as-success class this repo treats as its worst bug family;
- flagged in the review report rather than fixed here."""
+ """Regression (fail-reads-as-success class): a UNHCR outage used to
+ return global_totals of all zeros with NO error/degraded key —
+ byte-shape identical to a world with zero displaced persons. The
+ outage shape must carry honest markers; the zeroed structure stays
+ for consumers that read fields without checking (cli.py reads
+ global_totals directly)."""
async def _no_sleep(*args, **kwargs) -> None:
return None
@@ -119,7 +120,9 @@ async def test_fetch_displacement_summary_api_down_returns_zeroed_shape(
assert result["by_origin"] == []
assert result["count"] == 0
assert result["global_totals"]["grand_total"] == 0
- assert "error" not in result # current (dishonest-quiet) behavior
+ assert "unavailable" in result["error"].lower()
+ assert result["degraded"] is True
+ assert result["reason"] == "unhcr_fetch_failed"
def test_safe_int() -> None: