meta-ads
Meta Ads MCP
把 Meta(Facebook)廣告 Graph API 包成 MCP server,給 Claude(Desktop / Claude Code)直接呼叫,公司同事就可以用對話的方式查廣告成效跟素材。
對應 PDF 規格的兩支 API:
Tool | Endpoint | 用途 |
|
| 抓花費、曝光、觸及、點擊、CTR/CPC/CPM、actions、影片觀看率等 |
|
| 抓單支廣告的素材(圖、文案、CTA、貼文連結) |
兩種跑法
模式 | 適用 | 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. 把 code 放到 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 .env3. 啟動 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 + serverInfo5. 同事的 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 endpoint 之間做轉接,他們不需要裝 Python / uv / 你的程式碼。
升級 / 更新流程
cd /path/to/meta-ads-mcp
git pull
docker compose up -d --build關掉
docker compose downToken 輪替
token 外洩或定期換新時:
EC2 上改
.env的MCP_BEARER_TOKENdocker compose up -d(會 recreate mcp 容器)把新 token 發給同事,更新他們的
claude_desktop_config.json
對話範例
「幫我抓 2026-03-23 到 2026-03-25 的廣告數據,並列出花費前三的廣告」
「幫我看一下廣告 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 對外,其他 port(特別是 22)建議鎖到公司 IP 範圍。
This server cannot be installed
Maintenance
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
Conversational access to advertising performance data, creative analysis, and campaign insights
Conversational access to advertising performance data, creative analysis, and campaign insights
Query Meta Ads performance data — accounts, campaigns, ad sets, ads, metrics & settings.
Ask AI about your ads — query Meta, TikTok, and Google Ads performance in natural language.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceWraps the Meta Marketing API to enable creating, modifying, viewing, and deleting Instagram ads via natural language.27MIT
- AlicenseNot gradedqualityDmaintenancePython MCP server that exposes Meta Marketing API data, providing tools to manage ad accounts, campaigns, and analytics through natural language interfaces.MIT
- AlicenseNot gradedqualityDmaintenanceEnables management and analysis of Meta (Facebook/Instagram) ads through natural language conversations, with 30 tools for reading and writing ad data.MIT
- AlicenseNot gradedqualityDmaintenanceEnables 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
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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