meta-ads-mcp 0.7.7__tar.gz → 0.7.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/PKG-INFO +1 -1
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/__init__.py +1 -1
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/accounts.py +40 -11
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/auth.py +38 -2
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/pipeboard_auth.py +43 -1
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/pyproject.toml +1 -1
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_dsa_beneficiary.py +69 -5
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_dsa_integration.py +88 -19
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/.github/workflows/publish.yml +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/.github/workflows/test.yml +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/.gitignore +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/CUSTOM_META_APP.md +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/Dockerfile +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/LICENSE +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/LOCAL_INSTALLATION.md +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/META_API_NOTES.md +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/README.md +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/RELEASE.md +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/STREAMABLE_HTTP_SETUP.md +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/examples/README.md +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/examples/example_http_client.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/future_improvements.md +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/images/meta-ads-example.png +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_auth.sh +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/__main__.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/__init__.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/ads.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/ads_library.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/adsets.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/api.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/authentication.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/budget_schedules.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/callback_server.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/campaigns.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/duplication.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/http_auth_integration.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/insights.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/openai_deep_research.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/reports.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/resources.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/server.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/targeting.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/meta_ads_mcp/core/utils.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/requirements.txt +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/setup.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/smithery.yaml +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/README.md +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/README_REGRESSION_TESTS.md +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/__init__.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/conftest.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_account_search.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_budget_update.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_budget_update_e2e.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_duplication.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_duplication_regression.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_get_ad_creatives_fix.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_get_ad_image_regression.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_http_transport.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_insights_actions_and_values.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_integration_openai_mcp.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_openai.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_openai_mcp_deep_research.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_targeting.py +0 -0
- {meta_ads_mcp-0.7.7 → meta_ads_mcp-0.7.8}/tests/test_targeting_search_e2e.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: meta-ads-mcp
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.8
|
|
4
4
|
Summary: Model Context Protocol (MCP) plugin for interacting with Meta Ads API
|
|
5
5
|
Project-URL: Homepage, https://github.com/pipeboard-co/meta-ads-mcp
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/pipeboard-co/meta-ads-mcp/issues
|
|
@@ -36,29 +36,58 @@ async def get_account_info(access_token: str = None, account_id: str = None) ->
|
|
|
36
36
|
|
|
37
37
|
Args:
|
|
38
38
|
access_token: Meta API access token (optional - will use cached token if not provided)
|
|
39
|
-
account_id: Meta Ads account ID (format: act_XXXXXXXXX)
|
|
39
|
+
account_id: Meta Ads account ID (format: act_XXXXXXXXX) - REQUIRED
|
|
40
40
|
"""
|
|
41
|
-
# If no account ID is specified, try to get the first one for the user
|
|
42
41
|
if not account_id:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
return {
|
|
43
|
+
"error": {
|
|
44
|
+
"message": "Account ID is required",
|
|
45
|
+
"details": "Please specify an account_id parameter",
|
|
46
|
+
"example": "Use account_id='act_123456789' or account_id='123456789'"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
50
49
|
|
|
51
50
|
# Ensure account_id has the 'act_' prefix for API compatibility
|
|
52
51
|
if not account_id.startswith("act_"):
|
|
53
52
|
account_id = f"act_{account_id}"
|
|
54
53
|
|
|
54
|
+
# First, check if the account is accessible to the user
|
|
55
|
+
endpoint = "me/adaccounts"
|
|
56
|
+
params = {
|
|
57
|
+
"fields": "id,name,account_id,account_status,amount_spent,balance,currency,age,business_city,business_country_code",
|
|
58
|
+
"limit": 50
|
|
59
|
+
}
|
|
60
|
+
accessible_accounts_data = await make_api_request(endpoint, access_token, params)
|
|
61
|
+
|
|
62
|
+
if "data" in accessible_accounts_data:
|
|
63
|
+
accessible_account_ids = [acc["id"] for acc in accessible_accounts_data["data"]]
|
|
64
|
+
if account_id not in accessible_account_ids:
|
|
65
|
+
# Provide a helpful error message with accessible accounts
|
|
66
|
+
accessible_accounts = [
|
|
67
|
+
{"id": acc["id"], "name": acc["name"]}
|
|
68
|
+
for acc in accessible_accounts_data["data"][:10] # Show first 10
|
|
69
|
+
]
|
|
70
|
+
return {
|
|
71
|
+
"error": {
|
|
72
|
+
"message": f"Account {account_id} is not accessible to your user account",
|
|
73
|
+
"details": "This account either doesn't exist or you don't have permission to access it",
|
|
74
|
+
"accessible_accounts": accessible_accounts,
|
|
75
|
+
"total_accessible_accounts": len(accessible_accounts_data["data"]),
|
|
76
|
+
"suggestion": "Try using one of the accessible account IDs listed above"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
55
80
|
endpoint = f"{account_id}"
|
|
56
81
|
params = {
|
|
57
|
-
"fields": "id,name,account_id,account_status,amount_spent,balance,currency,age,
|
|
82
|
+
"fields": "id,name,account_id,account_status,amount_spent,balance,currency,age,business_city,business_country_code,timezone_name"
|
|
58
83
|
}
|
|
59
84
|
|
|
60
85
|
data = await make_api_request(endpoint, access_token, params)
|
|
61
86
|
|
|
87
|
+
# Check if the API request returned an error
|
|
88
|
+
if "error" in data:
|
|
89
|
+
return data
|
|
90
|
+
|
|
62
91
|
# Add DSA requirement detection
|
|
63
92
|
if "business_country_code" in data:
|
|
64
93
|
european_countries = ["DE", "FR", "IT", "ES", "NL", "BE", "AT", "IE", "DK", "SE", "FI", "NO"]
|
|
@@ -69,4 +98,4 @@ async def get_account_info(access_token: str = None, account_id: str = None) ->
|
|
|
69
98
|
data["dsa_required"] = False
|
|
70
99
|
data["dsa_compliance_note"] = "This account is not subject to European DSA requirements"
|
|
71
100
|
|
|
72
|
-
return
|
|
101
|
+
return data
|
|
@@ -25,7 +25,7 @@ from .pipeboard_auth import pipeboard_auth_manager
|
|
|
25
25
|
# Auth constants
|
|
26
26
|
# Scope includes pages_show_list and pages_read_engagement to fix issue #16
|
|
27
27
|
# where get_account_pages failed for regular users due to missing page permissions
|
|
28
|
-
AUTH_SCOPE = "
|
|
28
|
+
AUTH_SCOPE = "business_management,public_profile,pages_show_list,pages_read_engagement"
|
|
29
29
|
AUTH_REDIRECT_URI = "http://localhost:8888/callback"
|
|
30
30
|
AUTH_RESPONSE_TYPE = "token"
|
|
31
31
|
|
|
@@ -159,11 +159,41 @@ class AuthManager:
|
|
|
159
159
|
try:
|
|
160
160
|
with open(cache_path, "r") as f:
|
|
161
161
|
data = json.load(f)
|
|
162
|
+
|
|
163
|
+
# Validate the cached data structure
|
|
164
|
+
required_fields = ["access_token", "created_at"]
|
|
165
|
+
if not all(field in data for field in required_fields):
|
|
166
|
+
logger.warning("Cached token data is missing required fields")
|
|
167
|
+
return False
|
|
168
|
+
|
|
169
|
+
# Check if the token looks valid (basic format check)
|
|
170
|
+
if not data.get("access_token") or len(data["access_token"]) < 20:
|
|
171
|
+
logger.warning("Cached token appears malformed")
|
|
172
|
+
return False
|
|
173
|
+
|
|
162
174
|
self.token_info = TokenInfo.deserialize(data)
|
|
163
175
|
|
|
164
176
|
# Check if token is expired
|
|
165
177
|
if self.token_info.is_expired():
|
|
166
|
-
logger.info("Cached token is expired")
|
|
178
|
+
logger.info("Cached token is expired, removing cache file")
|
|
179
|
+
# Remove the expired cache file
|
|
180
|
+
try:
|
|
181
|
+
cache_path.unlink()
|
|
182
|
+
logger.info(f"Removed expired token cache: {cache_path}")
|
|
183
|
+
except Exception as e:
|
|
184
|
+
logger.warning(f"Could not remove expired cache file: {e}")
|
|
185
|
+
self.token_info = None
|
|
186
|
+
return False
|
|
187
|
+
|
|
188
|
+
# Additional validation: check if token is too old (more than 60 days)
|
|
189
|
+
current_time = int(time.time())
|
|
190
|
+
if self.token_info.created_at and (current_time - self.token_info.created_at) > (60 * 24 * 3600):
|
|
191
|
+
logger.warning("Cached token is too old (more than 60 days), removing cache file")
|
|
192
|
+
try:
|
|
193
|
+
cache_path.unlink()
|
|
194
|
+
logger.info(f"Removed old token cache: {cache_path}")
|
|
195
|
+
except Exception as e:
|
|
196
|
+
logger.warning(f"Could not remove old cache file: {e}")
|
|
167
197
|
self.token_info = None
|
|
168
198
|
return False
|
|
169
199
|
|
|
@@ -171,6 +201,12 @@ class AuthManager:
|
|
|
171
201
|
return True
|
|
172
202
|
except Exception as e:
|
|
173
203
|
logger.error(f"Error loading cached token: {e}")
|
|
204
|
+
# If there's any error reading the cache, try to remove the corrupted file
|
|
205
|
+
try:
|
|
206
|
+
cache_path.unlink()
|
|
207
|
+
logger.info(f"Removed corrupted token cache: {cache_path}")
|
|
208
|
+
except Exception as cleanup_error:
|
|
209
|
+
logger.warning(f"Could not remove corrupted cache file: {cleanup_error}")
|
|
174
210
|
return False
|
|
175
211
|
|
|
176
212
|
def _save_token_to_cache(self) -> None:
|
|
@@ -151,6 +151,18 @@ class PipeboardAuthManager:
|
|
|
151
151
|
with open(cache_path, "r") as f:
|
|
152
152
|
logger.debug(f"Reading token cache from {cache_path}")
|
|
153
153
|
data = json.load(f)
|
|
154
|
+
|
|
155
|
+
# Validate the cached data structure
|
|
156
|
+
required_fields = ["access_token"]
|
|
157
|
+
if not all(field in data for field in required_fields):
|
|
158
|
+
logger.warning("Cached token data is missing required fields")
|
|
159
|
+
return False
|
|
160
|
+
|
|
161
|
+
# Check if the token looks valid (basic format check)
|
|
162
|
+
if not data.get("access_token") or len(data["access_token"]) < 20:
|
|
163
|
+
logger.warning("Cached token appears malformed")
|
|
164
|
+
return False
|
|
165
|
+
|
|
154
166
|
self.token_info = TokenInfo.deserialize(data)
|
|
155
167
|
|
|
156
168
|
# Log token details (partial token for security)
|
|
@@ -159,7 +171,25 @@ class PipeboardAuthManager:
|
|
|
159
171
|
|
|
160
172
|
# Check if token is expired
|
|
161
173
|
if self.token_info.is_expired():
|
|
162
|
-
logger.info("Cached token is expired")
|
|
174
|
+
logger.info("Cached token is expired, removing cache file")
|
|
175
|
+
# Remove the expired cache file
|
|
176
|
+
try:
|
|
177
|
+
cache_path.unlink()
|
|
178
|
+
logger.info(f"Removed expired token cache: {cache_path}")
|
|
179
|
+
except Exception as e:
|
|
180
|
+
logger.warning(f"Could not remove expired cache file: {e}")
|
|
181
|
+
self.token_info = None
|
|
182
|
+
return False
|
|
183
|
+
|
|
184
|
+
# Additional validation: check if token is too old (more than 60 days)
|
|
185
|
+
current_time = int(time.time())
|
|
186
|
+
if self.token_info.created_at and (current_time - self.token_info.created_at) > (60 * 24 * 3600):
|
|
187
|
+
logger.warning("Cached token is too old (more than 60 days), removing cache file")
|
|
188
|
+
try:
|
|
189
|
+
cache_path.unlink()
|
|
190
|
+
logger.info(f"Removed old token cache: {cache_path}")
|
|
191
|
+
except Exception as e:
|
|
192
|
+
logger.warning(f"Could not remove old cache file: {e}")
|
|
163
193
|
self.token_info = None
|
|
164
194
|
return False
|
|
165
195
|
|
|
@@ -174,9 +204,21 @@ class PipeboardAuthManager:
|
|
|
174
204
|
logger.debug(f"Raw cache file content (first 100 chars): {raw_content[:100]}")
|
|
175
205
|
except Exception as e2:
|
|
176
206
|
logger.error(f"Could not read raw cache file: {e2}")
|
|
207
|
+
# If there's any error reading the cache, try to remove the corrupted file
|
|
208
|
+
try:
|
|
209
|
+
cache_path.unlink()
|
|
210
|
+
logger.info(f"Removed corrupted token cache: {cache_path}")
|
|
211
|
+
except Exception as cleanup_error:
|
|
212
|
+
logger.warning(f"Could not remove corrupted cache file: {cleanup_error}")
|
|
177
213
|
return False
|
|
178
214
|
except Exception as e:
|
|
179
215
|
logger.error(f"Error loading cached token: {e}")
|
|
216
|
+
# If there's any error reading the cache, try to remove the corrupted file
|
|
217
|
+
try:
|
|
218
|
+
cache_path.unlink()
|
|
219
|
+
logger.info(f"Removed corrupted token cache: {cache_path}")
|
|
220
|
+
except Exception as cleanup_error:
|
|
221
|
+
logger.warning(f"Could not remove corrupted cache file: {cleanup_error}")
|
|
180
222
|
return False
|
|
181
223
|
|
|
182
224
|
def _save_token_to_cache(self) -> None:
|
|
@@ -19,10 +19,10 @@ class TestDSABeneficiaryDetection:
|
|
|
19
19
|
|
|
20
20
|
@pytest.mark.asyncio
|
|
21
21
|
async def test_dsa_requirement_detection_business_account(self):
|
|
22
|
-
"""Test
|
|
22
|
+
"""Test DSA requirement detection for European business accounts"""
|
|
23
23
|
mock_account_response = {
|
|
24
24
|
"id": "act_701351919139047",
|
|
25
|
-
"name": "Test Business Account",
|
|
25
|
+
"name": "Test European Business Account",
|
|
26
26
|
"account_status": 1,
|
|
27
27
|
"business_country_code": "DE", # Germany - DSA compliant
|
|
28
28
|
"business_city": "Berlin",
|
|
@@ -35,7 +35,12 @@ class TestDSABeneficiaryDetection:
|
|
|
35
35
|
mock_api.return_value = mock_account_response
|
|
36
36
|
|
|
37
37
|
result = await get_account_info(account_id="act_701351919139047")
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
# Handle new return format (dictionary instead of JSON string)
|
|
40
|
+
if isinstance(result, dict):
|
|
41
|
+
result_data = result
|
|
42
|
+
else:
|
|
43
|
+
result_data = json.loads(result)
|
|
39
44
|
|
|
40
45
|
# Verify account info is retrieved
|
|
41
46
|
assert result_data["id"] == "act_701351919139047"
|
|
@@ -62,7 +67,12 @@ class TestDSABeneficiaryDetection:
|
|
|
62
67
|
mock_api.return_value = mock_account_response
|
|
63
68
|
|
|
64
69
|
result = await get_account_info(account_id="act_123456789")
|
|
65
|
-
|
|
70
|
+
|
|
71
|
+
# Handle new return format (dictionary instead of JSON string)
|
|
72
|
+
if isinstance(result, dict):
|
|
73
|
+
result_data = result
|
|
74
|
+
else:
|
|
75
|
+
result_data = json.loads(result)
|
|
66
76
|
|
|
67
77
|
# Verify no DSA requirement for US accounts
|
|
68
78
|
assert result_data["business_country_code"] == "US"
|
|
@@ -77,7 +87,7 @@ class TestDSABeneficiaryDetection:
|
|
|
77
87
|
|
|
78
88
|
result = await get_account_info(account_id="act_invalid")
|
|
79
89
|
|
|
80
|
-
# Handle
|
|
90
|
+
# Handle new return format (dictionary instead of JSON string)
|
|
81
91
|
if isinstance(result, dict):
|
|
82
92
|
result_data = result
|
|
83
93
|
else:
|
|
@@ -85,6 +95,60 @@ class TestDSABeneficiaryDetection:
|
|
|
85
95
|
|
|
86
96
|
# Verify error is properly handled
|
|
87
97
|
assert "error" in result_data
|
|
98
|
+
|
|
99
|
+
@pytest.mark.asyncio
|
|
100
|
+
async def test_account_info_requires_account_id(self):
|
|
101
|
+
"""Test that get_account_info requires an account_id parameter"""
|
|
102
|
+
|
|
103
|
+
with patch('meta_ads_mcp.core.api.get_current_access_token', new_callable=AsyncMock) as mock_auth:
|
|
104
|
+
mock_auth.return_value = "test_access_token"
|
|
105
|
+
|
|
106
|
+
# Test without account_id parameter
|
|
107
|
+
result = await get_account_info()
|
|
108
|
+
|
|
109
|
+
# Handle new return format (dictionary instead of JSON string)
|
|
110
|
+
if isinstance(result, dict):
|
|
111
|
+
result_data = result
|
|
112
|
+
else:
|
|
113
|
+
result_data = json.loads(result)
|
|
114
|
+
|
|
115
|
+
# Verify error message for missing account_id
|
|
116
|
+
assert "error" in result_data
|
|
117
|
+
assert "Account ID is required" in result_data["error"]["message"]
|
|
118
|
+
assert "Please specify an account_id parameter" in result_data["error"]["details"]
|
|
119
|
+
assert "example" in result_data["error"]
|
|
120
|
+
|
|
121
|
+
@pytest.mark.asyncio
|
|
122
|
+
async def test_account_info_inaccessible_account_error(self):
|
|
123
|
+
"""Test that get_account_info provides helpful error for inaccessible accounts"""
|
|
124
|
+
|
|
125
|
+
# Mock accessible accounts response
|
|
126
|
+
mock_accessible_accounts = {
|
|
127
|
+
"data": [
|
|
128
|
+
{"id": "act_123", "name": "Test Account 1"},
|
|
129
|
+
{"id": "act_456", "name": "Test Account 2"}
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
with patch('meta_ads_mcp.core.accounts.make_api_request', new_callable=AsyncMock) as mock_api:
|
|
134
|
+
with patch('meta_ads_mcp.core.api.get_current_access_token', new_callable=AsyncMock) as mock_auth:
|
|
135
|
+
mock_auth.return_value = "test_access_token"
|
|
136
|
+
mock_api.return_value = mock_accessible_accounts
|
|
137
|
+
|
|
138
|
+
result = await get_account_info(account_id="act_inaccessible")
|
|
139
|
+
|
|
140
|
+
# Handle new return format (dictionary instead of JSON string)
|
|
141
|
+
if isinstance(result, dict):
|
|
142
|
+
result_data = result
|
|
143
|
+
else:
|
|
144
|
+
result_data = json.loads(result)
|
|
145
|
+
|
|
146
|
+
# Verify helpful error message for inaccessible account
|
|
147
|
+
assert "error" in result_data
|
|
148
|
+
assert "not accessible to your user account" in result_data["error"]["message"]
|
|
149
|
+
assert "accessible_accounts" in result_data["error"]
|
|
150
|
+
assert "suggestion" in result_data["error"]
|
|
151
|
+
assert len(result_data["error"]["accessible_accounts"]) == 2
|
|
88
152
|
|
|
89
153
|
|
|
90
154
|
class TestDSABeneficiaryParameter:
|
|
@@ -19,12 +19,12 @@ class TestDSAIntegration:
|
|
|
19
19
|
|
|
20
20
|
@pytest.mark.asyncio
|
|
21
21
|
async def test_dsa_beneficiary_complete_workflow(self):
|
|
22
|
-
"""Test complete DSA beneficiary workflow from detection to creation"""
|
|
22
|
+
"""Test complete DSA beneficiary workflow from account detection to ad set creation"""
|
|
23
23
|
|
|
24
|
-
# Step 1:
|
|
24
|
+
# Step 1: Get account info and detect DSA requirement
|
|
25
25
|
mock_account_response = {
|
|
26
26
|
"id": "act_701351919139047",
|
|
27
|
-
"name": "Test European
|
|
27
|
+
"name": "Test European Account",
|
|
28
28
|
"account_status": 1,
|
|
29
29
|
"business_country_code": "DE", # Germany - DSA compliant
|
|
30
30
|
"business_city": "Berlin",
|
|
@@ -38,7 +38,12 @@ class TestDSAIntegration:
|
|
|
38
38
|
|
|
39
39
|
# Get account info and verify DSA detection
|
|
40
40
|
result = await get_account_info(account_id="act_701351919139047")
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
# Handle new return format (dictionary instead of JSON string)
|
|
43
|
+
if isinstance(result, dict):
|
|
44
|
+
result_data = result
|
|
45
|
+
else:
|
|
46
|
+
result_data = json.loads(result)
|
|
42
47
|
|
|
43
48
|
# Verify DSA requirement is detected
|
|
44
49
|
assert result_data["business_country_code"] == "DE"
|
|
@@ -151,43 +156,53 @@ class TestDSAIntegration:
|
|
|
151
156
|
async def test_dsa_beneficiary_regional_compliance_integration(self):
|
|
152
157
|
"""Test DSA beneficiary compliance across different regions"""
|
|
153
158
|
|
|
154
|
-
# Test European account (DSA required)
|
|
155
|
-
|
|
159
|
+
# Test 1: European account (DSA required)
|
|
160
|
+
mock_de_account_response = {
|
|
156
161
|
"id": "act_de",
|
|
157
|
-
"name": "German
|
|
162
|
+
"name": "German Account",
|
|
158
163
|
"business_country_code": "DE",
|
|
159
|
-
"
|
|
164
|
+
"currency": "EUR"
|
|
160
165
|
}
|
|
161
166
|
|
|
162
167
|
with patch('meta_ads_mcp.core.accounts.make_api_request', new_callable=AsyncMock) as mock_api:
|
|
163
168
|
with patch('meta_ads_mcp.core.api.get_current_access_token', new_callable=AsyncMock) as mock_auth:
|
|
164
169
|
mock_auth.return_value = "test_access_token"
|
|
165
|
-
mock_api.return_value =
|
|
170
|
+
mock_api.return_value = mock_de_account_response
|
|
166
171
|
|
|
167
172
|
result = await get_account_info(account_id="act_de")
|
|
168
|
-
result_data = json.loads(result)
|
|
169
173
|
|
|
170
|
-
#
|
|
174
|
+
# Handle new return format (dictionary instead of JSON string)
|
|
175
|
+
if isinstance(result, dict):
|
|
176
|
+
result_data = result
|
|
177
|
+
else:
|
|
178
|
+
result_data = json.loads(result)
|
|
179
|
+
|
|
180
|
+
# Verify DSA requirement for German account
|
|
171
181
|
assert result_data["business_country_code"] == "DE"
|
|
172
182
|
assert result_data["dsa_required"] == True
|
|
173
183
|
|
|
174
|
-
# Test US account (DSA not required)
|
|
175
|
-
|
|
184
|
+
# Test 2: US account (DSA not required)
|
|
185
|
+
mock_us_account_response = {
|
|
176
186
|
"id": "act_us",
|
|
177
|
-
"name": "US
|
|
187
|
+
"name": "US Account",
|
|
178
188
|
"business_country_code": "US",
|
|
179
|
-
"
|
|
189
|
+
"currency": "USD"
|
|
180
190
|
}
|
|
181
191
|
|
|
182
192
|
with patch('meta_ads_mcp.core.accounts.make_api_request', new_callable=AsyncMock) as mock_api:
|
|
183
193
|
with patch('meta_ads_mcp.core.api.get_current_access_token', new_callable=AsyncMock) as mock_auth:
|
|
184
194
|
mock_auth.return_value = "test_access_token"
|
|
185
|
-
mock_api.return_value =
|
|
195
|
+
mock_api.return_value = mock_us_account_response
|
|
186
196
|
|
|
187
197
|
result = await get_account_info(account_id="act_us")
|
|
188
|
-
result_data = json.loads(result)
|
|
189
198
|
|
|
190
|
-
#
|
|
199
|
+
# Handle new return format (dictionary instead of JSON string)
|
|
200
|
+
if isinstance(result, dict):
|
|
201
|
+
result_data = result
|
|
202
|
+
else:
|
|
203
|
+
result_data = json.loads(result)
|
|
204
|
+
|
|
205
|
+
# Verify no DSA requirement for US account
|
|
191
206
|
assert result_data["business_country_code"] == "US"
|
|
192
207
|
assert result_data["dsa_required"] == False
|
|
193
208
|
|
|
@@ -377,4 +392,58 @@ class TestDSAIntegration:
|
|
|
377
392
|
|
|
378
393
|
# Verify ad set details are retrieved correctly
|
|
379
394
|
assert result_data["id"] == "120229746624860183"
|
|
380
|
-
assert "dsa_beneficiary" not in result_data # Should not be present for US accounts
|
|
395
|
+
assert "dsa_beneficiary" not in result_data # Should not be present for US accounts
|
|
396
|
+
|
|
397
|
+
@pytest.mark.asyncio
|
|
398
|
+
async def test_account_info_requires_account_id(self):
|
|
399
|
+
"""Test that get_account_info requires an account_id parameter"""
|
|
400
|
+
|
|
401
|
+
with patch('meta_ads_mcp.core.api.get_current_access_token', new_callable=AsyncMock) as mock_auth:
|
|
402
|
+
mock_auth.return_value = "test_access_token"
|
|
403
|
+
|
|
404
|
+
# Test without account_id parameter
|
|
405
|
+
result = await get_account_info()
|
|
406
|
+
|
|
407
|
+
# Handle new return format (dictionary instead of JSON string)
|
|
408
|
+
if isinstance(result, dict):
|
|
409
|
+
result_data = result
|
|
410
|
+
else:
|
|
411
|
+
result_data = json.loads(result)
|
|
412
|
+
|
|
413
|
+
# Verify error message for missing account_id
|
|
414
|
+
assert "error" in result_data
|
|
415
|
+
assert "Account ID is required" in result_data["error"]["message"]
|
|
416
|
+
assert "Please specify an account_id parameter" in result_data["error"]["details"]
|
|
417
|
+
assert "example" in result_data["error"]
|
|
418
|
+
|
|
419
|
+
@pytest.mark.asyncio
|
|
420
|
+
async def test_account_info_inaccessible_account_error(self):
|
|
421
|
+
"""Test that get_account_info provides helpful error for inaccessible accounts"""
|
|
422
|
+
|
|
423
|
+
# Mock accessible accounts response
|
|
424
|
+
mock_accessible_accounts = {
|
|
425
|
+
"data": [
|
|
426
|
+
{"id": "act_123", "name": "Test Account 1"},
|
|
427
|
+
{"id": "act_456", "name": "Test Account 2"}
|
|
428
|
+
]
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
with patch('meta_ads_mcp.core.accounts.make_api_request', new_callable=AsyncMock) as mock_api:
|
|
432
|
+
with patch('meta_ads_mcp.core.api.get_current_access_token', new_callable=AsyncMock) as mock_auth:
|
|
433
|
+
mock_auth.return_value = "test_access_token"
|
|
434
|
+
mock_api.return_value = mock_accessible_accounts
|
|
435
|
+
|
|
436
|
+
result = await get_account_info(account_id="act_inaccessible")
|
|
437
|
+
|
|
438
|
+
# Handle new return format (dictionary instead of JSON string)
|
|
439
|
+
if isinstance(result, dict):
|
|
440
|
+
result_data = result
|
|
441
|
+
else:
|
|
442
|
+
result_data = json.loads(result)
|
|
443
|
+
|
|
444
|
+
# Verify helpful error message for inaccessible account
|
|
445
|
+
assert "error" in result_data
|
|
446
|
+
assert "not accessible to your user account" in result_data["error"]["message"]
|
|
447
|
+
assert "accessible_accounts" in result_data["error"]
|
|
448
|
+
assert "suggestion" in result_data["error"]
|
|
449
|
+
assert len(result_data["error"]["accessible_accounts"]) == 2
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|