Skip to main content
Glama

delete_image

Permanently remove an ad image by providing its hash. This irreversible action helps keep your asset library organized.

Instructions

Delete an ad image by hash. This action is irreversible.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hashYesImage hash to delete

Implementation Reference

  • The 'delete_image' tool handler function. Uses Zod for input validation (hash string), calls client.delete with the ad account path and hash, and returns the result or an error. This is the core implementation of the tool.
    // ─── delete_image ──────────────────────────────────────────
    server.tool(
      "delete_image",
      "Delete an ad image by hash. This action is irreversible.",
      {
        hash: z.string().describe("Image hash to delete"),
      },
      async ({ hash }) => {
        try {
          const { data, rateLimit } = await client.delete(`${client.accountPath}/adimages`, { hash });
          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 };
        }
      }
    );
  • Input schema for the delete_image tool: requires a single 'hash' string parameter describing the image hash to delete.
    {
      hash: z.string().describe("Image hash to delete"),
    },
  • The registerImageTools function registers all image tools (including delete_image) on the MCP server. Called from src/index.ts line 56.
    export function registerImageTools(server: McpServer, client: AdsClient): void {
      // ─── list_images ───────────────────────────────────────────
      server.tool(
        "list_images",
        "List ad images uploaded to the ad account.",
        {
          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 ({ fields, limit, after }) => {
          try {
            const params: Record<string, unknown> = {};
            if (fields) params.fields = fields;
            if (limit) params.limit = limit;
            if (after) params.after = after;
            const { data, rateLimit } = await client.get(`${client.accountPath}/adimages`, 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 };
          }
        }
      );
    
      // ─── upload_image ──────────────────────────────────────────
      server.tool(
        "upload_image",
        "Upload an ad image from a public URL. Returns image hash for use in ad creatives.",
        {
          url: z.string().describe("Public URL of the image to upload"),
        },
        async ({ url }) => {
          try {
            const { data, rateLimit } = await client.post(`${client.accountPath}/adimages`, { url });
            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_image ─────────────────────────────────────────────
      server.tool(
        "get_image",
        "Get details of a specific ad image by ID.",
        {
          image_id: z.string().describe("Image ID"),
          fields: z.string().optional().describe("Comma-separated fields to return"),
        },
        async ({ image_id, fields }) => {
          try {
            const params: Record<string, unknown> = {};
            if (fields) params.fields = fields;
            const { data, rateLimit } = await client.get(`/${image_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_image ──────────────────────────────────────────
      server.tool(
        "delete_image",
        "Delete an ad image by hash. This action is irreversible.",
        {
          hash: z.string().describe("Image hash to delete"),
        },
        async ({ hash }) => {
          try {
            const { data, rateLimit } = await client.delete(`${client.accountPath}/adimages`, { hash });
            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 };
          }
        }
      );
    }
  • The AdsClient.delete() method called by the delete_image handler. Sends a DELETE request to the Meta Ads API via the private request() method.
    async delete(
      path: string,
      params?: Record<string, unknown>
    ): Promise<ClientResponse> {
      return this.request("DELETE", path, params);
    }
Behavior3/5

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

Discloses irreversibility ('This action is irreversible'), which is a key trait beyond the schema. However, with no annotations provided, the description should cover more behavioral aspects like auth requirements or side effects; currently minimal.

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 short sentences with no wasted words. Effectively front-loaded with the core action and critical caution about irreversibility.

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

Completeness5/5

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

For a simple delete operation with one required parameter and no output schema, the description covers the essential aspects: what it does and the irreversible nature. No obvious gaps for typical usage.

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 coverage is 100%, and the description does not add meaning beyond the schema's description of the 'hash' parameter. The phrase 'by hash' is redundant with the schema, so baseline 3 applies.

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 explicitly states 'Delete an ad image by hash', clearly identifying the action and resource. It distinguishes from sibling tools like delete_video or delete_ad by specifying 'ad image'.

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 on when to use this tool versus alternatives like delete_video or delete_ad. Does not mention prerequisites, use cases, or exclusions, leaving the agent without decision support.

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