update_ad
Update an ad's name, status, or creative. Provide the ad ID and optionally change the name, set the status (ACTIVE, PAUSED, DELETED, ARCHIVED), or replace the creative by passing a creative ID.
Instructions
WRITE: Update an ad's name, status, or swap its creative. To replace the creative pass creative: {creative_id: 'XXX'}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ad_id | Yes | ||
| name | No | ||
| status | No | ||
| creative | No | e.g. {creative_id: '123456'} |
Implementation Reference
- src/tools/ads.ts:78-82 (handler)Handler function for the 'update_ad' tool. Destructures ad_id from the args, then calls metaPost to the ad's Graph API endpoint with the remaining fields (name, status, creative).
handler: async (args) => { const { ad_id, ...rest } = args; return metaPost(`/${String(ad_id)}`, rest as Record<string, unknown>); }, }, - src/tools/ads.ts:69-77 (schema)Input schema for 'update_ad'. Accepts ad_id (required string), name (optional string), status (optional enum: ACTIVE/PAUSED/DELETED/ARCHIVED), and creative (optional record, e.g. {creative_id: '123456'}).
inputSchema: { ad_id: z.string(), name: z.string().optional(), status: STATUS.optional(), creative: z .record(z.unknown()) .optional() .describe("e.g. {creative_id: '123456'}"), }, - src/index.ts:65-90 (registration)Registration loop in stdio entry point (index.ts). Iterates allToolDefs (including adTools) and calls server.registerTool() for each, connecting the handler to the MCP server.
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:48-67 (registration)Registration loop in HTTP entry point (http.ts). Same pattern as index.ts but for the HTTP Streamable server.
for (const tool of allTools) { server.registerTool( tool.name, { description: tool.description, inputSchema: tool.inputSchema }, 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/client.ts:168-188 (helper)The metaPost helper function used by the update_ad handler. Sends a POST request to the Meta Graph API with URL-encoded form body and access token.
export async function metaPost<T = unknown>( path: string, body: Record<string, unknown> = {}, ): Promise<T> { const form = buildQuery(body); form.append("access_token", getCurrentToken()); const url = `${META_API_BASE}${normalizePath(path)}`; const res = await fetch(url, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: form.toString(), }); 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; return JSON.parse(raw) as T; }