Skip to main content
Glama
Mike25app

scaleforge-mcp-meta-ads

search_ads_library

Search Meta's public Ad Library to find and analyze active and inactive ads by keywords or page IDs. Perform competitive research across countries, ad categories, and platforms with filters for delivery times and creative previews.

Instructions

Search Meta's public Ad Library for competitive research. Returns active and inactive ads matching search_terms OR search_page_ids in the selected countries. Default country = ['US']. Returns ad_snapshot_url (preview), creative bodies/titles, page_id, delivery times, publisher_platforms.

Note: only ads in categories subject to public transparency (political / housing / employment / credit) return full metadata; other categories return lighter data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
search_termsNoKeywords to search ad text/creative
search_page_idsNoSpecific Facebook Page IDs to look at
ad_reached_countriesNoISO-2 country codes. Default ['US']
ad_typeNoDefault ALL
ad_active_statusNoDefault ACTIVE
publisher_platformsNo
limitNo
afterNo
fieldsNoOverride default field list

Implementation Reference

  • The handler function for the search_ads_library tool. Validates that at least one of search_terms or search_page_ids is provided, then calls metaGet('/ads_archive', ...) to query Meta's public Ad Library.
    handler: async (args) => {
      if (!args.search_terms && !args.search_page_ids) {
        throw new Error(
          "search_ads_library requires either `search_terms` or `search_page_ids`.",
        );
      }
      return metaGet("/ads_archive", {
        search_terms: args.search_terms,
        search_page_ids: args.search_page_ids,
        ad_reached_countries: args.ad_reached_countries ?? ["US"],
        ad_type: args.ad_type ?? "ALL",
        ad_active_status: args.ad_active_status ?? "ACTIVE",
        publisher_platforms: args.publisher_platforms,
        limit: args.limit ?? 50,
        after: args.after,
        fields: args.fields ?? DEFAULT_AD_ARCHIVE_FIELDS,
      });
    },
  • Input schema for search_ads_library using Zod definitions for search_terms, search_page_ids, ad_reached_countries, ad_type, ad_active_status, publisher_platforms, limit, after, and fields.
    inputSchema: {
      search_terms: z
        .string()
        .optional()
        .describe("Keywords to search ad text/creative"),
      search_page_ids: z
        .array(z.string())
        .optional()
        .describe("Specific Facebook Page IDs to look at"),
      ad_reached_countries: z
        .array(z.string().length(2))
        .optional()
        .describe("ISO-2 country codes. Default ['US']"),
      ad_type: z
        .enum([
          "ALL",
          "POLITICAL_AND_ISSUE_ADS",
          "HOUSING_ADS",
          "EMPLOYMENT_ADS",
          "CREDIT_ADS",
        ])
        .optional()
        .describe("Default ALL"),
      ad_active_status: z
        .enum(["ALL", "ACTIVE", "INACTIVE"])
        .optional()
        .describe("Default ACTIVE"),
      publisher_platforms: z
        .array(z.enum(["FACEBOOK", "INSTAGRAM", "AUDIENCE_NETWORK", "MESSENGER"]))
        .optional(),
      limit: z.number().int().positive().max(500).optional(),
      after: z.string().optional(),
      fields: z.string().optional().describe("Override default field list"),
    },
  • The full ToolDef array export 'adsLibraryTools' containing the search_ads_library tool definition with name, description, inputSchema, and handler.
    export const adsLibraryTools: ToolDef[] = [
      {
        name: "search_ads_library",
        description:
          "Search Meta's public Ad Library for competitive research. Returns active and inactive " +
          "ads matching `search_terms` OR `search_page_ids` in the selected countries. Default " +
          "country = ['US']. Returns ad_snapshot_url (preview), creative bodies/titles, page_id, " +
          "delivery times, publisher_platforms.\n\n" +
          "Note: only ads in categories subject to public transparency (political / housing / " +
          "employment / credit) return full metadata; other categories return lighter data.",
        inputSchema: {
          search_terms: z
            .string()
            .optional()
            .describe("Keywords to search ad text/creative"),
          search_page_ids: z
            .array(z.string())
            .optional()
            .describe("Specific Facebook Page IDs to look at"),
          ad_reached_countries: z
            .array(z.string().length(2))
            .optional()
            .describe("ISO-2 country codes. Default ['US']"),
          ad_type: z
            .enum([
              "ALL",
              "POLITICAL_AND_ISSUE_ADS",
              "HOUSING_ADS",
              "EMPLOYMENT_ADS",
              "CREDIT_ADS",
            ])
            .optional()
            .describe("Default ALL"),
          ad_active_status: z
            .enum(["ALL", "ACTIVE", "INACTIVE"])
            .optional()
            .describe("Default ACTIVE"),
          publisher_platforms: z
            .array(z.enum(["FACEBOOK", "INSTAGRAM", "AUDIENCE_NETWORK", "MESSENGER"]))
            .optional(),
          limit: z.number().int().positive().max(500).optional(),
          after: z.string().optional(),
          fields: z.string().optional().describe("Override default field list"),
        },
        handler: async (args) => {
          if (!args.search_terms && !args.search_page_ids) {
            throw new Error(
              "search_ads_library requires either `search_terms` or `search_page_ids`.",
            );
          }
          return metaGet("/ads_archive", {
            search_terms: args.search_terms,
            search_page_ids: args.search_page_ids,
            ad_reached_countries: args.ad_reached_countries ?? ["US"],
            ad_type: args.ad_type ?? "ALL",
            ad_active_status: args.ad_active_status ?? "ACTIVE",
            publisher_platforms: args.publisher_platforms,
            limit: args.limit ?? 50,
            after: args.after,
            fields: args.fields ?? DEFAULT_AD_ARCHIVE_FIELDS,
          });
        },
      },
    ];
  • src/index.ts:30-30 (registration)
    Import of adsLibraryTools from adslibrary.ts in the stdio entrypoint.
    import { adsLibraryTools } from "./tools/adslibrary.js";
  • src/index.ts:57-57 (registration)
    adsLibraryTools spread into allTools array for registration with McpServer in stdio mode.
    ...adsLibraryTools,
  • src/http.ts:27-27 (registration)
    Import of adsLibraryTools from adslibrary.ts in the HTTP entrypoint.
    import { adsLibraryTools } from "./tools/adslibrary.js";
  • src/http.ts:40-40 (registration)
    adsLibraryTools spread into allTools array for registration with McpServer in HTTP mode.
    ...adsLibraryTools,
  • The metaGet helper function used by the handler to make GET requests to the Meta Graph API.
    export async function metaGet<T = unknown>(
      path: string,
      params: Record<string, unknown> = {},
    ): Promise<T> {
      const qs = buildQuery(params);
      qs.append("access_token", getCurrentToken());
      const url = `${META_API_BASE}${normalizePath(path)}?${qs.toString()}`;
    
      const res = await fetch(url, { method: "GET" });
      if (!res.ok) {
        const text = await res.text().catch(() => "");
        throw new Error(enhanceMetaError(res.status, text));
      }
      const raw = await res.text();
      if (!raw) return {} as T;
      return JSON.parse(raw) as T;
    }
  • The META_API_BASE constant pointing to https://graph.facebook.com/v24.0 used for the /ads_archive endpoint.
    export const META_API_BASE = "https://graph.facebook.com/v24.0";
  • The getCurrentToken function that resolves the Meta access token for API calls.
    function getCurrentToken(): string {
      const sessionToken = getMetaToken();
      if (sessionToken) return sessionToken;
      const envToken = process.env.META_ACCESS_TOKEN;
      if (envToken) return envToken;
      throw new Error(
        "META_ACCESS_TOKEN missing. Stdio mode: set the env var. HTTP mode: pass " +
          "the token via ?config=<base64(JSON)> query or Authorization: Bearer. " +
          "Get a token at https://developers.facebook.com/tools/explorer/ (2h) or " +
          "via Business Manager System User (never expires): " +
          "https://github.com/Mike25app/scaleforge-mcp-meta-ads#stable-tokens",
      );
    }
  • The getMetaToken helper that retrieves the per-request token from AsyncLocalStorage.
    export function getMetaToken(): string | undefined {
      return tokenStorage.getStore()?.token;
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Discloses important behavioral nuance: only ads in political/housing/employment/credit categories return full metadata, others return lighter data. No annotations exist, so description compensates well.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two concise paragraphs with front-loaded purpose, no wasted words. Every sentence adds value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers main functionality and limitations, but does not address pagination details or publisher_platforms filtering. Adequate for a search tool with no output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Description adds context beyond schema by explaining search logic (OR between search_terms and search_page_ids), default country, and returned fields. Schema coverage is 67%, so description helps fill gaps.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool searches Meta's public Ad Library for competitive research, with specific verbs and resource. It distinguishes from sibling tools focused on account-level ads management.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implies usage for competitive research but does not explicitly guide when to use this vs alternatives like get_ad, list_ads, or when not to use it. No exclusions or alternative tool mentions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Mike25app/scaleforge-mcp-meta-ads'

If you have feedback or need assistance with the MCP directory API, please join our Discord server