Skip to main content
Glama

update_adset

Modify ad set parameters including frequency caps, budgets, targeting, and bid strategies to optimize campaign performance on Meta platforms.

Instructions

Update an ad set with new settings including frequency caps and budgets.

Args:
    adset_id: Meta Ads ad set ID
    frequency_control_specs: List of frequency control specifications 
                             (e.g. [{"event": "IMPRESSIONS", "interval_days": 7, "max_frequency": 3}])
    bid_strategy: Bid strategy (e.g., 'LOWEST_COST_WITH_BID_CAP')
    bid_amount: Bid amount in account currency (in cents for USD)
    status: Update ad set status (ACTIVE, PAUSED, etc.)
    targeting: Complete targeting specifications (will replace existing targeting)
              (e.g. {"targeting_automation":{"advantage_audience":1}, "geo_locations": {"countries": ["US"]}})
    optimization_goal: Conversion optimization goal (e.g., 'LINK_CLICKS', 'CONVERSIONS', 'APP_INSTALLS', etc.)
    daily_budget: Daily budget in account currency (in cents) as a string
    lifetime_budget: Lifetime budget in account currency (in cents) as a string
    is_dynamic_creative: Enable/disable Dynamic Creative for this ad set.
    access_token: Meta API access token (optional - will use cached token if not provided)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
adset_idYes
frequency_control_specsNo
bid_strategyNo
bid_amountNo
statusNo
targetingNo
optimization_goalNo
daily_budgetNo
lifetime_budgetNo
is_dynamic_creativeNo
access_tokenNo

Implementation Reference

  • The primary handler function for the 'update_adset' tool. Decorated with @mcp_server.tool() which registers it as an MCP tool. Implements the logic to update a Meta Ads adset via API call with various parameters like budgets, targeting, frequency controls, etc.
    @mcp_server.tool()
    @meta_api_tool
    async def update_adset(adset_id: str, frequency_control_specs: Optional[List[Dict[str, Any]]] = None, bid_strategy: Optional[str] = None, 
                            bid_amount: Optional[int] = None, status: Optional[str] = None, targeting: Optional[Dict[str, Any]] = None, 
                            optimization_goal: Optional[str] = None, daily_budget: Optional[int] = None, lifetime_budget: Optional[int] = None, 
                            is_dynamic_creative: Optional[bool] = None,
                            access_token: Optional[str] = None) -> str:
        """
        Update an ad set with new settings including frequency caps and budgets.
        
        Args:
            adset_id: Meta Ads ad set ID
            frequency_control_specs: List of frequency control specifications 
                                     (e.g. [{"event": "IMPRESSIONS", "interval_days": 7, "max_frequency": 3}])
            bid_strategy: Bid strategy (e.g., 'LOWEST_COST_WITH_BID_CAP')
            bid_amount: Bid amount in account currency (in cents for USD)
            status: Update ad set status (ACTIVE, PAUSED, etc.)
            targeting: Complete targeting specifications (will replace existing targeting)
                      (e.g. {"targeting_automation":{"advantage_audience":1}, "geo_locations": {"countries": ["US"]}})
            optimization_goal: Conversion optimization goal (e.g., 'LINK_CLICKS', 'CONVERSIONS', 'APP_INSTALLS', etc.)
            daily_budget: Daily budget in account currency (in cents) as a string
            lifetime_budget: Lifetime budget in account currency (in cents) as a string
            is_dynamic_creative: Enable/disable Dynamic Creative for this ad set.
            access_token: Meta API access token (optional - will use cached token if not provided)
        """
        if not adset_id:
            return json.dumps({"error": "No ad set ID provided"}, indent=2)
        
        params = {}
        
        if frequency_control_specs is not None:
            params['frequency_control_specs'] = frequency_control_specs
        
        if bid_strategy is not None:
            params['bid_strategy'] = bid_strategy
            
        if bid_amount is not None:
            params['bid_amount'] = str(bid_amount)
            
        if status is not None:
            params['status'] = status
            
        if optimization_goal is not None:
            params['optimization_goal'] = optimization_goal
            
        if targeting is not None:
            # Ensure proper JSON encoding for targeting
            if isinstance(targeting, dict):
                params['targeting'] = json.dumps(targeting)
            else:
                params['targeting'] = targeting  # Already a string
        
        # Add budget parameters if provided
        if daily_budget is not None:
            params['daily_budget'] = str(daily_budget)
        
        if lifetime_budget is not None:
            params['lifetime_budget'] = str(lifetime_budget)
        
        if is_dynamic_creative is not None:
            params['is_dynamic_creative'] = "true" if bool(is_dynamic_creative) else "false"
        
        if not params:
            return json.dumps({"error": "No update parameters provided"}, indent=2)
    
        endpoint = f"{adset_id}"
        
        try:
            # Use POST method for updates as per Meta API documentation
            data = await make_api_request(endpoint, access_token, params, method="POST")
            return json.dumps(data, indent=2)
        except Exception as e:
            error_msg = str(e)
            # Include adset_id in error for better context
            return json.dumps({
                "error": f"Failed to update ad set {adset_id}",
                "details": error_msg,
                "params_sent": params
            }, indent=2) 
  • Imports and exports the update_adset function in the core package __init__.py, making it available for use.
    from .adsets import get_adsets, get_adset_details, update_adset
    from .ads import get_ads, get_ad_details, get_ad_creatives, get_ad_image, update_ad
    from .insights import get_insights
    from . import authentication  # Import module to register conditional auth tools
    from .server import login_cli, main
    from .auth import login
    from . import ads_library  # Import module to register conditional tools
    from .budget_schedules import create_budget_schedule
    from .targeting import search_interests, get_interest_suggestions, estimate_audience_size, search_behaviors, search_demographics, search_geo_locations
    from . import reports  # Import module to register conditional tools
    from . import duplication  # Import module to register conditional duplication tools
    from .openai_deep_research import search, fetch  # OpenAI MCP Deep Research tools
    
    __all__ = [
        'mcp_server',
        'get_ad_accounts',
        'get_account_info',
        'get_campaigns',
        'get_campaign_details',
        'create_campaign',
        'get_adsets',
        'get_adset_details',
        'update_adset',
  • Re-exports update_adset from core at the package level.
    from .core import (
        get_ad_accounts,
        get_account_info,
        get_campaigns,
        get_campaign_details,
        create_campaign,
        get_adsets,
        get_adset_details,
        update_adset,

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