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 };
          }
        }
      );
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.2.0

TDQS

B3.1/5.0
Behavior2/5

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

With no annotations, the description carries the full burden of behavioral disclosure. It does not mention whether this is a read-only operation, what permissions are required, or any limitations of the estimate (e.g., based on targeting settings). It only states what the tool returns.

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?

The description is a single sentence that states the purpose and key output in a clear, front-loaded manner. It contains no filler or redundant information.

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

Completeness3/5

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

The tool is relatively simple with two parameters and no output schema. The description mentions the return value (daily reach and cost), which is useful, but it lacks usage guidance and does not describe edge cases or important behavioral context. For a simple read tool, it is minimally adequate but not complete.

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 description coverage is 100%, so the schema already documents both parameters (ad_id and optimization_goal). The description adds minimal context by mentioning 'daily reach and cost' but does not explain the role of optimization_goal beyond what the schema provides. Baseline of 3 is appropriate.

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?

The description clearly states the tool gets a delivery estimate for an ad, specifying it includes estimated daily reach and cost. This is a specific verb+resource combination that distinguishes it from sibling tools like get_reach_estimate, though it does not explicitly name alternatives.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives such as get_reach_estimate or get_ad_preview. The description gives no context for choosing this tool or when it would be inappropriate.

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

Deploy Server

Other Tools