Facebook Ads Library MCP logo

Facebook Ads Library MCP

Community
RamsesAguirre777

Free, self-hosted MCP server that scrapes the public Facebook Ad Library (no API token) for competitive ad research — advertiser, copy, landing pages, CTAs, any country.

PublisherRamsesAguirre777
Repositoryfacebook-ads-library-mcp
LanguagePython
Forks
39
Stars
257
Available tools
0
Transport typestdio
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    Facebook Ads Library MCP exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    257 stars and 39 forks from the linked repository.

Facebook Ad Library MCP

Python 3.10+ FastMCP License: MIT

A small MCP server that scrapes the public Facebook Ad Library for competitive ad research — from your MCP client, with no Facebook account and no API token.

It exists because the paid Ad Library scrapers (Apify actors, ScrapeCreators, and friends) charge for something that is publicly visible in a browser. This just drives a headless browser instead.

Why not the official API?

Meta's ads_archive API only returns political & issue ads worldwide (and all ad types only for the EU/UK). For an ordinary commercial advertiser in most of the world it returns nothing useful — no ads, no spend, no impressions. So this server doesn't use it at all. It renders the same Ad Library web page you'd open yourself and parses the cards.

What you get

Two tools:

  • search_ad_library(query, country="MX", ...) — keyword search.
  • scrape_ad_library_url(url, ...) — scrape any Ad Library URL you already have.

Both return structured records per ad:

fieldmeaning
advertiser, advertiser_handlePage name and its facebook.com/<handle>
started_runningfirst-seen date
ads_using_creativehow many creatives share this copy — a rough scale signal
landing_url, landing_domaindestination, unwrapped from the l.facebook.com redirect
ctathe button label (Learn more, Sign up, Send message, …)
link_textthe headline strip under the creative
bodyfull ad copy
creative_imagethumbnail URL
ad_details_urldeep link to that ad's detail view

Plus an advertisers histogram and the raw_markdown of the page so the model can pull anything the parser missed.

Install

bash
git clone https://github.com/RamsesAguirre777/facebook-ads-library-mcp.git
cd facebook-ads-library-mcp
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
python -m playwright install chromium   # crawl4ai needs a browser

Register with your MCP client

Claude Code:

bash
claude mcp add facebook-ads -- /abs/path/venv/bin/python /abs/path/facebook_ads_mcp_complete.py

Claude Desktop (claude_desktop_config.json):

json
{
  "mcpServers": {
    "facebook-ads": {
      "command": "/abs/path/venv/bin/python",
      "args": ["/abs/path/facebook_ads_mcp_complete.py"]
    }
  }
}

Restart the client.

Usage

"Search the Mexico Ad Library for 'automatización con inteligencia artificial',
 group by advertiser, and list the landing domains."

"Scrape https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=MX&q=nike&search_type=keyword_unordered
 with scroll_rounds=15 and summarise the creative angles."

Full discovery → website-teardown workflow: docs/examples.md.

Parameters worth knowing

  • scroll_rounds (default 8) — the Ad Library is infinite-scroll; the first paint is only ~20–26 cards. Each round is a scroll-to-bottom + 2.5s wait. 0 = first render only (fast); 15+ for a deep historical sweep. It trades time for completeness.
  • wait_seconds (default 8) — SPA hydration wait before scraping. Raise it if results come back empty.
  • country — ISO code the ads were delivered in (MX, US, ES, …).
  • advertiser_page_id — target one Page's "all ads" view. This view is heavier client-rendered and doesn't always hydrate headless; a keyword search of the advertiser name is more reliable.

How it works

crawl4ai (AsyncWebCrawler) opens the Ad Library URL in headless Chromium, waits for the React app to hydrate, runs a scroll loop to trigger lazy-loaded cards, serialises the DOM to markdown, and a regex parser (_parse_ad_library_markdown) splits it on Library ID: boundaries and pulls the fields above.

Facebook answers the headless browser with HTTP 403 but still serves the rendered cards, so the tools judge success by whether cards parsed, not by status code.

Limitations

  • It parses the public SPA markup, so a Facebook layout change can break field extraction. raw_markdown is always returned as a fallback.
  • platforms often comes back empty — the FB/IG/Messenger markers render as icons, not text, so they only survive when the page includes their labels.
  • No caching or rate-limit handling. If you hammer it you'll get empty results for a while; back off and raise wait_seconds.
  • Spend and impression numbers are not available — Meta only publishes those for political ads, and only through the API. This tool gives you creative, cadence and landing-page intelligence, not budget figures.

Tests

bash
python -m pytest tests/ -q

Offline — they exercise the markdown parser against a fixture.

License

MIT — see LICENSE.

Acknowledgments

Installation

TypingMind
{
  "mcpServers": {
    "facebook-ads-library-mcp": {
      "command": "python",
      "args": [
        "/path/to/facebook-ads-library-mcp/facebook_ads_mcp_complete.py",
        "--facebook-token",
        "YOUR_FACEBOOK_ACCESS_TOKEN"
      ]
    }
  }
}

Use Facebook Ads Library MCP MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once Facebook Ads Library MCP is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add Facebook Ads Library MCP as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the Facebook Ads Library MCP MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "facebook-ads-library-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the Facebook Ads Library MCP MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the Facebook Ads Library MCP MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use Facebook Ads Library MCP to help me with this task?
Facebook Ads Library MCP
Sure. I read it.
Here is what I found using Facebook Ads Library MCP.

Frequently asked questions

What is the Facebook Ads Library MCP MCP server used for?

Facebook Ads Library MCP is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use Facebook Ads Library MCP MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use Facebook Ads Library MCP with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use Facebook Ads Library MCP MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With Facebook Ads Library MCP connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect Facebook Ads Library MCP MCP to TypingMind?

Facebook Ads Library MCP runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does Facebook Ads Library MCP MCP provide in TypingMind?

Facebook Ads Library MCP exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use Facebook Ads Library MCP MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If Facebook Ads Library MCP requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇