Skip to main content

MCP server for Swiss federal finances (EFV): budget, debt, forecasts and spending data

Project description

๐Ÿ‡จ๐Ÿ‡ญ Part of the Swiss Public Data MCP Portfolio โ€” open-source MCP servers connecting AI agents to Swiss public and open data. This is a private project. It is independent of any employer or institutional affiliation.

๐Ÿ›๏ธ swiss-efv-mcp

Version CI License: MIT Python 3.11+ MCP Auth: none Portfolio

MCP server for Swiss federal finances (EFV): budget, debt, forecasts and spending by task and institution.

๐Ÿ‡ฉ๐Ÿ‡ช Deutsche Version

Overview

This server closes the fiscal gap in the portfolio's Economics & Finance cluster. swiss-snb-mcp already covers monetary policy; swiss-efv-mcp adds the state budget โ€” federal revenue, expenditure, balance, debt ratios (with forecasts to 2029), a hierarchical budget drill-down, and spending by department. Data comes from the Eidgenรถssische Finanzverwaltung (EFV) via opendata.swiss (OGD Schweiz).

Features

  • Five read-only tools over the curated EFV FS/GFS dump files.
  • Headline series 1990โ€“2029 per household (bund, ktn, gdn, staat, sv) and model (FS / GFS); every point carries is_projection so actuals and plan/forecast years are unambiguous.
  • Hierarchical federal-budget drill-down and spending by department / unit.
  • 24 h TTL in-memory cache with stale-serve fallback; retry with exponential backoff (2/4/8 s); dump_status never returns empty silently.
  • Dual transport: stdio (local) and SSE (cloud).
  • No authentication required โ€” public open-government data (No-Auth-First).

๐ŸŽฏ Anchor Demo Query

"How has the federal balance developed since the SNB rate turnaround in 2022 โ€” and which task areas absorbed the growth in spending?"

fiscal_headline(variable="saldo", household="bund", year_from=2021)
fiscal_budget_breakdown(topic="Ausgaben nach Aufgabengebiet", level=2)

Cross-read with swiss-snb-mcp, this connects the interest-rate cycle to the federal deficit โ€” something neither server can answer alone.

Prerequisites

  • Python 3.11+
  • uv / uvx (recommended) or pip
  • Network access to data.finance.admin.ch and efv.admin.ch โ€” no API key needed

Installation

uvx swiss-efv-mcp            # zero-install run (once published to PyPI)
# or
pip install swiss-efv-mcp

Claude Desktop (claude_desktop_config.json):

{
  "mcpServers": {
    "swiss-efv": {
      "command": "uvx",
      "args": ["swiss-efv-mcp"]
    }
  }
}

Quickstart

# Run locally over stdio (default transport)
uvx swiss-efv-mcp

# From a checkout, without installing
PYTHONPATH=src python -m swiss_efv_mcp

Configuration

All configuration is loaded once into a typed Settings object (pydantic-settings). The legacy unprefixed names below keep working; the canonical names use the EFV_MCP_ prefix. Defaults are safe for local use.

Variable Default Purpose
TRANSPORT stdio Transport: stdio (Claude Desktop) or sse / streamable-http (cloud)
HOST 127.0.0.1 Bind host (SSE only). Loopback by default; set 0.0.0.0 only in a container
PORT 8000 Bind port (SSE only)
EFV_MCP_LOG_LEVEL INFO structlog level (JSON to stderr)
EFV_MCP_CORS_ORIGINS [] SSE only: explicit allowed browser origins (default-deny; comma-separated or JSON)

Cloud (Render / Railway):

TRANSPORT=sse PORT=8000 swiss-efv-mcp   # exposes /sse

Available Tools

Tool Purpose
fiscal_headline Revenue / expenditure / balance / debt ratios over 1990โ€“2029, per household and model; every point flags is_projection
fiscal_budget_breakdown Hierarchical federal budget by topic (Ausgaben nach Art / nach Aufgabengebiet, Einnahmen, Bilanz, โ€ฆ)
fiscal_by_institution Spending per department / administrative unit since 2007 (Personalausgaben, Informatik, external services, FTE)
fiscal_list_dimensions Discover valid parameter values โ€” call this first to build correct arguments
dump_status Cache freshness and upstream health per dataset; never returns empty silently

All tools are read-only: each is annotated readOnlyHint: true, destructiveHint: false, only issues HTTP GETs against the EFV dump files, and has no write, send, or filesystem capability.

MCP primitives. This server uses only the Tools primitive. The EFV data are sliced live from cached dumps with no stable resource hierarchy to expose as Resources, and there are no server-authored Prompts. The five tools are small and closely related, so they live in a single server.py rather than a tools/ package.

Architecture

                      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   Claude / Agent โ”€โ”€โ–ถ โ”‚  swiss-efv-mcp (FastMCP)      โ”‚
                      โ”‚  5 tools ยท Pydantic v2 env.   โ”‚
                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                      โ”‚ fetch + retry + TTL cache
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ–ผ                                               โ–ผ
   data.finance.admin.ch                          efv.admin.ch/dam
   fs_dashboard/main_extern.csv                   bundeshaushalt_de.csv
   (headline, 1990โ€“2029)                          institutionen_de.csv

Architecture decision

This server uses Architecture C (Dump-first).

Rationale (verified live on 2026-07-24):

  • The EFV FS/GFS dashboard has no filtered query API; it serves static CSV dumps that its front-end filters in the browser.
  • Three curated files are small enough to fetch-and-cache whole (516 KB / 5 MB / 1 MB). They cover the headline aggregates, the hierarchical budget and the by-institution view โ€” i.e. the answerable questions.
  • The full detail cubes (standardauswertung.csv 157 MB, fir_art_funk.csv 1.23 GB) are out of scope for v0.1.0; loading them per request is not viable. A future Phase 2 would pre-process them into SQLite/Parquet.

Consequences:

  • Files are cached in memory with a 24 h TTL; stale cache is preferred over an empty response when upstream is down.
  • Retry with exponential backoff on all HTTP; dump_status always returns a readable state.

Project Structure

swiss-efv-mcp/
โ”œโ”€โ”€ src/swiss_efv_mcp/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ __main__.py        # entry point; dual transport (stdio / SSE+CORS)
โ”‚   โ”œโ”€โ”€ client.py          # dump-first data layer: egress allow-list, retry, UA, TTL cache
โ”‚   โ”œโ”€โ”€ logging_config.py  # structlog JSON to stderr
โ”‚   โ”œโ”€โ”€ models.py          # Pydantic v2 envelopes (source + provenance)
โ”‚   โ”œโ”€โ”€ server.py          # 5 FastMCP tools (annotated) + testable *_impl functions
โ”‚   โ””โ”€โ”€ settings.py        # typed pydantic-settings config
โ”œโ”€โ”€ tests/                 # respx mock tests + hardening tests + @pytest.mark.live
โ”œโ”€โ”€ docs/                  # network-egress.md + accepted-risk ADRs
โ”œโ”€โ”€ audits/                # MCP best-practice audit runs (findings, report, summary)
โ”œโ”€โ”€ README.md ยท README.de.md ยท CHANGELOG.md ยท SECURITY.md ยท CONTRIBUTING.md
โ”œโ”€โ”€ Dockerfile ยท server.json ยท LICENSE
โ””โ”€โ”€ pyproject.toml

Safety & Limits

  • Read-only. Every tool is annotated readOnlyHint: true, only issues HTTP GETs against the EFV dump files, and has no write, send, or filesystem capability.
  • Egress allow-list. An immutable ALLOWED_HOSTS frozenset + assert_host_allowed() is enforced before every request (HTTPS-only, two fixed EFV hosts). URLs are hardcoded constants; no user input builds a URL. See docs/network-egress.md.
  • TLS on. httpx certificate verification is on by default and never disabled.
  • No credentials. The endpoints are public OGD; no API keys or secrets are stored or forwarded. A browser User-Agent is injected because the endpoints 403 the default httpx/curl UA (see Known limitations) โ€” do not remove it.
  • Error masking. mask_error_details=True plus client-side masking keep raw upstream/internal detail out of tool results; full detail goes only to the structlog stderr log.
  • Input bounds. Tool arguments carry explicit Pydantic constraints (year 1900โ€“2100, level 1โ€“8, string max_length).
  • Graceful degradation. Retry with exponential backoff (2/4/8 s); a stale cache is served over an empty response; dump_status always returns a readable state and never a silent empty.
  • Loopback + default-deny CORS. SSE binds to HOST, default 127.0.0.1; set HOST=0.0.0.0 only inside a container (the provided Dockerfile does). Browser origins must be listed explicitly via EFV_MCP_CORS_ORIGINS.
  • Audited. Reviewed against the portfolio MCP best-practice catalogue (44 applicable checks) โ€” see audits/ and SECURITY.md. Accepted risks are documented as ADRs under docs/adr/.
  • Not authoritative. Figures are not official; consult the EFV originals for official use.

Known limitations

Live-probe findings (2026-07-24), also in CHANGELOG.md โ†’ Known findings:

Finding Impact
Endpoints return HTTP 403 without a browser User-Agent UA is injected by the client; do not remove it
opendata.swiss "CSV" links for 2 datasets point to an HTML landing page real files resolved to a DAM path (/dam/de/sd-web/{id}/โ€ฆ) whose opaque id may rotate on re-upload
NA appears as a literal string in hh/model/source cleaned to None centrally
"Forward-looking" is not one label: Bund uses "Budget/financial plans", staat uses "Forecasts" abstracted via is_projection
Accounting-model break at 2022/2023 ("bis 2022" vs "ab 2023" topics) series has a seam; a note flags affected topics
Detail cubes (157 MB / 1.23 GB) not served Phase 2; use the curated files for now

Project Phase

This server is in Phase 1 (read-only). Every tool only ever fetches the public EFV dump files โ€” there are no write, send, or filesystem capabilities.

Phase Scope Status
1 โ€” Read-only Headline series, budget breakdown, spending by institution โœ… current
2 โ€” Detail cubes Pre-process the 157 MB / 1.23 GB cubes to SQLite/Parquet planned
3 โ€” Multi-agent (none planned) โ€”

A transition to a later phase would require a re-audit before any write-capable tool is added.

MCP Protocol Version

The protocol version is negotiated at the initialize handshake by FastMCP (pinned fastmcp>=3.4 in pyproject.toml), which builds on the mcp Python SDK. Dependencies are kept current via monthly Dependabot PRs (.github/dependabot.yml); protocol-relevant bumps are noted in CHANGELOG.md.

Testing

PYTHONPATH=src pytest tests/ -m "not live"   # offline, respx-mocked
PYTHONPATH=src pytest tests/ -m live         # hits the real EFV endpoints
PYTHONPATH=src ruff check src tests

Changelog

See CHANGELOG.md.

Security

See SECURITY.md for the security posture, hardening controls, and how to report a vulnerability.

Contributing

Issues and pull requests are welcome. Please keep tools read-only, run ruff check and the offline test suite before submitting, and add a CHANGELOG.md entry under [Unreleased] for user-facing changes. See CONTRIBUTING.md.

Maintainers: see PUBLISHING.md for the step-by-step PyPI release process (Trusted Publishing via GitHub Release).

License

MIT for this server โ€” see LICENSE. The EFV data remain subject to the OGD Schweiz terms (freely usable, with attribution).

Author

Hayal Oezkan ยท github.com/malkreide

Credits & Related Projects

  • Data: Eidgenรถssische Finanzverwaltung EFV via opendata.swiss (OGD Schweiz, freely usable)
  • Companion: swiss-snb-mcp (monetary policy) โ€” the fiscal/monetary pair
  • Portfolio index: swiss-public-data-mcp

Disclaimer: private project, independent of any employer or institution. No warranty; figures are not authoritative โ€” consult the EFV originals for official use.

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_efv_mcp-0.2.0.tar.gz (149.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_efv_mcp-0.2.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file swiss_efv_mcp-0.2.0.tar.gz.

File metadata

  • Download URL: swiss_efv_mcp-0.2.0.tar.gz
  • Upload date:
  • Size: 149.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for swiss_efv_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1bc930809404d9b5ab4d85c0aecb2e3644fb7186a5eb469afdb8e799baef4f49
MD5 e8e54d0056f47fd29c6736f72bb09342
BLAKE2b-256 a5df630eedcaffe44b6f29d416e43ffcfb076ad29a50230d015294e371004d6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for swiss_efv_mcp-0.2.0.tar.gz:

Publisher: publish.yml on malkreide/swiss-efv-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file swiss_efv_mcp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: swiss_efv_mcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for swiss_efv_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d36bfd83a8f8bc0c9d5a912a84e4dcafcadab28d177ffee7ca87f1ec1438dd83
MD5 ec1f9526fd7672a9943401565c951b48
BLAKE2b-256 4a209b94c527b7d63f2a5f1d4f95e60b7b7f20b0d6a0d199f77ced0df066d5c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for swiss_efv_mcp-0.2.0-py3-none-any.whl:

Publisher: publish.yml on malkreide/swiss-efv-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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