Answers / Get data into your AI
How do I keep a daily snapshot of a CSV export so my AI can compare days?
Recipe verified on
Ran on a private test instance
Short answer
Save each day's export with its date in the file name in one folder, and mark that folder as a history folder. cdb-localdata then loads every file as a dated version of a single table, so you can ask for any day, a range of days, or what changed.
Steps
- Connect your assistant to your instance (this writes, so it needs your own instance with a ReadWrite key
from the accounts portal; the public demo is read-only). In Claude Code:
claude mcp add --transport http mcpdata https://[you].mcpdata.org/mcp --header "Authorization: Bearer $CDB_API_KEY"
Replace
[you]with your instance's name. Other apps: Connect your AI. - Install the client and sign it in.
pip install https://[you].mcpdata.org/help/download/cdb-0.3.4-py3-none-any.whl cdb-localdata login --to https://[you].mcpdata.org
- Mark the exports folder as a history folder. Put a
.cdb/config.jsonin it saying where the date is in each file name (the sample folder exports/daily has it):{"type": "history", "timestamp_from": "filename:%Y-%m-%d"} - Add the folder above it and sync. Each file is sent as a dated version of
exports.daily:cdb-localdata add ./samples/exports --to https://[you].mcpdata.org --namespace exports cdb-localdata sync
- Compare two days. In the workbench, or from Python (your AI can save the same SQL as a view for a report):
import cdb s = cdb.Session("https://[you].mcpdata.org") first = s.execute_sql("SELECT COUNT(*) AS orders FROM exports.daily AS OF LASTDATA BETWEEN #2023-01-01# AND #2023-01-01#") latest = s.execute_sql("SELECT COUNT(*) AS orders FROM exports.daily AS OF LASTDATA") print("2023-01-01:", int(first.to_dataframe()["orders"][0]), "orders; latest day:", int(latest.to_dataframe()["orders"][0]), "orders") - Ask your question. Give your AI this prompt:
Using mcpdata, save a view of orders and revenue by channel on the latest day of exports.daily (AS OF LASTDATA), and make it a daily report.
What your AI does: the tool calls it makes for this prompt, and what came back
create_view(name="exports.latest_by_channel", select_sql="SELECT channel, COUNT(*) AS orders, SUM(revenue) AS revenue FROM exports.daily AS OF LASTDATA GROUP BY channel") → created true, view exports.latest_by_channel
create_report(name="Latest day by channel", view="exports.latest_by_channel") → report_id a760d6d7f5394a07a286bef55c7e5205
run_report(report_id="a760d6d7f5394a07a286bef55c7e5205") → status ok, rows 3
Output of the steps above, from the last run
2023-01-01: 1556 orders; latest day: 1559 orders
The assistant needs mcpdata connected (step 1) to run the query.
Why this works
Overwriting yesterday's export loses it; keeping files with different names gives you many tables. A history table keeps one name and one version per day. AS OF LASTDATA BETWEEN #d# AND #d# reads one day, AS OF LASTDATA the latest, and AS OF ALLVERSIONS every day.