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 multi_advertiser_ads and image_crops parameters (#48)

Yves Junqueirac2d0cc1d872c
diff --git a/meta_ads_mcp/__init__.py b/meta_ads_mcp/__init__.py
index 11038cc..14da141 100644
--- a/meta_ads_mcp/__init__.py
+++ b/meta_ads_mcp/__init__.py
@@ -6,7 +6,7 @@ This package provides a Meta Ads MCP integration
from meta_ads_mcp.core.server import main
-__version__ = "1.0.62"
+__version__ = "1.0.63"
__all__ = [
'get_ad_accounts',
diff --git a/meta_ads_mcp/core/ads.py b/meta_ads_mcp/core/ads.py
index f8a98f3..df3a972 100644
--- a/meta_ads_mcp/core/ads.py
+++ b/meta_ads_mcp/core/ads.py
@@ -1126,7 +1126,8 @@ async def create_ad_creative(
creative_features_spec: Optional[Dict[str, Any]] = None,
phone_number: Optional[str] = None,
url_tags: Optional[str] = None,
- caption: Optional[str] = None
+ caption: Optional[str] = None,
+ image_crops: Optional[Dict[str, Any]] = None,
) -> str:
"""
Create a new ad creative using an uploaded image hash or video ID.
@@ -1199,6 +1200,10 @@ async def create_ad_creative(
caption: Display URL shown in the ad (e.g., "example.com/shoes"). Sets the
caption field in link_data. If not provided, Meta auto-generates it
from the destination URL. Only applies to image (link_data) creatives.
+ image_crops: Crop coordinates for different aspect ratios. Applied in link_data for
+ image creatives. Format: {"100x100": [[x1,y1],[x2,y2]], "191x100": [[x1,y1],[x2,y2]]}.
+ Coordinates specify top-left and bottom-right corners of the crop rectangle
+ in the original image's pixel space. Omit to let Meta auto-crop.
asset_customization_rules: Lets you assign different images or videos to specific placement groups
(e.g., feed vs. stories). Only valid with image_hashes or plural asset params.
Each rule uses a user-friendly format that is automatically translated to
@@ -1250,6 +1255,14 @@ async def create_ad_creative(
except (json.JSONDecodeError, TypeError):
pass
+ if isinstance(image_crops, str):
+ try:
+ _parsed = json.loads(image_crops)
+ if isinstance(_parsed, dict):
+ image_crops = _parsed
+ except (json.JSONDecodeError, TypeError):
+ pass
+
for _param_name, _param_val in [
('image_hashes', image_hashes),
('messages', messages),
@@ -1533,6 +1546,8 @@ async def create_ad_creative(
link_data["image_hash"] = image_hashes[0]
if caption:
link_data["caption"] = caption
+ if image_crops:
+ link_data["image_crops"] = image_crops
if call_to_action_type:
cta = {"type": call_to_action_type}
cta_value = {}
@@ -1619,6 +1634,10 @@ async def create_ad_creative(
if caption:
creative_data["object_story_spec"]["link_data"]["caption"] = caption
+ # Add image crops to link_data for placement-specific cropping
+ if image_crops:
+ creative_data["object_story_spec"]["link_data"]["image_crops"] = image_crops
+
# Add call_to_action to link_data for simple creatives
if call_to_action_type:
cta_data = {"type": call_to_action_type}
diff --git a/meta_ads_mcp/core/adsets.py b/meta_ads_mcp/core/adsets.py
index b8b55cb..7448d50 100644
--- a/meta_ads_mcp/core/adsets.py
+++ b/meta_ads_mcp/core/adsets.py
@@ -104,6 +104,7 @@ async def create_adset(
destination_type: Optional[str] = None,
is_dynamic_creative: Optional[bool] = None,
frequency_control_specs: Optional[List[Dict[str, Any]]] = None,
+ multi_advertiser_ads: Optional[int] = None,
access_token: Optional[str] = None
) -> str:
"""
@@ -154,6 +155,8 @@ async def create_adset(
immutable after the ad set is created (error 1815198).
Only works with OUTCOME_AWARENESS campaigns + optimization_goal REACH or THRUPLAY.
Example: [{"event": "IMPRESSIONS", "interval_days": 7, "max_frequency": 1}]
+ multi_advertiser_ads: Set to 0 to opt out of Multi-Advertiser Ads, 1 to opt in.
+ This is a TOP-LEVEL ad set parameter — do NOT put it inside the targeting object.
access_token: Meta API access token (optional - will use cached token if not provided)
"""
# Check required parameters
@@ -354,6 +357,9 @@ async def create_adset(
if frequency_control_specs is not None:
params["frequency_control_specs"] = json.dumps(frequency_control_specs)
+ if multi_advertiser_ads is not None:
+ params["multi_advertiser_ads"] = str(multi_advertiser_ads)
+
try:
data = await make_api_request(endpoint, access_token, params, method="POST")
return json.dumps(data, indent=2)
@@ -402,6 +408,7 @@ async def update_adset(adset_id: str, frequency_control_specs: Optional[List[Dic
end_time: Optional[str] = None,
dsa_beneficiary: Optional[str] = None,
dsa_payor: Optional[str] = None,
+ multi_advertiser_ads: Optional[int] = None,
access_token: Optional[str] = None) -> str:
"""
Update an ad set with new settings including frequency caps and budgets.
@@ -435,6 +442,8 @@ async def update_adset(adset_id: str, frequency_control_specs: Optional[List[Dic
Required for EU-targeted ad sets along with dsa_payor.
dsa_payor: DSA payor for European compliance (person/org paying for the ads).
Required for EU-targeted ad sets along with dsa_beneficiary.
+ multi_advertiser_ads: Set to 0 to opt out of Multi-Advertiser Ads, 1 to opt in.
+ This is a TOP-LEVEL ad set parameter — do NOT put it inside the targeting object.
access_token: Meta API access token (optional - will use cached token if not provided)
"""
if not adset_id:
@@ -533,6 +542,9 @@ async def update_adset(adset_id: str, frequency_control_specs: Optional[List[Dic
if dsa_payor is not None:
params['dsa_payor'] = dsa_payor
+ if multi_advertiser_ads is not None:
+ params['multi_advertiser_ads'] = str(multi_advertiser_ads)
+
if not params:
return json.dumps({"error": "No update parameters provided"}, indent=2)
diff --git a/pyproject.toml b/pyproject.toml
index d6e7032..f8fa8bd 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "meta-ads-mcp"
-version = "1.0.62"
+version = "1.0.63"
description = "Model Context Protocol (MCP) server for Meta Ads - Use Remote MCP at pipeboard.co for easiest setup"
readme = "README.md"
requires-python = ">=3.10"
diff --git a/server.json b/server.json
index 834bbe5..d0128fb 100644
--- a/server.json
+++ b/server.json
@@ -2,7 +2,7 @@
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
"name": "co.pipeboard/meta-ads-mcp",
"description": "Facebook / Meta Ads automation with AI: analyze performance, test creatives, optimize spend.",
- "version": "1.0.62",
+ "version": "1.0.63",
"remotes": [
{
"type": "streamable-http",
diff --git a/tests/test_image_crops.py b/tests/test_image_crops.py
new file mode 100644
index 0000000..4e4ae1b
--- /dev/null
+++ b/tests/test_image_crops.py
@@ -0,0 +1,171 @@
+import json
+import pytest
+from unittest.mock import AsyncMock, patch
+
+from meta_ads_mcp.core.ads import create_ad_creative
+
+
+async def test_simple_creative_includes_image_crops():
+ """image_crops should appear in link_data for simple image creatives."""
+ crops = {"100x100": [[0, 0], [600, 600]]}
+
+ 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_1"},
+ {"id": "creative_1", "name": "Test", "status": "ACTIVE"},
+ ]
+
+ await create_ad_creative(
+ account_id="act_123",
+ image_hash="abc123",
+ name="Crop Test",
+ link_url="https://example.com/",
+ message="Hello",
+ image_crops=crops,
+ access_token="test_token",
+ )
+
+ creative_data = mock_api.call_args_list[0][0][2]
+ link_data = creative_data["object_story_spec"]["link_data"]
+ assert link_data["image_crops"] == crops
+
+
+async def test_dof_creative_includes_image_crops():
+ """image_crops should appear in link_data for DOF/FLEX creatives."""
+ crops = {"191x100": [[0, 0], [1200, 628]]}
+
+ 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_2"},
+ {"id": "creative_2", "name": "DOF Crop", "status": "ACTIVE"},
+ ]
+
+ await create_ad_creative(
+ account_id="act_123",
+ image_hashes=["abc123", "def456"],
+ name="DOF Crop Test",
+ link_url="https://example.com/",
+ messages=["Msg 1", "Msg 2"],
+ optimization_type="DEGREES_OF_FREEDOM",
+ image_crops=crops,
+ access_token="test_token",
+ )
+
+ creative_data = mock_api.call_args_list[0][0][2]
+ link_data = creative_data["object_story_spec"]["link_data"]
+ assert link_data["image_crops"] == crops
+
+
+async def test_simple_creative_omits_image_crops_when_none():
+ """When image_crops is not provided, link_data should not contain it."""
+ 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_3"},
+ {"id": "creative_3", "name": "No Crop", "status": "ACTIVE"},
+ ]
+
+ await create_ad_creative(
+ account_id="act_123",
+ image_hash="abc123",
+ name="No Crop Test",
+ link_url="https://example.com/",
+ message="Hello",
+ access_token="test_token",
+ )
+
+ creative_data = mock_api.call_args_list[0][0][2]
+ link_data = creative_data["object_story_spec"]["link_data"]
+ assert "image_crops" not in link_data
+
+
+async def test_image_crops_json_string_coercion():
+ """image_crops passed as a JSON string should be parsed into a dict."""
+ crops_str = '{"100x100": [[0, 0], [600, 600]]}'
+ expected = {"100x100": [[0, 0], [600, 600]]}
+
+ 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_4"},
+ {"id": "creative_4", "name": "Coerce", "status": "ACTIVE"},
+ ]
+
+ await create_ad_creative(
+ account_id="act_123",
+ image_hash="abc123",
+ name="Coerce Test",
+ link_url="https://example.com/",
+ message="Hello",
+ image_crops=crops_str,
+ access_token="test_token",
+ )
+
+ creative_data = mock_api.call_args_list[0][0][2]
+ link_data = creative_data["object_story_spec"]["link_data"]
+ assert link_data["image_crops"] == expected
+
+
+async def test_image_crops_coexists_with_caption():
+ """image_crops and caption should both appear in link_data."""
+ crops = {"100x100": [[0, 0], [600, 600]]}
+
+ 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_5"},
+ {"id": "creative_5", "name": "Both", "status": "ACTIVE"},
+ ]
+
+ await create_ad_creative(
+ account_id="act_123",
+ image_hash="abc123",
+ name="Both Test",
+ link_url="https://example.com/",
+ message="Hello",
+ caption="example.com/shoes",
+ image_crops=crops,
+ access_token="test_token",
+ )
+
+ creative_data = mock_api.call_args_list[0][0][2]
+ link_data = creative_data["object_story_spec"]["link_data"]
+ assert link_data["caption"] == "example.com/shoes"
+ assert link_data["image_crops"] == crops
diff --git a/tests/test_multi_advertiser_ads.py b/tests/test_multi_advertiser_ads.py
new file mode 100644
index 0000000..af237f0
--- /dev/null
+++ b/tests/test_multi_advertiser_ads.py
@@ -0,0 +1,139 @@
+import json
+import pytest
+from unittest.mock import AsyncMock, patch
+
+from meta_ads_mcp.core.adsets import create_adset, update_adset
+
+
+async def test_create_adset_includes_multi_advertiser_ads_opt_out():
+ """multi_advertiser_ads=0 should be sent as string '0' in POST params."""
+ sample_response = {"id": "adset_1"}
+
+ with patch('meta_ads_mcp.core.adsets.make_api_request', new_callable=AsyncMock) as mock_api:
+ mock_api.return_value = sample_response
+
+ result = await create_adset(
+ account_id="act_123",
+ campaign_id="cmp_1",
+ name="Opt Out Adset",
+ optimization_goal="LINK_CLICKS",
+ billing_event="IMPRESSIONS",
+ targeting={"geo_locations": {"countries": ["US"]}},
+ multi_advertiser_ads=0,
+ access_token="test_token",
+ )
+
+ assert json.loads(result)["id"] == "adset_1"
+ params = mock_api.call_args[0][2]
+ assert params["multi_advertiser_ads"] == "0"
+
+
+async def test_create_adset_includes_multi_advertiser_ads_opt_in():
+ """multi_advertiser_ads=1 should be sent as string '1' in POST params."""
+ sample_response = {"id": "adset_2"}
+
+ with patch('meta_ads_mcp.core.adsets.make_api_request', new_callable=AsyncMock) as mock_api:
+ mock_api.return_value = sample_response
+
+ result = await create_adset(
+ account_id="act_123",
+ campaign_id="cmp_1",
+ name="Opt In Adset",
+ optimization_goal="LINK_CLICKS",
+ billing_event="IMPRESSIONS",
+ targeting={"geo_locations": {"countries": ["US"]}},
+ multi_advertiser_ads=1,
+ access_token="test_token",
+ )
+
+ assert json.loads(result)["id"] == "adset_2"
+ params = mock_api.call_args[0][2]
+ assert params["multi_advertiser_ads"] == "1"
+
+
+async def test_create_adset_omits_multi_advertiser_ads_when_none():
+ """When multi_advertiser_ads is not provided, it should not appear in params."""
+ sample_response = {"id": "adset_3"}
+
+ with patch('meta_ads_mcp.core.adsets.make_api_request', new_callable=AsyncMock) as mock_api:
+ mock_api.return_value = sample_response
+
+ await create_adset(
+ account_id="act_123",
+ campaign_id="cmp_1",
+ name="No Multi Adset",
+ optimization_goal="LINK_CLICKS",
+ billing_event="IMPRESSIONS",
+ targeting={"geo_locations": {"countries": ["US"]}},
+ access_token="test_token",
+ )
+
+ params = mock_api.call_args[0][2]
+ assert "multi_advertiser_ads" not in params
+
+
+async def test_create_adset_multi_advertiser_ads_coexists_with_other_params():
+ """multi_advertiser_ads should coexist with other optional params."""
+ sample_response = {"id": "adset_4"}
+
+ with patch('meta_ads_mcp.core.adsets.make_api_request', new_callable=AsyncMock) as mock_api:
+ mock_api.return_value = sample_response
+
+ await create_adset(
+ account_id="act_123",
+ campaign_id="cmp_1",
+ name="Full Adset",
+ optimization_goal="LINK_CLICKS",
+ billing_event="IMPRESSIONS",
+ daily_budget=5000,
+ targeting={"geo_locations": {"countries": ["US"]}},
+ is_dynamic_creative=False,
+ multi_advertiser_ads=0,
+ access_token="test_token",
+ )
+
+ params = mock_api.call_args[0][2]
+ assert params["multi_advertiser_ads"] == "0"
+ assert params["daily_budget"] == "5000"
+ assert params["is_dynamic_creative"] == "false"
+
+
+async def test_update_adset_includes_multi_advertiser_ads():
+ """update_adset should pass multi_advertiser_ads as string in params."""
+ sample_response = {"success": True}
+
+ with patch('meta_ads_mcp.core.adsets.make_api_request', new_callable=AsyncMock) as mock_api:
+ mock_api.return_value = sample_response
+
+ result = await update_adset(
+ adset_id="120",
+ multi_advertiser_ads=0,
+ access_token="test_token",
+ )
+
+ assert json.loads(result)["success"] is True
+ params = mock_api.call_args[0][2]
+ assert params["multi_advertiser_ads"] == "0"
+
+
+async def test_update_adset_omits_multi_advertiser_ads_when_none():
+ """When multi_advertiser_ads is not provided to update_adset, it should not appear in params."""
+ sample_response = {"success": True}
+
+ with patch('meta_ads_mcp.core.adsets.make_api_request', new_callable=AsyncMock) as mock_api:
+ mock_api.return_value = sample_response
+
+ await update_adset(
+ adset_id="120",
+ name="Renamed",
+ access_token="test_token",
+ )
+
+ params = mock_api.call_args[0][2]
+ assert "multi_advertiser_ads" not in params