IndianRailwaysMCP
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@IndianRailwaysMCPIs the 12951 Mumbai Rajdhani running on time today?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
π Table of Contents
π― Purpose & Philosophy
Indian Railways runs over 13,000 trains a day, but its data lives behind inconsistent HTML pages and rate-limited endpoints β making it painful for AI agents to answer a simple question like "is my train running late?"
Indian Railways MCP Server solves this by normalizing schedules, live status, PNR, fares, and seat data into a single, structured MCP interface that any AI assistant can call directly.
π No auth, no secrets β every data source is public; there's nothing to leak
π§© Layered architecture β server, client, and parser layers are independently testable and swappable
π TTL-aware caching β every tool call respects a data-freshness window instead of hammering upstream sites
β‘ Resilient by default β exponential-backoff retries absorb upstream flakiness so your agent doesn't crash mid-conversation
π Architecture
graph TD
Client["π₯οΈ MCP Client<br/>(Claude Desktop / Cursor / Continue.dev)"] -->|MCP Protocol Β· stdio| Server
subgraph Server["π Indian Railways MCP Server"]
direction TB
SL["π οΈ Server Layer<br/>Tool registration (10 tools)<br/>Pydantic input validation"]
CL["π Client Layer<br/>httpx session mgmt<br/>tenacity retry logic<br/>TTL response cache"]
PL["π Parser Layer<br/>BeautifulSoup HTML parsing<br/>Pydantic JSON parsing<br/>Regex extraction"]
SL --> CL --> PL
end
PL -->|HTTP/HTTPS| ERail[("ποΈ ERail.in<br/>Schedules Β· Live status<br/>PNR Β· Seats Β· Fares")]
PL -->|HTTP/HTTPS| IRInfo[("ποΈ IndianRailways.info<br/>Coach position<br/>Platform locator")]Data flow: MCP client sends a tool call over stdio β Server layer validates input with Pydantic β Client layer issues an HTTP request with retry logic β Parser layer extracts structured data from HTML/JSON β Cache layer stores the result with a TTL β response is formatted and returned to the client.
β¨ Features
Module | Capability | Real-Time | Cache TTL |
π Station & Train Search | Search 8,000+ stations and 10,000+ trains by name or code | β | 24 hours |
π Train Schedule | Complete route with all stations, timings, and distances | β | 1 hour |
π Live Running Status | Real-time location, delays, and platform info | β | 2 minutes |
π« PNR Status | Passenger details, coach/berth allocation, journey info | β | 30 seconds |
πΊ Seat Availability | Class-wise availability β AVAILABLE / RAC / WL | β | 2 minutes |
π° Fare Enquiry | Fare breakdown across all travel classes | β | 1 hour |
π Trains Between Stations | Every train connecting two stations | β | 1 hour |
π’ Station Live | Upcoming departures from any station | β | 2 minutes |
π Coach Position | Coach layout at any station platform | β | 1 hour |
π§° Tech Stack
Layer | Technology |
Runtime | Python 3.10+ |
Protocol | Model Context Protocol (MCP) SDK 1.0+ |
HTTP Client | httpx |
HTML Parsing | BeautifulSoup4 |
Validation | Pydantic 2.0+ |
Retry Logic | tenacity (exponential backoff) |
Testing | pytest, pytest-cov, pytest-mock, pytest-asyncio |
Packaging | pyproject.toml (pip-installable) |
Containerization | Docker ( |
Process Management | systemd (Linux server deployments) |
π Quick Start
Prerequisites
Tool | Version | Notes |
Python | 3.10+ | Check with |
pip | Latest | Ships with Python |
An MCP client | Any | Claude Desktop, Cursor, or Continue.dev |
Step 1 β Clone
git clone https://github.com/Shadhai/Railway_mcp.git
cd Railway_mcpStep 2 β Configure
# Create and activate a virtual environment (recommended)
python -m venv .venv
source .venv/bin/activate # Linux/Mac
# .venv\Scripts\activate # Windows
# Install dependencies
pip install mcp httpx beautifulsoup4 pydantic tenacityStep 3 β Run
# Run directly
python -m src.indian_railways_mcp.server
# Or install as a package and run the entry point
pip install -e .
indian-railways-mcpβ Success β expect this output:
β
Available tools: 10
- search_stations: Search Indian Railways stations by name or code...
- search_trains: Search Indian Railways trains by number or name...
- get_train_schedule: Get complete train schedule with all stations...
...βοΈ Environment Configuration
No credentials are required β every upstream source is publicly accessible. The only environment variable in use configures the Python import path:
# ββ Runtime βββββββββββββββββββββββββββββββββββββββββββββ
PYTHONPATH=/path/to/Railway_mcp/src
# <!-- VERIFY: add PORT/NODE_ENV-style vars here only if you front this
# server with a custom HTTP/SSE transport wrapper. Stdio transport
# (the default) needs nothing beyond PYTHONPATH. -->π MCP Tool Reference
This server communicates over the MCP stdio protocol, not a public REST API β tools are invoked by your AI client, not by HTTP requests you make yourself. Each tool maps to one or more upstream data-source calls.
Discovery Tools
Tool | Description | Auth |
| Find station code(s) by name, with fuzzy/case-insensitive matching | β |
| Find train number(s) by name, with fuzzy/case-insensitive matching | β |
| List all trains connecting two stations | β |
Schedule & Status Tools
Tool | Description | Auth |
| Full route: every station, arrival/departure time, distance | β |
| Real-time location, delay minutes, last station | β |
| Upcoming departures at a given station | β |
Booking & Fare Tools
Tool | Description | Auth |
| PNR status, passenger list, coach/berth, confirmation state | β |
| Class-wise seat status (AVAILABLE / RAC / WL) | β |
| Fare breakdown by class | β |
Platform Tools
Tool | Description | Auth |
| Coach layout at a specific platform | β |
| Locate which platform a train arrives at | β |
π See
docs/API_REFERENCE.mdin the repo for full parameter schemas.
π Data Sources
ERail.in (Primary)
Endpoint | Method | Format | Cache TTL |
|
| JS/JSON array | 24 hours |
|
| JS/JSON array | 24 hours |
|
| HTML table | 1 hour |
|
| HTML | 2 minutes |
|
| JSON | 30 seconds |
|
| HTML table | 2 minutes |
|
| HTML table | 1 hour |
|
| HTML table | 1 hour |
|
| HTML table | 2 minutes |
IndianRailways.info (Secondary)
Endpoint | Method | Format | Cache TTL |
|
| HTML table | 1 hour |
|
| HTML | 1 hour |
β± Caching Strategy
Data Type | TTL | Reason |
Station List | 24 hours | Rarely changes |
Train List | 24 hours | Rarely changes |
Train Schedule | 1 hour | Occasional updates |
Live Status | 2 minutes | Real-time data |
PNR Status | 30 seconds | Real-time data |
Seat Availability | 2 minutes | Frequent updates |
π§ Use Cases
πΊοΈ AI Travel Planning Assistant
A chatbot built on Claude Desktop uses this server to plan an end-to-end journey β searching trains between two cities, checking live seat availability, pulling the fare, and confirming the schedule, all from one natural-language conversation.
π Live Train Tracker for Commuters
A commuter-facing IVR or WhatsApp bot polls get_live_status every few minutes to tell passengers exactly how delayed their train is and which station it last passed.
π« PNR Concierge Bot
A support bot integrated with check_pnr answers "is my ticket confirmed?" instantly, including per-passenger coach, berth, and waitlist position β without a human agent.
π Academic / Portfolio Project
A student building an MCP-based AI agent uses this repo as a reference implementation of a layered, cached, retry-safe scraping architecture behind the Model Context Protocol.
π‘ Usage Examples
Complete journey planning
from indian_railways_mcp.client import IndianRailwaysClient
client = IndianRailwaysClient()
trains = client.get_trains_between("NDLS", "BCT")
train = trains['trains'][0]
seats = client.check_seat_availability(
train['train_number'], "NDLS", "BCT", "20-Jul-2026"
)
if any(c['status'] == 'AVAILABLE' for c in seats['classes']):
fare = client.get_fare(train['train_number'], "NDLS", "BCT")
print(f"Fare: βΉ{fare['classes'][0]['total_fare']}")
schedule = client.get_train_schedule(train['train_number'])
print(f"Travel time: {schedule['travel_time']} hours")Live train tracking
status = client.get_live_status("04815")
if status['status'] == 'RUNNING':
print(f"{status['train_name']} last seen at {status['last_station']}, "
f"delayed {status['delay_minutes']} min")PNR status check
pnr = client.check_pnr("4553137968")
for p in pnr['passengers']:
print(f"Passenger {p['serial']}: {p['current_status']} | "
f"Coach {p['coach']} | Berth {p['berth']} ({p['berth_type']})")π Project Structure
Railway_mcp/
βββ π README.md # Main documentation
βββ π pyproject.toml # Package configuration
βββ π LICENSE # MIT License
βββ π .gitignore # Git ignore rules
βββ π docs/
β βββ API_REFERENCE.md # Complete tool/API documentation
β βββ ARCHITECTURE.md # System architecture
β βββ EXAMPLES.md # Usage examples
βββ π src/
β βββ π indian_railways_mcp/
β βββ __init__.py # Package init
β βββ server.py # MCP server (10 tools)
β βββ client.py # HTTP client (all endpoints)
β βββ parsers.py # HTML/JSON parsers
β βββ models.py # Pydantic data models
β βββ utils.py # Caching + retry utilities
βββ π tests/
βββ test_client.py # Client tests
βββ test_parsers.py # Parser testsπ Client Integrations
Edit your config file:
Mac:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"indian-railways": {
"command": "python",
"args": ["-m", "src.indian_railways_mcp.server"],
"cwd": "/path/to/Railway_mcp",
"env": { "PYTHONPATH": "/path/to/Railway_mcp/src" }
}
}
}Restart Claude Desktop β you'll see a π icon with the Indian Railways tools listed.
Add to ~/.cursor/mcp.json:
{
"mcpServers": {
"indian-railways": {
"command": "python",
"args": ["-m", "src.indian_railways_mcp.server"],
"cwd": "/path/to/Railway_mcp"
}
}
}Add to ~/.continue/config.json:
{
"experimental": {
"modelContextProtocolServers": [
{
"transport": {
"type": "stdio",
"command": "python",
"args": ["-m", "src.indian_railways_mcp.server"],
"cwd": "/path/to/Railway_mcp"
}
}
]
}
}npx @modelcontextprotocol/inspector python -m src.indian_railways_mcp.serverπ³ Docker Deployment
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY src/ ./src/
ENV PYTHONPATH=/app
CMD ["python", "-m", "src.indian_railways_mcp.server"]# Build
docker build -t indian-railways-mcp .
# Run (stdio requires interactive mode)
docker run -i indian-railways-mcp/etc/systemd/system/indian-railways-mcp.service:
[Unit]
Description=Indian Railways MCP Server
After=network.target
[Service]
Type=simple
User=mcp
WorkingDirectory=/opt/indian-railways-mcp
Environment=PYTHONPATH=/opt/indian-railways-mcp/src
ExecStart=/usr/bin/python3 -m src.indian_railways_mcp.server
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable indian-railways-mcp
sudo systemctl start indian-railways-mcp
sudo systemctl status indian-railways-mcpπ§ͺ Testing
# Install test dependencies
pip install pytest pytest-cov pytest-mock pytest-asyncio
# Run all tests
pytest tests/ -v
# Run with coverage
pytest tests/ -v --cov=src/indian_railways_mcp --cov-report=html
# Run a specific file / class / test
pytest tests/test_client.py -v
pytest tests/test_client.py::TestPNRStatus -v
pytest tests/test_client.py::TestPNRStatus::test_check_pnr_success -vCoverage summary
Module | Tests | Coverage |
| 40+ | ~95% |
| 25+ | ~95% |
| 10+ | ~90% |
| 5+ | ~85% |
Total | 80+ | ~92% |
π Performance
Response times (typical)
Operation | Cold (ms) | Cached (ms) |
Search Stations | 800 | 5 |
Search Trains | 1000 | 5 |
Train Schedule | 1500 | 100 |
Live Status | 2000 | 200 |
PNR Status | 1200 | 50 |
Seat Availability | 2000 | 100 |
Memory footprint: ~50MB base (Python + deps) Β· ~65MB with station/train cache warm Β· ~80MB peak during HTML parsing.
π Security Notes
No authentication required β every data source is public
Rate-limit safe β built-in exponential backoff prevents abusive request patterns
Validated inputs β all tool arguments pass through Pydantic models
No persistence β PNR and passenger data are never written to disk
HTTPS only β every outbound request is encrypted
π§ Troubleshooting
Symptom | Likely Cause | Fix |
|
|
|
| Missing execute bit |
|
Server silently exits | Docker missing | Always run with |
Dependencies missing | Fresh clone, no install |
|
| Wrong or malformed train number | Verify it's a 5-digit number via |
| Train doesn't run that day | Check the train's days of operation |
| Invalid station code | Run |
| Upstream network issue | Handled automatically β 3x retry with exponential backoff |
| Upstream site changed its HTML structure | Requires a manual parser update in |
| Too many requests in a short window | Backs off automatically; avoid tight polling loops |
πΊ Roadmap
Core tool set β station/train search, schedule, live status
PNR status, seat availability, and fare enquiry tools
TTL-based caching layer with retry/backoff
Docker + systemd deployment paths
80+ test suite with ~92% coverage
π§ Streamable HTTP/SSE transport for remote (non-stdio) deployments
π§ Multi-language station/train name matching (Hindi, regional scripts)
π§ Webhook/push alerts for delay and platform changes
π§ Official
llms.txt-based tool discovery for broader agent frameworks
π€ Contributing
# 1. Fork the repository
# 2. Clone your fork
git clone https://github.com/YOUR_USERNAME/Railway_mcp.git
cd Railway_mcp
# 3. Create a feature branch
git checkout -b feature/your-feature-name
# 4. Make your changes and add tests
pytest tests/ -v
# 5. Commit and push
git commit -m "Add: your feature description"
git push origin feature/your-feature-name
# 6. Open a Pull Request against mainPlease keep parser changes covered by tests in tests/test_parsers.py β upstream HTML structure changes are the most common source of regressions in this project.
π₯ Contributors
β Star History
π€ AI-Ready Files
This repo ships with agent-discovery stubs so AI coding assistants (and MCP-aware crawlers) can understand the project without parsing the full README:
llms.txtβ machine-readable project summary for LLM toolsAGENTS.mdβ instructions for coding agents working in this repo
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Read and update your Everway trips and itineraries from any MCP-compatible AI assistant.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yoβ¦
TravelMind: 8 MCP tools for travel (12306 trains, flights, hotels, geocode, planning, policy).
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Shadhai/Railway_mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server