create_custom_audience
Create a custom audience from various sources like website, app, engagement, or customer file. Define audience subtype to specify the data origin.
Instructions
Create a new custom audience. Subtype determines the audience source (CUSTOM, WEBSITE, APP, OFFLINE_CONVERSION, LOOKALIKE, ENGAGEMENT, etc.).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Audience name | |
| subtype | Yes | Audience subtype | |
| description | No | Audience description | |
| customer_file_source | No | Source of customer file: USER_PROVIDED_ONLY, PARTNER_PROVIDED_ONLY, BOTH_USER_AND_PARTNER_PROVIDED |
Implementation Reference
- src/tools/audiences.ts:73-84 (handler)The async handler function that executes the tool logic: builds params from name/subtype/description/customer_file_source, calls POST to /customaudiences, and returns the result.
async ({ name, subtype, description, customer_file_source }) => { try { const params: Record<string, unknown> = { name, subtype }; if (description) params.description = description; if (customer_file_source) params.customer_file_source = customer_file_source; const { data, rateLimit } = await client.post(`${client.accountPath}/customaudiences`, 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/audiences.ts:53-72 (schema)Input schema definitions using Zod: name (string, required), subtype (enum of 12 audience subtypes), description (optional string), customer_file_source (optional string).
{ name: z.string().describe("Audience name"), subtype: z.enum([ "CUSTOM", "WEBSITE", "APP", "OFFLINE_CONVERSION", "CLAIM", "PARTNER", "MANAGED", "VIDEO", "LOOKALIKE", "ENGAGEMENT", "BAG_OF_ACCOUNTS", "STUDY_RULE_AUDIENCE", "FOX", ]).describe("Audience subtype"), description: z.string().optional().describe("Audience description"), customer_file_source: z.string().optional().describe("Source of customer file: USER_PROVIDED_ONLY, PARTNER_PROVIDED_ONLY, BOTH_USER_AND_PARTNER_PROVIDED"), }, - src/tools/audiences.ts:50-84 (registration)Registration of the tool on the MCP server using server.tool() with name 'create_custom_audience', description, schema, and handler.
server.tool( "create_custom_audience", "Create a new custom audience. Subtype determines the audience source (CUSTOM, WEBSITE, APP, OFFLINE_CONVERSION, LOOKALIKE, ENGAGEMENT, etc.).", { name: z.string().describe("Audience name"), subtype: z.enum([ "CUSTOM", "WEBSITE", "APP", "OFFLINE_CONVERSION", "CLAIM", "PARTNER", "MANAGED", "VIDEO", "LOOKALIKE", "ENGAGEMENT", "BAG_OF_ACCOUNTS", "STUDY_RULE_AUDIENCE", "FOX", ]).describe("Audience subtype"), description: z.string().optional().describe("Audience description"), customer_file_source: z.string().optional().describe("Source of customer file: USER_PROVIDED_ONLY, PARTNER_PROVIDED_ONLY, BOTH_USER_AND_PARTNER_PROVIDED"), }, async ({ name, subtype, description, customer_file_source }) => { try { const params: Record<string, unknown> = { name, subtype }; if (description) params.description = description; if (customer_file_source) params.customer_file_source = customer_file_source; const { data, rateLimit } = await client.post(`${client.accountPath}/customaudiences`, 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/audiences.ts:1-6 (helper)Imports and function wrapper: imports zod, McpServer, AdsClient. The registerAudienceTools function registers all audience tools including create_custom_audience.
import { z } from "zod"; import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { AdsClient } from "../services/ads-client.js"; export function registerAudienceTools(server: McpServer, client: AdsClient): void { // ─── list_custom_audiences ─────────────────────────────────