Meta Ads MCP Server

Meta Ads MCP Server

Enables comprehensive management of Facebook and Instagram advertising campaigns via the Meta Marketing API, supporting campaign creation, targeting optimization, and budget management. It provides tools for detailed performance reporting and creative analysis, including insights into spend, ROI, and audience breakdowns.

Category
Visit Server

README

πŸš€ Meta Ads MCP Server

<div align="center">

Python 3.10+ Meta Marketing API MCP License: MIT

Server MCP completo per gestire campagne pubblicitarie Facebook/Instagram

Quick Start β€’ Tools Disponibili β€’ Configurazione β€’ Esempi

</div>


✨ Caratteristiche

<table> <tr> <td width="50%">

πŸ“Š Analisi & Reporting

  • πŸ“ˆ Metriche performance complete
  • 🎯 Report avanzati con breakdown
  • πŸ’° Insights su spend, ROI, ROAS
  • πŸ“… Date personalizzate o preset

</td> <td width="50%">

🎨 Gestione Campagne

  • ✏️ Crea campagne e ad set
  • 🎯 Modifica targeting e budget
  • πŸ“ Analizza creative e annunci
  • πŸ”„ Gestisci stato (attiva/pausa)

</td> </tr> </table>

πŸ”₯ FunzionalitΓ  Principali

graph LR
    A[Account] --> B[Campagne]
    B --> C[Ad Set]
    C --> D[Annunci]
    D --> E[Creative]

    B -.-> F[Insights]
    C -.-> F
    D -.-> F
    F --> G[Report]
  • βœ… 10 Tools Completi - Dalla creazione alla reportistica
  • βœ… System User Compatible - Funziona con token permanenti
  • βœ… Error Handling Avanzato - Messaggi di errore dettagliati Meta API
  • βœ… Date Flessibili - Preset o range personalizzati (fino a 37 mesi)
  • βœ… Validazione Automatica - Controlli Pydantic per parametri corretti

⚑ Quick Start

# 1️⃣ Clona il repository
git clone https://github.com/mikdeangelis/mcp-meta-ads.git
cd mcp-meta-ads

# 2️⃣ Crea ambiente virtuale
python3 -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate

# 3️⃣ Installa dipendenze
pip install -r requirements.txt

# 4️⃣ Configura token (vedi guida sotto)
export META_ACCESS_TOKEN="your_token_here"

# 5️⃣ Aggiungi al tuo MCP client
# Vedi sezione "Configurazione" per istruzioni specifiche

πŸ’‘ Primo utilizzo? Segui la guida completa per ottenere il token piΓΉ sotto.


πŸ› οΈ Tools Disponibili

πŸ“‹ Gestione Risorse

Tool Descrizione Esempio
meta_ads_list_accounts Lista tutti gli account pubblicitari "Mostrami i miei account Meta"
meta_ads_list_campaigns Lista campagne di un account "Campagne dell'account act_123456"
meta_ads_list_adsets Lista ad set di una campagna "Ad set della campagna 789"
meta_ads_list_ads Lista annunci di un ad set "Annunci dell'ad set 456"

✏️ Creazione & Modifica

Tool Descrizione Parametri Chiave
meta_ads_create_campaign Crea nuova campagna objective, daily_budget, special_ad_categories
meta_ads_create_adset Crea nuovo ad set targeting, bid_amount, optimization_goal ⚠️
meta_ads_update_adset_targeting Modifica targeting age_min, age_max, genders
meta_ads_update_adset_budget Modifica budget daily_budget
meta_ads_update_adset_status Attiva/pausa ad set status (ACTIVE/PAUSED)

⚠️ Nota: create_adset richiede bid_amount per LINK_CLICKS e targeting_automation.advantage_audience (0 o 1)

πŸ“Š Analytics & Insights

Tool Descrizione Dettagli
meta_ads_get_insights Metriche performance Impressions, clicks, spend, CTR, CPC, conversions
meta_ads_get_creative Dettagli creative Testi, immagini, link, CTA
meta_ads_generate_report Report con breakdown EtΓ , genere, paese, placement

πŸ”‘ Ottenere il Token Meta

Metodo Rapido: Graph API Explorer

<details> <summary><b>πŸ“– Clicca per espandere la guida passo-passo</b></summary>

1️⃣ Crea App Meta Developer

  1. Vai su Facebook Developers
  2. My Apps β†’ Create App β†’ Business
  3. Completa i dettagli dell'app

2️⃣ Aggiungi Marketing API

  1. Dashboard app β†’ trova Marketing API
  2. Clicca Set Up
  3. La Marketing API apparirΓ  nel menu

3️⃣ Genera Token

Opzione A: Graph API Explorer (raccomandato)

  1. Vai su Graph API Explorer
  2. Seleziona la tua app
  3. Get User Access Token β†’ Seleziona permessi:
    • βœ… ads_management (gestione completa)
    • βœ… ads_read (lettura)
    • βœ… read_insights (metriche)
  4. Generate Access Token β†’ Autorizza β†’ Copia token

Opzione B: System User Token (non scade)

Per produzione, usa System User nel Business Manager.

4️⃣ Converti in Long-Lived Token (60 giorni)

curl -X GET "https://graph.facebook.com/v21.0/oauth/access_token" \
  -d "grant_type=fb_exchange_token" \
  -d "client_id=YOUR_APP_ID" \
  -d "client_secret=YOUR_APP_SECRET" \
  -d "fb_exchange_token=YOUR_SHORT_LIVED_TOKEN"

Sostituisci:

  • YOUR_APP_ID: Dashboard β†’ Settings β†’ Basic
  • YOUR_APP_SECRET: Dashboard β†’ Settings β†’ Basic
  • YOUR_SHORT_LIVED_TOKEN: Token generato al punto 3

5️⃣ Verifica Token

curl "https://graph.facebook.com/v21.0/me?access_token=YOUR_TOKEN"

Dovresti vedere i dettagli del tuo profilo Facebook.

</details>

Configurazione Token

Opzione 1: File .env (raccomandato)

Crea .env nella directory del progetto:

META_ACCESS_TOKEN=your_token_here

Opzione 2: Variabile d'ambiente

# Linux/macOS
export META_ACCESS_TOKEN="your_token_here"

# Windows PowerShell
$env:META_ACCESS_TOKEN="your_token_here"

# Persistente: aggiungi a ~/.bashrc o ~/.zshrc
echo 'export META_ACCESS_TOKEN="your_token_here"' >> ~/.bashrc
source ~/.bashrc

βš™οΈ Configurazione

Per Claude Code

Metodo Automatico

claude mcp add meta-ads \
  --command "$(pwd)/.venv/bin/python" \
  --arg "$(pwd)/meta_ads_mcp.py"

Metodo Manuale

Modifica ~/.config/claude-code/config.json:

{
  "mcpServers": {
    "meta-ads": {
      "command": "/path/to/mcp-meta-ads/.venv/bin/python",
      "args": ["/path/to/mcp-meta-ads/meta_ads_mcp.py"],
      "env": {
        "META_ACCESS_TOKEN": "your_token_here"
      }
    }
  }
}

Per Claude Desktop

Modifica claude_desktop_config.json:

macOS/Linux: ~/.config/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "meta-ads": {
      "command": "python",
      "args": ["/path/to/mcp-meta-ads/meta_ads_mcp.py"],
      "env": {
        "META_ACCESS_TOKEN": "your_token_here"
      }
    }
  }
}

πŸ’‘ Esempi Pratici

🎯 Creare una Campagna Completa

// 1. Crea campagna
meta_ads_create_campaign({
  "account_id": "act_123456789",
  "name": "Estate 2025 - Promozione",
  "objective": "OUTCOME_SALES",
  "daily_budget": 5000,  // €50/giorno
  "status": "PAUSED"
})
// βœ… Campagna creata: ID 120236574531090062

// 2. Crea ad set con targeting
meta_ads_create_adset({
  "campaign_id": "120236574531090062",
  "name": "Italia 25-55 anni",
  "optimization_goal": "LINK_CLICKS",
  "billing_event": "LINK_CLICKS",
  "bid_amount": 150,  // €1.50 per click
  "targeting": {
    "geo_locations": {"countries": ["IT"]},
    "age_min": 25,
    "age_max": 55,
    "targeting_automation": {
      "advantage_audience": 0  // ⚠️ OBBLIGATORIO
    }
  },
  "status": "PAUSED"
  // ⚠️ NON specificare daily_budget se campagna ha già budget
})
// βœ… Ad set creato: ID 120236575096660062

πŸ“Š Analisi Performance

// Metriche ultimi 30 giorni
meta_ads_get_insights({
  "object_id": "act_123456789",
  "level": "campaign",
  "date_preset": "last_30d"
})

// Metriche con date personalizzate
meta_ads_get_insights({
  "object_id": "120236574531090062",
  "level": "campaign",
  "since": "2025-01-01",
  "until": "2025-01-31"
})

// Report breakdown per etΓ  e genere
meta_ads_generate_report({
  "object_id": "120236575096660062",
  "breakdowns": ["age", "gender"],
  "date_preset": "last_7d"
})

🎨 Analisi Creative

// Dettagli creative di un annuncio
meta_ads_get_creative({
  "ad_id": "123456789"
})
// Restituisce: titolo, body, link, CTA, immagini/video

πŸ”„ Gestione Stato e Budget

// Modifica targeting
meta_ads_update_adset_targeting({
  "adset_id": "120236575096660062",
  "age_min": 30,
  "age_max": 50,
  "genders": [2]  // Solo donne
})

// Aumenta budget
meta_ads_update_adset_budget({
  "adset_id": "120236575096660062",
  "daily_budget": 3000  // €30/giorno
})

// Attiva ad set
meta_ads_update_adset_status({
  "adset_id": "120236575096660062",
  "status": "ACTIVE"
})

πŸ“ Struttura Meta Ads

Account Pubblicitario (act_XXXXX)
β”‚
β”œβ”€β”€ πŸ“ Campagna (Campaign)
β”‚   β”œβ”€β”€ 🎯 Obiettivo: OUTCOME_SALES, OUTCOME_TRAFFIC, ecc.
β”‚   β”œβ”€β”€ πŸ’° Budget: Giornaliero o Lifetime
β”‚   β”œβ”€β”€ ⏱️ Schedule: Data inizio/fine
β”‚   β”‚
β”‚   └── πŸ“¦ Ad Set
β”‚       β”œβ”€β”€ 🎯 Targeting
β”‚       β”‚   β”œβ”€β”€ Geo: Paesi, regioni, cittΓ 
β”‚       β”‚   β”œβ”€β”€ Demografia: EtΓ , genere
β”‚       β”‚   └── Advantage Audience: 0 o 1
β”‚       β”œβ”€β”€ πŸ’΅ Bid Amount (per alcuni goals)
β”‚       β”œβ”€β”€ πŸ“Š Optimization Goal: LINK_CLICKS, CONVERSIONS, ecc.
β”‚       β”‚
β”‚       └── 🎨 Annuncio (Ad)
β”‚           └── πŸ–ΌοΈ Creative
β”‚               β”œβ”€β”€ πŸ“ Headline & Body
β”‚               β”œβ”€β”€ πŸ–ΌοΈ Immagine/Video
β”‚               β”œβ”€β”€ πŸ”— Link URL
β”‚               └── 🎬 Call-to-Action

⚠️ Requisiti Importanti

Per meta_ads_create_adset

Parametro Obbligatorio? Note
targeting.geo_locations βœ… SΓ¬ Almeno paesi, regioni o cittΓ 
targeting.targeting_automation.advantage_audience βœ… SΓ¬ 0 (disabilitato) o 1 (abilitato)
bid_amount ⚠️ Dipende OBBLIGATORIO per LINK_CLICKS, LANDING_PAGE_VIEWS, ecc.
daily_budget/lifetime_budget ⚠️ Dipende NON usare se campagna ha già budget

Budget: Regole

  • βœ… Budget solo campagna: OK
  • βœ… Budget solo ad set: OK (se campagna senza budget)
  • ❌ Budget campagna + budget ad set: ERRORE (subcode 1885621)

πŸ› Troubleshooting

<details> <summary><b>❌ Errore: "META_ACCESS_TOKEN non trovato"</b></summary>

Causa: Variabile d'ambiente non configurata

Soluzione:

export META_ACCESS_TOKEN="your_token_here"
# Oppure crea file .env nella directory del progetto

</details>

<details> <summary><b>❌ Errore: "Token non valido o scaduto"</b></summary>

Causa: Token scaduto (short-lived durano poche ore)

Soluzione:

  1. Genera nuovo token da Graph API Explorer
  2. Converti in long-lived (60 giorni)
  3. Oppure usa System User token (permanente) </details>

<details> <summary><b>❌ Errore: "Permessi insufficienti"</b></summary>

Causa: Token senza permessi necessari

Soluzione: Rigenera token includendo:

  • ads_management (gestione completa)
  • ads_read (minimo per lettura)
  • read_insights (per metriche) </details>

<details> <summary><b>❌ Errore: "Invalid parameter (subcode 1815857)"</b></summary>

Causa: Manca bid_amount per LINK_CLICKS

Soluzione: Aggiungi bid_amount in centesimi (es. 100 = €1.00) </details>

<details> <summary><b>❌ Errore: "Cannot set budget (subcode 1885621)"</b></summary>

Causa: Campagna ha giΓ  budget, non puoi specificarlo anche nell'ad set

Soluzione: Ometti daily_budget/lifetime_budget dall'ad set </details>

<details> <summary><b>❌ Errore: "Advantage audience required (subcode 1870227)"</b></summary>

Causa: Manca targeting_automation.advantage_audience

Soluzione: Aggiungi al targeting:

"targeting_automation": {
  "advantage_audience": 0  // o 1
}

</details>

<details> <summary><b>❌ Errore: "Rate limit raggiunto (429)"</b></summary>

Causa: Troppe richieste API in poco tempo

Soluzione: Attendi 5-10 minuti prima di riprovare </details>


πŸ“š Risorse Utili


🀝 Contributi

Contributi, issues e feature requests sono benvenuti!

  1. Fork del progetto
  2. Crea il tuo feature branch (git checkout -b feature/AmazingFeature)
  3. Commit delle modifiche (git commit -m 'Add some AmazingFeature')
  4. Push al branch (git push origin feature/AmazingFeature)
  5. Apri una Pull Request

πŸ“„ Licenza

Questo progetto Γ¨ rilasciato sotto licenza MIT. Vedi il file LICENSE per i dettagli.


πŸ™ Riconoscimenti


<div align="center">

⭐ Se questo progetto ti è utile, lascia una stella su GitHub!

</div>

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured