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
Situation brief and digest: a missing Kp reading is unavailable, not a crash
Phoenix Agent (mac-studio)3e34c43e2437
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 58d185a..82c0b32 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -278,6 +278,11 @@ source here, and no proxy is substituted for any of these measures.request; it now searches the default AI, ML and NLP categories. Thesearch also goes into the first request: before, the first request wassent to the bare API URL and the query only reached a fallback.+- `intel_situation_brief` and `intel_daily_digest` raised a TypeError when+ NOAA SWPC was down, because the space weather source then reports no Kp+ reading. The brief now says "Kp unavailable (no reading)" and+ `metrics_snapshot.kp_index` is null, and the digest lists "Space weather:+ no Kp reading" in `data_gaps`.### Added: tropical cyclone forecast tracks- `intel_cyclones` and `intel_jtwc_cyclones` take `include_forecast`diff --git a/src/world_intel_mcp/analysis/daily_digest.py b/src/world_intel_mcp/analysis/daily_digest.pyindex 7ba50de..a18f12f 100644--- a/src/world_intel_mcp/analysis/daily_digest.py+++ b/src/world_intel_mcp/analysis/daily_digest.py@@ -117,6 +117,15 @@ async def _fetch_current_events(fetcher) -> tuple[dict, list[str]]:)domain_gaps.append(f"{label}: {reason or 'unavailable'}")+ # The space weather source returns current_kp None (no error key) when+ # SWPC fails: that is a missing reading, not a quiet sky.+ if (+ isinstance(space_weather_data, dict)+ and not space_weather_data.get("error")+ and space_weather_data.get("current_kp") is None+ ):+ domain_gaps.append("Space weather: no Kp reading")+# Conflict is a fallback pair (ACLED, then UCDP): only a gap if both failed.acled_ok = isinstance(acled_events, dict) and not acled_events.get("error")ucdp_ok = isinstance(ucdp_events, dict) and not ucdp_events.get("error")diff --git a/src/world_intel_mcp/analysis/situation.py b/src/world_intel_mcp/analysis/situation.pyindex eaea0c1..e1d0782 100644--- a/src/world_intel_mcp/analysis/situation.py+++ b/src/world_intel_mcp/analysis/situation.py@@ -250,8 +250,10 @@ def _extract_metrics(data: dict) -> tuple[dict, list[dict], dict[str, list[int]]_cite(citations, "alerts", n)space = data.get("space_weather", {})- kp = space.get("current_kp", 0) if isinstance(space, dict) else 0- if isinstance(space, dict) and space.get("current_kp") is not None:+ # No Kp reading (SWPC down or breaker open) stays None: it is unknown,+ # not quiet, and rendering it must not raise.+ kp = space.get("current_kp") if isinstance(space, dict) else None+ if kp is not None:n = _add_source(sources,"space_weather",@@ -332,7 +334,7 @@ def _extract_metrics(data: dict) -> tuple[dict, list[dict], dict[str, list[int]]"posture_score": round(posture_score),"risk_level": risk_level,"alerts": alert_count,- "kp_index": round(kp, 1),+ "kp_index": round(kp, 1) if kp is not None else None,"outbreaks": outbreaks,"total_aircraft": total_aircraft,"avg_congestion": avg_congestion,@@ -341,6 +343,13 @@ def _extract_metrics(data: dict) -> tuple[dict, list[dict], dict[str, list[int]]return metrics, sources, citations+def _kp_text(m: dict) -> str:+ """The Kp reading as text; a missing reading says so instead of "None"."""+ if m["kp_index"] is None:+ return "Kp unavailable (no reading)"+ return f"Kp {m['kp_index']}"++def _build_prompt(m: dict, sources: list[dict]) -> str:"""Build an LLM prompt from extracted metrics and the source list."""headline_block = (@@ -362,7 +371,7 @@ CONFLICT: {m["conflicts"]} active eventsSEISMIC: {m["earthquakes"]} earthquakes (max M{m["max_magnitude"]})FIRES: {m["fire_clusters"]} active fire clustersCYBER: {m["cyber_threats"]} tracked IOCs-SPACE WEATHER: Kp {m["kp_index"]}+SPACE WEATHER: {_kp_text(m)}HEALTH: {m["outbreaks"]} high-concern outbreaksAIR TRAFFIC: {m["total_aircraft"]} aircraft airborneTRAFFIC: {m["avg_congestion"]}% avg city congestion@@ -394,7 +403,7 @@ def _fallback_brief(m: dict, citations: dict[str, list[int]]) -> str:f"{_citation_suffix(citations, 'earthquakes', 'fire_clusters')}",f"CYBER: {m['cyber_threats']} IOCs. HEALTH: {m['outbreaks']} high-concern outbreaks."f"{_citation_suffix(citations, 'cyber_threats', 'outbreaks')}",- f"SPACE: Kp {m['kp_index']}. AIR TRAFFIC: {m['total_aircraft']} airborne. CONGESTION: {m['avg_congestion']}%."+ f"SPACE: {_kp_text(m)}. AIR TRAFFIC: {m['total_aircraft']} airborne. CONGESTION: {m['avg_congestion']}%."f"{_citation_suffix(citations, 'kp_index', 'total_aircraft', 'avg_congestion')}",]return "\n".join(lines)diff --git a/src/world_intel_mcp/tests/test_daily_digest.py b/src/world_intel_mcp/tests/test_daily_digest.pyindex 1f7304e..78580bb 100644--- a/src/world_intel_mcp/tests/test_daily_digest.py+++ b/src/world_intel_mcp/tests/test_daily_digest.py@@ -306,3 +306,48 @@ def test_intel_daily_digest_registered_and_dispatched() -> None:handler = tools_pkg.ALL_HANDLERS["intel_daily_digest"]assert "fetch_daily_digest" in inspect.getsource(handler)+++_REAL_FETCH_SPACE_WEATHER = space_weather.fetch_space_weather+++async def test_digest_survives_a_swpc_outage_and_names_the_gap(+ cache, monkeypatch+) -> None:+ """The real space weather source answers a SWPC outage with+ current_kp None and no error key; the digest must still render, cite+ the healthy domains, and list the missing reading as a gap."""+ import httpx+ import respx++ from world_intel_mcp.circuit_breaker import CircuitBreaker+ from world_intel_mcp.fetcher import Fetcher++ _patch_all_domains(monkeypatch)+ monkeypatch.setattr(+ space_weather, "fetch_space_weather", _REAL_FETCH_SPACE_WEATHER+ )+ real_fetcher = Fetcher(cache=cache, breaker=CircuitBreaker(), max_retries=0)+ try:+ with respx.mock(assert_all_called=False) as router:+ router.get(url__startswith="https://services.swpc.noaa.gov/").mock(+ return_value=httpx.Response(503)+ )+ result = await fetch_daily_digest(real_fetcher, vector_store=None)+ finally:+ await real_fetcher.close()++ assert "Space weather: no Kp reading" in result["data_gaps"]+ assert "- Space weather: no Kp reading" in result["markdown"]+ assert not any(s["domain"] == "space_weather" for s in result["sources"])+ assert any(s["domain"] == "earthquakes" for s in result["sources"])+++async def test_digest_with_a_kp_reading_lists_no_space_weather_gap(+ fetcher, monkeypatch+) -> None:+ _patch_all_domains(monkeypatch)+ result = await fetch_daily_digest(fetcher, vector_store=None)+ assert not any(g.startswith("Space weather") for g in result["data_gaps"])diff --git a/src/world_intel_mcp/tests/test_situation.py b/src/world_intel_mcp/tests/test_situation.pyindex 7d583ca..7517efa 100644--- a/src/world_intel_mcp/tests/test_situation.py+++ b/src/world_intel_mcp/tests/test_situation.py@@ -570,3 +570,53 @@ def test_intel_situation_brief_registered_and_dispatched() -> None:handler = tools_pkg.ALL_HANDLERS["intel_situation_brief"]assert "fetch_live_situation_brief" in inspect.getsource(handler)+++# A SWPC outage reaches the brief as the real source's failure shape,+# {"current_kp": None, ...} with no error key, not as a fake {"error": ...}.+_REAL_FETCH_SPACE_WEATHER = space_weather.fetch_space_weather+++async def test_situation_brief_survives_a_swpc_outage(+ monkeypatch: pytest.MonkeyPatch, cache+) -> None:+ from world_intel_mcp.circuit_breaker import CircuitBreaker+ from world_intel_mcp.fetcher import Fetcher++ _patch_all_compact_domains(monkeypatch)+ monkeypatch.setattr(+ space_weather, "fetch_space_weather", _REAL_FETCH_SPACE_WEATHER+ )+ respx.get(url__startswith="https://services.swpc.noaa.gov/").mock(+ return_value=httpx.Response(503)+ )+ respx.post(_OLLAMA_GENERATE).mock(+ side_effect=httpx.ConnectError("no ollama in test env")+ )+ real_fetcher = Fetcher(cache=cache, breaker=CircuitBreaker(), max_retries=0)+ try:+ result = await fetch_live_situation_brief(real_fetcher)+ finally:+ await real_fetcher.close()++ assert result["metrics_snapshot"]["kp_index"] is None+ assert not any(s["domain"] == "space_weather" for s in result["sources"])+ assert "Kp unavailable" in result["brief"]+ assert "Kp None" not in result["brief"]+ assert "Kp 0" not in result["brief"]+++def test_missing_kp_is_unavailable_in_the_prompt_not_zero() -> None:+ overview = _synthetic_overview()+ overview["space_weather"] = {"current_kp": None, "timestamp": None}+ metrics, sources, _ = _extract_metrics(overview)+ from world_intel_mcp.analysis.situation import _build_prompt++ prompt = _build_prompt(metrics, sources)+ assert "SPACE WEATHER: Kp unavailable (no reading)" in prompt+ assert metrics["kp_index"] is None+ # A real reading still renders as before.+ metrics_ok, sources_ok, _ = _extract_metrics(_synthetic_overview())+ assert "SPACE WEATHER: Kp 6.0" in _build_prompt(metrics_ok, sources_ok)