list_custom_audiences
Retrieve custom audiences in your Meta ad account with optional field selection and pagination.
Instructions
List custom audiences in the ad account.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fields | No | Comma-separated fields to return | |
| limit | No | Number of results (default 25) | |
| after | No | Pagination cursor for next page |
Implementation Reference
- src/tools/audiences.ts:8-8 (registration)Registration of the 'list_custom_audiences' tool with the MCP server.
"list_custom_audiences", - src/tools/audiences.ts:10-14 (schema)Zod schema definition for the tool's input parameters (fields, limit, after).
{ fields: z.string().optional().describe("Comma-separated fields to return"), limit: z.number().optional().default(25).describe("Number of results (default 25)"), after: z.string().optional().describe("Pagination cursor for next page"), }, - src/tools/audiences.ts:15-27 (handler)Handler function that makes a GET request to the Meta Ads API endpoint for listing custom audiences and returns the results.
async ({ fields, limit, after }) => { try { const params: Record<string, unknown> = {}; if (fields) params.fields = fields; if (limit) params.limit = limit; if (after) params.after = after; const { data, rateLimit } = await client.get(`${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/index.ts:61-61 (registration)Registration of all audience tools (including list_custom_audiences) at the server level.
registerAudienceTools(server, client); - src/services/ads-client.ts:180-185 (helper)The AdsClient.get() helper method used by the handler to make GET requests to the Meta Graph API.
async get( path: string, params?: Record<string, unknown> ): Promise<ClientResponse> { return this.request("GET", path, params); }