---
title: 'OpenAI Codex + Meta Ads MCP Workflow: Setup & Guardrails'
description: 'Connect OpenAI Codex to Meta Ads via Plainrouter MCP in ~/.codex/config.toml. Run signal-first campaign audits, trace CAPI bugs in code, and govern writes safely.'
canonical: 'https://plainrouter.com/library/codex-meta-ads-workflow'
format: Guide
last_updated: '2026-12-02'
---

Connecting [OpenAI Codex to Meta Ads via Plainrouter MCP](</agents/codex/meta>) lets you audit Meta campaign spend alongside first-party arrivals, inspect stored conversion signal health, and stage governed ad changes right next to your codebase without putting raw Meta System User tokens in your prompts or repository.

## Step 1: Configure Plainrouter MCP in \~/.codex/config.toml

First, sign in to Plainrouter, connect your Meta ad account, and create a Read workspace key. Export that key in your protected local environment as PLAINROUTER\_WORKSPACE\_TOKEN, then add the remote MCP entry to \~/.codex/config.toml:

` [mcp_servers.plainrouter]
url = "https://plainrouter.com/mcp"
bearer_token_env_var = "PLAINROUTER_WORKSPACE_TOKEN" `

Notice that config.toml only stores the environment variable name, never the secret key itself. Keep PLAINROUTER\_WORKSPACE\_TOKEN out of git commits, Codex prompts, and literal bearer headers.

## Step 2: Verify the read-only connection before doing real work

Confirm the entry is registered in Codex CLI:

` codex mcp list `

A listed server alone does not prove authentication or workspace scope. Launch Codex in the same shell environment where PLAINROUTER\_WORKSPACE\_TOKEN is set and run a read-only handshake prompt:

` Use the plainrouter MCP server to read account state. Show which workspace and ad account answered, the reporting window of retained data, and any missing inputs. Do not preview, propose, or execute any changes. `

If your workspace contains multiple Meta ad accounts, name the exact ad account in every prompt so Codex never mixes campaigns across brands.

## Step 3: Run a signal-first Meta Ads + codebase audit in Codex

Because Codex can read both your local repository and Plainrouter's MCP tools in one session, it excels at diagnosing tracking-driven CPA spikes that browser chat tools miss:

- **1\. Check retained performance beside arrivals: **Ask Codex to list active campaigns for the last 7 and 14 days with Meta spend, Meta purchases, and Plainrouter first-party arrivals, explicitly flagging the freshness timestamp.
- **2\. Inspect stored signal-health evidence: **Verify whether conversion ingestion or Meta CAPI delivery dropped on the same date CPA spiked.
- **3\. Trace tracking regressions straight to code: **If arrivals or match keys dropped after a release, have Codex inspect your Next.js Route Handler, checkout component, or webhook handler for missing event\_id keys, hashed \_fbp/\_fbc cookies, or broken consent gates.

## Step 4: Preview and govern Meta ad writes cleanly

Remember one critical boundary: Codex asking your permission to run an MCP tool is client-level tool approval, not Plainrouter approval to mutate a live Meta ad. When you are ready to move from audits to changes:

- **Switch to a Write key with Ask mode first: **In Ask mode, every proposal Codex submits lands in Plainrouter's Inbox with its target, diff, and evidence waiting for you to click Approve or Reject.
- **Require a preview first: **Instruct Codex to preview any supported change (pausing or resuming campaigns/ad sets/ads, eligible daily-budget changes, image uploads, or paused ad copies) and show the policy evaluation before submitting a proposal.
- **Know Custom and Full modes before switching: **In Custom mode, your workspace switches decide which agent changes run automatically and which wait for a person. In Full mode, every agent change that passes admission and workspace policy runs automatically, including budget increases, campaign/ad-set creation, ad-set duplication, and campaign/ad-set activation. Rule violations are always blocked and shown in the Inbox across all modes.

## What Codex cannot do through Plainrouter MCP

Plainrouter's MCP server is intentionally focused on safe, auditable ad operations rather than unrestricted Marketing API access. Codex cannot create custom audiences, switch lifetime budgets, or bypass workspace policy rules. New ad copies always start paused and require a separate governed resume to go live. If you ever need an immediate stop, trigger Plainrouter's kill switch (which halts queued and future changes without undoing completed actions) or revoke the workspace key.

## Frequently asked questions

### Why does Codex show plainrouter in codex mcp list but fail to authenticate?

Codex reads PLAINROUTER\_WORKSPACE\_TOKEN from the process environment of the terminal or launcher running Codex. A variable exported in one shell tab is not automatically visible in a GUI launcher or separate subshell. Verify the variable is present in the same process environment and that the workspace key has not been revoked.

### Does Codex need write access to audit my Meta campaigns?

No. Start with a Read workspace key so Codex can inspect account state, retained performance, first-party arrivals, and stored signal-health evidence while being unable to preview or propose any Meta writes.

### Can Codex run budget increases automatically in Full mode?

Yes, if your workspace is set to Full mode and the change passes admission and workspace policy. If you want a human to approve budget increases or every ad write, keep the workspace in Ask mode or configure Custom mode switches.

### Should my team use Codex, Claude Code, or Cursor with Plainrouter MCP?

All three clients connect to the exact same hosted Plainrouter MCP server and approval engine. Pick whichever coding agent your team already uses, or compare our [Claude Code + Meta Ads MCP workflow](</library/claude-code-meta-ads-workflow>) and [Cursor + Meta Ads MCP workflow](</library/cursor-meta-ads-workflow>) guides.

## Related guides and tools

- [Connect Codex to Meta Ads via MCP](</agents/codex/meta>): official Plainrouter setup reference for OpenAI Codex.
- [Server-side tracking MCP](</library/server-side-tracking-mcp>): why pairing first-party CAPI diagnostics with Meta Ads MCP prevents bad ad decisions.
- [15 Meta Ads MCP prompts](</library/meta-ads-mcp-prompts>): copy-paste prompts for wasted-spend audits, fatigue checks, and governed proposals.
- [Claude Code + Meta Ads MCP workflow](</library/claude-code-meta-ads-workflow>): companion terminal workflow for Claude Code.
