Skip to main content
Glama

get_adsets

Retrieve ad sets for a Meta Ads account, with optional filtering by campaign, using specified account ID and access token. Limits the number of results for targeted analysis.

Instructions

Get ad sets for a Meta Ads account with optional filtering by campaign. Args: access_token: Meta API access token (optional - will use cached token if not provided) account_id: Meta Ads account ID (format: act_XXXXXXXXX) limit: Maximum number of ad sets to return (default: 10) campaign_id: Optional campaign ID to filter by

Input Schema

NameRequiredDescriptionDefault
access_tokenNo
account_idNo
campaign_idNo
limitNo

Input Schema (JSON Schema)

{ "properties": { "access_token": { "default": null, "title": "Access Token", "type": "string" }, "account_id": { "default": null, "title": "Account Id", "type": "string" }, "campaign_id": { "default": "", "title": "Campaign Id", "type": "string" }, "limit": { "default": 10, "title": "Limit", "type": "integer" } }, "title": "get_adsetsArguments", "type": "object" }

Implementation Reference

  • The primary handler function implementing the 'get_adsets' MCP tool. It uses Meta Ads API to retrieve adsets for an account or campaign, with decorators for MCP tool registration (@mcp_server.tool()) and API handling (@meta_api_tool). Includes input validation, dynamic endpoint selection based on campaign_id, and JSON-formatted API response.
    @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)

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