meta-ads-mcp 0.9.2__tar.gz → 0.10.0__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.10.0/LICENSE +44 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/PKG-INFO +3 -3
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/__init__.py +3 -3
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/__init__.py +2 -2
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/accounts.py +27 -26
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/openai_deep_research.py +2 -2
- meta_ads_mcp-0.10.0/meta_ads_mcp/core/targeting.py +288 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/pyproject.toml +3 -3
- meta_ads_mcp-0.10.0/tests/e2e_account_info_search_issue.py +320 -0
- meta_ads_mcp-0.10.0/tests/test_account_info_access_fix.py +317 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_dsa_beneficiary.py +12 -2
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_dsa_integration.py +12 -2
- meta_ads_mcp-0.10.0/tests/test_estimate_audience_size.py +482 -0
- meta_ads_mcp-0.10.0/tests/test_estimate_audience_size_e2e.py +639 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_targeting.py +7 -7
- meta_ads_mcp-0.9.2/LICENSE +0 -201
- meta_ads_mcp-0.9.2/meta_ads_mcp/core/targeting.py +0 -185
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/.github/workflows/publish.yml +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/.github/workflows/test.yml +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/.gitignore +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/CUSTOM_META_APP.md +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/Dockerfile +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/LOCAL_INSTALLATION.md +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/META_API_NOTES.md +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/README.md +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/RELEASE.md +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/STREAMABLE_HTTP_SETUP.md +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/examples/README.md +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/examples/example_http_client.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/future_improvements.md +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/images/meta-ads-example.png +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_auth.sh +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/__main__.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/ads.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/ads_library.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/adsets.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/api.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/auth.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/authentication.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/budget_schedules.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/callback_server.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/campaigns.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/duplication.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/http_auth_integration.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/insights.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/pipeboard_auth.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/reports.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/resources.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/server.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/meta_ads_mcp/core/utils.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/requirements.txt +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/setup.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/smithery.yaml +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/README.md +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/README_REGRESSION_TESTS.md +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/__init__.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/conftest.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_account_search.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_budget_update.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_budget_update_e2e.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_duplication.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_duplication_regression.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_dynamic_creatives.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_get_account_pages.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_get_ad_creatives_fix.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_get_ad_image_quality_improvements.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_get_ad_image_regression.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_http_transport.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_insights_actions_and_values.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_integration_openai_mcp.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_mobile_app_adset_creation.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_mobile_app_adset_issue.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_openai.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_openai_mcp_deep_research.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_page_discovery.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_page_discovery_integration.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_targeting_search_e2e.py +0 -0
- {meta_ads_mcp-0.9.2 → meta_ads_mcp-0.10.0}/tests/test_update_ad_creative_id.py +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
License text copyright © 2017 MariaDB Corporation Ab, All Rights Reserved.
|
|
4
|
+
"Business Source License" is a trademark of MariaDB Corporation Ab.
|
|
5
|
+
|
|
6
|
+
Parameters
|
|
7
|
+
|
|
8
|
+
Licensor: ARTELL SOLUÇÕES TECNOLÓGICAS LTDA
|
|
9
|
+
Licensed Work: Meta Ads MCP Server. The Licensed Work is (c) 2025
|
|
10
|
+
Additional Use Grant: You may make production use of the Licensed Work, provided such use does not include offering the Licensed Work to third parties on a hosted or embedded basis which competes with the Licensor's commercial offerings.
|
|
11
|
+
Change Date: January 1, 2029
|
|
12
|
+
Change License: Apache License, Version 2.0
|
|
13
|
+
|
|
14
|
+
Terms
|
|
15
|
+
|
|
16
|
+
The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
|
|
17
|
+
|
|
18
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.
|
|
19
|
+
|
|
20
|
+
If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
|
|
21
|
+
|
|
22
|
+
All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
|
|
23
|
+
|
|
24
|
+
You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.
|
|
25
|
+
|
|
26
|
+
Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
|
|
27
|
+
|
|
28
|
+
This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License).
|
|
29
|
+
|
|
30
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE.
|
|
31
|
+
|
|
32
|
+
MariaDB hereby grants you permission to use this License's text to license your works, and to refer to it using the trademark "Business Source License", as long as you comply with the Covenants of Licensor below.
|
|
33
|
+
|
|
34
|
+
Covenants of Licensor
|
|
35
|
+
|
|
36
|
+
In consideration of the right to use this License's text and the "Business Source License" name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
|
|
37
|
+
|
|
38
|
+
1. To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where "compatible" means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation.
|
|
39
|
+
|
|
40
|
+
2. To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text "None".
|
|
41
|
+
|
|
42
|
+
3. To specify a Change Date.
|
|
43
|
+
|
|
44
|
+
4. Not to modify this License in any other way.
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: meta-ads-mcp
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0
|
|
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
|
|
7
7
|
Author-email: Yves Junqueira <yves.junqueira@gmail.com>
|
|
8
|
-
License:
|
|
8
|
+
License: BUSL-1.1
|
|
9
9
|
License-File: LICENSE
|
|
10
10
|
Keywords: ads,api,claude,facebook,mcp,meta
|
|
11
|
-
Classifier: License ::
|
|
11
|
+
Classifier: License :: Other/Proprietary License
|
|
12
12
|
Classifier: Operating System :: OS Independent
|
|
13
13
|
Classifier: Programming Language :: Python :: 3
|
|
14
14
|
Requires-Python: >=3.10
|
|
@@ -7,7 +7,7 @@ with the Claude LLM.
|
|
|
7
7
|
|
|
8
8
|
from meta_ads_mcp.core.server import main
|
|
9
9
|
|
|
10
|
-
__version__ = "0.
|
|
10
|
+
__version__ = "0.10.0"
|
|
11
11
|
|
|
12
12
|
__all__ = [
|
|
13
13
|
'get_ad_accounts',
|
|
@@ -29,7 +29,7 @@ __all__ = [
|
|
|
29
29
|
'main',
|
|
30
30
|
'search_interests',
|
|
31
31
|
'get_interest_suggestions',
|
|
32
|
-
'
|
|
32
|
+
'estimate_audience_size',
|
|
33
33
|
'search_behaviors',
|
|
34
34
|
'search_demographics',
|
|
35
35
|
'search_geo_locations'
|
|
@@ -56,7 +56,7 @@ from .core import (
|
|
|
56
56
|
main,
|
|
57
57
|
search_interests,
|
|
58
58
|
get_interest_suggestions,
|
|
59
|
-
|
|
59
|
+
estimate_audience_size,
|
|
60
60
|
search_behaviors,
|
|
61
61
|
search_demographics,
|
|
62
62
|
search_geo_locations
|
|
@@ -11,7 +11,7 @@ from .server import login_cli, main
|
|
|
11
11
|
from .auth import login
|
|
12
12
|
from . import ads_library # Import module to register conditional tools
|
|
13
13
|
from .budget_schedules import create_budget_schedule
|
|
14
|
-
from .targeting import search_interests, get_interest_suggestions,
|
|
14
|
+
from .targeting import search_interests, get_interest_suggestions, estimate_audience_size, search_behaviors, search_demographics, search_geo_locations
|
|
15
15
|
from . import reports # Import module to register conditional tools
|
|
16
16
|
from . import duplication # Import module to register conditional duplication tools
|
|
17
17
|
from .openai_deep_research import search, fetch # OpenAI MCP Deep Research tools
|
|
@@ -39,7 +39,7 @@ __all__ = [
|
|
|
39
39
|
'create_budget_schedule',
|
|
40
40
|
'search_interests',
|
|
41
41
|
'get_interest_suggestions',
|
|
42
|
-
'
|
|
42
|
+
'estimate_audience_size',
|
|
43
43
|
'search_behaviors',
|
|
44
44
|
'search_demographics',
|
|
45
45
|
'search_geo_locations',
|
|
@@ -51,32 +51,7 @@ async def get_account_info(access_token: str = None, account_id: str = None) ->
|
|
|
51
51
|
if not account_id.startswith("act_"):
|
|
52
52
|
account_id = f"act_{account_id}"
|
|
53
53
|
|
|
54
|
-
#
|
|
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
|
-
|
|
54
|
+
# Try to get the account info directly first
|
|
80
55
|
endpoint = f"{account_id}"
|
|
81
56
|
params = {
|
|
82
57
|
"fields": "id,name,account_id,account_status,amount_spent,balance,currency,age,business_city,business_country_code,timezone_name"
|
|
@@ -86,6 +61,32 @@ async def get_account_info(access_token: str = None, account_id: str = None) ->
|
|
|
86
61
|
|
|
87
62
|
# Check if the API request returned an error
|
|
88
63
|
if "error" in data:
|
|
64
|
+
# If access was denied, provide helpful error message with accessible accounts
|
|
65
|
+
if "access" in str(data.get("error", {})).lower() or "permission" in str(data.get("error", {})).lower():
|
|
66
|
+
# Get list of accessible accounts for helpful error message
|
|
67
|
+
accessible_endpoint = "me/adaccounts"
|
|
68
|
+
accessible_params = {
|
|
69
|
+
"fields": "id,name,account_id,account_status,amount_spent,balance,currency,age,business_city,business_country_code",
|
|
70
|
+
"limit": 50
|
|
71
|
+
}
|
|
72
|
+
accessible_accounts_data = await make_api_request(accessible_endpoint, access_token, accessible_params)
|
|
73
|
+
|
|
74
|
+
if "data" in accessible_accounts_data:
|
|
75
|
+
accessible_accounts = [
|
|
76
|
+
{"id": acc["id"], "name": acc["name"]}
|
|
77
|
+
for acc in accessible_accounts_data["data"][:10] # Show first 10
|
|
78
|
+
]
|
|
79
|
+
return {
|
|
80
|
+
"error": {
|
|
81
|
+
"message": f"Account {account_id} is not accessible to your user account",
|
|
82
|
+
"details": "This account either doesn't exist or you don't have permission to access it",
|
|
83
|
+
"accessible_accounts": accessible_accounts,
|
|
84
|
+
"total_accessible_accounts": len(accessible_accounts_data["data"]),
|
|
85
|
+
"suggestion": "Try using one of the accessible account IDs listed above"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
# Return the original error for non-permission related issues
|
|
89
90
|
return data
|
|
90
91
|
|
|
91
92
|
# Add DSA requirement detection
|
|
@@ -23,7 +23,7 @@ class MetaAdsDataManager:
|
|
|
23
23
|
self._cache = {}
|
|
24
24
|
logger.debug("MetaAdsDataManager initialized")
|
|
25
25
|
|
|
26
|
-
async def _get_ad_accounts(self, access_token: str, limit: int =
|
|
26
|
+
async def _get_ad_accounts(self, access_token: str, limit: int = 200) -> List[Dict[str, Any]]:
|
|
27
27
|
"""Get ad accounts data"""
|
|
28
28
|
try:
|
|
29
29
|
endpoint = "me/adaccounts"
|
|
@@ -141,7 +141,7 @@ class MetaAdsDataManager:
|
|
|
141
141
|
|
|
142
142
|
try:
|
|
143
143
|
# Search ad accounts
|
|
144
|
-
accounts = await self._get_ad_accounts(access_token, limit=
|
|
144
|
+
accounts = await self._get_ad_accounts(access_token, limit=200)
|
|
145
145
|
for account in accounts:
|
|
146
146
|
account_text = f"{account.get('name', '')} {account.get('id', '')} {account.get('account_status', '')} {account.get('business_city', '')} {account.get('business_country_code', '')}".lower()
|
|
147
147
|
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"""Targeting search functionality for Meta Ads API."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Optional, List, Dict, Any
|
|
5
|
+
from .api import meta_api_tool, make_api_request
|
|
6
|
+
from .server import mcp_server
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@mcp_server.tool()
|
|
10
|
+
@meta_api_tool
|
|
11
|
+
async def search_interests(access_token: str = None, query: str = None, limit: int = 25) -> str:
|
|
12
|
+
"""
|
|
13
|
+
Search for interest targeting options by keyword.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
access_token: Meta API access token (optional - will use cached token if not provided)
|
|
17
|
+
query: Search term for interests (e.g., "baseball", "cooking", "travel")
|
|
18
|
+
limit: Maximum number of results to return (default: 25)
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
JSON string containing interest data with id, name, audience_size, and path fields
|
|
22
|
+
"""
|
|
23
|
+
if not query:
|
|
24
|
+
return json.dumps({"error": "No search query provided"}, indent=2)
|
|
25
|
+
|
|
26
|
+
endpoint = "search"
|
|
27
|
+
params = {
|
|
28
|
+
"type": "adinterest",
|
|
29
|
+
"q": query,
|
|
30
|
+
"limit": limit
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
data = await make_api_request(endpoint, access_token, params)
|
|
34
|
+
|
|
35
|
+
return json.dumps(data, indent=2)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@mcp_server.tool()
|
|
39
|
+
@meta_api_tool
|
|
40
|
+
async def get_interest_suggestions(access_token: str = None, interest_list: List[str] = None, limit: int = 25) -> str:
|
|
41
|
+
"""
|
|
42
|
+
Get interest suggestions based on existing interests.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
access_token: Meta API access token (optional - will use cached token if not provided)
|
|
46
|
+
interest_list: List of interest names to get suggestions for (e.g., ["Basketball", "Soccer"])
|
|
47
|
+
limit: Maximum number of suggestions to return (default: 25)
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
JSON string containing suggested interests with id, name, audience_size, and description fields
|
|
51
|
+
"""
|
|
52
|
+
if not interest_list:
|
|
53
|
+
return json.dumps({"error": "No interest list provided"}, indent=2)
|
|
54
|
+
|
|
55
|
+
endpoint = "search"
|
|
56
|
+
params = {
|
|
57
|
+
"type": "adinterestsuggestion",
|
|
58
|
+
"interest_list": json.dumps(interest_list),
|
|
59
|
+
"limit": limit
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
data = await make_api_request(endpoint, access_token, params)
|
|
63
|
+
|
|
64
|
+
return json.dumps(data, indent=2)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@mcp_server.tool()
|
|
68
|
+
@meta_api_tool
|
|
69
|
+
async def estimate_audience_size(
|
|
70
|
+
access_token: str = None,
|
|
71
|
+
account_id: str = None,
|
|
72
|
+
targeting: Dict[str, Any] = None,
|
|
73
|
+
optimization_goal: str = "REACH",
|
|
74
|
+
# Backwards compatibility for simple interest validation
|
|
75
|
+
interest_list: List[str] = None,
|
|
76
|
+
interest_fbid_list: List[str] = None
|
|
77
|
+
) -> str:
|
|
78
|
+
"""
|
|
79
|
+
Estimate audience size for targeting specifications using Meta's delivery_estimate API.
|
|
80
|
+
|
|
81
|
+
This function provides comprehensive audience estimation for complex targeting combinations
|
|
82
|
+
including demographics, geography, interests, and behaviors. It also maintains backwards
|
|
83
|
+
compatibility for simple interest validation.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
access_token: Meta API access token (optional - will use cached token if not provided)
|
|
87
|
+
account_id: Meta Ads account ID (format: act_XXXXXXXXX) - required for comprehensive estimation
|
|
88
|
+
targeting: Complete targeting specification including demographics, geography, interests, etc.
|
|
89
|
+
Example: {
|
|
90
|
+
"age_min": 25,
|
|
91
|
+
"age_max": 65,
|
|
92
|
+
"geo_locations": {"countries": ["PL"]},
|
|
93
|
+
"flexible_spec": [
|
|
94
|
+
{"interests": [{"id": "6003371567474"}]},
|
|
95
|
+
{"interests": [{"id": "6003462346642"}]}
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
optimization_goal: Optimization goal for estimation (default: "REACH").
|
|
99
|
+
Options: "REACH", "LINK_CLICKS", "IMPRESSIONS", "CONVERSIONS", etc.
|
|
100
|
+
interest_list: [DEPRECATED - for backwards compatibility] List of interest names to validate
|
|
101
|
+
interest_fbid_list: [DEPRECATED - for backwards compatibility] List of interest IDs to validate
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
JSON string with audience estimation results including estimated_audience_size,
|
|
105
|
+
reach_estimate, and targeting validation
|
|
106
|
+
"""
|
|
107
|
+
# Handle backwards compatibility - simple interest validation
|
|
108
|
+
# Check if we're in backwards compatibility mode (interest params provided OR no comprehensive params)
|
|
109
|
+
is_backwards_compatible_call = (interest_list or interest_fbid_list) or (not account_id and not targeting)
|
|
110
|
+
|
|
111
|
+
if is_backwards_compatible_call and not targeting:
|
|
112
|
+
if not interest_list and not interest_fbid_list:
|
|
113
|
+
return json.dumps({"error": "No interest list or FBID list provided"}, indent=2)
|
|
114
|
+
|
|
115
|
+
endpoint = "search"
|
|
116
|
+
params = {
|
|
117
|
+
"type": "adinterestvalid"
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if interest_list:
|
|
121
|
+
params["interest_list"] = json.dumps(interest_list)
|
|
122
|
+
|
|
123
|
+
if interest_fbid_list:
|
|
124
|
+
params["interest_fbid_list"] = json.dumps(interest_fbid_list)
|
|
125
|
+
|
|
126
|
+
data = await make_api_request(endpoint, access_token, params)
|
|
127
|
+
|
|
128
|
+
return json.dumps(data, indent=2)
|
|
129
|
+
|
|
130
|
+
# Comprehensive audience estimation using delivery_estimate API
|
|
131
|
+
if not account_id:
|
|
132
|
+
return json.dumps({
|
|
133
|
+
"error": "account_id is required for comprehensive audience estimation",
|
|
134
|
+
"details": "For simple interest validation, use interest_list or interest_fbid_list parameters"
|
|
135
|
+
}, indent=2)
|
|
136
|
+
|
|
137
|
+
if not targeting:
|
|
138
|
+
return json.dumps({
|
|
139
|
+
"error": "targeting specification is required for comprehensive audience estimation",
|
|
140
|
+
"example": {
|
|
141
|
+
"age_min": 25,
|
|
142
|
+
"age_max": 65,
|
|
143
|
+
"geo_locations": {"countries": ["US"]},
|
|
144
|
+
"flexible_spec": [
|
|
145
|
+
{"interests": [{"id": "6003371567474"}]}
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
}, indent=2)
|
|
149
|
+
|
|
150
|
+
# Build delivery estimate request
|
|
151
|
+
endpoint = f"{account_id}/delivery_estimate"
|
|
152
|
+
params = {
|
|
153
|
+
"targeting": targeting,
|
|
154
|
+
"optimization_goal": optimization_goal
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
# Add basic campaign parameters for estimation
|
|
158
|
+
if optimization_goal == "REACH":
|
|
159
|
+
params["objective"] = "REACH"
|
|
160
|
+
elif optimization_goal in ["LINK_CLICKS", "LANDING_PAGE_VIEWS"]:
|
|
161
|
+
params["objective"] = "TRAFFIC"
|
|
162
|
+
elif optimization_goal == "CONVERSIONS":
|
|
163
|
+
params["objective"] = "CONVERSIONS"
|
|
164
|
+
elif optimization_goal == "APP_INSTALLS":
|
|
165
|
+
params["objective"] = "APP_INSTALLS"
|
|
166
|
+
else:
|
|
167
|
+
params["objective"] = "REACH" # Default fallback
|
|
168
|
+
|
|
169
|
+
try:
|
|
170
|
+
data = await make_api_request(endpoint, access_token, params, method="POST")
|
|
171
|
+
|
|
172
|
+
# Format the response for easier consumption
|
|
173
|
+
if "data" in data and len(data["data"]) > 0:
|
|
174
|
+
estimate_data = data["data"][0]
|
|
175
|
+
formatted_response = {
|
|
176
|
+
"success": True,
|
|
177
|
+
"account_id": account_id,
|
|
178
|
+
"targeting": targeting,
|
|
179
|
+
"optimization_goal": optimization_goal,
|
|
180
|
+
"estimated_audience_size": estimate_data.get("estimate_mau", 0),
|
|
181
|
+
"estimate_details": {
|
|
182
|
+
"monthly_active_users": estimate_data.get("estimate_mau", 0),
|
|
183
|
+
"daily_outcomes_curve": estimate_data.get("estimate_dau", []),
|
|
184
|
+
"bid_estimate": estimate_data.get("bid_estimates", {}),
|
|
185
|
+
"unsupported_targeting": estimate_data.get("unsupported_targeting", [])
|
|
186
|
+
},
|
|
187
|
+
"raw_response": data
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return json.dumps(formatted_response, indent=2)
|
|
191
|
+
else:
|
|
192
|
+
return json.dumps({
|
|
193
|
+
"error": "No estimation data returned from Meta API",
|
|
194
|
+
"raw_response": data
|
|
195
|
+
}, indent=2)
|
|
196
|
+
|
|
197
|
+
except Exception as e:
|
|
198
|
+
return json.dumps({
|
|
199
|
+
"error": f"Failed to get audience estimation: {str(e)}",
|
|
200
|
+
"details": "Check targeting parameters and account permissions"
|
|
201
|
+
}, indent=2)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
@mcp_server.tool()
|
|
205
|
+
@meta_api_tool
|
|
206
|
+
async def search_behaviors(access_token: str = None, limit: int = 50) -> str:
|
|
207
|
+
"""
|
|
208
|
+
Get all available behavior targeting options.
|
|
209
|
+
|
|
210
|
+
Args:
|
|
211
|
+
access_token: Meta API access token (optional - will use cached token if not provided)
|
|
212
|
+
limit: Maximum number of results to return (default: 50)
|
|
213
|
+
|
|
214
|
+
Returns:
|
|
215
|
+
JSON string containing behavior targeting options with id, name, audience_size bounds, path, and description
|
|
216
|
+
"""
|
|
217
|
+
endpoint = "search"
|
|
218
|
+
params = {
|
|
219
|
+
"type": "adTargetingCategory",
|
|
220
|
+
"class": "behaviors",
|
|
221
|
+
"limit": limit
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
data = await make_api_request(endpoint, access_token, params)
|
|
225
|
+
|
|
226
|
+
return json.dumps(data, indent=2)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
@mcp_server.tool()
|
|
230
|
+
@meta_api_tool
|
|
231
|
+
async def search_demographics(access_token: str = None, demographic_class: str = "demographics", limit: int = 50) -> str:
|
|
232
|
+
"""
|
|
233
|
+
Get demographic targeting options.
|
|
234
|
+
|
|
235
|
+
Args:
|
|
236
|
+
access_token: Meta API access token (optional - will use cached token if not provided)
|
|
237
|
+
demographic_class: Type of demographics to retrieve. Options: 'demographics', 'life_events',
|
|
238
|
+
'industries', 'income', 'family_statuses', 'user_device', 'user_os' (default: 'demographics')
|
|
239
|
+
limit: Maximum number of results to return (default: 50)
|
|
240
|
+
|
|
241
|
+
Returns:
|
|
242
|
+
JSON string containing demographic targeting options with id, name, audience_size bounds, path, and description
|
|
243
|
+
"""
|
|
244
|
+
endpoint = "search"
|
|
245
|
+
params = {
|
|
246
|
+
"type": "adTargetingCategory",
|
|
247
|
+
"class": demographic_class,
|
|
248
|
+
"limit": limit
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
data = await make_api_request(endpoint, access_token, params)
|
|
252
|
+
|
|
253
|
+
return json.dumps(data, indent=2)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
@mcp_server.tool()
|
|
257
|
+
@meta_api_tool
|
|
258
|
+
async def search_geo_locations(access_token: str = None, query: str = None,
|
|
259
|
+
location_types: List[str] = None, limit: int = 25) -> str:
|
|
260
|
+
"""
|
|
261
|
+
Search for geographic targeting locations.
|
|
262
|
+
|
|
263
|
+
Args:
|
|
264
|
+
access_token: Meta API access token (optional - will use cached token if not provided)
|
|
265
|
+
query: Search term for locations (e.g., "New York", "California", "Japan")
|
|
266
|
+
location_types: Types of locations to search. Options: ['country', 'region', 'city', 'zip',
|
|
267
|
+
'geo_market', 'electoral_district']. If not specified, searches all types.
|
|
268
|
+
limit: Maximum number of results to return (default: 25)
|
|
269
|
+
|
|
270
|
+
Returns:
|
|
271
|
+
JSON string containing location data with key, name, type, and geographic hierarchy information
|
|
272
|
+
"""
|
|
273
|
+
if not query:
|
|
274
|
+
return json.dumps({"error": "No search query provided"}, indent=2)
|
|
275
|
+
|
|
276
|
+
endpoint = "search"
|
|
277
|
+
params = {
|
|
278
|
+
"type": "adgeolocation",
|
|
279
|
+
"q": query,
|
|
280
|
+
"limit": limit
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if location_types:
|
|
284
|
+
params["location_types"] = json.dumps(location_types)
|
|
285
|
+
|
|
286
|
+
data = await make_api_request(endpoint, access_token, params)
|
|
287
|
+
|
|
288
|
+
return json.dumps(data, indent=2)
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "meta-ads-mcp"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.10.0"
|
|
8
8
|
description = "Model Context Protocol (MCP) plugin for interacting with Meta Ads API"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -12,10 +12,10 @@ authors = [
|
|
|
12
12
|
{name = "Yves Junqueira", email = "yves.junqueira@gmail.com"},
|
|
13
13
|
]
|
|
14
14
|
keywords = ["meta", "facebook", "ads", "api", "mcp", "claude"]
|
|
15
|
-
license = {text = "
|
|
15
|
+
license = {text = "BUSL-1.1"}
|
|
16
16
|
classifiers = [
|
|
17
17
|
"Programming Language :: Python :: 3",
|
|
18
|
-
"License ::
|
|
18
|
+
"License :: Other/Proprietary License",
|
|
19
19
|
"Operating System :: OS Independent",
|
|
20
20
|
]
|
|
21
21
|
dependencies = [
|