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
fix: add image_hash anchor to link_data for multi-image FLEX creatives
Yves Junqueira9658acdc35fa
diff --git a/meta_ads_mcp/core/ads.py b/meta_ads_mcp/core/ads.pyindex ed841c8..19f4de5 100644--- a/meta_ads_mcp/core/ads.py+++ b/meta_ads_mcp/core/ads.py@@ -1298,28 +1298,23 @@ async def create_ad_creative(else:# Image creative with asset_feed_spec (FLEX / Dynamic Creative).#- # Per Meta API docs, when using asset_feed_spec the- # object_story_spec should contain ONLY page_id — the link URL- # goes in asset_feed_spec.link_urls instead.+ # Meta requires link_data in object_story_spec even when+ # asset_feed_spec is present (error 2061015 without it).#- # For multi-image creatives (image_hashes), including link_data- # causes Meta to treat the request as a simple link post and- # silently ignore the entire asset_feed_spec.- #- # For single-image creatives (image_hash), Meta historically- # required link_data (error 2061015 without it), so we keep it- # as a compatibility measure until we can verify removal is safe.+ # For multi-image creatives (image_hashes), link_data MUST+ # include an image_hash as the "primary" image anchor.+ # Without it, Meta silently ignores the asset_feed_spec and+ # creates a bare link creative instead. This matches what+ # Meta's own GET response returns for FLEX creatives — both+ # link_data.image_hash (primary) and asset_feed_spec.images+ # (all variants) are present.+ link_data = {"link": link_url}if image_hashes:- creative_data["object_story_spec"] = {- "page_id": page_id,- }- else:- creative_data["object_story_spec"] = {- "page_id": page_id,- "link_data": {- "link": link_url- }- }+ link_data["image_hash"] = image_hashes[0]+ creative_data["object_story_spec"] = {+ "page_id": page_id,+ "link_data": link_data,+ }else:if is_video:# Use object_story_spec with video_data for simple video creatives.diff --git a/tests/test_ad_formats_flexible.py b/tests/test_ad_formats_flexible.pyindex 78a3b1b..b6e3a8c 100644--- a/tests/test_ad_formats_flexible.py+++ b/tests/test_ad_formats_flexible.py@@ -284,10 +284,14 @@ class TestFlexibleCreativeFullFlow:assert afs["call_to_action_types"] == ["SHOP_NOW"]assert afs["link_urls"] == [{"website_url": "https://example.com"}]- # Multi-image: object_story_spec has ONLY page_id (no link_data).- # link_data would cause Meta to silently ignore asset_feed_spec.+ # Multi-image: link_data must include image_hash as primary anchor.+ # Without it, Meta silently ignores asset_feed_spec.assert creative_data["object_story_spec"] == {"page_id": "987654321",+ "link_data": {+ "link": "https://example.com",+ "image_hash": "hash1",+ },}async def test_full_flexible_creative_single_image_keeps_link_data(self):diff --git a/tests/test_flex_creatives.py b/tests/test_flex_creatives.pyindex d5180ff..8cc4aaa 100644--- a/tests/test_flex_creatives.py+++ b/tests/test_flex_creatives.py@@ -320,9 +320,12 @@ class TestFlexCreatives:assert afs["descriptions"] == [{"text": "Desc 1"}, {"text": "Desc 2"}]assert afs["call_to_action_types"] == ["SHOP_NOW"]- # Multi-image: object_story_spec must have ONLY page_id (no link_data).- # Adding link_data causes Meta to silently ignore asset_feed_spec.- assert creative_data["object_story_spec"] == {"page_id": "987654321"}+ # Multi-image: link_data must include image_hash as primary anchor.+ # Without it, Meta silently ignores asset_feed_spec.+ assert creative_data["object_story_spec"] == {+ "page_id": "987654321",+ "link_data": {"link": "https://example.com", "image_hash": "hash1"},+ }async def test_image_hashes_without_optimization_type_uses_asset_feed(self):"""image_hashes (plural) triggers asset_feed_spec even without optimization_type."""@@ -359,8 +362,11 @@ class TestFlexCreatives:# No optimization_type should be setassert "optimization_type" not in creative_data["asset_feed_spec"]- # Multi-image: object_story_spec must have ONLY page_id (no link_data)- assert creative_data["object_story_spec"] == {"page_id": "987654321"}+ # Multi-image: link_data must include image_hash as primary anchor+ assert creative_data["object_story_spec"] == {+ "page_id": "987654321",+ "link_data": {"link": "https://example.com", "image_hash": "hash1"},+ }async def test_no_image_hash_or_image_hashes_returns_error(self):"""Must provide either image_hash, image_hashes, or video_id."""