Skip to content

Meta Ads (Facebook/Instagram) MCP server for Claude, ChatGPT, Perplexity & Cursor — the Meta node of Pipeboard’s 5-platform family (+ Google, TikTok, Snap, Reddit). Hosted remote MCP, badged Meta Business Partner, free plan — no self-hosting required.

fix: convert amount_spent and balance from cents to currency units in get_ad_accounts and get_account_info

Yves Junqueira0009b0c1bb82
diff --git a/meta_ads_mcp/core/accounts.py b/meta_ads_mcp/core/accounts.py
index c14673f..f538116 100644
--- a/meta_ads_mcp/core/accounts.py
+++ b/meta_ads_mcp/core/accounts.py
@@ -5,13 +5,49 @@ from typing import Optional, Dict, Any
from .api import meta_api_tool, make_api_request
from .server import mcp_server
+# Currencies that have no sub-units (i.e., are not denominated in cents).
+# Meta API returns amount_spent and balance as integers in the smallest currency
+# unit, which is cents for most currencies but the base unit for these.
+_ZERO_DECIMAL_CURRENCIES = {
+ "BIF", "CLP", "DJF", "GNF", "JPY", "KMF", "KRW", "MGA",
+ "PYG", "RWF", "UGX", "VND", "VUV", "XAF", "XOF", "XPF",
+}
+
+
+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
+
@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
@@ -22,9 +58,12 @@ async def get_ad_accounts(access_token: Optional[str] = None, user_id: str = "me
"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)
@@ -58,7 +97,7 @@ async def get_account_info(account_id: str, access_token: Optional[str] = None)
}
data = await make_api_request(endpoint, access_token, params)
-
+
# Check if the API request returned an error
if "error" in data:
# If access was denied, provide helpful error message with accessible accounts
@@ -89,6 +128,8 @@ async def get_account_info(account_id: str, access_token: Optional[str] = None)
# Return the original error for non-permission related issues
return data
+ _normalize_account_monetary_fields(data)
+
# Add DSA requirement detection
if "business_country_code" in data:
european_countries = ["DE", "FR", "IT", "ES", "NL", "BE", "AT", "IE", "DK", "SE", "FI", "NO"]