update_campaign
Modify existing Facebook ad campaigns by updating only specified fields such as name, status, budget, or schedule, leaving other settings unchanged.
Instructions
Update an existing campaign. Only provided fields will be modified.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| campaign_id | Yes | Campaign ID to update | |
| name | No | New campaign name | |
| status | No | New status: ACTIVE, PAUSED, DELETED, ARCHIVED | |
| daily_budget | No | New daily budget in currency cents | |
| lifetime_budget | No | New lifetime budget in currency cents | |
| start_time | No | New start time (ISO 8601) | |
| stop_time | No | New stop time (ISO 8601) |
Implementation Reference
- src/tools/campaigns.ts:92-120 (handler)The full tool definition including both schema (input validation with Zod) and handler (async function that builds params from optional fields and POSTs to /{campaign_id})
// ─── update_campaign ─────────────────────────────────────── server.tool( "update_campaign", "Update an existing campaign. Only provided fields will be modified.", { campaign_id: z.string().describe("Campaign ID to update"), name: z.string().optional().describe("New campaign name"), status: z.string().optional().describe("New status: ACTIVE, PAUSED, DELETED, ARCHIVED"), daily_budget: z.string().optional().describe("New daily budget in currency cents"), lifetime_budget: z.string().optional().describe("New lifetime budget in currency cents"), start_time: z.string().optional().describe("New start time (ISO 8601)"), stop_time: z.string().optional().describe("New stop time (ISO 8601)"), }, async ({ campaign_id, name, status, daily_budget, lifetime_budget, start_time, stop_time }) => { try { const params: Record<string, unknown> = {}; if (name) params.name = name; if (status) params.status = status; if (daily_budget) params.daily_budget = daily_budget; if (lifetime_budget) params.lifetime_budget = lifetime_budget; if (start_time) params.start_time = start_time; if (stop_time) params.stop_time = stop_time; const { data, rateLimit } = await client.post(`/${campaign_id}`, 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/campaigns.ts:96-104 (schema)Zod schema defining input validation: required campaign_id string, optional name, status, daily_budget, lifetime_budget, start_time, stop_time
{ campaign_id: z.string().describe("Campaign ID to update"), name: z.string().optional().describe("New campaign name"), status: z.string().optional().describe("New status: ACTIVE, PAUSED, DELETED, ARCHIVED"), daily_budget: z.string().optional().describe("New daily budget in currency cents"), lifetime_budget: z.string().optional().describe("New lifetime budget in currency cents"), start_time: z.string().optional().describe("New start time (ISO 8601)"), stop_time: z.string().optional().describe("New stop time (ISO 8601)"), }, - src/tools/campaigns.ts:93-120 (registration)Tool registered on MCP server via server.tool() with name 'update_campaign' inside registerCampaignTools()
server.tool( "update_campaign", "Update an existing campaign. Only provided fields will be modified.", { campaign_id: z.string().describe("Campaign ID to update"), name: z.string().optional().describe("New campaign name"), status: z.string().optional().describe("New status: ACTIVE, PAUSED, DELETED, ARCHIVED"), daily_budget: z.string().optional().describe("New daily budget in currency cents"), lifetime_budget: z.string().optional().describe("New lifetime budget in currency cents"), start_time: z.string().optional().describe("New start time (ISO 8601)"), stop_time: z.string().optional().describe("New stop time (ISO 8601)"), }, async ({ campaign_id, name, status, daily_budget, lifetime_budget, start_time, stop_time }) => { try { const params: Record<string, unknown> = {}; if (name) params.name = name; if (status) params.status = status; if (daily_budget) params.daily_budget = daily_budget; if (lifetime_budget) params.lifetime_budget = lifetime_budget; if (start_time) params.start_time = start_time; if (stop_time) params.stop_time = stop_time; const { data, rateLimit } = await client.post(`/${campaign_id}`, 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/services/ads-client.ts:187-192 (helper)The AdsClient.post() convenience method used by the handler to make the POST request to Meta Ads API
async post( path: string, params?: Record<string, unknown> ): Promise<ClientResponse> { return this.request("POST", path, params); }