Skip to main content
Glama
vitahuang629

meta-ads

by vitahuang629

Meta Ads MCP

Meta(Facebook)広告 Graph API を MCP サーバーとしてラップし、Claude(Desktop / Claude Code)から直接呼び出せるようにします。会社の同僚は会話形式で広告の効果やクリエイティブを確認できるようになります。

PDF 仕様に対応する 2 つの API:

Tool

Endpoint

用途

get_ad_insights

GET /{ad_account_id}/insights (v23.0)

費用、インプレッション、リーチ、クリック、CTR/CPC/CPM、actions、動画視聴率などを取得

get_ad_creative

GET /{ad_id} (v25.0)

単一広告のクリエイティブ(画像、コピー、CTA、投稿リンク)を取得

2 つの実行方法

モード

適用

Transport

stdio(デフォルト)

ローカル / 個人利用 / 開発

Claude Desktop が子プロセスを spawn

http

EC2 / コンテナ / 全社共有

streamable-http + Bearer auth


A. ローカル(stdio)

Related MCP server: Meta Ads MCP Server

インストール

cd C:\Users\bexo6\OneDrive\桌面\mcp_meta_claude
uv sync
Copy-Item .env.example .env   # 然後填好 META_ACCESS_TOKEN 等

Claude Desktop に接続

%APPDATA%\Claude\claude_desktop_config.json を編集:

{
  "mcpServers": {
    "meta-ads": {
      "command": "uv",
      "args": [
        "--directory",
        "C:\\Users\\bexo6\\OneDrive\\桌面\\mcp_meta_claude",
        "run",
        "python",
        "server.py"
      ]
    }
  }
}

Claude Desktop を再起動 → Settings → Developer に meta-ads が表示されるはずです。


B. EC2 にデプロイして全社で利用(http)

すでに EC2 + nginx + HTTPS が https://ai.gastom.com.tw で稼働している前提です。 Caddy は追加でインストールせず、MCP コンテナ(127.0.0.1:8000 にバインド)だけを実行し、既存の nginx で https://ai.gastom.com.tw/meta-ads/* を転送します。

1. 共有 Bearer token を生成

python3 -c "import secrets; print(secrets.token_urlsafe(32))"

文字列を保存しておきます(パスワード管理ツール / 社内 vault)。後で:

  • EC2 の .env に書き込む

  • 同僚に配布して Claude Desktop に記入してもらう

2. コードを EC2 に配置

ssh your-user@ec2-host
git clone <你的 repo 位置> meta-ads-mcp
cd meta-ads-mcp

cat > .env <<'EOF'
META_ACCESS_TOKEN=<長效 Graph API token>
META_AD_ACCOUNT_ID=act_870176260326362
MCP_BEARER_TOKEN=<上一步產生的字串>
EOF
chmod 600 .env

3. MCP コンテナを起動

docker compose up -d --build
docker compose logs -f mcp     # 看到 "Uvicorn running on http://0.0.0.0:8000" 就 OK

EC2 ローカルから検証(まだ nginx 経由ではない):

curl -i http://127.0.0.1:8000/healthz                # 200
curl -i -X POST http://127.0.0.1:8000/mcp            # 401(沒 token)

4. nginx に location を追加

deploy/nginx-meta-ads.conf の内容を既存の server { listen 443 ssl; server_name ai.gastom.com.tw; ... } ブロックに貼り付けて、次に:

sudo nginx -t                # 語法檢查
sudo systemctl reload nginx  # 套用

外部ネットワークから検証:

curl -i https://ai.gastom.com.tw/meta-ads/healthz                  # 200
curl -i -X POST https://ai.gastom.com.tw/meta-ads/mcp              # 401
curl -i -X POST -H "Authorization: Bearer <你的token>" \
     -H "Accept: application/json, text/event-stream" \
     -H "Content-Type: application/json" \
     -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"t","version":"1"}}}' \
     https://ai.gastom.com.tw/meta-ads/mcp                          # 200 + serverInfo

5. 同僚の Claude Desktop 設定

各同僚は %APPDATA%\Claude\claude_desktop_config.json(macOS:~/Library/Application Support/Claude/claude_desktop_config.json)に追加:

{
  "mcpServers": {
    "meta-ads": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "https://ai.gastom.com.tw/meta-ads/mcp",
        "--header",
        "Authorization: Bearer 上面產生的_MCP_BEARER_TOKEN"
      ]
    }
  }
}

同僚の PC には Node.js(npx を実行するため)が必要です。mcp-remote が stdio と HTTPS エンドポイントの間を中継するため、Python / uv / あなたのコードをインストールする必要はありません


アップグレード / 更新手順

cd /path/to/meta-ads-mcp
git pull
docker compose up -d --build

停止

docker compose down

Token のローテーション

token が漏洩した場合や定期的に更新する場合:

  1. EC2 で .envMCP_BEARER_TOKEN を変更

  2. docker compose up -d(mcp コンテナが recreate されます)

  3. 新しい token を同僚に配布し、彼らの claude_desktop_config.json を更新


会話例

「2026-03-23 から 2026-03-25 までの広告データを取得して、費用上位 3 つの広告をリストアップして」

「広告 ID 120228265609960545 のクリエイティブがどんなものか見せて」

Claude は自動的に get_ad_insights を呼び、その後特定の ad_id に対して get_ad_creative を呼びます。

セキュリティ上の注意事項

  • .env は絶対に commit しない.gitignore で除外済み。

  • MCP_BEARER_TOKEN は会社の予算の鍵:誰でも Meta API を呼び出して会社の広告費を使えます。パスワードと同等の扱いで保管してください。

  • HTTPS は必須:Bearer token を HTTP で送信すると平文で転送されることになります。

  • EC2 Security Group:80/443 以外のポート(特に 22)は社内 IP 範囲に制限することを推奨します。

Maintenance

ActivityMaintained
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Python MCP server that exposes Meta Marketing API data, providing tools to manage ad accounts, campaigns, and analytics through natural language interfaces.
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables management and analysis of Meta (Facebook/Instagram) ads through natural language conversations, with 30 tools for reading and writing ad data.
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    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.
    MIT

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vitahuang629/mcp_meta_ads_claude'

If you have feedback or need assistance with the MCP directory API, please join our Discord server