Skip to main content
Glama
DB Timetable MCP Server

DB Timetable MCP Server

by jorekai

DB Timetable MCP Server

A Model Context Protocol (MCP) server for the Deutsche Bahn Timetable API. The server provides MCP tools and resources for accessing timetable data, station information, and train changes.

Obligation to name:

This project provides Deutsche Bahn timetable data, which is publicly available under the Creative Commons Attribution 4.0 International License (CC BY 4.0) .

Further information about the API and license terms can be found at developers.deutschebahn.com . API requests are subject to the license terms.

Functions

  • Current timetables : Retrieve current timetable data for a station

  • Timetable changes : Tracking the latest changes

  • Planned timetables : Access to planned timetable data for a specific time

  • Station search : Search for train stations by name or code

Related MCP server: db-mcp

Requirements

  • Node.js 18 or higher

  • API credentials for the DB Timetable API (client ID and client secret)

installation

  1. Clone repository:

    git clone <repository-url>
    cd db-mcp
  2. Install dependencies:

    npm install
  3. Compile TypeScript code:

    npm run build

configuration

Create an .env file in the root directory of the project with the following environment variables:

DB_TIMETABLE_CLIENT_ID=deine-client-id
DB_TIMETABLE_CLIENT_SECRET=dein-client-secret
TRANSPORT_TYPE=stdio
PORT=8080
SSE_ENDPOINT=/sse
LOG_LEVEL=info

Configuration options

  • DB_TIMETABLE_CLIENT_ID : Client ID for the DB API (required)

  • DB_TIMETABLE_CLIENT_SECRET : Client secret for the DB API (required)

  • TRANSPORT_TYPE : Transport type for the MCP server ( stdio or sse , default: stdio )

  • PORT : Port for the SSE server (default: 8080 )

  • SSE_ENDPOINT : Endpoint for SSE connections (default: /sse )

  • LOG_LEVEL : Logging level ( debug , info , warn , error , default: info )

use

Start server

In stdio mode (for CLI testing and debugging):

npm start

In SSE mode (for web clients):

TRANSPORT_TYPE=sse npm start

Test with Inspect mode

The server can be tested with the FastMCP Inspector:

npx fastmcp inspect path/to/index.js

MCP tools

The server provides the following tools:

  1. getCurrentTimetable : Retrieves current timetable data for a station

    • Parameter: evaNo - EVA number of the station (e.g. 8000105 for Frankfurt Hbf)

  2. getRecentChanges : Retrieves recent changes for a station

    • Parameter: evaNo - EVA number of the station (e.g. 8000105 for Frankfurt Hbf)

  3. getPlannedTimetable : Retrieves planned timetable data for a station

    • Parameter:

      • evaNo - EVA number of the station (e.g. 8000105 for Frankfurt Hbf)

      • date - Date in YYMMDD format (e.g. 230401 for 01.04.2023)

      • hour - hour in HH format (e.g. 14 for 2 p.m.)

  4. findStations : Searches for stations using a search pattern

    • Parameter: pattern - search pattern (e.g. "Frankfurt" or "BLS")

MCP resources

The server provides the following resources:

  1. Current timetable data : db-api:timetable/current/{evaNo}

  2. Current timetable changes : db-api:timetable/changes/{evaNo}

  3. Planned timetable data : db-api:timetable/planned/{evaNo}/{date}/{hour}

  4. Station search : db-api:station/{pattern}

Development

Project structure

db-mcp/
├── src/
│   ├── api/             # API-Client und Typen
│   ├── tools/           # MCP-Tools
│   ├── resources/       # MCP-Ressourcen
│   ├── utils/           # Hilfsfunktionen
│   ├── config.ts        # Konfiguration
│   └── index.ts         # Haupteinstiegspunkt
├── dist/                # Kompilierte Dateien
├── .env                 # Umgebungsvariablen
├── package.json
├── tsconfig.json
└── README.md

NPM scripts

  • npm run build : Compiles the TypeScript code

  • npm start : Starts the server

  • npm run dev : Starts the server in development mode with automatic reloading

  • npm test : Runs tests

Extensibility

Potential extensions

  1. Data processing and enrichment

    • Semantic timetable data processing: XML to structured JSON with semantic enrichment

    • Historical data analysis for delays and disruptions

    • Integration of multimodal transport connections

  2. Advanced MCP tools

    • Route planning between stations

    • AI-based delay and capacity forecasts

    • Travel disruption analysis

    • Accessibility check for stations and connections

License

MCP Server: MIT License

DB Timetable API: Creative Commons Attribution 4.0 International License

Available Tools

4 tools
findStationsB

Durchsucht das Verzeichnis der Bahnhofsstationen anhand eines gegebenen Suchmusters. Dies kann der Name der Station oder die EVA-Nummer sein. Das Tool liefert eine Liste von Stationen, die dem Suchmuster entsprechen.

Inputs: pattern (required).

getCurrentTimetableA

Ruft die aktuellen Fahrplandaten einer bestimmten Bahnhofsstation ab. Dies beinhaltet Informationen zu Ankunfts- und Abfahrtszeiten, Gleisbelegungen, Verspätungen und weitere Echtzeitinformationen für den aktuellen Betriebstag.

Inputs: evaNo (required).

getPlannedTimetableB

Holt die geplanten Fahrplandaten für eine angegebene Bahnhofsstation zu einem bestimmten Datum und einer bestimmten Stunde ein. Diese Funktion ist nützlich, um Fahrpläne im Voraus zu planen und Informationen über zukünftige Zugverbindungen zu erhalten.

Inputs: evaNo (required), date (required), hour (required).

getRecentChangesB

Ermittelt die neuesten Fahrplanänderungen für eine spezifische Bahnhofsstation. Dazu gehören Verspätungen, Gleisänderungen, Ausfälle und andere kurzfristige Anpassungen im Betriebsablauf, die in Echtzeit aktualisiert werden.

Inputs: evaNo (required).

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: findStations searches for stations, getCurrentTimetable retrieves real-time data, getPlannedTimetable fetches future schedules, and getRecentChanges tracks recent changes. There is no overlap in functionality, making tool selection straightforward for an agent.

    Naming Consistency4/5

    The naming follows a consistent verb_noun pattern with three tools starting with 'get' and one with 'find', all using camelCase. The minor deviation is 'findStations' versus 'getX', but it remains readable and predictable.

    Tool Count5/5

    With 4 tools, the server is well-scoped for its purpose of accessing railway timetable data. Each tool serves a specific and necessary function, providing a focused set without being too sparse or overwhelming.

    Completeness4/5

    The tool set covers core operations for timetable data: searching stations, retrieving current and planned schedules, and tracking changes. A minor gap is the lack of tools for modifying or managing data (e.g., CRUD operations), but this may be intentional for a read-only server, and agents can work around this limitation.

    Maintenance

    ActivityMaintained
    ResponsivenessLimited data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      An MCP server that exposes the Deutsche Bahn public transport API to any MCP-compatible client (Claude Desktop, Cursor, Cline, Continue, etc.). Five tools cover station search, departures, journey planning, trip details, and nearby stations.
      6
      2
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      An (unofficial) MCP server for the Deutsche Bahn Timetables API — station search, planned departures, and real-time changes (delays, platform changes, cancellations) as tools for Claude and other MCP clients.
      4
      2
      MIT