update_campaign
Modify existing Meta Ads campaigns by updating name, status, budget, bid strategy, and other parameters to optimize advertising performance.
Instructions
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
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| campaign_id | Yes | ||
| access_token | No | ||
| name | No | ||
| status | No | ||
| special_ad_categories | No | ||
| daily_budget | No | ||
| lifetime_budget | No | ||
| bid_strategy | No | ||
| bid_cap | No | ||
| spend_cap | No | ||
| campaign_budget_optimization | No | ||
| objective | No | ||
| use_adset_level_budgets | No |
Implementation Reference
- meta_ads_mcp/core/campaigns.py:232-354 (handler)The handler function for the 'update_campaign' MCP tool. It is decorated with @mcp_server.tool() for registration and @meta_api_tool for API integration. This async function handles updating Meta Ads campaigns by making POST requests to the Meta API with the provided parameters, handling budgets, bid strategies, and error cases.@mcp_server.tool() @meta_api_tool 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)