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: add phone_number parameter to create_ad_creative for CALL_NOW CTAs

Yves Junqueirad10918f962e7
diff --git a/meta_ads_mcp/core/ads.py b/meta_ads_mcp/core/ads.py
index 12980e6..8ba9fdf 100644
--- a/meta_ads_mcp/core/ads.py
+++ b/meta_ads_mcp/core/ads.py
@@ -1086,7 +1086,8 @@ async def create_ad_creative(
instagram_actor_id: Optional[str] = None,
ad_formats: Optional[List[str]] = None,
asset_customization_rules: Optional[List[Dict[str, Any]]] = None,
- creative_features_spec: Optional[Dict[str, Any]] = None
+ creative_features_spec: Optional[Dict[str, Any]] = None,
+ phone_number: Optional[str] = None
) -> str:
"""
Create a new ad creative using an uploaded image hash or video ID.
@@ -1120,7 +1121,8 @@ async def create_ad_creative(
DEGREES_OF_FREEDOM, at least one asset field (image_hashes, messages,
headlines, or descriptions) must contain more than one variant.
dynamic_creative_spec: Dynamic creative optimization settings
- call_to_action_type: Call to action button type (e.g., 'LEARN_MORE', 'SIGN_UP', 'SHOP_NOW')
+ call_to_action_type: Call to action button type (e.g., 'LEARN_MORE', 'SIGN_UP', 'SHOP_NOW',
+ 'CALL_NOW'). When using CALL_NOW, also provide phone_number.
lead_gen_form_id: Lead generation form ID for lead generation campaigns. Required when using
lead generation CTAs like 'SIGN_UP', 'GET_OFFER', 'SUBSCRIBE', etc.
instagram_actor_id: Optional Instagram account ID for Instagram placements.
@@ -1132,6 +1134,11 @@ async def create_ad_creative(
["AUTOMATIC_FORMAT"] (Flexible format). For video creatives, defaults to
["SINGLE_VIDEO"]. Otherwise defaults to ["SINGLE_IMAGE"].
asset_customization_rules: List of placement-specific asset overrides for asset_feed_spec.
+ phone_number: Phone number for CALL_NOW call-to-action ads (click-to-call).
+ Required when call_to_action_type is CALL_NOW. Use E.164 format
+ (e.g., "+18005551234"). The number is passed to Meta in
+ call_to_action.value.phone_number. Common use case: geo-routed
+ call ads with different phone numbers per ad set.
creative_features_spec: Advantage+ Creative feature opt-ins/opt-outs. Controls individual
creative enhancements like image_touchups, text_optimizations, inline_comment,
add_text_overlay, music, 3d_animation, etc. Each feature is a dict with
@@ -1439,6 +1446,8 @@ async def create_ad_creative(
cta_value["link"] = link_url
if lead_gen_form_id:
cta_value["lead_gen_form_id"] = lead_gen_form_id
+ if phone_number:
+ cta_value["phone_number"] = phone_number
cta_data = {"type": cta_type}
if cta_value:
cta_data["value"] = cta_value
@@ -1460,6 +1469,8 @@ async def create_ad_creative(
cta_value["link"] = link_url
if lead_gen_form_id:
cta_value["lead_gen_form_id"] = lead_gen_form_id
+ if phone_number:
+ cta_value["phone_number"] = phone_number
if cta_value:
cta["value"] = cta_value
link_data["call_to_action"] = cta
@@ -1498,6 +1509,8 @@ async def create_ad_creative(
cta_value["link"] = link_url
if lead_gen_form_id:
cta_value["lead_gen_form_id"] = lead_gen_form_id
+ if phone_number:
+ cta_value["phone_number"] = phone_number
cta_type = call_to_action_type or ("LEARN_MORE" if link_url else None)
if cta_type:
cta_data = {"type": cta_type}
@@ -1534,10 +1547,15 @@ async def create_ad_creative(
# Add call_to_action to link_data for simple creatives
if call_to_action_type:
cta_data = {"type": call_to_action_type}
+ cta_value = {}
# Add lead form ID to value object if provided (required for lead generation campaigns)
if lead_gen_form_id:
- cta_data["value"] = {"lead_gen_form_id": lead_gen_form_id}
+ cta_value["lead_gen_form_id"] = lead_gen_form_id
+ if phone_number:
+ cta_value["phone_number"] = phone_number
+ if cta_value:
+ cta_data["value"] = cta_value
creative_data["object_story_spec"]["link_data"]["call_to_action"] = cta_data
diff --git a/tests/test_call_now_phone_number.py b/tests/test_call_now_phone_number.py
new file mode 100644
index 0000000..8e9f8ed
--- /dev/null
+++ b/tests/test_call_now_phone_number.py
@@ -0,0 +1,183 @@
+"""Test that create_ad_creative passes phone_number for CALL_NOW CTAs."""
+
+import pytest
+import json
+from unittest.mock import patch
+from meta_ads_mcp.core.ads import create_ad_creative
+
+
+async def test_simple_image_call_now_includes_phone_number():
+ """Simple image creative with CALL_NOW should include phone_number in CTA value."""
+
+ 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 = [
+ {"id": "creative_123"},
+ {"id": "creative_123", "name": "Test Creative", "status": "ACTIVE"}
+ ]
+
+ result = await create_ad_creative(
+ account_id="act_701351919139047",
+ image_hash="test_hash_123",
+ name="Plumbing Call Ad",
+ link_url="https://facebook.com/105246524341910/",
+ message="Need a plumber? Call now!",
+ headline="Call Now",
+ call_to_action_type="CALL_NOW",
+ phone_number="+18005551234",
+ access_token="test_token"
+ )
+
+ create_call_args = mock_api.call_args_list[0]
+ creative_data = create_call_args[0][2]
+
+ # Verify object_story_spec with link_data
+ assert "object_story_spec" in creative_data
+ link_data = creative_data["object_story_spec"]["link_data"]
+ assert "call_to_action" in link_data
+
+ cta = link_data["call_to_action"]
+ assert cta["type"] == "CALL_NOW"
+ assert "value" in cta
+ assert cta["value"]["phone_number"] == "+18005551234"
+
+
+async def test_simple_image_without_phone_number_has_no_phone_in_cta():
+ """Simple image creative with LEARN_MORE should NOT include phone_number."""
+
+ 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 = [
+ {"id": "creative_456"},
+ {"id": "creative_456", "name": "Test Creative", "status": "ACTIVE"}
+ ]
+
+ result = await create_ad_creative(
+ account_id="act_701351919139047",
+ image_hash="test_hash_456",
+ name="Regular Ad",
+ link_url="https://example.com/",
+ message="Learn more about us",
+ headline="Learn More",
+ call_to_action_type="LEARN_MORE",
+ access_token="test_token"
+ )
+
+ create_call_args = mock_api.call_args_list[0]
+ creative_data = create_call_args[0][2]
+
+ link_data = creative_data["object_story_spec"]["link_data"]
+ cta = link_data["call_to_action"]
+ assert cta["type"] == "LEARN_MORE"
+ # No phone_number should be in value (value might not exist at all, or
+ # if it does, should not have phone_number)
+ if "value" in cta:
+ assert "phone_number" not in cta["value"]
+
+
+async def test_dof_image_call_now_includes_phone_number():
+ """DOF (DEGREES_OF_FREEDOM) image creative with CALL_NOW should include phone_number."""
+
+ 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 = [
+ {"id": "creative_789"},
+ {"id": "creative_789", "name": "DOF Creative", "status": "ACTIVE"}
+ ]
+
+ result = await create_ad_creative(
+ account_id="act_701351919139047",
+ image_hashes=["hash_a"],
+ name="Plumbing DOF Call Ad",
+ link_url="https://facebook.com/105246524341910/",
+ messages=["Need a plumber? Call now!"],
+ headlines=["Call Now"],
+ call_to_action_type="CALL_NOW",
+ optimization_type="DEGREES_OF_FREEDOM",
+ phone_number="+18005551234",
+ access_token="test_token"
+ )
+
+ create_call_args = mock_api.call_args_list[0]
+ creative_data = create_call_args[0][2]
+
+ # DOF puts CTA in link_data
+ assert "object_story_spec" in creative_data
+ link_data = creative_data["object_story_spec"]["link_data"]
+ assert "call_to_action" in link_data
+
+ cta = link_data["call_to_action"]
+ assert cta["type"] == "CALL_NOW"
+ assert cta["value"]["phone_number"] == "+18005551234"
+
+
+async def test_simple_video_call_now_includes_phone_number():
+ """Simple video creative with CALL_NOW should include phone_number in CTA value."""
+
+ 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 = [
+ # First call: fetch video thumbnail (picture field)
+ {"picture": "https://example.com/thumb.jpg"},
+ # Second call: create creative
+ {"id": "creative_vid1"},
+ # Third call: get creative details
+ {"id": "creative_vid1", "name": "Video Call Ad", "status": "ACTIVE"}
+ ]
+
+ result = await create_ad_creative(
+ account_id="act_701351919139047",
+ video_id="video_123",
+ name="Plumbing Video Call Ad",
+ link_url="https://facebook.com/105246524341910/",
+ message="Need a plumber? Call now!",
+ headline="Call Now",
+ call_to_action_type="CALL_NOW",
+ phone_number="+18005551234",
+ access_token="test_token"
+ )
+
+ # Index 1 because index 0 is the video thumbnail fetch
+ create_call_args = mock_api.call_args_list[1]
+ creative_data = create_call_args[0][2]
+
+ # Simple video uses video_data
+ assert "object_story_spec" in creative_data
+ video_data = creative_data["object_story_spec"]["video_data"]
+ assert "call_to_action" in video_data
+
+ cta = video_data["call_to_action"]
+ assert cta["type"] == "CALL_NOW"
+ assert cta["value"]["phone_number"] == "+18005551234"