Meta MCP Connector
Enables querying and managing Facebook Ads data, offering capabilities to list ad accounts, campaigns, ad sets, and obtain daily trends and performance breakdowns across campaigns, ad sets, or placements.
Provides natural language access to Meta advertising data via the Facebook Marketing API, including tools to list ad accounts, campaigns, ad sets, and retrieve performance metrics such as spend, impressions, clicks, and purchases.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Meta MCP ConnectorShow me my ad spend for the last 7 days"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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)
Related MCP server: Meta Ads MCP Server
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/devopsbrandmirchi/meta-mcp-connector.git
cd meta-mcp-connector
python -m venv .venv
# Windows
.venv\Scripts\activate
pip install -r requirements.txt
copy .env.example .env2. 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=114810198697538Token requirements
Must be a User Token (
EAA…), not an App Token (app_id|secret)Generated in Graph API Explorer for your
FACEBOOK_APP_IDPermissions:
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 --httpEndpoint | URL |
MCP |
|
Account spend UI |
|
Account list API |
|
Account spend API |
|
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 |
| What you can ask |
| Ad accounts + parent Business Manager |
| Campaigns in an ad account |
| Ad sets in an ad account |
| Ads + creative thumbnails / preview URLs |
| Token / app health check |
| KPI totals for a date range |
| Day-by-day spend & metrics |
| Hourly spend / clicks / purchases |
| By campaign / adset / placement / region / age / gender / … |
| Age / gender / age×gender |
| Purchases & spend by state/region |
| Reach & frequency (delivery pressure) |
| Top ads by spend or other metric |
| Campaign budgets + status |
| Pause / activate campaign, ad set, or ad ( |
| Who each ad set targets |
| Spend rollup across all accounts |
Example prompts
"List my Meta ad accounts"
"Spend across all accounts yesterday"
"Meta ads summary from 2026-08-01 to 2026-08-15"
"Daily spend last 7 days for WOW Ad Account"
"Hourly performance yesterday"
"Age and gender breakdown last week"
"Conversions by state for yesterday"
"Show creatives with preview URLs"
"Who does the Prospecting ad set target?"
"Campaign budgets and status"
"Pause campaign 120…" / "Activate campaign 120…"
"Reach and frequency by campaign this month"
"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.envDeploys with
--source .(Dockerfile), env vars, and secret injectionSets
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
After a successful Connect, Claude should stay connected when you reopen the app.
OAuth access/refresh tokens are HMAC-signed and stateless (no /tmp session store).
They survive Cloud Run deploys and cold starts — this is what stopped the daily
"Your session has expired" loop. Signing uses MCP_OAUTH_JWT_SECRET or falls back
to FACEBOOK_APP_SECRET (already on Cloud Run via Secret Manager).
You only need to reconnect once after this update is live, or if you remove the connector.
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_endpointConfirm
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
If you see "This connector has a server configuration issue":
Redeploy the latest code (fixes OAuth metadata for Claude: public-client DCR +
/mcpprotected-resource metadata)Remove the old connector in Claude, then add it again (clears stale OAuth registration)
Verify health:
https://YOUR-CLOUD-RUN-URL/health→oauth_enabled: trueVerify protected resource:
https://YOUR-CLOUD-RUN-URL/.well-known/oauth-protected-resource/mcp→ JSON (not 404)Verify auth metadata includes
"none"intoken_endpoint_auth_methods_supported
Verify deployment
Check | URL |
Health |
|
MCP endpoint |
|
OAuth discovery |
|
Protected resource |
|
Account spend UI |
|
Local vs Cloud
Local | Cloud Run | |
Start |
|
|
URL |
|
|
Secrets |
| Secret Manager → env injection |
Host / port |
|
|
Claude OAuth | Off (no | On ( |
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"OAuth metadata missing
/mcpprotected resource or"none"auth method → "server configuration issue"Committing
.envor secret filesForgetting to redeploy after OAuth code changes
Deploying without
FACEBOOK_ACCESS_TOKEN→ Graph API returns permission errors
Push to GitHub
Repo: https://github.com/devopsbrandmirchi/meta-mcp-connector
# Sign in to the devopsbrandmirchi GitHub account if needed
git credential-manager github login --force
# Point origin at the org repo (replaces any old personal remote)
git remote remove origin 2>$null
git remote add origin https://github.com/devopsbrandmirchi/meta-mcp-connector.git
git push -u origin mainFor a new Cloud Run service (fresh URL, no old meta-mcp-connector-git fallback):
.\deploy-cloudrun.ps1 -ProjectId "YOUR_GCP_PROJECT_ID" -Region "us-central1" -Service "meta-mcp"Then in Claude use exactly: https://YOUR-NEW-SERVICE-URL/mcp
Security
Never commit
.env— it is gitignoredFACEBOOK_ACCESS_TOKENis a secret; rotate if exposedCloud Run deploy uses
--allow-unauthenticatedfor MCP URL reachability; OAuth protects tool access whenMCP_PUBLIC_URLis set
This server cannot be deployed
Maintenance
Related MCP Connectors
Query Meta Ads performance data — accounts, campaigns, ad sets, ads, metrics & settings.
- AdCrunchOAuthdev.adcrunch
Ask AI about your ads — query Meta, TikTok, and Google Ads performance in natural language.
- mcp-serverOAuthco.flyweel
Access Google & Meta Ads data via AI. Analyse campaign performance in seconds.
Conversational access to advertising performance data, creative analysis, and campaign insights
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceConnects AI assistants to Facebook's Ads API to enable natural language queries for campaign data, insights, and performance metrics. It allows users to manage ad accounts and retrieve detailed analytics like impressions, clicks, and spend through MCP-compatible interfaces.-
- 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
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to browse and query Facebook Ads data including ad accounts, campaigns, ad sets, and performance insights via natural language.5 npmMIT