run_query
Raw SELECT SQL against analytics tables (ClickHouse), for joins across tables, arrays (groupArray), window functions, or arithmetic across metrics. Available tables:
ads_olap: Amazon Ads analytics - daily performance data with campaigns, targets, search terms, and metrics.
product_catalog: Product catalog — current pricing, availability, BSR, ad eligibility per ASIN.
product_changes: Product change log — price movements, stock flips, BSR shifts, eligibility updates. Every time-series scan needs a literal lower date bound: time_window_date for ads_olap and changed_at for product_changes. A closed literal range meets the bound. product_catalog is a current snapshot and is exempt. ads_olap time_window_month is 1-12 and time_window_week is a week number; neither includes the year. Buckets: toStartOfMonth(time_window_date), toYYYYMM(time_window_date), or toStartOfWeek(time_window_date, 1) (Monday). ads_olap holds daily, weekly, and monthly granules. time_granularity is 'daily', 'weekly', or 'monthly'; omitted means daily. business_profile_id and profile_id are injected by the server and are not WHERE predicates. Money metrics are sums. Ratio form is
if(x=0,null,x); nullIf is blocked. LIMIT defaults and caps by credential: MCP 100/500, API key 500/5,000, first-party frontend 1,000/50,000. Money is the profile's native currency (get_session_context(section="accounts") currency_code). Column schema and enums are returned by describe(kind='tables').
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SELECT query against enabled tables (e.g., ads_olap). Every time-series table scan must include its physical date column with a literal lower bound or closed range. | |
| round | No | Decimals, default 2. | |
| format | No | Default compact {columns,rows}; tsv smallest. | |
| target | No | From get_session_context targets: kind:account[:unit]. | |
| columns | No | ||
| max_rows | No | Maximum rows. Absent: the credential tier's default (100 MCP, 500 API key, 1,000 first-party). Caps are 500, 5,000, and 50,000. Larger values are clamped silently, not rejected. Responses are also bounded by a byte budget. |