@pipeworx/mcp-datacube-sk 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pipeworx
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 ADDED
@@ -0,0 +1,55 @@
1
+ # mcp-datacube-sk
2
+
3
+ DATAcube — Statistical Office of the Slovak Republic (data.statistics.sk).
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 250+ live data sources.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+
12
+ ## Quick Start
13
+
14
+ Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
15
+
16
+ ```json
17
+ {
18
+ "mcpServers": {
19
+ "datacube-sk": {
20
+ "url": "https://gateway.pipeworx.io/datacube-sk/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 250+ data sources:
27
+
28
+ ```json
29
+ {
30
+ "mcpServers": {
31
+ "pipeworx": {
32
+ "url": "https://gateway.pipeworx.io/mcp"
33
+ }
34
+ }
35
+ }
36
+ ```
37
+
38
+ ## Using with ask_pipeworx
39
+
40
+ Instead of calling tools directly, you can ask questions in plain English:
41
+
42
+ ```
43
+ ask_pipeworx({ question: "your question about Datacube Sk data" })
44
+ ```
45
+
46
+ The gateway picks the right tool and fills the arguments automatically.
47
+
48
+ ## More
49
+
50
+ - [All tools and guides](https://github.com/pipeworx-io/examples)
51
+ - [pipeworx.io](https://pipeworx.io)
52
+
53
+ ## License
54
+
55
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-datacube-sk",
3
+ "version": "0.1.0",
4
+ "description": "DATAcube — Statistical Office of the Slovak Republic (data.statistics.sk).",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "datacube-sk"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-datacube-sk"
13
+ },
14
+ "scripts": {
15
+ "typecheck": "tsc --noEmit"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^5.7.0"
19
+ }
20
+ }
package/server.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.pipeworx-io/datacube-sk",
4
+ "title": "Datacube Sk",
5
+ "description": "DATAcube — Statistical Office of the Slovak Republic (data.statistics.sk).",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/datacube-sk",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-datacube-sk",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/datacube-sk/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,203 @@
1
+ interface McpToolDefinition {
2
+ name: string;
3
+ description: string;
4
+ inputSchema: {
5
+ type: 'object';
6
+ properties: Record<string, unknown>;
7
+ required?: string[];
8
+ };
9
+ }
10
+
11
+ interface McpToolExport {
12
+ tools: McpToolDefinition[];
13
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
14
+ meter?: { credits: number };
15
+ cost?: Record<string, unknown>;
16
+ provider?: string;
17
+ }
18
+
19
+ /**
20
+ * DATAcube — Statistical Office of the Slovak Republic (data.statistics.sk).
21
+ *
22
+ * Keyless JSON-stat API. Browse 600+ statistical cubes, inspect their
23
+ * dimensions/valid codes, then pull data with one positional selection per
24
+ * dimension. Topics: Slovak demographics, labour market, economy, prices,
25
+ * households, regional statistics, etc.
26
+ */
27
+
28
+
29
+ const BASE = 'https://data.statistics.sk/api/v2';
30
+ const UA = 'pipeworx-mcp-datacube-sk/1.0 (+https://pipeworx.io)';
31
+
32
+ const tools: McpToolExport['tools'] = [
33
+ {
34
+ name: 'list_datasets',
35
+ description:
36
+ 'Browse / search the DATAcube collection of Slovak statistical cubes. ' +
37
+ 'Filter by case-insensitive substring of the English label. Returns each ' +
38
+ "matching cube's code (use it as `cube` in the other tools), label, last " +
39
+ 'update date, and its ordered list of dimension codes.',
40
+ inputSchema: {
41
+ type: 'object',
42
+ properties: {
43
+ query: { type: 'string', description: 'Case-insensitive substring to match against dataset labels (e.g. "population", "unemployment"). Omit to list everything.' },
44
+ limit: { type: 'number', description: 'Max results to return (default 50, max 200).' },
45
+ lang: { type: 'string', enum: ['en', 'sk'], description: 'Label language (default "en").' },
46
+ },
47
+ },
48
+ },
49
+ {
50
+ name: 'dataset_dimensions',
51
+ description:
52
+ 'List the dimensions of one cube, in path order, with each dimension\'s ' +
53
+ 'valid value codes and labels. Selections in get_data are positional and ' +
54
+ 'must follow this dimension order. Get the cube code from list_datasets.',
55
+ inputSchema: {
56
+ type: 'object',
57
+ properties: {
58
+ cube: { type: 'string', description: 'Cube code, e.g. "as1001rs" (from list_datasets).' },
59
+ lang: { type: 'string', enum: ['en', 'sk'], description: 'Label language (default "en").' },
60
+ },
61
+ required: ['cube'],
62
+ },
63
+ },
64
+ {
65
+ name: 'get_data',
66
+ description:
67
+ 'Pull data for a cube as JSON-stat. Provide one selection per dimension, ' +
68
+ 'in the dimension order returned by dataset_dimensions. Each selection is ' +
69
+ 'either a single value code, a comma-separated list of codes (e.g. ' +
70
+ '"SEX_M,SEX_F"), or the literal "all" for every value of that dimension. ' +
71
+ 'The number of selections must equal the cube\'s dimension count. Output ' +
72
+ 'is JSON-stat: `value` is the flat data array, `dimension`/`size`/`id` ' +
73
+ 'describe its shape.',
74
+ inputSchema: {
75
+ type: 'object',
76
+ properties: {
77
+ cube: { type: 'string', description: 'Cube code, e.g. "as1001rs" (from list_datasets).' },
78
+ selections: {
79
+ type: 'array',
80
+ items: { type: 'string' },
81
+ description: 'One entry per dimension, in dataset_dimensions order. Each is a value code, a comma-separated list of codes, or "all". Example for as1001rs: ["2024", "UKAZ01", "all"].',
82
+ },
83
+ lang: { type: 'string', enum: ['en', 'sk'], description: 'Label language (default "en").' },
84
+ },
85
+ required: ['cube', 'selections'],
86
+ },
87
+ },
88
+ ];
89
+
90
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
91
+ switch (name) {
92
+ case 'list_datasets':
93
+ return listDatasets(args);
94
+ case 'dataset_dimensions':
95
+ return datasetDimensions(args);
96
+ case 'get_data':
97
+ return getData(args);
98
+ default:
99
+ throw new Error(`Unknown tool: ${name}`);
100
+ }
101
+ }
102
+
103
+ async function listDatasets(args: Record<string, unknown>): Promise<unknown> {
104
+ const lang = langOf(args);
105
+ const query = (args.query as string | undefined)?.toLowerCase().trim() ?? '';
106
+ const limit = clampLimit(args.limit, 50, 200);
107
+
108
+ const coll = (await dcGet(`/collection?lang=${lang}`)) as {
109
+ link?: { item?: Array<{ href?: string; label?: string; update?: string; dimension?: Record<string, unknown> }> };
110
+ };
111
+ const items = coll.link?.item ?? [];
112
+
113
+ const results: Array<{ cube: string; label: string; updated?: string; dimensions: string[] }> = [];
114
+ for (const it of items) {
115
+ const label = it.label ?? '';
116
+ if (query && !label.toLowerCase().includes(query)) continue;
117
+ const cube = cubeFromHref(it.href);
118
+ if (!cube) continue;
119
+ results.push({
120
+ cube,
121
+ label,
122
+ updated: it.update,
123
+ dimensions: Object.keys(it.dimension ?? {}),
124
+ });
125
+ if (results.length >= limit) break;
126
+ }
127
+
128
+ return { total_matched: results.length, lang, results };
129
+ }
130
+
131
+ async function datasetDimensions(args: Record<string, unknown>): Promise<unknown> {
132
+ const lang = langOf(args);
133
+ const cube = reqStr(args, 'cube', '"as1001rs"');
134
+
135
+ // Find the cube in the collection to learn its dimension order.
136
+ const coll = (await dcGet(`/collection?lang=${lang}`)) as {
137
+ link?: { item?: Array<{ href?: string; label?: string; dimension?: Record<string, unknown> }> };
138
+ };
139
+ const item = (coll.link?.item ?? []).find((it) => cubeFromHref(it.href) === cube);
140
+ if (!item) throw new Error(`Unknown cube "${cube}". Use list_datasets to find valid cube codes.`);
141
+
142
+ const dimCodes = Object.keys(item.dimension ?? {});
143
+ const dimensions = await Promise.all(
144
+ dimCodes.map(async (dim, position) => {
145
+ const d = (await dcGet(`/dimension/${cube}/${dim}?lang=${lang}`)) as {
146
+ note?: string;
147
+ category?: { index?: Record<string, number>; label?: Record<string, string> };
148
+ };
149
+ const index = d.category?.index ?? {};
150
+ const labels = d.category?.label ?? {};
151
+ return {
152
+ position,
153
+ dimension: dim,
154
+ note: d.note,
155
+ values: Object.keys(index).map((code) => ({ code, label: labels[code] ?? code })),
156
+ };
157
+ }),
158
+ );
159
+
160
+ return { cube, label: item.label, lang, dimensions };
161
+ }
162
+
163
+ async function getData(args: Record<string, unknown>): Promise<unknown> {
164
+ const lang = langOf(args);
165
+ const cube = reqStr(args, 'cube', '"as1001rs"');
166
+ const sel = args.selections;
167
+ if (!Array.isArray(sel) || sel.length === 0 || !sel.every((s) => typeof s === 'string' && s.trim())) {
168
+ throw new Error('selections must be a non-empty array of strings (one per dimension, in dataset_dimensions order). Use dataset_dimensions to find dimension order and valid codes.');
169
+ }
170
+ const path = (sel as string[]).map((s) => encodeURIComponent(s.trim())).join('/');
171
+ return dcGet(`/dataset/${encodeURIComponent(cube)}/${path}?lang=${lang}`);
172
+ }
173
+
174
+ async function dcGet(path: string): Promise<unknown> {
175
+ const res = await fetch(`${BASE}${path}`, {
176
+ headers: { Accept: 'application/json', 'User-Agent': UA },
177
+ });
178
+ if (!res.ok) throw new Error(`DATAcube: ${res.status} ${await res.text().then((t) => t.slice(0, 200))}`);
179
+ return res.json();
180
+ }
181
+
182
+ function cubeFromHref(href: string | undefined): string | undefined {
183
+ if (!href) return undefined;
184
+ const m = href.match(/\/dataset\/([^/?]+)/);
185
+ return m ? m[1] : undefined;
186
+ }
187
+
188
+ function langOf(args: Record<string, unknown>): 'en' | 'sk' {
189
+ return args.lang === 'sk' ? 'sk' : 'en';
190
+ }
191
+
192
+ function clampLimit(v: unknown, def: number, max: number): number {
193
+ const n = typeof v === 'number' && Number.isFinite(v) ? Math.floor(v) : def;
194
+ return Math.min(Math.max(n, 1), max);
195
+ }
196
+
197
+ function reqStr(args: Record<string, unknown>, key: string, example: string): string {
198
+ const v = args[key];
199
+ if (typeof v !== 'string' || !v.trim()) throw new Error(`Required argument "${key}" is missing. Pass a string like ${example}.`);
200
+ return v.trim();
201
+ }
202
+
203
+ export default { tools, callTool, meter: { credits: 1 } } satisfies McpToolExport;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "dist",
10
+ "rootDir": "src",
11
+ "declaration": true
12
+ },
13
+ "include": ["src"]
14
+ }