Skip to main content
Glama
vitahuang629

meta-ads

by vitahuang629

Meta Ads MCP

Meta(Facebook) 광고 Graph API를 MCP server로 패키징하여 Claude(Desktop / Claude Code)에서 직접 호출할 수 있게 했습니다. 회사 동료들이 대화 방식으로 광고 성과와 소재를 조회할 수 있습니다.

PDF 사양에 대응하는 두 개의 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, 게시물 링크) 수집

두 가지 실행 방식

모드

적용

Transport

stdio(기본)

로컬 / 개인용 / 개발

Claude Desktop이 하위 프로세스 생성

http

EC2 / 컨테이너 / 전사 공용

streamable-http + Bearer 인증


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"
      ]
    }
  }
}

동료 컴퓨터에 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 컨테이너 재생성됨)

  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를 호출하여 회사의 광고 비용을 소진할 수 있습니다. password 수준으로 보관하세요.

  • 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