copy_ad
Duplicate an existing ad within the same or a different ad set. Assign a new name and status to the copy.
Instructions
Copy an existing ad. Creates a duplicate within the same or different ad set.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ad_id | Yes | Source ad ID to copy | |
| adset_id | No | Target ad set ID. If omitted, copies to same ad set | |
| name | No | Name for the copied ad | |
| status | No | Status for copied ad (default PAUSED) | PAUSED |
Implementation Reference
- src/tools/ads.ts:131-143 (handler)The handler function for copy_ad that copies an existing ad via POST /{ad_id}/copies. Supports optional adset_id, name (renaming), and status parameters.
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 }; } } ); - src/tools/ads.ts:125-130 (schema)Zod schema defining input parameters for copy_ad: ad_id (required), adset_id (optional), name (optional), status (optional, defaults to PAUSED).
{ 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)"), }, - src/tools/ads.ts:122-143 (registration)Tool registration via server.tool() within the registerAdTools function. The tool is named 'copy_ad' with a description about duplicating ads.
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 }; } } ); - src/index.ts:52-52 (registration)Top-level registration call in index.ts that activates the copy_ad (and all other ad) tools.
registerAdTools(server, client); - src/tools/ads.ts:5-5 (helper)The exported registerAdTools function that encapsulates all ad tool registrations including copy_ad.
export function registerAdTools(server: McpServer, client: AdsClient): void {