create_ad
Create a new ad by specifying name, ad set ID, and creative JSON. Default status is PAUSED; optionally set status and tracking specs.
Instructions
Create a new ad. Requires name, adset_id, and creative (JSON object_story_spec). Defaults to PAUSED status.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Ad name | |
| adset_id | Yes | Parent ad set ID | |
| creative | Yes | JSON string of creative spec (object_story_spec with page_id, link_data/photo_data/video_data) | |
| status | No | Ad status (default PAUSED) | PAUSED |
| tracking_specs | No | JSON string of tracking specs array |
Implementation Reference
- src/tools/ads.ts:56-76 (handler)The create_ad tool handler: registers an MCP tool named 'create_ad' that accepts name, adset_id, creative (JSON), optional status (default PAUSED), and optional tracking_specs. It POSTs to the Meta Ads API endpoint /act_{account_id}/ads to create a new ad.
server.tool( "create_ad", "Create a new ad. Requires name, adset_id, and creative (JSON object_story_spec). Defaults to PAUSED status.", { name: z.string().describe("Ad name"), adset_id: z.string().describe("Parent ad set ID"), creative: z.string().describe("JSON string of creative spec (object_story_spec with page_id, link_data/photo_data/video_data)"), status: z.string().optional().default("PAUSED").describe("Ad status (default PAUSED)"), tracking_specs: z.string().optional().describe("JSON string of tracking specs array"), }, async ({ name, adset_id, creative, status, tracking_specs }) => { try { const params: Record<string, unknown> = { name, adset_id, creative, status }; if (tracking_specs) params.tracking_specs = tracking_specs; const { data, rateLimit } = await client.post(`${client.accountPath}/ads`, 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:59-65 (schema)Zod schema for create_ad input: name (string), adset_id (string), creative (JSON string), status (string, default PAUSED), tracking_specs (optional JSON string).
{ name: z.string().describe("Ad name"), adset_id: z.string().describe("Parent ad set ID"), creative: z.string().describe("JSON string of creative spec (object_story_spec with page_id, link_data/photo_data/video_data)"), status: z.string().optional().default("PAUSED").describe("Ad status (default PAUSED)"), tracking_specs: z.string().optional().describe("JSON string of tracking specs array"), }, - src/index.ts:52-52 (registration)Registration call: registerAdTools(server, client) is invoked in the main server setup, which registers the create_ad (and all other ad) tools on the MCP server.
registerAdTools(server, client); - src/tools/ads.ts:5-5 (registration)Function signature export: export function registerAdTools(server, client) that registers all ad-related tools including create_ad.
export function registerAdTools(server: McpServer, client: AdsClient): void { - src/services/ads-client.ts:187-191 (helper)The AdsClient.post() method used by create_ad to make the HTTP POST request to the Meta Ads Graph API.
async post( path: string, params?: Record<string, unknown> ): Promise<ClientResponse> { return this.request("POST", path, params);