facebook-ads-library
MCP Server for Facebook ADs Library - Get instant answers from FB's ad library
claude mcp add --transport stdio talknerdytome-labs-facebook-ads-library-mcp python mcp_server.py \ --env GEMINI_API_KEY="Google Gemini API key (optional for video analysis)" \ --env SCRAPE_CREATORS_API_KEY="Your Scrape Creators API key"
How to use
This MCP server provides a Python-based integration for querying Facebook's public Ads Library. It exposes tools to map brand strings to platform IDs, fetch current ads for one or more pages, analyze ad creatives (images and videos), and batch-process multiple items to improve efficiency. Use the batch-enabled tools to perform bulk lookups and analyses across several brands or pages in a single request, with smart caching and credit management to minimize redundant calls. The server outputs structured data suitable for downstream analysis in Claude Desktop or Cursor, including insights on ad visuals, messaging, and video performance where you have a Gemini API key configured.
To use, connect this MCP server to Claude Desktop or Cursor using the provided configuration example. Once connected, you can invoke tools such as get_meta_platform_id to resolve brand names to platform IDs, get_meta_ads to retrieve current ads for specific pages, analyze_ad_image to inspect image elements, analyze_ad_video for video-level insights, and analyze_ad_videos_batch to process multiple videos in a single call. The tooling also includes cache and credit management utilities to keep operations fast and within API limits. When using the video analysis tools, ensure you have a Google Gemini API key configured if you plan to analyze video ads.
How to install
Prerequisites:
- Python 3.12+
- Pip (Python package manager)
- Scrape Creators API key
- Optional: Google Gemini API key for video analysis
Quick Install (Recommended):
- Clone the repository and install dependencies in a virtual environment
git clone http://github.com/talknerdytome-labs/facebook-ads-library-mcp.git cd facebook-ads-library-mcp python3 -m venv venv source venv/bin/activate # macOS/Linux # Windows: .\venv\Scripts\activate pip install -r requirements.txt - Configure API keys
Required keys include SCRAPE_CREATORS_API_KEY and optionally GEMINI_API_KEY for video analysis.# Create and edit .env or use provided template cp .env.template .env # Edit .env with your actual keys - Run the MCP server locally (development/testing)
python mcp_server.py - Connect to Claude Desktop or Cursor by adding the MCP server configuration:
Replace {{PATH_TO_PROJECT}} with the full path to the cloned repository.{ "mcpServers": { "fb_ad_library": { "command": "{{PATH_TO_PROJECT}}/facebook-ads-library-mcp/venv/bin/python", "args": ["{{PATH_TO_PROJECT}}/facebook-ads-library-mcp/mcp_server.py"] } } }
Manual Install:
- Clone the repository
git clone https://github.com/trypeggy/facebook-ads-library-mcp.git cd facebook-ads-library-mcp - Create a virtual environment and install dependencies
python3 -m venv venv source venv/bin/activate # macOS/Linux # Windows: .\venv\Scripts\activate pip install -r requirements.txt - Configure API keys
cp .env.template .env # Edit .env with actual API keys for SCRAPE_CREATORS_API_KEY and GEMINI_API_KEY (optional) - Connect to the MCP server in Claude Desktop or Cursor using the same JSON snippet as above.
Additional notes
Notes and tips:
- The server supports batch operations for get_meta_platform_id and get_meta_ads, allowing single strings or arrays of inputs for efficiency.
- If you enable video analysis, provide a Google Gemini API key; otherwise, video insights will be limited.
- The system includes smart credit management that detects API credit exhaustion and provides direct top-up links.
- Ensure your environment variables are loaded from a .env file rather than passing keys on the command line for security.
- If you encounter path issues, ensure the command points to the correct Python interpreter inside your virtual environment (venv/bin/python or equivalent on Windows).
- The MCP tools cache results to speed up repeated queries; you can inspect cache stats via get_cache_stats, and manage storage with cleanup_media_cache.
Related MCP Servers
aci
ACI.dev is the open source tool-calling platform that hooks up 600+ tools into any agentic IDE or custom AI agent through direct function calling or a unified MCP server. The birthplace of VibeOps.
anyquery
Query anything (GitHub, Notion, +40 more) with SQL and let LLMs (ChatGPT, Claude) connect to using MCP
bytechef
Open-source, AI-native, low-code platform for API orchestration, workflow automation, and AI agent integration across internal systems and SaaS products.
lihil
2X faster ASGI web framework for python, offering high-level development, low-level performance.
instagram_dm_mcp
Instagram Direct messages MCP
hackmd
A Model Context Protocol server for integrating HackMD's note-taking platform with AI assistants.