meta-ads-mcp 0.2.0__tar.gz → 0.2.2__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.
Files changed (32) hide show
  1. {meta_ads_mcp-0.2.0 → meta_ads_mcp-0.2.2}/.gitignore +10 -0
  2. meta_ads_mcp-0.2.2/PKG-INFO +329 -0
  3. meta_ads_mcp-0.2.2/README.md +308 -0
  4. meta_ads_mcp-0.2.2/future_improvements.md +59 -0
  5. meta_ads_mcp-0.2.2/meta-ads-mcp +13 -0
  6. {meta_ads_mcp-0.2.0 → meta_ads_mcp-0.2.2}/meta_ads_mcp/__init__.py +19 -5
  7. meta_ads_mcp-0.2.2/meta_ads_mcp/core/__init__.py +34 -0
  8. meta_ads_mcp-0.2.2/meta_ads_mcp/core/accounts.py +59 -0
  9. meta_ads_mcp-0.2.2/meta_ads_mcp/core/ads.py +361 -0
  10. meta_ads_mcp-0.2.2/meta_ads_mcp/core/adsets.py +115 -0
  11. meta_ads_mcp-0.2.2/meta_ads_mcp/core/api.py +211 -0
  12. meta_ads_mcp-0.2.2/meta_ads_mcp/core/auth.py +416 -0
  13. meta_ads_mcp-0.2.2/meta_ads_mcp/core/authentication.py +56 -0
  14. meta_ads_mcp-0.2.2/meta_ads_mcp/core/campaigns.py +119 -0
  15. meta_ads_mcp-0.2.2/meta_ads_mcp/core/insights.py +412 -0
  16. meta_ads_mcp-0.2.2/meta_ads_mcp/core/resources.py +46 -0
  17. meta_ads_mcp-0.2.2/meta_ads_mcp/core/server.py +47 -0
  18. meta_ads_mcp-0.2.2/meta_ads_mcp/core/utils.py +128 -0
  19. {meta_ads_mcp-0.2.0 → meta_ads_mcp-0.2.2}/pyproject.toml +1 -2
  20. {meta_ads_mcp-0.2.0 → meta_ads_mcp-0.2.2}/test_meta_ads_auth.py +2 -1
  21. meta_ads_mcp-0.2.0/.python-version +0 -1
  22. meta_ads_mcp-0.2.0/.uv.toml +0 -2
  23. meta_ads_mcp-0.2.0/PKG-INFO +0 -250
  24. meta_ads_mcp-0.2.0/README.md +0 -229
  25. meta_ads_mcp-0.2.0/login.bat +0 -18
  26. meta_ads_mcp-0.2.0/login.sh +0 -17
  27. meta_ads_mcp-0.2.0/meta_ads_generated.py +0 -1840
  28. meta_ads_mcp-0.2.0/poetry.lock +0 -437
  29. meta_ads_mcp-0.2.0/uv.lock +0 -462
  30. {meta_ads_mcp-0.2.0 → meta_ads_mcp-0.2.2}/meta_ads_mcp/api.py +0 -0
  31. {meta_ads_mcp-0.2.0 → meta_ads_mcp-0.2.2}/requirements.txt +0 -0
  32. {meta_ads_mcp-0.2.0 → meta_ads_mcp-0.2.2}/setup.py +0 -0
@@ -10,3 +10,13 @@ wheels/
10
10
  .venv
11
11
  .cursor/rules/meta-ads-credentials.mdc
12
12
  .DS_Store
13
+
14
+ # Development environment files
15
+ .python-version
16
+ poetry.lock
17
+ uv.lock
18
+ .uv.toml
19
+ .cursor/
20
+
21
+ # Generated content
22
+ ad_creatives/
@@ -0,0 +1,329 @@
1
+ Metadata-Version: 2.4
2
+ Name: meta-ads-mcp
3
+ Version: 0.2.2
4
+ Summary: Model Calling Protocol (MCP) plugin for interacting with Meta Ads API
5
+ Project-URL: Homepage, https://github.com/nictuku/meta-ads-mcp
6
+ Project-URL: Bug Tracker, https://github.com/nictuku/meta-ads-mcp/issues
7
+ Author-email: Your Name <your.email@example.com>
8
+ License: MIT
9
+ Keywords: ads,api,claude,facebook,mcp,meta
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Requires-Python: >=3.11
14
+ Requires-Dist: httpx>=0.26.0
15
+ Requires-Dist: mcp[cli]>=1.6.0
16
+ Requires-Dist: pathlib>=1.0.1
17
+ Requires-Dist: pillow>=10.0.0
18
+ Requires-Dist: python-dotenv>=1.1.0
19
+ Requires-Dist: requests>=2.32.3
20
+ Description-Content-Type: text/markdown
21
+
22
+ # Meta Ads MCP
23
+
24
+ A [Model Calling Protocol (MCP)](https://github.com/anthropics/anthropic-tools) plugin for interacting with Meta Ads API.
25
+
26
+ ## Features
27
+
28
+ - Seamless authentication with Meta's Graph API for desktop applications
29
+ - Automatic token caching across sessions
30
+ - Cross-platform support (Windows, macOS, Linux)
31
+ - Access to ad accounts, campaigns, ad sets, and ads
32
+ - Image download and analysis capabilities
33
+ - Performance insights
34
+
35
+ ## Installation
36
+
37
+ ### Using uv (recommended)
38
+
39
+ When using uv no specific installation is needed. We can use uvx to directly run meta-ads-mcp:
40
+
41
+ ```bash
42
+ uvx meta-ads-mcp
43
+ ```
44
+
45
+ If you want to install the package:
46
+
47
+ ```bash
48
+ uv pip install meta-ads-mcp
49
+ ```
50
+
51
+ For development (if you've cloned the repository):
52
+
53
+ ```bash
54
+ # From the repository root
55
+ uv pip install -e .
56
+ ```
57
+
58
+ ### Using pip
59
+
60
+ Alternatively, you can install meta-ads-mcp via pip:
61
+
62
+ ```bash
63
+ pip install meta-ads-mcp
64
+ ```
65
+
66
+ After installation, you can run it as:
67
+
68
+ ```bash
69
+ python -m meta_ads_mcp
70
+ ```
71
+
72
+ ## Configuration
73
+
74
+ ### Usage with Claude in Cursor
75
+
76
+ Add this to your `claude_desktop_config.json` to integrate with Claude in Cursor:
77
+
78
+ ```json
79
+ "mcpServers": {
80
+ "meta-ads": {
81
+ "command": "uvx",
82
+ "args": ["meta-ads-mcp"]
83
+ }
84
+ }
85
+ ```
86
+
87
+ ### Available MCP Tools
88
+
89
+ 1. `mcp_meta_ads_get_ad_accounts`
90
+ - Get ad accounts accessible by a user
91
+ - Inputs:
92
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
93
+ - `user_id`: Meta user ID or "me" for the current user
94
+ - `limit`: Maximum number of accounts to return (default: 10)
95
+ - Returns: List of accessible ad accounts with their details
96
+
97
+ 2. `mcp_meta_ads_get_account_info`
98
+ - Get detailed information about a specific ad account
99
+ - Inputs:
100
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
101
+ - `account_id`: Meta Ads account ID (format: act_XXXXXXXXX)
102
+ - Returns: Detailed information about the specified account
103
+
104
+ 3. `mcp_meta_ads_get_campaigns`
105
+ - Get campaigns for a Meta Ads account with optional filtering
106
+ - Inputs:
107
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
108
+ - `account_id`: Meta Ads account ID (format: act_XXXXXXXXX)
109
+ - `limit`: Maximum number of campaigns to return (default: 10)
110
+ - `status_filter`: Filter by status (empty for all, or 'ACTIVE', 'PAUSED', etc.)
111
+ - Returns: List of campaigns matching the criteria
112
+
113
+ 4. `mcp_meta_ads_get_campaign_details`
114
+ - Get detailed information about a specific campaign
115
+ - Inputs:
116
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
117
+ - `campaign_id`: Meta Ads campaign ID
118
+ - Returns: Detailed information about the specified campaign
119
+
120
+ 5. `mcp_meta_ads_create_campaign`
121
+ - Create a new campaign in a Meta Ads account
122
+ - Inputs:
123
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
124
+ - `account_id`: Meta Ads account ID (format: act_XXXXXXXXX)
125
+ - `name`: Campaign name
126
+ - `objective`: Campaign objective (AWARENESS, TRAFFIC, ENGAGEMENT, etc.)
127
+ - `status`: Initial campaign status (default: PAUSED)
128
+ - `special_ad_categories`: List of special ad categories if applicable
129
+ - `daily_budget`: Daily budget in account currency (in cents)
130
+ - `lifetime_budget`: Lifetime budget in account currency (in cents)
131
+ - Returns: Confirmation with new campaign details
132
+
133
+ 6. `mcp_meta_ads_get_adsets`
134
+ - Get ad sets for a Meta Ads account with optional filtering by campaign
135
+ - Inputs:
136
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
137
+ - `account_id`: Meta Ads account ID (format: act_XXXXXXXXX)
138
+ - `limit`: Maximum number of ad sets to return (default: 10)
139
+ - `campaign_id`: Optional campaign ID to filter by
140
+ - Returns: List of ad sets matching the criteria
141
+
142
+ 7. `mcp_meta_ads_get_adset_details`
143
+ - Get detailed information about a specific ad set
144
+ - Inputs:
145
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
146
+ - `adset_id`: Meta Ads ad set ID
147
+ - Returns: Detailed information about the specified ad set
148
+
149
+ 8. `mcp_meta_ads_get_ads`
150
+ - Get ads for a Meta Ads account with optional filtering
151
+ - Inputs:
152
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
153
+ - `account_id`: Meta Ads account ID (format: act_XXXXXXXXX)
154
+ - `limit`: Maximum number of ads to return (default: 10)
155
+ - `campaign_id`: Optional campaign ID to filter by
156
+ - `adset_id`: Optional ad set ID to filter by
157
+ - Returns: List of ads matching the criteria
158
+
159
+ 9. `mcp_meta_ads_get_ad_details`
160
+ - Get detailed information about a specific ad
161
+ - Inputs:
162
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
163
+ - `ad_id`: Meta Ads ad ID
164
+ - Returns: Detailed information about the specified ad
165
+
166
+ 10. `mcp_meta_ads_get_ad_creatives`
167
+ - Get creative details for a specific ad
168
+ - Inputs:
169
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
170
+ - `ad_id`: Meta Ads ad ID
171
+ - Returns: Creative details including text, images, and URLs
172
+
173
+ 11. `mcp_meta_ads_get_ad_image`
174
+ - Get, download, and visualize a Meta ad image in one step
175
+ - Inputs:
176
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
177
+ - `ad_id`: Meta Ads ad ID
178
+ - Returns: The ad image ready for direct visual analysis
179
+
180
+ 12. `mcp_meta_ads_get_insights`
181
+ - Get performance insights for a campaign, ad set, ad or account
182
+ - Inputs:
183
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
184
+ - `object_id`: ID of the campaign, ad set, ad or account
185
+ - `time_range`: Time range for insights (default: maximum)
186
+ - `breakdown`: Optional breakdown dimension (e.g., age, gender, country)
187
+ - `level`: Level of aggregation (ad, adset, campaign, account)
188
+ - Returns: Performance metrics for the specified object
189
+
190
+ 13. `mcp_meta_ads_debug_image_download`
191
+ - Debug image download issues and report detailed diagnostics
192
+ - Inputs:
193
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
194
+ - `url`: Direct image URL to test (optional)
195
+ - `ad_id`: Meta Ads ad ID (optional, used if url is not provided)
196
+ - Returns: Diagnostic information about image download attempts
197
+
198
+ 14. `mcp_meta_ads_save_ad_image_via_api`
199
+ - Try to save an ad image by using the Marketing API's attachment endpoints
200
+ - Inputs:
201
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
202
+ - `ad_id`: Meta Ads ad ID
203
+ - Returns: Results of attempts to save the ad image
204
+
205
+ 15. `mcp_meta_ads_get_login_link`
206
+ - Get a clickable login link for Meta Ads authentication
207
+ - Inputs:
208
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
209
+ - Returns: A clickable resource link for Meta authentication
210
+
211
+ ## Create a Meta Developer App
212
+
213
+ Before using the MCP server, you'll need to set up a Meta Developer App:
214
+
215
+ 1. Go to [Meta for Developers](https://developers.facebook.com/) and create a new app
216
+ 2. Choose the "Consumer" app type
217
+ 3. In your app settings, add the "Marketing API" product
218
+ 4. Configure your app's OAuth redirect URI to include `http://localhost:8888/callback`
219
+ 5. Note your App ID (Client ID) for use with the MCP
220
+
221
+ ## Authentication
222
+
223
+ The Meta Ads MCP uses the OAuth 2.0 flow designed for desktop apps. When authenticating, it will:
224
+
225
+ 1. Start a local callback server on your machine
226
+ 2. Open a browser window to authenticate with Meta
227
+ 3. Ask you to authorize the app
228
+ 4. Redirect back to the local server to extract and store the token securely
229
+
230
+ ### Authentication Methods
231
+
232
+ There are two ways to authenticate with the Meta Ads API:
233
+
234
+ 1. **LLM/MCP Interface Authentication** (Recommended)
235
+
236
+ When using the Meta Ads MCP through an LLM interface (like Claude), simply use any Meta Ads function. If you're not authenticated, the system will automatically provide a clickable Markdown link to complete the authentication flow.
237
+
238
+ ```
239
+ [Click here to authenticate with Meta Ads API](https://www.facebook.com/dialog/oauth?...)
240
+ ```
241
+
242
+ Just click the link, complete the authorization in your browser, and the token will be automatically captured and stored.
243
+
244
+ 2. **Command Line Authentication**
245
+
246
+ You can authenticate directly from the command line:
247
+
248
+ ```bash
249
+ uvx meta-ads-mcp --login --app-id YOUR_APP_ID
250
+ ```
251
+
252
+ ### Token Caching
253
+
254
+ Tokens are cached in a platform-specific secure location:
255
+ - Windows: `%APPDATA%\meta-ads-mcp\token_cache.json`
256
+ - macOS: `~/Library/Application Support/meta-ads-mcp/token_cache.json`
257
+ - Linux: `~/.config/meta-ads-mcp/token_cache.json`
258
+
259
+ You do not need to provide your access token for each command; it will be automatically retrieved from the cache.
260
+
261
+ ## Environment Variables
262
+
263
+ You can set the following environment variables instead of passing them as arguments:
264
+
265
+ - `META_APP_ID`: Your Meta App ID (Client ID)
266
+
267
+ ## Testing
268
+
269
+ ### CLI Testing
270
+
271
+ Run the test script to verify authentication and basic functionality:
272
+
273
+ ```bash
274
+ python test_meta_ads_auth.py --app-id YOUR_APP_ID
275
+ ```
276
+
277
+ Use the `--force-login` flag to force a new authentication even if a cached token exists:
278
+
279
+ ```bash
280
+ python test_meta_ads_auth.py --app-id YOUR_APP_ID --force-login
281
+ ```
282
+
283
+ ### LLM Interface Testing
284
+
285
+ When using the Meta Ads MCP with an LLM interface (like Claude):
286
+
287
+ 1. Test authentication by calling the `mcp_meta_ads_get_login_link` tool
288
+ 2. Verify account access by calling `mcp_meta_ads_get_ad_accounts`
289
+ 3. Check specific account details with `mcp_meta_ads_get_account_info`
290
+
291
+ These functions will automatically handle authentication if needed and provide a clickable login link.
292
+
293
+ ## Troubleshooting
294
+
295
+ ### Authentication Issues
296
+
297
+ If you encounter authentication issues:
298
+
299
+ 1. When using the LLM interface:
300
+ - Use the `mcp_meta_ads_get_login_link` tool to generate a fresh authentication link
301
+ - Ensure you click the link and complete the authorization flow in your browser
302
+ - Check that the callback server is running properly (the tool will report this)
303
+
304
+ 2. When using the command line:
305
+ - Run with `--force-login` to get a fresh token: `uvx meta-ads-mcp --login --app-id YOUR_APP_ID --force-login`
306
+ - Make sure the terminal has permissions to open a browser window
307
+
308
+ 3. General authentication troubleshooting:
309
+ - Check that your app is properly configured in the Meta Developers portal
310
+ - Ensure your app has the necessary permissions (ads_management, ads_read, business_management)
311
+ - Verify the app's redirect URI includes `http://localhost:8888/callback`
312
+ - Try clearing the token cache (located in platform-specific directories listed in the Token Caching section)
313
+
314
+ ### API Errors
315
+
316
+ If you receive errors from the Meta API:
317
+
318
+ 1. Verify your app has the Marketing API product added
319
+ 2. Ensure the user has appropriate permissions on the ad accounts
320
+ 3. Check if there are rate limits or other restrictions on your app
321
+
322
+ ## Versioning
323
+
324
+ You can check the current version of the package:
325
+
326
+ ```python
327
+ import meta_ads_mcp
328
+ print(meta_ads_mcp.__version__)
329
+ ```
@@ -0,0 +1,308 @@
1
+ # Meta Ads MCP
2
+
3
+ A [Model Calling Protocol (MCP)](https://github.com/anthropics/anthropic-tools) plugin for interacting with Meta Ads API.
4
+
5
+ ## Features
6
+
7
+ - Seamless authentication with Meta's Graph API for desktop applications
8
+ - Automatic token caching across sessions
9
+ - Cross-platform support (Windows, macOS, Linux)
10
+ - Access to ad accounts, campaigns, ad sets, and ads
11
+ - Image download and analysis capabilities
12
+ - Performance insights
13
+
14
+ ## Installation
15
+
16
+ ### Using uv (recommended)
17
+
18
+ When using uv no specific installation is needed. We can use uvx to directly run meta-ads-mcp:
19
+
20
+ ```bash
21
+ uvx meta-ads-mcp
22
+ ```
23
+
24
+ If you want to install the package:
25
+
26
+ ```bash
27
+ uv pip install meta-ads-mcp
28
+ ```
29
+
30
+ For development (if you've cloned the repository):
31
+
32
+ ```bash
33
+ # From the repository root
34
+ uv pip install -e .
35
+ ```
36
+
37
+ ### Using pip
38
+
39
+ Alternatively, you can install meta-ads-mcp via pip:
40
+
41
+ ```bash
42
+ pip install meta-ads-mcp
43
+ ```
44
+
45
+ After installation, you can run it as:
46
+
47
+ ```bash
48
+ python -m meta_ads_mcp
49
+ ```
50
+
51
+ ## Configuration
52
+
53
+ ### Usage with Claude in Cursor
54
+
55
+ Add this to your `claude_desktop_config.json` to integrate with Claude in Cursor:
56
+
57
+ ```json
58
+ "mcpServers": {
59
+ "meta-ads": {
60
+ "command": "uvx",
61
+ "args": ["meta-ads-mcp"]
62
+ }
63
+ }
64
+ ```
65
+
66
+ ### Available MCP Tools
67
+
68
+ 1. `mcp_meta_ads_get_ad_accounts`
69
+ - Get ad accounts accessible by a user
70
+ - Inputs:
71
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
72
+ - `user_id`: Meta user ID or "me" for the current user
73
+ - `limit`: Maximum number of accounts to return (default: 10)
74
+ - Returns: List of accessible ad accounts with their details
75
+
76
+ 2. `mcp_meta_ads_get_account_info`
77
+ - Get detailed information about a specific ad account
78
+ - Inputs:
79
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
80
+ - `account_id`: Meta Ads account ID (format: act_XXXXXXXXX)
81
+ - Returns: Detailed information about the specified account
82
+
83
+ 3. `mcp_meta_ads_get_campaigns`
84
+ - Get campaigns for a Meta Ads account with optional filtering
85
+ - Inputs:
86
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
87
+ - `account_id`: Meta Ads account ID (format: act_XXXXXXXXX)
88
+ - `limit`: Maximum number of campaigns to return (default: 10)
89
+ - `status_filter`: Filter by status (empty for all, or 'ACTIVE', 'PAUSED', etc.)
90
+ - Returns: List of campaigns matching the criteria
91
+
92
+ 4. `mcp_meta_ads_get_campaign_details`
93
+ - Get detailed information about a specific campaign
94
+ - Inputs:
95
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
96
+ - `campaign_id`: Meta Ads campaign ID
97
+ - Returns: Detailed information about the specified campaign
98
+
99
+ 5. `mcp_meta_ads_create_campaign`
100
+ - Create a new campaign in a Meta Ads account
101
+ - Inputs:
102
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
103
+ - `account_id`: Meta Ads account ID (format: act_XXXXXXXXX)
104
+ - `name`: Campaign name
105
+ - `objective`: Campaign objective (AWARENESS, TRAFFIC, ENGAGEMENT, etc.)
106
+ - `status`: Initial campaign status (default: PAUSED)
107
+ - `special_ad_categories`: List of special ad categories if applicable
108
+ - `daily_budget`: Daily budget in account currency (in cents)
109
+ - `lifetime_budget`: Lifetime budget in account currency (in cents)
110
+ - Returns: Confirmation with new campaign details
111
+
112
+ 6. `mcp_meta_ads_get_adsets`
113
+ - Get ad sets for a Meta Ads account with optional filtering by campaign
114
+ - Inputs:
115
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
116
+ - `account_id`: Meta Ads account ID (format: act_XXXXXXXXX)
117
+ - `limit`: Maximum number of ad sets to return (default: 10)
118
+ - `campaign_id`: Optional campaign ID to filter by
119
+ - Returns: List of ad sets matching the criteria
120
+
121
+ 7. `mcp_meta_ads_get_adset_details`
122
+ - Get detailed information about a specific ad set
123
+ - Inputs:
124
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
125
+ - `adset_id`: Meta Ads ad set ID
126
+ - Returns: Detailed information about the specified ad set
127
+
128
+ 8. `mcp_meta_ads_get_ads`
129
+ - Get ads for a Meta Ads account with optional filtering
130
+ - Inputs:
131
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
132
+ - `account_id`: Meta Ads account ID (format: act_XXXXXXXXX)
133
+ - `limit`: Maximum number of ads to return (default: 10)
134
+ - `campaign_id`: Optional campaign ID to filter by
135
+ - `adset_id`: Optional ad set ID to filter by
136
+ - Returns: List of ads matching the criteria
137
+
138
+ 9. `mcp_meta_ads_get_ad_details`
139
+ - Get detailed information about a specific ad
140
+ - Inputs:
141
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
142
+ - `ad_id`: Meta Ads ad ID
143
+ - Returns: Detailed information about the specified ad
144
+
145
+ 10. `mcp_meta_ads_get_ad_creatives`
146
+ - Get creative details for a specific ad
147
+ - Inputs:
148
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
149
+ - `ad_id`: Meta Ads ad ID
150
+ - Returns: Creative details including text, images, and URLs
151
+
152
+ 11. `mcp_meta_ads_get_ad_image`
153
+ - Get, download, and visualize a Meta ad image in one step
154
+ - Inputs:
155
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
156
+ - `ad_id`: Meta Ads ad ID
157
+ - Returns: The ad image ready for direct visual analysis
158
+
159
+ 12. `mcp_meta_ads_get_insights`
160
+ - Get performance insights for a campaign, ad set, ad or account
161
+ - Inputs:
162
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
163
+ - `object_id`: ID of the campaign, ad set, ad or account
164
+ - `time_range`: Time range for insights (default: maximum)
165
+ - `breakdown`: Optional breakdown dimension (e.g., age, gender, country)
166
+ - `level`: Level of aggregation (ad, adset, campaign, account)
167
+ - Returns: Performance metrics for the specified object
168
+
169
+ 13. `mcp_meta_ads_debug_image_download`
170
+ - Debug image download issues and report detailed diagnostics
171
+ - Inputs:
172
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
173
+ - `url`: Direct image URL to test (optional)
174
+ - `ad_id`: Meta Ads ad ID (optional, used if url is not provided)
175
+ - Returns: Diagnostic information about image download attempts
176
+
177
+ 14. `mcp_meta_ads_save_ad_image_via_api`
178
+ - Try to save an ad image by using the Marketing API's attachment endpoints
179
+ - Inputs:
180
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
181
+ - `ad_id`: Meta Ads ad ID
182
+ - Returns: Results of attempts to save the ad image
183
+
184
+ 15. `mcp_meta_ads_get_login_link`
185
+ - Get a clickable login link for Meta Ads authentication
186
+ - Inputs:
187
+ - `access_token` (optional): Meta API access token (will use cached token if not provided)
188
+ - Returns: A clickable resource link for Meta authentication
189
+
190
+ ## Create a Meta Developer App
191
+
192
+ Before using the MCP server, you'll need to set up a Meta Developer App:
193
+
194
+ 1. Go to [Meta for Developers](https://developers.facebook.com/) and create a new app
195
+ 2. Choose the "Consumer" app type
196
+ 3. In your app settings, add the "Marketing API" product
197
+ 4. Configure your app's OAuth redirect URI to include `http://localhost:8888/callback`
198
+ 5. Note your App ID (Client ID) for use with the MCP
199
+
200
+ ## Authentication
201
+
202
+ The Meta Ads MCP uses the OAuth 2.0 flow designed for desktop apps. When authenticating, it will:
203
+
204
+ 1. Start a local callback server on your machine
205
+ 2. Open a browser window to authenticate with Meta
206
+ 3. Ask you to authorize the app
207
+ 4. Redirect back to the local server to extract and store the token securely
208
+
209
+ ### Authentication Methods
210
+
211
+ There are two ways to authenticate with the Meta Ads API:
212
+
213
+ 1. **LLM/MCP Interface Authentication** (Recommended)
214
+
215
+ When using the Meta Ads MCP through an LLM interface (like Claude), simply use any Meta Ads function. If you're not authenticated, the system will automatically provide a clickable Markdown link to complete the authentication flow.
216
+
217
+ ```
218
+ [Click here to authenticate with Meta Ads API](https://www.facebook.com/dialog/oauth?...)
219
+ ```
220
+
221
+ Just click the link, complete the authorization in your browser, and the token will be automatically captured and stored.
222
+
223
+ 2. **Command Line Authentication**
224
+
225
+ You can authenticate directly from the command line:
226
+
227
+ ```bash
228
+ uvx meta-ads-mcp --login --app-id YOUR_APP_ID
229
+ ```
230
+
231
+ ### Token Caching
232
+
233
+ Tokens are cached in a platform-specific secure location:
234
+ - Windows: `%APPDATA%\meta-ads-mcp\token_cache.json`
235
+ - macOS: `~/Library/Application Support/meta-ads-mcp/token_cache.json`
236
+ - Linux: `~/.config/meta-ads-mcp/token_cache.json`
237
+
238
+ You do not need to provide your access token for each command; it will be automatically retrieved from the cache.
239
+
240
+ ## Environment Variables
241
+
242
+ You can set the following environment variables instead of passing them as arguments:
243
+
244
+ - `META_APP_ID`: Your Meta App ID (Client ID)
245
+
246
+ ## Testing
247
+
248
+ ### CLI Testing
249
+
250
+ Run the test script to verify authentication and basic functionality:
251
+
252
+ ```bash
253
+ python test_meta_ads_auth.py --app-id YOUR_APP_ID
254
+ ```
255
+
256
+ Use the `--force-login` flag to force a new authentication even if a cached token exists:
257
+
258
+ ```bash
259
+ python test_meta_ads_auth.py --app-id YOUR_APP_ID --force-login
260
+ ```
261
+
262
+ ### LLM Interface Testing
263
+
264
+ When using the Meta Ads MCP with an LLM interface (like Claude):
265
+
266
+ 1. Test authentication by calling the `mcp_meta_ads_get_login_link` tool
267
+ 2. Verify account access by calling `mcp_meta_ads_get_ad_accounts`
268
+ 3. Check specific account details with `mcp_meta_ads_get_account_info`
269
+
270
+ These functions will automatically handle authentication if needed and provide a clickable login link.
271
+
272
+ ## Troubleshooting
273
+
274
+ ### Authentication Issues
275
+
276
+ If you encounter authentication issues:
277
+
278
+ 1. When using the LLM interface:
279
+ - Use the `mcp_meta_ads_get_login_link` tool to generate a fresh authentication link
280
+ - Ensure you click the link and complete the authorization flow in your browser
281
+ - Check that the callback server is running properly (the tool will report this)
282
+
283
+ 2. When using the command line:
284
+ - Run with `--force-login` to get a fresh token: `uvx meta-ads-mcp --login --app-id YOUR_APP_ID --force-login`
285
+ - Make sure the terminal has permissions to open a browser window
286
+
287
+ 3. General authentication troubleshooting:
288
+ - Check that your app is properly configured in the Meta Developers portal
289
+ - Ensure your app has the necessary permissions (ads_management, ads_read, business_management)
290
+ - Verify the app's redirect URI includes `http://localhost:8888/callback`
291
+ - Try clearing the token cache (located in platform-specific directories listed in the Token Caching section)
292
+
293
+ ### API Errors
294
+
295
+ If you receive errors from the Meta API:
296
+
297
+ 1. Verify your app has the Marketing API product added
298
+ 2. Ensure the user has appropriate permissions on the ad accounts
299
+ 3. Check if there are rate limits or other restrictions on your app
300
+
301
+ ## Versioning
302
+
303
+ You can check the current version of the package:
304
+
305
+ ```python
306
+ import meta_ads_mcp
307
+ print(meta_ads_mcp.__version__)
308
+ ```