BFS STAT-TAB PxWeb API for official Swiss statistics
Valid MCP server (1 strong, 3 medium validity signals). No known CVEs in dependencies. Package registry verified. Imported from the Official MCP Registry.
3 files analyzed Β· 1 issue found
Security scores are indicators to help you make informed decisions, not guarantees. Always review permissions before connecting any MCP server.
This plugin requests these system permissions. Most are normal for its category.
Add this to your MCP configuration file:
{
"mcpServers": {
"io-github-malkreide-swiss-statistics-mcp": {
"args": [
"swiss-statistics-mcp"
],
"command": "uvx"
}
}
}From the project's GitHub README.
π¨π Part of the Swiss Public Data MCP Portfolio
MCP Server for Swiss Federal Statistical Office (BFS) data via STAT-TAB PxWeb API β 682 datasets across 21 themes, no authentication required
This server is Alpha (0.x) as per the PyPI classifier. Until 1.0:
mainSee CHANGELOG.md for breaking changes.
swiss-statistics-mcp provides AI-native access to the Swiss Federal Statistical Office (BFS) via the STAT-TAB PxWeb API, without authentication:
| Property | Details |
|---|---|
| API | STAT-TAB PxWeb API v1 |
| Endpoint | https://www.pxweb.bfs.admin.ch/api/v1/ |
| Provider | Swiss Federal Statistical Office (BFS) |
| Datasets | 682 tables across 21 thematic areas |
| Languages | German (de), French (fr), Italian (it), English (en) |
| Licence | Open Government Data (OGD) β BFS Terms of Use |
| Authentication | None β fully public |
Anchor demo query: "How many students attended lower secondary schools in the canton of Zurich in 2024?" β real BFS figures, no hallucination.
# Clone the repository
git clone https://github.com/malkreide/swiss-statistics-mcp.git
cd swiss-statistics-mcp
# Install
pip install -e .
# or with uv:
uv pip install -e .
Or with uvx (no permanent installation):
uvx swiss-statistics-mcp
# stdio (for Claude Desktop)
python -m swiss_statistics_mcp.server
# Streamable HTTP, loopback only (default: host=127.0.0.1, port=8000)
python -m swiss_statistics_mcp.server --http --port 8000
# Streamable HTTP, all interfaces (only behind a reverse proxy with access control)
MCP_HOST=0.0.0.0 python -m swiss_statistics_mcp.server --http --port 8000
# or
python -m swiss_statistics_mcp.server --http --host 0.0.0.0 --port 8000
Try it immediately in Claude Desktop:
"How many teachers worked in the canton of Zurich in 2023?" "What is the population of canton Bern broken down by age?" "Compare the social assistance rate across all cantons for 2022."
Edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"swiss-statistics": {
"command": "python",
"args": ["-m", "swiss_statistics_mcp.server"]
}
}
}
Or with uvx:
{
"mcpServers": {
"swiss-statistics": {
"command": "uvx",
"args": ["swiss-statistics-mcp"]
}
}
}
Config file locations:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.jsonThe configuration syntax is identical to Claude Desktop. The file name depends on the client:
.cursor/mcp.json in the project folder, or ~/.cursor/mcp.json globally~/.codeium/windsurf/mcp_config.json.continue/config.jsonFor use via claude.ai in the browser (e.g. on managed workstations without local software).
β οΈ Security note β this server has no authentication. A public URL turns it into an open proxy to the BFS API on your deployment's IP. Any client with the URL can drive the tools, consume your platform quota, and attribute traffic to your IP. Two mitigations, in order of preference:
- Put it behind access control β Render's Β«Private ServiceΒ», Cloudflare Access, or a reverse proxy with Basic-Auth / IP allowlist in front of the container.
- Accept it as a public open-data proxy β only acceptable because all data is BFS OGD (Public Open Data) and tools are read-only.
The server binds to
127.0.0.1by default. To expose it on a container port you must explicitly setMCP_HOST=0.0.0.0(e.g. as a Render env var) or pass--host 0.0.0.0. Do not do this without one of the mitigations above.
Render.com:
MCP_HOST=0.0.0.0python -m swiss_statistics_mcp.server --http --port 8000https://your-app.onrender.com/sseπ‘ "stdio for the developer laptop, SSE for the browser."
Since v0.2.0, every tool returns a typed Pydantic model rather than a JSON
string. FastMCP serializes these as structured content so MCP clients can
read fields directly.
# Old (pre-0.2.0)
result = await bfs_get_data(...) # str
data = json.loads(result) # dict
print(data["rows_total"])
# New (>= 0.2.0)
result = await bfs_get_data(...) # DataTableResult
print(result.rows_total) # 1000
print(result.truncated) # True
Every result carries error: str | None and hint: str | None at the top
level β result.error is None means success. Data-returning tools
(bfs_get_data, bfs_education_stats, bfs_population,
bfs_compare_cantons) additionally expose truncated: bool,
rows_total: int, and rows_returned: int for machine-readable cap
detection.
| Tool | Result type |
|---|---|
bfs_list_themes | ListThemesResult |
bfs_list_tables_by_theme | ListTablesByThemeResult |
bfs_search_tables | SearchTablesResult |
bfs_get_table_metadata | TableMetadataResult |
bfs_get_data | DataTableResult |
bfs_education_stats | DataTableResult |
bfs_population | DataTableResult |
bfs_compare_cantons | DataTableResult |
bfs_featured_datasets | FeaturedDatasetsResult |
| Tool | Description |
|---|---|
bfs_featured_datasets | Curated list of highly relevant datasets (focus on education and demographics) |
bfs_list_themes | All 21 BFS themes with number of available datasets |
bfs_list_tables_by_theme | All tables for a given theme (e.g. "15" = Education and Science) |
bfs_search_tables | Full-text search across the entire data catalogue (682 datasets) |
bfs_get_table_metadata | Variables, values and metadata for a specific table |
bfs_get_data | Data retrieval with optional filters by dimensions and values |
bfs_education_stats | Convenience tool: teachers, pupils, demographic scenarios, scholarships |
bfs_population | Resident population by canton, year, age structure or sex |
bfs_compare_cantons | Cross-cantonal comparison for any table and any variable |
| Query | Tool |
|---|---|
| "How many teachers worked in Zurich in 2023?" | bfs_education_stats |
| "How will upper secondary enrolment develop until 2031?" | bfs_education_stats |
| "What is the population of canton Zurich by age?" | bfs_population |
| "Compare the social assistance rate across all cantons" | bfs_compare_cantons |
| "Is there data on school buildings?" | bfs_search_tables |
β More use cases by audience β
| Code | Theme | Code | Theme |
|---|---|---|---|
| 01 | Population | 12 | Money, banks, insurance |
| 02 | Territory and environment | 13 | Social security |
| 03 | Work and income | 14 | Health |
| 04 | National economy | 15 | Education and science |
| 05 | Prices | 16 | Culture, media, information society |
| 06 | Industry and services | 17 | Politics |
| 07 | Agriculture and forestry | 18 | General government |
| 08 | Energy | 19 | Crime and criminal justice |
| 09 | Construction and housing | 20 | Economic and social situation |
| 10 | Tourism | 21 | Sustainable development |
| 11 | Mobility and transport |
βββββββββββββββββββ ββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββ
β Claude / AI ββββββΆβ Swiss Statistics MCP ββββββΆβ BFS STAT-TAB β
β (MCP Host) βββββββ (MCP Server) βββββββ PxWeb API v1 β
βββββββββββββββββββ β β ββββββββββββββββββββββββββββ
β 9 Tools β
β 682 datasets Β· 21 themes β
β Stdio | Streamable HTTP β
β β
β No authentication required β
ββββββββββββββββββββββββββββββββ
| Source | Protocol | Coverage | Auth |
|---|---|---|---|
| BFS STAT-TAB | PxWeb REST API | 682 tables, 21 themes | None |
swiss-statistics-mcp/
βββ src/swiss_statistics_mcp/
β βββ __init__.py # Package
β βββ server.py # 9 tools
βββ tests/
β βββ test_server.py # Unit + integration tests (mocked HTTP)
βββ .github/workflows/ci.yml # GitHub Actions (Python 3.11/3.12/3.13)
βββ pyproject.toml
βββ CHANGELOG.md
βββ CONTRIBUTING.md # English
βββ CONTRIBUTING.de.md # German version
βββ SECURITY.md # English
βββ SECURITY.de.md # German version
βββ LICENSE
βββ README.md # This file (English)
βββ README.de.md # German version
The server emits one JSON log line per tool call on stderr:
{"ts": "2026-05-20T04:02:28", "level": "INFO", "logger": "swiss_statistics_mcp",
"event": "tool_start", "tool": "bfs_list_themes", "rid": "1091cb73", "params_keys": ["lang"]}
{"ts": "2026-05-20T04:02:28", "level": "INFO", "logger": "swiss_statistics_mcp",
"event": "tool_end", "tool": "bfs_list_themes", "rid": "1091cb73", "status": "ok", "duration_ms": 303}
rid β 8-char correlation id linking tool_start and tool_end for the same callparams_keys β sorted list of input field names (no values, no PII)duration_ms β per-call latency on the tool_end eventstatus β "ok" or "error"; error_type is added when a tool raisesRender and other cloud platforms can index these directly for per-tool latency
dashboards and error-rate alerts. Set MCP_LOG_LEVEL=DEBUG for verbose output
or WARNING to suppress per-call events.
βΉοΈ Logs go to stderr so they never collide with the MCP protocol on stdio transport (which uses stdout).
The server absorbs transient BFS-API hiccups before they reach the LLM:
5xx, 429, and network errors are retried up to 3 times with
exponential backoff (0.5s β 4s). 4xx errors surface immediately so client
bugs aren't masked. Tunable via MCP_RETRY_MAX_ATTEMPTS,
MCP_RETRY_WAIT_INITIAL, MCP_RETRY_WAIT_MAX env vars.(table_id, lang) for 1h. Cold list/detail flows
warm the cache; subsequent calls return instantly.bfs_list_tables_by_theme
run in parallel bounded by FANOUT_CONCURRENCY = 5. For limit=20 this
cuts wall-clock from ~20s sequential to ~4s, without overwhelming the
upstream API.# Unit tests (no API key required)
PYTHONPATH=src pytest tests/ -m "not live"
# Integration tests (live API calls)
pytest tests/ -m "live"
See CHANGELOG.md
See CONTRIBUTING.md
Read-only, no PII, no authentication, single fixed BFS endpoint. See SECURITY.md for the full security posture and accepted-risk decisions.
MIT License β see LICENSE
Hayal Oezkan Β· malkreide
Be the first to review this server!
by Modelcontextprotocol Β· Developer Tools
Read, search, and manipulate Git repositories programmatically
by Modelcontextprotocol Β· Developer Tools
Web content fetching and conversion for efficient LLM usage
by Toleno Β· Developer Tools
Toleno Network MCP Server β Manage your Toleno mining account with Claude AI using natural language.