Skip to main content
Glama
meta-ads-mcp

meta-ads-mcp

by 1nc0gn30
README.md
# meta-ads-mcp

**Live Web Workbench & 24-Tool Playground**: https://ads-mcp-workbench.netlify.app

Model Context Protocol (MCP) server for the **Meta Marketing API (v22.0)** — manage Facebook & Instagram ad accounts, ODAX campaigns, ad sets, targeting, creatives, insights, custom audiences, pixels, and automated account performance audits directly from Claude Desktop, Cursor, Windsurf, or Antigravity.

## Highlights

- **24 MCP Tools** covering Account Discovery, Campaigns, Ad Sets & Targeting, Ads & Creatives, Insights & Automated Audits, Custom Audiences, and Pixels.
- **2 MCP Resources & 2 MCP Prompts** (`meta-ads://config/status`, `meta-ads://reference/objectives`, `audit-ad-account`, `draft-campaign-plan`).
- **Spend Safety Guardrails**:
  - New campaigns, ad sets, and ads default to `status: "PAUSED"`.
  - Every mutating tool supports `dry_run: true` to inspect the exact Graph API endpoint and payload without touching live spend.
- **Production HTTP Client**:
  - Automatic `act_` account ID normalization (`123456` → `act_123456`).
  - Automatic cursor pagination (`fetchAllPages`).
  - Exponential backoff retries on transient Meta rate-limit/server error codes (`1`, `2`, `4`, `17`, `32`, `613`, `80000`, `80004`).
  - Rate-limit header telemetry (`x-app-usage`, `x-ad-account-usage`, `x-business-use-case-usage`).
  - Detailed Meta error reporting (`error_user_title`, `error_user_msg`, `code`, `error_subcode`, `fbtrace_id`).
- **Built-in Demo Mode**: Set `META_ADS_DEMO_MODE=true` to test every tool with realistic mock ad accounts and insights before adding a live token.

---

## Quick Start

### 1. Clone & Build

```bash
git clone https://github.com/1nc0gn30/meta-ads-mcp.git
cd meta-ads-mcp
npm install
npm run build
```

### 2. Configure Your MCP Client

#### Claude Desktop (`claude_desktop_config.json`) / Cursor / Antigravity

```json
{
  "mcpServers": {
    "meta-ads": {
      "command": "node",
      "args": ["/absolute/path/to/meta-ads-mcp/dist/index.js"],
      "env": {
        "META_ACCESS_TOKEN": "EAAB...",
        "META_AD_ACCOUNT_ID": "act_1234567890",
        "META_API_VERSION": "v22.0"
      }
    }
  }
}
```

#### Test Without a Token (Demo Mode)

```json
{
  "mcpServers": {
    "meta-ads": {
      "command": "node",
      "args": ["/absolute/path/to/meta-ads-mcp/dist/index.js"],
      "env": {
        "META_ADS_DEMO_MODE": "true"
      }
    }
  }
}
```

---

## Environment Variables

| Variable | Required | Default | Description |
| --- | --- | --- | --- |
| `META_ACCESS_TOKEN` | Yes (live) | — | Meta System User or User Access Token (`ads_read`, `ads_management`, `business_management`, `pages_read_engagement`) |
| `META_AD_ACCOUNT_ID` | No | — | Default Ad Account ID (with or without `act_` prefix) |
| `META_API_VERSION` | No | `v22.0` | Meta Graph / Marketing API version |
| `META_API_BASE_URL` | No | `https://graph.facebook.com` | Override Graph API base URL (proxies / testing) |
| `META_ADS_DEMO_MODE` | No | `false` | Set `true` to run with mock datasets without a Meta token |
| `META_API_TIMEOUT_MS` | No | `30000` | HTTP timeout per request in milliseconds |

---

## Tool Reference (24 Tools)

### Auth & Account Discovery
| Tool | Description |
| --- | --- |
| `meta_check_auth` | Verify token validity, granted permissions, API version, and rate limits |
| `meta_list_ad_accounts` | List accessible ad accounts with status, currency, spend cap, and business info |
| `meta_get_ad_account` | Fetch full metadata, balance, spend cap, and funding details for an account |
| `meta_list_pages` | List Facebook Pages and linked Instagram Business Accounts |

### Campaigns
| Tool | Description |
| --- | --- |
| `meta_list_campaigns` | List campaigns with `effective_status` filter and pagination |
| `meta_get_campaign` | Get full configuration and budget details for a campaign |
| `meta_create_campaign` | Create an ODAX campaign (defaults to `PAUSED`, supports `dry_run`) |
| `meta_update_campaign` | Update campaign name, status, budget, or bid strategy (supports `dry_run`) |

### Ad Sets & Targeting
| Tool | Description |
| --- | --- |
| `meta_list_adsets` | List ad sets by ad account or campaign |
| `meta_get_adset` | Get full ad set details including targeting spec and schedule |
| `meta_create_adset` | Create an ad set (defaults to `PAUSED`, supports `dry_run`) |
| `meta_update_adset` | Update ad set status, budget, bid amount, end time, or targeting (supports `dry_run`) |
| `meta_search_targeting` | Search interests, geos, employers, job titles, or locales |
| `meta_estimate_reach` | Estimate potential audience reach for a targeting spec |

### Ads & Creatives
| Tool | Description |
| --- | --- |
| `meta_list_ads` | List ads by account, campaign, or ad set |
| `meta_get_ad` | Get ad details and linked creative metadata |
| `meta_create_ad_creative` | Create a link/image ad creative (`object_story_spec`, supports `dry_run`) |
| `meta_create_ad` | Create an ad inside an ad set (defaults to `PAUSED`, supports `dry_run`) |
| `meta_update_ad` | Update ad name, status, or creative (supports `dry_run`) |
| `meta_list_ad_images` | List uploaded ad images and their `hash` values |

### Insights, Audits, Audiences & Pixels
| Tool | Description |
| --- | --- |
| `meta_get_insights` | Pull account/campaign/adset/ad insights with breakdowns and blended ROAS/CPA/CTR summary |
| `meta_audit_account_performance` | Automated audit flagging creative fatigue, zero-conversion spend bleed, low CTR, and scaling winners |
| `meta_list_custom_audiences` | List custom and lookalike audiences with approximate size and delivery status |
| `meta_list_pixels` | List Meta Pixels / Datasets attached to an ad account |

---

## Development & Testing

```bash
npm run typecheck
npm run build
npm test
```

The test suite runs unit tests for the HTTP client (retry/backoff, pagination, rate-limit header capture, error parsing), analytics/audit checks, and full end-to-end stdio MCP client tests in both Demo Mode and Live HTTP Mode against a local mock Graph API server.

---

## Support

This project is 100% free and open-source under the MIT License. If it saves you time:

- **☕ Buy Us a Coffee**: [https://buy.stripe.com/3cIfZg27PdKo2D64Ocfw40X](https://buy.stripe.com/3cIfZg27PdKo2D64Ocfw40X)
- **Solana Tip Address**: `GG2eQbVh8ut1BK6j1A2tz7pSySdLpD38BgyEhGcxdXoK`

---

Engineered by Neal Frazier Tech ([@1nc0gn30](https://github.com/1nc0gn30/meta-ads-mcp)) • [NullAI Platform](https://nullai.tech)

TDQS

B3.4/5.0

Scored across 24 tools

Disambiguation4/5

Most tools have a clearly distinct resource and action, with strong separation between campaign, ad set, ad, creative, targeting, and insights operations. Minor overlap exists between meta_get_insights and meta_audit_account_performance, and between meta_create_ad_creative and meta_create_ad, but descriptions make the boundaries workable.

Naming Consistency5/5

All tools consistently use a meta_ prefix followed by a verb_noun pattern such as list_campaigns, get_ad, create_adset, update_campaign, and search_targeting. The convention is predictable throughout, with only natural variations like check_auth and audit_account_performance.

Tool Count4/5

Twenty-four tools is on the heavy side, but the breadth of Meta Ads management justifies separate operations for accounts, campaigns, ad sets, ads, creatives, targeting, insights, and auditing. Each tool maps to a meaningful API operation, though some auxiliary listing tools could potentially be consolidated.

Completeness4/5

The core lifecycle from account discovery through campaign, ad set, ad, creative, targeting, and performance insights is well covered. Gaps remain around explicit delete operations, creative retrieval/update beyond image listing, and creation of custom audiences or pixels, though archiving via status updates mitigates some of this.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues