meta-mcp

brijr/meta-mcp

3.4

If you are the rightful owner of meta-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

Meta Marketing API MCP Server is a comprehensive Model Context Protocol server that facilitates interaction with Facebook/Instagram advertising data through the Meta Marketing API.

Meta Marketing API MCP Server

A comprehensive Model Context Protocol (MCP) server that enables AI assistants like Claude to interact with Facebook/Instagram advertising data through the Meta Marketing API. This server provides full campaign lifecycle management, analytics, audience targeting, and creative optimization capabilities.

๐Ÿš€ Features

Campaign Management

  • โœ… Create, update, pause, resume, and delete campaigns
  • โœ… Support for all campaign objectives (traffic, conversions, awareness, etc.)
  • โœ… Budget management and scheduling
  • โœ… Ad set creation with advanced targeting
  • โœ… Individual ad management

Analytics & Reporting

  • ๐Ÿ“Š Performance insights with customizable date ranges
  • ๐Ÿ“ˆ Multi-object performance comparison
  • ๐Ÿ“‹ Data export in CSV/JSON formats
  • ๐ŸŽฏ Attribution modeling and conversion tracking
  • ๐Ÿ“… Daily performance trends analysis

Audience Management

  • ๐Ÿ‘ฅ Custom audience creation and management
  • ๐ŸŽฏ Lookalike audience generation
  • ๐Ÿ“ Audience size estimation
  • ๐Ÿ” Targeting recommendations and insights
  • ๐Ÿฅ Audience health monitoring

Creative Management

  • ๐ŸŽจ Ad creative creation and management
  • ๐Ÿ‘๏ธ Cross-platform ad previews
  • ๐Ÿงช A/B testing setup and guidance
  • ๐Ÿ“ธ Creative performance analysis

Enterprise Features

  • ๐Ÿ” Secure OAuth 2.0 authentication
  • โšก Automatic rate limiting with exponential backoff
  • ๐Ÿ”„ Pagination support for large datasets
  • ๐Ÿ›ก๏ธ Comprehensive error handling
  • ๐Ÿ“š Rich MCP resources for contextual data access
  • ๐ŸŒ Multi-account support

๐Ÿ“ฆ Installation & Setup

Option 1: Direct Installation (Recommended)

npm install -g meta-ads-mcp

Option 2: From Source

git clone https://github.com/your-org/meta-ads-mcp.git
cd meta-ads-mcp
npm install
npm run build

Option 3: Automated Setup (Easiest)

# Clone the repository first
git clone https://github.com/your-org/meta-ads-mcp.git
cd meta-ads-mcp

# Run the interactive setup
npm run setup

The setup script will:

  • โœ… Check system requirements
  • โœ… Validate your Meta access token
  • โœ… Create Claude Desktop configuration
  • โœ… Install dependencies
  • โœ… Test the connection

๐Ÿ”ง Configuration Guide

Step 1: Get Meta Access Token

  1. Create a Meta App at developers.facebook.com
  2. Add Marketing API product
  3. Generate an access token with ads_read and ads_management permissions
  4. (Optional) Set up OAuth for automatic token refresh

Step 2: Configure Claude Desktop

Find your configuration file:
  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

If the file doesn't exist, create it with the following content:

Basic Configuration (Token-based):
{
  "mcpServers": {
    "meta-ads": {
      "command": "npx",
      "args": ["-y", "meta-ads-mcp"],
      "env": {
        "META_ACCESS_TOKEN": "your_access_token_here"
      }
    }
  }
}
Advanced Configuration (with OAuth):
{
  "mcpServers": {
    "meta-ads": {
      "command": "npx",
      "args": ["-y", "meta-ads-mcp"],
      "env": {
        "META_ACCESS_TOKEN": "your_access_token_here",
        "META_APP_ID": "your_app_id",
        "META_APP_SECRET": "your_app_secret",
        "META_AUTO_REFRESH": "true",
        "META_BUSINESS_ID": "your_business_id"
      }
    }
  }
}
Local Development Configuration:

If you've cloned the repository locally:

{
  "mcpServers": {
    "meta-ads": {
      "command": "node",
      "args": ["/absolute/path/to/meta-ads-mcp/build/index.js"],
      "env": {
        "META_ACCESS_TOKEN": "your_access_token_here"
      }
    }
  }
}

Step 3: Configure for Cursor

Cursor uses the same MCP configuration as Claude Desktop. Add the configuration to your Cursor settings:

  1. Open Cursor Settings
  2. Go to "Extensions" > "Claude"
  3. Add the MCP server configuration in the JSON settings

Step 4: Restart Your Client

  • Claude Desktop: Completely quit and restart the application
  • Cursor: Restart the IDE

Step 5: Verify Setup

# Run health check to verify everything is working
npm run health-check

# Or if installed globally
npx meta-ads-mcp --health-check

๐Ÿ” Troubleshooting

Common Issues

1. "Command not found" or "npx" errors
# Install Node.js if not installed
# macOS: brew install node
# Windows: Download from nodejs.org
# Linux: Use your package manager

# Verify installation
node --version
npm --version
npx --version
2. Permission errors
# Fix npm permissions (macOS/Linux)
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

# Or install without sudo
npm config set prefix ~/.npm-global
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
3. Meta API connection issues
# Test your token manually
curl -G \
  -d "access_token=YOUR_ACCESS_TOKEN" \
  "https://graph.facebook.com/v23.0/me/adaccounts"
4. Check Claude Desktop logs
  • macOS: ~/Library/Logs/Claude/mcp*.log
  • Windows: %APPDATA%\Claude\logs\mcp*.log
# macOS/Linux - View logs
tail -f ~/Library/Logs/Claude/mcp*.log

# Windows - View logs
type "%APPDATA%\Claude\logs\mcp*.log"
5. Test the server manually
# Test the MCP server directly
npx -y meta-ads-mcp

# Or if installed locally
node build/index.js

Debug Mode

Enable debug logging by adding to your environment:

{
  "mcpServers": {
    "meta-ads": {
      "command": "npx",
      "args": ["-y", "meta-ads-mcp"],
      "env": {
        "META_ACCESS_TOKEN": "your_access_token_here",
        "DEBUG": "mcp:*",
        "NODE_ENV": "development"
      }
    }
  }
}

๐ŸŒ Web Deployment (Vercel)

For web applications, this server is also available as a Vercel deployment with OAuth authentication:

Configuration:

  1. Deploy to Vercel or use our hosted version
  2. Set environment variables in Vercel dashboard
  3. Configure OAuth app in Meta Developer Console
  4. Use the web endpoint: https://your-project.vercel.app/api/mcp

MCP Client Configuration for Web:

{
  "mcpServers": {
    "meta-ads-remote": {
      "url": "https://mcp.offerarc.com/api/mcp",
      "headers": {
        "Authorization": "Bearer your_session_token"
      }
    }
  }
}

Note: You need to authenticate first at https://mcp.offerarc.com/api/auth/login to get your session token.

Remote MCP Configuration (mcp-remote)

For Vercel deployments, use mcp-remote to bridge HTTP to stdio:

{
  "mcpServers": {
    "meta-ads": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "https://mcp.offerarc.com/api/mcp",
        "--header",
        "Authorization:${META_AUTH_HEADER}"
      ],
      "env": {
        "META_AUTH_HEADER": "Bearer your_session_token_here"
      }
    }
  }
}

๐Ÿ› ๏ธ Available Tools

This MCP server provides 25 comprehensive tools across all major Meta advertising categories:

๐Ÿ“Š Analytics & Insights (3 tools)

  • get_insights - Get detailed performance metrics (impressions, clicks, ROAS, CTR, CPC, etc.)
  • compare_performance - Side-by-side performance comparison of multiple campaigns/ads
  • export_insights - Export performance data in JSON or CSV formats

๐Ÿ“ˆ Campaign Management (4 tools)

  • create_campaign - Create new advertising campaigns with full configuration (includes special_ad_categories)
  • update_campaign - Modify existing campaigns (name, budget, status, etc.)
  • pause_campaign - Pause active campaigns
  • resume_campaign - Resume/activate paused campaigns

๐ŸŽฏ Ad Set Management (2 tools)

  • create_ad_set - Create ad sets with detailed targeting, budgets, and optimization goals
  • list_ad_sets - List and filter ad sets within campaigns

๐Ÿ“ฑ Ad Management (2 tools)

  • create_ad - Create individual ads within ad sets using creative IDs
  • list_ads - List and filter ads by ad set, campaign, or account

๐Ÿ‘ฅ Audience Management (4 tools)

  • list_audiences - List all custom audiences for an account
  • create_custom_audience - Create custom audiences from various sources
  • create_lookalike_audience - Generate lookalike audiences from source audiences
  • get_audience_info - Get detailed information about specific audiences

๐ŸŽจ Creative Management (2 tools)

  • list_ad_creatives - List all ad creatives for an account
  • create_ad_creative - Create new ad creatives with rich specifications (supports external image URLs)

๐Ÿ”ง Account & Basic Tools (3 tools)

  • health_check - Comprehensive authentication and server status check
  • get_ad_accounts - List accessible Meta ad accounts
  • get_campaigns - List campaigns with filtering options

๐Ÿ” Authentication Tools (1 tool)

  • get_token_info - Token validation and information retrieval

๐Ÿฉบ Diagnostic Tools (2 tools)

  • diagnose_campaign_readiness - Check campaign status and identify ad set creation issues
  • check_account_setup - Comprehensive account validation and setup verification

๐Ÿ› ๏ธ Usage Examples

Test the Connection

Check the health of the Meta Marketing API server and authentication status

Analytics & Performance Insights

Get detailed performance insights for my Deal Draft campaign including impressions, clicks, ROAS, and CTR for the last 30 days
Compare the performance of my top 3 campaigns side-by-side for the last quarter
Export campaign performance data for all my campaigns last month in CSV format

Campaign Management

Create a new traffic campaign named "Holiday Sale 2024" with a $50 daily budget and OUTCOME_TRAFFIC objective
Update my existing campaign budget to $100 daily and change the name to "Black Friday Special"
Pause all campaigns that have a CPC above $2.00
Resume my paused "Summer Collection" campaign

Complete Campaign Setup (Campaign โ†’ Ad Set โ†’ Ads)

Create a complete "Test 3" campaign setup: 1) Create the campaign with OUTCOME_LEADS objective, 2) Create an ad set targeting US users aged 25-45 interested in entrepreneurship, 3) Create 4 different ads using my existing creatives
Create an ad set for my existing campaign targeting women aged 30-50 in major US cities with interests in business and personal development
Create a new ad in my ad set using creative ID 123456 and name it "Headline Test A"

Troubleshooting & Diagnostics

Diagnose my "Test 3" campaign to see if it's ready for ad set creation and identify any potential issues
Check my account setup to verify payment methods, business verification, and ad account permissions
Check why my ad set creation failed and get specific recommendations for my account setup

Audience Management

List all my custom audiences and show their sizes and status
Create a custom audience named "Website Visitors" from people who visited my site
Create a 5% lookalike audience based on my "High Value Customers" audience targeting the US
Get detailed information about my "Newsletter Subscribers" audience including health status

Creative Management

List all my ad creatives and show their performance data
Create a new ad creative for my holiday campaign with external image URL from my website and specific messaging

Account Management

Show me all my accessible Meta ad accounts with their currencies and time zones
Get my current access token information including permissions and expiration

๐Ÿ“š Resources Access

The server provides rich contextual data through MCP resources:

  • meta://campaigns/{account_id} - Campaign overview
  • meta://insights/account/{account_id} - Performance dashboard
  • meta://audiences/{account_id} - Audience insights
  • meta://audience-health/{account_id} - Audience health report

๐Ÿ”ง Environment Variables

Required

META_ACCESS_TOKEN=your_access_token_here

Optional

META_APP_ID=your_app_id                    # For OAuth
META_APP_SECRET=your_app_secret            # For OAuth
META_BUSINESS_ID=your_business_id          # For business-specific operations
META_API_VERSION=v23.0                     # API version (default: v23.0)
META_API_TIER=standard                     # 'development' or 'standard'
META_AUTO_REFRESH=true                     # Enable automatic token refresh
META_REFRESH_TOKEN=your_refresh_token      # For token refresh

๐Ÿ“– Documentation

  • - 5-minute setup instructions
  • - Complete installation and configuration
  • - All available tools and resources
  • - Sample configuration file

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Claude AI     โ”‚โ—„โ”€โ”€โ–บโ”‚ MCP Server       โ”‚โ—„โ”€โ”€โ–บโ”‚ Meta Marketing  โ”‚
โ”‚                 โ”‚    โ”‚                  โ”‚    โ”‚ API             โ”‚
โ”‚ - Natural       โ”‚    โ”‚ - Authentication โ”‚    โ”‚                 โ”‚
โ”‚   Language      โ”‚    โ”‚ - Rate Limiting  โ”‚    โ”‚ - Campaigns     โ”‚
โ”‚ - Tool Calls    โ”‚    โ”‚ - Error Handling โ”‚    โ”‚ - Analytics     โ”‚
โ”‚ - Resource      โ”‚    โ”‚ - Data Transform โ”‚    โ”‚ - Audiences     โ”‚
โ”‚   Access        โ”‚    โ”‚ - Pagination     โ”‚    โ”‚ - Creatives     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Core Components

  • Meta API Client: Handles authentication, rate limiting, and API communication
  • Tool Handlers: 25 tools covering analytics, campaigns, ad sets, ads, audiences, creatives, and diagnostics
  • Resource Providers: Contextual data access for AI understanding
  • Error Management: Robust error handling with automatic retries
  • Rate Limiter: Intelligent rate limiting with per-account tracking

๐Ÿ”’ Security & Best Practices

Token Security

  • โœ… Environment variable configuration
  • โœ… No token logging or exposure
  • โœ… Automatic token validation
  • โœ… Secure credential management

API Management

  • โœ… Rate limit compliance
  • โœ… Exponential backoff retries
  • โœ… Request validation
  • โœ… Error boundary protection

Data Privacy

  • โœ… Meta data use policy compliance
  • โœ… No persistent data storage
  • โœ… Secure API communication
  • โœ… Audit trail support

โšก Performance

Rate Limits

  • Development Tier: 60 API calls per 5 minutes
  • Standard Tier: 9000 API calls per 5 minutes
  • Automatic Management: Built-in rate limiting and retry logic

Optimization

  • ๐Ÿš€ Concurrent request processing
  • ๐Ÿ“ฆ Efficient pagination handling
  • ๐ŸŽฏ Smart data caching
  • โšก Minimal memory footprint

๐Ÿงช Testing

Run the test suite:

npm test

Test with example client:

npx tsx examples/client-example.ts

Health check:

# In Claude:
Check the health of the Meta Marketing API server

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/new-feature
  3. Make your changes and add tests
  4. Run the test suite: npm test
  5. Submit a pull request

๐Ÿ“„ License

MIT License - see for details.

๐Ÿ†˜ Support

๐Ÿท๏ธ Version History

v1.1.0 (Latest)

  • โœ… Complete tool suite: 25 comprehensive tools for all Meta advertising needs
  • ๐Ÿฉบ Advanced diagnostics: Campaign readiness checking, account setup validation, and issue identification
  • ๐Ÿš€ Full campaign creation pipeline: Campaign โ†’ Ad Set โ†’ Ads complete workflow (fully functional)
  • ๐ŸŽฏ Advanced ad set targeting: Demographics, interests, behaviors, custom audiences
  • ๐Ÿ“ฑ Individual ad management: Create and manage ads with creative assignments
  • ๐Ÿ–ผ๏ธ External image URL support: Create ad creatives using external image URLs (picture field in link_data)
  • ๐Ÿ”ง Fixed campaign creation: Added special_ad_categories parameter and missing API methods
  • ๐Ÿ—‘๏ธ Removed ping tool: Simplified tool set, health_check provides better connectivity testing
  • โœ… Enhanced Vercel deployment: Full web interface with OAuth authentication
  • โœ… Advanced analytics: Performance insights, comparison, and export tools
  • โœ… Campaign management: Create, update, pause, resume campaigns
  • โœ… Audience tools: Custom and lookalike audience creation and management
  • โœ… Creative management: Ad creative listing and creation tools with external URL support
  • โœ… Improved authentication: Session-based auth for remote deployments
  • โœ… Better error handling: Comprehensive TypeScript error resolution
  • โœ… Using Meta Graph API v23.0 (latest version)
  • โœ… Added support for Outcome-Driven Ad Experience (ODAE) objectives
  • โœ… Added campaign-level budget optimization support
  • โœ… Added bid strategy options (LOWEST_COST_WITHOUT_CAP, LOWEST_COST_WITH_BID_CAP, COST_CAP)
  • โœ… Removed deprecated insights metrics per Meta API v19.0 changes
  • โœ… Enhanced campaign creation with bid cap and budget optimization features

v1.0.5

  • โœ… Fixed ad set creation to use correct account endpoint
  • โœ… Improved error handling for campaign operations

v1.0.4

  • โœ… Enhanced campaign management features
  • โœ… Improved API error responses

v1.0.3

  • โœ… Added docker support
  • โœ… Improved deployment options

v1.0.2

  • โœ… Fixed entry point issue for npx compatibility
  • โœ… Added detailed startup debugging logs
  • โœ… Improved error handling and diagnostics

v1.0.1

  • โœ… Enhanced debugging capabilities
  • โœ… Better error reporting

v1.0.0

  • โœ… Complete Meta Marketing API integration
  • โœ… 40+ tools and resources
  • โœ… Advanced rate limiting
  • โœ… Comprehensive error handling
  • โœ… Multi-account support
  • โœ… Production-ready security

Built with โค๏ธ for the AI-powered advertising future