Skip to main content
Glama
nomis-mcp

nomis-mcp

nomis-mcp

Query the NOMIS API — the ONS labour market and census data service — from Claude. Two halves that are meant to be installed together:

  • an MCP server, six tools shaped around the discovery chain NOMIS actually requires rather than a one-to-one mapping of its endpoints;

  • the nomis-extract skill, which drives those tools: it turns a vague data request into a confirmed spec before it fetches anything, carries the West of England geography codes, and can emit the finished query as a reproducible nomisdata R script.

The server without the skill works, but every session then re-derives the same geography vintages and dataset quirks.

Why hand-written tools

NOMIS publishes 1,617 datasets sharing 482 distinct dimension concepts. Only measures and freq appear in all of them, geography in 1,586. No fixed OpenAPI parameter list covers that, so generating tools from a spec cannot work. The useful unit of work is a four-step chain: search datasets, read the dimensions of one, resolve codes, fetch.

Related MCP server: Australian Bureau of Statistics

Getting started

1. Install the server

git clone https://github.com/stevecrawshaw/nomis-mcp.git ~/projects/nomis-mcp
cd ~/projects/nomis-mcp
uv sync

2. Get an API key

Sign in at nomisweb.co.uk, open My Account, and copy the unique ID — it starts with 0x.

This matters more than it looks. Without a key you are an anonymous user capped at 25,000 cells, and NOMIS enforces that cap by returning HTTP 200 with a body cut short and no error of any kind. A query matching 1.7 million records comes back as 25,000 rows that look complete.

cp .env.example .env    # then paste the key into NOMIS_UID

Either variable works:

NOMIS_UID="0x..."                        # quote it, see below
NOMIS_CONFIG_FILE=~/projects/config.yml  # or reuse the R project's config

NOMIS_CONFIG_FILE reads the same layout nomis_codes.R uses:

nomis:
  uid: "0x1a2b3c"

Quote the value. YAML 1.1 reads unquoted 0x1a2b3c as the integer 1715004, which would send a mangled key and silently demote you to anonymous. The loader recovers the literal token anyway, and there is a test for it, but quoting is clearer.

3. Register the server with Claude Code

Copy .mcp.json.example to .mcp.json in whichever project should have NOMIS access, then set the absolute path and your key:

{
  "mcpServers": {
    "nomis": {
      "command": "uv",
      "args": ["run", "--directory", "/home/you/projects/nomis-mcp",
               "python", "-m", "nomis_mcp.server"],
      "env": {
        "NOMIS_UID": "0x...",
        "NOMIS_OUTPUT_DIR": "~/nomis-downloads"
      }
    }
  }
}

.mcp.json is git-ignored here because it holds the key. For access from every project instead of one, run claude mcp add --scope user with the same command.

4. Install the skill

bash scripts/install-skill.sh                     # symlink into ~/.claude/skills
bash scripts/install-skill.sh --copy              # snapshot instead of symlink
bash scripts/install-skill.sh --project ~/work/x  # one project only

The symlink is the default so a git pull here updates the skill in place. The script also merges the nomis-extract entry into your skill-rules.json, backing up the existing file, so its trigger keywords fire without you naming the skill.

5. Check it works

Restart Claude Code, then ask it to run check_auth. That tool probes a known large query and reports whether the cap is actually lifted, rather than trusting that a key is present. Then try a real request:

Claimant count for the West of England authorities, latest month

The skill should ask about topic, geography and timescale, show you a written spec, and fetch only after you confirm it.

Tools

Tool

Purpose

check_auth

Report key status and empirically test the 25,000-cell cap

search_datasets

Find datasets by keyword, with status and last-updated

get_dataset_dimensions

List a dataset's filterable dimensions and geography types

search_codes

Resolve names to the opaque numeric codes fetches need

fetch_data

Fetch observations, capped and truncation-checked

fetch_data_to_file

Stream an unrestricted query to CSV on disc

Worked example

Claimant count for Bristol, latest month:

search_datasets("claimant")                       # -> NM_1_1
get_dataset_dimensions("NM_1_1")                  # -> geography, time, sex, item, measures
search_codes("NM_1_1", "geography")               # -> TYPE424 = local authorities (April 2023)
search_codes("NM_1_1", "geography", "bristol", "TYPE424")
                                                  # -> 1778384919, E06000023
fetch_data("NM_1_1", {"geography": "1778384919", "sex": "7",
                      "item": "1", "measures": "20100", "time": "latest"})
                                                  # -> 626, July 2026

Geography takes two steps deliberately. Searching the geography codelist without a type returns nothing and reports success, because the top of that hierarchy holds only a few country nodes. search_codes routes around this by returning the type list instead.

The skill

skills/nomis-extract/ is the canonical copy.

File

Loaded

SKILL.md

Always. The seven-step chain: scope, dataset, columns, filters, confirm, fetch, R script

reference.md

On geography, MAKE aggregates, or a search_datasets error

r-script.md

On step 7, when writing the nomisdata script

reference.md is where the local knowledge lives: the four West of England authority codes, why no single NOMIS code covers that footprint, the latest boundary vintage per geography level, and the per-dataset traps (NM_2014_1 returns duplicate "All Ages" rows; NM_162_1 rounds to the nearest 5). Add a dataset quirk there each time you find one.

Silent failures this server guards against

NOMIS answers many bad requests with HTTP 200. Each of these is handled explicitly and has a test or an error path:

Input

NOMIS response

Handling

Oversized query

200, body truncated at the cap

RECORD_COUNT compared to rows returned, truncated flag plus a warning in the reply

Unknown dataset id

200, {"overview": {"id": "NM_NOPE"}}

Absence of a name raises ToolError

Unknown dimension name

200, empty body

Empty body raises ToolError naming the likely cause

Search without wildcards

200, no matches

Wildcards added automatically

Geography search above a type

200, empty codelist

Returns the geography type list instead

One it does not: a search_datasets query matching nothing throws 'NoneType' object has no attribute 'get' from the API rather than returning an empty list. The skill treats that error as "no results", not "bad query".

Development

uv run pytest        # 21 tests, fixtures captured from the live API 2026-08-29
uv run ruff check src tests
uv run mypy src

parse.py holds no network calls, so the SDMX and CSV handling is tested against fixtures in tests/fixtures/.

Scope

Exploratory querying inside Claude. The nomisdata R package remains the analysis path; fetch_data_to_file and the generated R script are the handover points. Not implemented: jsonstat output, spatial/KML fetch (1,000-cell cap), response caching.

Licence

MIT. See LICENSE.

Last reviewed: 2026-08-29

Available Tools

6 tools
check_authA

Report whether the server holds a NOMIS API key, and test the cell limit.

Without a key, every data request is silently capped at 25,000 records: NOMIS answers with HTTP 200 and a truncated body, no error. With a valid unique ID the cap is lifted.

Run this when a fetch reports truncation, or to confirm setup. The probe downloads one narrow column of a large query, so it takes a few seconds.

To obtain a key: sign in at nomisweb.co.uk, open My Account, and copy the unique ID (it starts with 0x). Supply it to this server as the NOMIS_UID environment variable, or point NOMIS_CONFIG_FILE at a YAML file with nomis: {uid: 0x...}. The key is a password: it is never exposed as a tool parameter and is redacted from every URL returned here.

Inputs: no named parameters. Returns: object

fetch_dataA

Fetch observations from a dataset. Codes must come from search_codes.

Returns rows plus 'total', the number of records matching the query, and 'truncated'. Read them. NOMIS answers an oversized query with HTTP 200 and a body cut short with no error, so a result can look complete while holding a small fraction of the data. Never total, average or rank a truncated result; narrow the filters, or use fetch_data_to_file.

A worked example, claimant count for Bristol in the latest month:

fetch_data('NM_1_1', {'geography': '1778384919', 'sex': '7',
                      'item': '1', 'measures': '20100',
                      'time': 'latest'})

Requesting a whole geography type (e.g. 'TYPE151' for 2021 LSOAs) across several dimensions produces millions of records. Use fetch_data_to_file.

Inputs: filters (required), dataset_id (required), select, record_limit, +1 more. Returns: object

fetch_data_to_fileA

Stream an unrestricted query to a CSV file instead of into the reply.

For results too large to read: whole geography types, long time series, LSOA-level census tables. Nothing is loaded into memory or context, so use this rather than paging fetch_data hundreds of times.

Without an API key the file is still capped at 25,000 records; run check_auth first if the row count looks suspiciously round.

Returns the path for onward analysis in R, DuckDB or pandas.

Inputs: filters (required), filename (required), dataset_id (required), select. Returns: object

get_dataset_dimensionsA

List the dimensions a dataset accepts as filters, and its geography types.

Essential before fetching. Dimensions vary per dataset: across NOMIS there are over 480 distinct dimension concepts, and only 'measures', 'freq' and 'geography' are near-universal. A filter this tool does not list will be rejected or silently ignored by fetch_data.

The returned 'geography_types' are the vintages available for this dataset, e.g. TYPE424 (local authorities as of April 2023) or TYPE151 (2021 LSOAs). Pick one, then pass it to search_codes to resolve an area name to a code.

Inputs: dataset_id (required). Returns: object

search_codesA

Resolve dimension values to the numeric codes fetch_data needs.

Codes are opaque integers (Bristol, City of is 1778384919 in TYPE424) and cannot be guessed or derived from ONS GSS codes. Always come here first.

Geography needs two steps. Searching geography without a type_code returns the list of geography types for the dataset, because the top of the geography codelist holds only a handful of country nodes and a search there matches nothing and returns success. Pick a type, then search within it:

search_codes('NM_1_1', 'geography')                     -> type list
search_codes('NM_1_1', 'geography', 'bristol', 'TYPE424')
    -> value 1778384919, geog_code E06000023

Non-geography dimensions are searched directly, no type_code needed.

Inputs: concept (required), dataset_id (required), pattern, type_code. Returns: object

search_datasetsA

Find NOMIS datasets by keyword. Start here, then call get_dataset_dimensions.

Returns dataset ids such as NM_1_1 along with name, description, keywords and status. Prefer datasets whose status is "Current (being actively updated)" over "Historical (not actively being updated)" unless the user asked for a historical series.

NOMIS publishes over 1,600 datasets, so a narrow term is better than a broad one. Census topic summary tables are named with a TS prefix, e.g. searching 'TS058' finds the travel-to-work table.

Inputs: query (required). Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.7/5.0

    Scored across 6 tools

    Disambiguation5/5

    Each tool maps to a distinct stage of the NOMIS workflow: authentication, dataset discovery, dimension introspection, code lookup, inline data retrieval, and file-based retrieval. Even fetch_data and fetch_data_to_file are cleanly separated by output mode and result size, with explicit guidance on when to use each.

    Naming Consistency5/5

    All six tools follow a consistent verb_noun pattern: check_auth, search_datasets, get_dataset_dimensions, search_codes, fetch_data, fetch_data_to_file. The one compound name still fits the same convention and is easy to predict.

    Tool Count5/5

    Six tools is a well-scoped size for a read-only statistics API wrapper. Each tool earns its place and together they cover discovery, preparation, and retrieval without bloat.

    Completeness5/5

    The tool set covers the full read-only lifecycle: find datasets, inspect dimensions, resolve codes, fetch small results, and stream large results to file. No obvious dead ends or missing operations for the stated purpose of accessing NOMIS data.

    Maintenance

    ActivitySlowing
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables access to official UK Office for National Statistics data including demographics, economics, and social statistics through the ONS Beta API. Supports browsing, searching, and querying datasets with built-in shortcuts for popular statistics like inflation, regional GDP, and wellbeing data.
      5
      19 npm
      1
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables querying UK Office for National Statistics datasets and their editions through natural language, with no authentication required.
      72 npm
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Exposes the Eurostat Statistics API, enabling LLMs to discover, explore, and retrieve official EU statistical data through search, dimension inspection, and data retrieval tools.
      3
      -