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
Collector: list upstream-error payloads apart from data; never store a stale copy as new
Phoenix Agent (mac-studio)1b7d4ce32716
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f817103..771a296 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -55,6 +55,16 @@default 1,024 open-file limit. Test runs also no longer leave`wim-server-test-*` directories in the system temp directory.+### Fixed: the collector cycle summary separates data from errors+- A source that answers with an upstream error (`{"error": ...}`) still+ counts as a completed fetch, but the cycle summary now lists it under+ `upstream_errors`, and `intel-collector` prints how many of the+ "succeeded" sources stored nothing. Before, such a cycle read as data+ collected.+- A stale cache copy (`_stale`) is no longer stored in the vector store as+ if it were collected this cycle; the summary lists it under+ `stale_not_stored`.+### Added: liquidity and money (Phase 29)Keyless sources only: the FRED graph CSV (`fred.stlouisfed.org/graph/fredgraph.csv`,allowed by robots.txt with `Crawl-delay: 1`, honored by a 1 s `fred-graph` ratediff --git a/src/world_intel_mcp/collector.py b/src/world_intel_mcp/collector.pyindex a1b143e..38bdb11 100644--- a/src/world_intel_mcp/collector.py+++ b/src/world_intel_mcp/collector.py@@ -270,7 +270,11 @@ async def collect_once() -> dict:"""Run one collection cycle across all sources.- Returns dict with counts of successes, failures, and skipped.+ Returns dict with counts of successes and failures. A fetch that+ completed counts as a success even when its payload carries an upstream+ error; those are also listed in ``upstream_errors`` and are not stored.+ Stale cache copies (``_stale``) are listed in ``stale_not_stored`` and+ are not stored in the vector store as this cycle's data."""start = time.time()sources_to_run = [@@ -301,6 +305,8 @@ async def collect_once(successes = 0failures = 0errors = []+ upstream_errors = []+ stale_not_stored = []outcomes = []for (source_name, _, _, _), item in zip(sources_to_run, results):@@ -328,11 +334,21 @@ async def collect_once(errors.append(f"{name}: {error}")logger.warning("Collect %s failed: %s", name, error)elif data is not None:+ # A completed fetch counts as a success even when its payload+ # carries an upstream error; that error is listed separately so+ # the summary never reads it as data collected.successes += 1- # The fetcher already stores in vector_store via its hook,- # but for sources that return composite data (analysis modules),- # we also store the high-level result directly.- if not isinstance(data, dict) or not data.get("error"):+ if isinstance(data, dict) and data.get("error"):+ upstream_errors.append(f"{name}: {str(data['error'])[:100]}")+ logger.warning("Collect %s returned an upstream error: %s", name, data["error"])+ elif isinstance(data, dict) and data.get("_stale"):+ # A stale cache copy is old data; storing it again would+ # file it in the vector store as if collected this cycle.+ stale_not_stored.append(name)+ else:+ # The fetcher already stores in vector_store via its hook,+ # but for sources that return composite data (analysis modules),+ # we also store the high-level result directly.await vector_store.store(name, data)else:failures += 1@@ -348,6 +364,8 @@ async def collect_once("successes": successes,"failures": failures,"errors": errors[:10],+ "upstream_errors": upstream_errors,+ "stale_not_stored": stale_not_stored,"vector_store_points": stats.get("points_count", 0),"history": history,}@@ -474,9 +492,14 @@ def main():else:summary = asyncio.run(run_once(source_filter=args.sources))print("Collection complete:")- print(- f" Sources: {summary['successes']}/{summary['sources_attempted']} succeeded"- )+ upstream = summary.get("upstream_errors") or []+ line = f" Sources: {summary['successes']}/{summary['sources_attempted']} succeeded"+ if upstream:+ line += f"; {len(upstream)} of them returned an upstream error and stored nothing"+ print(line)+ stale = summary.get("stale_not_stored") or []+ if stale:+ print(f" Stale copies, not stored as new ({len(stale)}): {', '.join(sorted(stale))}")print(f" Time: {summary['cycle_time_s']}s")print(f" Vector store: {summary['vector_store_points']} points")history = summary.get("history") or {}@@ -494,6 +517,10 @@ def main():print(f" Errors ({len(summary['errors'])}):")for e in summary["errors"]:print(f" - {e}")+ if upstream:+ print(f" Upstream errors ({len(upstream)}):")+ for e in upstream:+ print(f" - {e}")sys.exit(0 if summary["failures"] == 0 else 1)diff --git a/src/world_intel_mcp/tests/test_collector_runtime.py b/src/world_intel_mcp/tests/test_collector_runtime.pyindex 170067e..97bff50 100644--- a/src/world_intel_mcp/tests/test_collector_runtime.py+++ b/src/world_intel_mcp/tests/test_collector_runtime.py@@ -222,6 +222,60 @@ async def test_collect_once_error_dict_is_success_but_not_stored(assert vs.stored == []+async def test_collect_once_lists_upstream_errors_apart_from_data(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """The error dict stays a completed fetch (pinned above), but the summary+ names it, so a cycle where every source answered with an error never+ reads as data collected."""+ good = {"count": 2, "earthquakes": [{"id": "a"}, {"id": "b"}]}+ monkeypatch.setattr(+ collector,+ "_import_fetch_fn",+ _importer_for(+ {+ "earthquakes": _returning(good),+ "acled_events": _returning({"error": "ACLED token missing"}),+ }+ ),+ )+ vs = FakeVectorStore()++ summary = await collector.collect_once(+ FakeFetcher(), vs, source_filter={"earthquakes", "acled_events"}+ )++ assert (summary["successes"], summary["failures"]) == (2, 0)+ assert summary["upstream_errors"] == ["acled_events: ACLED token missing"]+ assert summary["stale_not_stored"] == []+ assert vs.stored == [("earthquakes", good)]+++async def test_collect_once_does_not_store_a_stale_copy_as_new(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """A stale cache copy is served so callers see something, but it is old+ data: the collector must not file it in the vector store as this cycle's+ collection. It still counts as a completed fetch."""+ stale = {"warnings": [{"id": "NAVAREA IV 1/26"}], "_stale": True, "_stale_age_seconds": 86400}+ fresh = {"quotes": [{"symbol": "TSTX", "price": 1.0}]}+ monkeypatch.setattr(+ collector,+ "_import_fetch_fn",+ _importer_for({"nav_warnings": _returning(stale), "market_quotes": _returning(fresh)}),+ )+ vs = FakeVectorStore()++ summary = await collector.collect_once(+ FakeFetcher(), vs, source_filter={"nav_warnings", "market_quotes"}+ )++ assert (summary["successes"], summary["failures"]) == (2, 0)+ assert summary["stale_not_stored"] == ["nav_warnings"]+ assert summary["upstream_errors"] == []+ assert vs.stored == [("market_quotes", fresh)]++async def test_collect_once_unfiltered_attempts_every_source(monkeypatch: pytest.MonkeyPatch,) -> None:@@ -413,6 +467,34 @@ def test_main_single_run_failure_exits_one_and_lists_errors(assert "acled_events: boom" in out+def test_main_names_upstream_errors_and_stale_copies(+ monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture+) -> None:+ async def fake_run_once(source_filter=None):+ return {+ "successes": 3,+ "sources_attempted": 3,+ "cycle_time_s": 1.0,+ "vector_store_points": 7,+ "errors": [],+ "failures": 0,+ "upstream_errors": ["acled_events: ACLED token missing"],+ "stale_not_stored": ["nav_warnings"],+ }++ monkeypatch.setattr(collector, "run_once", fake_run_once)+ monkeypatch.setattr(collector.sys, "argv", ["intel-collector"])++ with pytest.raises(SystemExit) as excinfo:+ collector.main()++ assert excinfo.value.code == 0 # completed fetches; the exit code is unchanged+ out = capsys.readouterr().out+ assert "3/3 succeeded; 1 of them returned an upstream error and stored nothing" in out+ assert "Upstream errors (1):\n - acled_events: ACLED token missing" in out+ assert "Stale copies, not stored as new (1): nav_warnings" in out++def test_main_daemon_flag_forwards_interval_and_sources(monkeypatch: pytest.MonkeyPatch,) -> None: