create_rf_prediction
Create a reach and frequency prediction for Meta ad campaigns by providing targeting spec, budget in cents, and scheduling info.
Instructions
Create a new reach & frequency prediction. Provide targeting spec as JSON string, budget in cents, and scheduling info.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| target_spec | Yes | JSON string of targeting specification | |
| start_time | Yes | Prediction start time (ISO 8601 or Unix timestamp) | |
| stop_time | Yes | Prediction stop time (ISO 8601 or Unix timestamp) | |
| budget | Yes | Budget in account currency cents | |
| frequency_cap | Yes | Maximum frequency cap per user | |
| destination_id | Yes | Destination ID (e.g. Facebook Page ID) |
Implementation Reference
- src/tools/reach_frequency.ts:41-56 (handler)Handler function for the 'create_rf_prediction' tool. Takes target_spec, start_time, stop_time, budget, frequency_cap, destination_id; sends a POST to /{accountPath}/reachfrequencypredictions on the Meta Ads API.
async ({ target_spec, start_time, stop_time, budget, frequency_cap, destination_id }) => { try { const params: Record<string, unknown> = { target_spec, start_time, stop_time, budget, frequency_cap, destination_id, }; const { data, rateLimit } = await client.post(`${client.accountPath}/reachfrequencypredictions`, 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/reach_frequency.ts:33-40 (schema)Zod schema defining input parameters for create_rf_prediction: target_spec (JSON string), start_time (ISO string), stop_time (ISO string), budget (number cents), frequency_cap (number), destination_id (string).
{ target_spec: z.string().describe("JSON string of targeting specification"), start_time: z.string().describe("Prediction start time (ISO 8601 or Unix timestamp)"), stop_time: z.string().describe("Prediction stop time (ISO 8601 or Unix timestamp)"), budget: z.number().describe("Budget in account currency cents"), frequency_cap: z.number().describe("Maximum frequency cap per user"), destination_id: z.string().describe("Destination ID (e.g. Facebook Page ID)"), }, - src/tools/reach_frequency.ts:29-57 (registration)Registration of 'create_rf_prediction' as an MCP tool using server.tool() with name 'create_rf_prediction' and description about creating a reach & frequency prediction.
// ─── create_rf_prediction ───────────────────────────────────── server.tool( "create_rf_prediction", "Create a new reach & frequency prediction. Provide targeting spec as JSON string, budget in cents, and scheduling info.", { target_spec: z.string().describe("JSON string of targeting specification"), start_time: z.string().describe("Prediction start time (ISO 8601 or Unix timestamp)"), stop_time: z.string().describe("Prediction stop time (ISO 8601 or Unix timestamp)"), budget: z.number().describe("Budget in account currency cents"), frequency_cap: z.number().describe("Maximum frequency cap per user"), destination_id: z.string().describe("Destination ID (e.g. Facebook Page ID)"), }, async ({ target_spec, start_time, stop_time, budget, frequency_cap, destination_id }) => { try { const params: Record<string, unknown> = { target_spec, start_time, stop_time, budget, frequency_cap, destination_id, }; const { data, rateLimit } = await client.post(`${client.accountPath}/reachfrequencypredictions`, 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:83-83 (registration)Registration call linking registerReachFrequencyTools into the main server.
registerReachFrequencyTools(server, client); - src/services/ads-client.ts:187-201 (helper)The AdsClient.post() method used by the handler to POST data to the Meta Ads API.
async post( path: string, params?: Record<string, unknown> ): Promise<ClientResponse> { return this.request("POST", path, params); } async delete( path: string, params?: Record<string, unknown> ): Promise<ClientResponse> { return this.request("DELETE", path, params); } // --- Upload (URL-based) ---