Skip to main content
Glama

Statistics Canada MCP Server

query_sdmx

Read-only

Fetch SDMX observations and run ONE read-only SQL query over them server-side, returning only the query result. Nothing is stored — the data is loaded into a temporary in-memory table named data and discarded after the query.

*** Use this for compute/compare/rank questions ("which province grew fastest", "average since 2020", "year-over-year change") instead of pulling raw rows with get_sdmx_data and doing arithmetic yourself. It is not limited to 500 rows. ***

Same productId, key and time parameters as get_sdmx_data (see that tool for key syntax and wildcard rules). lastNObservations cannot be combined with startPeriod/endPeriod.

Table data columns: one per dimension (names sanitized: spaces/punctuation → '_'), "period" (TEXT, e.g. "2024" or "2024-03"), "value" (REAL, NULL = suppressed), plus SDMX attributes like VECTOR_ID, UOM, SCALAR_FACTOR, STATUS. Quote mixed-case column names with double quotes.

Example — CPI growth by province since Jan 2020: productId=18100004, key="2+3+5+6.2", startPeriod="2020-01", sql: SELECT "Geography", MAX(CASE WHEN period = '2025-12' THEN value END) / MAX(CASE WHEN period = '2020-01' THEN value END) - 1 AS growth FROM data GROUP BY 1 ORDER BY growth DESC

If the SQL fails, the response includes table_columns — fix the query and retry. Limits: one statement, SELECT only, ~2s execution time, result capped at 500 rows.

IMPORTANT: In your final response, cite the _sdmx_url, productId and key used.

Input Schema

NameRequiredDescriptionDefault
keyYesDot-separated dimension codes in position order (e.g. '1.2.1'). Use '+' for OR ('1+2.2.1' = Geography 1 or 2). Omit a value for wildcard ('.2.1' = all geographies, Gender=2, Age=1). Code numbers match WDS memberIds — no translation needed. Call get_sdmx_structure first to see dimension positions and valid codes.
sqlYesOne read-only SELECT (WITH/CTEs and window functions allowed) against table 'data'. Columns: one per dimension (spaces/punctuation -> '_', e.g. "Products_and_product_groups"), period, value (REAL), VECTOR_ID, UOM, SCALAR_FACTOR, STATUS, etc. Quote mixed-case names: SELECT "Geography", ...
endPeriodNoEnd period in YYYY or YYYY-MM format.
productIdYes
startPeriodNoStart period in YYYY or YYYY-MM format.
lastNObservationsNoReturn only the last N observations per series (e.g. 12 for one year of monthly data).

Output Schema

NameRequiredDescriptionDefault
rowsYesSQL result rows (max 500).
columnsYesColumns of the SQL result.
messageNoPresent when the result was truncated.
_sdmx_urlYesSDMX request URL — cite as the data source.
table_columnsYesColumns available in table 'data'.
fetched_row_countYesRows loaded into the temporary 'data' table.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.9/5.0
Behavior5/5

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

Annotations already declare readOnlyHint=true and openWorldHint=true; the description goes well beyond them by disclosing that nothing is persisted, that data lands in a temporary in-memory table named `data` and is discarded, that execution is capped at ~2s and one statement, and that the result is capped at 500 rows while the underlying pull is not. It even documents the failure path: a failed SQL returns `table_columns` so the agent can correct and retry.

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?

Purpose and the get_sdmx_data contrast are front-loaded in bold, and the remaining blocks (table shape, example, limits) are chunked rather than buried. It is on the long side and the column list partially repeats the `sql` schema description, but the example and limits each earn their space.

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?

An output schema exists, so return values need not be explained, and the description still covers dialect, column naming, timeouts, row caps, and the retry signal on error. For a six-parameter SQL-execution tool whose main failure mode is a malformed query, nothing an agent needs to call it correctly is missing.

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

Parameters5/5

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

Schema coverage is already 83%, yet the description still adds meaning the schema lacks: key/time parameters are declared identical to get_sdmx_data (deferring to that tool for wildcard syntax), the resolved `data` table shape is spelled out with period formats and NULL-as-suppressed semantics, mixed-case quoting is mandated, and a full worked example shows the expected SQL dialect. This substantially lowers invocation errors beyond what the schema conveys.

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?

The description opens with a specific verb-plus-resource statement: fetch SDMX observations and run one read-only SQL query server-side, returning only the result. It explicitly distinguishes itself from the sibling get_sdmx_data ('instead of pulling raw rows ... and doing arithmetic yourself'), so an agent can route between them without opening either 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?

It names the exact question class that selects this tool (compute/compare/rank, with three concrete example questions) and the alternative that does not (get_sdmx_data). It also states a hard exclusion — lastNObservations cannot be combined with startPeriod/endPeriod — which is the kind of when-not guidance most definitions omit.

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.