fb-ads-automation

fb-ads-automation

Enables full read/write management of Facebook ad campaigns, ad sets, ads, and creatives via the Meta Marketing API through natural language, with AI creative generation, performance analytics, and PDF reporting.

Category
访问服务器

README

Facebook Ads Automation

An MCP server for Claude Code that gives you full read/write access to the Meta Marketing API. Manage campaigns, analyze performance, generate AI creatives, and get optimization recommendations — all through natural language.

77 MCP tools | 7 AI agents | PDF reports | AI creative generation | Multi-account support

Built on FastMCP + Facebook Marketing API v24.0.

How It Works

YOU (natural language in Claude Code)
  |
  v
SLASH COMMANDS      /fb-ads:daily-check, /fb-ads:weekly-report, /fb-ads:optimize, ...
  |
  v
AGENTS (7)          Report, Market Analyst, Creative Strategist, Creative Generator,
                    Performance Optimizer, Competitive Intel, Ads Optimizer
  |
  v
KNOWLEDGE           Per-client context: business goals, brand voice, audience, competitors
  |
  v
MCP SERVER (77)     Facebook API tools + Analytics engine + AI creative generation

What You Can Do

  • Manage campaigns — Create, read, update, pause/activate campaigns, ad sets, ads, and creatives
  • Analyze performance — Get insights, run analytics, detect creative fatigue, check audience saturation
  • Generate creatives — AI image/video generation via Freepik (14 image + 24 video models), Gemini (Imagen 3 + Veo), and OpenAI (DALL-E 3 + Sora)
  • Edit images — Upscale, remove backgrounds, reimagine, recolor, inpaint, and more (9 editing operations)
  • Optimize — Get data-driven recommendations based on your KPIs, thresholds, and business rules
  • Generate reports — KPMG-style PDF reports with charts, KPIs, and recommendations
  • Research competitors — Search the Facebook Ad Library and analyze competitor strategies
  • Manage multiple accounts — Switch between ad accounts with labeled aliases

Quick Start

1. Install

git clone https://github.com/your-username/fb-ads-automation.git
cd fb-ads-automation

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

2. Configure

cp .env.example .env
cp .mcp.json.example .mcp.json

Edit .env with your Facebook credentials (see Setup Guide for step-by-step instructions on getting each credential):

FB_APP_ID=your_app_id
FB_APP_SECRET=your_app_secret
FB_ACCESS_TOKEN=your_access_token
FB_AD_ACCOUNT_ID=act_your_account_id

Edit .mcp.json with absolute paths to your Python and server:

{
  "mcpServers": {
    "fb-ads": {
      "command": "/absolute/path/to/.venv/bin/python3",
      "args": ["/absolute/path/to/fb_ads_mcp_server/server.py"]
    }
  }
}

3. Verify

Open Claude Code in the project directory:

check_token_status

If you see your token info, you're ready.

4. Onboard Your First Client

/fb-ads:onboard-client

This interactive wizard validates your account, interviews you about your business, and creates the knowledge files that agents use.

Tool Groups

Only 8 core tools load at startup. Load more on demand:

enable_tools(groups="crud,insights")   # Campaign management + reporting
enable_tools(groups="creative_gen")    # AI image/video generation
enable_tools(groups="all")             # Everything (77 tools)
Group Tools What It Does
core 8 Account management, token tools, tool loading
crud 21 Create/read/update campaigns, ad sets, ads, creatives
insights 5 Performance data and breakdowns
analytics 7 Trends, fatigue detection, saturation analysis
targeting 3 Interest search, audience estimation, suggestions
pages 5 Facebook Page management and insights
instagram 4 Instagram account and media management
ad_library 2 Competitor ad research
creative_gen 7 AI image and video generation
image_editing 9 Upscale, remove BG, reimagine, recolor, inpaint
stock 3 Search Freepik image/icon/video libraries
audio 3 AI music, sound effects, vocal isolation

Full tool reference: docs/mcp-tools.md

Agents

Seven specialized agents live in agents/. Activate by saying "Load [agent name]":

Agent What It Does
Report Agent Generates KPMG-style PDF reports with charts and KPIs
Market Analyst Audience research, demographic analysis, expansion planning
Creative Strategist Ad copy, messaging angles, A/B test design
Creative Generator AI image/video generation with brand-aware prompts
Performance Optimizer Data-driven optimization recommendations
Competitive Intel Ad Library research, competitor strategy analysis
Ads Optimizer Campaign-level optimization (deprecated, kept for reference)

Agents auto-read your knowledge files for business context, brand voice, audience data, and competitive landscape.

Slash Commands

Command What It Does
/fb-ads:onboard-client Set up a new client (interactive wizard)
/fb-ads:daily-check Morning health check on your ad account
/fb-ads:weekly-report Weekly performance summary
/fb-ads:optimize Analyze and get optimization recommendations
/fb-ads:new-campaign Interactive campaign creation wizard
/fb-ads:creative-refresh Check for creative fatigue + guide refresh
/fb-ads:generate-creative Generate AI images/videos for ads
/fb-ads:competitor-check Research competitor ads via Ad Library

Knowledge System

Agents use per-client knowledge files to understand your business:

knowledge/
  playbook.md              # Global optimization thresholds
  accounts.md              # Account registry
  report-specs.md          # PDF report configuration
  clients/
    _templates/            # Blank templates to copy
    _example/              # Filled example (fictional cafe)
    your-client/           # Your client's knowledge files
      business-context.md  # Company, product, KPIs, strategy
      brand-voice.md       # Tone, messaging, visual direction
      audience-research.md # Segments, demographics, saturation
      competitive-landscape.md  # Competitors, benchmarks, gaps

Important Notes

Budgets use the smallest currency unit. USD uses cents ($50/day = daily_budget: 5000). INR uses paisa (Rs 1,000/day = daily_budget: 100000).

Campaign objectives must be OUTCOME-based: OUTCOME_TRAFFIC, OUTCOME_ENGAGEMENT, OUTCOME_LEADS, OUTCOME_AWARENESS, OUTCOME_SALES, OUTCOME_APP_PROMOTION.

Rate limits are ~200 API calls/hour/user. Analytics tools make multiple calls per invocation.

Tokens expire after ~60 days. Use check_token_status and refresh_access_token to manage them.

Optional: AI Creative Generation

The core ads management works without these. Add API keys for creative generation:

Provider Models Key Required
Freepik 14 image + 24 video + editing FREEPIK_API_KEY
Google Gemini Imagen 3 + Veo GEMINI_API_KEY
OpenAI DALL-E 3 + Sora OPENAI_API_KEY

See docs/freepik.md for model selection guides.

Documentation

Doc Contents
Setup Guide Step-by-step installation and credential setup
MCP Tools Reference All 77 tools by group with descriptions
Agents & Clients Agent system, onboarding, code structure
Freepik Guide AI models, editing operations, parameters
Dashboard Client dashboard architecture and deployment

Project Structure

fb_ads_mcp_server/         # MCP server
  server.py                # Entry point (FastMCP)
  api/                     # Pure Facebook SDK wrappers (no MCP coupling)
  tools/                   # MCP tool registration (thin orchestrators)
  analytics/               # Pure computation functions
  rules/                   # Business rule engine
  providers/               # AI provider abstraction (Gemini, OpenAI, Freepik)
agents/                    # 7 agent instruction files
knowledge/                 # Global + per-client knowledge files
reports/                   # PDF report generator + charts
dashboard/                 # Static client dashboard (Netlify-ready)
docs/                      # Documentation
tests/                     # Test suite

Contributing

See CONTRIBUTING.md for development setup, testing, and PR guidelines.

License

MIT - see LICENSE.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选