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
Collection health: restore root logging on a failed roster import and name the roster (review r2 behavior F6)
Phoenix Agent (mac-studio)a2cb9be942fb
diff --git a/src/world_intel_mcp/dashboard/app.py b/src/world_intel_mcp/dashboard/app.pyindex dc91d2b..6605068 100644--- a/src/world_intel_mcp/dashboard/app.py+++ b/src/world_intel_mcp/dashboard/app.py@@ -882,18 +882,28 @@ def _collector_roster() -> list[str]:(level INFO); in this process, where nothing configures the rootlogger, that would attach a stderr handler and start printing a lineper upstream request. The root logger's handlers and level are put- back as they were. Called on the event loop thread, so no other- request reconfigures logging in between."""+ back as they were, on every path: basicConfig can add its handler and+ then raise (an unknown WORLD_INTEL_LOG_LEVEL). Called on the event loop+ thread, so no other request reconfigures logging in between. Raises+ _RosterUnavailable when the collector module cannot be imported."""root = logging.getLogger()handlers, level = list(root.handlers), root.level- from world_intel_mcp.collector import SOURCES-- for handler in [h for h in root.handlers if h not in handlers]:- root.removeHandler(handler)- root.setLevel(level)+ try:+ from world_intel_mcp.collector import SOURCES+ except Exception as exc:+ raise _RosterUnavailable(f"{type(exc).__name__}: {exc}") from exc+ finally:+ for handler in [h for h in root.handlers if h not in handlers]:+ root.removeHandler(handler)+ root.setLevel(level)return [name for name, _, _, _ in SOURCES]+class _RosterUnavailable(Exception):+ """The collector roster could not be read; the history store was not+ involved."""++def _read_collection_health(db_path: Path, roster: list[str], source: str | None) -> dict:"""Open the history store, read collection health, close. Runs in aworker thread, so the store's SQLite connection is created and used on@@ -911,12 +921,17 @@ async def api_collection_health(request):(``?source=`` for one source). A store that cannot be opened or read isa 503 with the reason and the database path, never a list of zeros; adatabase the collector never wrote reports every source ``never_run``;- an unknown source is a 404 naming the known ones."""+ an unknown source is a 404 naming the known ones; a collector module+ that cannot be imported is a 503 saying so, not blaming the store."""source = request.query_params.get("source") or None+ try:+ roster = _collector_roster()+ except _RosterUnavailable as exc:+ logger.warning("Collector roster unavailable: %s", exc)+ return JSONResponse({"error": f"collector roster unavailable: {exc}"}, status_code=503)db_path = Nonetry:db_path = _history_db_path()- roster = _collector_roster()data = await asyncio.to_thread(_read_collection_health, db_path, roster, source)except Exception as exc:logger.warning("Collection health unavailable: %s", exc)diff --git a/src/world_intel_mcp/tests/test_dashboard_research.py b/src/world_intel_mcp/tests/test_dashboard_research.pyindex 807d4ee..8c3a1da 100644--- a/src/world_intel_mcp/tests/test_dashboard_research.py+++ b/src/world_intel_mcp/tests/test_dashboard_research.py@@ -631,6 +631,30 @@ def test_reading_the_roster_leaves_root_logging_as_it_was(monkeypatch) -> None:assert roster == [name for name, _, _, _ in collector.SOURCES]+def test_roster_import_failure_restores_logging_and_names_the_roster(client, tmp_path, monkeypatch) -> None:+ """basicConfig adds its handler, then rejects a lowercase level and the+ collector import raises. The handler and level are still put back (the+ next import would otherwise find a handler and succeed with it left+ attached), and the 503 names the roster, not the history store."""+ import world_intel_mcp+ from world_intel_mcp import collector++ root = logging.getLogger()+ monkeypatch.setattr(root, "handlers", [])+ monkeypatch.setattr(root, "level", logging.WARNING)+ monkeypatch.delitem(sys.modules, "world_intel_mcp.collector")+ monkeypatch.setattr(world_intel_mcp, "collector", collector)+ monkeypatch.setenv("WORLD_INTEL_LOG_LEVEL", "debug")+ monkeypatch.setattr(dashboard_app, "_history_db_path", lambda: tmp_path / "cache.db")+ for _ in range(2): # the same answer every time, not a 503 then a 200+ r = client.get("/api/collection-health")+ assert (r.status_code, r.json()) == (+ 503, {"error": "collector roster unavailable: ValueError: Unknown level: 'debug'"}+ )+ assert root.handlers == []+ assert root.level == logging.WARNING++# ---------------------------------------------------------------------------# Page: static checks (no JavaScript runtime needed)# ---------------------------------------------------------------------------