ETLMCPData Conveyance Works
Log in Start free
Docs

Agent recipe: re-sync a pipeline, then answer from fresh data

The tool order an AI agent should follow to refresh a pipeline over MCP, wait for the run to end, and only then query the numbers it reports.

When you ask an agent for "yesterday's spend, freshly synced", it has to do four things in order: call list_pipelines to find the pipeline's id, call run_pipeline with that id and no dates, call get_run until the status is success or partial, and only then call query_data for the days you asked about. run_pipeline returns as soon as the run is queued, not when it is done. An agent that queries straight after it reads the rows from the previous sync and reports them as fresh.

Each tool's parameters and output fields are on its own page: list_pipelines, run_pipeline, get_run and query_data.

Step 1: find the pipeline

Call list_pipelines, match the pipeline by name, and keep two values: the id, for run_pipeline, and the source_id, for filtering query_data in step 4.

Check paused_reason too. When it is set, the plan's limits have paused the pipeline and run_pipeline refuses it with this pipeline is paused by the plan's limits. The agent should tell you so instead of retrying.

Step 2: start the sync with no dates

Call run_pipeline with only pipeline_id. With no start and end, the run re-pulls the same trailing window the scheduled run pulls: it ends today in the pipeline's timezone, never later than today in UTC, and reaches back a number of days that depends on the platform, never past the plan's history. See the trailing window for the days per platform. Pass start and end only when you need older days than that window covers, and pass both: one without the other is refused.

The tool answers at once with the new run, whose status is queued. Keep its id. This is the only id the agent can poll from MCP, because no MCP tool lists runs.

run_pipeline needs a credential with the run scope. A read-only key or connection gets this credential cannot start runs; create a key with the run scope. Runs started by hand also count toward the plan's cap on runs queued or running at once, across the organization; over it, the answer is {…} syncs are already queued or running: wait for one.

If a sync is already running

Only one run per pipeline can be queued or running at a time. When one already is, perhaps the scheduled run or one started from the dashboard, run_pipeline answers a sync is already running for this pipeline; check it with get_run and starts nothing.

Do not let the agent call run_pipeline again in a loop: the run in progress is already re-pulling the data, so the agent should wait for it. If it started that run itself earlier in the conversation, it has the run's id and polls it with get_run. The refusal does not carry the other run's id, so for a run started elsewhere the agent can watch last_run_at and last_status on the pipeline from list_pipelines: they change when that run ends. A script with REST access can find the run with List runs, filtered by pipeline.

Step 3: poll get_run until the run ends

Call get_run with the run's id. queued and running mean the run is still going. A run that hits a passing error, such as a rate limit, goes from running back to queued and tries again while it has attempts left, so a queued after running is not an end. The run has ended only when the status is success, partial or failed; Run statuses covers each one.

  • success: the rows are fetched, stored and delivered. Go to step 4.
  • partial: the rows were fetched and stored, but delivery to the destination failed. query_data already shows the fresh rows, so the agent can answer, but it should say that the destination did not get them and quote the run's error.
  • failed: do not report the numbers as fresh. The stored rows for those days may still be the ones from the last good sync. The agent should report the run's error instead.

Leave a pause between calls. Every MCP call counts against the credential's limit of 120 requests a minute, REST and MCP together, and a tight loop spends it on nothing.

The run's range_start and range_end say which days it covered. etlmcp can move range_start later when a platform cannot serve the earliest days asked for, so read them from the finished run rather than assuming them.

Step 4: query the days you need

Now call query_data with start and end for the days the question is about, and source_id set to the pipeline's source, so that rows from other sources do not mix in. Ask only for the fields the answer needs, such as date and cost. Dates are in the ad account's own timezone. The run's window ends today, so today's row holds only what the platform had reported when the run pulled it.

Tell the agent what these rows are. query_data reads the rows etlmcp stored as they came from the platform, before any of the pipeline's transform rules. It does not read what the destination received. If the pipeline renames, filters or derives columns, the agent's numbers can differ from your warehouse or sheet, and it should say which one it read.

When more rows match than the limit, truncated is true and the answer is incomplete. Query data well covers narrowing the query.

A prompt you can give the agent

Put the order in your request, so the agent does not skip a step:

Re-sync the "Meta - Brand" pipeline, wait until get_run says success or partial,
then use query_data with that pipeline's source_id for 2026-11-23 to 2026-11-29
and give me cost by day. If run_pipeline says a sync is already running, wait for
that run instead of starting another. If the run fails, tell me the error.

The same flow from a script is in Start a run and wait.

Related