get_adset_leads
Fetch leads generated by a specific ad set using its ID. Supports pagination and custom field selection.
Instructions
Get leads generated by a specific ad set. Requires leads_retrieval permission.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| adset_id | Yes | Ad set ID | |
| 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/adsets.ts:221-232 (handler)The async handler function that executes the 'get_adset_leads' tool logic. It receives adset_id, optional fields, limit (default 25), and pagination cursor 'after', then calls client.get('/{adset_id}/leads') to fetch leads for the ad set.
async ({ adset_id, 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(`/${adset_id}/leads`, 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/adsets.ts:215-220 (schema)Input schema/type definitions for the 'get_adset_leads' tool, defining parameters: adset_id (required string), fields (optional string), limit (optional number, default 25), after (optional string for pagination).
{ adset_id: z.string().describe("Ad set ID"), 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/adsets.ts:211-233 (registration)Registration of the 'get_adset_leads' tool via server.tool() call inside registerAdsetTools(), with description 'Get leads generated by a specific ad set. Requires leads_retrieval permission.'
// ─── get_adset_leads ─────────────────────────────────────── server.tool( "get_adset_leads", "Get leads generated by a specific ad set. Requires leads_retrieval permission.", { adset_id: z.string().describe("Ad set ID"), 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"), }, async ({ adset_id, 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(`/${adset_id}/leads`, 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/adsets.ts:5-5 (registration)The function signature that wraps all adset tool registrations: export function registerAdsetTools(server: McpServer, client: AdsClient).
export function registerAdsetTools(server: McpServer, client: AdsClient): void { - src/index.ts:51-51 (registration)Top-level registration call invoking registerAdsetTools(server, client) to register all adset tools including 'get_adset_leads'.
registerAdsetTools(server, client);