Skip to main content
Glama

Trafikverket MCP Server

MCP server for Trafikverket (the Swedish Transport Administration) open traffic data: live train departures and arrivals, live train positions, railway disruptions, replacement traffic for cancelled trains, road incidents and measured road weather. Built on Trafikverket's open Trafikinfo API.

Features

  • search_stations - Find train stations by name or location signature

  • get_train_announcements - Live departures or arrivals at a station, with delays, platforms and cancellations

  • get_train_positions - Live GPS position, speed and bearing of a train by number, or of all trains around a point

  • get_train_messages - Current railway traffic messages (track work, faults, disruptions), optionally per county

  • get_replacement_traffic - Replacement buses and taxis for cancelled trains, with stops, boarding locations and times

  • get_railway_events - Railway events (faults, failures, disruptions) with reason code, status and affected sections, by station, status or related operative event

  • get_road_situations - Current road incidents: accidents, road works, obstacles and restrictions, by county and/or around a point

  • get_road_weather - Measured road weather (air and road surface temperature, wind, grip, precipitation) from the nearest roadside stations

Related MCP server: DB Timetable MCP Server

Coverage

Sweden only (Trafikverket's state road and railway network).

Requirements

A free Trafikverket API key. Create one in the Trafikverket data portal and provide it to the server in the TRAFIKVERKET_API_KEY environment variable. The server starts without a key, but every tool returns an error until one is set.

Installation

Claude Code

Add to your Claude Code settings (~/.claude/settings.json):

{
  "mcpServers": {
    "trafikverket": {
      "command": "node",
      "args": ["/path/to/trafikverket-mcp-server/dist/index.js"],
      "env": {
        "TRAFIKVERKET_API_KEY": "your-api-key"
      }
    }
  }
}

Claude Desktop

Add the same trafikverket entry under mcpServers in claude_desktop_config.json.

Build from source

npm install
npm run build

Usage Examples

Next departures from Stockholm Central

Tool: get_train_announcements
Input: { "station": "Stockholm", "hoursAhead": 2 }

Arrivals in Göteborg, including trains that arrived 30 minutes ago

Tool: get_train_announcements
Input: { "station": "Göteborg C", "direction": "arrivals", "minutesBack": 30 }

Find the exact station before querying

Tool: search_stations
Input: { "query": "Hässleholm" }

Where is train 421 right now?

Tool: get_train_positions
Input: { "trainNumber": "421" }

Trains within 5 km of Göteborg C

Tool: get_train_positions
Input: { "latitude": 57.7089, "longitude": 11.9732, "radiusKm": 5 }

Railway disruptions in Skåne

Tool: get_train_messages
Input: { "county": "Skåne" }

Replacement buses from Lund C

Tool: get_replacement_traffic
Input: { "station": "Lund C" }

What replaces train 1043 today?

Tool: get_replacement_traffic
Input: { "trainNumber": "1043" }

Ongoing railway events around Hässleholm

Tool: get_railway_events
Input: { "station": "Hässleholm C" }

Accidents within 30 km of Gothenburg

Tool: get_road_situations
Input: { "latitude": 57.7089, "longitude": 11.9746, "radiusKm": 30, "messageType": "Olycka" }

Road weather near Skövde

Tool: get_road_weather
Input: { "latitude": 58.3912, "longitude": 13.8453 }

API Reference

search_stations

Find train stations by name (diacritics and case are ignored) or location signature.

Parameter

Type

Required

Default

Description

query

string

Yes

-

Station name, part of a name, or signature

limit

number

No

10

1-25

latitude

number

No

-

With longitude: include distance to each match

longitude

number

No

-

With latitude: include distance to each match

Returns name, signature, shortName, counties, coordinates and optionally distanceKm per station.

get_train_announcements

Live departures or arrivals at one station. Accepts a station name or a location signature; an ambiguous name returns an error listing the candidates (a bare city name such as "Stockholm" resolves to the central station "Stockholm C").

Parameter

Type

Required

Default

Description

station

string

Yes

-

Station name or location signature

direction

string

No

departures

departures or arrivals

minutesBack

number

No

15

0-120, minutes before now to include

hoursAhead

number

No

2

0.25-12, hours after now to include

limit

number

No

25

1-100

Returns per train: train number, operator, product, origin and destination names, track, advertised/estimated/actual time, delayMinutes (positive = late), canceled, deviation notes and other information.

get_train_positions

Live GPS positions of trains. Give a train number, a point to search around, or both.

Parameter

Type

Required

Default

Description

trainNumber

string

No*

-

Advertised or operational train number, e.g. "421"

latitude

number

No*

-

Center of a radius search (requires longitude)

longitude

number

No*

-

Center of a radius search (requires latitude)

radiusKm

number

No

10

0.5-100

maxAgeMinutes

number

No

10

1-60, ignore positions reported longer ago

limit

number

No

25

1-100

* At least trainNumber or latitude/longitude is required.

Returns per train (newest report only): train number, departure date, coordinates, distanceKm (radius searches, nearest first), speedKmh, bearingDegrees (direction of travel), active, report timestamp and ageMinutes.

get_train_messages

Current railway traffic messages (Trafikverket operative events): track work, faults and other disruptions.

Parameter

Type

Required

Default

Description

county

string / number

No

-

County name (e.g. "Skåne") or code (e.g. 12)

activeOnly

boolean

No

true

Only ongoing events

limit

number

No

20

1-100

Returns event type, header, description (when a public message has been published), start/end/expected end, and the affected stations and sections.

get_replacement_traffic

Replacement traffic (ersättningstrafik) reported by the train operators: the bus, coach or taxi trips that run instead of cancelled trains. Not every replacement is reported, so check get_train_announcements for which trains are cancelled.

Parameter

Type

Required

Default

Description

station

string

No

-

Only trips stopping here (station name or location signature)

trainNumber

string

No

-

Only trips replacing this advertised train number

date

string

No

-

Departure date of the replaced train (YYYY-MM-DD); searches the whole day instead of the time window

minutesBack

number

No

30

0-240, include trips running or departing this many minutes before now

hoursAhead

number

No

12

0.5-48, include trips departing up to this many hours after now

limit

number

No

20

1-50

Returns per trip: replaced trains (number, date, product), vehicleMode (bus, coach, taxi, ...), status (planned, ordered, confirmed, running, finished, canceled), vehicle identifier, wheelchairAccessible, toilet, origin/destination, departure/arrival time and every stop in order with stop description (where to board), coordinates, planned/expected/actual arrival and departure, delayMinutes, disembarkingOnly, traveller note and connecting stations. With station, the stop there is also returned as atStation and trips are ordered by the time at that stop.

get_railway_events

Railway events (Trafikverket RailwayEvent): faults, failures and disruptions registered in Trafikverket's event system, including cause-coded events that never became a public traffic message. Deleted events are never returned.

Parameter

Type

Required

Default

Description

station

string

No

-

Station name or signature; matches sections that start, end, pass via or include it

status

string

No

-

Ingen, MöjligOperativHändelse, BedömdEjOperativHändelse or OperativHändelse

operativeEventId

string

No

-

Related operative event id (the eventId from get_train_messages)

activeOnly

boolean

No

true

Only events without an end time or with an end time in the future

limit

number

No

20

1-100

Returns per event (most recently modified first): eventId, status, reasonCode, operativeEventId, active, start/end/created/last updated time, version, the affected sections (from, via, to and ordered intermediate stations) and a flat list of all locations.

get_road_situations

Current incidents on the state road network.

Parameter

Type

Required

Default

Description

county

string / number

No

-

County name or code

latitude

number

No

-

Center of a radius search (requires longitude)

longitude

number

No

-

Center of a radius search (requires latitude)

radiusKm

number

No

25

0.5-200

messageType

string

No

-

Swedish message type as used by Trafikverket, e.g. "Olycka", "Vägarbete"

limit

number

No

25

1-100

Results are ordered by severity (code 1-5, higher is more severe), then distance. Each entry has message, type, severity, road number and name, location, start/end time, restrictions and coordinates.

get_road_weather

Observations from the nearest roadside weather stations (not a forecast).

Parameter

Type

Required

Default

Description

latitude

number

Yes

-

-90 to 90

longitude

number

Yes

-

-180 to 180

radiusKm

number

No

25

1-100

limit

number

No

3

1-20 nearest stations

Returns per station: name, distance, sample time, air temperature (°C), humidity (%), dew point (°C), visibility (m), wind (m/s, degrees), road surface temperature (°C), grip, ice/snow/water flags, and precipitation and wind over the last 10 minutes.

Development

npm install
npm run typecheck
npm test
npm run build

Tests mock fetch and run against JSON fixtures, so no API key is needed.

Data Source

Data from Trafikverket's open Trafikinfo API, published as open data (CC0 according to the API documentation). Please check Trafikverket's current terms before redistributing data at scale.

License

MIT

Available Tools

8 tools
get_railway_eventsA
Read-onlyIdempotent

Get railway events from Trafikverket: faults, failures and disruptions in the railway as registered in Trafikverket's event system (Basun), including ones that never became a public traffic message. Each event has an id, status (Swedish: "Ingen" = only cause-coded, "MöjligOperativHändelse", "BedömdEjOperativHändelse", "OperativHändelse"), reason code, start/end time, the affected sections (from/via/to and intermediate stations) and, when it has one, the id of the related operative event (the eventId returned by get_train_messages). Filter by station (name or signature), status or operative event id. Use get_train_messages for the public disruption text instead. Returns an error result (isError: true) if TRAFIKVERKET_API_KEY is missing/invalid or the Trafikverket API is unreachable. Coverage: Sweden only (Trafikverket data).

Inputs: limit, status, station, activeOnly, +1 more.

get_replacement_trafficA
Read-onlyIdempotent

Get replacement traffic (ersättningstrafik) for Swedish trains: the buses, coaches or taxis that run instead of cancelled trains, with the replaced train numbers, vehicle type, status (planned, ordered, confirmed, running, finished, canceled), wheelchair access, toilet, and every stop with stop description (where to board), planned/expected/actual times, delay in minutes and traveller notes. Filter by station (name or signature; the stop there is returned as atStation), by replaced train number, and/or by the replaced train's departure date; otherwise trips from minutesBack before now to hoursAhead after now. Operators report this voluntarily, so not every replacement is listed: use get_train_announcements to see which trains are cancelled and get_train_messages for the disruption behind them. Returns an error result (isError: true) if TRAFIKVERKET_API_KEY is missing/invalid or the Trafikverket API is unreachable. Coverage: Sweden only (Trafikverket data).

Inputs: date, limit, station, hoursAhead, +2 more.

get_road_situationsA
Read-onlyIdempotent

Get current road incidents and disruptions on the Swedish state road network: accidents, road works, obstacles, restrictions and traffic messages, each with severity (code 1-5, higher is more severe), road number, location, start/end time and coordinates. Filter by county and/or by a point plus radius (latitude, longitude, radiusKm); results are ordered by severity, then distance. Message types are Swedish, e.g. "Olycka" (accident) and "Vägarbete" (road work). Use get_road_weather for measured road conditions instead. Returns an error result (isError: true) if TRAFIKVERKET_API_KEY is missing/invalid or the Trafikverket API is unreachable. Coverage: Sweden only (Trafikverket data).

Inputs: limit, county, latitude, radiusKm, +2 more.

get_road_weatherA
Read-onlyIdempotent

Get measured road weather from Trafikverket's roadside stations nearest to a point: air temperature (°C), humidity (%), dew point (°C), visibility (m), wind speed (m/s) and direction (degrees), road surface temperature (°C), grip, ice/snow/water on the road, and precipitation and wind over the last 10 minutes. These are actual observations, not a forecast; use a forecast source such as SMHI for future weather. Returns an error result (isError: true) if TRAFIKVERKET_API_KEY is missing/invalid or the Trafikverket API is unreachable. Coverage: Sweden only (Trafikverket data).

Inputs: latitude (required), longitude (required), limit, radiusKm.

get_train_announcementsA
Read-onlyIdempotent

Get live train departures or arrivals at a Swedish station: train number, operator, product (e.g. "Pendeltåg"), origin/destination, platform (track), advertised vs. estimated/actual time, delay in minutes, cancellation and deviation notes. Accepts a station name (e.g. "Göteborg C", "Stockholm") or a location signature; an ambiguous name returns an error listing the candidates. Covers a window from minutesBack before now to hoursAhead after now. Use get_train_messages for broader disruption notices (track work, faults) instead of per-train data. Times are ISO 8601, delays in minutes (positive = late). Returns an error result (isError: true) if TRAFIKVERKET_API_KEY is missing/invalid or the Trafikverket API is unreachable. Coverage: Sweden only (Trafikverket data).

Inputs: station (required), limit, direction, hoursAhead, +1 more.

get_train_messagesA
Read-onlyIdempotent

Get current railway traffic messages from Trafikverket: track work, technical faults and other disruptions, with event type, header, description, start/expected end time, and the affected stations/sections. Optionally filter by county. Use this for "is there a disruption on the railway" questions; use get_train_announcements for per-train timetable and delay data. Returns an error result (isError: true) if TRAFIKVERKET_API_KEY is missing/invalid or the Trafikverket API is unreachable. Coverage: Sweden only (Trafikverket data).

Inputs: limit, county, activeOnly.

get_train_positionsA
Read-onlyIdempotent

Get live GPS positions of Swedish trains: coordinates, speed (km/h), direction of travel (degrees) and when the position was reported. Locate one train by its train number, list trains within a radius of a point (latitude, longitude, radiusKm), or both. Only positions reported within the last maxAgeMinutes are returned. Use get_train_announcements for timetable and delay data at a station. Returns an error result (isError: true) if TRAFIKVERKET_API_KEY is missing/invalid or the Trafikverket API is unreachable. Coverage: Sweden only (Trafikverket data).

Inputs: limit, latitude, radiusKm, longitude, +2 more.

search_stationsA
Read-onlyIdempotent

Find Swedish train stations by name or location signature. Returns each station's display name, location signature (the short code used by the other train tools, e.g. "Cst" for Stockholm Central), county codes and coordinates; pass latitude/longitude to also get the distance to each match. Use this to look up the exact station before calling get_train_announcements when a name is ambiguous. Returns an error result (isError: true) if TRAFIKVERKET_API_KEY is missing/invalid or the Trafikverket API is unreachable. Coverage: Sweden only (Trafikverket data).

Inputs: query (required), limit, latitude, longitude.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.7/5.0

    Scored across 8 tools

    Disambiguation5/5

    Each tool targets a distinct data source and clearly separates superficially similar concepts: get_railway_events (raw internal event registry) vs get_train_messages (public disruption text) vs get_train_announcements (per-train timetable/delays), with explicit 'use X instead' cross-references in the descriptions. Road tools (situations vs weather) and replacement traffic are likewise unambiguous, and search_stations is clearly the lookup helper for the train tools.

    Naming Consistency5/5

    Seven of eight tools follow a strict get_<resource>_<noun> snake_case pattern with consistent resource grouping (train_*, road_*). The single deviation, search_stations, is a conventional, readable choice for a lookup operation rather than an inconsistency.

    Tool Count5/5

    Eight tools is a well-scoped set for a national transport data API, with each tool mapping to one coherent data domain (rail events, positions, replacement traffic, road incidents, road weather, announcements, messages, station lookup). No tool appears redundant or padded.

    Completeness4/5

    The live rail and road information surface is strong, including the station lookup needed to resolve ambiguous names. However, there are no tools for road traffic flow/volumes, weather forecasts, planned timetables/routes for a given train number, or ferry/other Trafikverket modes, leaving some natural follow-up questions unanswered.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Provides real-time access to Swedish road weather, traffic cameras, road conditions, and traffic flow data from Trafikverket (Swedish Transport Administration). Enables users to query weather stations, cameras, traffic situations, and flow data through natural language.
      10
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Provides access to Deutsche Bahn's timetable data through MCP, enabling real-time train schedules, station search, and change tracking for German railway stations.
      4
      259 npm
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables querying Swiss public transport data (stations, departures, connections) from the Transport Open Data API via natural language through an MCP gateway.
      278 npm
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI assistants to access Swiss public transport data including journey planning, real-time departures, disruptions, occupancy forecasts, ticket prices, and train formations via a standardized MCP interface.
      11
      27 PyPI
      7
      MIT