delete_ad
Permanently delete an ad by its ID. This action cannot be undone. To maintain ad history, use the update_ad tool to set status to ARCHIVED.
Instructions
WRITE: Hard-delete an ad. Prefer update_ad status=ARCHIVED to keep history.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ad_id | Yes |
Implementation Reference
- src/tools/ads.ts:84-92 (handler)The delete_ad tool handler. Accepts an ad_id, then calls metaDelete (HTTP DELETE) against Meta Graph API to hard-delete the ad.
{ name: "delete_ad", description: "WRITE: Hard-delete an ad. Prefer update_ad status=ARCHIVED to keep history.", inputSchema: { ad_id: z.string(), }, handler: async (args) => metaDelete(`/${String(args.ad_id)}`), }, - src/tools/ads.ts:88-90 (schema)Input schema for delete_ad: requires a single string ad_id.
inputSchema: { ad_id: z.string(), }, - src/index.ts:47-58 (registration)delete_ad is registered via adTools array being spread into allTools, then the registration loop in index.ts calls server.registerTool for each tool.
const allTools: ToolDef[] = [ ...accountTools, ...campaignTools, ...adsetTools, ...adTools, ...creativeTools, ...mediaTools, ...insightsTools, ...bulkTools, ...pageTools, ...adsLibraryTools, ]; - src/client.ts:190-211 (helper)The metaDelete helper function that executes the actual HTTP DELETE request to the Meta Graph API with the access token appended.
/** * DELETE a Graph API resource. Some endpoints return `{success: true}`, others * return empty bodies; we tolerate both. */ export async function metaDelete<T = unknown>(path: string): Promise<T> { const qs = new URLSearchParams(); qs.append("access_token", getCurrentToken()); const url = `${META_API_BASE}${normalizePath(path)}?${qs.toString()}`; const res = await fetch(url, { method: "DELETE" }); 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; try { return JSON.parse(raw) as T; } catch { return raw as unknown as T; } } - src/tools/types.ts:9-15 (helper)The ToolDef interface used to type the delete_ad definition (name, description, inputSchema, handler).
export interface ToolDef { name: string; description: string; inputSchema: Record<string, ZodTypeAny>; handler: (args: Record<string, unknown>) => Promise<unknown>; }