Renfe MCP Server 🚄
A Model Context Protocol (MCP) server for querying Renfe (Spanish national railway) train schedules using official GTFS data. Integrates seamlessly with Claude Desktop and other MCP-compatible clients.
接入你的智能体
從發布者安裝。不是 PlugMCP 端點。
遠端 URL 還是本機指令? 兩種安裝方式的差異
來自發布者
A Model Context Protocol (MCP) server for querying Renfe (Spanish national railway) train schedules using official GTFS data. Integrates seamlessly with Claude Desktop and other MCP-compatible clients.
MCP server for Spanish Renfe train schedules and live prices with custom DWR scraper
Clone the repository
git clone https://github.com/yourusername/renfe_mcp.git
cd renfe_mcp
Install dependencies
uv sync
Run the server (GTFS data downloads automatically)
uv run python -m renfe_mcp.server
Test the search functionality directly:
from renfe_mcp.schedule_searcher import ScheduleSearcher
from renfe_mcp.price_checker import check_prices
# Search trains
searcher = ScheduleSearcher("renfe_schedule")
trains = searcher.search("Madrid", "Barcelona", "2025-11-20")
# Check prices
prices = check_prices("Madrid", "Barcelona", "2025-11-20")
Add to your Claude Desktop config file:
Windows (%APPDATA%\Claude\claude_desktop_config.json):
{
"mcpServers": {
"renfe": {
"command": "uv",
"args": [
"--directory",
"C:\\Users\\YourName\\path\\to\\renfe_mcp",
"run",
"python",
"-m",
"renfe_mcp.server"
]
}
}
}
macOS (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"renfe": {
"command": "uv",
"args": [
"--directory",
"/path/to/renfe_mcp",
"run",
"python",
"-m",
"renfe_mcp.server"
]
}
}
}
Linux (~/.config/Claude/claude_desktop_config.json):
{
"mcpServers": {
"renfe": {
"command": "uv",
"args": [
"--directory",
"/path/to/renfe_mcp",
"run",
"python",
"-m",
"renfe_mcp.server"
]
}
}
}
Restart Claude Desktop, and you can ask:
search_trainsFind trains between two cities on a specific date with pagination support.
Parameters:
origin (string): Origin city name (e.g., "Madrid", "Barcelona")destination (string): Destination city name (e.g., "Valencia", "Sevilla")date (string, optional): Travel date in flexible formats:
"2025-11-28""28/11/2025""November 28, 2025"page (integer, optional): Page number to display (default: 1)per_page (integer, optional): Results per page (default: 10, max: 50)Example Output:
Found 36 train(s) total
Showing page 1 of 4 (10 trains)
1. AVE
Madrid Pta.Atocha - Almudena Grandes → Barcelona-Sants
Departs: 6:16:00 | Arrives: 9:05:00
Duration: 2h 49min
2. AVE
Madrid Pta.Atocha - Almudena Grandes → Barcelona-Sants
Departs: 6:27:00 | Arrives: 9:25:00
Duration: 2h 58min
...
─────────────────────────────────
To see more trains, use page=2
Total pages: 4
find_stationSearch for train stations in a city.
Parameters:
city_name (string): City name to search (e.g., "Madrid")Example Output:
Found 7 stations:
All stations found:
1. Madrid-Chamartín-Clara Campoamor (ID: 17000)
2. Madrid - Atocha Cercanías (ID: 18000)
3. Madrid Pta.Atocha - Almudena Grandes (ID: 60000)
...
get_train_pricesCheck actual ticket prices by scraping the Renfe website with pagination support.
Parameters:
origin (string): Origin city name (e.g., "Madrid", "Barcelona")destination (string): Destination city name (e.g., "Valencia", "Sevilla")date (string, optional): Travel date (same formats as search_trains)page (integer, optional): Page number to display (default: 1)per_page (integer, optional): Results per page (default: 5, max: 20)Example Output:
PRICE CHECK RESULTS
From: Madrid -> Barcelona
Date: 2025-11-17
Showing 5 train(s)
1. AVE
Departs: 06:16 | Arrives: 09:05
Duration: 2h 49min
Price: 94.90 EUR | [Available]
2. AVE
Departs: 06:27 | Arrives: 09:25
Duration: 2h 58min
Price: 118.60 EUR | [Available]
...
To see more prices, try page=2
Note: This tool scrapes the Renfe website and may take a few seconds to complete. Pagination now matches search_trains so you can get prices for trains on any page (e.g., page 2 shows prices for trains 6-10).
The server includes automatic GTFS data updates from Renfe's open data portal.
On server startup, it checks for new data and downloads if needed:
uv run python -m renfe_mcp.server
# [CHECK] Checking data versions:
# Server: 2025-11-15T00:40:21
# Local: 2025-11-10T00:30:15
# [UPDATE] Server has newer data
# [DOWNLOAD] Downloading GTFS data...
# [OK] GTFS data updated successfully!
Check and update if needed:
uv run python -m renfe_mcp.update_data
Force update (download regardless of version):
uv run python -m renfe_mcp.update_data --force
The update system:
renfe_schedule/.last_updatedrenfe_mcp/
├── pyproject.toml # Dependencies & build config
├── README.md # This file
├── src/renfe_mcp/ # Main package
│ ├── __init__.py # Package exports
│ ├── server.py # FastMCP server implementation
│ ├── config.py # Pydantic configuration
│ ├── exceptions.py # Exception hierarchy
│ ├── logging.py # Structured logging
│ ├── security.py # Auth & rate limiting
│ ├── price_checker.py # Price checking module
│ ├── schedule_searcher.py # GTFS schedule search
│ ├── station_service.py # Unified station lookups
│ ├── update_data.py # GTFS data updater
│ └── scraper/ # Price scraper package
│ ├── __init__.py # Package exports
│ ├── scraper.py # RenfeScraper with DWR protocol
│ ├── dwr.py # DWR utilities
│ ├── models.py # Pydantic models
│ ├── exceptions.py # Scraper exceptions
│ └── stations.json # Station code database
├── tests/ # Test suite
│ ├── test_final_integration.py
│ ├── test_security.py
│ └── ...
└── renfe_schedule/ # GTFS data (auto-downloaded)
├── stops.txt # Station information
├── routes.txt # Train routes
├── trips.txt # Trip schedules
├── stop_times.txt # Arrival/departure times
├── calendar.txt # Service schedules
├── calendar_dates.txt # Holiday exceptions
└── .last_updated # Version tracking
calendar.txt for service schedules (day of week)calendar_dates.txt (holidays, special dates)pickup_type, drop_off_type)The server supports any route in the Renfe network:
Popular Cities:
Use find_station to discover available stations in any city.
# Clone and install
git clone https://github.com/yourusername/renfe_mcp.git
cd renfe_mcp
uv sync
# Run the server
uv run python -m renfe_mcp.server
# Run tests
uv run python tests/test_final_integration.py
Configure via environment variables (prefix RENFE_) or .env file:
# Authentication
RENFE_ENABLE_AUTH=true
RENFE_API_KEY=your-secret-key
# Rate Limiting
RENFE_RATE_LIMIT_ENABLED=true
RENFE_MAX_REQUESTS_PER_MINUTE=30
RENFE_MAX_REQUESTS_PER_HOUR=200
# Development
RENFE_DEV_MODE=false
RENFE_LOG_LEVEL=INFO
GTFS data from Renfe's Open Data Portal:
https://data.renfe.com/api/3/action/resource_show25d6b043-9e47-4f99-bd91-edd51d782450Contributions welcome! Please:
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
Travel smart, travel by train! 🚄
MCP server for Spanish Renfe train schedules and live prices with custom DWR scraper
工具
尚無工具清單。遠端伺服器會在首次健康檢查後取得工具清單。
常見問題
在本頁複製適用於 Cursor、Claude Desktop、Claude Code 或 VS Code 的 stdio 設定。它使用發布者的安裝方式,而不是 PlugMCP 代理伺服器。
這筆記錄未列出必要的環境變數。
Renfe 透過 stdio 在本機執行。
上次檢查時間:2026-10-28。 MCP server for Spanish Renfe train schedules and live prices with custom DWR scraper