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.

feat: enhance update_ad_creative to handle content update limitations

Yves Junqueiraf0f486d6098f
diff --git a/meta_ads_mcp/core/ads.py b/meta_ads_mcp/core/ads.py
index 4030f66..27fac4f 100644
--- a/meta_ads_mcp/core/ads.py
+++ b/meta_ads_mcp/core/ads.py
@@ -1378,27 +1378,56 @@ async def update_ad_creative(
# Prepare the API endpoint for updating the creative
endpoint = f"{creative_id}"
-
+
try:
# Make API request to update the creative
data = await make_api_request(endpoint, access_token, update_data, method="POST")
-
+
# If successful, get more details about the updated creative
if "id" in data:
creative_endpoint = f"{creative_id}"
creative_params = {
"fields": "id,name,status,thumbnail_url,image_url,image_hash,object_story_spec,url_tags,link_url,dynamic_creative_spec"
}
-
+
creative_details = await make_api_request(creative_endpoint, access_token, creative_params)
return json.dumps({
"success": True,
"creative_id": creative_id,
"details": creative_details
}, indent=2)
-
+
+ # Check for Meta API content update limitation (error_subcode 1815573)
+ error_obj = data.get("error", {})
+ if isinstance(error_obj, dict):
+ error_details = error_obj.get("details", {})
+ if isinstance(error_details, dict):
+ inner_error = error_details.get("error", {})
+ error_subcode = inner_error.get("error_subcode") if isinstance(inner_error, dict) else None
+ else:
+ error_subcode = error_obj.get("error_subcode")
+ else:
+ error_subcode = None
+
+ if error_subcode == 1815573:
+ return json.dumps({
+ "error": "Content updates are not allowed on existing creatives",
+ "explanation": (
+ "The Meta API does not allow updating content fields (message, headline, "
+ "description, CTA, image, video, URL) on existing creatives. "
+ "Only the creative 'name' can be changed."
+ ),
+ "workaround": (
+ "To change ad content: (1) create a new creative with the desired content "
+ "using create_ad_creative, then (2) call update_ad with the ad's ID and the "
+ "new creative_id to swap it on the ad."
+ ),
+ "creative_id": creative_id,
+ "attempted_updates": update_data
+ }, indent=2)
+
return json.dumps(data, indent=2)
-
+
except Exception as e:
return json.dumps({
"error": "Failed to update ad creative",
diff --git a/tests/test_update_ad_creative_content_limit.py b/tests/test_update_ad_creative_content_limit.py
new file mode 100644
index 0000000..5b65019
--- /dev/null
+++ b/tests/test_update_ad_creative_content_limit.py
@@ -0,0 +1,148 @@
+"""Tests for update_ad_creative content update limitation handling.
+
+Tests that update_ad_creative provides clear, actionable error messages
+when Meta API rejects content updates (error_subcode 1815573).
+"""
+
+import pytest
+import json
+from unittest.mock import AsyncMock, patch
+from meta_ads_mcp.core.ads import update_ad_creative
+
+
+def _unwrap_result(result_str):
+ """Unwrap the result, handling the meta_api_tool data wrapping."""
+ result_data = json.loads(result_str)
+ if "data" in result_data:
+ return json.loads(result_data["data"])
+ return result_data
+
+
+class TestUpdateAdCreativeContentLimit:
+ """Test cases for update_ad_creative content update limitation."""
+
+ async def test_content_update_1815573_returns_workaround(self):
+ """When Meta rejects content update with 1815573, return clear workaround."""
+
+ # Simulate the error structure returned by make_api_request for HTTP 400
+ api_error = {
+ "error": {
+ "message": "HTTP Error: 400",
+ "details": {
+ "error": {
+ "message": "(#100) The parameter is not supported",
+ "type": "OAuthException",
+ "code": 100,
+ "error_subcode": 1815573,
+ "fbtrace_id": "abc123"
+ }
+ },
+ "full_response": {
+ "status_code": 400
+ }
+ }
+ }
+
+ with patch('meta_ads_mcp.core.ads.make_api_request', new_callable=AsyncMock) as mock_api:
+ mock_api.return_value = api_error
+
+ result = await update_ad_creative(
+ creative_id="test_creative_123",
+ message="New message text",
+ access_token="test_token"
+ )
+
+ result_data = _unwrap_result(result)
+ assert result_data["error"] == "Content updates are not allowed on existing creatives"
+ assert "workaround" in result_data
+ assert "create_ad_creative" in result_data["workaround"]
+ assert "update_ad" in result_data["workaround"]
+ assert result_data["creative_id"] == "test_creative_123"
+ assert "attempted_updates" in result_data
+
+ async def test_content_update_1815573_headline(self):
+ """Headline update also triggers the helpful error."""
+
+ api_error = {
+ "error": {
+ "message": "HTTP Error: 400",
+ "details": {
+ "error": {
+ "message": "(#100) The parameter is not supported",
+ "type": "OAuthException",
+ "code": 100,
+ "error_subcode": 1815573,
+ }
+ },
+ "full_response": {"status_code": 400}
+ }
+ }
+
+ with patch('meta_ads_mcp.core.ads.make_api_request', new_callable=AsyncMock) as mock_api:
+ mock_api.return_value = api_error
+
+ result = await update_ad_creative(
+ creative_id="test_creative_123",
+ headline="New headline",
+ access_token="test_token"
+ )
+
+ result_data = _unwrap_result(result)
+ assert result_data["error"] == "Content updates are not allowed on existing creatives"
+ assert "workaround" in result_data
+
+ async def test_name_update_still_works(self):
+ """Name-only updates should succeed normally (not trigger 1815573 path)."""
+
+ success_response = {"id": "test_creative_123"}
+ creative_details = {
+ "id": "test_creative_123",
+ "name": "Updated Name",
+ "status": "ACTIVE"
+ }
+
+ with patch('meta_ads_mcp.core.ads.make_api_request', new_callable=AsyncMock) as mock_api:
+ mock_api.side_effect = [success_response, creative_details]
+
+ result = await update_ad_creative(
+ creative_id="test_creative_123",
+ name="Updated Name",
+ access_token="test_token"
+ )
+
+ result_data = _unwrap_result(result)
+ assert result_data["success"] is True
+ assert result_data["creative_id"] == "test_creative_123"
+
+ async def test_other_errors_not_intercepted(self):
+ """Non-1815573 errors should pass through unchanged."""
+
+ api_error = {
+ "error": {
+ "message": "HTTP Error: 400",
+ "details": {
+ "error": {
+ "message": "Invalid creative ID",
+ "type": "OAuthException",
+ "code": 100,
+ "error_subcode": 9999,
+ }
+ },
+ "full_response": {"status_code": 400}
+ }
+ }
+
+ with patch('meta_ads_mcp.core.ads.make_api_request', new_callable=AsyncMock) as mock_api:
+ mock_api.return_value = api_error
+
+ result = await update_ad_creative(
+ creative_id="test_creative_123",
+ message="New message",
+ access_token="test_token"
+ )
+
+ result_data = _unwrap_result(result)
+ # Should pass through the raw error, not the workaround message
+ assert "workaround" not in result_data
+ assert "error" in result_data