list_business_ad_accounts
List ad accounts owned by your configured business. Filter by fields, set result limit, or paginate with after cursor.
Instructions
List ad accounts owned by the configured business. Requires META_BUSINESS_ID env var.
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/business.ts:50-76 (handler)The handler function for list_business_ad_accounts tool. Registered via server.tool(), it calls the Meta API endpoint `GET /{businessId}/owned_ad_accounts` using the AdsClient.
server.tool( "list_business_ad_accounts", "List ad accounts owned by the configured business. Requires META_BUSINESS_ID env var.", { 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 ({ fields, limit, after }) => { try { let businessId: string; try { businessId = client.businessId; } catch { return { content: [{ type: "text" as const, text: "META_BUSINESS_ID environment variable is required for this operation. Please set it and restart the server." }], isError: true }; } 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(`/${businessId}/owned_ad_accounts`, 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/business.ts:50-76 (registration)Tool registration via server.tool() call in registerBusinessTools(). The function registerBusinessTools is imported and called in src/index.ts at line 90.
server.tool( "list_business_ad_accounts", "List ad accounts owned by the configured business. Requires META_BUSINESS_ID env var.", { 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 ({ fields, limit, after }) => { try { let businessId: string; try { businessId = client.businessId; } catch { return { content: [{ type: "text" as const, text: "META_BUSINESS_ID environment variable is required for this operation. Please set it and restart the server." }], isError: true }; } 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(`/${businessId}/owned_ad_accounts`, 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/business.ts:53-57 (schema)Input schema using Zod: fields (optional string), limit (optional number, default 25), after (optional string for pagination).
{ 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/services/ads-client.ts:235-242 (helper)The businessId getter on AdsClient reads from config (META_BUSINESS_ID env var) and throws if unset.
get businessId(): string { if (!this.config.businessId) { throw new Error( "META_BUSINESS_ID is not configured. Set it as an environment variable." ); } return this.config.businessId; }