Skip to main content
Glama

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
NameRequiredDescriptionDefault
account_idYes
access_tokenNo
limitNo
campaign_idNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • 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)
  • 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
  • Re-export of get_adsets from core module to the top-level package __init__.py, listed in __all__ and explicitly imported.
    get_adsets,
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions optional filtering and a default limit, but lacks critical behavioral details: it doesn't specify if this is a read-only operation, what permissions are needed, how pagination or rate limits work, or the format of returned data. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and concise: a clear purpose statement followed by a bullet-point list of parameter semantics. Every sentence earns its place by providing essential information without redundancy, making it easy to scan and understand.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (4 parameters, 1 required), no annotations, and the presence of an output schema, the description is fairly complete. It covers the purpose and parameters well, but lacks behavioral context (e.g., safety, permissions, or output hints). The output schema reduces the need to describe return values, but more guidance on usage and behavior would enhance completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds substantial meaning beyond the input schema, which has 0% description coverage. It explains each parameter's purpose: 'account_id' as the Meta Ads account ID with a format example, 'access_token' as optional with caching behavior, 'limit' as the maximum number to return with a default, and 'campaign_id' as an optional filter. This fully compensates for the schema's lack of descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get ad sets for a Meta Ads account with optional filtering by campaign.' This specifies the verb ('Get'), resource ('ad sets'), and scope ('Meta Ads account'), but doesn't explicitly differentiate it from sibling tools like 'get_adset_details' or 'get_ads' beyond the campaign filtering mention.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context through 'optional filtering by campaign,' suggesting this tool is for listing ad sets, potentially filtered. However, it doesn't explicitly state when to use this versus alternatives like 'get_adset_details' (for specific ad sets) or 'get_campaigns' (for campaigns), nor does it mention prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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