Transitland-Transit-MCP-Server

geetanshi0205/Transitland-Transit-MCP-Server

3.2

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.

Tools
5
Resources
0
Prompts
0

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

  1. Clone or download the project

    git clone <repository-url>
    cd Transitland_Transit_MCP_Agent
    
  2. Install dependencies

    pip install -r requirements.txt
    
  3. 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
  1. Visit Transitland
  2. Sign up for an account
  3. Navigate to your dashboard to get your API key
  4. Add the key to your .env file
Google Maps API Key
  1. Go to the Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the following APIs:
    • Geocoding API
    • Maps JavaScript API (optional, for enhanced functionality)
  4. Create credentials (API Key)
  5. 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 coordinates
  • search_nearby_stops(latitude, longitude, radius, route_types, limit) - Find stops near coordinates
Transit Information
  • search_feeds(spec, search, limit) - Search GTFS feeds
  • get_feed_details(feed_id) - Get detailed feed information
  • search_operators(search, adm0_name, adm1_name, city_name, limit) - Find operators
  • search_agencies(search, agency_name, adm0_name, adm1_name, limit) - Find agencies
  • search_routes(search, route_type, operator_onestop_id, include_geometry, limit) - Find routes
  • search_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 location
  • get_stop_departures(stop_id, next, include_alerts, limit) - Get departure times
  • find_stops_and_departures(location_name, radius, max_stops) - Combined stop and departure search
  • get_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 route
  • get_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 rail
  • 1 - Subway, Metro
  • 2 - Rail
  • 3 - Bus
  • 4 - Ferry
  • 5 - Cable tram
  • 6 - Aerial lift, Gondola
  • 7 - 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

  1. Missing API Keys: Ensure your .env file exists and contains valid API keys
  2. Module Not Found: Run pip install -r requirements.txt to install dependencies
  3. API Rate Limits: Some APIs have rate limits; implement appropriate delays if needed
  4. 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

Author

Geetanshi Goel

License

This project is open source. Please check the repository for license details.

Support

For issues and questions:

  1. Check the Troubleshooting section above
  2. Review the Transitland API documentation
  3. Check the Google Maps API documentation
  4. Open an issue in the project repository