meta-ads-mcp 0.2.0__tar.gz → 0.2.1__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.
@@ -0,0 +1,329 @@
1
+ Metadata-Version: 2.4
2
+ Name: meta-ads-mcp
3
+ Version: 0.2.1
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
+ ```
@@ -1,6 +1,6 @@
1
1
  """Meta Ads MCP - Model Calling Protocol plugin for Meta Ads API."""
2
2
 
3
- __version__ = "0.2.0"
3
+ __version__ = "0.2.1"
4
4
 
5
5
  # Import key functions to make them available at package level
6
6
  from .api import (
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "meta-ads-mcp"
7
- version = "0.2.0"
7
+ version = "0.2.1"
8
8
  description = "Model Calling Protocol (MCP) plugin for interacting with Meta Ads API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -33,7 +33,6 @@ dependencies = [
33
33
 
34
34
  [project.scripts]
35
35
  meta-ads-mcp = "meta_ads_mcp:entrypoint"
36
- meta-ads-login = "meta_ads_mcp.api:login_cli"
37
36
 
38
37
  [tool.hatch.build.targets.wheel]
39
38
  packages = ["meta_ads_mcp"]
@@ -1,250 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: meta-ads-mcp
3
- Version: 0.2.0
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
- ## Setup
36
-
37
- ### 1. Create a Meta Developer App
38
-
39
- 1. Go to [Meta for Developers](https://developers.facebook.com/) and create a new app
40
- 2. Choose the "Consumer" app type
41
- 3. In your app settings, add the "Marketing API" product
42
- 4. Configure your app's OAuth redirect URI to include `http://localhost:8888/callback`
43
- 5. Note your App ID (Client ID) for use with the MCP
44
-
45
- ### 2. Install the Package
46
-
47
- #### Using uv (Recommended)
48
-
49
- Install directly from GitHub:
50
-
51
- ```bash
52
- uv pip install git+https://github.com/nictuku/meta-ads-mcp.git
53
- ```
54
-
55
- Or if you've cloned the repository:
56
-
57
- ```bash
58
- # From the repository root
59
- uv pip install -e .
60
- ```
61
-
62
- #### Using pip
63
-
64
- ```bash
65
- pip install git+https://github.com/nictuku/meta-ads-mcp.git
66
- ```
67
-
68
- ### 3. Install Dependencies (If installing from source)
69
-
70
- ```bash
71
- uv pip install -r requirements.txt
72
- ```
73
-
74
- Or:
75
-
76
- ```bash
77
- pip install -r requirements.txt
78
- ```
79
-
80
- ## Authentication
81
-
82
- The Meta Ads MCP uses the OAuth 2.0 flow designed for desktop apps. When authenticating, it will:
83
-
84
- 1. Start a local callback server on your machine
85
- 2. Open a browser window to authenticate with Meta
86
- 3. Ask you to authorize the app
87
- 4. Redirect back to the local server to extract and store the token securely
88
-
89
- ### Authentication Methods
90
-
91
- There are two ways to authenticate with the Meta Ads API:
92
-
93
- 1. **LLM/MCP Interface Authentication** (Recommended)
94
-
95
- 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.
96
-
97
- ```
98
- [Click here to authenticate with Meta Ads API](https://www.facebook.com/dialog/oauth?...)
99
- ```
100
-
101
- Just click the link, complete the authorization in your browser, and the token will be automatically captured and stored.
102
-
103
- 2. **Command Line Authentication**
104
-
105
- You can also initiate authentication directly from the command line:
106
-
107
- ```bash
108
- python meta_ads_generated.py --login --app-id YOUR_APP_ID
109
- ```
110
-
111
- Or use the convenience scripts:
112
-
113
- ```bash
114
- # On macOS/Linux
115
- ./login.sh YOUR_APP_ID
116
-
117
- # On Windows
118
- login.bat YOUR_APP_ID
119
- ```
120
-
121
- ### Token Caching
122
-
123
- Tokens are cached in a platform-specific secure location:
124
- - Windows: `%APPDATA%\meta-ads-mcp\token_cache.json`
125
- - macOS: `~/Library/Application Support/meta-ads-mcp/token_cache.json`
126
- - Linux: `~/.config/meta-ads-mcp/token_cache.json`
127
-
128
- You do not need to provide your access token for each command; it will be automatically retrieved from the cache.
129
-
130
- ## Usage Examples
131
-
132
- ### Test Authentication
133
-
134
- ```bash
135
- python test_meta_ads_auth.py --app-id YOUR_APP_ID
136
- ```
137
-
138
- ### Get Ad Accounts
139
-
140
- ```python
141
- import asyncio
142
- from meta_ads_mcp import get_ad_accounts
143
-
144
- async def main():
145
- # Token will be automatically retrieved from cache
146
- accounts_json = await get_ad_accounts()
147
- print(accounts_json)
148
-
149
- asyncio.run(main())
150
- ```
151
-
152
- ### Get Campaign Details
153
-
154
- ```python
155
- import asyncio
156
- from meta_ads_mcp import get_campaign_details
157
-
158
- async def main():
159
- # Provide a campaign ID
160
- campaign_details = await get_campaign_details(campaign_id="123456789")
161
- print(campaign_details)
162
-
163
- asyncio.run(main())
164
- ```
165
-
166
- ### Create a Campaign
167
-
168
- ```python
169
- import asyncio
170
- from meta_ads_mcp import create_campaign
171
-
172
- async def main():
173
- result = await create_campaign(
174
- account_id="act_123456789",
175
- name="Test Campaign via MCP",
176
- objective="AWARENESS",
177
- status="PAUSED",
178
- daily_budget=1000 # $10.00
179
- )
180
- print(result)
181
-
182
- asyncio.run(main())
183
- ```
184
-
185
- ## Environment Variables
186
-
187
- You can set the following environment variables instead of passing them as arguments:
188
-
189
- - `META_APP_ID`: Your Meta App ID (Client ID)
190
-
191
- ## Testing
192
-
193
- ### CLI Testing
194
-
195
- Run the test script to verify authentication and basic functionality:
196
-
197
- ```bash
198
- python test_meta_ads_auth.py --app-id YOUR_APP_ID
199
- ```
200
-
201
- Use the `--force-login` flag to force a new authentication even if a cached token exists:
202
-
203
- ```bash
204
- python test_meta_ads_auth.py --app-id YOUR_APP_ID --force-login
205
- ```
206
-
207
- ### LLM Interface Testing
208
-
209
- When using the Meta Ads MCP with an LLM interface (like Claude):
210
-
211
- 1. Test authentication by calling the `get_login_link` tool
212
- 2. Verify account access by calling `get_ad_accounts`
213
- 3. Check specific account details with `get_account_info`
214
-
215
- These functions will automatically handle authentication if needed and provide a clickable login link.
216
-
217
- ## Troubleshooting
218
-
219
- ### Authentication Issues
220
-
221
- If you encounter authentication issues:
222
-
223
- 1. When using the LLM interface:
224
- - Use the `get_login_link` tool to generate a fresh authentication link
225
- - Ensure you click the link and complete the authorization flow in your browser
226
- - Check that the callback server is running properly (the tool will report this)
227
-
228
- 2. When using the command line:
229
- - Run with `--force-login` to get a fresh token: `python meta_ads_generated.py --login --app-id YOUR_APP_ID --force-login`
230
- - Make sure the terminal has permissions to open a browser window
231
-
232
- 3. General authentication troubleshooting:
233
- - Check that your app is properly configured in the Meta Developers portal
234
- - Ensure your app has the necessary permissions (ads_management, ads_read, business_management)
235
- - Verify the app's redirect URI includes `http://localhost:8888/callback`
236
- - Try clearing the token cache (located in platform-specific directories listed in the Token Caching section)
237
-
238
- ### API Errors
239
-
240
- If you receive errors from the Meta API:
241
-
242
- 1. Verify your app has the Marketing API product added
243
- 2. Ensure the user has appropriate permissions on the ad accounts
244
- 3. Check if there are rate limits or other restrictions on your app
245
-
246
- ## Files
247
-
248
- This repository contains the implementation for the Meta Ads Marketing API Client Protocol (MCP).
249
-
250
- - `meta_ads_generated.py`: The main MCP implementation for Meta Ads API
@@ -1,229 +0,0 @@
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
- ## Setup
15
-
16
- ### 1. Create a Meta Developer App
17
-
18
- 1. Go to [Meta for Developers](https://developers.facebook.com/) and create a new app
19
- 2. Choose the "Consumer" app type
20
- 3. In your app settings, add the "Marketing API" product
21
- 4. Configure your app's OAuth redirect URI to include `http://localhost:8888/callback`
22
- 5. Note your App ID (Client ID) for use with the MCP
23
-
24
- ### 2. Install the Package
25
-
26
- #### Using uv (Recommended)
27
-
28
- Install directly from GitHub:
29
-
30
- ```bash
31
- uv pip install git+https://github.com/nictuku/meta-ads-mcp.git
32
- ```
33
-
34
- Or if you've cloned the repository:
35
-
36
- ```bash
37
- # From the repository root
38
- uv pip install -e .
39
- ```
40
-
41
- #### Using pip
42
-
43
- ```bash
44
- pip install git+https://github.com/nictuku/meta-ads-mcp.git
45
- ```
46
-
47
- ### 3. Install Dependencies (If installing from source)
48
-
49
- ```bash
50
- uv pip install -r requirements.txt
51
- ```
52
-
53
- Or:
54
-
55
- ```bash
56
- pip install -r requirements.txt
57
- ```
58
-
59
- ## Authentication
60
-
61
- The Meta Ads MCP uses the OAuth 2.0 flow designed for desktop apps. When authenticating, it will:
62
-
63
- 1. Start a local callback server on your machine
64
- 2. Open a browser window to authenticate with Meta
65
- 3. Ask you to authorize the app
66
- 4. Redirect back to the local server to extract and store the token securely
67
-
68
- ### Authentication Methods
69
-
70
- There are two ways to authenticate with the Meta Ads API:
71
-
72
- 1. **LLM/MCP Interface Authentication** (Recommended)
73
-
74
- 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.
75
-
76
- ```
77
- [Click here to authenticate with Meta Ads API](https://www.facebook.com/dialog/oauth?...)
78
- ```
79
-
80
- Just click the link, complete the authorization in your browser, and the token will be automatically captured and stored.
81
-
82
- 2. **Command Line Authentication**
83
-
84
- You can also initiate authentication directly from the command line:
85
-
86
- ```bash
87
- python meta_ads_generated.py --login --app-id YOUR_APP_ID
88
- ```
89
-
90
- Or use the convenience scripts:
91
-
92
- ```bash
93
- # On macOS/Linux
94
- ./login.sh YOUR_APP_ID
95
-
96
- # On Windows
97
- login.bat YOUR_APP_ID
98
- ```
99
-
100
- ### Token Caching
101
-
102
- Tokens are cached in a platform-specific secure location:
103
- - Windows: `%APPDATA%\meta-ads-mcp\token_cache.json`
104
- - macOS: `~/Library/Application Support/meta-ads-mcp/token_cache.json`
105
- - Linux: `~/.config/meta-ads-mcp/token_cache.json`
106
-
107
- You do not need to provide your access token for each command; it will be automatically retrieved from the cache.
108
-
109
- ## Usage Examples
110
-
111
- ### Test Authentication
112
-
113
- ```bash
114
- python test_meta_ads_auth.py --app-id YOUR_APP_ID
115
- ```
116
-
117
- ### Get Ad Accounts
118
-
119
- ```python
120
- import asyncio
121
- from meta_ads_mcp import get_ad_accounts
122
-
123
- async def main():
124
- # Token will be automatically retrieved from cache
125
- accounts_json = await get_ad_accounts()
126
- print(accounts_json)
127
-
128
- asyncio.run(main())
129
- ```
130
-
131
- ### Get Campaign Details
132
-
133
- ```python
134
- import asyncio
135
- from meta_ads_mcp import get_campaign_details
136
-
137
- async def main():
138
- # Provide a campaign ID
139
- campaign_details = await get_campaign_details(campaign_id="123456789")
140
- print(campaign_details)
141
-
142
- asyncio.run(main())
143
- ```
144
-
145
- ### Create a Campaign
146
-
147
- ```python
148
- import asyncio
149
- from meta_ads_mcp import create_campaign
150
-
151
- async def main():
152
- result = await create_campaign(
153
- account_id="act_123456789",
154
- name="Test Campaign via MCP",
155
- objective="AWARENESS",
156
- status="PAUSED",
157
- daily_budget=1000 # $10.00
158
- )
159
- print(result)
160
-
161
- asyncio.run(main())
162
- ```
163
-
164
- ## Environment Variables
165
-
166
- You can set the following environment variables instead of passing them as arguments:
167
-
168
- - `META_APP_ID`: Your Meta App ID (Client ID)
169
-
170
- ## Testing
171
-
172
- ### CLI Testing
173
-
174
- Run the test script to verify authentication and basic functionality:
175
-
176
- ```bash
177
- python test_meta_ads_auth.py --app-id YOUR_APP_ID
178
- ```
179
-
180
- Use the `--force-login` flag to force a new authentication even if a cached token exists:
181
-
182
- ```bash
183
- python test_meta_ads_auth.py --app-id YOUR_APP_ID --force-login
184
- ```
185
-
186
- ### LLM Interface Testing
187
-
188
- When using the Meta Ads MCP with an LLM interface (like Claude):
189
-
190
- 1. Test authentication by calling the `get_login_link` tool
191
- 2. Verify account access by calling `get_ad_accounts`
192
- 3. Check specific account details with `get_account_info`
193
-
194
- These functions will automatically handle authentication if needed and provide a clickable login link.
195
-
196
- ## Troubleshooting
197
-
198
- ### Authentication Issues
199
-
200
- If you encounter authentication issues:
201
-
202
- 1. When using the LLM interface:
203
- - Use the `get_login_link` tool to generate a fresh authentication link
204
- - Ensure you click the link and complete the authorization flow in your browser
205
- - Check that the callback server is running properly (the tool will report this)
206
-
207
- 2. When using the command line:
208
- - Run with `--force-login` to get a fresh token: `python meta_ads_generated.py --login --app-id YOUR_APP_ID --force-login`
209
- - Make sure the terminal has permissions to open a browser window
210
-
211
- 3. General authentication troubleshooting:
212
- - Check that your app is properly configured in the Meta Developers portal
213
- - Ensure your app has the necessary permissions (ads_management, ads_read, business_management)
214
- - Verify the app's redirect URI includes `http://localhost:8888/callback`
215
- - Try clearing the token cache (located in platform-specific directories listed in the Token Caching section)
216
-
217
- ### API Errors
218
-
219
- If you receive errors from the Meta API:
220
-
221
- 1. Verify your app has the Marketing API product added
222
- 2. Ensure the user has appropriate permissions on the ad accounts
223
- 3. Check if there are rate limits or other restrictions on your app
224
-
225
- ## Files
226
-
227
- This repository contains the implementation for the Meta Ads Marketing API Client Protocol (MCP).
228
-
229
- - `meta_ads_generated.py`: The main MCP implementation for Meta Ads API
@@ -1,18 +0,0 @@
1
- @echo off
2
- REM Simple script to log in to Meta Ads MCP on Windows
3
-
4
- SET APP_ID=%1
5
-
6
- IF "%APP_ID%"=="" (
7
- IF NOT "%META_APP_ID%"=="" (
8
- SET APP_ID=%META_APP_ID%
9
- ) ELSE (
10
- echo Error: No Meta App ID provided.
11
- echo Usage: login.bat YOUR_APP_ID
12
- echo or set the META_APP_ID environment variable.
13
- exit /b 1
14
- )
15
- )
16
-
17
- echo Starting Meta Ads authentication with App ID: %APP_ID%
18
- python meta_ads_generated.py --login --app-id "%APP_ID%"
@@ -1,17 +0,0 @@
1
- #!/bin/bash
2
- # Simple script to log in to Meta Ads MCP
3
-
4
- # Check for app ID in argument or environment variable
5
- if [ "$1" != "" ]; then
6
- APP_ID="$1"
7
- elif [ "$META_APP_ID" != "" ]; then
8
- APP_ID="$META_APP_ID"
9
- else
10
- echo "Error: No Meta App ID provided."
11
- echo "Usage: ./login.sh YOUR_APP_ID"
12
- echo " or set the META_APP_ID environment variable."
13
- exit 1
14
- fi
15
-
16
- echo "Starting Meta Ads authentication with App ID: $APP_ID"
17
- python meta_ads_generated.py --login --app-id "$APP_ID"
File without changes
File without changes
File without changes
File without changes
File without changes