Skip to content

Meta Ads (Facebook/Instagram) MCP server for Claude, ChatGPT, Perplexity & Cursor — the Meta node of Pipeboard’s 5-platform family (+ Google, TikTok, Snap, Reddit). Hosted remote MCP, badged Meta Business Partner, free plan — no self-hosting required.

Add update_campaign function for modifying existing campaigns in Meta Ads API

Yves Junqueira7d0d1165b9e6
diff --git a/meta_ads_mcp/core/campaigns.py b/meta_ads_mcp/core/campaigns.py
index 9533278..b1775f8 100644
--- a/meta_ads_mcp/core/campaigns.py
+++ b/meta_ads_mcp/core/campaigns.py
@@ -165,4 +165,86 @@ async def create_campaign(
"error": "Failed to create campaign",
"details": error_msg,
"params_sent": params
+ }, indent=2)
+
+
+@mcp_server.tool()
+@meta_api_tool
+async def update_campaign(
+ access_token: str = None,
+ campaign_id: str = None,
+ name: str = None,
+ status: str = None,
+ special_ad_categories: List[str] = None,
+ daily_budget = None,
+ lifetime_budget = None,
+ bid_strategy: str = None,
+ bid_cap = None,
+ spend_cap = None,
+ campaign_budget_optimization: bool = None,
+ objective: str = None, # Add objective if it's updatable
+ # Add other updatable fields as needed based on API docs
+) -> str:
+ """
+ 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
+ lifetime_budget: New lifetime budget in account currency (in cents) as a string
+ 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)
+ """
+ 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)
+ if daily_budget is not None:
+ params["daily_budget"] = str(daily_budget)
+ if lifetime_budget is not None:
+ params["lifetime_budget"] = str(lifetime_budget)
+ 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 campaign_budget_optimization is not None:
+ params["campaign_budget_optimization"] = "true" if campaign_budget_optimization else "false"
+ 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")
+ 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)
\ No newline at end of file