Facebook Ads Library MCP Server
This is a Model Context Protocol (MCP) server for the Facebook Ads Library.
With this you can search Facebook's public ads library for any company or brand, see what they're currently running and analyze their advertising. You can analyze ad images/text, analyze video ads with comprehensive insights, compare companies' strategies, and get insights into what's working in their campaigns.
✨ New Features
- 🚀 Batch Processing: Query multiple brands and platform IDs simultaneously to reduce API calls and improve efficiency
- 🎬 Video Batch Analysis: Analyze multiple videos in a single Gemini API call with ~88% token savings
- 💳 Smart Credit Management: Automatic detection of API credit exhaustion with direct links to top-up your ScrapeCreators account
- ⚡ Enhanced Performance: Intelligent caching and request deduplication for faster results
- 🔄 Backward Compatible: All existing queries work unchanged while gaining new batch capabilities
Here's an example of what you can do when it's connected to Claude.
https://github.com/user-attachments/assets/a47aa689-e89d-4d4b-9df7-6eb3a81937ee
To get updates on this and other projects we work on subscribe here
PS: Join our Twitter community for all things MCP
Example Prompts
Single Brand Analysis
Batch Analysis (New!)
Installation
Prerequisites
- Python 3.12+
- Anthropic Claude Desktop app (or Cursor)
- Pip (Python package manager), install with
python -m pip install
- An access token for Scrape Creators
- A Google Gemini API key for video analysis (optional, only needed for video ads)
Quick Install (Recommended)
- Clone and run the install scriptThe install script will:
- Create a virtual environment for dependency isolation
- Install all required dependencies
- Set up your configuration files
- Configure your API keysEdit the
.env
file that was created and add your API keys:- Get your ScrapeCreators API key at scrapecreators.com
- Get your Gemini API key at Google AI Studio (optional, for video analysis)
- Follow the displayed MCP configurationThe install script will show you the exact configuration to add to Claude Desktop or Cursor.
Manual Install
If you prefer to install manually:
- Clone this repository
- Create a virtual environment and install dependencies
- Configure API keysCopy the template and configure your API keys:To obtain API keys:
- Connect to the MCP serverAdd the MCP server configuration to your Claude Desktop or Cursor config:Replace
{{PATH_TO_PROJECT}}
with the full path to where you cloned this repository.Note: The configuration uses the virtual environment's Python interpreter (venv/bin/python
) for better dependency isolation and reliability.Note: API keys are now automatically loaded from the.env
file, so you don't need to pass them as command line arguments.For Claude Desktop:Save this asclaude_desktop_config.json
in your Claude Desktop configuration directory at:For Cursor:Save this asmcp.json
in your Cursor configuration directory at: - Restart Claude Desktop / CursorOpen Claude Desktop and you should now see the Facebook Ads Library as an available integration.Or restart Cursor.
Technical Details
- Claude sends requests to the Python MCP server
- The MCP server intelligently batches and optimizes queries to the ScrapeCreators API
- Smart caching reduces redundant API calls and improves performance
- Credit monitoring prevents workflow interruption with proactive error handling
- Data flows back through the chain to Claude with enhanced batch information
Available MCP Tools (Enhanced)
This MCP server provides tools for interacting with Facebook Ads library objects:
Tool Name | Description | Batch Support |
---|---|---|
get_meta_platform_id | Returns platform ID given one or many brand names | ✅ Multiple brands |
get_meta_ads | Retrieves ads for specific page(s) (platform ID) | ✅ Multiple platform IDs |
analyze_ad_image | Analyzes ad images for visual elements, text, colors, and composition | ⚡ Enhanced caching |
analyze_ad_video | Analyzes single ad video using Gemini AI for comprehensive insights | ⚡ Enhanced caching |
analyze_ad_videos_batch | NEW - Analyzes multiple videos in single API call for token efficiency | 🎬 ~88% token savings |
get_cache_stats | Gets statistics about cached media (images and videos) and storage usage | - |
search_cached_media | Searches previously analyzed media by brand, colors, people, or media type | - |
cleanup_media_cache | Cleans up old cached media files to free disk space | - |
🆕 Enhanced Features:
- Batch Processing:
get_meta_platform_id
andget_meta_ads
now accept single strings or arrays for efficient bulk operations - Video Batch Analysis:
analyze_ad_videos_batch
processes multiple videos in a single Gemini API call for massive token savings - Smart Credit Management: All tools detect API credit exhaustion and provide direct links to top-up
- Request Deduplication: Automatic removal of duplicate requests in batch operations
- Token Optimization: Shared prompt processing reduces Gemini API costs by ~88% for video analysis
- Backward Compatibility: All existing single-query workflows continue to work unchanged
Troubleshooting
Common Issues
🆕 ScrapeCreators API Credits Exhausted:
- When you see "ScrapeCreators API credits exhausted", you need to top up your account
- The error message includes a direct link to ScrapeCreators Dashboard
- You can check your current credit balance and purchase more credits there
- The server will automatically resume working once credits are available
🆕 Rate Limit Exceeded:
- If you hit rate limits, the server will tell you how long to wait
- Batch operations help reduce the chance of hitting rate limits
- Consider spacing out large batch requests if you frequently hit limits
API Key Not Found Error:
- Ensure your
.env
file is in the project root directory - If you don't have a
.env
file, copy it from the template:cp .env.template .env
- Check that your API keys are correctly formatted without quotes
- Verify the
.env
file containsSCRAPECREATORS_API_KEY=your_key_here
- For video analysis, ensure
GEMINI_API_KEY=your_key_here
is also added
Video Analysis Not Working:
- Confirm you have a valid Google Gemini API key in your
.env
file - Video analysis requires the
GEMINI_API_KEY
environment variable
MCP Server Connection Issues:
- Verify the path in your MCP configuration points to the correct location
- Make sure you've created a virtual environment and installed dependencies with
python3 -m venv venv && ./venv/bin/pip install -r requirements.txt
- Ensure your MCP configuration uses the virtual environment Python path (ending with
/venv/bin/python
) - Restart Claude Desktop/Cursor after configuration changes
For additional Claude Desktop integration troubleshooting, see the MCP documentation. The documentation includes helpful tips for checking logs and resolving common issues.
Feedback
Your feedback will be massively appreciated. Please tell us which features on that list you like to see next or request entirely new ones.
License
This project is licensed under the MIT License.
This server cannot be installed
This MCP server lets you search Facebook's Ad Library, retrieve brand ads, and analyze ad images/videos using AI - all with intelligent caching and batch processing for efficiency.