Skip to main content

MCP server for Swiss electricity data โ€” Energiedashboard (BFE), ElCom tariffs, consumption

Project description

๐Ÿ‡จ๐Ÿ‡ญโšก swiss-electricity-mcp

MCP server for Swiss electricity data โ€” three official sources, twelve tools, zero authentication.

CI PyPI Python License: MIT

๐ŸŒ Read this in your language: ๐Ÿ‡ฉ๐Ÿ‡ช Deutsch

Part of the Swiss Public Data MCP Portfolio โ€” a coordinated set of MCP servers for Swiss public administration.


๐Ÿ”ฅ Anchor demo query

"How have ewz electricity tariffs for a typical school building (consumption category C3, โ‰ˆ150'000 kWh/a) developed since 2019, and how do they compare to the Swiss median?"

A single conversation calls tariff_get_by_municipality (bfs_nr=261, category="C3") + tariff_get_median_swiss and returns a year-by-year comparison with full provenance โ€” ready for a Geschรคftsleitung slide.


๐Ÿ“Š What's inside

Three official Swiss data sources combined into one MCP server, each with its own dedicated tool group:

Source What it provides Provenance
Energiedashboard.ch (Bundesamt fรผr Energie) National production mix, consumption forecast, storage-lake fill, consumer price index live_api
ElCom electricity-price cubes (via LINDAS SPARQL) Tariffs per municipality, category, year, with full breakdown (energy + grid usage + KEV + Abgaben) sparql
opendata.swiss + Stadt Zรผrich OGD (CKAN) Dataset discovery for raw time series (e.g. quarter-hour NE5/NE7 consumption) live_api

No authentication required. All endpoints are public Swiss OGD.


๐Ÿ› ๏ธ Tools (12)

dashboard_* โ€” Energiedashboard.ch (BFE)

  • dashboard_get_production_mix โ€” Production mix by year (TWh + %): Kernkraft, Wasserkraft, PV, Wind, thermal.
  • dashboard_get_consumption_forecast โ€” Current consumption forecast + 5-day outlook + 5-year envelope.
  • dashboard_get_storage_lakes โ€” Speichersee fill level (CH or per region: Wallis, Tessin, Graubรผnden, Zentral/Ost) โ€” critical winter-supply indicator.
  • dashboard_get_consumer_price_index โ€” Endverbraucher-Strompreis-Index (2020-01-01 = 100).

tariff_* โ€” ElCom (via LINDAS SPARQL)

  • tariff_list_categories โ€” H1โ€“H8 (households) and C1โ€“C7 (commercial). C3 โ‰ˆ 150'000 kWh/a is the typical reference for school buildings.
  • tariff_get_by_municipality โ€” Tariffs for a BFS-Nr + category + year range, broken into energy / grid usage / KEV / Abgaben.
  • tariff_get_median_swiss โ€” National median benchmark.
  • tariff_get_median_canton โ€” Cantonal median (e.g. for Kanton Zรผrich).
  • tariff_compare_municipalities โ€” Compare up to 20 municipalities side-by-side.

consumption_* โ€” opendata.swiss + Stadt Zรผrich OGD

  • consumption_search_bfe_datasets โ€” CKAN search across BFE-published datasets.
  • consumption_search_zurich โ€” CKAN search across Stadt Zรผrich OGD (includes quarter-hour NE5/NE7 consumption).

Status

  • electricity_check_status โ€” Liveness probe across all four upstreams (HTTP status + latency + overall-healthy flag).

๐Ÿš€ Installation

From PyPI

pip install swiss-electricity-mcp

From source

git clone https://github.com/malkreide/swiss-electricity-mcp.git
cd swiss-electricity-mcp
pip install -e ".[dev]"

๐Ÿ’ฌ Use with Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "swiss-electricity": {
      "command": "swiss-electricity-mcp"
    }
  }
}

โ˜๏ธ Cloud deployment (Streamable HTTP)

SWISS_ELECTRICITY_TRANSPORT=streamable-http \
SWISS_ELECTRICITY_HOST=0.0.0.0 \
SWISS_ELECTRICITY_PORT=8000 \
swiss-electricity-mcp

Works on Render.com, Railway, Fly.io.

Host binding (security). In HTTP mode the host defaults to 127.0.0.1 (loopback only). Bind to all interfaces with SWISS_ELECTRICITY_HOST=0.0.0.0 only inside a container, where the network boundary is the container, not the host. Setting 0.0.0.0 on a developer machine exposes the server to the local network (NeighborJack).

Docker

A multi-stage Dockerfile is provided. It runs as a non-root user (UID 10001) and sets SWISS_ELECTRICITY_HOST=0.0.0.0 explicitly for the containerised case.

docker build -t swiss-electricity-mcp .
docker run --rm -p 8000:8000 swiss-electricity-mcp

๐Ÿ”ญ Observability & configuration

Env var Default Purpose
SWISS_ELECTRICITY_TRANSPORT stdio stdio or streamable-http
SWISS_ELECTRICITY_HOST 127.0.0.1 HTTP bind host (0.0.0.0 in containers only)
SWISS_ELECTRICITY_PORT 8000 HTTP port
SWISS_ELECTRICITY_LOG_LEVEL INFO Log level (DEBUG/INFO/WARNING/ERROR)
SWISS_ELECTRICITY_CORS_ORIGINS (empty) Comma-separated allowed CORS origins (browser clients); never *
OTEL_EXPORTER_OTLP_ENDPOINT (unset) Enables OpenTelemetry tracing when set
SWISS_ELECTRICITY_ENV unknown deployment.environment resource attribute for traces
  • Logging is structured JSON on stderr (stdout is reserved for the stdio JSON-RPC channel). Upstream failures are logged in full server-side but masked in client-facing responses.

  • Tracing is opt-in. Install the extra and point it at a collector:

    pip install "swiss-electricity-mcp[otel]"
    OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 swiss-electricity-mcp
    

    You get one span per tool call (mcp.tool.<name>) plus automatic httpx child spans for each upstream request. No argument values or PII are recorded.


๐Ÿ—๏ธ Architecture

          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ MCP client (Claude etc.) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚                          stdio  or  Streamable HTTP                           โ”‚
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                   โ”‚  12 read-only tools (annotated)
                                          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                          โ”‚  FastMCP server   โ”‚  egress allow-list + HTTPS gate
                                          โ”‚  + structlog/OTel โ”‚  per-source TTL cache + retry
                                          โ””โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”˜
                  dashboard_* โ”‚ tariff_*      โ”‚        โ”‚   โ”‚   consumption_*
                              โ–ผ               โ–ผ        โ–ผ   โ–ผ
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Energiedashboard  โ”‚ โ”‚  LINDAS   โ”‚ โ”‚ opendata.swissโ”‚ โ”‚ data.stadt-zuerich.chโ”‚
                  โ”‚ .admin.ch (BFE)   โ”‚ โ”‚  SPARQL   โ”‚ โ”‚   CKAN        โ”‚ โ”‚   CKAN (OGD)         โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Hybrid (live API + SPARQL + CKAN discovery), no authentication. Three reasons this is the right shape:

  1. Different latency profiles per source: Energiedashboard responds in ~200 ms (great live); LINDAS SPARQL is slower and occasionally returns 504 (longer timeout + 3 retries); CKAN is metadata-only and inherently safe.
  2. Different update cadences: Dashboard updates intraday; ElCom tariffs update once per year; OGD datasets are stable for months. Per-source TTL caching (600 s / 3600 s) reflects this.
  3. Domain separation from swiss-energy-mcp: that server covers geo and infrastructure data (power plants, grid lines). swiss-electricity-mcp covers time-series and tariffs. Both compose cleanly.

Provenance discipline

Every tool response is a Pydantic envelope carrying:

  • source โ€” full attribution string (e.g. "Daten: Bundesamt fรผr Energie (BFE)โ€ฆ").
  • provenance โ€” exactly one of live_api / sparql / cached / weekly_dump / stale_cache_fallback.
  • retrieved_at โ€” ISO-8601 UTC timestamp.

This makes accidental misattribution structurally impossible.

Resilience

  • Retry: 3 attempts with exponential backoff (2 s / 4 s / 8 s).
  • 5xx + 429: retried. 4xx (except 429): raised immediately (permanent client error).
  • In-memory TTL cache: per-source TTLs reduce upstream load and round-trip during multi-step agent workflows.

MCP primitives โ€” why Tools only

This server intentionally exposes only Tools, not Resources or Prompts. The data is parametric and query-driven (a municipality BFS number, a category, a year), which maps naturally to tool calls; there is no stable, enumerable set of documents to expose as Resources, and no curated prompt templates to ship. If a future use case needs, say, a fixed "national production mix" document, the read-only dashboard_* tools are the obvious Resource-migration candidates.

Project phase

Phase 1 โ€” read-only. All 12 tools are read-only (readOnlyHint=true) with no write or destructive operations. Phase-transition criteria and the longer-term plan live in docs/roadmap.md. Security posture (egress, supply-chain, lethal-trifecta assessment) is documented in docs/security-posture.md.


๐Ÿงช Testing

# Unit tests (mocked, fast, CI default) โ€” tests/test_unit.py + tests/test_security.py
PYTHONPATH=src pytest -m "not live" -v

# Live tests (hits real upstreams) โ€” tests/test_live.py
PYTHONPATH=src pytest -m live -v

Unit tests cover the contract layers: Happy (response parsing), Retry (5xx, 429, 4xx), Timeout (network errors โ†’ clean UpstreamUnreachableError), envelope/attribution invariants, plus security (egress allow-list, SPARQL escaping, tool-definition lock). CI runs ruff + pytest -m "not live" on Python 3.11โ€“3.13.


๐Ÿ”Œ MCP protocol version

This server is built on the official MCP Python SDK (mcp[cli]), pinned to >=1.2.0,<2.0.0. The MCP protocol version is negotiated by the SDK at the initialize handshake; the supported spec version tracks the pinned SDK (currently MCP spec 2025-11-25).

Update policy: SDK updates arrive as weekly Dependabot PRs. A protocol-spec bump is only adopted via an explicit SDK minor/major bump, recorded in CHANGELOG.md, and verified against the tool-definition lock (tool-definitions.lock.json).


โš ๏ธ Known limitations

  • LINDAS SPARQL 504 timeouts: the LINDAS public endpoint occasionally returns 504 under load. The 3-retry policy handles transient cases; persistent unavailability surfaces as UpstreamUnreachableError.
  • No historical PV/wind detail: Energiedashboard exposes only aggregated production mix at year level. For sub-yearly PV or wind, use consumption_search_bfe_datasets.
  • No FHIR or smart-meter data: out of scope. Future work may add a swiss-prosumer-mcp or similar.
  • Year coverage: ElCom tariff data starts in 2009. Energiedashboard mix starts in 2014.

๐ŸŒ Portfolio synergy

This server composes naturally with other portfolio servers:

  • + swiss-energy-mcp โ€” combine geo/asset data (power plants) with time-series and tariffs for full energy-infrastructure analysis.
  • + meteoswiss-mcp โ€” correlate consumption forecasts with weather (temperature drives heating/cooling load).
  • + fedlex-mcp โ€” pair tariff data with the Stromversorgungsgesetz (StromVG) for compliance/legal context.
  • + zh-education-mcp โ€” Schulamt-relevant queries combining tariffs, school counts, infrastructure budgets.

๐Ÿ“œ Data sources & licensing

All upstream data is Open Government Data Switzerland (OGD-CH):

  • Energiedashboard.ch ยฉ Bundesamt fรผr Energie BFE โ€” Open data, free to use.
  • ElCom / LINDAS ยฉ Eidgenรถssische Elektrizitรคtskommission ElCom โ€” CC BY 4.0.
  • opendata.swiss ยฉ Various Swiss public bodies โ€” Mostly CC0 / CC BY 4.0.
  • Stadt Zรผrich OGD ยฉ Stadt Zรผrich โ€” CC0.

This MCP server is MIT-licensed (see LICENSE). Always cite the original data source โ€” the response envelope includes the proper attribution string automatically.


๐Ÿค Contributing

See CONTRIBUTING.md.

๐Ÿ”’ Security

See SECURITY.md for the security policy and how to report a vulnerability.

๐Ÿ“ Changelog

See CHANGELOG.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swiss_electricity_mcp-0.2.3.tar.gz (110.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swiss_electricity_mcp-0.2.3-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

Details for the file swiss_electricity_mcp-0.2.3.tar.gz.

File metadata

  • Download URL: swiss_electricity_mcp-0.2.3.tar.gz
  • Upload date:
  • Size: 110.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for swiss_electricity_mcp-0.2.3.tar.gz
Algorithm Hash digest
SHA256 f56a810806b7a621d1259e607d3e14db00430fc1f48ae4d7a145647c3e3bc3c2
MD5 1c447a503f2c50f5a69f5d19b89ec048
BLAKE2b-256 f49683be36247e4d9d5616d0052e8be0ae25fbb8724e0f0a06256795c3922c7d

See more details on using hashes here.

File details

Details for the file swiss_electricity_mcp-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for swiss_electricity_mcp-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b1589625b50f653e67b74d5555cac8e263e8568015bd3abdbf54869c9b587761
MD5 c2159c8908e8399a2d33baba03686579
BLAKE2b-256 740f09064dfe9b00bd169b4d0d297c55629983012b875b8f4e2cb33587ecdf05

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page