Model Context Protocol (MCP) server for interacting with Meta Ads API
A Model Context Protocol (MCP) server for interacting with Meta Ads API. This tool enables AI models to access, analyze, and manage Meta advertising campaigns through a standardized interface, allowing LLMs to retrieve performance data, visualize ad creatives, and provide strategic insights for Facebook, Instagram, and other Meta platforms.
DISCLAIMER: This is an unofficial third-party tool and is not associated with, endorsed by, or affiliated with Meta in any way. This project is maintained independently and uses Meta's public APIs according to their terms of service. Meta, Facebook, Instagram, and other Meta brand names are trademarks of their respective owners.
Screenhot: using an LLM to understand your ad performance.
When using uv no specific installation is needed. We can use uvx to directly run meta-ads-mcp:
# RECOMMENDED: Use with Pipeboard authentication
export PIPEBOARD_API_TOKEN=your_pipeboard_token # Get your token at https://pipeboard.co
uvx meta-ads-mcp
# Alternative: Use with direct Meta authentication
uvx meta-ads-mcp --app-id YOUR_META_ADS_APP_ID
If you want to install the package:
uv pip install meta-ads-mcp
For development (if you've cloned the repository):
# From the repository root
uv pip install -e .
Alternatively, you can install meta-ads-mcp via pip:
pip install meta-ads-mcp
After installation, you can run it as:
# RECOMMENDED: Use with Pipeboard authentication
export PIPEBOARD_API_TOKEN=your_pipeboard_token # Get your token at https://pipeboard.co
python -m meta_ads_mcp
# Alternative: Use with direct Meta authentication
python -m meta_ads_mcp --app-id YOUR_META_ADS_APP_ID
The easiest way to configure Meta Ads MCP is using Pipeboard authentication:
export PIPEBOARD_API_TOKEN=your_pipeboard_token # Token obtainable via https://pipeboard.co
uvx meta-ads-mcp
This method provides longer-lived tokens (60 days), simplified setup, and automatic token renewal.
Add this to your claude_desktop_config.json
to integrate with Claude or ~/.cursor/mcp.json
to integrate with Cursor:
"mcpServers": {
"meta-ads": {
"command": "uvx",
"args": ["meta-ads-mcp"],
"env": {
"PIPEBOARD_API_TOKEN": "your_pipeboard_token" // Token obtainable via https://pipeboard.co
}
}
}
Or if you prefer direct Meta authentication (using your own Facebook app):
"mcpServers": {
"meta-ads": {
"command": "uvx",
"args": ["meta-ads-mcp", "--app-id", "YOUR_META_ADS_APP_ID"]
}
}
mcp_meta_ads_get_ad_accounts
access_token
(optional): Meta API access token (will use cached token if not provided)user_id
: Meta user ID or "me" for the current userlimit
: Maximum number of accounts to return (default: 10)mcp_meta_ads_get_account_info
access_token
(optional): Meta API access token (will use cached token if not provided)account_id
: Meta Ads account ID (format: act_XXXXXXXXX)mcp_meta_ads_get_campaigns
access_token
(optional): Meta API access token (will use cached token if not provided)account_id
: Meta Ads account ID (format: act_XXXXXXXXX)limit
: Maximum number of campaigns to return (default: 10)status_filter
: Filter by status (empty for all, or 'ACTIVE', 'PAUSED', etc.)mcp_meta_ads_get_campaign_details
access_token
(optional): Meta API access token (will use cached token if not provided)campaign_id
: Meta Ads campaign IDmcp_meta_ads_create_campaign
access_token
(optional): Meta API access token (will use cached token if not provided)account_id
: Meta Ads account ID (format: act_XXXXXXXXX)name
: Campaign nameobjective
: Campaign objective (AWARENESS, TRAFFIC, ENGAGEMENT, etc.)status
: Initial campaign status (default: PAUSED)special_ad_categories
: List of special ad categories if applicabledaily_budget
: Daily budget in account currency (in cents)lifetime_budget
: Lifetime budget in account currency (in cents)mcp_meta_ads_get_adsets
access_token
(optional): Meta API access token (will use cached token if not provided)account_id
: Meta Ads account ID (format: act_XXXXXXXXX)limit
: Maximum number of ad sets to return (default: 10)campaign_id
: Optional campaign ID to filter bymcp_meta_ads_get_adset_details
access_token
(optional): Meta API access token (will use cached token if not provided)adset_id
: Meta Ads ad set IDmcp_meta_ads_get_ads
access_token
(optional): Meta API access token (will use cached token if not provided)account_id
: Meta Ads account ID (format: act_XXXXXXXXX)limit
: Maximum number of ads to return (default: 10)campaign_id
: Optional campaign ID to filter byadset_id
: Optional ad set ID to filter bymcp_meta_ads_get_ad_details
access_token
(optional): Meta API access token (will use cached token if not provided)ad_id
: Meta Ads ad IDmcp_meta_ads_get_ad_creatives
access_token
(optional): Meta API access token (will use cached token if not provided)ad_id
: Meta Ads ad IDmcp_meta_ads_get_ad_image
access_token
(optional): Meta API access token (will use cached token if not provided)ad_id
: Meta Ads ad IDmcp_meta_ads_update_ad
ad_id
: Meta Ads ad IDstatus
: Update ad status (ACTIVE, PAUSED, etc.)bid_amount
: Bid amount in account currency (in cents for USD)access_token
(optional): Meta API access token (will use cached token if not provided)mcp_meta_ads_update_adset
adset_id
: Meta Ads ad set IDfrequency_control_specs
: List of frequency control specificationsbid_strategy
: Bid strategy (e.g., 'LOWEST_COST_WITH_BID_CAP')bid_amount
: Bid amount in account currency (in cents for USD)status
: Update ad set status (ACTIVE, PAUSED, etc.)targeting
: Targeting specifications including targeting_automationaccess_token
(optional): Meta API access token (will use cached token if not provided)mcp_meta_ads_get_insights
access_token
(optional): Meta API access token (will use cached token if not provided)object_id
: ID of the campaign, ad set, ad or accounttime_range
: Time range for insights (default: maximum)breakdown
: Optional breakdown dimension (e.g., age, gender, country)level
: Level of aggregation (ad, adset, campaign, account)mcp_meta_ads_debug_image_download
access_token
(optional): Meta API access token (will use cached token if not provided)url
: Direct image URL to test (optional)ad_id
: Meta Ads ad ID (optional, used if url is not provided)mcp_meta_ads_get_login_link
access_token
(optional): Meta API access token (will use cached token if not provided)Before using the MCP server, you'll need to set up a Meta Developer App:
http://localhost:8888/callback
The Meta Ads MCP supports two authentication methods:
This method uses Pipeboard.co to manage Meta API authentication, providing longer-lived tokens and a simplified flow:
PIPEBOARD_API_TOKEN
environment variable with your token:
export PIPEBOARD_API_TOKEN=your_pipeboard_token
uvx meta-ads-mcp
Benefits of Pipeboard authentication:
To test the Pipeboard authentication flow:
python test_pipeboard_auth.py --api-token YOUR_PIPEBOARD_TOKEN
The traditional OAuth 2.0 flow designed for desktop apps. This method should only be used if you are using your own Facebook app instead of Pipeboard.
When authenticating, it will:
This method requires you to create a Meta Developer App first.
The Meta Ads MCP includes a comprehensive logging system to help troubleshoot issues:
Log files are stored in a platform-specific location:
~/Library/Application Support/meta-ads-mcp/meta_ads_debug.log
%APPDATA%\meta-ads-mcp\meta_ads_debug.log
~/.config/meta-ads-mcp/meta_ads_debug.log
If you're having authentication problems:
Recommended: Use Pipeboard Authentication
export PIPEBOARD_API_TOKEN=your_token
and retryFor App ID issues (when using direct authentication):
If you encounter errors like (#200) Provide valid app ID
, check the following:
META_APP_ID
environment variable: export META_APP_ID=your_app_id
meta-ads-mcp --app-id your_app_id
If you receive errors from the Meta API:
For specific image download issues, use the built-in diagnostic tool:
# Using direct tool call
mcp_meta_ads_debug_image_download(ad_id="your_ad_id")
This will give you detailed information about the download process and potential issues.
If you need to use different Meta App IDs for different purposes:
# Using environment variable
export META_APP_ID=your_app_id
uvx meta-ads-mcp
# Or using command line argument
uvx meta-ads-mcp --app-id=your_app_id
The Meta Ads MCP follows security best practices:
Tokens are cached in a platform-specific secure location:
%APPDATA%\meta-ads-mcp\token_cache.json
or %APPDATA%\meta-ads-mcp\pipeboard_token_cache.json
~/Library/Application Support/meta-ads-mcp/token_cache.json
or ~/Library/Application Support/meta-ads-mcp/pipeboard_token_cache.json
~/.config/meta-ads-mcp/token_cache.json
or ~/.config/meta-ads-mcp/pipeboard_token_cache.json
You do not need to provide your access token for each command; it will be automatically retrieved from the cache.
You can set the following environment variables instead of passing them as arguments:
META_APP_ID
: Your Meta App ID (Client ID) - for direct OAuth methodPIPEBOARD_API_TOKEN
: Your Pipeboard API token - for Pipeboard authentication methodRun the test script to verify authentication and basic functionality:
python test_meta_ads_auth.py --app-id YOUR_APP_ID
Use the --force-login
flag to force a new authentication even if a cached token exists:
python test_meta_ads_auth.py --app-id YOUR_APP_ID --force-login
When using the Meta Ads MCP with an LLM interface (like Claude):
mcp_meta_ads_get_login_link
toolmcp_meta_ads_get_ad_accounts
mcp_meta_ads_get_account_info
These functions will automatically handle authentication if needed and provide a clickable login link if required.
If you encounter authentication issues:
When using the LLM interface:
mcp_meta_ads_get_login_link
tool to generate a fresh authentication linkWhen using Pipeboard authentication:
PIPEBOARD_API_TOKEN
is set correctly (token obtainable via https://pipeboard.co)python test_pipeboard_auth.py --force-login
When using direct Meta OAuth:
--force-login
to get a fresh token: uvx meta-ads-mcp --login --app-id YOUR_APP_ID --force-login
If you receive errors from the Meta API:
You can check the current version of the package:
import meta_ads_mcp
print(meta_ads_mcp.__version__)