geetanshi0205/Transitland-Transit-MCP-Server
If you are the rightful owner of Transitland-Transit-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.
Transitland Transit MCP Server provides comprehensive transit information using the Transitland API and Google Maps integration.
Transitland Transit MCP Server
A Model Context Protocol (MCP) server that provides comprehensive transit information using the Transitland API and Google Maps integration. This tool allows you to search for transit feeds, operators, routes, stops, and real-time departure information.
Features
- Location Services: Geocode addresses and reverse geocode coordinates
- Transit Feeds: Search and retrieve GTFS feed information
- Operators & Agencies: Find transit operators and agencies by location
- Routes: Search for transit routes with filtering capabilities
- Stops: Find stops by location, name, or coordinates with departure times
- Real-time Information: Get live departure times and delays
- Trip Planning: Access detailed trip and stop time information
Installation
Prerequisites
- Python 3.8 or higher
- pip package manager
Setup
-
Clone or download the project
git clone <repository-url> cd Transitland_Transit_MCP_Agent
-
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
Copy the example environment file:
cp .env.example .env
Edit
.env
and add your API keys:# Transitland API Configuration TRANSITLAND_API_KEY=your_transitland_api_key_here # Google Maps API Configuration GOOGLE_MAPS_API_KEY=your_google_maps_api_key_here
Getting API Keys
Transitland API Key
- Visit Transitland
- Sign up for an account
- Navigate to your dashboard to get your API key
- Add the key to your
.env
file
Google Maps API Key
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Enable the following APIs:
- Geocoding API
- Maps JavaScript API (optional, for enhanced functionality)
- Create credentials (API Key)
- Add the key to your
.env
file
Usage
Running the Server
Start the MCP server:
python server.py
The server will run using stdio transport and can be integrated with MCP-compatible clients.
Available Tools
Location Services
geocode_address(address)
- Convert address to coordinatessearch_nearby_stops(latitude, longitude, radius, route_types, limit)
- Find stops near coordinates
Transit Information
search_feeds(spec, search, limit)
- Search GTFS feedsget_feed_details(feed_id)
- Get detailed feed informationsearch_operators(search, adm0_name, adm1_name, city_name, limit)
- Find operatorssearch_agencies(search, agency_name, adm0_name, adm1_name, limit)
- Find agenciessearch_routes(search, route_type, operator_onestop_id, include_geometry, limit)
- Find routessearch_stops(search, lat, lon, radius, served_by_route_types, limit)
- Find stops
Real-time Information
search_stops_by_location_name(location_name, radius, route_types, limit)
- Find stops near a named locationget_stop_departures(stop_id, next, include_alerts, limit)
- Get departure timesfind_stops_and_departures(location_name, radius, max_stops)
- Combined stop and departure searchget_live_transit_info(location_name, radius)
- Comprehensive live transit information
Trip Planning
get_route_trips(route_id, service_date, include_geometry, limit)
- Get trips for a routeget_trip_details(route_id, trip_id)
- Get detailed trip information with stop times
Route Types
When using route type filters, use these GTFS route type codes:
0
- Tram, Streetcar, Light rail1
- Subway, Metro2
- Rail3
- Bus4
- Ferry5
- Cable tram6
- Aerial lift, Gondola7
- Funicular
Example Usage
# Find transit stops near Times Square
result = await search_stops_by_location_name("Times Square, NYC", radius=500, limit=10)
# Get live departures for a specific area
info = await get_live_transit_info("Union Station, Chicago", radius=1000)
# Search for bus routes in a city
routes = await search_routes(search="downtown", route_type=3, limit=20)
# Get next departures from a stop
departures = await get_stop_departures("stop_id_here", next=5)
Project Structure
Transitland_Transit_MCP_Agent/
āāā server.py # Main MCP server implementation
āāā requirements.txt # Python dependencies
āāā .env.example # Environment variables template
āāā .env # Your API keys (create this)
āāā README.md # This documentation
Dependencies
- fastmcp - MCP server framework
- httpx - Async HTTP client for API requests
- python-dotenv - Environment variable management
Security Notes
- Never commit your
.env
file with actual API keys - The
.env.example
file is safe to commit as it contains no real credentials - Keep your API keys secure and rotate them periodically
- Consider implementing rate limiting for production deployments
Troubleshooting
Common Issues
- Missing API Keys: Ensure your
.env
file exists and contains valid API keys - Module Not Found: Run
pip install -r requirements.txt
to install dependencies - API Rate Limits: Some APIs have rate limits; implement appropriate delays if needed
- No Results: Check that your search parameters are valid and that transit data exists for your area
Debugging
Enable debug logging by setting environment variables:
export PYTHONPATH=.
export DEBUG=1
python server.py
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Author
Geetanshi Goel
- GitHub: @geetanshi
- LinkedIn: Geetanshi Goel
License
This project is open source. Please check the repository for license details.
Support
For issues and questions:
- Check the Troubleshooting section above
- Review the Transitland API documentation
- Check the Google Maps API documentation
- Open an issue in the project repository