# Renfe Data MCP

> Renfe Data provides direct access to Spain's national railway network data. You get real-time GPS coordinates for Cercanías and Long Distance trains (AVE/LD/MD). It also gives you static GTFS schedules, service alerts, and a searchable repository of thousands of open government datasets.

## Overview
- **Category:** iot-hardware
- **Price:** Free
- **Tags:** railway, real-time-tracking, gps-data, public-transport, logistics, open-data

## Description

You connect your AI agent to this server to access Spain's national railway data—it’s got everything from live GPS coordinates to thousands of open government datasets. When you use it, you get real-time operational status and static resources all in one spot.

### Real-Time Tracking

You can track where trains are right now. For the commuter lines (Cercanías), `rt_vehicle_positions_cercanias` gives you the live GPS coordinates and movement status, updating every 20 seconds. If you need to know if a Cercanías train is delayed or canceled, `rt_trip_updates_cercanias` provides that specific trip status update, also refreshing every 20 seconds. For Long Distance services (AVE/LD/MD), the system tracks vehicle positions using `rt_vehicle_positions_ld`, which updates roughly every 15 minutes. To get a direct read on whether an entire long-distance service is delayed or canceled, you use `rt_trip_updates_ld`; this update comes through around every 30 seconds.

### Service Alerts and Disruptions

You don't have to guess if the line's running smooth. You check for system-wide disruptions using `get_avisos`, which reports planned service modifications or actual track incidents across the entire network. If you need real-time alerts specific to the commuter lines, `rt_alerts_cercanias` feeds you those immediate updates on service changes or incidents every 20 seconds.

### Static Data and Offline Prep

When your app needs data without Wi-Fi, this server has you covered. You use `get_static_datasets` to pull direct download URLs for major static datasets, like comprehensive GTFS schedules and station lists, perfect for building an application that runs totally offline.

### Dataset Discovery and Metadata

The service exposes a massive repository of open government data using the CKAN tools. You start by seeing what's available with `ckan_package_list`, which returns a list of every single dataset package name hosted in the Renfe Data portal. If you know generally what kind of data you want, you run `ckan_datastore_search` to filter and search specific resources within that data portal using keywords or defined filters.

To understand the structure of a particular set of data, you use `ckan_package_show`, which retrieves detailed metadata about one entire package, telling you its source and what it's built around. If you know exactly which resource you need inside those packages, `ckan_resource_show` gives you the metadata for that specific data asset.

Finally, if you want to see the raw details of a dataset without searching through the whole portal, you can get precise information using `ckan_datastore_search` again; this function lets you target and pull data resources based on your criteria.

## Tools

### ckan_datastore_search
Searches specific data resources within the Renfe Data portal using keywords or filters.

### ckan_package_list
Retrieves a list of all available dataset names hosted in the Renfe Data repository.

### ckan_package_show
Gets detailed metadata about one specific dataset, including its structure and source.

### ckan_resource_show
Retrieves metadata for a specific data resource within a package.

### get_avisos
Checks planned service modifications or track incidents across the network.

### get_static_datasets
Lists direct download URLs for comprehensive static datasets like schedules and station lists.

### rt_alerts_cercanias
Gets real-time service alerts specifically for the Cercanías (commuter) lines, updating every 20 seconds.

### rt_trip_updates_cercanias
Provides live trip status updates for Cercanías trains, showing delays or cancellations, updated every 20 seconds.

### rt_trip_updates_ld
Gets real-time trip updates for Long Distance (AVE/LD/MD) services, updating approximately every 30 seconds.

### rt_vehicle_positions_cercanias
Retrieves the live GPS position and movement status of Cercanías trains, updated every 20 seconds.

### rt_vehicle_positions_ld
Gets real-time vehicle positions for Long Distance (AVE/LD/MD) services, updated every 15 minutes.

## Prompt Examples

**Prompt:** 
```
List all available dataset names in the Renfe Data portal.
```

**Response:** 
```
I've retrieved the list of datasets. There are several available, including 'Estaciones', 'Horarios-GTFS', and 'Ocupacion-Trenes'. Which one would you like to explore further?
```

**Prompt:** 
```
Show me the current real-time positions of Cercanías trains.
```

**Response:** 
```
Fetching live GPS data... I found 42 trains currently active. For example, train C-4 is currently moving near Madrid-Atocha (Lat: 40.406, Lon: -3.692). Would you like a full list or a specific line?
```

**Prompt:** 
```
Are there any trip updates or delays for Long Distance trains right now?
```

**Response:** 
```
Checking trip updates for AV/LD/MD... I see a 10-minute delay for the AVE 03122 from Barcelona to Madrid due to a technical check. Other services are running on time. Should I check for alerts in specific regions?
```

## Capabilities

### Track Live Vehicle Positions
Retrieves the current GPS coordinates and movement status of trains (Cercanías or Long Distance) at set intervals.

### Check Service Alerts and Delays
Gathers real-time information on track incidents, planned service changes, or system-wide disruptions across the network.

### Search Open Datasets
Uses the CKAN tools to list, search, and view metadata for thousands of available railway datasets.

### Retrieve Static Schedules (GTFS)
Fetches direct download URLs containing standardized GTFS schedules and station lists for offline application development.

### Monitor Trip Updates
Provides updates on specific train routes, indicating if a service is running on time or if there's an expected delay/cancellation.

## Use Cases

### A commuter needs to check for morning delays.
The user asks their agent: 'Are there any issues on the Madrid-Cercanías line?' The agent immediately calls `rt_alerts_cercanias` and then follows up with `rt_trip_updates_cercanias`, solving the problem by giving a clear status report of delays or cancellations.

### A developer needs historical data for a map visualization.
Instead of manually collecting schedule PDFs, the agent runs `get_static_datasets`. This provides direct download URLs for GTFS files. The developer downloads these structured schedules and builds their full-featured mapping service.

### A logistics firm needs to monitor entire fleet movements.
The analyst asks: 'What are the positions of all long-distance trains right now?' The agent executes `rt_vehicle_positions_ld`, returning a structured list of vehicle IDs and their current coordinates, allowing immediate performance assessment.

### A researcher needs to know about local urban transport data.
The scientist first runs `ckan_package_list` to see what's available. They then use `ckan_datastore_search` with terms like 'mobility' or 'Estaciones' to find the exact dataset they need for their academic model.

## Benefits

- See the exact location of a train right now. Instead of checking multiple physical signs, calling `rt_vehicle_positions_cercanias` gives you GPS coordinates for every active commuter train instantly.
- Get current delay status in one call. You don't have to visit different websites to check if an AVE is delayed; running `rt_trip_updates_ld` pulls the latest information directly.
- Prepare for offline use. Use `get_static_datasets` to grab GTFS files and station lists once. Your application can then run without needing a constant connection to Renfe's servers.
- Find data schemas quickly. If you need to know what kind of datasets exist, start by listing packages with `ckan_package_list`. This tells you the scope before you dive into searching.
- Track service changes immediately. Running `get_avisos` gives you real-time alerts about track incidents or planned maintenance, letting you warn users *before* they reach a problem spot.

## How It Works

The bottom line is: you use natural language to call specific functions that pull live operational data from Spain's railway system.

1. Subscribe to the Renfe Data server and input your API key.
2. Tell your AI client (Claude, Cursor, etc.) exactly what data you need—for example, 'What is the current position of a Cercanías train?'
3. The agent runs the correct tool (e.g., `rt_vehicle_positions_cercanias`), and it returns structured, up-to-date JSON data.

## Frequently Asked Questions

**How do I find out what kind of datasets are available with ckan_package_list?**
You run `ckan_package_list`. This command retrieves all dataset names in the Renfe Data portal. It's a good first step to see if 'GTFS' or 'Estaciones' is listed before you try to use it.

**What should I use for real-time position updates on commuter trains?**
Use the `rt_vehicle_positions_cercanias` tool. It gives live GPS coordinates and movement status, updating every 20 seconds. This is the specific function you need for current location data.

**Can I get historical schedules from Renfe Data?**
Yes. You use `get_static_datasets` to list direct download URLs for GTFS schedules and station lists. These files are designed for offline analysis, unlike the live tools.

**Which tool shows planned service modifications? ckan_datastore_search or get_avisos?**
You must use `get_avisos`. This specific function retrieves real-time information on track incidents and planned service changes, which is different from searching general datasets.

**How often do the trip updates run for Long Distance trains using rt_trip_updates_ld?**
The `rt_trip_updates_ld` tool updates every 30 seconds. This provides a consistent, low-latency stream of delay and cancellation information for AVE/LD/MD services.

**I want to see the full schema of a specific dataset; should I use `ckan_package_show` or `ckan_resource_show`?**
`ckan_resource_show` gives you the precise metadata for an individual data resource. If you need to know what fields are available within a package, that's your tool. It provides details like format and last updated dates.

**How do I get download links for offline analysis using `get_static_datasets`?**
`get_static_datasets` returns direct URLs to static files, such as GTFS schedules and station lists. Your AI client can use these links directly to pull the data into a local format for deep-dive work.

**What is the update frequency when I run `rt_vehicle_positions_cercanias`?**
The `rt_vehicle_positions_cercanias` tool updates every 20 seconds. This means your agent will receive near real-time GPS coordinates for commuter trains, making it ideal for continuous monitoring.

**How often are the real-time train positions updated?**
It depends on the service: Cercanías positions (`rt_vehicle_positions_cercanias`) update every 20 seconds, while Long Distance trains (`rt_vehicle_positions_ld`) update every 15 minutes.

**Can I check for delays or platform changes for a specific trip?**
Yes. Use `rt_trip_updates_cercanias` or `rt_trip_updates_ld` to get live information on delays, cancellations, and platform assignments across the network.

**Where can I find the static GTFS files for schedules?**
You can use the `get_static_datasets` tool. It returns direct download URLs for GTFS schedule packages and CSV/XLSX lists of all Renfe stations.