Skip to main content
Glama

get_delivery_estimate

Estimate ad delivery daily reach and cost by providing ad ID and optimization goal.

Instructions

Get delivery estimate for an ad including estimated daily reach and cost.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ad_idYesAd ID
optimization_goalNoOptimization goal to estimate for

Implementation Reference

  • The handler function for the 'get_delivery_estimate' tool. It accepts ad_id and optional optimization_goal, calls the Meta Ads API to get delivery estimate data, and returns the result.
      async ({ ad_id, optimization_goal }) => {
        try {
          const params: Record<string, unknown> = {};
          if (optimization_goal) params.optimization_goal = optimization_goal;
          const { data, rateLimit } = await client.get(`/${ad_id}/delivery_estimate`, params);
          return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
        } catch (error) {
          return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
        }
      }
    );
  • Input schema for the 'get_delivery_estimate' tool: ad_id (required string) and optimization_goal (optional string).
    {
      ad_id: z.string().describe("Ad ID"),
      optimization_goal: z.string().optional().describe("Optimization goal to estimate for"),
    },
  • Registration of the 'get_delivery_estimate' tool on the MCP server via server.tool() with name, description, schema, and handler.
    server.tool(
      "get_delivery_estimate",
      "Get delivery estimate for an ad including estimated daily reach and cost.",
      {
        ad_id: z.string().describe("Ad ID"),
        optimization_goal: z.string().optional().describe("Optimization goal to estimate for"),
      },
      async ({ ad_id, optimization_goal }) => {
        try {
          const params: Record<string, unknown> = {};
          if (optimization_goal) params.optimization_goal = optimization_goal;
          const { data, rateLimit } = await client.get(`/${ad_id}/delivery_estimate`, params);
          return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
        } catch (error) {
          return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
        }
      }
    );
  • src/tools/ads.ts:5-182 (registration)
    The registerAdTools function is exported and called from src/index.ts line 52 to wire up all ad tools including get_delivery_estimate.
    export function registerAdTools(server: McpServer, client: AdsClient): void {
      // ─── list_ads ──────────────────────────────────────────────
      server.tool(
        "list_ads",
        "List ads in the ad account. Optionally filter by campaign, ad set, or status.",
        {
          campaign_id: z.string().optional().describe("Filter by campaign ID"),
          adset_id: z.string().optional().describe("Filter by ad set ID"),
          status: z.string().optional().describe("Filter by status: ACTIVE, PAUSED, DELETED, ARCHIVED"),
          fields: z.string().optional().describe("Comma-separated fields to return"),
          limit: z.number().optional().default(25).describe("Number of results (default 25)"),
          after: z.string().optional().describe("Pagination cursor for next page"),
        },
        async ({ campaign_id, adset_id, status, fields, limit, after }) => {
          try {
            const params: Record<string, unknown> = {};
            if (fields) params.fields = fields;
            if (limit) params.limit = limit;
            if (after) params.after = after;
            if (campaign_id) params.campaign_id = campaign_id;
            if (adset_id) params.adset_id = adset_id;
            if (status) params.effective_status = `["${status}"]`;
            const { data, rateLimit } = await client.get(`${client.accountPath}/ads`, params);
            return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
          } catch (error) {
            return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
          }
        }
      );
    
      // ─── get_ad ────────────────────────────────────────────────
      server.tool(
        "get_ad",
        "Get details of a specific ad by ID.",
        {
          ad_id: z.string().describe("Ad ID"),
          fields: z.string().optional().describe("Comma-separated fields to return"),
        },
        async ({ ad_id, fields }) => {
          try {
            const params: Record<string, unknown> = {};
            if (fields) params.fields = fields;
            const { data, rateLimit } = await client.get(`/${ad_id}`, params);
            return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
          } catch (error) {
            return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
          }
        }
      );
    
      // ─── create_ad ─────────────────────────────────────────────
      server.tool(
        "create_ad",
        "Create a new ad. Requires name, adset_id, and creative (JSON object_story_spec). Defaults to PAUSED status.",
        {
          name: z.string().describe("Ad name"),
          adset_id: z.string().describe("Parent ad set ID"),
          creative: z.string().describe("JSON string of creative spec (object_story_spec with page_id, link_data/photo_data/video_data)"),
          status: z.string().optional().default("PAUSED").describe("Ad status (default PAUSED)"),
          tracking_specs: z.string().optional().describe("JSON string of tracking specs array"),
        },
        async ({ name, adset_id, creative, status, tracking_specs }) => {
          try {
            const params: Record<string, unknown> = { name, adset_id, creative, status };
            if (tracking_specs) params.tracking_specs = tracking_specs;
            const { data, rateLimit } = await client.post(`${client.accountPath}/ads`, params);
            return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
          } catch (error) {
            return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
          }
        }
      );
    
      // ─── update_ad ─────────────────────────────────────────────
      server.tool(
        "update_ad",
        "Update an existing ad. Only provided fields will be modified.",
        {
          ad_id: z.string().describe("Ad ID to update"),
          name: z.string().optional().describe("New ad name"),
          status: z.string().optional().describe("New status: ACTIVE, PAUSED, DELETED, ARCHIVED"),
          creative: z.string().optional().describe("New creative spec as JSON string"),
          tracking_specs: z.string().optional().describe("New tracking specs as JSON string"),
        },
        async ({ ad_id, name, status, creative, tracking_specs }) => {
          try {
            const params: Record<string, unknown> = {};
            if (name) params.name = name;
            if (status) params.status = status;
            if (creative) params.creative = creative;
            if (tracking_specs) params.tracking_specs = tracking_specs;
            const { data, rateLimit } = await client.post(`/${ad_id}`, params);
            return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
          } catch (error) {
            return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
          }
        }
      );
    
      // ─── delete_ad ─────────────────────────────────────────────
      server.tool(
        "delete_ad",
        "Delete an ad. This action is irreversible.",
        {
          ad_id: z.string().describe("Ad ID to delete"),
        },
        async ({ ad_id }) => {
          try {
            const { data, rateLimit } = await client.delete(`/${ad_id}`);
            return { content: [{ type: "text" as const, text: JSON.stringify({ success: true, ...data as object, _rateLimit: rateLimit }, null, 2) }] };
          } catch (error) {
            return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
          }
        }
      );
    
      // ─── copy_ad ────────────────────────────────────────────────
      server.tool(
        "copy_ad",
        "Copy an existing ad. Creates a duplicate within the same or different ad set.",
        {
          ad_id: z.string().describe("Source ad ID to copy"),
          adset_id: z.string().optional().describe("Target ad set ID. If omitted, copies to same ad set"),
          name: z.string().optional().describe("Name for the copied ad"),
          status: z.string().optional().default("PAUSED").describe("Status for copied ad (default PAUSED)"),
        },
        async ({ ad_id, adset_id, name, status }) => {
          try {
            const params: Record<string, unknown> = {};
            if (adset_id) params.adset_id = adset_id;
            if (name) params.rename_options = JSON.stringify({ rename_suffix: "", rename_prefix: "", new_name_prefix: name });
            if (status) params.status_option = status;
            const { data, rateLimit } = await client.post(`/${ad_id}/copies`, params);
            return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
          } catch (error) {
            return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
          }
        }
      );
    
      // ─── get_ad_preview ────────────────────────────────────────
      server.tool(
        "get_ad_preview",
        "Get a preview of an ad in a specific format. Returns HTML iframe for rendering.",
        {
          ad_id: z.string().describe("Ad ID"),
          ad_format: z.string().describe("Ad format: DESKTOP_FEED_STANDARD, MOBILE_FEED_STANDARD, INSTAGRAM_STANDARD, INSTAGRAM_STORY, RIGHT_COLUMN_STANDARD, etc."),
        },
        async ({ ad_id, ad_format }) => {
          try {
            const { data, rateLimit } = await client.get(`/${ad_id}/previews`, { ad_format });
            return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
          } catch (error) {
            return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
          }
        }
      );
    
      // ─── get_delivery_estimate ─────────────────────────────────
      server.tool(
        "get_delivery_estimate",
        "Get delivery estimate for an ad including estimated daily reach and cost.",
        {
          ad_id: z.string().describe("Ad ID"),
          optimization_goal: z.string().optional().describe("Optimization goal to estimate for"),
        },
        async ({ ad_id, optimization_goal }) => {
          try {
            const params: Record<string, unknown> = {};
            if (optimization_goal) params.optimization_goal = optimization_goal;
            const { data, rateLimit } = await client.get(`/${ad_id}/delivery_estimate`, params);
            return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] };
          } catch (error) {
            return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true };
          }
        }
      );
    }
Behavior3/5

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

Description indicates a read-only operation, but no annotations are provided, and the description lacks details on edge cases, authentication, or rate limits.

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?

Single sentence, front-loaded with purpose, no redundant words.

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?

Adequate for a simple get operation; mentions return values (daily reach and cost) but does not address error handling or response structure.

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

Parameters3/5

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

Schema covers all parameters with descriptions (100% coverage). Description adds no extra meaning beyond the schema.

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

Purpose4/5

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

Clear verb 'Get' and resource 'delivery estimate for an ad' with specific output details (daily reach and cost). However, it does not differentiate from sibling tool 'get_reach_estimate'.

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?

Implied usage for obtaining a delivery estimate, but no explicit when-to-use, when-not-to-use, or alternatives.

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/mikusnuz/meta-ads-mcp'

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