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.
Python advertisingai-agentschatgptclaudefacebook-adsinstagram-adsmcpmeta-adsmodel-context-protocolpipeboard
Refactor ad creative structure to align with Meta API specifications
Yves Junqueirab4211215d2b4
diff --git a/meta_ads_mcp/core/ads.py b/meta_ads_mcp/core/ads.pyindex f08dd53..10ee877 100644--- a/meta_ads_mcp/core/ads.py+++ b/meta_ads_mcp/core/ads.py@@ -855,23 +855,25 @@ async def create_ad_creative(# ONLY use asset_feed_spec when user explicitly provides plural parameters (headlines/descriptions)if headlines or descriptions:# Use asset_feed_spec for dynamic creatives with multiple variants+ # Structure based on Meta API working example from documentation+ # ad_formats must be specified with exactly one formatasset_feed_spec = {- "ad_formats": ["SINGLE_IMAGE"],"images": [{"hash": image_hash}],- "link_urls": [{"website_url": link_url if link_url else "https://facebook.com"}]+ "link_urls": [{"website_url": link_url if link_url else "https://facebook.com"}],+ "ad_formats": ["SINGLE_IMAGE"]}- # Handle headlines+ # Handle headlines - Meta API uses "titles" not "headlines" in asset_feed_specif headlines:- asset_feed_spec["headlines"] = [{"text": headline_text} for headline_text in headlines]+ asset_feed_spec["titles"] = [{"text": headline_text} for headline_text in headlines]# Handle descriptionsif descriptions:asset_feed_spec["descriptions"] = [{"text": description_text} for description_text in descriptions]- # Add message as primary_texts if provided+ # Add message as bodies - Meta API uses "bodies" not "primary_texts" in asset_feed_specif message:- asset_feed_spec["primary_texts"] = [{"text": message}]+ asset_feed_spec["bodies"] = [{"text": message}]# Add call_to_action_types if providedif call_to_action_type:@@ -879,9 +881,14 @@ async def create_ad_creative(creative_data["asset_feed_spec"] = asset_feed_spec- # For dynamic creatives, we need a simplified object_story_spec+ # For dynamic creatives with asset_feed_spec, object_story_spec needs page_id+ # According to Meta API docs, link_data should have link and call_to_actioncreative_data["object_story_spec"] = {- "page_id": page_id+ "page_id": page_id,+ "link_data": {+ "link": link_url if link_url else "https://facebook.com",+ "call_to_action": {"type": call_to_action_type if call_to_action_type else "LEARN_MORE"}+ }}else:# Use traditional object_story_spec with link_data for simple creatives@@ -1023,17 +1030,17 @@ async def update_ad_creative(# Add required ad_formats field for dynamic creativesasset_feed_spec["ad_formats"] = ["SINGLE_IMAGE"]- # Handle headlines+ # Handle headlines - Meta API uses "titles" not "headlines" in asset_feed_specif headlines:- asset_feed_spec["headlines"] = [{"text": headline_text} for headline_text in headlines]+ asset_feed_spec["titles"] = [{"text": headline_text} for headline_text in headlines]# Handle descriptionsif descriptions:asset_feed_spec["descriptions"] = [{"text": description_text} for description_text in descriptions]- # Add message as primary_texts if provided+ # Add message as bodies - Meta API uses "bodies" not "primary_texts" in asset_feed_specif message:- asset_feed_spec["primary_texts"] = [{"text": message}]+ asset_feed_spec["bodies"] = [{"text": message}]# Add call_to_action_types if providedif call_to_action_type:diff --git a/tests/test_create_ad_creative_simple.py b/tests/test_create_ad_creative_simple.pyindex 0e5af58..b9935c9 100644--- a/tests/test_create_ad_creative_simple.py+++ b/tests/test_create_ad_creative_simple.py@@ -118,10 +118,10 @@ async def test_dynamic_creative_uses_asset_feed_spec():# Verify it uses asset_feed_spec for dynamic creativesassert "asset_feed_spec" in creative_data, "Should use asset_feed_spec for dynamic creatives"- # Verify asset_feed_spec structure+ # Verify asset_feed_spec structure (Meta API uses "titles" not "headlines")asset_feed_spec = creative_data["asset_feed_spec"]- assert "headlines" in asset_feed_spec- assert len(asset_feed_spec["headlines"]) == 2+ assert "titles" in asset_feed_spec+ assert len(asset_feed_spec["titles"]) == 2assert "descriptions" in asset_feed_specassert len(asset_feed_spec["descriptions"]) == 2diff --git a/tests/test_dynamic_creatives.py b/tests/test_dynamic_creatives.pyindex d982172..644e295 100644--- a/tests/test_dynamic_creatives.py+++ b/tests/test_dynamic_creatives.py@@ -190,10 +190,10 @@ class TestDynamicCreatives:first_call = call_args_list[0]creative_data = first_call[0][2] # params is the third argument- # Should use asset_feed_spec with headlines array format+ # Should use asset_feed_spec with titles array format (Meta API uses "titles" not "headlines")assert "asset_feed_spec" in creative_data- assert "headlines" in creative_data["asset_feed_spec"]- assert creative_data["asset_feed_spec"]["headlines"] == [+ assert "titles" in creative_data["asset_feed_spec"]+ assert creative_data["asset_feed_spec"]["titles"] == [{"text": "Headline 1"},{"text": "Headline 2"},{"text": "Headline 3"}@@ -331,7 +331,7 @@ class TestDynamicCreatives:creative_data = first_call[0][2] # params is the third argumentassert "asset_feed_spec" in creative_data- assert "headlines" in creative_data["asset_feed_spec"]+ assert "titles" in creative_data["asset_feed_spec"]assert "descriptions" in creative_data["asset_feed_spec"]assert "dynamic_creative_spec" in creative_data@@ -418,8 +418,8 @@ class TestDynamicCreatives:creative_data = first_call[0][2] # params is the third argumentassert "asset_feed_spec" in creative_data- assert "headlines" in creative_data["asset_feed_spec"]- assert creative_data["asset_feed_spec"]["headlines"] == [+ assert "titles" in creative_data["asset_feed_spec"]+ assert creative_data["asset_feed_spec"]["titles"] == [{"text": "New Headline 1"},{"text": "New Headline 2"},{"text": "New Headline 3"}@@ -814,19 +814,19 @@ class TestDynamicCreatives:# Should have asset_feed_spec with all dynamic contentassert "asset_feed_spec" in creative_data- assert "headlines" in creative_data["asset_feed_spec"]+ assert "titles" in creative_data["asset_feed_spec"]assert "descriptions" in creative_data["asset_feed_spec"]- assert "primary_texts" in creative_data["asset_feed_spec"]+ assert "bodies" in creative_data["asset_feed_spec"]assert "call_to_action_types" in creative_data["asset_feed_spec"]# Verify content- assert creative_data["asset_feed_spec"]["headlines"] == [+ assert creative_data["asset_feed_spec"]["titles"] == [{"text": "New Headline 1"}, {"text": "New Headline 2"}]assert creative_data["asset_feed_spec"]["descriptions"] == [{"text": "New Description 1"}]- assert creative_data["asset_feed_spec"]["primary_texts"] == [+ assert creative_data["asset_feed_spec"]["bodies"] == [{"text": "Updated message"}]assert creative_data["asset_feed_spec"]["call_to_action_types"] == ["SIGN_UP"]