meta-ads-mcp 0.1.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.
@@ -0,0 +1,12 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+ .cursor/rules/meta-ads-credentials.mdc
12
+ .DS_Store
@@ -0,0 +1 @@
1
+ 3.11
@@ -0,0 +1,2 @@
1
+ [uv]
2
+ python-path = ["python3.11"]
@@ -0,0 +1,250 @@
1
+ Metadata-Version: 2.4
2
+ Name: meta-ads-mcp
3
+ Version: 0.1.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
@@ -0,0 +1,229 @@
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
@@ -0,0 +1,18 @@
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%"
@@ -0,0 +1,17 @@
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"