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.
README
π Meta Ads MCP Server
<div align="center">
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_adsetrichiedebid_amountper LINK_CLICKS etargeting_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
- Vai su Facebook Developers
- My Apps β Create App β Business
- Completa i dettagli dell'app
2οΈβ£ Aggiungi Marketing API
- Dashboard app β trova Marketing API
- Clicca Set Up
- La Marketing API apparirΓ nel menu
3οΈβ£ Genera Token
Opzione A: Graph API Explorer (raccomandato)
- Vai su Graph API Explorer
- Seleziona la tua app
- Get User Access Token β Seleziona permessi:
- β
ads_management(gestione completa) - β
ads_read(lettura) - β
read_insights(metriche)
- β
- 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 β BasicYOUR_APP_SECRET: Dashboard β Settings β BasicYOUR_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:
- Genera nuovo token da Graph API Explorer
- Converti in long-lived (60 giorni)
- 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
- π Meta Marketing API Documentation
- π§ͺ Graph API Explorer
- π API Error Reference
- πΌ Meta Business Help Center
- π Insights API Reference
- π€ Model Context Protocol
π€ Contributi
Contributi, issues e feature requests sono benvenuti!
- Fork del progetto
- Crea il tuo feature branch (
git checkout -b feature/AmazingFeature) - Commit delle modifiche (
git commit -m 'Add some AmazingFeature') - Push al branch (
git push origin feature/AmazingFeature) - Apri una Pull Request
π Licenza
Questo progetto Γ¨ rilasciato sotto licenza MIT. Vedi il file LICENSE per i dettagli.
π Riconoscimenti
- Basato su Meta Marketing API v21.0
- Costruito con FastMCP
- Validazione con Pydantic v2
<div align="center">
β Se questo progetto ti Γ¨ utile, lascia una stella su GitHub!
</div>
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.