@pipeworx/mcp-stat-ee 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 +21 -0
- package/README.md +58 -0
- package/package.json +20 -0
- package/server.json +18 -0
- package/src/index.ts +109 -0
- package/tsconfig.json +14 -0
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,58 @@
|
|
|
1
|
+
# mcp-stat-ee
|
|
2
|
+
|
|
3
|
+
Statistics Estonia (andmed.stat.ee) PxWeb MCP. Keyless.
|
|
4
|
+
|
|
5
|
+
Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 965+ live data sources.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
|------|-------------|
|
|
11
|
+
| `subjects` | Navigate the subject tree. Items are type "l" (folder) or "t" (table, id ends in .px). |
|
|
12
|
+
| `table_meta` | Table definition (dimensions, valid values). Use these to build a filtered query_table call. |
|
|
13
|
+
| `query_table` | Pull data from a table. body is a PxWeb query object. Filter selections to stay under the ~100k-cell limit. |
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"mcpServers": {
|
|
22
|
+
"stat-ee": {
|
|
23
|
+
"url": "https://gateway.pipeworx.io/stat-ee/mcp"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or connect to the full Pipeworx gateway for access to all 965+ data sources:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"mcpServers": {
|
|
34
|
+
"pipeworx": {
|
|
35
|
+
"url": "https://gateway.pipeworx.io/mcp"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Using with ask_pipeworx
|
|
42
|
+
|
|
43
|
+
Instead of calling tools directly, you can ask questions in plain English:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
ask_pipeworx({ question: "your question about Stat Ee data" })
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The gateway picks the right tool and fills the arguments automatically.
|
|
50
|
+
|
|
51
|
+
## More
|
|
52
|
+
|
|
53
|
+
- [All tools and guides](https://github.com/pipeworx-io/examples)
|
|
54
|
+
- [pipeworx.io](https://pipeworx.io)
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pipeworx/mcp-stat-ee",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Statistics Estonia (andmed.stat.ee) PxWeb MCP. Keyless.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "stat-ee"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pipeworx-io/mcp-stat-ee"
|
|
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/stat-ee",
|
|
4
|
+
"title": "Stat Ee",
|
|
5
|
+
"description": "Statistics Estonia (andmed.stat.ee) PxWeb MCP. Keyless.",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://pipeworx.io/packs/stat-ee",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/pipeworx-io/mcp-stat-ee",
|
|
10
|
+
"source": "github"
|
|
11
|
+
},
|
|
12
|
+
"remotes": [
|
|
13
|
+
{
|
|
14
|
+
"type": "streamable-http",
|
|
15
|
+
"url": "https://gateway.pipeworx.io/stat-ee/mcp"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
* Statistics Estonia (andmed.stat.ee) PxWeb MCP. Keyless.
|
|
21
|
+
*
|
|
22
|
+
* PxWeb API: navigate the subject tree (items are type "l" = folder or "t" = table),
|
|
23
|
+
* fetch table metadata, then POST a query to pull data.
|
|
24
|
+
*
|
|
25
|
+
* Table codes carry a ".px" suffix (the API serves them uppercase, e.g. "RV021.PX",
|
|
26
|
+
* but the suffix is case-insensitive). The table id returned by the tree already
|
|
27
|
+
* includes the suffix, so a full table path looks like
|
|
28
|
+
* rahvastik/rahvastikunaitajad-ja-koosseis/rahvaarv-ja-rahvastiku-koosseis/RV021.PX
|
|
29
|
+
*
|
|
30
|
+
* PxWeb enforces a per-query cell limit (~100k cells). Large tables (many years ×
|
|
31
|
+
* age groups × counties) will be rejected unless you filter — use table_meta to read
|
|
32
|
+
* the variables and pass a narrow {filter:"item", values:[...]} selection per dimension.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
const BASE = 'https://andmed.stat.ee/api/v1/en/stat';
|
|
37
|
+
const UA = 'pipeworx-mcp-stat-ee/1.0 (+https://pipeworx.io)';
|
|
38
|
+
|
|
39
|
+
const tools: McpToolExport['tools'] = [
|
|
40
|
+
{
|
|
41
|
+
name: 'subjects',
|
|
42
|
+
description: 'Navigate the subject tree. Items are type "l" (folder) or "t" (table, id ends in .px).',
|
|
43
|
+
inputSchema: {
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: { path: { type: 'string', description: 'Sub-path under /stat/ (default empty = root). e.g. "rahvastik/rahvastikunaitajad-ja-koosseis"' } },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'table_meta',
|
|
50
|
+
description: 'Table definition (dimensions, valid values). Use these to build a filtered query_table call.',
|
|
51
|
+
inputSchema: {
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties: { path: { type: 'string', description: 'e.g. "rahvastik/rahvastikunaitajad-ja-koosseis/rahvaarv-ja-rahvastiku-koosseis/RV021.PX"' } },
|
|
54
|
+
required: ['path'],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'query_table',
|
|
59
|
+
description: 'Pull data from a table. body is a PxWeb query object. Filter selections to stay under the ~100k-cell limit.',
|
|
60
|
+
inputSchema: {
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties: {
|
|
63
|
+
path: { type: 'string', description: 'Table path ending in .px, e.g. ".../RV021.PX"' },
|
|
64
|
+
body: { type: 'object', description: '{query: [{code, selection: {filter, values}}], response: {format: "json-stat2"}}' },
|
|
65
|
+
},
|
|
66
|
+
required: ['path', 'body'],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
72
|
+
switch (name) {
|
|
73
|
+
case 'subjects': {
|
|
74
|
+
const path = (args.path as string | undefined)?.replace(/^\/+|\/+$/g, '') ?? '';
|
|
75
|
+
return statGet(path ? `/${path}` : '');
|
|
76
|
+
}
|
|
77
|
+
case 'table_meta':
|
|
78
|
+
return statGet(`/${reqStr(args, 'path', '"rahvastik/rahvastikunaitajad-ja-koosseis/rahvaarv-ja-rahvastiku-koosseis/RV021.PX"').replace(/^\/+|\/+$/g, '')}`);
|
|
79
|
+
case 'query_table': {
|
|
80
|
+
const path = reqStr(args, 'path', '"rahvastik/rahvastikunaitajad-ja-koosseis/rahvaarv-ja-rahvastiku-koosseis/RV021.PX"').replace(/^\/+|\/+$/g, '');
|
|
81
|
+
const body = args.body;
|
|
82
|
+
if (!body || typeof body !== 'object') throw new Error('body must be a PxWeb query object.');
|
|
83
|
+
const res = await fetch(`${BASE}/${path}`, {
|
|
84
|
+
method: 'POST',
|
|
85
|
+
headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'User-Agent': UA },
|
|
86
|
+
body: JSON.stringify(body),
|
|
87
|
+
});
|
|
88
|
+
if (!res.ok) throw new Error(`Statistics Estonia: ${res.status} ${await res.text().then((t) => t.slice(0, 200))}`);
|
|
89
|
+
return res.json();
|
|
90
|
+
}
|
|
91
|
+
default:
|
|
92
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function statGet(path: string): Promise<unknown> {
|
|
97
|
+
// No trailing slash on the bare base — andmed.stat.ee 302-redirects "/stat/" to "/stat".
|
|
98
|
+
const res = await fetch(`${BASE}${path}`, { headers: { Accept: 'application/json', 'User-Agent': UA } });
|
|
99
|
+
if (!res.ok) throw new Error(`Statistics Estonia: ${res.status} ${await res.text().then((t) => t.slice(0, 200))}`);
|
|
100
|
+
return res.json();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function reqStr(args: Record<string, unknown>, key: string, example: string): string {
|
|
104
|
+
const v = args[key];
|
|
105
|
+
if (typeof v !== 'string' || !v.trim()) throw new Error(`Required argument "${key}" is missing. Pass a string like ${example}.`);
|
|
106
|
+
return v;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
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
|
+
}
|