meta-ads-mcp 0.7.0__py3-none-any.whl → 0.7.2__py3-none-any.whl
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/__init__.py +1 -1
- meta_ads_mcp/core/authentication.py +115 -52
- {meta_ads_mcp-0.7.0.dist-info → meta_ads_mcp-0.7.2.dist-info}/METADATA +1 -1
- {meta_ads_mcp-0.7.0.dist-info → meta_ads_mcp-0.7.2.dist-info}/RECORD +7 -7
- {meta_ads_mcp-0.7.0.dist-info → meta_ads_mcp-0.7.2.dist-info}/WHEEL +0 -0
- {meta_ads_mcp-0.7.0.dist-info → meta_ads_mcp-0.7.2.dist-info}/entry_points.txt +0 -0
- {meta_ads_mcp-0.7.0.dist-info → meta_ads_mcp-0.7.2.dist-info}/licenses/LICENSE +0 -0
meta_ads_mcp/__init__.py
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
|
-
"""Authentication-specific functionality for Meta Ads API.
|
|
1
|
+
"""Authentication-specific functionality for Meta Ads API.
|
|
2
|
+
|
|
3
|
+
The Meta Ads MCP server supports three authentication modes:
|
|
4
|
+
|
|
5
|
+
1. **Development/Local Mode** (default)
|
|
6
|
+
- Uses local callback server on localhost:8080+ for OAuth redirect
|
|
7
|
+
- Requires META_ADS_DISABLE_CALLBACK_SERVER to NOT be set
|
|
8
|
+
- Best for local development and testing
|
|
9
|
+
|
|
10
|
+
2. **Production with API Token**
|
|
11
|
+
- Uses PIPEBOARD_API_TOKEN for server-to-server authentication
|
|
12
|
+
- Bypasses OAuth flow entirely
|
|
13
|
+
- Best for server deployments with pre-configured tokens
|
|
14
|
+
|
|
15
|
+
3. **Production OAuth Flow** (NEW)
|
|
16
|
+
- Uses Pipeboard OAuth endpoints for dynamic client registration
|
|
17
|
+
- Triggered when META_ADS_DISABLE_CALLBACK_SERVER is set but no PIPEBOARD_API_TOKEN
|
|
18
|
+
- Supports MCP clients that implement OAuth 2.0 discovery
|
|
19
|
+
|
|
20
|
+
Environment Variables:
|
|
21
|
+
- PIPEBOARD_API_TOKEN: Enables mode 2 (token-based auth)
|
|
22
|
+
- META_ADS_DISABLE_CALLBACK_SERVER: Disables local server, enables mode 3
|
|
23
|
+
- META_ACCESS_TOKEN: Direct Meta token (fallback)
|
|
24
|
+
"""
|
|
2
25
|
|
|
3
26
|
import json
|
|
4
27
|
import asyncio
|
|
@@ -27,50 +50,88 @@ async def get_login_link(access_token: str = None) -> str:
|
|
|
27
50
|
"""
|
|
28
51
|
# Check if we're using pipeboard authentication
|
|
29
52
|
using_pipeboard = bool(os.environ.get("PIPEBOARD_API_TOKEN", ""))
|
|
53
|
+
callback_server_disabled = bool(os.environ.get("META_ADS_DISABLE_CALLBACK_SERVER", ""))
|
|
30
54
|
|
|
31
55
|
if using_pipeboard:
|
|
32
|
-
#
|
|
33
|
-
# Check if we have a cached token
|
|
34
|
-
cached_token = pipeboard_auth_manager.get_access_token()
|
|
35
|
-
token_status = "No token" if not cached_token else "Valid token"
|
|
36
|
-
|
|
37
|
-
# If we already have a valid token and none was provided, just return success
|
|
38
|
-
if cached_token and not access_token:
|
|
39
|
-
logger.info("get_login_link called with existing valid Pipeboard token")
|
|
40
|
-
return json.dumps({
|
|
41
|
-
"message": "Already authenticated with Pipeboard",
|
|
42
|
-
"token_status": token_status,
|
|
43
|
-
"token_preview": cached_token[:10] + "..." if cached_token else None,
|
|
44
|
-
"authentication_method": "pipeboard"
|
|
45
|
-
}, indent=2)
|
|
46
|
-
|
|
47
|
-
# Initiate the auth flow via Pipeboard
|
|
56
|
+
# Pipeboard token-based authentication
|
|
48
57
|
try:
|
|
49
|
-
|
|
50
|
-
login_url = auth_data.get("loginUrl")
|
|
58
|
+
logger.info("Using Pipeboard token-based authentication")
|
|
51
59
|
|
|
52
|
-
#
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"note": "After authenticating, the token will be automatically saved."
|
|
62
|
-
}
|
|
60
|
+
# If an access token was provided, this is likely a test - return success
|
|
61
|
+
if access_token:
|
|
62
|
+
return json.dumps({
|
|
63
|
+
"message": "✅ Authentication Token Provided",
|
|
64
|
+
"status": "Using provided access token for authentication",
|
|
65
|
+
"token_info": f"Token preview: {access_token[:10]}...",
|
|
66
|
+
"authentication_method": "manual_token",
|
|
67
|
+
"ready_to_use": "You can now use all Meta Ads MCP tools and commands."
|
|
68
|
+
}, indent=2)
|
|
63
69
|
|
|
64
|
-
|
|
70
|
+
# Check if Pipeboard token is working
|
|
71
|
+
token = pipeboard_auth_manager.get_access_token()
|
|
72
|
+
if token:
|
|
73
|
+
return json.dumps({
|
|
74
|
+
"message": "✅ Already Authenticated",
|
|
75
|
+
"status": "You're successfully authenticated with Meta Ads via Pipeboard!",
|
|
76
|
+
"token_info": f"Token preview: {token[:10]}...",
|
|
77
|
+
"authentication_method": "pipeboard_token",
|
|
78
|
+
"ready_to_use": "You can now use all Meta Ads MCP tools and commands."
|
|
79
|
+
}, indent=2)
|
|
80
|
+
|
|
81
|
+
# Start Pipeboard auth flow
|
|
82
|
+
auth_data = pipeboard_auth_manager.initiate_auth_flow()
|
|
83
|
+
login_url = auth_data.get('loginUrl')
|
|
84
|
+
|
|
85
|
+
if login_url:
|
|
86
|
+
return json.dumps({
|
|
87
|
+
"message": "🔗 Click to Authenticate",
|
|
88
|
+
"login_url": login_url,
|
|
89
|
+
"markdown_link": f"[🚀 Authenticate with Meta Ads]({login_url})",
|
|
90
|
+
"instructions": "Click the link above to complete authentication with Meta Ads.",
|
|
91
|
+
"authentication_method": "pipeboard_oauth",
|
|
92
|
+
"what_happens_next": "After clicking, you'll be redirected to Meta's authentication page. Once completed, your token will be automatically saved.",
|
|
93
|
+
"token_duration": "Your token will be valid for approximately 60 days."
|
|
94
|
+
}, indent=2)
|
|
95
|
+
else:
|
|
96
|
+
return json.dumps({
|
|
97
|
+
"message": "❌ Authentication Error",
|
|
98
|
+
"error": "Could not generate authentication URL from Pipeboard",
|
|
99
|
+
"troubleshooting": [
|
|
100
|
+
"Check that your PIPEBOARD_API_TOKEN is valid",
|
|
101
|
+
"Ensure the Pipeboard service is accessible",
|
|
102
|
+
"Try again in a few moments"
|
|
103
|
+
],
|
|
104
|
+
"authentication_method": "pipeboard_oauth_failed"
|
|
105
|
+
}, indent=2)
|
|
106
|
+
|
|
65
107
|
except Exception as e:
|
|
66
108
|
logger.error(f"Error initiating Pipeboard auth flow: {e}")
|
|
67
109
|
return json.dumps({
|
|
110
|
+
"message": "❌ Pipeboard Authentication Error",
|
|
68
111
|
"error": f"Failed to initiate Pipeboard authentication: {str(e)}",
|
|
69
|
-
"
|
|
70
|
-
|
|
112
|
+
"troubleshooting": [
|
|
113
|
+
"✅ Check that PIPEBOARD_API_TOKEN environment variable is set correctly",
|
|
114
|
+
"🌐 Verify that pipeboard.co is accessible from your network",
|
|
115
|
+
"🔄 Try refreshing your Pipeboard API token",
|
|
116
|
+
"⏰ Wait a moment and try again"
|
|
117
|
+
],
|
|
118
|
+
"get_help": "Contact support if the issue persists",
|
|
119
|
+
"authentication_method": "pipeboard_error"
|
|
71
120
|
}, indent=2)
|
|
121
|
+
elif callback_server_disabled:
|
|
122
|
+
# Production OAuth flow - use Pipeboard OAuth endpoints directly
|
|
123
|
+
logger.info("Production OAuth flow - using Pipeboard OAuth endpoints")
|
|
124
|
+
|
|
125
|
+
return json.dumps({
|
|
126
|
+
"message": "🔐 Authentication Required",
|
|
127
|
+
"instructions": "Please sign in to your Pipeboard account to authenticate with Meta Ads.",
|
|
128
|
+
"sign_in_url": "https://pipeboard.co/auth/signin",
|
|
129
|
+
"markdown_link": "[🚀 Sign in to Pipeboard](https://pipeboard.co/auth/signin)",
|
|
130
|
+
"what_to_do": "Click the link above to sign in to your Pipeboard account and complete authentication.",
|
|
131
|
+
"authentication_method": "production_oauth"
|
|
132
|
+
}, indent=2)
|
|
72
133
|
else:
|
|
73
|
-
# Original Meta authentication flow
|
|
134
|
+
# Original Meta authentication flow (development/local)
|
|
74
135
|
# Check if we have a cached token
|
|
75
136
|
cached_token = auth_manager.get_access_token()
|
|
76
137
|
token_status = "No token" if not cached_token else "Valid token"
|
|
@@ -79,12 +140,13 @@ async def get_login_link(access_token: str = None) -> str:
|
|
|
79
140
|
if cached_token and not access_token:
|
|
80
141
|
logger.info("get_login_link called with existing valid token")
|
|
81
142
|
return json.dumps({
|
|
82
|
-
"message": "Already
|
|
83
|
-
"
|
|
84
|
-
"
|
|
143
|
+
"message": "✅ Already Authenticated",
|
|
144
|
+
"status": "You're successfully authenticated with Meta Ads!",
|
|
145
|
+
"token_info": f"Token preview: {cached_token[:10]}...",
|
|
85
146
|
"created_at": auth_manager.token_info.created_at if hasattr(auth_manager, "token_info") else None,
|
|
86
147
|
"expires_in": auth_manager.token_info.expires_in if hasattr(auth_manager, "token_info") else None,
|
|
87
|
-
"authentication_method": "meta_oauth"
|
|
148
|
+
"authentication_method": "meta_oauth",
|
|
149
|
+
"ready_to_use": "You can now use all Meta Ads MCP tools and commands."
|
|
88
150
|
}, indent=2)
|
|
89
151
|
|
|
90
152
|
# IMPORTANT: Start the callback server first by calling our helper function
|
|
@@ -102,9 +164,14 @@ async def get_login_link(access_token: str = None) -> str:
|
|
|
102
164
|
except Exception as e:
|
|
103
165
|
logger.error(f"Failed to start callback server: {e}")
|
|
104
166
|
return json.dumps({
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
167
|
+
"message": "❌ Local Authentication Unavailable",
|
|
168
|
+
"error": "Cannot start local callback server for authentication",
|
|
169
|
+
"reason": str(e),
|
|
170
|
+
"solutions": [
|
|
171
|
+
"🌐 Use Pipeboard authentication: Set PIPEBOARD_API_TOKEN environment variable",
|
|
172
|
+
"🔑 Use direct token: Set META_ACCESS_TOKEN environment variable",
|
|
173
|
+
"🔧 Check if another service is using the required ports"
|
|
174
|
+
],
|
|
108
175
|
"authentication_method": "meta_oauth_disabled"
|
|
109
176
|
}, indent=2)
|
|
110
177
|
|
|
@@ -114,19 +181,15 @@ async def get_login_link(access_token: str = None) -> str:
|
|
|
114
181
|
|
|
115
182
|
# Return a special format that helps the LLM format the response properly
|
|
116
183
|
response = {
|
|
184
|
+
"message": "🔗 Click to Authenticate",
|
|
117
185
|
"login_url": login_url,
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"
|
|
122
|
-
"instructions_for_llm": "You must present this link as clickable Markdown to the user using the markdown_link format provided.",
|
|
123
|
-
"token_exchange": "enabled" if token_exchange_supported else "disabled",
|
|
124
|
-
"token_duration": token_duration,
|
|
186
|
+
"markdown_link": f"[🚀 Authenticate with Meta Ads]({login_url})",
|
|
187
|
+
"instructions": "Click the link above to authenticate with Meta Ads.",
|
|
188
|
+
"server_info": f"Local callback server running on port {port}",
|
|
189
|
+
"token_duration": f"Your token will be valid for approximately {token_duration}",
|
|
125
190
|
"authentication_method": "meta_oauth",
|
|
126
|
-
"
|
|
127
|
-
|
|
128
|
-
" For direct Meta authentication, long-lived tokens require META_APP_SECRET. Consider using Pipeboard authentication instead (60-day tokens by default)."),
|
|
129
|
-
"note": "After authenticating, the token will be automatically saved."
|
|
191
|
+
"what_happens_next": "After clicking, you'll be redirected to Meta's authentication page. Once completed, your token will be automatically saved.",
|
|
192
|
+
"security_note": "This uses a secure local callback server for development purposes."
|
|
130
193
|
}
|
|
131
194
|
|
|
132
195
|
# Wait a moment to ensure the server is fully started
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: meta-ads-mcp
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.2
|
|
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
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
meta_ads_mcp/__init__.py,sha256=
|
|
1
|
+
meta_ads_mcp/__init__.py,sha256=KwWEwtUuoU8IdDlVrrrmoG5dF51_f0RcetZ8dUiTwRA,1492
|
|
2
2
|
meta_ads_mcp/__main__.py,sha256=XaQt3iXftG_7f0Zu7Wop9SeFgrD2WBn0EQOaPMc27d8,207
|
|
3
3
|
meta_ads_mcp/core/__init__.py,sha256=IHBUfLTQW44VLbH_gZDT83nqzGrVWZ0l7FG4P3bp_bU,1706
|
|
4
4
|
meta_ads_mcp/core/accounts.py,sha256=Nmp7lPxO9wmq25jWV7_H0LIqnEbBhpCVBlLGW2HUaq0,2277
|
|
@@ -7,7 +7,7 @@ meta_ads_mcp/core/ads_library.py,sha256=onStn9UkRqYDC60gOPS-iKDtP1plz6DygUb7hUZ0
|
|
|
7
7
|
meta_ads_mcp/core/adsets.py,sha256=k76rm3rkhEebUzvBnM_QaVktrzGTKvTJOtWbBd6s3i8,10399
|
|
8
8
|
meta_ads_mcp/core/api.py,sha256=aAzM6Q75VQOFXtr5D-mDmBRhxWK4wsiODsJYnR3mpDI,14994
|
|
9
9
|
meta_ads_mcp/core/auth.py,sha256=H-0s0O2fLo14rmi81Hh5S64pyRl1HS7dm9Q_8UCa3Jg,21622
|
|
10
|
-
meta_ads_mcp/core/authentication.py,sha256
|
|
10
|
+
meta_ads_mcp/core/authentication.py,sha256=-AJxa3a5ZshRCvmJThBaNwCAJ1D2_qOgUkvu539c_MY,10159
|
|
11
11
|
meta_ads_mcp/core/budget_schedules.py,sha256=UxseExsvKAiPwfDCY9aycT4kys4xqeNytyq-yyDOxrs,2901
|
|
12
12
|
meta_ads_mcp/core/callback_server.py,sha256=LIAJv9DW--83kdZ7VWWZal8xEprYjRZ8iug4rMczYbQ,9372
|
|
13
13
|
meta_ads_mcp/core/campaigns.py,sha256=Fd477GsD1Gx08Ve0uXUCvr4fC-xQCeVHPBwRVaeRQKk,10965
|
|
@@ -21,8 +21,8 @@ meta_ads_mcp/core/resources.py,sha256=-zIIfZulpo76vcKv6jhAlQq91cR2SZ3cjYZt3ek3x0
|
|
|
21
21
|
meta_ads_mcp/core/server.py,sha256=WhbAag7xdhbGcp7rnU4sKhqXJ8Slapa_ba3T23Yp_2U,17889
|
|
22
22
|
meta_ads_mcp/core/targeting.py,sha256=3HW1qirEdwaQurlBZGenbIwawcb5J06ghJKRfgu9ZEs,6318
|
|
23
23
|
meta_ads_mcp/core/utils.py,sha256=ofKUhyo-5SZoJVuBeTVFPPQCffk0UKpwmDMrd8qQxNc,8715
|
|
24
|
-
meta_ads_mcp-0.7.
|
|
25
|
-
meta_ads_mcp-0.7.
|
|
26
|
-
meta_ads_mcp-0.7.
|
|
27
|
-
meta_ads_mcp-0.7.
|
|
28
|
-
meta_ads_mcp-0.7.
|
|
24
|
+
meta_ads_mcp-0.7.2.dist-info/METADATA,sha256=qE7hnGdcACq3_MRBnFb_kGV-gJzMes_d1AJjPx8u01s,20409
|
|
25
|
+
meta_ads_mcp-0.7.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
26
|
+
meta_ads_mcp-0.7.2.dist-info/entry_points.txt,sha256=Dv2RkoBjRJBqj6CyhwqGIiwPCD-SCL1-7B9-zmVRuv0,57
|
|
27
|
+
meta_ads_mcp-0.7.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
28
|
+
meta_ads_mcp-0.7.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|