list_ad_accounts
Retrieve all accessible Meta ad accounts for a user to manage campaigns, targeting, and reporting through the Meta Marketing API.
Instructions
List ad accounts visible to a user context.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| meta_access_token | No | ||
| meta_user_id | No | me | |
| page_size | No | ||
| page_cursor | No |
Implementation Reference
- The `list_ad_accounts` function, registered as an MCP tool, fetches ad accounts for a given user from the Meta API, normalizes currency fields, and returns the response as a JSON string.
async def list_ad_accounts( meta_access_token: Optional[str] = None, meta_user_id: str = "me", page_size: int = 200, page_cursor: str = "", ) -> str: """List ad accounts visible to a user context.""" params: Dict[str, Any] = { "fields": ( "id,name,account_id,account_status,amount_spent,balance,currency," "age,business_city,business_country_code" ), "page_size": int(page_size), } if page_cursor: params["page_cursor"] = page_cursor payload = await make_api_request(f"{meta_user_id}/adaccounts", meta_access_token, params) if isinstance(payload, dict) and isinstance(payload.get("data"), list): payload["data"] = [ _normalize_money_fields(item) if isinstance(item, dict) else item for item in payload["data"] ] return json.dumps(payload, indent=2)