#!/usr/bin/env python3 """ run_test_queries.py — execute the 50 demo queries from TEST_QUERIES.md against the SAME code paths the MCP tools use (direct import of rag_server functions; FastMCP's @mcp.tool() returns the original fn, so direct calls == tool calls). Run ONLY with the rag_server process stopped (embedded-Qdrant locks). Output: TEST_RESULTS.md (query -> tool -> top hits, truncated). """ import json import sys import time from pathlib import Path sys.path.insert(0, "/Users/dmpantiu/copernicus_mcp/marine_rag") import rag_server as R OUT = Path("/Users/dmpantiu/copernicus_mcp/TEST_RESULTS.md") def j(x, n=900): try: s = json.dumps(x, ensure_ascii=False, indent=1, default=str) except Exception: s = str(x) return s[:n] + (" …[cut]" if len(s) > n else "") CASES = [ # ── A. L1 discover ── ("A1", "search_datasets", dict(query="global daily gap-free sea surface temperature", top_k=3)), ("A2", "search_datasets", dict(query="river discharge forecast for European rivers", top_k=3)), ("A3", "search_datasets", dict(query="satellite observations of atmospheric CO2 concentration", store="CDS", top_k=3)), ("A4", "search_datasets", dict(query="high resolution regional reanalysis Europe", top_k=3)), ("A5", "search_datasets", dict(query="chlorophyll concentration Baltic Sea", store="CMEMS", top_k=3)), ("A6", "search_datasets", dict(query="soil moisture climate data record", top_k=3)), ("A7", "search_datasets", dict(query="global fire emissions for atmosphere modelling", store="ADS", top_k=3)), ("A8", "search_datasets", dict(query="Arctic sea ice concentration long time series", top_k=4)), # ── B. L2 CMEMS deep docs ── ("B9", "get_dataset_docs", dict(dataset_or_product_id="GLOBAL_ANALYSISFORECAST_PHY_001_024", question="What is the SST accuracy?", top_k=3)), ("B10", "get_dataset_docs", dict(dataset_or_product_id="GLOBAL_MULTIYEAR_PHY_001_030", question="Which in-situ observations are assimilated?", top_k=3)), ("B11", "search_docs", dict(query="known biases Mediterranean wave model", doc_type="QUID", top_k=3)), ("B12", "get_dataset_docs", dict(dataset_or_product_id="SEALEVEL_GLO_PHY_L4_MY_008_047", question="grid resolution and projection", top_k=3)), ("B13", "search_docs", dict(query="ocean colour chlorophyll validation against in-situ matchups", top_k=3)), ("B14", "search_docs", dict(query="Baltic sea ice product update frequency timeliness", top_k=3)), ("B15", "search_docs", dict(query="Class 4 forecast verification metrics against observations", top_k=3)), ("B16", "search_docs", dict(query="estimated accuracy numbers temperature salinity", top_k=3)), # ── C. L2 CDS/ADS/EWDS deep docs ── ("C17", "search_deep_docs", dict(query="ERA5 uncertainty estimation ensemble spread", store="CDS", top_k=3)), ("C18", "search_deep_docs", dict(query="EAC4 aerosol optical depth validation AERONET", store="ADS", top_k=3)), ("C19", "search_deep_docs", dict(query="GloFAS forecast skill evaluation", store="EWDS", top_k=3)), ("C20", "search_deep_docs", dict(query="ERA5-Land soil layer depths definition", top_k=3)), ("C21", "search_deep_docs", dict(query="CERRA domain extent horizontal resolution", top_k=3)), ("C22", "search_deep_docs", dict(query="SEAS5 bias correction calibration", top_k=3)), # ── D. EQC quality ── ("D23", "get_eqc_quality_report", dict(query="completeness of the satellite methane XCH4 record", top_k=3)), ("D24", "get_eqc_quality_report", dict(query="are CMIP6 models consistent for temperature projections", dataset_id="projections-cmip6", top_k=3)), ("D25", "get_eqc_quality_report", dict(query="seasonal forecast skill for precipitation", top_k=3)), ("D26", "get_eqc_quality_report", dict(query="glacier mass change trend assessment maturity", top_k=3)), ("D27", "get_eqc_quality_report", dict(query="uncertainty of Greenland ice sheet velocity", top_k=3)), ("D28", "get_eqc_quality_report", dict(query="ERA5 representation of extreme events heat waves", top_k=3)), # ── E. code notebooks ── ("E29", "get_dataset_code", dict(dataset_id="reanalysis-era5-single-levels")), ("E30", "get_dataset_code", dict(dataset_id="GLOBAL_ANALYSISFORECAST_PHY_001_024")), ("E31", "get_dataset_code", dict(dataset_id="cems-glofas-historical")), ("E32", "get_dataset_code", dict(dataset_id="cams-europe-air-quality-forecasts", kind="plot")), ("E33", "get_dataset_code", dict(dataset_id="satellite-sea-surface-temperature")), # ── F. L3 publications ── ("F34", "search_publications", dict(query="marine heatwave detection from SST reanalysis", top_k=3)), ("F35", "search_publications", dict(query="ERA5 wind energy resource assessment", domain="atmosphere", top_k=3)), ("F36", "search_publications", dict(query="validation of ERA5-Land snow depth against stations", top_k=3)), ("F37", "search_publications", dict(query="machine learning downscaling of reanalysis fields", top_k=3)), ("F38", "search_publications", dict(query="storm surge modelling satellite altimetry sea level", domain="ocean/marine", top_k=3)), ("F39", "search_publications", dict(query="PM2.5 estimation from CAMS aerosol", top_k=3)), ("F40", "search_publications", dict(query="drought monitoring soil moisture anomalies", domain="land", top_k=3)), ("F41", "search_publications", dict(query="RMSE comparison against buoy observations table", top_k=3)), # ── G. linkage (after relink_full) ── ("G42", "get_dataset_publications", dict(dataset_or_product_id="reanalysis-era5-single-levels", top_k=5)), ("G43", "search_publications", dict(query="evaluation", dataset_or_product_id="reanalysis-era5-land", top_k=3)), ("G44", "search_publications", dict(query="flood", dataset_or_product_id="cems-glofas-historical", top_k=3)), ("G45", "search_publications", dict(query="sea level trend", dataset_or_product_id="SEALEVEL_GLO_PHY_L4_MY_008_047", top_k=3)), ("G46", "search_publications", dict(query="coastal erosion", orphan_only=True, top_k=3)), ("G47", "search_publications", dict(query="ERA5 global reanalysis applications", dataset_or_product_id="reanalysis-era5-single-levels", top_k=3)), # ── H. metadata / full texts ── ("H48", "dataset_metadata", dict(dataset_or_collection_id="reanalysis-era5-single-levels")), ("H49", "list_dataset_documents", dict(dataset_or_product_id="GLOBAL_MULTIYEAR_PHY_001_030")), ("H50", "read_publication", dict(doi_or_paper_id="10.1002_2016jc012391", max_chars=1200)), ] def main(): lines = ["# copernicus-rag — TEST RESULTS (50 queries)", f"run: {time.strftime('%Y-%m-%d %H:%M')}", ""] ok = fail = 0 for tag, tool, kw in CASES: fn = getattr(R, tool) t0 = time.time() try: res = fn(**kw) dt = time.time() - t0 ok += 1 lines += [f"## {tag} · `{tool}` ({dt:.1f}s)", f"**args:** `{json.dumps(kw, ensure_ascii=False)}`", "", "```json", j(res), "```", ""] print(f"{tag} OK {dt:.1f}s") except Exception as e: fail += 1 lines += [f"## {tag} · `{tool}` — ERROR", f"**args:** `{json.dumps(kw, ensure_ascii=False)}`", "", f"`{type(e).__name__}: {str(e)[:300]}`", ""] print(f"{tag} FAIL: {str(e)[:120]}") lines.insert(2, f"**passed {ok}/{len(CASES)}, failed {fail}**\n") OUT.write_text("\n".join(lines), encoding="utf-8") print(f"\nwrote {OUT} — passed {ok}/{len(CASES)}") if __name__ == "__main__": main()