Meta Ads MCP
Manages Facebook ads as part of Meta Ads, including campaigns, ad sets, ads, creatives, audiences, and performance results.
Manages Instagram ads as part of Meta Ads, including campaigns, ad sets, ads, creatives, audiences, and performance results.
Manages Meta Ads campaigns, ad sets, ads, creatives, audiences, results, and analytics through the Meta Marketing API.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Connect a Meta account, then manage your ads from a dashboard, from an AI assistant (Claude, ChatGPT, Cursor) or from a script.
How the safety works: every change an AI or API key asks for is checked against limits you set (highest daily budget, biggest raise, changes per day, protected campaigns). Anything above them waits on an approval page until you confirm it. Pausing an ad, which only stops spend, runs straight away.
Don't want to host it? Use the hosted version. This repository is the self-hosted edition: you run the server, the database and your own Meta app.
Contents
Features · How it works · Platforms · Quick start · MCP tools · REST API and CLI · Project layout · FAQ · Contributing · License
Related MCP server: Meta Marketing API MCP Server
Features
Dashboard | Campaigns, ad sets, ads, results and analytics, a saved-ads library, and a guided way to create a campaign |
MCP server |
|
Limits and approvals | You set the limits. Anything above them waits for your approval link. The server enforces this, not the AI |
Activity log | Every read and change is recorded, with who made it: you, an API key or an AI app |
REST API and CLI | The same tools over plain HTTP with scoped API keys, and a command-line client |
Alerts and webhooks | A daily account check that emails you when something needs attention (for example, the monthly budget is used up), and webhooks you can send to your own tools |
Several accounts | Link more than one Meta login and switch between ad accounts |
How it works
flowchart LR
A["Claude, ChatGPT, Cursor (MCP)"] --> S
B["Dashboard"] --> S
C["REST API and CLI"] --> S
S["Safety layer: scopes, limits, approvals"] --> M["Meta Marketing API"]
S --> D[("Your PostgreSQL: encrypted tokens, activity log")]Everything goes through the safety layer. An AI app only sees the tools its key or sign-in allows, reads run straight away, and changes that raise spend or change what people see wait for you.
Platforms
Meta Ads (Facebook and Instagram) is the only platform for now: campaigns, ad sets, ads, results, creatives and audiences.
Want another platform? You can add it. There is no plugin system, but docs/ADDING_A_PLATFORM.md walks through it step by step, using Meta as the pattern to copy.
What you need
Node 22.9 or newer and PostgreSQL 13+ | to run it |
A public HTTPS address | Meta only redirects back to HTTPS addresses (localhost is allowed while developing) |
A Firebase project | for sign-in only; the free plan is enough |
A Meta app | your own, from https://developers.facebook.com |
Resend account (optional) | for email alerts |
Cloudflare Turnstile (optional) | "I'm not a robot" on the sign-in page |
Quick start
One command does the setup. It installs the packages, makes your secret keys, creates the database,
writes .env.local and offers to start the app.
git clone https://github.com/black12-ag/meta-ads-mcp.git && cd meta-ads-mcp
npm run setupIt asks for a few things. Press Enter to skip any you don't have yet; you can fill them in
later in .env.local, and running npm run setup again keeps what you already entered:
It asks for | Where to get it |
Public address |
|
PostgreSQL address | Your database. The database itself is created for you |
Firebase values (4) | Firebase, 5 minutes |
Meta App ID and Secret | Meta app, 10 minutes |
It makes these for you, so you never have to invent them: TOKEN_ENCRYPTION_KEY (encrypts the stored
Meta tokens; keep it safe, because losing it makes them unreadable), CREATIVE_URL_SECRET,
META_WEBHOOK_VERIFY_TOKEN and META_SYNC_CRON_SECRET.
At the end it prints the two addresses to enter in your Meta app. Then open the app, sign up, and connect Meta.
.env.local is git-ignored. Never commit it. After that, npm run dev starts the app any time.
npm install
createdb viral4all_ads
cp .env.example .env.local # fill it in
openssl rand -hex 32 # TOKEN_ENCRYPTION_KEY
openssl rand -hex 24 # CREATIVE_URL_SECRET, META_WEBHOOK_VERIFY_TOKEN, META_SYNC_CRON_SECRET (one each)
npm run db:migrate
npm run devFirebase (sign-in)
Create a project at https://console.firebase.google.com.
Authentication → Sign-in method → turn on Email/Password and Google.
Authentication → Settings → Authorized domains → add your domain.
Project settings → add a Web app and copy its config into
VITE_FIREBASE_API_KEY,VITE_FIREBASE_AUTH_DOMAIN,VITE_FIREBASE_PROJECT_ID,VITE_FIREBASE_APP_ID.Set
FIREBASE_PROJECT_IDto the same project id. The server checks sign-in tokens itself, so you don't need a service-account file.
Meta app
https://developers.facebook.com → Create app → use case Create & manage ads with Marketing API.
Add Facebook Login (or Facebook Login for Business) and set the Valid OAuth Redirect URI to
https://YOUR-DOMAIN/api/public/meta/callback.Settings → Basic: copy the App ID and App Secret into
META_APP_IDandMETA_APP_SECRET. Add a privacy policy URL (https://YOUR-DOMAIN/privacy) and a data deletion URL (https://YOUR-DOMAIN/api/public/meta/data-deletion).The app asks for these permissions:
ads_management,ads_read,pages_show_list,pages_read_engagement,pages_manage_ads,business_management.PUBLIC_BASE_URLmust be that same address (the setup script asks for it).
Development mode. A new Meta app starts in development mode. In that mode only people with a role on the app (you, plus testers you add under App roles) can connect, and reading and managing existing ads works. Meta refuses to create new ad creatives until the app is switched to Live. To manage ad accounts that belong to other people you also need Meta's App Review and business verification. Meta changes these rules, so check their current documentation before you promise anything to your users.
Run it for real
npm run build
npm start # port 3000; set PORT (and HOST) to change itPut it behind an HTTPS reverse proxy (nginx, Caddy). npm start reads .env.local too. Under
systemd or Docker, put the same variables in the service's environment instead.
Meta data is synced by a scheduler you set up. Every 30 minutes, call:
curl -X POST https://YOUR-DOMAIN/api/public/meta/sync -H "x-cron-secret: $META_SYNC_CRON_SECRET"Connect an AI
Open Connect AI in the dashboard. It shows your MCP address, https://YOUR-DOMAIN/mcp. Add it to
Claude, ChatGPT or Cursor as a custom connector and sign in when asked.
MCP tools
An AI app only sees the tools its sign-in or API key allows (each tool needs a scope, for example
ads:read).
Kind | Tools |
Read (run straight away) |
|
Safe changes (run straight away) |
|
Need your approval |
|
Your limits (highest daily budget, biggest raise, changes per day, protected campaigns) are checked by the server on every request. "Blocked by your limits" means the AI must stop and ask you.
REST API and CLI
Create an API key in the dashboard (API keys), choose its scopes, and call any tool over HTTP:
curl -X POST https://YOUR-DOMAIN/api/public/v1/tools/meta_list_campaigns \
-H "Authorization: Bearer sk_meta_..." \
-H "Content-Type: application/json" -d '{}'The OpenAPI description is at /api/public/v1/openapi.json. The same tools are in the command-line
client in cli/. Point it at your server with --server https://YOUR-DOMAIN or
VIRAL4ALL_SERVER, and use VIRAL4ALL_API_KEY for the key.
Project layout
src/routes/ pages and API endpoints (TanStack Start file routes)
src/components/ the interface
src/lib/meta/ Meta Graph API client, sync and ad actions
src/lib/mcp/ the MCP server, its tools, limits and approvals
src/lib/db/ database access and token encryption
src/lib/auth/ sign-in checks
db/schema.sql the whole database schema (safe to re-run)
cli/ the command-line client
integrations/ Claude and OpenAI plugin files
tests/ the test suite
scripts/ setup.mjs and build helpers
docs/ guides, such as adding a platformBuilt with TanStack Start (React 19), Tailwind and shadcn/ui, PostgreSQL and the official MCP SDK.
Commands
Command | What it does |
| Does the whole setup in one go (safe to run again) |
| Development server |
| Test suite (needs a local PostgreSQL) |
| Applies |
| Production build / run it |
| ESLint / Prettier |
| Fails if a server secret can reach client code |
FAQ
Is it really free? Yes. The code is open source (AGPL-3.0). You pay for your own server and your own ad spend to Meta.
Do I need Meta's App Review? Not to try it on your own ad accounts in development mode, where you can read and manage existing ads. To create new ads the app must be Live, and to manage other people's ad accounts you need App Review and business verification. See Meta app.
Can the AI overspend? The server checks your limits on every request, whatever the AI says. A change above them is refused, and anything that raises spend waits for your approval.
Where is my data? In your own PostgreSQL database on your own server. Meta tokens are encrypted with your key. The app talks to Meta and Firebase (sign-in), and to Resend and Cloudflare Turnstile only if you turn them on.
Which AI apps work? Any app that supports MCP: Claude, ChatGPT, Cursor, Claude Code, Codex, Gemini CLI and more.
Can I add another platform? Yes. See docs/ADDING_A_PLATFORM.md.
Security
Meta tokens are encrypted at rest with
TOKEN_ENCRYPTION_KEY. Losing the key makes them unreadable.Server secrets never reach the browser (
npm run check:secretschecks this).Found a vulnerability? Please report it privately. See SECURITY.md.
Contributing
Bug reports and pull requests are welcome. Read CONTRIBUTING.md first, and please follow the code of conduct. Adding a platform? Start with docs/ADDING_A_PLATFORM.md. There is no support promise: use GitHub issues for bugs.
Support the project
The best way to support it is to use the hosted version, or tell someone who runs Meta ads. The Sponsor button on this repository links there too.
Community and contact
WhatsApp: https://wa.me/message/XAPGDNH6M4HGB1
Telegram: https://t.me/ethioviral_support
Instagram: https://www.instagram.com/munir.kab
Email: support@viral4all.com
License and copyright
Copyright (C) 2026 Viral4All Ads authors
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3. It comes with no warranty. If you run a modified version as a service for other people, you must share your changes under the same license.
The code is free to use and fork. The Viral4All name and logo belong to the project: if you publish a fork or run a public service, please use your own name and logo.
Hosted-only extras of the service at ads.viral4all.com are not part of this repository.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
The simplest way to manage your Meta (Facebook and Instagram) ad accounts with your AI agent.
60+ Meta Ads tools for AI agents: audits, campaign management, audiences and CAPI tracking.
Connect authorized ad accounts to AI assistants for audits, reporting, and approval-gated changes.
Boost posts and launch community growth campaigns from your AI assistant. OAuth, credit-billed.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to manage Facebook and Instagram advertising via the Meta Marketing API. It provides comprehensive tools for campaign lifecycle management, performance analytics, audience targeting, and creative optimization.36 npm202MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to manage Facebook and Instagram advertising data through the Meta Marketing API. It supports full campaign lifecycle management, performance analytics, audience targeting, and creative optimization.811 npmMIT
- -licenseNot gradedqualityNot gradedmaintenanceEnables AI assistants to manage Facebook and Instagram advertising campaigns through the Meta Marketing API. Supports full campaign lifecycle management, performance analytics, audience targeting, and creative optimization.-
- AlicenseNot gradedqualityDmaintenanceEnables management and analysis of Meta (Facebook/Instagram) ads through natural language conversations, with 30 tools for reading and writing ad data.MIT