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 #23: climate zones that fail to fetch are named, not silently dropped
Phoenix Agent (Marcs-Mac-Studio)387eb78ddd6a
diff --git a/src/world_intel_mcp/sources/climate.py b/src/world_intel_mcp/sources/climate.pyindex 5136adf..4202390 100644--- a/src/world_intel_mcp/sources/climate.py+++ b/src/world_intel_mcp/sources/climate.py@@ -46,6 +46,7 @@ _CACHE_TTL = 1800 # 30 minutes# Helpers# ---------------------------------------------------------------------------+def _utc_now_iso() -> str:return datetime.now(timezone.utc).isoformat()@@ -104,9 +105,7 @@ def _compute_anomalies(# Percentage anomaly (guard against near-zero baseline)precip_anomaly_pct = round(- ((current_precip_mm - baseline_precip_mm)- / max(baseline_precip_mm, 0.1))- * 100,+ ((current_precip_mm - baseline_precip_mm) / max(baseline_precip_mm, 0.1)) * 100,1,)@@ -128,6 +127,7 @@ def _compute_anomalies(# Public API# ---------------------------------------------------------------------------+async def fetch_climate_anomalies(fetcher: Fetcher,zones: list[str] | None = None,@@ -157,12 +157,12 @@ async def fetch_climate_anomalies(# Determine which zones to fetchif zones is not None:- target_zones = {- k: v for k, v in CLIMATE_ZONES.items() if k in zones- }+ target_zones = {k: v for k, v in CLIMATE_ZONES.items() if k in zones}if not target_zones:logger.warning("No valid zone keys in %s", zones)return {+ "error": f"No valid zone keys in {zones!r}; "+ f"valid keys: {sorted(CLIMATE_ZONES)}","zones": {},"significant_anomalies": [],"source": "open-meteo",@@ -223,30 +223,38 @@ async def fetch_climate_anomalies(anomalies = _compute_anomalies(current_data, baseline_data)- return (zone_key, {- "name": zone_info["name"],- "lat": lat,- "lon": lon,- **anomalies,- })+ return (+ zone_key,+ {+ "name": zone_info["name"],+ "lat": lat,+ "lon": lon,+ **anomalies,+ },+ )# Fetch all target zones in paralleltasks = [- _fetch_zone(zone_key, zone_info)- for zone_key, zone_info in target_zones.items()+ _fetch_zone(zone_key, zone_info) for zone_key, zone_info in target_zones.items()]results = await asyncio.gather(*tasks)- # Assemble response+ # Assemble response. A zone whose fetch failed is NAMED in+ # unavailable_zones, not silently omitted: before this, a full+ # Open-Meteo outage returned {"zones": {}} indistinguishable in+ # shape from a valid run (the silent-degradation class).zone_results: dict[str, dict] = {}significant_anomalies: list[str] = []+ unavailable_zones: list[str] = []for zone_key, zone_data in results:if zone_data is None:+ unavailable_zones.append(zone_key)continuezone_results[zone_key] = zone_dataif zone_data["is_significant"]:significant_anomalies.append(zone_key)+ unavailable_zones.sort()response = {"zones": zone_results,@@ -254,6 +262,15 @@ async def fetch_climate_anomalies("source": "open-meteo","timestamp": _utc_now_iso(),}+ if unavailable_zones:+ response["unavailable_zones"] = unavailable_zones+ response["degraded"] = True+ if not zone_results:+ response["error"] = (+ "Open-Meteo unavailable for all requested zones: "+ + ", ".join(unavailable_zones)+ )+ response["reason"] = "open_meteo_fetch_failed"# Cache composite resultcache_label = "selected" if zones is not None else "all"diff --git a/src/world_intel_mcp/tests/test_sources_climate.py b/src/world_intel_mcp/tests/test_sources_climate.pyindex 010916f..87b985e 100644--- a/src/world_intel_mcp/tests/test_sources_climate.py+++ b/src/world_intel_mcp/tests/test_sources_climate.py@@ -104,13 +104,14 @@ async def test_fetch_climate_anomalies_unknown_zone(fetcher: Fetcher) -> None:@respx.mock@pytest.mark.asyncio-async def test_fetch_climate_anomalies_api_failure_omits_zone(+async def test_fetch_climate_anomalies_api_failure_is_marked_degraded(fetcher: Fetcher, monkeypatch: pytest.MonkeyPatch) -> None:- """Suspected bug (documented, not fixed): a zone whose fetch fails is- silently omitted — the response carries no error/data_gaps marker, so a- full Open-Meteo outage returns {"zones": {}} indistinguishable in shape- from a valid run over zero requested zones."""+ """Regression (silent-degradation class): a zone whose fetch failed+ used to be silently omitted — a full Open-Meteo outage returned+ {"zones": {}} indistinguishable in shape from a valid run. Failed+ zones must now be named in unavailable_zones, and an all-zones+ failure must carry error/degraded/reason."""async def _no_sleep(*args, **kwargs) -> None:return None@@ -124,7 +125,10 @@ async def test_fetch_climate_anomalies_api_failure_omits_zone(result = await fetch_climate_anomalies(fetcher, zones=["sahel"])assert result["zones"] == {}assert result["significant_anomalies"] == []- assert "error" not in result # current (dishonest-quiet) behavior+ assert result["unavailable_zones"] == ["sahel"]+ assert result["degraded"] is True+ assert result["reason"] == "open_meteo_fetch_failed"+ assert "unavailable" in result["error"].lower()def test_compute_anomalies_significant_temp() -> None:@@ -171,3 +175,41 @@ def test_safe_avg_and_sum() -> None:assert _safe_avg([1.0, None, 3.0]) == 2.0assert _safe_sum([]) == 0.0assert _safe_sum([1.5, None, 2.5]) == 4.0+++async def test_fetch_climate_anomalies_partial_failure_names_zone(+ fetcher: Fetcher, monkeypatch: pytest.MonkeyPatch+) -> None:+ """One zone failing while another succeeds is degraded (with the+ failed zone named) but NOT an error: partial data is still data."""++ async def _no_sleep(*args, **kwargs) -> None:+ return None++ monkeypatch.setattr(asyncio_mod, "sleep", _no_sleep)++ def _by_zone(request):+ # Sahel is lat 14.0, arctic is lat 80.0 (CLIMATE_ZONES): fail+ # every sahel request (retries included), serve arctic.+ if request.url.params.get("latitude") == "14.0":+ return httpx.Response(500)+ return httpx.Response(+ 200,+ json={+ "daily": {+ "temperature_2m_max": [10.0] * 7,+ "temperature_2m_min": [0.0] * 7,+ "precipitation_sum": [1.0] * 7,+ }+ },+ )++ respx.get(url__regex=r".*archive-api\.open-meteo\.com.*").mock(side_effect=_by_zone)++ result = await fetch_climate_anomalies(fetcher, zones=["sahel", "arctic"])+ assert list(result["zones"]) == ["arctic"]+ assert result["unavailable_zones"] == ["sahel"]+ assert result["degraded"] is True+ assert "error" not in result