get_ad_accounts
Retrieve ad accounts accessible to a user, returning amount spent and balance in currency units. Specify user ID and limit to control results.
Instructions
Get ad accounts accessible by a user.
amount_spent and balance are returned in currency units (e.g. USD dollars),
not cents.
Args:
access_token: Meta API access token (optional - will use cached token if not provided)
user_id: Meta user ID or "me" for the current user
limit: Maximum number of accounts to return (default: 200)Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| access_token | No | ||
| user_id | No | me | |
| limit | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- meta_ads_mcp/core/accounts.py:42-67 (handler)The main tool handler for 'get_ad_accounts'. This async function is decorated with @mcp_server.tool() and @meta_api_tool. It calls the Meta Graph API endpoint '{user_id}/adaccounts' with fields like id, name, account_id, amount_spent, balance, etc. It normalizes monetary fields (cents to currency units) and returns the result as a JSON string.
@mcp_server.tool() @meta_api_tool async def get_ad_accounts(access_token: Optional[str] = None, user_id: str = "me", limit: int = 200) -> str: """ Get ad accounts accessible by a user. amount_spent and balance are returned in currency units (e.g. USD dollars), not cents. Args: access_token: Meta API access token (optional - will use cached token if not provided) user_id: Meta user ID or "me" for the current user limit: Maximum number of accounts to return (default: 200) """ endpoint = f"{user_id}/adaccounts" params = { "fields": "id,name,account_id,account_status,amount_spent,balance,currency,age,business_city,business_country_code", "limit": limit } data = await make_api_request(endpoint, access_token, params) if "data" in data: data["data"] = [_normalize_account_monetary_fields(acc) for acc in data["data"]] return json.dumps(data, indent=2) - meta_ads_mcp/core/accounts.py:45-55 (schema)Input schema for the tool defined in the docstring/args. Parameters: access_token (optional), user_id (default 'me'), limit (default 200). No Pydantic model - schema is inferred from function signature by FastMCP.
""" Get ad accounts accessible by a user. amount_spent and balance are returned in currency units (e.g. USD dollars), not cents. Args: access_token: Meta API access token (optional - will use cached token if not provided) user_id: Meta user ID or "me" for the current user limit: Maximum number of accounts to return (default: 200) """ - meta_ads_mcp/core/accounts.py:17-39 (helper)Helper functions: _cents_to_currency converts Meta API monetary values from cents to human-readable currency units. _normalize_account_monetary_fields applies this conversion to amount_spent and balance fields in each account dict.
def _cents_to_currency(amount, currency: str) -> str: """Convert a Meta API monetary value (cents) to a currency-unit string. Meta returns amount_spent and balance as integers representing the smallest currency unit (cents for USD/EUR/GBP, base unit for zero-decimal currencies like JPY). This converts to the human-readable decimal amount. """ try: amount_int = int(amount) except (TypeError, ValueError): return str(amount) if currency.upper() in _ZERO_DECIMAL_CURRENCIES: return str(amount_int) return f"{amount_int / 100:.2f}" def _normalize_account_monetary_fields(account: dict) -> dict: """Convert amount_spent and balance from cents to currency units in-place.""" currency = account.get("currency", "USD") for field in ("amount_spent", "balance"): if field in account: account[field] = _cents_to_currency(account[field], currency) return account - meta_ads_mcp/core/__init__.py:1-4 (registration)The tool is registered via the @mcp_server.tool() decorator on the function (in accounts.py line 42). It is then re-exported in core/__init__.py where 'get_ad_accounts' is imported from .accounts and added to __all__.
"""Core functionality for Meta Ads API MCP package.""" from .server import mcp_server from .accounts import get_ad_accounts, get_account_info - meta_ads_mcp/core/accounts.py:42-42 (registration)The @mcp_server.tool() decorator (from FastMCP) registers 'get_ad_accounts' as an MCP tool on the server instance at module import time.
@mcp_server.tool()