MCP Trenitalia

MCP Trenitalia

An MCP server for real-time Italian railway data, enabling natural language queries about train schedules, delays, departures, arrivals, and live tracking via the Viaggiatreno API.

Category
访问服务器

README

MCP Trenitalia

An MCP (Model Context Protocol) server for real-time Italian railway data (Trenitalia), built with FastMCP and the unofficial Viaggiatreno API.

Lets LLMs like Claude answer questions about Italian trains in natural language: schedules, delays, departures, arrivals, live tracking.

🌐 ciuff.org — project landing page. Ciuff as in ciuff ciuff (the sound a train makes): the name is intentionally playful.


Demo

Connect the server to Claude Desktop, Claude Web, or any MCP-compatible client (see setup sections below) and ask Claude in natural language.

Example queries:

"Which trains run from Roma Tuscolana to Roma Aurelia this morning?"

"Is Frecciarossa 9631 delayed?"

"Show me the next departures from Milano Centrale"

"What time does the train from Tuscolana to Aurelia leave tomorrow morning?"


Features

5 available tools:

Tool Description
trenitalia_cerca_stazione Find stations by name and return the Viaggiatreno ID
trenitalia_monitora_partenze Real-time departure board for a station
trenitalia_monitora_arrivi Real-time arrival board for a station
trenitalia_traccia_treno Full telemetry for a single train (position, delay, stops)
trenitalia_orari_tra_stazioni Schedules between two stations with live verification and real-time delays

All tools accept plain names (e.g. "Tuscolana", "Roma Termini") as well as technical IDs ("S08408").


How it works

Data sources

Viaggiatreno (real-time) Trenitalia's unofficial API for live data: departures, arrivals, train position and delay.

NeTEx (offline timetable) NeTEx Italian Profile file published by IT-RAP, containing 25,480 train journeys with stops and schedules. Used as the primary source for orari_tra_stazioni.

Hybrid logic for orari_tra_stazioni

  1. NeTEx offline — finds all journeys connecting station A to station B on the requested day, filtered by weekday and validity period
  2. Live cross-check — for journeys departing within the next 90 minutes, verifies the train actually appears on the Viaggiatreno departure board (removes "ghost trains" present in NeTEx but not actually stopping at that station)
  3. Real-time delay enrichment — enriches each journey with the current delay from Viaggiatreno, parallelised with asyncio.gather
  4. Viaggiatreno fallback — if NeTEx returns no results (special services, cancellations, etc.), queries the live board directly and verifies stop-by-stop the actual route

Tech stack

  • Python 3.12
  • mcp[cli] 1.26.0 — FastMCP with SSE and streamable-http transport
  • httpx — async HTTP client for the Viaggiatreno API
  • pydantic v2 — tool input validation

Project structure

server.py               # FastMCP server + 5 tools (entrypoint)
viaggiatreno.py         # httpx client for the Viaggiatreno API
models.py               # Pydantic v2 input models
data/
  stazioni.json         # Name → Viaggiatreno ID dictionary (1,610 stations)
  timetable.json.gz     # Compressed NeTEx timetable (25,480 journeys, ~1.1 MB)
build_stazioni.py       # Script to regenerate stazioni.json
build_timetable.py      # Script to regenerate timetable.json.gz
web/                    # Next.js landing page (ciuff.org)

Local installation

Prerequisites

1. Clone the repo

git clone https://github.com/Fanfulla/MCP_Trenitalia.git
cd MCP_Trenitalia

2. Install dependencies

You can use uv (recommended, much faster) or the standard pip.

With uv (recommended)

uv is a modern Python package manager, significantly faster than pip. To install it:

# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Then, inside the project folder:

uv venv && uv pip install -r requirements.txt

With pip (alternative)

If you prefer not to install uv, the standard pip works just fine:

python -m venv .venv

# macOS / Linux
source .venv/bin/activate

# Windows
.venv\Scripts\activate

pip install -r requirements.txt

Running the server

# stdio mode — for Claude Desktop / Cursor / local IDEs
python server.py

# HTTP mode — for remote deploy or Claude Web
python server.py --http

In --http mode the server exposes the MCP endpoint at:

  • POST /mcp (streamable-http transport)

Default port: 8000 (override with the PORT environment variable).


Claude Desktop setup

Claude Desktop reads its configuration from a JSON file. Open or create claude_desktop_config.json:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Add the mcpServers section:

macOS / Linux:

{
  "mcpServers": {
    "MCP Trenitalia": {
      "command": "/absolute/path/to/.venv/bin/python",
      "args": ["/absolute/path/to/server.py"]
    }
  }
}

Windows:

{
  "mcpServers": {
    "MCP Trenitalia": {
      "command": "C:\\absolute\\path\\to\\.venv\\Scripts\\python.exe",
      "args": ["C:\\absolute\\path\\to\\server.py"]
    }
  }
}

Note: use absolute paths. Restart Claude Desktop after saving the file.


Deploy to Railway

The repo includes a ready-made Procfile for Railway:

web: python server.py --http

Just connect the GitHub repo to a new Railway project — deploys are automatic. The PORT variable is injected automatically by Railway.


Environment variables

Variable Default Description
PORT 8000 HTTP server port
MCP_HOST 0.0.0.0 Binding host
LOG_LEVEL info Log level

Notes

  • The Viaggiatreno API is unofficial and undocumented — the server handles all anomalous responses defensively
  • The NeTEx file is valid for the period 2025-12-14 → 2026-06-13 — to update it, run build_timetable.py with a new NeTEx file
  • Tools never raise exceptions to the client: on error they return a descriptive message in Italian

License

MIT — Copyright (c) 2026 Fanfulla

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选