Research & Benchmarks Optimization AI Ads Analytics Why Madgicx? About Us Blog Careers Case Studies Events Glossary Guides Answers Pricing Login Try for Free

How to Connect Meta Ads to Codex (MCP Setup Guide)

Category
AI Marketing
Date updated
Nov 12, 2026
Reading time
30 mins
How to Connect Meta Ads to Codex (MCP Setup Guide)

Add a [mcp_servers.madgicx] block to Codex's config.toml and sign in with one command to ask about your Meta ads from the CLI, IDE or desktop app.

To connect Meta ads to Codex, add a [mcp_servers.madgicx] block with the Madgicx MCP address to ~/.codex/config.toml, then run codex mcp login madgicx and sign in with your Madgicx login. After you pick a team, Codex can answer questions about your Meta ad accounts.

OpenAI's documentation says the Codex CLI, the IDE extension and the desktop app share the same MCP configuration, so you set it up once.

Connect Codex to your Meta ads

Add the Madgicx MCP to config.toml, sign in with codex mcp login and ask about your ad accounts. Included in the 7-day free trial.

Start your 7-day free trial

What you need before you connect Meta ads to Codex

  • A Madgicx subscription or the 7-day free trial. The trial includes the MCP, so you can set this up before you pay.
  • A Facebook ad account connected in Madgicx. If it shows under Settings, Ad Accounts in Madgicx, the assistant can reach it.
  • Codex installed. OpenAI's Codex MCP documentation covers the CLI, the IDE extension and the desktop app. Check your plan's connector settings for Codex access.

For the bigger picture, see what the Madgicx MCP can do: everything the connection can read and change. To connect other assistants, here is how to connect your AI assistant.

Set up the Madgicx MCP in Codex, step by step

  1. Open ~/.codex/config.toml, or create it if it does not exist.
  2. Add the Madgicx server:
    [mcp_servers.madgicx]
    url = "https://mcp.madgicx.com/mcp"
    OpenAI's documented codex mcp add example is for local servers, so for a remote server like this one, edit the config file directly.
  3. Save the file. The CLI, the IDE extension and the desktop app read the same configuration, so the server appears in all three. Restart any that are already open.
  4. Sign in from your terminal:
    codex mcp login madgicx

Sign in with your Madgicx login

The command opens a browser window. Log in to Madgicx, pick a team and approve access. The team decides which Facebook ad accounts Codex can use, and your Madgicx password is never shared with Codex. Authentication defaults to OAuth, so you do not need an auth setting.

If your machine has no local browser, such as a remote server, run codex mcp login madgicx --no-browser, open the URL it prints on another device, then paste the full redirect URL back into the terminal.

Check that the connection works

Start Codex and ask: “What Madgicx team am I connected to?” Codex should call the Madgicx server and answer with your name and team. If it answers without naming your team, the server is not loaded. Restart Codex and check the config file for typos.

How to get clear answers from Codex

Codex only knows what the Madgicx MCP returns, so be specific. Name the ad account if you have more than one, give a date range such as the last 7 days, and say which numbers you care about, such as spend, cost per result or ROAS. If an answer looks off, ask Codex to show which account and dates it used, then compare with Ads Manager. Keep early questions read only until you trust the setup.

Three prompts to try first in Codex

Start with questions that only read, and name the date range each time so the answer is clear.

  1. Who am I connected as? “What Madgicx team am I connected to, and which Facebook ad accounts can you see?” Once that works, you can audit a Facebook ad account in one conversation.

  2. List my ad accounts. “List my Facebook ad accounts with their status, currency and amount spent.” If you run several, here is how to manage multiple ad accounts.

  3. Last 7 days by campaign. “Show the last 7 days by campaign: spend, results, cost per result and ROAS, as a table.” To turn that into a shareable summary, see how to make a Facebook ads report.

Results come back as one total per campaign for the dates you choose, using Meta's own calculated rates. To see a trend, ask for two periods separately, such as this week and last week.

What the Madgicx MCP reads and changes

The connection can read your ad accounts, campaigns, ad sets, ads, creatives, Facebook Pages and posts, results at every level, the account change history and Event Match Quality.

It can also change things: pause and restart campaigns, ad sets and ads, change budgets and bids, and edit names in bulk. Every change needs your confirmation. Codex shows the exact change first, such as which campaign and what new budget, and waits for you to say yes before anything runs. See how to pause ads after you confirm and scale budgets after you confirm. For how access is limited, read how to connect AI assistants to Meta ads safely.

Add the Google Ads MCP to Codex (read only)

Madgicx also runs a Google Ads MCP. It only reads: Codex can analyze search terms, keywords, placements and performance by device or hour, and it changes nothing in Google Ads. It needs a Google Ads account linked in Madgicx. The same Madgicx login authorizes both servers, and Codex picks the right one for each question.

Add a second block to the same file:

[mcp_servers.madgicx_google]
url = "https://mcp-google-ads.madgicx.com/mcp"
Then run codex mcp login madgicx_google to sign in for that server.

Troubleshooting

  • No sign-in prompt. Run codex mcp login madgicx yourself, with --no-browser if you have no local browser. If sign-in still fails, use the client ID and secret from Workspace Settings, MCP Integration in Madgicx.
  • Tools do not show. Check that the block header is exactly [mcp_servers.madgicx] and the URL ends in /mcp. Confirm your Madgicx subscription or trial is active and a Facebook ad account is connected in Madgicx, then restart Codex.
  • Codex shows the wrong accounts. The team you picked at sign-in sets the accounts. Run the login again to pick another team.
  • The connection times out. Check your network and try the login again.

More detail is in the Madgicx MCP docs.

Try it on your own ad account

The MCP gives Codex a read on your Facebook ad accounts. Madgicx is also the agentic AI advertising platform for Meta ads and an official Meta Business Partner, with an AI marketer that prepares actions for you to approve. To see the connection working before you commit, the 7-day free trial includes the MCP.

Try Madgicx free for 7 days

FAQ

Where does the Madgicx MCP config go in Codex?

In ~/.codex/config.toml, as a [mcp_servers.madgicx] block with a url line.

Does it work in the Codex app and IDE extension, or only the CLI?

OpenAI's documentation says the Codex CLI, the IDE extension and the desktop app share the same MCP configuration, so one setup covers all three.

How do I sign in?

Run codex mcp login madgicx, log in to Madgicx in the browser and pick a team. Add --no-browser if you have no local browser.

Can Codex change my campaigns?

It can pause and restart ads and change budgets and bids, but only after it shows you the exact change and you confirm.

Can I add the Google Ads MCP too?

Yes, as a second block with the Google Ads address. It is read only, so Codex can analyze Google Ads and changes nothing there.

Working in a different assistant? See how to use ChatGPT for Facebook ads, connect Meta ads to Gemini, connect Meta ads to Grok or automate Meta ads with n8n.

You scrolled so far. You want this. Trust us.