meta-ads-mcp 0.2.5__py3-none-any.whl → 0.2.6__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 CHANGED
@@ -7,7 +7,7 @@ with the Claude LLM.
7
7
 
8
8
  from meta_ads_mcp.core.server import main
9
9
 
10
- __version__ = "0.2.5"
10
+ __version__ = "0.2.6"
11
11
 
12
12
  __all__ = [
13
13
  'get_ad_accounts',
@@ -22,6 +22,7 @@ __all__ = [
22
22
  'get_ad_details',
23
23
  'get_ad_creatives',
24
24
  'get_ad_image',
25
+ 'update_ad',
25
26
  'get_insights',
26
27
  'debug_image_download',
27
28
  'get_login_link',
@@ -43,6 +44,7 @@ from .core import (
43
44
  get_ad_details,
44
45
  get_ad_creatives,
45
46
  get_ad_image,
47
+ update_ad,
46
48
  get_insights,
47
49
  debug_image_download,
48
50
  get_login_link,
meta_ads_mcp/core/ads.py CHANGED
@@ -363,4 +363,64 @@ async def get_ad_image(access_token: str = None, ad_id: str = None) -> Image:
363
363
  return Image(data=img_bytes, format="jpeg")
364
364
 
365
365
  except Exception as e:
366
- return f"Error processing image: {str(e)}"
366
+ return f"Error processing image: {str(e)}"
367
+
368
+
369
+ @mcp_server.tool()
370
+ @meta_api_tool
371
+ async def update_ad(ad_id: str, status: str = None, bid_amount: int = None, access_token: str = None) -> str:
372
+ """
373
+ Update an ad with new settings.
374
+
375
+ Args:
376
+ ad_id: Meta Ads ad ID
377
+ status: Update ad status (ACTIVE, PAUSED, etc.)
378
+ bid_amount: Bid amount in account currency (in cents for USD)
379
+ access_token: Meta API access token (optional - will use cached token if not provided)
380
+ """
381
+ if not ad_id:
382
+ return json.dumps({"error": "No ad ID provided"}, indent=2)
383
+
384
+ changes = {}
385
+
386
+ if status is not None:
387
+ changes['status'] = status
388
+
389
+ if bid_amount is not None:
390
+ changes['bid_amount'] = bid_amount
391
+
392
+ if not changes:
393
+ return json.dumps({"error": "No update parameters provided"}, indent=2)
394
+
395
+ # Get current ad details for comparison
396
+ current_details_json = await get_ad_details(ad_id=ad_id, access_token=access_token)
397
+ current_details = json.loads(current_details_json)
398
+
399
+ # Import the callback server components
400
+ from .callback_server import start_callback_server, update_confirmation
401
+ import urllib.parse
402
+
403
+ # Start the callback server if not already running
404
+ port = start_callback_server()
405
+
406
+ # Generate confirmation URL with properly encoded parameters
407
+ changes_json = json.dumps(changes)
408
+ encoded_changes = urllib.parse.quote(changes_json)
409
+ confirmation_url = f"http://localhost:{port}/confirm-update?ad_id={ad_id}&token={access_token}&changes={encoded_changes}"
410
+
411
+ # Reset the update confirmation
412
+ update_confirmation.clear()
413
+ update_confirmation.update({"approved": False})
414
+
415
+ # Return the confirmation link
416
+ response = {
417
+ "message": "Please confirm the ad update",
418
+ "confirmation_url": confirmation_url,
419
+ "markdown_link": f"[Click here to confirm ad update]({confirmation_url})",
420
+ "current_details": current_details,
421
+ "proposed_changes": changes,
422
+ "instructions_for_llm": "You must present this link as clickable Markdown to the user using the markdown_link format provided.",
423
+ "note": "After authenticating, the token will be automatically saved and your ad will be updated. Refresh the browser page if it doesn't load immediately."
424
+ }
425
+
426
+ return json.dumps(response, indent=2)
@@ -6,7 +6,7 @@ from .api import meta_api_tool, make_api_request
6
6
  from .accounts import get_ad_accounts
7
7
  from .server import mcp_server
8
8
  import asyncio
9
- from .auth import start_callback_server, update_confirmation
9
+ from .callback_server import start_callback_server, update_confirmation
10
10
  import urllib.parse
11
11
 
12
12