UK ONS MCP Server
This server provides access to UK Office for National Statistics (ONS) data, enabling you to discover, search, and retrieve official government statistics — no API key required.
List Datasets: Browse the full ONS dataset catalogue with pagination support.
Search Datasets: Find datasets by keyword, title, description, or ID (e.g. search "inflation" to find
cpih01).Get Dataset Metadata: Retrieve detailed metadata for a specific dataset by its ID.
Discover Dimensions: Learn about a dataset's required dimensions, including option counts and sample codes — essential before querying observations.
Get Dimension Options: Page through the complete list of valid option codes for any specific dimension.
Retrieve Observations: Fetch specific data points by supplying values for all dimensions, with exactly one wildcard (
*) allowed to vary a single dimension.Get Latest Data: Quickly obtain the most recent observations using auto-filled defaults (
time=*,geography=K02000001for UK-wide), with optional filters.Access Curated Resources: Use
ons://popular_datasetsfor a list of common dataset IDs, andons://api_infofor API details and recommended workflow.
All operations are read-only GET requests against the public ONS API, with input validation and bounded responses.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@UK ONS MCP Server what's the latest UK inflation rate?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
UK ONS MCP Server
A Model Context Protocol (MCP) server for the UK Office for National Statistics (ONS) CMD API (https://api.beta.ons.gov.uk/v1).
Query official UK government statistics — inflation, GDP, wellbeing, trade, deaths and more — straight from your MCP-compatible assistant. No API key required.
Features
Direct ONS access — no authentication, no tokens
Browse & search the full published dataset catalogue
Dimension discovery — inspect a dataset's dimensions and valid option codes before querying
Real observations — pull data points filtered by geography, time and any other dimension
Latest-data shortcut that auto-fills sensible defaults
TypeScript, native
fetch, zero runtime deps beyond the MCP SDK and ZodInput validation and actionable, self-correcting error messages
Related MCP server: ONS + Nomis MCP server
Requirements
Node.js >= 18.17 (uses the global
fetchandAbortSignal.timeout)
Recommended agent workflow
The ONS observations endpoint requires a value for every dimension of a dataset, and allows exactly one wildcard *. The intended flow is:
search_datasets— find a dataset id by keyword (e.g."inflation"->cpih01).get_dataset_dimensions— learn the required dimensions and see sample option codes.get_observation— request data, giving each dimension a value and using*for the one you want to vary.
get_latest_data is a convenience wrapper: it auto-fills time="*" and geography="K02000001" (UK) and any single-option dimension. If a dataset needs more choices, it returns the available options so you can switch to get_observation.
Available Tools
Tool | Purpose |
| Paginated list of all datasets ( |
| Keyword search over id/title/description/keywords. |
| Full metadata for one dataset by id. |
| Dimensions of a dataset's latest version, with option counts and samples. Call before |
| Page through the full list of valid option codes for one dimension. |
| Retrieve observations. Every dimension needs a value; exactly one may be |
| Latest observations with auto-filled |
Resources
URI | Description |
| Curated, live-verified list of common dataset ids. |
| API base URL, auth model and the recommended workflow. |
Example
Query CPIH (UK inflation) as a UK-wide time series:
// 1) discover dimensions
get_dataset_dimensions { "dataset_id": "cpih01" }
// -> dimensions: aggregate (122 options, e.g. CP00 "Overall Index"), geography, time
// 2) fetch the Overall Index across all time periods for the UK
get_observation {
"dataset_id": "cpih01",
"dimensions": { "time": "*", "geography": "K02000001", "aggregate": "CP00" }
}Omitting a required dimension returns a helpful error listing what is missing and sample codes to use, so an agent can retry without guessing.
Installation & configuration
Option A — npx (published package)
No install step; the client runs it on demand.
Claude Desktop (claude_desktop_config.json) or Claude Code (.mcp.json):
{
"mcpServers": {
"uk-ons": {
"command": "npx",
"args": ["-y", "uk_ons_mcp_server"]
}
}
}Option B — local build (from source)
git clone https://github.com/dwain-barnes/uk-ons-mcp-server.git
cd uk-ons-mcp-server
npm install
npm run buildThen point your client at the built entry point (use an absolute path):
{
"mcpServers": {
"uk-ons": {
"command": "node",
"args": ["/absolute/path/to/uk_ons_mcp_server/dist/index.js"]
}
}
}On Windows, use a full path such as C:\\Users\\you\\uk_ons_mcp_server\\dist\\index.js.
Claude Code can also add it from the CLI:
claude mcp add uk-ons -- node /absolute/path/to/uk_ons_mcp_server/dist/index.jsDevelopment
npm install
npm run build # compile TypeScript to dist/
npm start # run the built server on stdio
npm run dev # tsc --watch
npm run clean # remove dist/
npm test # build, then run the end-to-end smoke test against the live APIThe smoke test (test/smoke.mjs) spawns the built server over stdio with the MCP SDK client and checks all seven tools plus a resource end-to-end.
Security notes
Read-only. Every tool only performs
GETrequests against the public ONS API; nothing is written or mutated.No authentication or secrets. The ONS CMD API is open and keyless, so there are no tokens to store or leak.
Input validation. Dataset ids, editions, versions and dimension names are validated against a strict character set (
[A-Za-z0-9._-], max 100 chars) and every path/query value is URL-encoded before a request is made. Dimension values may additionally be the single wildcard*.Bounded responses. Observation results are capped (with a
truncatedflag and total count) to avoid overwhelming the model's context.
License
MIT — see LICENSE.
Disclaimer This project is unofficial and not endorsed by the UK Office for National Statistics. Data usage remains subject to ONS terms and the Open Government Licence.
Available Tools
5 toolsget_datasetC
Get detailed information about a specific dataset
Inputs: dataset_id (required).
get_latest_dataC
Get the latest available data for a dataset with optional filters
Inputs: dataset_id (required), geography, time_period.
get_observationC
Get specific data observations with dimension filters
Inputs: dataset_id (required), dimensions (required), edition, version.
list_datasetsB
List available ONS datasets with metadata
Inputs: limit, offset.
search_datasetsB
Search for datasets by name or description
Inputs: query (required), limit.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool has a clearly distinct purpose: list_datasets and search_datasets handle dataset discovery, get_dataset retrieves metadata, get_latest_data provides filtered current data, and get_observation targets specific data points. There is no overlap or ambiguity between these functions.
All tools follow a consistent verb_noun pattern with snake_case (get_dataset, get_latest_data, get_observation, list_datasets, search_datasets). The naming is predictable and follows a clear convention throughout.
With 5 tools, this server is well-scoped for accessing UK ONS data. The count is appropriate, covering dataset discovery, metadata retrieval, and data access without being too sparse or bloated.
The toolset provides strong coverage for data retrieval and discovery in the ONS domain, including listing, searching, and accessing datasets and observations. A minor gap is the lack of update or administrative tools, but this is reasonable for a read-only data access server.
Maintenance
Related MCP Connectors
Query UK Parliament, elections, crime stats, ONS census data, and national archives
UK Office for National Statistics dataset catalogue + Beta JSON API
ONS statistics and time series (CPI, GDP, unemployment) and Bank of England rates
Official statistics for AI agents: Eurostat, World Bank, OECD, IMF and WHO data for 150+ countries.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables querying UK Office for National Statistics datasets and their editions through natural language, with no authentication required.72 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 gradedqualityFmaintenanceProvides tools to list, retrieve metadata, editions, latest observations, and time series from the UK Office for National Statistics (ONS) datasets.2 npmMIT
- AlicenseAqualityCmaintenanceEnables querying the ONS NOMIS labour market and census API from Claude, with tools for dataset discovery, dimension exploration, code resolution, and data fetching while guarding against silent truncation.6MIT