JorritPeters/sweden-public-transport-mcp-server
If you are the rightful owner of sweden-public-transport-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Swedish Public Transport MCP Server provides real-time transport data for Swedish public transport using the ResRobot API, enabling AI assistants to plan journeys efficiently.
find_station_id_tool
Finds station IDs by city or station name using the ResRobot location API.
get_travel_options_tool
Gets travel information between two cities using their station IDs.
Swedish Public Transport MCP Server
A Model Context Protocol (MCP) server that provides access to Swedish public transport information through the ResRobot API. This server allows AI assistants to retrieve real-time transport data for Swedish public transport to plan your journey from A to B.
Prerequisites
- Python 3.8+
- UV package manager (for local development)
- ResRobot API key from Trafiklab
- Google Cloud SDK (for Cloud Run deployment)
Setup
1. Clone the repo
Clone this repository and navigate to the directory:
git clone <repository-url>
cd sweden-public-transport-mcp-server
2. Environment Variables
Create a .env
file in the project root:
# ResRobot API Configuration
resbot_key=your_resrobot_api_key_here
Local Development
Running the Server Locally
-
Install dependencies:
cd transport uv sync
-
Run the local MCP server:
uv run mcp_local.py
Claude Desktop Configuration (Local)
Add this to your Claude Desktop configuration file (working version for Claude desktop):
{
"mcpServers": {
"transport": {
"command": "uv",
"args": [
"--directory",
"/Users/jorpet/Documents/git/sweden-public-transport-mcp-server/transport",
"run",
"mcp_local.py"
]
}
}
}
Cloud Deployment
Deploy to Google Cloud Run
- Deploy to Cloud Run:
gcloud run deploy mcp-server \ --no-allow-unauthenticated \ --region=us-central1 \ --set-env-vars resbot_key=your_resrobot_api_key_here,local_run=false --source .
Obs: this is a very unsecure way of setting the api key. Next version will use Google Secret Manager.
- Set up proxy for local access:
gcloud run services proxy mcp-server --region=us-central1
Claude Desktop Configuration (Cloud Run)
For the cloud-deployed version, add this to your LLM configuration (working version for Claude desktop):
{
"mcpServers": {
"transport_cloud_run": {
"command": "npx",
"args": ["-y", "mcp-remote", "http://localhost:8080/mcp"]
}
}
}
Testing
Test Cloud Run Deployment
Use the provided test script to verify your Cloud Run deployment:
python test_mcp_cloud_run.py
This script will:
- List available tools from the MCP server
- Test the
find_station_id_tool
with "Uppsala" - Test the
get_travel_options_tool
with example station IDs
Manual Testing
You can also test the tools manually through Claude Desktop once configured:
Get travel options:
What are the travel options from Uppsala to Stockholm?
Available Tools
The MCP server provides two main tools for Swedish public transport information:
find_station_id_tool
Finds station IDs by city or station name using the ResRobot location API.
Parameters:
city_name
(string, required): The name of the city or station to search for
Input Example:
{
"city_name": "Uppsala"
}
Output Example:
Station ID of Uppsala is 740000005
Usage in Claude:
Find the station ID for "Stockholm"
Claude Response:
The tool will return station information for Stockholm, including the main Stockholm Centralstation with ID 740000001
.
get_travel_options_tool
Gets travel information between two cities using their station IDs.
Parameters:
start_city_id
(string, required): The station ID of the departure cityend_city_id
(string, required): The station ID of the destination city
Input Example:
{
"start_city_id": "740000005",
"end_city_id": "740000001"
}
Output Example:
Travel options from 740000005 to 740000001:
1. Departure: 14:17 → Arrival: 14:55 (Duration: 38 minutes)
2. Departure: 14:47 → Arrival: 15:25 (Duration: 38 minutes)
3. Departure: 15:17 → Arrival: 15:55 (Duration: 38 minutes)
Usage in Claude:
What are the travel options from Uppsala to Stockholm?
Claude Response: The assistant will:
- First use
find_station_id_tool
to find station IDs for Uppsala and Stockholm - Then use
get_travel_options_tool
with the found station IDs - Present you with formatted departure times, arrival times, and journey durations
Common Station IDs:
- Stockholm Centralstation:
740000001
- Uppsala Centralstation:
740000005
- Göteborg Centralstation:
740000002
- Malmö Centralstation:
740000003