Active public Meta ads worldwide (plus EU/UK/BR and political archives) from one static binary — zero browser, zero API key required, plus local SQLite competitive intelligence.
Search active and inactive commercial ads across Facebook, Instagram, Threads, Messenger, and Audience Network in any country via pure HTTP, with optional official Graph API v27.0 ads_archive lookups when META_ACCESS_TOKEN is set. Captures from ads search, ads details, diff --refresh, sov --live, and sync compound into local SQLite FTS5 tables powering winners, diff, compare, hooks, funnels, transparency, and sov (official archive queries Graph API independently).
Authentication
No API key or browser is required for public commercial ad search (ads search), advertiser lookup (advertisers search), ad details (ads details), media downloads (media download), or local intelligence commands — the CLI bootstraps an anonymous GraphQL session automatically. To query Meta's official Graph API v27.0 ads_archive endpoint (archive) for political/issue spend ranges and EU/UK/BR reach datasets, export META_ACCESS_TOKEN (also accepts META_ADS_ARCHIVE_TOKEN or FACEBOOK_ACCESS_TOKEN) or persist it with meta-ads-library-pp-cli auth set-token (auth status and auth logout manage stored tokens). Note: doctor reports META_ACCESS_TOKEN as missing in zero-auth mode unless configured for archive.
Quick Start
# Preview CLI doctor health check and local database paths without network calls
meta-ads-library-pp-cli doctor --dry-run
# Resolve a brand name to its official Facebook Page ID with zero API key
meta-ads-library-pp-cli advertisers search "Nike" --country US --agent
# Fetch active ads via pure HTTP and persist them into the local SQLite mirror
meta-ads-library-pp-cli ads search --page-id 15087023444 --country US --limit 25 --agent
# Rank longest-running evergreen ads and highest-collation creatives from local SQLite
meta-ads-library-pp-cli winners 15087023444 --min-days 30 --agent
# Group unwrapped landing domains, URL paths, and UTM funnels across active creatives
meta-ads-library-pp-cli funnels 15087023444 --agent
Unique Features
Creative & funnel intelligence
-
winners — Rank active ads by proven longevity (days running), collation scale, and platform breadth.
Reach for this when an operator asks which competitor creatives have been running longest or scaling hardest.
meta-ads-library-pp-cli winners 15087023444 --min-days 30 --agent
-
funnels — Group active ads by unwrapped destination domain, URL path, and UTM parameters including carousel cards.
Reach for this to map where a competitor sends paid traffic and which landing pages carry the most ad volume.
meta-ads-library-pp-cli funnels 15087023444 --agent
-
hooks — Extract, deduplicate, and rank opening copy hooks, headlines, and CTAs weighted by collation count and longevity.
Reach for this when preparing creative briefs or extracting the highest-volume opening hooks from synced ads.
meta-ads-library-pp-cli hooks 15087023444 --agent
Temporal tracking & benchmarking
-
diff — See exactly which ads an advertiser launched, stopped, or scaled between timestamped snapshots.
Reach for this when monitoring what changed for a competitor since the last check.
meta-ads-library-pp-cli diff 15087023444 --refresh --agent
-
compare — Benchmark multiple advertisers side by side on active volume, median age, format mix, platforms, CTAs, and refresh velocity.
Reach for this when building a multi-competitor paid social benchmark or client audit.
meta-ads-library-pp-cli compare 15087023444 182162001806727 --agent
Transparency & market share
-
transparency — Roll up EU/UK/BR reach, age-gender breakdowns, beneficiary/payer pairs, spend brackets, and violation flags per advertiser or byline.
Reach for this when auditing regulated EU/UK commercial spenders or political advertisers across all stored disclosures.
meta-ads-library-pp-cli transparency 15087023444 --agent
-
sov — Rank which advertisers dominate a category keyword by active ad count, collation-weighted volume, dominant format, and median longevity.
Reach for this to discover who owns paid share of voice in a niche before naming specific competitors.
meta-ads-library-pp-cli sov "running shoes" --country US --live --agent
Recipes
Compact competitor creative scan with --agent and --select
meta-ads-library-pp-cli ads search --query "running shoes" --country US --limit 10 --agent --select ad_archive_id,page_name,cta_text,landing_domain,collation_count,start_date
Fetch active US commercial ads and project only the high-signal creative and funnel fields to keep agent context compact.
Weekly competitor change diff
meta-ads-library-pp-cli diff 15087023444 --refresh --country US --agent
Pull a fresh snapshot for a Facebook Page and diff it against the previous SQLite capture to see launched, stopped, and scaled ads.
Side-by-side brand benchmark
meta-ads-library-pp-cli compare 15087023444 182162001806727 --agent
Compare multiple synced competitors on active volume, median ad age, format mix, placements, CTAs, and 7d/30d launch velocity.
Category share-of-voice discovery
meta-ads-library-pp-cli sov "cold plunge" --country US --live --agent
Rank advertisers dominating a keyword by active ad share, collation-weighted creative volume, and median longevity.
Official Graph API EU/political archive lookup
meta-ads-library-pp-cli archive --ad-reached-countries '["DE"]' --search-terms "nike" --limit 10 --agent --select id,page_name,eu_total_reach,spend,impressions,currency
Query Meta's official v27.0 ads_archive endpoint for regulated EU/UK/BR reach and political spend brackets when META_ACCESS_TOKEN is set.
Usage
Run meta-ads-library-pp-cli --help for the full command reference and flag list.
Paths & environment variables
This CLI separates local files into four path kinds:
| Kind | Contents |
|---|
config | User-editable settings such as config.toml and saved profiles |
data | Durable local data: credentials.toml, data.db, cookies, browser-session proof files, and other auth sidecars |
state | Runtime state such as persisted queries, jobs, and teach.log |
cache | Regenerable HTTP/cache files |
Each kind resolves independently. The ladder is:
- Per-kind env var:
META_ADS_LIBRARY_CONFIG_DIR, META_ADS_LIBRARY_DATA_DIR, META_ADS_LIBRARY_STATE_DIR, or META_ADS_LIBRARY_CACHE_DIR
--home <dir> for this invocation
META_ADS_LIBRARY_HOME for a flat relocated root
- XDG env vars:
XDG_CONFIG_HOME, XDG_DATA_HOME, XDG_STATE_HOME, XDG_CACHE_HOME
- Platform defaults matching existing installs
For containers and agent sandboxes, prefer a single relocated root:
export META_ADS_LIBRARY_HOME=/srv/meta-ads-library
meta-ads-library-pp-cli doctor
Under META_ADS_LIBRARY_HOME=/srv/meta-ads-library, the four dirs resolve to /srv/meta-ads-library/config, /srv/meta-ads-library/data, /srv/meta-ads-library/state, and /srv/meta-ads-library/cache.
On Windows, set the same variable in PowerShell:
$env:META_ADS_LIBRARY_HOME = "C:\srv\meta-ads-library"
meta-ads-library-pp-cli doctor
Under $env:META_ADS_LIBRARY_HOME = "C:\srv\meta-ads-library", the four dirs resolve to C:\srv\meta-ads-library\config, C:\srv\meta-ads-library\data, C:\srv\meta-ads-library\state, and C:\srv\meta-ads-library\cache.
MCP servers do not receive CLI flags from the host. Put relocation in the host env block:
{
"mcpServers": {
"meta-ads-library": {
"command": "meta-ads-library-pp-mcp",
"env": {
"META_ADS_LIBRARY_HOME": "/srv/meta-ads-library"
}
}
}
}
Precedence matters in fleets: an ambient per-kind variable such as META_ADS_LIBRARY_DATA_DIR overrides an explicit --home for that kind. Use META_ADS_LIBRARY_HOME or the per-kind variables for durable fleet relocation; treat --home as the weaker per-invocation lever.
Relocation is one-way. Unsetting META_ADS_LIBRARY_HOME does not move files back to platform defaults, and doctor cannot find credentials left under a former root. Move the files manually before unsetting relocation variables.
Existing installs keep working because the platform-default rung matches the legacy layout. On the first auth write, stored secrets leave config.toml and are consolidated into credentials.toml under the data directory. Run meta-ads-library-pp-cli doctor --fail-on warn to check path and credential-location warnings in automation.
Local data
Reads are saved locally by default: in --data-source auto mode every successful read is also written to the SQLite store (data.db, or data-<hash>.db per credential) in the data directory. GET responses are cached for five minutes under http/ in the cache directory. Credentials live in credentials.toml in the data directory. The learn journal lives under learn/ in the state directory. meta-ads-library-pp-cli doctor prints the resolved paths, every store file, and the response-cache size.
None of it is encrypted. New files are created owner-only; beyond that the data relies on OS account permissions and full-disk encryption (FileVault, BitLocker, LUKS).
- Erase it:
meta-ads-library-pp-cli local-data purge lists the store files, response cache, and learn journal it would delete; add --yes to delete them, or --only store|cache|journal to narrow it. Config and credentials are kept.
- Run without a local copy: set
META_ADS_LIBRARY_NO_LOCAL_DATA=1. Reads go to the API (--data-source live; --data-source local still reads an existing store), the response cache is off (--no-cache), nothing new is written to the store, and sync and workflow archive refuse to run. Set it in an MCP host's env block and every command the server runs inherits it.
- Choose the read source without flags:
META_ADS_LIBRARY_DATA_SOURCE=auto|live|local sets the --data-source default; an explicit flag wins.
Commands
ads
Zero-auth public Meta Ad Library search, transparency details, and deep links (pure HTTP, no API key required)
meta-ads-library-pp-cli ads search - Search public Meta ads globally by keyword, page ID, brand name, or Ad Library URL
meta-ads-library-pp-cli ads details - Fetch full ad details and EU/UK/BR transparency disclosures for a single ad (zero API key)
meta-ads-library-pp-cli ads url - Build a clickable Meta Ad Library deep link for an ad ID, page ID, or keyword query
advertisers
Look up advertiser Facebook Pages and Page IDs in Meta Ad Library (zero API key)
meta-ads-library-pp-cli advertisers search - Resolve a brand or advertiser name to its Facebook Page ID, likes, IG handle, and verification
media
Download ad creative images and videos from locally stored Meta ads
meta-ads-library-pp-cli media download - Download creative images and videos for synced ads to a local folder
archive
Official Meta Ad Library Graph API v27.0 (ads_archive — political/issue ads globally and all EU/UK/BR ads; requires META_ACCESS_TOKEN)
meta-ads-library-pp-cli archive - Query official Meta Ad Library Graph API v27.0 ads_archive for political/issue ads globally and all EU/UK/BR ads
compare
meta-ads-library-pp-cli compare - Benchmark multiple advertisers side by side on active volume, median age, format mix, platforms, CTAs, and refresh velocity.
diff
meta-ads-library-pp-cli diff - See exactly which ads an advertiser launched, stopped, or scaled between timestamped snapshots.
funnels
meta-ads-library-pp-cli funnels - Group active ads by unwrapped destination domain, URL path, and UTM parameters including carousel cards.
hooks
meta-ads-library-pp-cli hooks - Extract, deduplicate, and rank opening copy hooks, headlines, and CTAs weighted by collation count and longevity.
sov
meta-ads-library-pp-cli sov - Rank which advertisers dominate a category keyword by active ad count, collation-weighted volume, dominant format, and median longevity.
transparency
meta-ads-library-pp-cli transparency - Roll up EU/UK/BR reach, age-gender breakdowns, beneficiary/payer pairs, spend brackets, and violation flags per advertiser or byline.
winners
meta-ads-library-pp-cli winners - Rank active ads by proven longevity (days running), collation scale, and platform breadth.
Self-learning loop
This CLI caches per-question discovery so repeat queries skip the walk and structurally similar queries get answered via entity substitution. The loop also self-captures: every invocation is journaled locally, and failed-flag corrections plus fresh teaches surface as candidates on the next recall for confirm/reject judgment. Agents call recall before discovery and fire teach & after answering. See the ## Automatic learning section in SKILL.md for the full protocol.
meta-ads-library-pp-cli recall <query> - Look up cached resources for a query before running discovery
meta-ads-library-pp-cli teach - Record a query -> resource mapping (silent on success, safe to background with &)
meta-ads-library-pp-cli learnings list - Inspect taught rows
meta-ads-library-pp-cli learnings forget <query> - Undo a teach
meta-ads-library-pp-cli learnings candidates - List auto-captured candidates awaiting confirm/reject
meta-ads-library-pp-cli learnings stats - Local loop metrics: recall hit rate, teach-to-reuse, playbook resolution, candidate counts
meta-ads-library-pp-cli teach-pattern - Install a query/resource template up front
meta-ads-library-pp-cli teach-lookup - Add an entity mapping (e.g. country code, team alias) for pattern substitution
Pass --no-learn or set META_ADS_LIBRARY_NO_LEARN=true to disable the loop for deterministic flows.
The local store's schema version stamp is one-way: once this version of meta-ads-library-pp-cli opens the database, older binaries refuse it with a version error — upgrade the binary rather than downgrading.
Output Formats
# Human-readable table (default in terminal, JSON when piped)
meta-ads-library-pp-cli archive --ad-reached-countries '["US"]'
# JSON for scripting and agents
meta-ads-library-pp-cli archive --ad-reached-countries '["US"]' --json
# Filter to specific fields
meta-ads-library-pp-cli archive --ad-reached-countries '["US"]' --json --select id,page_id,page_name
# Dry run — show the request without sending
meta-ads-library-pp-cli archive --ad-reached-countries '["US"]' --dry-run
# Agent mode — JSON + compact + no prompts in one flag
meta-ads-library-pp-cli archive --ad-reached-countries '["US"]' --agent
--csv prefixes a leading ' on cells and header keys that start with =, +, -, @, a tab, or a line break (including fullwidth =+-@) so a spreadsheet does not run them as formulas. Plain signed numbers such as -5 and +2.5e3 are left unchanged.
Agent Usage
This CLI is designed for AI agent consumption:
- Non-interactive - never prompts, every input is a flag
- Pipeable -
--json output to stdout, errors to stderr
- Filterable -
--select <field>[,<field>...] returns only fields you need
- Previewable -
--dry-run shows the request without sending
- Read-only by default - this CLI does not create, update, delete, publish, send, or mutate remote resources
- Offline-friendly - sync/search commands can use the local SQLite store when available
- Agent-safe by default - no colors or formatting unless
--human-friendly is set
Exit codes: 0 success, 2 usage error, 3 not found, 4 auth error, 5 API error, 7 rate limited, 10 config error.
Health Check
meta-ads-library-pp-cli doctor
Verifies configuration, credentials, and connectivity to the API.
Configuration
Run meta-ads-library-pp-cli doctor to see the resolved config, data, state, and cache directories. The platform-default config path is ~/.config/meta-ads-library-pp-cli/config.toml on macOS/Linux and %USERPROFILE%\.config\meta-ads-library-pp-cli\config.toml on Windows; --home, META_ADS_LIBRARY_HOME, and per-kind env vars can relocate it.
Static request headers can be configured under headers; per-command header overrides take precedence.
--ca-cert, META_ADS_LIBRARY_CA_CERT, or ca_cert adds a PEM CA bundle to the system trust roots. --tls-server-name, META_ADS_LIBRARY_TLS_SERVER_NAME, or tls_server_name is the name checked against the certificate when the dialed address does not match it. Precedence is flag, then environment, then the config file. A config file other users can change does not supply these settings. Certificate verification failures are not retried.
Environment variables:
| Name | Kind | Required | Description |
|---|
META_ACCESS_TOKEN | per_call | No (required only for archive) | Optional Meta Graph API token for official ads_archive lookups (also accepts META_ADS_ARCHIVE_TOKEN or FACEBOOK_ACCESS_TOKEN). |
agentcookie (optional)
If you use agentcookie to sync secrets across machines, this CLI auto-adopts agentcookie-managed credentials with no extra setup. When the daemon writes to this CLI's config, meta-ads-library-pp-cli doctor reports agentcookie: detected and auth status labels the source as agentcookie. Skip this section if you don't use agentcookie - the CLI works the same as any other.
Troubleshooting
Authentication errors (exit code 4)
- Run
meta-ads-library-pp-cli doctor to check credentials
- Verify the environment variable is set:
echo $META_ACCESS_TOKEN
Not found errors (exit code 3)
- Check the resource ID is correct
- Run
meta-ads-library-pp-cli advertisers search "<brand>" or meta-ads-library-pp-cli ads search --query "<term>" to find valid page and ad IDs
API-specific
- GraphQL error 1675004 (rate limit exceeded) during large paginated searches — Lower --limit or reduce --max-pages; the client applies adaptive backoff automatically and retries cleanly.
- archive returns an empty array for US commercial brands — Meta's official v27.0 ads_archive only returns political/issue ads globally and all ads in EU/UK/BR; use
meta-ads-library-pp-cli ads search for non-EU commercial ads.
- archive fails with OAuth error 190 or missing META_ACCESS_TOKEN — Export a valid Meta Graph API user access token via
export META_ACCESS_TOKEN=<token> or run meta-ads-library-pp-cli ads search for zero-auth public queries.
- winners, diff, hooks, funnels, or compare reports no local rows — Run
meta-ads-library-pp-cli ads search --page-id <page_id> --country US first to populate the local SQLite archive.
Sources & Inspiration
This CLI was built by studying these projects and resources:
Generated by CLI Printing Press