Skip to main content
Glama

update_ad

Modify Meta advertising campaign settings including status, bid amount, creative content, and tracking specifications to optimize ad performance.

Instructions

Update an ad with new settings.

Args:
    ad_id: Meta Ads ad ID
    status: Update ad status (ACTIVE, PAUSED, etc.)
    bid_amount: Bid amount in account currency (in cents for USD)
    tracking_specs: Optional tracking specifications (e.g., for pixel events).
    creative_id: ID of the creative to associate with this ad (changes the ad's image/content)
    access_token: Meta API access token (optional - will use cached token if not provided)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ad_idYes
statusNo
bid_amountNo
tracking_specsNo
creative_idNo
access_tokenNo

Implementation Reference

  • The main handler function for the 'update_ad' MCP tool. It updates Meta Ads ad properties such as status, bid_amount, tracking_specs, or swaps the creative using creative_id. Decorated with @mcp_server.tool() for MCP registration and @meta_api_tool for API handling.
    @mcp_server.tool()
    @meta_api_tool
    async def update_ad(
        ad_id: str,
        status: Optional[str] = None,
        bid_amount: Optional[int] = None,
        tracking_specs: Optional[List[Dict[str, Any]]] = None,
        creative_id: Optional[str] = None,
        access_token: Optional[str] = None
    ) -> str:
        """
        Update an ad with new settings.
        
        Args:
            ad_id: Meta Ads ad ID
            status: Update ad status (ACTIVE, PAUSED, etc.)
            bid_amount: Bid amount in account currency (in cents for USD)
            tracking_specs: Optional tracking specifications (e.g., for pixel events).
            creative_id: ID of the creative to associate with this ad (changes the ad's image/content)
            access_token: Meta API access token (optional - will use cached token if not provided)
        """
        if not ad_id:
            return json.dumps({"error": "Ad ID is required"}, indent=2)
    
        params = {}
        if status:
            params["status"] = status
        if bid_amount is not None:
            # Ensure bid_amount is sent as a string if it's not null
            params["bid_amount"] = str(bid_amount)
        if tracking_specs is not None: # Add tracking_specs to params if provided
            params["tracking_specs"] = json.dumps(tracking_specs) # Needs to be JSON encoded string
        if creative_id is not None:
            # Creative parameter needs to be a JSON object containing creative_id
            params["creative"] = json.dumps({"creative_id": creative_id})
    
        if not params:
            return json.dumps({"error": "No update parameters provided (status, bid_amount, tracking_specs, or creative_id)"}, indent=2)
    
        endpoint = f"{ad_id}"
        try:
            data = await make_api_request(endpoint, access_token, params, method='POST')
            return json.dumps(data, indent=2)
        except Exception as e:
            return json.dumps({"error": f"Failed to update ad: {str(e)}"}, indent=2)
  • Package-level export of the update_ad function in __all__ for easy import.
        'update_ad',
        'get_insights',
        # 'get_login_link' is conditionally exported via core.__all__
        'login_cli',
        'main',
        'search_interests',
        'get_interest_suggestions',
        'estimate_audience_size',
        'search_behaviors',
        'search_demographics',
        'search_geo_locations'
    ]
  • Import of update_ad from core module to make it available at package level.
        update_ad,
        get_insights,
        login_cli,
        main,
        search_interests,
        get_interest_suggestions,
        estimate_audience_size,
        search_behaviors,
        search_demographics,
        search_geo_locations
    )

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pipeboard-co/meta-ads-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server