get_adsets
Retrieve ad sets from a Meta Ads account with optional campaign filtering to analyze and manage advertising structures.
Instructions
Get ad sets for a Meta Ads account with optional filtering by campaign.
Args:
account_id: Meta Ads account ID (format: act_XXXXXXXXX)
access_token: Meta API access token (optional - will use cached token if not provided)
limit: Maximum number of ad sets to return (default: 10)
campaign_id: Optional campaign ID to filter by
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | Yes | ||
| access_token | No | ||
| limit | No | ||
| campaign_id | No |
Implementation Reference
- meta_ads_mcp/core/adsets.py:10-45 (handler)The primary handler function for the 'get_adsets' tool. It is decorated with @mcp_server.tool() for MCP registration and @meta_api_tool. Fetches ad sets from a specified Meta Ads account or campaign, constructs the appropriate API endpoint and parameters, calls make_api_request, and returns JSON-formatted results.@mcp_server.tool() @meta_api_tool async def get_adsets(account_id: str, access_token: Optional[str] = None, limit: int = 10, campaign_id: str = "") -> str: """ Get ad sets for a Meta Ads account with optional filtering by campaign. Args: account_id: Meta Ads account ID (format: act_XXXXXXXXX) access_token: Meta API access token (optional - will use cached token if not provided) limit: Maximum number of ad sets to return (default: 10) campaign_id: Optional campaign ID to filter by """ # Require explicit account_id if not account_id: return json.dumps({"error": "No account ID specified"}, indent=2) # Change endpoint based on whether campaign_id is provided if campaign_id: endpoint = f"{campaign_id}/adsets" params = { "fields": "id,name,campaign_id,status,daily_budget,lifetime_budget,targeting,bid_amount,bid_strategy,optimization_goal,billing_event,start_time,end_time,created_time,updated_time,is_dynamic_creative,frequency_control_specs{event,interval_days,max_frequency}", "limit": limit } else: # Use account endpoint if no campaign_id is given endpoint = f"{account_id}/adsets" params = { "fields": "id,name,campaign_id,status,daily_budget,lifetime_budget,targeting,bid_amount,bid_strategy,optimization_goal,billing_event,start_time,end_time,created_time,updated_time,is_dynamic_creative,frequency_control_specs{event,interval_days,max_frequency}", "limit": limit } # Note: Removed the attempt to add campaign_id to params for the account endpoint case, # as it was ineffective and the logic now uses the correct endpoint for campaign filtering. data = await make_api_request(endpoint, access_token, params) return json.dumps(data, indent=2)
- meta_ads_mcp/core/__init__.py:6-6 (registration)Import of the get_adsets function from adsets.py into core/__init__.py, making it available at the core package level. Also listed in __all__ at line 26.from .adsets import get_adsets, get_adset_details, update_adset
- meta_ads_mcp/__init__.py:44-44 (registration)Re-export of get_adsets from core module to the top-level package __init__.py, listed in __all__ and explicitly imported.get_adsets,