"""Verify trifecta-bro MCP server tools with local data.""" from __future__ import annotations import json import sys from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(REPO_ROOT / "src")) from mcp_server import get_predictions, get_race, list_pdfs, get_latest_meetings, health def call(name: str, fn): print(f"==> {name}") try: results = fn() assert isinstance(results, list) and len(results) == 1 text = results[0].text obj = json.loads(text) print(json.dumps({"ok": True, "tool": name, "data": obj}, indent=2)[:3000]) except Exception as exc: # noqa: BLE001 print(json.dumps({"ok": False, "tool": name, "error": str(exc)}, indent=2)) print() call("trifecta.health", health) call("trifecta.get_latest_meetings", lambda: get_latest_meetings()) sample_dates = sorted( p.stem.replace("predictions-", "") for p in (REPO_ROOT / "data" / "predictions").glob("predictions-*.json") ) if sample_dates: d = sample_dates[0] call("trifecta.get_predictions", lambda dd=d: get_predictions(dd)) call("trifecta.list_pdfs", list_pdfs) try: payload = json.loads( (REPO_ROOT / "data" / "predictions" / f"predictions-{d}.json").read_text() ) races = payload.get("races", []) if races: rn = races[0].get("race_number") call("trifecta.get_race", lambda dd=d, rn=int(rn): get_race(dd, rn)) except Exception as exc: # noqa: BLE001 print(json.dumps({"ok": False, "tool": "trifecta.get_race", "error": str(exc)}, indent=2)) else: print("No predictions JSON files found under data/predictions")