stats-nz
This server has a remotely hosted endpoint. Open its connector listing for connection details, authentication requirements, and setup instructions:
@pipeworx/stats-nz
New Zealand official statistics (Aotearoa Data Explorer) — search Stats NZ's 911 published datasets by keyword and pull their observations, covering the 2013/2018/2023 censuses, LEED earnings, business demography, population estimates and projections, household expenditure, corrections and justice.
Part of Pipeworx — an MCP gateway connecting AI agents to 1857+ live data sources. This is an independent, unofficial integration — not affiliated with, endorsed by, or published by the upstream provider.
Tools
statsnz_datasets({ query, limit, offset })— keyless. Keyword-search all 911 datasets; returns dataset id, full title, description, agency, version.statsnz_smoking_by_region({ region?, year?, _apiKey })— Census smoking status (regular smoker / ex-smoker / never smoked regularly) by regional council for 2006, 2013, 2018 and 2023, with counts and percentages of people whose status was stated. Census self-report, not the Ministry of Health NZ Health Survey.statsnz_observations({ dataset, key, agency, version, startPeriod, endPeriod, lastNObservations, _apiKey })— period/value pairs with their dimension labels. A too-wide unfiltered query is auto-narrowed to totals and flagged innarrowed(see Traps).statsnz_resources({ dataset, agency, version, includeCodes, maxCodesPerList, _apiKey })— dimensions in key order, time dimension, measure, and the code lists that turn a key like1.2.Qinto something readable.
Related MCP server: ONS + Nomis MCP server
Auth
Platform key PLATFORM_STATSNZ_KEY (in the encrypted keystore since
2026-09-18) with BYO override via ?_apiKey=; sent upstream as an
Ocp-Apim-Subscription-Key header. Callers need no key of their own. Free
subscription at https://portal.apis.stats.govt.nz/ — sign up, then subscribe
to the Aotearoa Data Explorer API product.
statsnz_datasets additionally works with no key at all.
Data sources
https://api.data.stats.govt.nz/rest/dataflow/all/all/latest — dataset catalogue (keyless).
https://api.data.stats.govt.nz/rest/data/{agency},{dataset},{version}/{key} — observations (keyed).
https://api.data.stats.govt.nz/rest/datastructure/{agency}/{dataset}/{version}?references=all — structure + code lists (keyed).
Traps
The catalogue is SDMX-ML now, whatever you ask for.
/rest/dataflow/all/all/latestserved SDMX-JSON until 2026-09-18 and now servesapplication/vnd.sdmx.structure+xml; version=2.1on every Accept header tried —structure+json;version=1.0, bareapplication/json,structure+json;version=2.0— keyed and keyless alike.res.json()on it throwsUnexpected token '<', "<?xml vers", which classifies asupstream_downand reads like an outage rather than a format change. The pack parses the XML. This is endpoint-specific:/rest/datastructure/…still answers structure+JSON, so don't convert that one too.The flowRef commas must stay literal — encoding them is a silent zero. The data path is
/rest/data/{agency},{dataset},{version}/{key}. Their Azure APIM does not percent-decode path segments, and an unmatched route falls through to a handler that answers 401 "missing subscription key" without a key and an empty-but-valid 200 with one. Measured 2026-09-18:/rest/data/STATSNZ,AGR_AGR_001,1.0/all?lastNObservations=1→ 200 with 80 observations; the same URL with%2C→ 401.encodeURIComponenton that segment is what madestatsnz_observationsreturncount: 0against a perfectly healthy dataset./rest/dataflow/%61ll/all/latest→ 401 too, so it is their routing, not this one path.A zero from
statsnz_observationsis always explained, and a bad id is an error. Because an unknown dataset, a malformed path and a genuinely empty query are indistinguishable by status on this gateway, the tool validates the dataset id against the keyless catalogue before calling the data endpoint (cached 30 min per isolate). An unknown id raises a 404-shaped error naming near matches; an id that exists but returns nothing comes back withempty_reasonsaying which case it is — no structure at all (routed but uninterpretable), a dimensionkeythat filtered everything out, a period window with nothing in it, or a genuine upstream gap.An unfiltered query on a wide census table is too big to return, so the pack narrows it and says so. CEN23_HAD_020 with key
allwas ~208MB of SDMX-JSON on 2026-10-16 (no Content-Length, no time dimension forlastNObservationsto shrink), past the pack's 16MB streaming cap; that was 24 of 44 externalstatsnz_observationscalls in 48h. When the cap trips on an unfiltered query, the pack reads the dataset structure, pins geography dimensions (then the widest remaining ones, while the open cross product is over 250k cells) to the ROOT code Stats NZ labels "Total …" — never a "Total stated …" subtotal — re-queries, and returns the slice withrequested_key: "all"and anarrowedobject listing each pin and how to ask for the breakdown. CEN23_HAD_020 comes back as key.9999....(Total - New Zealand by regional council), 16,920 rows. A caller-suppliedkeyis never narrowed; a too-wide one, or a dataset with no Total code to pin, fails asuser_errorwith the dimensions and sample codes inline.401 does not mean "bad credential" here. Because an unmatched route also answers 401, a malformed path and a missing key are indistinguishable by status. The pack's 401 message says both possibilities out loud.
Observations come back FLAT, not series-keyed.
dataSets[0].observationsis a map of"0:3" → [value, …]anddataSets[0].seriesis absent. Reading onlyseries(as this pack first did) yields zero observations from a goodBoth layouts are mapped, plus dataset-level dimensions.
lastNObservationsdrops the collapsed dimension from the observation key, and it is NOT always the time axis. WithlastNObservations=1on AGR_AGR_001 the key is 2 parts for 3 declared dimensions — the year is simply not in the response, so rows cannot say which year they are. On INC_INC_001 the collapsed dimension isMEASURE_INC_INC_001, a measure axis, across 35,610 rows. The pack reportscollapsed_dimensionsplus a note rather than returning rows that look fully labelled.startPeriod/endPeriodonly bite on a declared time dimension, and Stats NZ mostly declares none.statsnz_resourcesreportstime_dimension: []for AGR_AGR_001, and therolefield in the data message just echoes each dimension's own id, so there is no usable time marker: a dimension namedYEAR_*is not a time dimension to this server. The pack therefore tests for the SDMX standardTIME_PERIODid and, for anything else, tells the caller to pin the dimension through thekeyargument — naming its segment position and handing back a worked key such as..<YEAR_AGR_AGR_001>. The note used to recommendstartPeriod/endPeriodunconditionally, which is advice that cannot work on a measure axis (fleet #2244).Accept: application/vnd.sdmx.data+json;version=1.0.0is a 406. Their server lists genericdata+xml 2.1 and data+json 2.0 as acceptable. Plainapplication/jsonreturns SDMX-JSON 1.0 and is what this pack asks for.Wrong host looks like an outage. The older documented host
api.stats.govt.nzanswers HTTP 502 from its Azure Application Gateway on every path including the root. A 502 reads as "their service is down" when in fact the service moved. The live host isapi.data.stats.govt.nz. Do not "fix" this pack back to the old hostname.A bare SDMX resource path 404s.
/rest/dataflowis404 Resource not found; only the fully-qualified/rest/dataflow/{agency}/{resource}/{version}form answers.Only 341 of the 911 dataflows carry a
description; the rest are title-only, so keyword filtering leans on long formal titles ("Earnings for people in paid employment", never "wages").CPI, GDP and merchandise trade are NOT in this catalogue. Measured 2026-09-17: 0 of 911 dataflows mention "price", "consumer" or "trade"; 705 are census tables. Describing the pack as covering CPI would misroute every inflation question to a source that cannot answer it.
Quick Start
Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
{
"mcpServers": {
"stats-nz": {
"url": "https://gateway.pipeworx.io/stats-nz/mcp"
}
}
}What this endpoint actually serves
tools/list at https://gateway.pipeworx.io/stats-nz/mcp returns the tools in the table
above plus the shared Pipeworx meta-tools — ask_pipeworx,
discover_tools, search_within, remember/recall and the rest of the
gateway-wide set. So the tool count you see is larger than this table: a
single-pack endpoint currently lists roughly 30 shared tools alongside the
pack's own. The connection's initialize response states its exact scope, and
is the authoritative answer for a given day.
This is deliberate, not multiplexing by accident. The meta-tools are what let a
scoped connection answer a question this pack does not cover — via
ask_pipeworx, which routes across the whole catalog — without you adding a
second MCP server. There is currently no way to mount a pack endpoint without
them; if the extra schemas cost you more context than the routing is worth,
connect to the full gateway once rather than to several pack endpoints.
Or connect to the full Pipeworx gateway to get every pack's tools listed directly, instead of just this one's:
{
"mcpServers": {
"pipeworx": {
"url": "https://gateway.pipeworx.io/mcp"
}
}
}Both URLs reach the same gateway and the same 1857+ data sources. The
only difference is which pack's tools are listed directly; ask_pipeworx
reaches all of them from either one.
No MCP client? Call it over HTTP
curl -X POST https://gateway.pipeworx.io/v1/tools/statsnz_datasets \
-H 'Content-Type: application/json' \
-d '{"query":"household income","limit":5}'No account needed for the first calls. Inspect any tool: GET https://gateway.pipeworx.io/v1/tools/statsnz_datasets. Find one: POST https://gateway.pipeworx.io/v1/tools/search_packs with {"query":"..."}.
Run it from npm
@pipeworx/mcp-stats-nz is a local stdio bridge to the Pipeworx gateway: your MCP client
starts it with npx, and it forwards every call to the same
https://gateway.pipeworx.io/stats-nz/mcp endpoint shown above. It needs network access;
there is no offline mode.
{
"mcpServers": {
"stats-nz": {
"command": "npx",
"args": ["-y", "@pipeworx/mcp-stats-nz"]
}
}
}Without a key it calls anonymously, capped at 50 calls a day. A free account
raises that to 200 a day: get a key at https://pipeworx.io/signup and add
"env": { "PIPEWORX_API_KEY": "<your key>" } to the server entry.
The key is sent as a Bearer token, the same way a hosted connection sends it,
so calls are metered and billed exactly as they are there.
It lists only this pack's tools by default. Set PIPEWORX_META_TOOLS=1 to
also list ask_pipeworx and the other gateway-wide tools.
Behind an HTTPS proxy: Node's built-in fetch does not read HTTPS_PROXY by
default. Newer Node releases honour it when NODE_USE_ENV_PROXY=1 is set; check
your Node version's documentation.
Using with ask_pipeworx
Instead of calling tools directly, you can ask questions in plain English — this works on the pack endpoint above as well as on the full gateway:
ask_pipeworx({ question: "your question about Stats Nz data" })The gateway picks the right tool and fills the arguments automatically.
More
License
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
UK Office for National Statistics dataset catalogue + Beta JSON API
Search and query 1,500+ OECD statistical datasets via SDMX. Keyless.
Search, filter, count and sum Australian government open data, with every version kept.
Search 77k public-sector open data APIs across 10 countries. Read-only, no API key.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables searching and retrieving records from the DigitalNZ collection, with tools for keyword search and fetching full item details.9 npmMIT
- AlicenseAqualityDmaintenanceProvides access to UK economic, social, and labour-market statistics via the ONS beta and Nomis APIs, enabling discovery and retrieval of time series, datasets, and census data.18MIT
- AlicenseNot gradedqualityBmaintenanceEnables searching and exploring New Zealand government data via CKAN API, including full-text search, organizations, groups, tags, and recent changes.447 npmMIT
- AlicenseNot gradedqualityAmaintenanceEnables searching, exploring, and querying over 1,500 OECD statistical datasets via SDMX, covering national accounts, employment, trade, PISA, health, and more.658 npm2Apache 2.0