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: support description field for video creatives via asset_feed_spec
Yves Junqueira46d741681c21
diff --git a/meta_ads_mcp/__init__.py b/meta_ads_mcp/__init__.pyindex 85cac2e..edbb402 100644--- a/meta_ads_mcp/__init__.py+++ b/meta_ads_mcp/__init__.py@@ -6,7 +6,7 @@ This package provides a Meta Ads MCP integrationfrom meta_ads_mcp.core.server import main-__version__ = "1.0.70"+__version__ = "1.0.74"__all__ = ['get_ad_accounts',diff --git a/meta_ads_mcp/core/ads.py b/meta_ads_mcp/core/ads.pyindex 0ed48d3..735997a 100644--- a/meta_ads_mcp/core/ads.py+++ b/meta_ads_mcp/core/ads.py@@ -1430,7 +1430,12 @@ async def create_ad_creative(# Determine whether to use asset_feed_spec path:# - plural parameters (headlines/descriptions/messages/image_hashes), OR# - optimization_type is set (FLEX creatives always use asset_feed_spec)- use_asset_feed = bool(headlines or descriptions or messages or image_hashes or optimization_type)+ # - video_id + description: Meta's video_data rejects "description" directly,+ # so route through asset_feed_spec which supports descriptions for video ads+ use_asset_feed = bool(+ headlines or descriptions or messages or image_hashes or optimization_type+ or (video_id and description)+ )# Track if this is a video creativeis_video = bool(video_id)diff --git a/tests/test_create_ad_creative_simple.py b/tests/test_create_ad_creative_simple.pyindex b9935c9..9be9e16 100644--- a/tests/test_create_ad_creative_simple.py+++ b/tests/test_create_ad_creative_simple.py@@ -69,9 +69,16 @@ async def test_simple_creative_uses_object_story_spec():assert link_data["image_hash"] == "test_hash_123"assert link_data["link"] == "https://adrocketx.ai/"assert link_data["message"] == "If you're spending 4+ hours per campaign..."-- # The issue: headline and description should be in link_data for simple creatives- # Not in asset_feed_spec++ # Headline and description must be in link_data for simple image creatives+ # (headline as "name", description as "description")+ assert link_data["name"] == "Stop paying yourself $12.50/hour", (+ "headline should appear as link_data.name for simple image creatives"+ )+ assert link_data["description"] == "AI builds campaigns in 3min. 156% higher conversions. Free beta.", (+ "description should appear as link_data.description for simple image creatives"+ )+print("\nlink_data structure:")print(json.dumps(link_data, indent=2))diff --git a/tests/test_duplication.py b/tests/test_duplication.pyindex bef9705..7ed4328 100644--- a/tests/test_duplication.py+++ b/tests/test_duplication.py@@ -75,18 +75,21 @@ async def test_forward_duplication_request_with_both_tokens():mock_response.status_code = 403mock_response.json.return_value = {"error": "premium_feature"}- # Mock the auth integration to return both tokens- with patch("meta_ads_mcp.core.duplication.FastMCPAuthIntegration") as mock_auth:- mock_auth.get_pipeboard_token.return_value = "pipeboard_token"- mock_auth.get_auth_token.return_value = "facebook_token"-- with patch("meta_ads_mcp.core.duplication.httpx.AsyncClient") as mock_client:- mock_client.return_value.__aenter__.return_value.post.return_value = mock_response-- with pytest.raises(DuplicationError) as exc_info:- await _forward_duplication_request("campaign", "123456789", None, {- "name_suffix": " - Test"- })+ # Mock the auth integration to return both tokens.+ # Explicitly unset PIPEBOARD_API_BASE_URL so the default production URL is used;+ # otherwise a dev-env value like http://localhost:4000 would override it.+ with patch.dict("os.environ", {"PIPEBOARD_API_BASE_URL": "https://mcp.pipeboard.co"}):+ with patch("meta_ads_mcp.core.duplication.FastMCPAuthIntegration") as mock_auth:+ mock_auth.get_pipeboard_token.return_value = "pipeboard_token"+ mock_auth.get_auth_token.return_value = "facebook_token"++ with patch("meta_ads_mcp.core.duplication.httpx.AsyncClient") as mock_client:+ mock_client.return_value.__aenter__.return_value.post.return_value = mock_response++ with pytest.raises(DuplicationError) as exc_info:+ await _forward_duplication_request("campaign", "123456789", None, {+ "name_suffix": " - Test"+ })result_json = json.loads(str(exc_info.value))# Should raise with premium feature message for 403 responsediff --git a/tests/test_duplication_regression.py b/tests/test_duplication_regression.pyindex f9e9197..25ebbcf 100644--- a/tests/test_duplication_regression.py+++ b/tests/test_duplication_regression.py@@ -108,11 +108,20 @@ class TestDuplicationDecorators:class TestDuplicationAPIContract:"""Test API contract to prevent regression in external API calls."""-+@pytest.fixture(autouse=True)def enable_feature(self):- """Enable the duplication feature for these tests."""- with patch.dict(os.environ, {"META_ADS_ENABLE_DUPLICATION": "1"}):+ """Enable the duplication feature for these tests.++ Also explicitly set PIPEBOARD_API_BASE_URL to the production default so+ that a dev-environment override (e.g. http://localhost:4000) does not+ cause URL-assertion tests to fail.+ """+ env = {+ "META_ADS_ENABLE_DUPLICATION": "1",+ "PIPEBOARD_API_BASE_URL": "https://mcp.pipeboard.co",+ }+ with patch.dict(os.environ, env):import importlibfrom meta_ads_mcp.core import duplicationimportlib.reload(duplication)diff --git a/tests/test_video_creatives.py b/tests/test_video_creatives.pyindex a10decc..e80fbcf 100644--- a/tests/test_video_creatives.py+++ b/tests/test_video_creatives.py@@ -48,7 +48,8 @@ async def test_simple_video_creative_uses_video_data():link_url="https://example.com/",message="Check out this video",headline="Watch Now",- description="Amazing content",+ # NOTE: no description here — providing description routes to asset_feed_spec;+ # see test_video_creative_with_description for that pathcall_to_action_type="LEARN_MORE",access_token="test_token")@@ -72,8 +73,6 @@ async def test_simple_video_creative_uses_video_data():assert "link" not in video_data, "link must NOT be in video_data directly"assert video_data["message"] == "Check out this video"assert video_data["title"] == "Watch Now"- # description is not settable for simple video creatives (Meta API v24- # rejects it in both video_data and call_to_action.value)assert "description" not in video_dataassert video_data["call_to_action"]["type"] == "LEARN_MORE"assert video_data["call_to_action"]["value"]["link"] == "https://example.com/"@@ -410,3 +409,113 @@ async def test_image_creative_still_works():# instagram_actor_id at top level for image creativesassert "instagram_actor_id" not in creative_data+++async def test_video_creative_with_description():+ """Test that video_id + description routes through asset_feed_spec (not video_data).++ Meta API v24 rejects 'description' inside video_data. To support descriptions+ for video ads, we route to asset_feed_spec when video_id + description is given.+ """++ with patch('meta_ads_mcp.core.ads.make_api_request') as mock_api, \+ patch('meta_ads_mcp.core.ads._discover_pages_for_account') as mock_discover:++ mock_discover.return_value = {+ "success": True,+ "page_id": "123456789",+ "page_name": "Test Page"+ }++ mock_api.side_effect = [+ # 1) Auto-fetch video thumbnail+ {"picture": "https://example.com/auto-thumb.jpg"},+ # 2) POST create creative+ {"id": "creative_vid_desc"},+ # 3) GET creative details+ {"id": "creative_vid_desc", "name": "Video With Desc", "status": "ACTIVE"}+ ]++ result = await create_ad_creative(+ account_id="act_123456",+ video_id="vid_desc_test",+ name="Video With Description",+ link_url="https://example.com/",+ message="Primary text for the ad",+ headline="Watch Now",+ description="The text below the headline in feed placements",+ call_to_action_type="LEARN_MORE",+ access_token="test_token"+ )++ assert mock_api.call_count == 3++ creative_data = mock_api.call_args_list[1][0][2]++ # Should use asset_feed_spec (not simple video_data path), because+ # video_data does not support description+ assert "asset_feed_spec" in creative_data, (+ "video + description should use asset_feed_spec so description is sent to Meta"+ )++ afs = creative_data["asset_feed_spec"]++ # Description should be in asset_feed_spec.descriptions+ assert "descriptions" in afs, "description should appear in asset_feed_spec.descriptions"+ assert afs["descriptions"] == [{"text": "The text below the headline in feed placements"}]++ # Other fields should also be present+ assert afs["bodies"] == [{"text": "Primary text for the ad"}]+ assert afs["titles"] == [{"text": "Watch Now"}]+ assert "videos" in afs+ assert afs["videos"][0]["video_id"] == "vid_desc_test"++ # object_story_spec should use video_data as the anchor (not link_data)+ assert "video_data" in creative_data["object_story_spec"]+ assert "link_data" not in creative_data["object_story_spec"]++ # description must NOT be in video_data (Meta API v24 rejects it there)+ video_data = creative_data["object_story_spec"]["video_data"]+ assert "description" not in video_data+++async def test_video_creative_description_only():+ """Test that video_id + description alone (no other plural params) still works."""++ with patch('meta_ads_mcp.core.ads.make_api_request') as mock_api, \+ patch('meta_ads_mcp.core.ads._discover_pages_for_account') as mock_discover:++ mock_discover.return_value = {+ "success": True,+ "page_id": "123456789",+ "page_name": "Test Page"+ }++ mock_api.side_effect = [+ # 1) Auto-fetch video thumbnail+ {"picture": "https://example.com/auto-thumb.jpg"},+ # 2) POST create creative+ {"id": "creative_vid_desc2"},+ # 3) GET creative details+ {"id": "creative_vid_desc2", "name": "Video Desc Only", "status": "ACTIVE"}+ ]++ result = await create_ad_creative(+ account_id="act_123456",+ video_id="vid_desc_only",+ name="Video Description Only",+ link_url="https://example.com/",+ description="Only description, no other plural params",+ access_token="test_token"+ )++ assert mock_api.call_count == 3++ creative_data = mock_api.call_args_list[1][0][2]++ assert "asset_feed_spec" in creative_data+ afs = creative_data["asset_feed_spec"]+ assert afs["descriptions"] == [{"text": "Only description, no other plural params"}]+ assert "videos" in afs