Skip to main content
Glama
EfrainTorres

ArmaVita Meta Ads MCP

estimate_audience_size

Calculate potential audience reach for Meta Ads targeting specifications or validate deprecated interest-based targeting lists.

Instructions

Estimate audience size for targeting specs or validate deprecated interest-list mode.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
meta_access_tokenNo
ad_account_idNo
targetingNo
optimization_goalNoREACH
interest_listNo
interest_fbid_listNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function that implements the 'estimate_audience_size' tool.
    async def estimate_audience_size(
        meta_access_token: Optional[str] = None,
        ad_account_id: Optional[str] = None,
        targeting: Optional[Dict[str, Any]] = None,
        optimization_goal: str = "REACH",
        interest_list: Optional[List[str]] = None,
        interest_fbid_list: Optional[List[str]] = None,
    ) -> str:
        """Estimate audience size for targeting specs or validate deprecated interest-list mode."""
        deprecated_interest_mode = _deprecated_interest_validation_mode(
            ad_account_id=ad_account_id,
            targeting=targeting,
            interest_list=interest_list,
            interest_fbid_list=interest_fbid_list,
        )
    
        if deprecated_interest_mode and not targeting:
            if not (interest_list or interest_fbid_list):
                return _as_json({"error": "No interest list or FBID list provided"})
    
            deprecated_interest_payload: Dict[str, Any] = {"type": "adinterestvalid"}
            if interest_list:
                deprecated_interest_payload["interest_list"] = json.dumps(list(interest_list))
            if interest_fbid_list:
                deprecated_interest_payload["interest_fbid_list"] = json.dumps(list(interest_fbid_list))
            payload = await make_api_request(
                "search",
                meta_access_token,
                deprecated_interest_payload,
            )
            return _as_json(payload)
    
        if not ad_account_id:
            return _as_json(
                {
                    "error": "ad_account_id is required for comprehensive audience estimation",
                    "details": "For simple interest validation, use interest_list or interest_fbid_list parameters",
                }
            )
    
        if not targeting:
            return _as_json(
                {
                    "error": "targeting specification is required for comprehensive audience estimation",
                    "example": {
                        "age_min": 25,
                        "age_max": 65,
                        "geo_locations": {"countries": ["US"]},
                        "flexible_spec": [{"interests": [{"id": "6003371567474"}]}],
                    },
                }
            )
    
        if not _has_location_or_custom_audience(targeting):
            return _as_json(
                {
                    "error": "Missing target audience location",
                    "details": "Select at least one location in targeting.geo_locations or include a custom audience.",
                    "action_required": "Add geo_locations with countries/regions/cities/zips or include custom_audiences.",
                    "example": {
                        "geo_locations": {"countries": ["US"]},
                        "age_min": 25,
                        "age_max": 65,
                    },
                }
            )
    
        fallback_disabled = os.environ.get("META_MCP_DISABLE_DELIVERY_FALLBACK", "1") == "1"
    
        try:
            reach_payload = await make_api_request(
                f"{ad_account_id}/reachestimate",
                meta_access_token,
                {"targeting_spec": targeting},
                method="GET",
            )
    
            if isinstance(reach_payload, dict) and reach_payload.get("error"):
                graph_error = _extract_graph_error(reach_payload)
                missing_location = _missing_location_error_payload(graph_error, ad_account_id)
                if missing_location:
                    return _as_json(missing_location)
    
                if fallback_disabled:
                    return _as_json(
                        {
                            "error": "Graph API returned an error for reachestimate",
                            "details": reach_payload.get("error"),
                            "endpoint_used": f"{ad_account_id}/reachestimate",
                            "request_params": {"has_targeting_spec": bool(targeting)},
                            "note": "delivery_estimate fallback disabled via META_MCP_DISABLE_DELIVERY_FALLBACK",
                        }
                    )
    
                fallback_result = await _run_delivery_estimate_fallback(
                    ad_account_id=ad_account_id,
                    meta_access_token=meta_access_token,
                    targeting=targeting,
                    optimization_goal=optimization_goal,
                )
                if fallback_result.get("success"):
                    return _as_json(fallback_result)
    
                return _as_json(
                    {
                        "error": "Graph API returned an error for reachestimate; delivery_estimate fallback did not return usable data",
                        "reachestimate_error": reach_payload.get("error"),
                        "fallback_endpoint_used": "delivery_estimate",
                        "fallback_raw_response": fallback_result,
                        "endpoint_used": f"{ad_account_id}/reachestimate",
                    }
                )
    
            normalized = _normalize_reach_result(
                reach_payload,
                ad_account_id=ad_account_id,
                targeting=targeting,
                optimization_goal=optimization_goal,
            )
            return _as_json(normalized)
    
        except Exception as exc:  # noqa: BLE001
            if not fallback_disabled:
                try:
                    fallback_result = await _run_delivery_estimate_fallback(
                        ad_account_id=ad_account_id,
                        meta_access_token=meta_access_token,
                        targeting=targeting,
                        optimization_goal=optimization_goal,
                    )
                    if fallback_result.get("success"):
                        return _as_json(fallback_result)
                except Exception:  # noqa: BLE001
                    pass
    
            return _as_json(
                {
                    "error": f"Failed to get audience estimation from reachestimate endpoint: {exc}",
                    "details": "Check targeting parameters and account permissions",
                    "error_type": "general_api_error",
                    "endpoint_used": f"{ad_account_id}/reachestimate",
                }
            )
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 of behavioral disclosure. It mentions 'deprecated interest-list mode,' which hints at legacy functionality, but doesn't describe key behaviors: whether this is a read-only estimation, if it requires authentication (implied by 'meta_access_token' but not stated), rate limits, or what the output contains. For a tool with 6 parameters and no annotations, this leaves significant gaps in understanding how it operates.

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 a single, efficient sentence that front-loads the core purpose. It avoids redundancy and wastes no words, making it easy to parse quickly. Every part of the sentence contributes to understanding the tool's use cases.

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

Completeness3/5

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

Given the complexity (6 parameters, no annotations, but an output schema exists), the description is incomplete. The output schema means return values don't need explanation, but the description lacks details on authentication needs, parameter interactions, and behavioral traits. It covers basic purpose but misses critical context for effective use, especially with undocumented parameters.

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

Parameters2/5

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

Schema description coverage is 0%, meaning parameters are undocumented in the schema. The description adds minimal semantics: it implies 'targeting' and 'interest_list' are used for estimation, and 'interest_list' is deprecated. However, it doesn't explain the purpose of other parameters like 'meta_access_token', 'ad_account_id', 'optimization_goal', or 'interest_fbid_list', nor their relationships. With 6 parameters, the description fails to compensate for the lack of schema documentation.

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: 'Estimate audience size for targeting specs or validate deprecated interest-list mode.' It specifies the verb ('estimate') and resource ('audience size'), and distinguishes between two use cases. However, it doesn't explicitly differentiate from sibling tools like 'search_demographics' or 'suggest_interests' that might also relate to audience analysis.

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 by mentioning two modes: 'for targeting specs' and 'validate deprecated interest-list mode.' This provides some context on when to use the tool, but it doesn't offer explicit guidance on when to choose this over alternatives (e.g., vs. 'search_demographics' for audience insights) or prerequisites like required parameters. The guidance is present but not comprehensive.

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/EfrainTorres/armavita-meta-ads-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server