npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@statsmcp/core

v0.4.1

Published

MCP server toolkit for statistics APIs: PxWeb v1 and v2, StatBank Denmark, CBS OData, PxStat, SDMX, Eurostat, Statistics Canada and SingStat

Readme

@statsmcp/core

A toolkit to make MCP servers for statistics databases that use the PxWeb API v1 or v2. Many national statistics offices use PxWeb.

For a ready server, refer to @statsmcp/sistat (Slovenia).

Install

You need Node.js 20 or later. TypeScript users need TypeScript 5.7 or later.

npm install @statsmcp/core @modelcontextprotocol/server

@modelcontextprotocol/server is a peer dependency. Your server and this package must use the same copy.

Make a server

Make a PxwebPreset for the PxWeb instance, then give it to createPresetServer:

import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
import {
  createMemoryCache,
  createPresetServer,
  type PxwebPreset
} from '@statsmcp/core';

const preset: PxwebPreset = {
  name: 'statfin',
  title: 'Statistics Finland',
  version: '0.1.0',
  apiBaseUrl: 'https://pxdata.stat.fi/PXWeb/api/v1',
  database: 'StatFin',
  languages: ['fi', 'en', 'sv'],
  attribution: () => 'Source: Statistics Finland',
  tableUrl: (lang) => `https://pxdata.stat.fi/PxWeb/pxweb/${lang}/StatFin/`,
  instructions: 'Official statistics for Finland. Call search_tables first.',
  maxCells: 5000,
  searchLimit: 10
};

const server = createPresetServer(preset, { cache: createMemoryCache() });
await server.connect(new StdioServerTransport());

createPresetServer makes the PxWeb client from the preset. Its options are cache, fetch and userAgent. The default user agent is <name>-mcp/<version>. To use your own client, call createPxwebServer(preset, client).

The server has three tools: search_tables, get_table_metadata and query_table. Each result ends with the text from attribution. Results of the table tools also contain the link from tableUrl.

Preset fields

| Field | Description | | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | | name | Server name that the MCP client sees. | | title | Display name. | | version | Server version. | | apiBaseUrl | API root, without the language segment. If each language has its own root, use an object, for example { en: '…/pxen/api/v1', is: '…/pxis/api/v1' }. | | database | Optional. Path segment after the language: Data (default) on SiStat, table on SSB, StatFin on StatFin. | | languages | Language codes. The first one is the default. | | attribution | Source line for a language. It is added to every result. | | tableUrl | Link in table results. It gets the language and the table ID. | | instructions | Instructions for the model, sent when the client connects. | | maxCells | Maximum number of cells in one query. Larger queries are refused. | | searchLimit | Default number of search results. | | searchAliases | Optional. Per language, { terms, query } pairs. If the query contains a term, the server also searches for query, for example salary → earnings. |

Other exports

  • createPxwebClient: the PxWeb client alone (search, getMetadata, query). It has a timeout and a response size limit, and it validates each response.
  • createMemoryCache: an in-memory cache with a size limit. To use a different store, implement the Cache interface (get and set).
  • planQuery: checks a selection against the table metadata and counts the cells.
  • flattenJsonStat and toCsv: convert a JSON-stat 2 dataset to rows and CSV.
  • PxwebError and QueryPlanError: the errors of the client and the planner.
  • createTableIndex and createTableIndexLoader: keyword search over a table list (BM25, stop words, prefix and fuzzy matching, the office's catalogue order). Use them for APIs without a good search.
  • Table snapshots: writeSnapshot, readSnapshot, urlSnapshotReader, bucketSnapshotReader and firstSnapshot store and read a table list as gzip JSON (index/<source>/<lang>.json.gz).
  • createPresetClient: the API client that a preset selects, without the MCP server. Clients that search a local index also have listTables(lang), which gives the full table list.
  • tableSnapshots (option of createPresetServer): a SnapshotReader. If the live table list of a source fails, search uses the snapshot of that source.
  • @statsmcp/core/node: nodeTableSnapshots(dir) for Node.js. It reads the snapshot from https://statsmcp.dev first, then from <dir>/<lang>.json.gz. Set STATSMCP_INDEX=off to stop the requests to statsmcp.dev. Set STATSMCP_INDEX_URL to use a mirror.
  • Other API clients: createPxwebV2Client, createStatbankDkClient, createCbsODataClient, createEurostatClient, createStatcanClient and createSingstatClient. A preset selects one with api.

Terms of use

Before you publish a server for a PxWeb instance, read the terms of use of that statistics office. Most offices require that you name them as the source.

Licence

MIT