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
tentative fix: omit link_data from object_story_spec for multi-image FLEX creatives
Yves Junqueira7c1f60b1286f
diff --git a/meta_ads_mcp/core/ads.py b/meta_ads_mcp/core/ads.pyindex 310e2ff..ed841c8 100644--- a/meta_ads_mcp/core/ads.py+++ b/meta_ads_mcp/core/ads.py@@ -1296,13 +1296,30 @@ async def create_ad_creative("video_data": video_anchor}else:- # Image FLEX: use link_data with the destination URL.- creative_data["object_story_spec"] = {- "page_id": page_id,- "link_data": {- "link": link_url+ # 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.+ #+ # 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.+ 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+ }}- }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 a866317..78a3b1b 100644--- a/tests/test_ad_formats_flexible.py+++ b/tests/test_ad_formats_flexible.py@@ -284,7 +284,47 @@ class TestFlexibleCreativeFullFlow:assert afs["call_to_action_types"] == ["SHOP_NOW"]assert afs["link_urls"] == [{"website_url": "https://example.com"}]- # object_story_spec needs page_id + link_data with destination URL+ # Multi-image: object_story_spec has ONLY page_id (no link_data).+ # link_data would cause Meta to silently ignore asset_feed_spec.+ assert creative_data["object_story_spec"] == {+ "page_id": "987654321",+ }++ async def test_full_flexible_creative_single_image_keeps_link_data(self):+ """Single-image DEGREES_OF_FREEDOM creative keeps link_data in object_story_spec.++ Meta historically required link_data for single-image asset_feed_spec+ creatives (error 2061015). This test preserves the verified behavior.+ """+ sample_creative_data = {"id": "123", "name": "Single Flex", "status": "ACTIVE"}++ with patch('meta_ads_mcp.core.ads.make_api_request', new_callable=AsyncMock) as mock_api:+ mock_api.return_value = sample_creative_data++ result = await create_ad_creative(+ access_token="test_token",+ account_id="act_123456789",+ name="Single Image Flexible Creative",+ image_hash="hash1",+ page_id="987654321",+ link_url="https://example.com",+ messages=["Primary text A", "Primary text B"],+ headlines=["Headline 1", "Headline 2"],+ optimization_type="DEGREES_OF_FREEDOM",+ call_to_action_type="SHOP_NOW"+ )++ result_data = json.loads(result)+ assert result_data["success"] is True++ creative_data = mock_api.call_args_list[0][0][2]+ afs = creative_data["asset_feed_spec"]++ assert afs["ad_formats"] == ["SINGLE_IMAGE"]+ assert afs["optimization_type"] == "DEGREES_OF_FREEDOM"+ assert afs["images"] == [{"hash": "hash1"}]++ # Single-image: object_story_spec keeps link_data (error 2061015 without it)assert creative_data["object_story_spec"] == {"page_id": "987654321","link_data": {"link": "https://example.com"}diff --git a/tests/test_flex_creatives.py b/tests/test_flex_creatives.pyindex 23b9f88..d5180ff 100644--- a/tests/test_flex_creatives.py+++ b/tests/test_flex_creatives.py@@ -320,6 +320,10 @@ 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"}+async def test_image_hashes_without_optimization_type_uses_asset_feed(self):"""image_hashes (plural) triggers asset_feed_spec even without optimization_type."""sample_creative_data = {@@ -355,6 +359,9 @@ 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"}+async def test_no_image_hash_or_image_hashes_returns_error(self):"""Must provide either image_hash, image_hashes, or video_id."""result = await create_ad_creative(