DEV Community

bursteri
bursteri

Posted on

Designing approval gates for an AI agent with Meta Ads write access (MCP architecture notes)

Connecting an AI agent to Meta Ads for read-only reporting is straightforward. You wire up OAuth, expose a handful of Insights endpoints over Model Context Protocol (MCP), and let Claude or Cursor summarize spend, CPA, and creative fatigue.

The hard engineering problem starts the moment someone asks the agent to make a change: pause an underperforming ad set, upload new creative variants, or adjust a daily budget.

Live ad accounts have real money attached to every POST call. If an LLM hallucinates a zero (500 instead of 50), targets the wrong client account, or activates an unreviewed creative, standard API retries cannot undo the spend.

Here is the three-layer governance architecture we landed on to make ad-account MCP writes safe enough for real teams.


1. Never let an agent mutate live spend directly by default

The most useful constraint is separating preparing a change from activating spend:

  1. Paused by default: Any newly created campaign, ad set, or creative variant starts PAUSED. Preparing ten creative variants never spends a cent until a human (or an explicit policy rule) activates them.
  2. Scoped ad-account boundary: An OAuth token or MCP session is pinned to an explicitly approved workspace and ad account, not every account inside a Business Manager portfolio. For agencies running multiple clients, cross-client blast radius has to be structurally impossible at the server layer, not left to prompt instructions.
  3. Structured proposals instead of raw Graph API passthrough: Rather than giving the LLM a generic meta_post(path, body) tool, every write passes through a typed proposal contract with explicit fields (target_id, before_value, after_value, reason, idempotency_key).

2. Three execution modes: Ask, Custom, and Full

Binary "read-only vs. full write" forces teams into a bad trade-off: either the agent can't help with execution at all, or you hand it unrestricted write access.

A three-tier execution model solves most real workflows cleanly:

Mode What happens when the agent calls a write tool Typical use case
Ask Every write creates a pending proposal in an approval queue; nothing executes on Meta until a human approves it. New accounts, agencies, sensitive budgets, creative launches.
Custom Policy rules auto-approve narrow, bounded actions (e.g., pausing an ad that exceeded a CPA cap, or staging paused drafts) while routing budget increases and activations to human approval. Day-to-day growth teams wanting safe guardrails.
Full Policy-compliant changes execute automatically within workspace bounds, while every action is still recorded in an immutable audit log. Mature, tightly scoped automations.

The key design detail is that the agent calls the exact same MCP tool in all three modes. Policy evaluation happens server-side, never inside the LLM prompt. If a tool call violates a cap or requires approval, the server returns a deterministic pending_approval state with a review URL so the agent doesn't panic or enter a retry loop.


3. Why ad-account ROAS alone misleads an AI agent

Even with tight write guardrails, there is a subtler failure mode: garbage-in measurement.

If an agent reads Meta's self-reported ROAS from the Marketing API and sees purchases drop 40% overnight, a naive agent will propose pausing campaigns or rotating creatives. Half the time, the ads didn't break; the Conversions API pipeline did (a Shopify update dropped event_id deduplication, a CMP change stopped passing _fbc, or someone started hashing fbp).

Giving the agent access to first-party signal health (landing arrivals, server delivery receipts, deduplication ratio, and backend-confirmed revenue) alongside Meta's ad metrics lets it distinguish a tracking regression from actual ad fatigue before proposing a spend change.


4. Practical implementation notes

If you are building or auditing an MCP server with write capabilities against any financial or advertising API:

  • Enforce idempotency keys on proposals. LLMs retry tool calls when responses are slow. Without an idempotency key, a timeout can duplicate a budget increase or create duplicate ad sets.
  • Keep tool definitions lean. Loading 60+ raw API wrappers into tools/list bloats the client's context window and degrades tool selection accuracy. Group read diagnostics and typed write proposals into a small, well-documented surface.
  • Record who proposed, who approved, and what changed. Store the actor (agent / user), policy evaluation result, pre-state, and post-state for every mutation.

(Disclosure: This is the governance model we built in Plainrouter for Meta Ads MCP and Conversions API diagnostics; our typed SDKs and CLI live on GitHub.)

Top comments (6)

Collapse
 
ar9avg profile image
Arnav Gupta •

Structured proposals with before_value and after_value are strongest piece here. Approver sees exact diff, not agent summary of it. One gap worth testing: proposals go stale. If budget changes between creation and approval, before_value no longer matches live state. Rejecting apply on mismatch turns each approval into compare-and-swap.

Collapse
 
mirabridge profile image
MiraBridge AI •

The stale proposal gap is real, and two guards together cover it. First, compare-and-swap on apply: read the live value right before the write, refuse if it no longer equals before_value, and make the agent propose again instead of silently rebasing. Second, a short expiry on the proposal itself, because a budget change that was right on Friday afternoon is often wrong by Monday even when before_value still matches: pacing and learning state moved while the number stayed the same. A third thing that is easy to skip: version the proposal, so an edit made after someone has reviewed it cancels the earlier approval instead of inheriting it. And store requester and approver as separate fields, with self-approval allowed but visible, because the question an agency gets from a client later is "who signed this off", not "what did the agent say". Disclosure: I work on Ads Control Center, which does this for Meta ad accounts (proposals expire within 24 hours and by default someone other than the requester approves).

Collapse
 
ar9avg profile image
Arnav Gupta •

Versioning is strongest guard here: edit after review should void approval. One more: hash exact action payload at approval time and compare at apply, so approved change cannot differ from applied one.

Collapse
 
parlup profile image
parlupme •

Returning a deterministic pending_approval state with a review URL—while keeping the tool signature identical across Ask/Custom/Full—is a great pattern. Models burn huge amounts of tokens (or invent workarounds) when a denied write throws a generic error.

Two edge cases worth pairing with this as teams run longer-lived or multi-agent workflows:

  • Async resumption without polling: If the human approves 4 hours later after the agent's session has closed or compacted, having the approval queue deliver a completion event (proposal_id, decision, applied_diff) back to the proposing agent's inbox lets the workflow resume cleanly without keeping a loop alive.
  • Approval TTL + CAS guard: Beyond matching before_value on apply (compare-and-swap), expiring pending proposals after a short TTL prevents a Friday afternoon budget proposal from getting approved on Monday against completely different pacing.
Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

Pausing every proposal by default is the right call when the agent can spend real money. I like that the policy stays on the server side, so the model never gets to decide what counts as approved.

Collapse
 
paul_irolla_6b5ae261d0224 profile image
Paul Irolla •

Read-only is the easy half, and the write side is where I would put the gate.