delete_adset
Hard-delete an ad set and its ads permanently. Consider archiving instead to retain historical data.
Instructions
WRITE: Hard-delete an ad set (and its ads). Prefer update_adset status=ARCHIVED to keep history.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| adset_id | Yes |
Implementation Reference
- src/tools/adsets.ts:187-195 (handler)The 'delete_adset' tool handler — calls metaDelete() with the adset_id to hard-delete an ad set via the Meta Graph API. The handler is an async arrow function that takes args, extracts adset_id, and issues a DELETE request to /{adset_id}.
{ name: "delete_adset", description: "WRITE: Hard-delete an ad set (and its ads). Prefer update_adset status=ARCHIVED to keep history.", inputSchema: { adset_id: z.string(), }, handler: async (args) => metaDelete(`/${String(args.adset_id)}`), }, - src/tools/adsets.ts:191-192 (schema)Input schema for delete_adset — takes a single required string parameter 'adset_id' validated with Zod.
inputSchema: { adset_id: z.string(), - src/index.ts:50-90 (registration)The adsetTools array (which contains delete_adset) is spread into allTools, then every tool is registered via server.registerTool() in the stdio entry point (src/index.ts).
...adsetTools, ...adTools, ...creativeTools, ...mediaTools, ...insightsTools, ...bulkTools, ...pageTools, ...adsLibraryTools, ]; const server = new McpServer( { name: "mcp-meta-ads", version: "0.2.0" }, { capabilities: { tools: {} } }, ); for (const tool of allTools) { server.registerTool( tool.name, { description: tool.description, inputSchema: tool.inputSchema, }, // The SDK's ToolCallback type infers the arg shape from inputSchema, but // our shared ToolDef uses a generic Record<string, unknown> signature for // portability. The cast here is intentional and isolated to the bridge. async (args: unknown) => { try { const result = await tool.handler(args as Record<string, unknown>); return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }], }; } catch (err) { const message = err instanceof Error ? err.message : String(err); return { content: [{ type: "text" as const, text: `Error: ${message}` }], isError: true, }; } }, ); } - src/http.ts:33-41 (registration)Same adsetTools array is also registered in the HTTP entry point (src/http.ts), ensuring delete_adset works in both stdio and HTTP modes.
...adsetTools, ...adTools, ...creativeTools, ...mediaTools, ...insightsTools, ...bulkTools, ...pageTools, ...adsLibraryTools, ]; - src/client.ts:194-211 (helper)The metaDelete() function called by the delete_adset handler. Sends an HTTP DELETE request to the Meta Graph API with the access_token appended as a query parameter.
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; } }