Skip to main content
Glama
dhawalshah

meta-ads-mcp

get_campaigns_by_adaccount

Retrieve Facebook ad campaigns from a specific account. Filter by status, objective, date range, and pagination to get targeted campaign data.

Instructions

Retrieves campaigns from a specific Facebook ad account.

This function allows querying all campaigns belonging to a specific ad account with various filtering options, pagination, and field selection.

Args: act_id (str): The ID of the ad account to retrieve campaigns from, prefixed with 'act_', e.g., 'act_1234567890'. fields (Optional[List[str]]): A list of specific fields to retrieve for each campaign. If None, a default set of fields will be returned. See get_campaign_by_id for a comprehensive list of available fields. filtering (Optional[List[dict]]): A list of filter objects to apply to the data. Each object should have 'field', 'operator', and 'value' keys. Operators include: 'EQUAL', 'NOT_EQUAL', 'GREATER_THAN', 'GREATER_THAN_OR_EQUAL', 'LESS_THAN', 'LESS_THAN_OR_EQUAL', 'IN_RANGE', 'NOT_IN_RANGE', 'CONTAIN', 'NOT_CONTAIN', 'IN', 'NOT_IN', 'EMPTY', 'NOT_EMPTY'. Example: [{'field': 'daily_budget', 'operator': 'GREATER_THAN', 'value': 1000}] limit (Optional[int]): Maximum number of campaigns to return per page. Default is 25, max is 100. after (Optional[str]): Pagination cursor for the next page. From response['paging']['cursors']['after']. before (Optional[str]): Pagination cursor for the previous page. From response['paging']['cursors']['before']. date_preset (Optional[str]): A predefined relative date range for selecting campaigns. Options include: 'today', 'yesterday', 'this_month', 'last_month', 'this_quarter', 'maximum', 'last_3d', 'last_7d', 'last_14d', 'last_28d', 'last_30d', 'last_90d', 'last_week_mon_sun', 'last_week_sun_sat', 'last_quarter', 'last_year', 'this_week_mon_today', 'this_week_sun_today', 'this_year'. time_range (Optional[Dict[str, str]]): A custom time range with 'since' and 'until' dates in 'YYYY-MM-DD' format. Example: {'since': '2023-01-01', 'until': '2023-01-31'} updated_since (Optional[int]): Return campaigns that have been updated since this Unix timestamp. effective_status (Optional[List[str]]): Filter campaigns by their effective status. Options include: 'ACTIVE', 'PAUSED', 'DELETED', 'PENDING_REVIEW', 'DISAPPROVED', 'PREAPPROVED', 'PENDING_BILLING_INFO', 'ARCHIVED', 'WITH_ISSUES'. is_completed (Optional[bool]): If True, returns only completed campaigns. If False, returns only active campaigns. If None, returns both. special_ad_categories (Optional[List[str]]): Filter campaigns by special ad categories. Options include: 'EMPLOYMENT', 'HOUSING', 'CREDIT', 'ISSUES_ELECTIONS_POLITICS', 'NONE'. objective (Optional[List[str]]): Filter campaigns by advertising objective. Options include: 'APP_INSTALLS', 'BRAND_AWARENESS', 'CONVERSIONS', 'EVENT_RESPONSES', 'LEAD_GENERATION', 'LINK_CLICKS', 'LOCAL_AWARENESS', 'MESSAGES', 'OFFER_CLAIMS', 'PAGE_LIKES', 'POST_ENGAGEMENT', 'PRODUCT_CATALOG_SALES', 'REACH', 'STORE_VISITS', 'VIDEO_VIEWS'. buyer_guarantee_agreement_status (Optional[List[str]]): Filter campaigns by buyer guarantee agreement status. Options include: 'APPROVED', 'NOT_APPROVED'. date_format (Optional[str]): Format for date responses. Options: - 'U': Unix timestamp (seconds since epoch) - 'Y-m-d H:i:s': MySQL datetime format - None: ISO 8601 format (default) include_drafts (Optional[bool]): If True, includes draft campaigns in the results.

Returns: Dict: A dictionary containing the requested campaigns. The main results are in the 'data' list, and pagination info is in the 'paging' object.

Example: ```python # Get active campaigns from an ad account campaigns = get_campaigns_by_adaccount( act_id="act_123456789", fields=["name", "objective", "effective_status", "created_time"], effective_status=["ACTIVE"], limit=50 )

# Get campaigns with specific objectives
lead_gen_campaigns = get_campaigns_by_adaccount(
    act_id="act_123456789",
    fields=["name", "objective", "spend_cap", "daily_budget"],
    objective=["LEAD_GENERATION", "CONVERSIONS"],
    date_format="U"
)

# Get campaigns created in a specific date range
date_filtered_campaigns = get_campaigns_by_adaccount(
    act_id="act_123456789",
    fields=["name", "created_time", "objective"],
    time_range={"since": "2023-01-01", "until": "2023-01-31"}
)

# Fetch the next page if available using the pagination cursor
next_page_cursor = campaigns.get("paging", {}).get("cursors", {}).get("after")
if next_page_cursor:
    next_page = get_campaigns_by_adaccount(
        act_id="act_123456789",
        fields=["name", "objective", "effective_status", "created_time"],
        effective_status=["ACTIVE"],
        limit=50,
        after=next_page_cursor
    )
```

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
afterNo
limitNo
act_idYes
beforeNo
fieldsNo
filteringNo
objectiveNo
time_rangeNo
date_formatNo
date_presetNo
is_completedNo
updated_sinceNo
include_draftsNo
effective_statusNo
special_ad_categoriesNo
buyer_guarantee_agreement_statusNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.5/5.0
Behavior4/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 discloses pagination via after/before cursors, default limit (25) and max (100), default field behavior (None returns default set), date formats, filtering operator syntax, and example response structure. It also shows how to handle pagination in the example. It does not mention authentication, rate limits, or error conditions, but given the complexity it covers most critical behavioral aspects.

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

Conciseness4/5

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

The description is long but warranted given 16 parameters. It uses a clear Args/Returns/Example structure, with parameters grouped logically and examples that illustrate common usage patterns. It is not tautological or padded; each sentence adds value. It could be slightly tighter, but the structure aids readability and is appropriate for the tool's complexity.

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

Completeness5/5

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

Given the tool has 16 parameters, an output schema, and is part of a large sibling family, the description is remarkably complete. It covers every parameter's semantics, default behaviors, valid enum values, pagination workflow, and even shows chained pagination in the example. The output schema (not shown in description but present) handles return structure; the description complements it by explaining where data and paging live. Nothing essential for calling this tool correctly is missing.

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?

Schema description coverage is 0%, so the description must compensate, and it does thoroughly. Every parameter is documented with its type, purpose, defaults, and often a list of valid values (e.g., date_preset options, effective_status options, objective options). The filtering parameter includes operator enums and a concrete example. The time_range and date_format have clear examples. This far exceeds schema-only information.

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

Purpose5/5

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

The description opens with a specific verb+resource: 'Retrieves campaigns from a specific Facebook ad account.' It clearly states the tool's scope (all campaigns of one account) and differentiates itself from single-resource tools like get_campaign_by_id, which is explicitly referenced for field lists. An agent can immediately understand what this does and how it differs from siblings.

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

Usage Guidelines4/5

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

The description gives clear context: it's for querying campaigns by ad account, with filtering and pagination. It explicitly points to get_campaign_by_id for the comprehensive field list, signaling that this tool is for bulk/listing queries. The example shows how to fetch the next page, implying when pagination is needed. However, it doesn't explicitly state 'use this when you need multiple campaigns and get_campaign_by_id for a single one,' leaving that to inference.

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