list_businesses
List all businesses accessible by the current user, with paginated results.
Instructions
List all businesses accessible by the current user. Returns paginated results.
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:6-27 (handler)The handler function (registered as server.tool('list_businesses', ...)) that calls client.get('/me/businesses', params) to list all businesses accessible by the current user.
// ─── list_businesses ────────────────────────────────────────── server.tool( "list_businesses", "List all businesses accessible by the current user. Returns paginated results.", { 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 { 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(`/me/businesses`, 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:10-14 (schema)Input schema for list_businesses: optional 'fields' (string), 'limit' (number, default 25), and 'after' (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/tools/business.ts:4-5 (registration)The registerBusinessTools function wraps all business tool registrations including list_businesses.
export function registerBusinessTools(server: McpServer, client: AdsClient): void { - src/index.ts:88-90 (registration)Registration call: registerBusinessTools(server, client) invoked in the main server initialization.
// --- Account & Business --- registerAccountTools(server, client); registerBusinessTools(server, client); - src/services/ads-client.ts:180-185 (helper)The AdsClient.get() method used by the handler to make the HTTP GET request to the Meta API.
async get( path: string, params?: Record<string, unknown> ): Promise<ClientResponse> { return this.request("GET", path, params); }