Skip to main content
Glama

Query marketing data

query_data
Read-only

Run an ad-hoc query across one or more connected accounts.

You can skip list_accounts in two cases, both needing connector:

  • the user NAMES an account — accounts=["Glamping Tabio"], connector="facebook-ads" resolves it against their authorized accounts. A name matching nothing, or two different accounts, is rejected rather than guessed.

  • the user wants them ALL — accounts=["*"], connector="facebook-ads" expands to every usable account, so you never type out one id per account.

Otherwise pass the signed accounts refs from list_accounts verbatim (they bind each account's identity so you never assemble ids by hand), the metrics and dimensions from list_fields, and a date_range (a preset like {"preset": "last_30_days"} or explicit {"from": "2026-01-01", "to": "2026-01-31"}) — pass EITHER a preset OR explicit bounds, never both. Optional filters is a list of {"field": <name from list_fields>, "operator": <op>, "value": <value>} combined with AND, where <op> is one of eq|neq|gt|gte|lt|lte|contains|ncontains|in|null|notnull. One side effect worth knowing before you fan out: an account listed as available (not yet connected) is MATERIALIZED the first time query_data runs against it, and each materialization takes a licence slot from the workspace. The read itself changes nothing the caller owns, but querying a whole listing to see which accounts have data does spend slots. Query what the user asked about. Accounts from different connectors are blended into shared columns. Returns {columns, rows, row_count, truncated}. Read-only. Each row is a positional tuple aligned with columns, and columns comes back in the order you asked for (metrics first, then dimensions) — always read values through columns rather than assuming a layout.

limit is the page size, not a cap on the result. total_rows is the size of the whole result; when it holds more rows than limit the response carries a next_cursor. Call again with the SAME arguments plus cursor=<next_cursor> to read the next page, and repeat until next_cursor is absent — pages come from the same run, so nothing is re-extracted and no row is skipped or repeated. Add up every page before reporting a total. total_rows_is_lower_bound: true means the result is larger than Porter reads in one query: narrow it (shorter range, fewer accounts, a filter) instead of paging. A cursor lasts 24 hours.

Presets resolve against the UTC calendar day; last_7_days / last_30_days end yesterday, while today / this_month / this_year include the incomplete current day. warnings, when present, flag ranges that include the not-yet-ingested current day for storage-backed connectors — surface them to the user instead of presenting the numbers as final; data_freshness reports lastRefreshed / coverageUntil of the stored data.

When the user names a connector but no account, do NOT pick one. Pass every account you have for that connector and add the connector's account-name dimension (e.g. facebook_ads_account_name). One call then returns both the figure and WHICH account it belongs to, which is the question you were about to search for. Trying accounts one at a time to see which has data costs minutes and answers the same thing.

A query that outlives one tool call comes back as {"status": "running", "query_id": …} instead of rows. That is NOT an error and nothing was lost: call get_query_result(query_id=…) with that id copied verbatim, and call it again immediately if it says running again. Never re-issue this call to answer a running one — that abandons the run in flight and starts the extraction over.

coverage says whether the result covers every account you asked for (complete: true) or some were dropped because the platform denied access, naming them. Read it and stop: a complete result has nothing further to find, and re-querying a denied account fails the same way. Report the gap to the user instead of splitting the query and retrying.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "accounts": "<accounts>",
      "metrics": "<metrics>"
    },
    "name": "query_data"
  }
}

Input Schema

NameRequiredDescriptionDefault
limitNo
cursorNo
filtersNo
metricsYes
accountsYes
order_byNo
connectorNo
date_rangeNo
dimensionsNo
compare_date_rangeNo

Output Schema

NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.6/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations declare readOnlyHint/openWorldHint, but the description adds genuinely non-obvious behavior: querying an unconnected account MATERIALIZES it and consumes a licence slot, runs can return ``{"status": "running", "query_id": …}``, cursors last 24 hours, and ``warnings``/``data_freshness`` flag not-yet-ingested days. The materialization side effect sits in mild tension with readOnlyHint, but the description owns that tension explicitly ("the read itself changes nothing the caller owns"), so it is disclosed rather than contradicted; the only real gap is that ``order_by`` and ``compare_date_range`` semantics are never discussed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loads the core call shape before the caveats, and bold/emphasis is used to mark the failure modes an agent most often gets wrong. It is long, though — the async/running paragraph and the coverage paragraph each restate their point, and asides like "which is the question you were about to search for" are chattier than needed. Nearly every sentence earns its place, but not all of them equally.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 10-parameter, open-world, async-capable tool with no schema descriptions, this covers the edges that actually bite: name-vs-id resolution, cross-connector column blending, positional row tuples, pagination completion, and denial handling. Return-value explanation partially duplicates the output schema, but the extra semantics (column ordering follows request order, read through ``columns``) justify it.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description must carry parameter meaning, and it does for most of the ten: ``accounts`` (name resolution, "*")."./ verbatim signed refs, ambiguity rejection), ``connector``, ``metrics``/``dimensions`` sourcing, ``date_range`` form and the preset-XOR-explicit rule, ``filters`` with the full operator list, ``limit`` as page size not cap, and ``cursor`` lifetime. ``order_by`` and ``compare_date_range`` are left entirely unexplained, which is a real hole at 0% schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Opens with a specific verb+resource ("Run an ad-hoc query across one or more connected accounts") and immediately positions it against named siblings: skip ``list_accounts`` in these cases, use ``list_fields`` for metrics/dimensions, hand off to ``get_query_result`` when a run outlives the call. An agent can route to it without opening another schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicit when-to-use, when-to-skip (two enumerated cases for bypassing list_accounts), and when-not-to-retry (never re-issue to answer a running query; stop when ``coverage`` is complete; narrow rather than page when ``total_rows_is_lower_bound``). It also names the exact alternative for each fallback, which is the strongest form of guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources