gads_get_account_hierarchy
Google Ads read low risk
Part of the Multi-Account Agent.
What it does
Resolve the manager/client account tree beneath a given account by querying the customer_client resource (SELECT customer_client.id, .descriptive_name, .manager, .level, .time_zone, .currency_code, .status FROM customer_client). Returns every account reachable below the supplied customer_id, with each node's level (0 = the account itself, 1 = direct children, etc.), whether it is itself a manager (MCC), and its currency/time_zone. Confirmed against official docs that customer_client is the authoritative way to expand an MCC hierarchy that ListAccessibleCustomers does NOT surface, and how you build the correct {customer_id, manager_id} pair needed to query metrics on a client account. ACCURACY NOTES: only client (manager=false) nodes hold ad performance data - querying metrics on a manager node fails; currency_code per node governs micros/1e6 formatting for that account, never the root's. Returns {success, data:[{id, name, is_manager, level, time_zone, currency_code, status}], count, warnings}.
When to use it
When the user asks how their MCC/manager structure looks, which accounts sit under a manager, or where a specific account lives in the tree.
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
customer_id | string | yes | Root account to expand, 10 digits, dashes stripped. Pass an MCC id to enumerate the client accounts beneath it. customer_client is queried in the context of this account. |
manager_id | string | no | login-customer-id (MCC) when the root is reached through a higher manager, dashes stripped. Often equal to customer_id when expanding an MCC directly; omit for a self-owned account. |
max_level | integer | no | Optional depth cap added as 'WHERE customer_client.level <= N'. Omitted = NO cap: the FULL tree at every depth (deep MCC trees included). Set it to reduce row counts on very large trees. |
Safeguards
Policy
Read-only structural discovery under the adwords scope. The traversal is bounded by the bearer token's authorized accounts and tenant context; never enumerate or expose a hierarchy the user is not entitled to. Strict per-account isolation applies even within an MCC - only return nodes the credentials can legitimately reach (Postgres RLS).
Reminder
Discovery only; persist only accounts the user explicitly selects to connect; do not pool client-account identities across tenants.
Errors
| Error class | Means | What to do | Retry |
|---|---|---|---|
CUSTOMER_NOT_FOUND | The root customer_id does not exist or is unreachable with these credentials. | Verify via gads_list_accessible_customers; if previously reachable, refresh token or prompt re-auth (needs_reauth). | no |
TOKEN_REVOKED | OAuth token expired/invalid/revoked (UNAUTHENTICATED / OAUTH_TOKEN_REVOKED). | Refresh once and retry; else prompt re-authorization (needs_reauth). | yes |
PERMISSION_DENIED | AuthorizationError.USER_PERMISSION_DENIED - login lacks access to this account/MCC, or part of the subtree is out of bearer scope. | Confirm the user manages this MCC; do not silently substitute another root. | no |
RESOURCE_EXHAUSTED | Daily-operations quota exceeded (QuotaError, HTTP 429), more likely when expanding large MCC trees. | If daily cap, stop until reset; else backoff 5/10/20s (cap 60s); lower max_level to reduce load, then retry. | yes |
RESOURCE_TEMPORARILY_EXHAUSTED | Per-second QPS rate limit hit (HTTP 429). | Backoff 5/10/20s (cap 60s), then retry; throttle concurrency and lower max_level. | yes |
PLATFORM_UNAVAILABLE | Google internal/transient error (HTTP 5xx). | Retry with backoff; report transient outage if persistent. | yes |
Edge cases
- Leaf (non-manager) account with no children -> returns a single level-0 node for itself; success:true, count:1.
- Large MCC tree -> can return many rows and risk RESOURCE_EXHAUSTED; cap with max_level and/or paginate; warn when the depth cap likely hid deeper accounts.
- Some child accounts are themselves managers (is_manager=true) -> mark them so the agent recurses for grandchildren rather than treating them as queryable client accounts.
- Per-node currency_code/time_zone differ across the tree -> apply each node's own currency for micros/1e6, never the root's.
- Child accounts here may not appear in gads_list_accessible_customers - this tool is the authoritative source for MCC children and for the manager_id needed in metrics queries.
- customer_client.status may be CANCELED/SUSPENDED -> surface it so the agent does not attempt metrics on a disabled child.
- Expired token -> refresh once and retry before surfacing needs_reauth.