digitraffic-mcp
# digitraffic-mcp
An MCP server for live Finnish **rail** and **road** traffic. The data comes from [Fintraffic Digitraffic](https://www.digitraffic.fi/en/), which is open data under CC BY 4.0. You don't need an API key.
All times are Finnish local time (Europe/Helsinki).
## Tools
| Tool | What it answers |
|---|---|
| `find_station` | Finds a station's short code from its name ("Tampere" → `TPE`) |
| `station_board` | Live departures or arrivals at a station, with estimates, delays, tracks and cancellations |
| `train_connections` | Direct trains between two stations, with travel time and live delay |
| `train_status` | One train's current delay, last station, next stop, GPS position and speed, delay causes, and stop-by-stop times |
| `road_weather` | Live readings from road weather stations: air and road temperature, wind, precipitation, visibility, road condition, friction and warnings |
| `traffic_messages` | Active incidents, roadworks, weight restrictions and oversize transports. Filter by road number, area or distance from a point |
| `find_weather_cameras` | Road weather cameras near a point or matching a name |
| `get_weather_camera_image` | The latest camera image, returned as an MCP image so the model can look at the road |
Example questions:
- "Is the next IC from Helsinki to Tampere on time?"
- "Where is train 9 right now?"
- "What's the road surface like on vt4 near Jyväskylä? Show me a camera."
- "Any roadworks on road 22 this week?"
## Setup
```bash
npm install # also builds dist/ (via the prepare script)
```
### Claude Code
```bash
claude mcp add digitraffic -- node /absolute/path/to/digitraffic-mcp/dist/index.js
claude mcp list # check that it connects
```
Replace `/absolute/path/to/digitraffic-mcp` with where you cloned the project. Running `pwd` in the project folder prints it.
Inside a session, `/mcp` shows the server status and its tools.
### Other MCP clients
Clients that use an `mcpServers` JSON config (for example Claude Desktop's `claude_desktop_config.json`):
```json
{
"mcpServers": {
"digitraffic": {
"command": "node",
"args": ["/absolute/path/to/digitraffic-mcp/dist/index.js"]
}
}
}
```
## Development
```bash
npm test # unit + MCP-level tests (offline, fetch is stubbed)
npm run lint # Biome lint
npm run typecheck # tsc, including the check that output schemas match the result types
npm run smoke # end-to-end: starts the server and calls every tool against the live API
npx tsx scripts/call.ts station_board '{"station":"HKI","limit":5}' # ad-hoc tool call
```
Layout:
- `src/http.ts`: the fetch wrapper. It sends the `Digitraffic-User` header, uses gzip, gives each request a 15 s deadline (retry included), retries once on network errors, 429 and 5xx, refuses images over 5 MB, and keeps an in-memory TTL cache capped at 500 entries.
- `src/rail.ts`: the rail API calls and pure functions that shape the responses.
- `src/road.ts`: road weather, traffic messages and weather cameras.
- `src/server.ts`: the MCP tool definitions.
- `src/schemas.ts`: the tools' output schemas. Every tool returns `structuredContent` matching its schema, and the same JSON as text for clients that don't read structured content.
Configuration: set `DIGITRAFFIC_USER` to change the client identifier sent in the `Digitraffic-User` header. The default is `digitraffic-mcp/<version>`, e.g. `digitraffic-mcp/0.1.0`.
## Notes
- Station names, traffic message texts and delay-cause names come from the API in Finnish. The server instructions tell the model to translate them.
- Station search ignores diacritics ("Jyvaskyla" finds Jyväskylä) and knows a few English names ("Helsinki airport" → `LEN`).
- Camera images come with their capture time and age, plus a warning when the image is over 30 minutes old.
- Caching: metadata such as stations and cause codes is kept for 24 hours, station and camera lists for 1 hour, live data for 10–60 seconds.
- Attribution: data © Fintraffic / digitraffic.fi, licensed CC BY 4.0.
TDQS
Scored across 8 tools
Each tool targets a distinct resource or action: train-specific status, station search, station boards, connections, road readings, traffic messages, camera discovery, and camera image fetching. The two camera tools are clearly split into find vs. fetch, and rail tools separate station-level, train-level, and route-level queries.
The set mixes verb_noun names like find_station and get_weather_camera_image with noun_phrase names like train_status and station_board. It remains readable, but there is no single predictable convention across all eight tools.
Eight tools is well-scoped for a Finnish transport data server spanning rail and road/weather use cases. Each tool has a clear role and no tools appear redundant or unnecessary.
The rail side covers station lookup, station boards, train status, and direct connections, while the road side covers weather readings, traffic messages, and camera discovery/image retrieval. Minor gaps exist, such as no dedicated rail disruption message feed or weather forecast capability, but core workflows are covered.