MCP server for Swiss federal finances (EFV): budget, debt, forecasts and spending data
π¨π 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.
MCP server for Swiss federal finances (EFV): budget, debt, forecasts and spending by task and institution.
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).
is_projection so actuals and plan/forecast
years are unambiguous.dump_status never returns empty silently.stdio (local) and SSE (cloud)."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.
uv / uvx (recommended) or pipdata.finance.admin.ch and efv.admin.ch β no API key neededuvx 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"]
}
}
}
# Run locally over stdio (default transport)
uvx swiss-efv-mcp
# From a checkout, without installing
PYTHONPATH=src python -m swiss_efv_mcp
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) |
EFV_MCP_OTEL_ENABLED | false | Enable OpenTelemetry tracing (requires the otel extra); standard OTEL_* env vars configure export |
Cloud (Render / Railway):
TRANSPORT=sse PORT=8000 swiss-efv-mcp # exposes /sse
| 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 |
fiscal_status | Cache freshness and upstream health per dataset; never returns empty silently |
dump_status | Deprecated alias of fiscal_status (kept for backward compatibility; removed in a future minor) |
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.
ββββββββββββββββββββββββββββββββ
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
This server uses Architecture C (Dump-first).
Rationale (verified live on 2026-07-24):
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:
dump_status always returns a
readable state.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
readOnlyHint: true, only issues HTTP
GETs against the EFV dump files, and has no write, send, or filesystem capability.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.User-Agent is injected because the endpoints
403 the default httpx/curl UA (see Known limitations) β do not remove it.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.1900β2100, level 1β8, string max_length).dump_status always returns a readable
state and never a silent empty.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.audits/ and SECURITY.md.
Accepted risks are documented as ADRs under docs/adr/.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 |
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.
This server is native to MCP spec 2026-07-28 and still serves the older
handshake era, so both pins are stated β a single number would describe only
half of what clients actually get.
| Era | Revision | How a connection negotiates it | Pinned as |
|---|---|---|---|
| modern (default) | 2026-07-28 | server/discover + a per-request envelope; no initialize handshake, and Client.initialize_result is None | MCP_MODERN_PROTOCOL_VERSION |
| handshake (legacy clients) | 2025-11-25 | the classic initialize handshake | MCP_HANDSHAKE_PROTOCOL_VERSION |
Both constants live in server.py and are held against the mcp SDK's own
LATEST_MODERN_VERSION / LATEST_HANDSHAKE_VERSION rather than against
copied-out spec text, and both eras are exercised over a real connection β a
protocol-changing SDK bump fails CI loudly instead of drifting silently
(ARCH-012).
The 2026-07-28 era carries consequences beyond the number:
Mcp-Protocol-Version,
Mcp-Method and (for tools/call) Mcp-Name. They are listed in the CORS
allow-list in __main__.py; without them a browser client fails at the
preflight and never reaches the server. Mcp-Param-* is deliberately absent β
no tool schema here carries the x-mcp-header annotation that would make a
client send one, and a test fails the day one does.EFV_MCP_LOG_LEVEL. Progress reporting is unaffected
and stays.fastmcp>=4.0 is a floor, not cosmetics. Only fastmcp 4 pulls in mcp
2.x, and only there does revision 2026-07-28 exist at all. Under fastmcp 3.x
this server would speak 2025-11-25 at best.Dependencies are kept current via monthly Dependabot PRs
(.github/dependabot.yml); protocol-relevant bumps are noted in
CHANGELOG.md.
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
See CHANGELOG.md.
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).
See SECURITY.md for the security posture, hardening controls, and how to report a vulnerability.
MIT for this server β see LICENSE. The EFV data remain subject to the OGD Schweiz terms (freely usable, with attribution).
Hayal Oezkan Β· github.com/malkreide
swiss-snb-mcp (monetary policy) β the fiscal/monetary pairDisclaimer: private project, independent of any employer or institution. No warranty; figures are not authoritative β consult the EFV originals for official use.
Source-derived launch command. Check the maintainerβs required arguments and credentials before running:
uvx swiss-efv-mcpMerge this template into ~/Library/Application Support/Claude/claude_desktop_config.json. Keep existing servers. Add any arguments, credentials, and permissions required by the maintainer; this template has not been install-tested.
{
"mcpServers": {
"io-github-malkreide-swiss-efv-mcp": {
"command": "uvx",
"args": [
"swiss-efv-mcp"
]
}
}
}Restart Claude Desktop completely for changes to take effect. Confirm the server appears connected in the clientβs tool list, then try a read-only example from its documentation.
Claude Desktop setup referenceswiss-efv-mcppypiio.github.malkreide/swiss-efv-mcp works with any MCP-compatible client. Copy the config snippet from the Configuration section above and add it to the file shown for your client, then restart the application.
~/Library/Application Support/Claude/claude_desktop_config.jsonRestart Claude Desktop completely for changes to take effect.~/.cursor/mcp.jsonRestart Cursor for changes to take effect..vscode/mcp.jsonReload VS Code window for changes to take effect.~/.codeium/windsurf/mcp_config.jsonRestart Windsurf for changes to take effect..mcp.jsonSave at the project root, then start Claude Code in that project and review the MCP server approval prompt. Keep real credentials out of shared files.