@statsmcp/core 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +87 -2
- package/dist/index.d.ts +376 -0
- package/dist/index.js +3192 -0
- package/dist/node.d.ts +14 -0
- package/dist/node.js +37 -0
- package/dist/snapshot-CT_ItdeR.js +118 -0
- package/dist/snapshot-DwtIVsqx.d.ts +51 -0
- package/package.json +60 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tadej Polajnar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @statsmcp/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A toolkit to make MCP servers for statistics databases that use the [PxWeb API](https://www.scb.se/en/services/open-data-api/api-for-the-statistical-database/) v1 or v2. Many national statistics offices use PxWeb.
|
|
4
|
+
|
|
5
|
+
For a ready server, refer to [@statsmcp/sistat](https://www.npmjs.com/package/@statsmcp/sistat) (Slovenia).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
You need Node.js 20 or later. TypeScript users need TypeScript 5.7 or later.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @statsmcp/core @modelcontextprotocol/server
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`@modelcontextprotocol/server` is a peer dependency. Your server and this package must use the same copy.
|
|
16
|
+
|
|
17
|
+
## Make a server
|
|
18
|
+
|
|
19
|
+
Make a `PxwebPreset` for the PxWeb instance, then give it to `createPresetServer`:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
23
|
+
import {
|
|
24
|
+
createMemoryCache,
|
|
25
|
+
createPresetServer,
|
|
26
|
+
type PxwebPreset
|
|
27
|
+
} from '@statsmcp/core';
|
|
28
|
+
|
|
29
|
+
const preset: PxwebPreset = {
|
|
30
|
+
name: 'statfin',
|
|
31
|
+
title: 'Statistics Finland',
|
|
32
|
+
version: '0.1.0',
|
|
33
|
+
apiBaseUrl: 'https://pxdata.stat.fi/PXWeb/api/v1',
|
|
34
|
+
database: 'StatFin',
|
|
35
|
+
languages: ['fi', 'en', 'sv'],
|
|
36
|
+
attribution: () => 'Source: Statistics Finland',
|
|
37
|
+
tableUrl: (lang) => `https://pxdata.stat.fi/PxWeb/pxweb/${lang}/StatFin/`,
|
|
38
|
+
instructions: 'Official statistics for Finland. Call search_tables first.',
|
|
39
|
+
maxCells: 5000,
|
|
40
|
+
searchLimit: 10
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const server = createPresetServer(preset, { cache: createMemoryCache() });
|
|
44
|
+
await server.connect(new StdioServerTransport());
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`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)`.
|
|
48
|
+
|
|
49
|
+
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`.
|
|
50
|
+
|
|
51
|
+
## Preset fields
|
|
52
|
+
|
|
53
|
+
| Field | Description |
|
|
54
|
+
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
55
|
+
| `name` | Server name that the MCP client sees. |
|
|
56
|
+
| `title` | Display name. |
|
|
57
|
+
| `version` | Server version. |
|
|
58
|
+
| `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' }`. |
|
|
59
|
+
| `database` | Optional. Path segment after the language: `Data` (default) on SiStat, `table` on SSB, `StatFin` on StatFin. |
|
|
60
|
+
| `languages` | Language codes. The first one is the default. |
|
|
61
|
+
| `attribution` | Source line for a language. It is added to every result. |
|
|
62
|
+
| `tableUrl` | Link in table results. It gets the language and the table ID. |
|
|
63
|
+
| `instructions` | Instructions for the model, sent when the client connects. |
|
|
64
|
+
| `maxCells` | Maximum number of cells in one query. Larger queries are refused. |
|
|
65
|
+
| `searchLimit` | Default number of search results. |
|
|
66
|
+
| `searchAliases` | Optional. Per language, `{ terms, query }` pairs. If the query contains a term, the server also searches for `query`, for example `salary` → `earnings`. |
|
|
67
|
+
|
|
68
|
+
## Other exports
|
|
69
|
+
|
|
70
|
+
- `createPxwebClient`: the PxWeb client alone (`search`, `getMetadata`, `query`). It has a timeout and a response size limit, and it validates each response.
|
|
71
|
+
- `createMemoryCache`: an in-memory cache with a size limit. To use a different store, implement the `Cache` interface (`get` and `set`).
|
|
72
|
+
- `planQuery`: checks a selection against the table metadata and counts the cells.
|
|
73
|
+
- `flattenJsonStat` and `toCsv`: convert a JSON-stat 2 dataset to rows and CSV.
|
|
74
|
+
- `PxwebError` and `QueryPlanError`: the errors of the client and the planner.
|
|
75
|
+
- `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.
|
|
76
|
+
- Table snapshots: `writeSnapshot`, `readSnapshot`, `urlSnapshotReader`, `bucketSnapshotReader` and `firstSnapshot` store and read a table list as gzip JSON (`index/<source>/<lang>.json.gz`).
|
|
77
|
+
- `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.
|
|
78
|
+
- `tableSnapshots` (option of `createPresetServer`): a `SnapshotReader`. If the live table list of a source fails, search uses the snapshot of that source.
|
|
79
|
+
- `@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.
|
|
80
|
+
- Other API clients: `createPxwebV2Client`, `createStatbankDkClient`, `createCbsODataClient`, `createEurostatClient`, `createStatcanClient` and `createSingstatClient`. A preset selects one with `api`.
|
|
81
|
+
|
|
82
|
+
## Terms of use
|
|
83
|
+
|
|
84
|
+
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.
|
|
85
|
+
|
|
86
|
+
## Licence
|
|
87
|
+
|
|
88
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { a as UrlSnapshotReaderOptions, c as readSnapshot, d as writeSnapshot, i as SnapshotReader, l as snapshotKey, n as Snapshot, o as bucketSnapshotReader, r as SnapshotBucket, s as firstSnapshot, t as SNAPSHOT_VERSION, u as urlSnapshotReader } from "./snapshot-DwtIVsqx.js";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
interface Cache {
|
|
5
|
+
get(key: string): Promise<string | undefined>;
|
|
6
|
+
set(key: string, value: string, ttlSeconds: number): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
interface MemoryCacheOptions {
|
|
9
|
+
maxEntries?: number;
|
|
10
|
+
/** Total budget in UTF-16 code units (about 2 bytes each). */
|
|
11
|
+
maxChars?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function createMemoryCache(options?: MemoryCacheOptions): Cache;
|
|
14
|
+
declare const jsonStatDatasetSchema: z.ZodObject<{
|
|
15
|
+
class: z.ZodLiteral<"dataset">;
|
|
16
|
+
label: z.ZodOptional<z.ZodString>;
|
|
17
|
+
source: z.ZodOptional<z.ZodString>;
|
|
18
|
+
id: z.ZodArray<z.ZodString>;
|
|
19
|
+
size: z.ZodArray<z.ZodNumber>;
|
|
20
|
+
dimension: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
21
|
+
label: z.ZodOptional<z.ZodString>;
|
|
22
|
+
category: z.ZodObject<{
|
|
23
|
+
index: z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodNumber>, z.ZodArray<z.ZodString>]>;
|
|
24
|
+
label: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
}, z.core.$strip>>;
|
|
27
|
+
value: z.ZodUnion<readonly [z.ZodArray<z.ZodNullable<z.ZodNumber>>, z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodNumber>>]>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
type JsonStatDataset = z.infer<typeof jsonStatDatasetSchema>;
|
|
30
|
+
interface FlatTable {
|
|
31
|
+
label: string | undefined;
|
|
32
|
+
columns: string[];
|
|
33
|
+
rows: (string | number | null)[][];
|
|
34
|
+
}
|
|
35
|
+
export declare function flattenJsonStat(dataset: JsonStatDataset): FlatTable;
|
|
36
|
+
export declare function toCsv(table: FlatTable): string;
|
|
37
|
+
/** One table in a source's catalogue, as the index and the snapshots store it. */
|
|
38
|
+
export declare const tableDocSchema: z.ZodObject<{
|
|
39
|
+
id: z.ZodString;
|
|
40
|
+
title: z.ZodString;
|
|
41
|
+
path: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
42
|
+
updated: z.ZodOptional<z.ZodString>;
|
|
43
|
+
lastPeriod: z.ZodOptional<z.ZodString>;
|
|
44
|
+
discontinued: z.ZodOptional<z.ZodBoolean>;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
type TableDoc = z.infer<typeof tableDocSchema>;
|
|
47
|
+
export declare class PxwebError extends Error {
|
|
48
|
+
readonly status: number;
|
|
49
|
+
constructor(message: string, status: number);
|
|
50
|
+
}
|
|
51
|
+
interface HttpOptions {
|
|
52
|
+
cache?: Cache;
|
|
53
|
+
fetch?: typeof fetch;
|
|
54
|
+
userAgent?: string;
|
|
55
|
+
timeoutMs?: number;
|
|
56
|
+
}
|
|
57
|
+
declare const searchHitSchema: z.ZodObject<{
|
|
58
|
+
id: z.ZodString;
|
|
59
|
+
path: z.ZodOptional<z.ZodString>;
|
|
60
|
+
title: z.ZodString;
|
|
61
|
+
published: z.ZodOptional<z.ZodString>;
|
|
62
|
+
score: z.ZodOptional<z.ZodNumber>;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
type SearchHit = z.infer<typeof searchHitSchema>;
|
|
65
|
+
interface TableSearchHit {
|
|
66
|
+
tableId: string;
|
|
67
|
+
title: string;
|
|
68
|
+
published: string | undefined;
|
|
69
|
+
/** The office has moved the table to its archive; ranked low and marked in results. */
|
|
70
|
+
archived?: true;
|
|
71
|
+
}
|
|
72
|
+
/** Clients with a local index leave out discontinued tables unless asked. */
|
|
73
|
+
interface TableSearchOptions {
|
|
74
|
+
includeArchived?: boolean;
|
|
75
|
+
}
|
|
76
|
+
interface TableVariable {
|
|
77
|
+
code: string;
|
|
78
|
+
label: string;
|
|
79
|
+
values: string[];
|
|
80
|
+
valueLabels: string[];
|
|
81
|
+
eliminable: boolean;
|
|
82
|
+
isTime: boolean;
|
|
83
|
+
}
|
|
84
|
+
interface TableMetadata {
|
|
85
|
+
title: string;
|
|
86
|
+
variables: TableVariable[];
|
|
87
|
+
}
|
|
88
|
+
interface PxwebSelection {
|
|
89
|
+
code: string;
|
|
90
|
+
selection: {
|
|
91
|
+
filter: 'item' | 'top' | 'all';
|
|
92
|
+
values: string[];
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
interface PxwebClient {
|
|
96
|
+
search(lang: string, query: string, options?: TableSearchOptions): Promise<TableSearchHit[]>;
|
|
97
|
+
getMetadata(lang: string, tableId: string): Promise<TableMetadata>;
|
|
98
|
+
/** The full table catalogue, for clients that search a local index. */
|
|
99
|
+
listTables?(lang: string): Promise<TableDoc[]>;
|
|
100
|
+
query(lang: string, tableId: string, selections: PxwebSelection[]): Promise<FlatTable>;
|
|
101
|
+
}
|
|
102
|
+
/** One API root, or one per language when each language has its own root. */
|
|
103
|
+
type ApiBaseUrl = string | Readonly<Record<string, string>>;
|
|
104
|
+
interface PxwebClientOptions {
|
|
105
|
+
baseUrl: ApiBaseUrl;
|
|
106
|
+
/**
|
|
107
|
+
* Database segment after the language, "Data" on SiStat. With an array, search
|
|
108
|
+
* covers every database in it and each table id starts with its database.
|
|
109
|
+
*/
|
|
110
|
+
database?: string | readonly [string, ...string[]];
|
|
111
|
+
cache?: Cache;
|
|
112
|
+
fetch?: typeof fetch;
|
|
113
|
+
userAgent?: string;
|
|
114
|
+
timeoutMs?: number;
|
|
115
|
+
/** Clock for search ranking; defaults to the system time. */
|
|
116
|
+
now?: () => Date;
|
|
117
|
+
/** Builds the table id from a search hit; defaults to `path/id`. */
|
|
118
|
+
tableIdFromHit?: (hit: SearchHit) => string;
|
|
119
|
+
/** True when the office keeps the table in its archive, for example by its path. */
|
|
120
|
+
isArchived?: (hit: SearchHit) => boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Full table list (for example a crawled snapshot). When set, search uses a
|
|
123
|
+
* local index over it instead of the API search.
|
|
124
|
+
*/
|
|
125
|
+
tableList?: (lang: string) => Promise<readonly TableDoc[]>;
|
|
126
|
+
}
|
|
127
|
+
export declare function createPxwebClient(options: PxwebClientOptions): PxwebClient;
|
|
128
|
+
interface SearchAlias {
|
|
129
|
+
/** Lower-case words or phrases that trigger the alias when the query contains them. */
|
|
130
|
+
terms: readonly string[];
|
|
131
|
+
/** Extra query in the database's own wording, for example "earnings" for "salary". */
|
|
132
|
+
query: string;
|
|
133
|
+
}
|
|
134
|
+
interface PxwebPreset {
|
|
135
|
+
/** MCP server name without a "-mcp" suffix, for example "sistat". */
|
|
136
|
+
name: string;
|
|
137
|
+
title: string;
|
|
138
|
+
version: string;
|
|
139
|
+
/**
|
|
140
|
+
* PxWeb API v1 root, for example "https://pxweb.stat.si/SiStatData/api/v1".
|
|
141
|
+
* Use `{ en: …, is: … }` when each language has its own root.
|
|
142
|
+
*/
|
|
143
|
+
apiBaseUrl: ApiBaseUrl;
|
|
144
|
+
/**
|
|
145
|
+
* API type, default "pxweb-v1". The other types need one string `apiBaseUrl`
|
|
146
|
+
* (the language is a parameter), use the API table ids as they are and ignore
|
|
147
|
+
* `database` and `tableIdFromHit`.
|
|
148
|
+
*/
|
|
149
|
+
api?: 'pxweb-v1' | 'pxweb-v2' | 'statbank-dk' | 'cbs-odata' | 'eurostat' | 'statcan-wds' | 'singstat' | 'cso-pxstat' | 'sdmx';
|
|
150
|
+
/** SDMX agency id, for example "ABS". Required when `api` is "sdmx". */
|
|
151
|
+
sdmxAgency?: string;
|
|
152
|
+
/**
|
|
153
|
+
* Search strategy for APIs that offer both: "api" uses the API's own search,
|
|
154
|
+
* "index" lists every table and searches locally (better on the golden sets).
|
|
155
|
+
* PxWeb v2 lists the tables itself. PxWeb v1 reads the crawled snapshot from the
|
|
156
|
+
* server's `tableSnapshots` option. PxStat ("cso-pxstat") always reads the
|
|
157
|
+
* snapshot. Other API types always search an index.
|
|
158
|
+
*/
|
|
159
|
+
search?: 'api' | 'index';
|
|
160
|
+
/**
|
|
161
|
+
* Path segment after the language: "Data" on SiStat (the default), "table" on SSB.
|
|
162
|
+
* With an array, search covers every database in it and each table id starts with its database.
|
|
163
|
+
* A database that fails is left out of the results; search fails only if all fail.
|
|
164
|
+
*/
|
|
165
|
+
database?: string | readonly [string, ...string[]];
|
|
166
|
+
languages: readonly [string, ...string[]];
|
|
167
|
+
/** Appended to every tool result. Most statistics offices require it. */
|
|
168
|
+
attribution: (lang: string) => string;
|
|
169
|
+
/** Human-facing table page, cited next to the attribution. */
|
|
170
|
+
tableUrl: (lang: string, tableId: string) => string;
|
|
171
|
+
instructions: string;
|
|
172
|
+
maxCells: number;
|
|
173
|
+
/** Maximum estimated size of a query result in characters. Default 30,000 (about 8,000 tokens). */
|
|
174
|
+
maxResultChars?: number;
|
|
175
|
+
searchLimit: number;
|
|
176
|
+
/** Builds the table id from a search hit, for example the table number in the title. */
|
|
177
|
+
tableIdFromHit?: (hit: SearchHit) => string;
|
|
178
|
+
/** True when the office keeps the table in its archive, for example by its path. */
|
|
179
|
+
isArchived?: (hit: SearchHit) => boolean;
|
|
180
|
+
/** Per language. Each matching alias adds one search in the database's own wording. */
|
|
181
|
+
searchAliases?: Readonly<Record<string, readonly SearchAlias[]>>;
|
|
182
|
+
}
|
|
183
|
+
export declare function createPxwebServer(preset: PxwebPreset, client: PxwebClient): McpServer;
|
|
184
|
+
interface PresetServerOptions {
|
|
185
|
+
cache?: Cache;
|
|
186
|
+
fetch?: typeof fetch;
|
|
187
|
+
userAgent?: string;
|
|
188
|
+
/** Crawled table lists, used when a source's live table list fails. */
|
|
189
|
+
tableSnapshots?: SnapshotReader;
|
|
190
|
+
}
|
|
191
|
+
export declare function createPresetClient(preset: PxwebPreset, options: Pick<PresetServerOptions, 'cache' | 'fetch' | 'tableSnapshots'> & {
|
|
192
|
+
userAgent: string;
|
|
193
|
+
}): PxwebClient;
|
|
194
|
+
export declare function createPresetServer(preset: PxwebPreset, options?: PresetServerOptions): McpServer;
|
|
195
|
+
interface SelectionInput {
|
|
196
|
+
code: string;
|
|
197
|
+
values?: string[] | undefined;
|
|
198
|
+
latest?: number | undefined;
|
|
199
|
+
}
|
|
200
|
+
interface QueryPlan {
|
|
201
|
+
selections: PxwebSelection[];
|
|
202
|
+
cells: number;
|
|
203
|
+
estimatedChars: number;
|
|
204
|
+
}
|
|
205
|
+
export declare const DEFAULT_MAX_RESULT_CHARS = 30000;
|
|
206
|
+
export declare class QueryPlanError extends Error {
|
|
207
|
+
constructor(message: string);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* PxWeb aggregates an omitted eliminable variable into one total and returns
|
|
211
|
+
* every value of an omitted non-eliminable one, so both count toward cells.
|
|
212
|
+
*/
|
|
213
|
+
export declare function planQuery(metadata: TableMetadata, inputs: SelectionInput[], maxCells: number, maxResultChars?: number): QueryPlan;
|
|
214
|
+
/**
|
|
215
|
+
* Keyword search over a local list of tables, for APIs without a working search.
|
|
216
|
+
* A table matches when at least half of the query words start a word in its title
|
|
217
|
+
* or equal its id, so a short word such as "for" alone does not match every table.
|
|
218
|
+
* Tables that match more words come first; ties keep the list order.
|
|
219
|
+
*/
|
|
220
|
+
export declare function searchTitles(tables: readonly TableSearchHit[], query: string, lang: string): TableSearchHit[];
|
|
221
|
+
interface TableIndexSearchOptions {
|
|
222
|
+
/** Also return discontinued tables; by default they are left out. */
|
|
223
|
+
includeArchived?: boolean;
|
|
224
|
+
}
|
|
225
|
+
interface TableIndex {
|
|
226
|
+
readonly size: number;
|
|
227
|
+
search(query: string, options?: TableIndexSearchOptions): TableSearchHit[];
|
|
228
|
+
}
|
|
229
|
+
interface TableIndexOptions {
|
|
230
|
+
/**
|
|
231
|
+
* Year for the recency and current-data boosts, fixed when the index is built;
|
|
232
|
+
* defaults to the current UTC year. Rebuild the index when the catalogue refreshes.
|
|
233
|
+
*/
|
|
234
|
+
currentYear?: number;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Keyword search over a source's table catalogue, for APIs whose own search is
|
|
238
|
+
* missing, broken or weak. It fuses two rankings: BM25 over titles (three times)
|
|
239
|
+
* and subject folders, and word-start matches in the office's own catalogue order,
|
|
240
|
+
* where offices list their main tables first.
|
|
241
|
+
*/
|
|
242
|
+
export declare function createTableIndex(docs: readonly TableDoc[], lang: string, options?: TableIndexOptions): TableIndex;
|
|
243
|
+
interface TableListOptions {
|
|
244
|
+
/** Tables to use when the live table list fails, for example a crawled snapshot. */
|
|
245
|
+
listFallback?: (lang: string) => Promise<readonly TableDoc[] | undefined>;
|
|
246
|
+
}
|
|
247
|
+
interface TableIndexLoaderOptions {
|
|
248
|
+
/** How long a built index stays fresh. */
|
|
249
|
+
ttlSeconds: number;
|
|
250
|
+
/** Wait before retrying after a failed refresh; the old index serves meanwhile. */
|
|
251
|
+
retrySeconds?: number;
|
|
252
|
+
/** Year for recency at build time; defaults to the current UTC year. */
|
|
253
|
+
currentYear?: () => number;
|
|
254
|
+
/**
|
|
255
|
+
* Tables for a language that has no index yet when the live list fails. A stale
|
|
256
|
+
* live index wins over the fallback, and a fallback index is kept only until
|
|
257
|
+
* the next retry.
|
|
258
|
+
*/
|
|
259
|
+
fallback?: TableListOptions['listFallback'];
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Keeps one built index per language. Parallel searches share a build, an index
|
|
263
|
+
* is rebuilt after `ttlSeconds`, and a failed refresh keeps serving the old one.
|
|
264
|
+
*/
|
|
265
|
+
export declare function createTableIndexLoader(load: (lang: string) => Promise<readonly TableDoc[]>, options: TableIndexLoaderOptions): (lang: string) => Promise<TableIndex>;
|
|
266
|
+
interface PxstatClientOptions extends HttpOptions {
|
|
267
|
+
/** PxStat root without the API name, for example "https://ws.cso.ie/public". */
|
|
268
|
+
baseUrl: string;
|
|
269
|
+
/** Full table list (the crawled snapshot); PxStat has no search. */
|
|
270
|
+
tableList?: (lang: string) => Promise<readonly TableDoc[]>;
|
|
271
|
+
/** Clock for search ranking; defaults to the system time. */
|
|
272
|
+
now?: () => Date;
|
|
273
|
+
}
|
|
274
|
+
export declare function createPxstatClient(options: PxstatClientOptions): PxwebClient;
|
|
275
|
+
interface SingstatClientOptions extends HttpOptions {
|
|
276
|
+
/** Table Builder API root, for example "https://tablebuilder.singstat.gov.sg/api/table". */
|
|
277
|
+
baseUrl: string;
|
|
278
|
+
/** Clock for search ranking; defaults to the system time. */
|
|
279
|
+
now?: () => Date;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Client for the SingStat Table Builder API of the Singapore Department of
|
|
283
|
+
* Statistics. Tables are series (rows) by periods (columns); the client shows
|
|
284
|
+
* them as two variables, "series" and "time".
|
|
285
|
+
*/
|
|
286
|
+
export declare function createSingstatClient(options: SingstatClientOptions): PxwebClient;
|
|
287
|
+
interface StatcanClientOptions extends HttpOptions, TableListOptions {
|
|
288
|
+
/** WDS root, for example "https://www150.statcan.gc.ca/t1/wds/rest". */
|
|
289
|
+
baseUrl: string;
|
|
290
|
+
/** Clock for search ranking; defaults to the system time. */
|
|
291
|
+
now?: () => Date;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Client for the Web Data Service of Statistics Canada. Tables have no time
|
|
295
|
+
* dimension and data is read per series ("coordinate"), so the client adds a
|
|
296
|
+
* "time" variable and turns a selection into a batch of coordinates.
|
|
297
|
+
*/
|
|
298
|
+
export declare function createStatcanClient(options: StatcanClientOptions): PxwebClient;
|
|
299
|
+
interface EurostatClientOptions extends HttpOptions, TableListOptions {
|
|
300
|
+
/** Root of the dissemination API, "https://ec.europa.eu/eurostat/api/dissemination". */
|
|
301
|
+
baseUrl: string;
|
|
302
|
+
/** Clock for search ranking; defaults to the system time. */
|
|
303
|
+
now?: () => Date;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Client for the Eurostat dissemination API: search over the table of contents,
|
|
307
|
+
* structure from SDMX 2.1, data as JSON-stat 2.0.
|
|
308
|
+
*/
|
|
309
|
+
export declare function createEurostatClient(options: EurostatClientOptions): PxwebClient;
|
|
310
|
+
interface SdmxClientOptions extends HttpOptions, TableListOptions {
|
|
311
|
+
/** SDMX REST root, for example "https://data.api.abs.gov.au/rest". */
|
|
312
|
+
baseUrl: string;
|
|
313
|
+
/** Agency of the dataflows, for example "ABS". */
|
|
314
|
+
agency: string;
|
|
315
|
+
/** Clock for search ranking; defaults to the system time. */
|
|
316
|
+
now?: () => Date;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Client for SDMX REST services that answer SDMX-JSON 1.0 (.Stat Suite), such as
|
|
320
|
+
* the Australian Bureau of Statistics. SDMX has no title search, so search uses
|
|
321
|
+
* a local index over the dataflow list.
|
|
322
|
+
*/
|
|
323
|
+
export declare function createSdmxClient(options: SdmxClientOptions): PxwebClient;
|
|
324
|
+
interface MultiServerEntry {
|
|
325
|
+
code: string;
|
|
326
|
+
preset: PxwebPreset;
|
|
327
|
+
/** Called at most once, when a tool call first uses this country. */
|
|
328
|
+
client: () => PxwebClient;
|
|
329
|
+
}
|
|
330
|
+
interface MultiServerOptions {
|
|
331
|
+
name: string;
|
|
332
|
+
title: string;
|
|
333
|
+
version: string;
|
|
334
|
+
}
|
|
335
|
+
export declare function createMultiServer(entries: readonly MultiServerEntry[], options: MultiServerOptions): McpServer;
|
|
336
|
+
interface CbsODataClientOptions extends HttpOptions, TableListOptions {
|
|
337
|
+
/** Root of the CBS open data service, for example "https://opendata.cbs.nl". */
|
|
338
|
+
baseUrl: string;
|
|
339
|
+
/**
|
|
340
|
+
* Root of the CBS OData v4 catalogue, used when the v3 service refuses a request.
|
|
341
|
+
* Defaults to "https://datasets.cbs.nl/odata/v1/CBS".
|
|
342
|
+
*/
|
|
343
|
+
datasetsUrl?: string;
|
|
344
|
+
/** Clock for search ranking; defaults to the system time. */
|
|
345
|
+
now?: () => Date;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Client for the OData v3 service of Statistics Netherlands (CBS), with OData v4 as
|
|
349
|
+
* the fallback. Measures are table columns, so the client shows them as one extra
|
|
350
|
+
* variable, "Topics".
|
|
351
|
+
*/
|
|
352
|
+
export declare function createCbsODataClient(options: CbsODataClientOptions): PxwebClient;
|
|
353
|
+
interface StatbankDkClientOptions extends HttpOptions, TableListOptions {
|
|
354
|
+
/** StatBank API root, for example "https://api.statbank.dk/v1". */
|
|
355
|
+
baseUrl: string;
|
|
356
|
+
/** Clock for search ranking; defaults to the system time. */
|
|
357
|
+
now?: () => Date;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Client for the StatBank API of Statistics Denmark. Its table search ignores the
|
|
361
|
+
* search text, so the client loads the full table list and searches it locally.
|
|
362
|
+
*/
|
|
363
|
+
export declare function createStatbankDkClient(options: StatbankDkClientOptions): PxwebClient;
|
|
364
|
+
interface PxwebV2ClientOptions extends HttpOptions, TableListOptions {
|
|
365
|
+
/** PxWeb API v2 root, for example "https://statistikdatabasen.scb.se/api/v2". */
|
|
366
|
+
baseUrl: string;
|
|
367
|
+
/** Clock for search ranking; defaults to the system time. */
|
|
368
|
+
now?: () => Date;
|
|
369
|
+
/** True when the office keeps the table in its archive, for example by its title. */
|
|
370
|
+
isArchived?: (hit: SearchHit) => boolean;
|
|
371
|
+
/** "index" lists every table once an hour and searches locally; "api" uses the API search. */
|
|
372
|
+
search?: 'api' | 'index';
|
|
373
|
+
}
|
|
374
|
+
/** Client for the PxWeb API v2, with the same interface as the v1 client. */
|
|
375
|
+
export declare function createPxwebV2Client(options: PxwebV2ClientOptions): PxwebClient;
|
|
376
|
+
export { type ApiBaseUrl, type Cache, type CbsODataClientOptions, type EurostatClientOptions, type FlatTable, type JsonStatDataset, type MemoryCacheOptions, type MultiServerEntry, type MultiServerOptions, type PresetServerOptions, type PxstatClientOptions, type PxwebClient, type PxwebClientOptions, type PxwebPreset, type PxwebSelection, type PxwebV2ClientOptions, type QueryPlan, SNAPSHOT_VERSION, type SdmxClientOptions, type SearchAlias, type SearchHit, type SelectionInput, type SingstatClientOptions, type Snapshot, type SnapshotBucket, type SnapshotReader, type StatbankDkClientOptions, type StatcanClientOptions, type TableDoc, type TableIndex, type TableIndexLoaderOptions, type TableIndexOptions, type TableIndexSearchOptions, type TableListOptions, type TableMetadata, type TableSearchHit, type TableSearchOptions, type TableVariable, type UrlSnapshotReaderOptions, bucketSnapshotReader, firstSnapshot, readSnapshot, snapshotKey, urlSnapshotReader, writeSnapshot };
|