Meta MCP Connector
Enables natural-language querying of Meta/Facebook Ads data via the Graph API, including ad accounts, campaigns, ad sets, spend, and performance metrics.
README
Meta MCP Connector
Plain-language MCP server for Meta / Facebook Ads via the Graph API.
Ask about ad accounts, campaigns, ad sets, spend, and performance in natural language — no table names or raw API paths required.
Features
- Live data from the Facebook Marketing API (Graph API)
- List ad accounts with parent Business Manager
- Campaign / ad set / ad performance (spend, impressions, clicks, purchases)
- Account-level spend dashboard (
account-spend.html) - Claude.ai OAuth when deployed to Cloud Run (
MCP_PUBLIC_URL)
Project structure
meta-mcp-connector/
├── meta_mcp_server.py # MCP server + HTTP routes + tools
├── meta_graph.py # Facebook Graph API client
├── meta_oauth.py # Claude-compatible OAuth provider
├── account-spend.html # Spend-by-account dashboard
├── test-accounts.html # Ad account list test page
├── get-token.html # Helper to obtain FACEBOOK_ACCESS_TOKEN
├── requirements.txt
├── Dockerfile
├── deploy-cloudrun.ps1 # Deploy to Google Cloud Run
├── .env.example
└── .cursor/mcp.json # Local Cursor MCP config (example)
Setup (local)
1. Clone and install
git clone https://github.com/YOUR_USERNAME/meta-mcp-connector.git
cd meta-mcp-connector
python -m venv .venv
# Windows
.venv\Scripts\activate
pip install -r requirements.txt
copy .env.example .env
2. Configure .env
FACEBOOK_APP_ID=your_app_id
FACEBOOK_APP_SECRET=your_app_secret
FACEBOOK_ACCESS_TOKEN=your_user_token_with_ads_read
FACEBOOK_AD_ACCOUNT_ID=114810198697538
Token requirements
- Must be a User Token (
EAA…), not an App Token (app_id|secret) - Generated in Graph API Explorer for your
FACEBOOK_APP_ID - Permissions:
ads_read,ads_management,business_management
Use get-token.html or run the server and open http://127.0.0.1:8001/get-token.
3. Start the server
python meta_mcp_server.py --http
| Endpoint | URL |
|---|---|
| MCP | http://127.0.0.1:8001/mcp |
| Account spend UI | http://127.0.0.1:8001/account-spend |
| Account list API | http://127.0.0.1:8001/api/accounts |
| Account spend API | http://127.0.0.1:8001/api/account-spend?date=YYYY-MM-DD |
4. Cursor MCP config
.cursor/mcp.json:
{
"mcpServers": {
"meta": {
"url": "http://127.0.0.1:8001/mcp"
}
}
}
Reload MCP in Cursor settings after starting the server.
MCP tools
| Tool | Purpose |
|---|---|
help_meta |
What you can ask |
list_accounts |
Ad accounts + parent Business Manager |
list_campaigns |
Campaigns in an ad account |
list_adsets |
Ad sets in an ad account |
get_integration_status |
Token / app health check |
get_ads_summary |
KPI totals for a date range |
get_daily_trend |
Day-by-day spend & metrics |
get_performance_breakdown |
Breakdown by campaign / ad set / placement |
get_top_ads |
Top ads by spend or other metric |
Example prompts
- "List my Meta ad accounts"
- "Meta ads summary from 2026-08-01 to 2026-08-15"
- "Daily spend last 7 days for WOW Ad Account"
- "Top ads by spend yesterday"
- "Break down spend by campaign last week"
Google Cloud Run
Host the same HTTP MCP endpoint on Cloud Run (same pattern as vdp-connector). The Docker image does not bake in .env or secrets.
Prerequisites
- Google Cloud SDK (
gcloud) installed and logged in (gcloud auth login) - A GCP project with billing enabled
- Your GCP Project ID
- Facebook credentials ready in local
.env(see.env.example)
Deploy
From this repo folder:
# App secret read from .env
.\deploy-cloudrun.ps1 -ProjectId "YOUR_GCP_PROJECT_ID"
# Optional overrides
.\deploy-cloudrun.ps1 -ProjectId "YOUR_GCP_PROJECT_ID" -Region "us-central1" -Service "meta-mcp"
# App secret from a one-line file (gitignored)
.\deploy-cloudrun.ps1 -ProjectId "YOUR_GCP_PROJECT_ID" -SecretFile ".\facebook-app-secret.key"
What the script does:
- Enables Cloud Run, Cloud Build, Secret Manager, Artifact Registry
- Uploads
FACEBOOK_APP_SECRET→ Secret Manager (meta-facebook-app-secret) - Uploads
FACEBOOK_ACCESS_TOKEN→ Secret Manager (meta-facebook-access-token) if set in.env - Deploys with
--source .(Dockerfile), env vars, and secret injection - Sets
MCP_PUBLIC_URLto the service URL (required for Claude OAuth) - Prints the connector URL:
https://SERVICE-URL/mcp
Deploy flags:
--set-env-vars MCP_TRANSPORT=http,HOST=0.0.0.0,FACEBOOK_APP_ID=…,FACEBOOK_AD_ACCOUNT_ID=…--set-secrets FACEBOOK_APP_SECRET=meta-facebook-app-secret:latest,FACEBOOK_ACCESS_TOKEN=meta-facebook-access-token:latest--allow-unauthenticated(needed for a working MCP URL on first deploy)--session-affinity,--max-instances 1,--timeout 300,--port 8080
Cursor (Cloud Run)
After deploy, put the printed URL in .cursor/mcp.json:
"meta": {
"url": "https://YOUR-CLOUD-RUN-URL/mcp"
}
You do not need a local python meta_mcp_server.py process when using Cloud Run.
Claude custom connector
Claude.ai requires OAuth for remote custom connectors. This server embeds a Claude-compatible OAuth provider (Dynamic Client Registration) when MCP_PUBLIC_URL is set (the deploy script sets it automatically).
- Deploy with
.\deploy-cloudrun.ps1 -ProjectId "YOUR_GCP_PROJECT_ID" - Remove any old broken connector
- Settings → Connectors → Add custom connector
- Paste exactly:
https://YOUR-CLOUD-RUN-URL/mcp(must include/mcp) - Leave OAuth Client ID empty in Advanced settings (DCR is enabled)
- Click Connect — Claude registers itself and authorizes briefly
If you see "Couldn't register with … sign-in service" (ofid_…):
- Confirm the URL ends with
/mcp(not the bare Cloud Run host) - Confirm the service is up: open
https://YOUR-CLOUD-RUN-URL/.well-known/oauth-authorization-server— you should see JSON withregistration_endpoint - Confirm
MCP_PUBLIC_URLmatches the service origin (redeploy if you changed the URL) - Do not paste a random OAuth Client ID unless you set up an external IdP
Verify deployment
| Check | URL |
|---|---|
| MCP endpoint | https://YOUR-SERVICE-URL/mcp |
| OAuth discovery | https://YOUR-SERVICE-URL/.well-known/oauth-authorization-server |
| Account spend UI | https://YOUR-SERVICE-URL/account-spend |
Local vs Cloud
| Local | Cloud Run | |
|---|---|---|
| Start | python meta_mcp_server.py --http |
.\deploy-cloudrun.ps1 -ProjectId … |
| URL | http://127.0.0.1:8001/mcp |
https://…run.app/mcp |
| Secrets | .env file |
Secret Manager → env injection |
| Host / port | 127.0.0.1:8001 |
0.0.0.0 + PORT=8080 |
| Claude OAuth | Off (no MCP_PUBLIC_URL) |
On (MCP_PUBLIC_URL = service URL) |
| Tools | Same | Same |
Security note
--allow-unauthenticated makes the Cloud Run URL publicly reachable. OAuth means Claude must complete registration/authorize before tools work; random callers without a token get 401. Still treat the URL as sensitive and add stronger auth before sharing widely.
Common pitfalls
- Claude URL missing
/mcp→ "Couldn't connect to the server" MCP_PUBLIC_URLnot set → OAuth 404 → "Couldn't register with sign-in service"- Committing
.envor secret files - Forgetting to redeploy after OAuth code changes
- Deploying without
FACEBOOK_ACCESS_TOKEN→ Graph API returns permission errors
Push to GitHub
# Sign in to your new GitHub account first
git credential-manager github login --force
# Create repo on GitHub (browser or gh), then:
git remote add origin https://github.com/YOUR_USERNAME/meta-mcp-connector.git
git add .
git commit -m "Initial commit: Meta MCP connector"
git push -u origin main
Security
- Never commit
.env— it is gitignored FACEBOOK_ACCESS_TOKENis a secret; rotate if exposed- Cloud Run deploy uses
--allow-unauthenticatedfor MCP URL reachability; OAuth protects tool access whenMCP_PUBLIC_URLis set
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。