Meta Ads MCP Server

Meta Ads MCP Server

Python MCP server that exposes Meta Marketing API data, providing tools to manage ad accounts, campaigns, and analytics through natural language interfaces.

Category
Visit Server

README

Meta Ads MCP Server

Servidor MCP em Python para expor dados da Meta Marketing API para clientes compatíveis com MCP.

O que mudou

Esta versão do servidor foi ajustada para execução mais confiável:

  • carrega .env automaticamente na raiz do projeto
  • falha no boot se META_ACCESS_TOKEN não estiver configurado
  • retorna JSON estruturado em todas as tools
  • valida date_preset, level e metric antes de chamar a Meta API
  • remove erros silenciosos e devolve erros acionáveis para o cliente MCP
  • usa streamable-http quando PORT está definido

Requisitos

  • Python 3.10+
  • token da Meta com permissões compatíveis, como ads_read e read_insights

Instalação

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Configuração

Crie um arquivo .env na raiz:

META_ACCESS_TOKEN=EAAB...

Opcionalmente, crie clients.json para apelidos de contas:

{
  "Minha Marca": "act_123456789",
  "Cliente Agencia X": "act_987654321"
}

Também é possível usar CLIENTS_JSON como variável de ambiente com o mesmo conteúdo em JSON.

Execução

Segurança (Public Hosting)

Se você hospedar este servidor publicamente (ex: no Render), é altamente recomendável definir a variável de ambiente MCP_API_KEY.

  • No Servidor (Render): Adicione a variável MCP_API_KEY com um valor secreto de sua preferência.
  • No Cliente (Ex: Claude Desktop): Adicione o header de autorização na configuração do servidor remoto.

Modo HTTP para deploy (Render)

Quando PORT estiver definido, o servidor usa SSE (Server-Sent Events).

PORT=8000 MCP_API_KEY=seu_segredo_aqui python3 server.py

Quando PORT estiver definido, o servidor usa streamable-http, que é o caminho mais alinhado com o SDK MCP atual para produção.

Exemplo de configuração MCP

{
  "mcpServers": {
    "meta-ads": {
      "command": "/ABSOLUTE/PATH/.venv/bin/python",
      "args": ["/ABSOLUTE/PATH/server.py"],
      "env": {
        "META_ACCESS_TOKEN": "EAAB..."
      }
    }
  }
}

Tools disponíveis

Tool Função
meta_list_clients Lista os clientes configurados
meta_get_structure Lista campanhas ou detalha adsets/ads de uma campanha
meta_get_analytics Retorna insights estruturados para conta, campanha, adset ou ad
meta_get_ad_creative_details Retorna dados do criativo de um anúncio
meta_get_account_balance Retorna saldo, gasto e spend cap da conta
meta_get_demographics Retorna breakdown por idade/gênero e plataforma
meta_compare_performance Compara múltiplos IDs
meta_get_trend_chart Retorna série temporal e gráfico ASCII

Formato de resposta

Todas as tools retornam JSON com este envelope:

{
  "ok": true,
  "data": {}
}

Em caso de erro:

{
  "ok": false,
  "error": {
    "code": "invalid_params",
    "message": "date_preset inválido.",
    "details": {}
  }
}

Problemas comuns

META_ACCESS_TOKEN não definido

  • configure a variável de ambiente ou o arquivo .env

ModuleNotFoundError: No module named 'mcp'

  • ative o ambiente virtual correto
  • rode pip install -r requirements.txt

account_ambiguous

  • use o nome exato do cliente em clients.json ou o act_ID

meta_api_error

  • valide permissões do token
  • confirme se o ID informado pertence à conta/token corretos
  • confira limites e rate limits da API da Meta

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