Swiss Efv Mcp

io.github.malkreide由 GitHub 账号 malkreide 发布v0.4.0更新于 Oct 24, 2026

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

已验证STDIO仅桌面金融数据与分析

概览

AI 生成的概览

只读 MCP 服务器,提供瑞士联邦预算、债务、收入、支出与预测数据(来自 EFV 开放数据)。

可以做什么
基于精选的 EFV FS/GFS 转储文件提供五个只读工具:fiscal_headline 返回 1990 至 2029 年的收入、支出、结余和债务比率,并用 is_projection 标记预测年份;fiscal_budget_breakdown 提供联邦预算的层级细分;fiscal_by_institution 提供 2007 年以来各部门或行政单位的支出;fiscal_list_dimensions 用于发现有效参数值;fiscal_status 报告缓存新鲜度和上游健康状况。数据从公开的 EFV 端点获取,并在内存中缓存 24 小时。
适用场景
适合需要瑞士联邦财政数据、预算层级细分或按部门支出的场景,也可与货币政策服务器配合,把利率周期与联邦赤字联系起来。不适用于官方或权威用途。
运行要求
本地进程,使用 uvx 或 pip 运行;建议 Python 3.11+ 及 uv/uvx。需要访问 data.finance.admin.ch 和 efv.admin.ch 的网络。无需 API 密钥或身份验证。可选环境变量用于配置传输方式、主机、端口、日志级别、CORS 来源和 OpenTelemetry。
安装前请注意
只读:工具仅发起 HTTP GET,没有写入、发送或文件系统能力。不存储或转发任何凭据。数据并非权威,官方用途请查阅 EFV 原始资料。若改用 SSE 传输,请保持默认回环主机,并通过 EFV_MCP_CORS_ORIGINS 明确列出浏览器来源。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Swiss Efv Mcp,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

🇨🇭 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.

Demo

[Demo: Claude using fiscal_headline and fiscal_budget_breakdown]

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

bash
uvx swiss-efv-mcp            # zero-install run (once published to PyPI)# orpip install swiss-efv-mcp

Claude Desktop (claude_desktop_config.json):

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

Quickstart

bash
# Run locally over stdio (default transport)uvx swiss-efv-mcp
# From a checkout, without installingPYTHONPATH=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.

VariableDefaultPurpose
TRANSPORTstdioTransport: stdio (Claude Desktop) or sse / streamable-http (cloud)
HOST127.0.0.1Bind host (SSE only). Loopback by default; set 0.0.0.0 only in a container
PORT8000Bind port (SSE only)
EFV_MCP_LOG_LEVELINFOstructlog level (JSON to stderr)
EFV_MCP_CORS_ORIGINS[]SSE only: explicit allowed browser origins (default-deny; comma-separated or JSON)
EFV_MCP_OTEL_ENABLEDfalseEnable OpenTelemetry tracing (requires the otel extra); standard OTEL_* env vars configure export

Cloud (Render / Railway):

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

Available Tools

ToolPurpose
fiscal_headlineRevenue / expenditure / balance / debt ratios over 1990–2029, per household and model; every point flags is_projection
fiscal_budget_breakdownHierarchical federal budget by topic (Ausgaben nach Art / nach Aufgabengebiet, Einnahmen, Bilanz, …)
fiscal_by_institutionSpending per department / administrative unit since 2007 (Personalausgaben, Informatik, external services, FTE)
fiscal_list_dimensionsDiscover valid parameter values — call this first to build correct arguments
fiscal_statusCache freshness and upstream health per dataset; never returns empty silently
dump_statusDeprecated 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.

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:

FindingImpact
Endpoints return HTTP 403 without a browser User-AgentUA is injected by the client; do not remove it
opendata.swiss "CSV" links for 2 datasets point to an HTML landing pagereal 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/sourcecleaned 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 servedPhase 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.

PhaseScopeStatus
1 — Read-onlyHeadline series, budget breakdown, spending by institution✅ current
2 — Detail cubesPre-process the 157 MB / 1.23 GB cubes to SQLite/Parquetplanned
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

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.

EraRevisionHow a connection negotiates itPinned as
modern (default)2026-07-28server/discover + a per-request envelope; no initialize handshake, and Client.initialize_result is NoneMCP_MODERN_PROTOCOL_VERSION
handshake (legacy clients)2025-11-25the classic initialize handshakeMCP_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:

  • Routing headers. Every modern request carries 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.
  • Logging is deprecated (SEP-2577). Tool handlers no longer send client-facing log notifications; per-call diagnostics go to the structlog stderr stream, honouring 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.

Testing

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

Changelog

See CHANGELOG.md.

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).

Security

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

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.

来源:README.md,提交 abbcbf0

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

2
  1. v0.4.0最新Sep 26, 2026
  2. v0.3.2Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分