update_campaign
Modify an existing Meta Ads campaign by updating its name, status, budget, bid strategy, or other parameters to optimize performance and align with advertising goals.
Instructions
Update an existing campaign in a Meta Ads account.
Args:
access_token: Meta API access token (optional - will use cached token if not provided)
campaign_id: Meta Ads campaign ID (required)
name: New campaign name
status: New campaign status (e.g., 'ACTIVE', 'PAUSED')
special_ad_categories: List of special ad categories if applicable
daily_budget: New daily budget in account currency (in cents) as a string.
Set to empty string "" to remove the daily budget.
lifetime_budget: New lifetime budget in account currency (in cents) as a string.
Set to empty string "" to remove the lifetime budget.
bid_strategy: New bid strategy
bid_cap: New bid cap in account currency (in cents) as a string
spend_cap: New spending limit for the campaign in account currency (in cents) as a string
campaign_budget_optimization: Enable/disable campaign budget optimization
objective: New campaign objective (Note: May not always be updatable)
use_adset_level_budgets: If True, removes campaign-level budgets to switch to ad set level budgets
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| access_token | No | ||
| bid_cap | No | ||
| bid_strategy | No | ||
| campaign_budget_optimization | No | ||
| campaign_id | No | ||
| daily_budget | No | ||
| lifetime_budget | No | ||
| name | No | ||
| objective | No | ||
| special_ad_categories | No | ||
| spend_cap | No | ||
| status | No | ||
| use_adset_level_budgets | No |
Implementation Reference
- meta_ads_mcp/core/campaigns.py:232-233 (registration)Registers the update_campaign tool using the mcp_server.tool decorator along with meta_api_tool decorator.@mcp_server.tool() @meta_api_tool
- meta_ads_mcp/core/campaigns.py:234-354 (handler)The main handler function for the 'update_campaign' tool. It constructs parameters based on inputs and makes a POST request to the Meta Ads API campaign endpoint to perform the update.async def update_campaign( campaign_id: str, access_token: Optional[str] = None, name: Optional[str] = None, status: Optional[str] = None, special_ad_categories: Optional[List[str]] = None, daily_budget: Optional[int] = None, lifetime_budget: Optional[int] = None, bid_strategy: Optional[str] = None, bid_cap: Optional[int] = None, spend_cap: Optional[int] = None, campaign_budget_optimization: Optional[bool] = None, objective: Optional[str] = None, # Add objective if it's updatable use_adset_level_budgets: Optional[bool] = None, # Add other updatable fields as needed based on API docs ) -> str: """ Update an existing campaign in a Meta Ads account. Args: campaign_id: Meta Ads campaign ID access_token: Meta API access token (optional - will use cached token if not provided) name: New campaign name status: New campaign status (e.g., 'ACTIVE', 'PAUSED') special_ad_categories: List of special ad categories if applicable daily_budget: New daily budget in account currency (in cents) as a string. Set to empty string "" to remove the daily budget. lifetime_budget: New lifetime budget in account currency (in cents) as a string. Set to empty string "" to remove the lifetime budget. bid_strategy: New bid strategy bid_cap: New bid cap in account currency (in cents) as a string spend_cap: New spending limit for the campaign in account currency (in cents) as a string campaign_budget_optimization: Enable/disable campaign budget optimization objective: New campaign objective (Note: May not always be updatable) use_adset_level_budgets: If True, removes campaign-level budgets to switch to ad set level budgets """ if not campaign_id: return json.dumps({"error": "No campaign ID provided"}, indent=2) endpoint = f"{campaign_id}" params = {} # Add parameters to the request only if they are provided if name is not None: params["name"] = name if status is not None: params["status"] = status if special_ad_categories is not None: # Note: Updating special_ad_categories might have specific API rules or might not be allowed after creation. # The API might require an empty list `[]` to clear categories. Check Meta Docs. params["special_ad_categories"] = json.dumps(special_ad_categories) # Handle budget parameters based on use_adset_level_budgets setting if use_adset_level_budgets is not None: if use_adset_level_budgets: # Remove campaign-level budgets when switching to ad set level budgets params["daily_budget"] = "" params["lifetime_budget"] = "" if campaign_budget_optimization is not None: params["campaign_budget_optimization"] = "false" else: # If switching back to campaign-level budgets, use the provided budget values if daily_budget is not None: if daily_budget == "": params["daily_budget"] = "" else: params["daily_budget"] = str(daily_budget) if lifetime_budget is not None: if lifetime_budget == "": params["lifetime_budget"] = "" else: params["lifetime_budget"] = str(lifetime_budget) if campaign_budget_optimization is not None: params["campaign_budget_optimization"] = "true" if campaign_budget_optimization else "false" else: # Normal budget updates when not changing budget strategy if daily_budget is not None: # To remove budget, set to empty string if daily_budget == "": params["daily_budget"] = "" else: params["daily_budget"] = str(daily_budget) if lifetime_budget is not None: # To remove budget, set to empty string if lifetime_budget == "": params["lifetime_budget"] = "" else: params["lifetime_budget"] = str(lifetime_budget) if campaign_budget_optimization is not None: params["campaign_budget_optimization"] = "true" if campaign_budget_optimization else "false" if bid_strategy is not None: params["bid_strategy"] = bid_strategy if bid_cap is not None: params["bid_cap"] = str(bid_cap) if spend_cap is not None: params["spend_cap"] = str(spend_cap) if objective is not None: params["objective"] = objective # Caution: Objective changes might reset learning or be restricted if not params: return json.dumps({"error": "No update parameters provided"}, indent=2) try: # Use POST method for updates as per Meta API documentation data = await make_api_request(endpoint, access_token, params, method="POST") # Add a note about budget strategy if switching to ad set level budgets if use_adset_level_budgets is not None and use_adset_level_budgets: data["budget_strategy"] = "ad_set_level" data["note"] = "Campaign updated to use ad set level budgets. Set budgets when creating ad sets within this campaign." return json.dumps(data, indent=2) except Exception as e: error_msg = str(e) # Include campaign_id in error for better context return json.dumps({ "error": f"Failed to update campaign {campaign_id}", "details": error_msg, "params_sent": params # Be careful about logging sensitive data if any }, indent=2)