Provides geocoding services for location detection to automatically determine which Malaysian transit service area a location belongs to, with fallback to OpenStreetMap Nominatim.
Serves as a fallback geocoding service through Nominatim for location detection when Google Maps API is unavailable.
Malaysia Transit MCP
MCP (Model Context Protocol) server for Malaysia's public transit system, providing real-time bus and train information across 10+ cities in Malaysia.
MCP Endpoint: https://mcp.techmavie.digital/malaysiatransit/mcp
Analytics Dashboard: https://mcp.techmavie.digital/malaysiatransit/analytics/dashboard
Data Source: Malaysia Transit Middleware
Table of Contents
Features
11 Operational Service Areas + 1 Under Maintenance + 1 Coming Soon across Malaysia
Klang Valley (Rapid Rail KL, Rapid Bus KL, MRT Feeder)
Penang (Rapid Penang, Penang Ferry, KTM Komuter Utara)
Ipoh (BAS.MY Ipoh, KTM Komuter Utara)
Seremban (BAS.MY Seremban, KTM Intercity)
Kangar (BAS.MY Kangar, KTM Komuter Utara)
Alor Setar (BAS.MY Alor Setar, KTM Komuter Utara)
Kota Bharu (BAS.MY Kota Bharu, KTM Intercity)
Kuala Terengganu, Melaka, Johor, Kuching (BAS.MY only)
Kuantan (Under Maintenance)
Kota Kinabalu (Coming Soon)
Real-time Vehicle Tracking - Live positions of buses and trains
Stop Search & Information - Find stops by name or location
Route Discovery - Browse available routes with destinations
Arrival Predictions - Get real-time arrival times at stops (shape-based, 40-60% more accurate)
Schedule Information - Get departure times, route schedules, and operating status
Fare Calculator - Calculate bus fares for BAS.MY and Rapid Penang routes
Multi-Modal Support - Bus, rail, and ferry services
Provider Status Monitoring - Check operational status of transit providers
Location Detection - Automatically detect service areas using geocoding
š KTM Komuter Utara - 23 stations from Padang Besar to Ipoh with fare calculation
š KTM Intercity - SH and ERT routes (Tumpat - Gemas - JB Sentral)
š Penang Ferry - Butterworth to George Town ferry information
š API Analytics - View API usage statistics, endpoint metrics, and client tracking
š Analytics Dashboard - Visual dashboard with charts for MCP server usage monitoring
š Client Identification - MCP identifies itself to middleware for analytics tracking
š Auto-Deployment - GitHub Actions workflow for automatic VPS deployment
Architecture
This MCP server acts as a bridge between AI assistants and the Malaysia Transit Middleware API:
Client Identification: This MCP automatically sends an X-App-Name: Malaysia-Transit-MCP header with every API request, allowing the middleware to track usage from this MCP separately in its analytics dashboard.
Quick Start
Connect to the MCP Server
Add this configuration to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
Test with MCP Inspector
Test with curl
Installation
Configuration
Environment Variables
The MCP server uses environment variables for configuration:
MIDDLEWARE_URL(required): Malaysia Transit Middleware API URLDefault:
https://malaysiatransit.techmavie.digital
GOOGLE_MAPS_API_KEY(optional): Google Maps API key for location detectionIf not provided, falls back to Nominatim (free but less accurate)
Get your API key from Google Cloud Console
Development
To run the MCP server in development mode:
Build
To build the MCP server for deployment:
Available Tools
Service Area Discovery
list_service_areas
List all available transit areas in Malaysia.
Parameters: None
Returns: List of service areas with their IDs, names, and capabilities.
Example:
get_area_info
Get detailed information about a specific area.
Parameters:
areaId(string): Service area ID (e.g., "penang", "klang-valley")
Example:
Location Detection
detect_location_area ā
Automatically detect which transit service area a location belongs to using geocoding.
Parameters:
location(string): Location name or place (e.g., "KTM Alor Setar", "Komtar", "KLCC")
Returns: Detected area ID, confidence level, and location details.
Example:
Stop Information
search_stops
Search for stops by name. Use detect_location_area first if unsure about the area.
Parameters:
area(string): Service area IDquery(string): Search query (e.g., "Komtar", "KLCC")
Example:
get_stop_details
Get detailed information about a stop.
Parameters:
area(string): Service area IDstopId(string): Stop ID from search results
get_stop_arrivals ā
Get real-time arrival predictions at a stop.
Parameters:
area(string): Service area IDstopId(string): Stop ID from search results
Returns: Includes a comprehensive disclaimer about prediction methodology, followed by arrival data with:
Calculation method (shape-based or straight-line)
Confidence level (high, medium, or low)
ETA in minutes
Vehicle information
Prediction Methodology:
Shape-Based Distance (Preferred): Uses actual route geometry, accurate within ±2-4 minutes
Straight-Line Distance (Fallback): Conservative estimates with 1.4x multiplier
Includes GPS speed validation, time-of-day adjustments, and stop dwell time
Conservative bias: Better to arrive early than miss the bus
Example:
find_nearby_stops
Find stops near a location.
Parameters:
area(string): Service area IDlat(number): Latitude coordinatelon(number): Longitude coordinateradius(number, optional): Search radius in meters (default: 500)
Route Information
list_routes
List all routes in an area.
Parameters:
area(string): Service area ID
get_route_details
Get detailed route information.
Parameters:
area(string): Service area IDrouteId(string): Route ID from list_routes
get_route_geometry
Get route path for map visualization.
Parameters:
area(string): Service area IDrouteId(string): Route ID from list_routes
Real-time Data
get_live_vehicles ā
Get real-time vehicle positions.
Parameters:
area(string): Service area IDtype(enum, optional): Filter by type ('bus' or 'rail')
Example:
get_provider_status
Check provider operational status.
Parameters:
area(string): Service area ID
Schedule Information (NEW)
get_route_departures
Get the next N departures for a specific route (both directions).
Parameters:
area(string): Service area ID (e.g., "ipoh", "seremban", "penang")routeId(string): Route ID from list_routescount(number, optional): Number of departures to return (default: 5)
Example:
get_next_departure
Get the single next departure for a route in a specific direction.
Parameters:
area(string): Service area IDrouteId(string): Route ID from list_routesdirection(enum, optional): 'outbound', 'inbound', or 'loop'
get_stop_routes
Get all routes serving a specific stop with their next departures.
Parameters:
area(string): Service area IDstopId(string): Stop ID from search_stopscount(number, optional): Number of departures per route (default: 3)
get_route_schedule
Get the complete daily schedule for a route.
Parameters:
area(string): Service area IDrouteId(string): Route ID from list_routes
get_route_origin
Get the origin stop name for a route in a specific direction.
Parameters:
area(string): Service area IDrouteId(string): Route ID from list_routesdirection(enum, optional): 'outbound' or 'inbound'
get_route_status
Check if a route is currently operating based on its schedule.
Parameters:
area(string): Service area IDrouteId(string): Route ID from list_routes
Fare Calculator (NEW)
get_fare_routes
Get all routes available for fare calculation in a specific area.
Parameters:
area(string): Service area ID (e.g., "ipoh", "seremban", "penang", "kangar")
Supported Areas: BAS.MY areas (Ipoh, Seremban, Kangar, Alor Setar, Kota Bharu, Kuala Terengganu, Melaka, Johor, Kuching) and Rapid Penang.
get_route_stops_for_fare
Get all stops on a route with their distances for fare calculation.
Parameters:
area(string): Service area IDrouteId(string): Route ID from get_fare_routes
calculate_fare ā
Calculate the bus fare between two stops on a route.
Parameters:
area(string): Service area IDrouteId(string): Route ID from get_fare_routesfromStop(string): Origin stop IDtoStop(string): Destination stop ID
Returns: Adult, concession, and child fares in MYR with disclaimer.
Example:
calculate_journey_fare
Calculate the total fare for a multi-leg journey with bus transfers.
Parameters:
area(string): Base service area IDlegs(array): Array of journey legs (max 5), each with:routeId(string): Route ID for this legfromStop(string): Origin stop IDtoStop(string): Destination stop IDareaId(string, optional): Area ID for this leg (for inter-area journeys)
Note: Each bus change requires a separate fare payment (BAS.MY does not have integrated transfers).
get_route_directions_for_fare
Get available directions for a route when calculating fares.
Parameters:
area(string): Service area IDrouteId(string): Route ID from get_fare_routes
KTM Komuter Utara Tools (NEW)
get_ktm_komuter_stations
Get all 23 KTM Komuter Utara stations (Padang Besar - Butterworth - Ipoh line).
Parameters: None
Returns: Station codes, names, and coordinates.
Example:
calculate_ktm_komuter_fare ā
Calculate KTM Komuter Utara fare between two stations.
Parameters:
from(string): Origin station code (e.g., "BU" for Butterworth)to(string): Destination station code (e.g., "IP" for Ipoh)
Example:
get_ktm_komuter_fare_matrix
Get the full KTM Komuter Utara fare matrix showing fares between all station pairs.
Parameters: None
get_ktm_station_departures ā
Get departure times for a specific KTM station.
Parameters:
stationName(string): Station name (e.g., "Butterworth", "Ipoh")type(enum): Schedule type -ktm-komuter-utaraorktm-intercity
Example:
get_ktm_stations
Get all KTM stations for a specific schedule type.
Parameters:
type(enum):ktm-komuter-utaraorktm-intercity
get_ktm_schedules
Get full KTM schedule data for a specific schedule type.
Parameters:
type(enum):ktm-komuter-utaraorktm-intercity
find_nearby_ktm_stations
Find KTM stations near a specific location.
Parameters:
lat(number): Latitude coordinatelon(number): Longitude coordinateradius(number, optional): Search radius in kilometers (default: 10)type(enum):ktm-komuter-utaraorktm-intercity
Penang Ferry Tools (NEW)
get_penang_ferry_info ā
Get Penang Ferry fare information, schedule, terminals, and payment methods.
Parameters: None
Returns: Ferry fare, operating hours, terminal locations, and payment options.
Example:
System Tools
get_system_health
Check the health status of the Malaysia Transit middleware service.
Parameters: None
get_debug_info
Get comprehensive debug information about the middleware service.
Parameters: None
Analytics Tools (NEW)
get_api_analytics
Get API usage analytics and statistics from the middleware.
Parameters:
type(enum, optional): Type of analytics to retrieve:summary(default): Overview with requests/hour, error rate, uptimeendpoints: Per-endpoint statisticsareas: Per-service-area statisticscumulative: All-time totalsclients: App/website usage breakdown
Example:
get_area_analytics
Get detailed API usage analytics for a specific service area.
Parameters:
area(string): Service area ID (e.g., "penang", "klang-valley")
Example:
Testing
hello
Simple test tool to verify server is working.
Usage Examples
Find When Your Bus is Coming
Track Live Buses
Discover Routes
AI Integration Guide
Key Use Cases
1. "When is my bus coming?" ā
This is the PRIMARY use case. Users want to know when their next bus/train will arrive.
Workflow:
2. "Where is my bus right now?"
Users want to track their bus in real-time.
Workflow:
Tool Usage Patterns
Always Start with Location Detection
When a user mentions a location without specifying the area, use location detection:
Search Before Details
Always search for stops/routes before requesting details:
Response Formatting
Arrival Times
Format arrival times in a user-friendly way:
Multiple Arrivals
Present multiple arrivals clearly:
Error Handling
Provider Unavailable
Best Practices
Use location detection when users mention place names
Always specify area for every tool (except
list_service_areasanddetect_location_area)Search before details - don't guess IDs
Handle errors gracefully - providers may have temporary outages
Format responses clearly - use minutes, not timestamps
Don't cache real-time data - it updates every 30 seconds
Supported Service Areas
Area ID | Name | Providers | Transit Types | Fare Calculator |
| Klang Valley | Rapid Rail KL, Rapid Bus KL, MRT Feeder | Bus, Rail | ā |
| Penang | Rapid Penang, Penang Ferry, KTM Komuter Utara | Bus, Ferry, Rail | ā |
| Kuantan | Under Maintenance | Bus | ā |
| Ipoh | BAS.MY Ipoh, KTM Komuter Utara | Bus, Rail | ā |
| Seremban | BAS.MY Seremban, KTM Intercity | Bus, Rail | ā |
| Kangar | BAS.MY Kangar, KTM Komuter Utara | Bus, Rail | ā |
| Alor Setar | BAS.MY Alor Setar, KTM Komuter Utara | Bus, Rail | ā |
| Kota Bharu | BAS.MY Kota Bharu, KTM Intercity | Bus, Rail | ā |
| Kuala Terengganu | BAS.MY Kuala Terengganu | Bus | ā |
| Melaka | BAS.MY Melaka | Bus | ā |
| Johor Bahru | BAS.MY Johor Bahru | Bus | ā |
| Kuching | BAS.MY Kuching | Bus | ā |
| Kota Kinabalu | Coming Soon | - | ā |
KTM Services
Service | Route | Stations | Fare Calculator |
KTM Komuter Utara | Padang Besar ā Butterworth ā Ipoh | 23 stations | ā |
KTM Intercity (SH) | JB Sentral ā Gemas ā Tumpat | Multiple | ā (Coming Soon) |
KTM Intercity (ERT) | JB Sentral ā Gemas ā Tumpat | Multiple | ā (Coming Soon) |
Location to Area Mapping
The detect_location_area tool automatically maps common locations to service areas:
User Says | Area ID |
Ipoh, Bercham, Tanjung Rambutan, Medan Kidd |
|
Seremban, Nilai, Port Dickson |
|
George Town, Butterworth, Bayan Lepas, Penang Sentral |
|
KLCC, Shah Alam, Putrajaya |
|
Kuantan, Pekan, Bandar Indera Mahkota |
|
Kangar, Arau, Kuala Perlis, Padang Besar |
|
Alor Setar, Sungai Petani, Pendang, Jitra |
|
Kota Bharu, Rantau Panjang, Bachok, Machang, Jeli |
|
Kuala Terengganu, Merang, Marang, Setiu |
|
Melaka, Tampin, Jasin, Masjid Tanah |
|
Johor Bahru, Iskandar Puteri, Pasir Gudang, Kulai |
|
Kuching, Bau, Serian, Bako, Siniawan, Matang |
|
Deployment
Production Server
The MCP server is deployed at:
Endpoint:
https://mcp.techmavie.digital/malaysiatransit/mcpHealth Check:
https://mcp.techmavie.digital/malaysiatransit/healthAnalytics Dashboard:
https://mcp.techmavie.digital/malaysiatransit/analytics/dashboardAnalytics API:
https://mcp.techmavie.digital/malaysiatransit/analyticsTransport: Streamable HTTP
Analytics Dashboard
The MCP server includes a built-in analytics dashboard that tracks:
Total requests and tool calls
Tool usage distribution (doughnut chart)
Hourly request trends (last 24 hours)
Requests by endpoint (bar chart)
Top clients by user agent
Recent tool calls feed
The dashboard auto-refreshes every 30 seconds.
Self-Hosting
To deploy your own instance, see the deployment guide.
Auto-Deployment
This repository includes a GitHub Actions workflow for automatic VPS deployment. When you push to main, the server automatically redeploys.
To set up auto-deployment, add these secrets to your GitHub repository:
VPS_HOST- Your VPS IP addressVPS_USERNAME- SSH username (e.g.,root)VPS_PORT- SSH port (e.g.,22)VPS_SSH_KEY- Private SSH key for authentication
Troubleshooting
Connection Issues
If you can't connect to the middleware:
Verify your
MIDDLEWARE_URLis correctEnsure the middleware is running and accessible
Check network connectivity
Test middleware directly:
curl https://your-middleware-url/api/areas
No Data Returned
If tools return empty data:
Check if the service area is operational using
get_provider_statusVerify the area ID is correct using
list_service_areasCheck middleware logs for errors
Real-time Data Unavailable
Real-time data depends on the upstream GTFS providers:
Use
get_provider_statusto check provider healthSome providers may have temporary outages
Check the middleware logs for API issues
Location Detection Not Working
If location detection returns incorrect results:
Ensure
GOOGLE_MAPS_API_KEYis set in environment variablesCheck Google Cloud Console for API quota limits
Verify the API key has Geocoding API enabled
Falls back to Nominatim if Google Maps fails
Requirements
Node.js: >= 18.0.0
Malaysia Transit Middleware: Running instance (local or deployed)
Google Maps API Key: Optional, for enhanced location detection
Project Structure
Related Projects
Malaysia Open Data MCP - MCP for Malaysia's open data portal
Contributing
Contributions are welcome! Please feel free to submit pull requests or open issues.
License
MIT - See LICENSE file for details.
Acknowledgments
Malaysia Open Data Portal for GTFS data
Prasarana Malaysia for Rapid KL services
BAS.MY for regional bus services
Model Context Protocol for the MCP framework
Google Maps Platform for geocoding services
OpenStreetMap Nominatim for fallback geocoding
Made with ā¤ļø by Aliff