Pune Transit & Commute MCP Server
Integrates with OpenStreetMap Nominatim API for geocoding, resolving Pune landmarks and addresses within a bounded viewbox to provide coordinates for transit trip planning.
Click on "Deploy 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., "@Pune Transit & Commute MCP ServerBest way from Pimpri to Hinjewadi Phase 3 at 8:30 AM?"
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.
π Pune Transit & Commute MCP Server
An enterprise-grade Model Context Protocol (MCP) server and full-featured interactive web application providing ground-truth transit intelligence for the Pune & Pimpri-Chinchwad Metropolitan Region.
It integrates PMPML bus schedules (GTFS), the complete Pune Metro network (Maha-Metro Purple & Aqua lines), intelligent geocoding, multi-modal trip planning, and tenant-isolated personal place bookmarks into an AI-ready context layer for LLMs like Claude, ChatGPT, and custom AI agents.
π Table of Contents
Related MCP server: Magic Lane MCP Server
π Overview & Problem Statement
Commuting across Pune and Pimpri-Chinchwad presents unique challenges:
High road traffic congestion between key IT corridors (Hinjewadi, Magarpatta, Kharadi, Yerwada).
Mixed transit options across PMPML city buses, Pune Metro (Line 1 Purple, Line 2 Aqua), suburban rail, and walking legs.
Large Language Models (LLMs) frequently hallucinate bus route numbers, stop sequences, operational hours, and transit fares when answering without tool augmentation.
The Pune Transit MCP Server eliminates hallucination by giving LLMs real-time tool calls and grounded knowledge primitives backed by:
SQLite GTFS database with spatial bounding-box indexing.
Official Maha-Metro network data with station graph, transfer hubs (Civil Court), and tiered fare logic.
Hybrid Geocoding: Offline Pune landmark alias dictionary + OpenStreetMap Nominatim with viewbox restriction.
Tenant Isolation: Multi-user saved place preferences (
home,office,gym) backed by secure authentication.
π How MCP Works in this Project
The Model Context Protocol (MCP) is an open standard that allows AI assistants (such as Claude Desktop, IDE extensions, or agent workflows) to securely discover and execute tools, read structured resources, and use system prompts exposed by local or remote servers.
sequenceDiagram
autonumber
actor User
participant LLM as Claude Desktop / AI Client
participant MCP as Pune Transit MCP Server (Python)
participant Engine as Transit Services & SQLite Engine
participant Metro as Metro JSON & OpenStreetMap
User->>LLM: "Best way from Pimpri to Hinjewadi Phase 3 leaving at 8:30 AM?"
Note over LLM: Model recognizes transit intent & inspects MCP tools
LLM->>MCP: call_tool("plan_trip", {origin: "Pimpri", destination: "Hinjewadi Phase 3", depart_at: "08:30"})
MCP->>Engine: resolve_place() & query SQLite GTFS schedules
Engine->>Metro: check metro connections & walking distances
Metro-->>Engine: itineraries calculated & ranked
Engine-->>MCP: Structured itinerary JSON (legs, transfers, durations, fares)
MCP-->>LLM: Return ToolResult JSON with provenance & timestamp
LLM-->>User: Answers with concrete bus routes (e.g., Route 348), exact timings, stop names, and fare!Key Protocol Highlights:
Dual Transport Support:
Stdio (
src.server): Direct process pipes with strict JSON-RPC communication onstdin/stdout. All logs safely piped tostderrto avoid JSON protocol corruption.Streamable HTTP (
src.http_server): Mounted at/mcpover HTTP/HTTPS with Bearer Token validation and tenant separation.
Self-Correcting Structured Errors: When a user inputs an ambiguous location like "Hinjewadi", the server does not guess. It responds with an
AMBIGUOUS_PLACEerror with candidates (Phase 1, Phase 2, Phase 3), enabling Claude to prompt the user for clarification.
ποΈ System Architecture
High-Level Architecture Diagram
graph TB
subgraph Clients["Clients & Consumers"]
CD["Claude Desktop (Stdio)"]
Browser["Modern Web UI (Browser)"]
Agent["Autonomous AI Agent (HTTP /mcp)"]
end
subgraph TransportLayer["Transport & Security Layer"]
STDIO["Stdio JSON-RPC Handler"]
HTTP["Starlette / Uvicorn ASGI Server"]
AUTH["Bearer Auth & Tenant Resolver<br/>(secrets.compare_digest)"]
CORS["CORS Middleware"]
end
subgraph MCPLayer["MCP Protocol Engine (mcp SDK)"]
TOOLS["Tools Registry (8 Tools)<br/>β’ plan_trip β’ resolve_place<br/>β’ next_departures β’ metro_info<br/>β’ find_nearby_stops β’ find_routes_between<br/>β’ save_place β’ list_saved_places"]
RES["Resources (4 URI Schemes)<br/>β’ transit://pune/routes<br/>β’ transit://pune/stops/{id}<br/>β’ transit://pune/metro<br/>β’ transit://user/places"]
PROMPTS["Prompts Engine<br/>β’ morning_commute<br/>β’ explore_area"]
end
subgraph ServiceLayer["Domain Services Layer"]
P_SRV["Place Resolution Service (places.py)"]
S_SRV["Nearby Stops Service (stops.py)"]
D_SRV["Departures Engine (departures.py)"]
TR_SRV["Multi-Modal Trip Planner (planner.py)"]
M_ADAPT["Metro Adapter (metro_adapter.py)"]
end
subgraph DataLayer["Data & Persistence Layer"]
SQLITE[("SQLite Database<br/>pune_transit.db<br/>β’ Stops β’ Routes β’ Trips<br/>β’ StopTimes β’ Calendar β’ SavedPlaces")]
METRO_JSON["Maha-Metro Graph<br/>(data/metro.json)"]
PLACES_JSON["Curated Landmarks Cache<br/>(data/pune_places.json)"]
OSM["OpenStreetMap Nominatim API<br/>(Pune Viewbox Bounded)"]
end
CD --> STDIO
Agent --> AUTH --> HTTP
Browser --> CORS --> HTTP
STDIO --> MCPLayer
HTTP --> MCPLayer
HTTP -->|REST API /api/...| ServiceLayer
MCPLayer --> ServiceLayer
P_SRV --> PLACES_JSON
P_SRV --> OSM
P_SRV --> SQLITE
S_SRV --> SQLITE
D_SRV --> SQLITE
TR_SRV --> SQLITE
TR_SRV --> M_ADAPT
M_ADAPT --> METRO_JSONDetailed Request & Execution Flow
flowchart TD
A[Client Request] --> B{Entrypoint}
B -->|Command Line / Claude App| C[Stdio Server: src.server]
B -->|Browser / Remote Agent| D[ASGI HTTP Server: src.http_server]
D --> E{Route Matched?}
E -->|/api/*| F[Direct REST Handlers]
E -->|/mcp| G[MCP Auth Verification]
E -->|/| H[Static Frontend HTML/CSS/JS]
G -->|Valid Token| I[Streamable MCP Endpoint]
G -->|Invalid Token| J[401 Unauthorized JSON]
C --> K[MCP Server Instance]
I --> K
K --> L[Input Validation via Pydantic]
L -->|Valid| M[Dispatch to Service Layer]
L -->|Invalid| N[Return Structured INVALID_INPUT Error]
M --> O[Haversine Math + SQL Range Queries]
O --> P[Build Response Payload + Provenance Metadata]
P --> Q[Return to Client]π Core Functionalities & Features
1. Multi-Modal Trip Planning
Direct Bus Trips: Identifies non-stop PMPML bus services between origin and destination stops.
One-Transfer Bus Connections: Discovers optimal transfer junctions (e.g., Swargate, Shivajinagar, Manapa Bhavan) with sensible layover buffers (5β45 minutes).
Metro Trips: Computes metro routes including transfers at Civil Court (interchange between Purple and Aqua lines).
Walking Legs: Computes walking segments between origin/destination coordinates and transit stops using Haversine distance.
Road Comparison: Estimates cab/auto road travel times and fares for clear comparison against public transit.
2. Next Departures & Timetable Intelligence
Seconds-from-Midnight Indexing: Handles after-midnight transit trips (e.g.
24:15:00or25:30:00) seamlessly without datetime wrapping errors.Calendar & Service Day Filtering: Evaluates active day schedules (
MondayβSunday) against GTFScalendar.txtand exceptions incalendar_dates.txt.Real-Time Context: Returns up to N upcoming departures sorted by departure time with destination names and route codes.
3. Pune Metro Engine
Complete Lines Modeled:
π£ Purple Line (Line 1): PCMC $\leftrightarrow$ Swargate (14 stations).
π· Aqua Line (Line 2): Vanaz $\leftrightarrow$ Ramwadi (16 stations).
Interchange Logic: Multi-level routing through Civil Court Hub.
Official Fares: Matches Maha-Metro fare slabs: βΉ10, βΉ15, βΉ20, βΉ25, βΉ30, βΉ35.
Timings: Accurately respects operational timings (06:00 to 22:00 IST), peak frequencies (every 7 mins), and off-peak frequencies (every 12 mins).
4. Stop Discovery & Spatial Geocoding
Fast Spatial Bounding Box: Uses latitude/longitude bounding-box pre-filtering in SQLite followed by exact spherical Haversine calculations.
Landmark Aliasing: Curated support for aliases like "Manapa", "Station", "Deccan", "COEP", "Symbiosis", "Balewadi Stadium", and "Hinjewadi Phase 1/2/3".
OSM Nominatim Fallback: Fallback geocoding with strict Pune geographic bounding box (
viewbox=73.65,18.75,74.05,18.40) to prevent resolving to namesakes in other cities.
5. Personalized Saved Places
Store named locations such as
home,office,gym, orcollege.Persisted in SQLite with tenant isolation per user/token.
Seamlessly used as origins and destinations in trip planning prompts.
6. Interactive Web Application
Complete responsive frontend available at
http://localhost:8000/.Features interactive tabs:
πΊοΈ Trip Planner: Multi-modal itinerary generator with step-by-step instructions.
π Nearby Stops: Radius-based search with direct distance badges.
π Live Departures: Filter departures by stop and route.
π Metro Guide: Station list, first/last train timings, and fare calculator.
π Saved Places: Local bookmark management.
βοΈ MCP Diagnostics: Real-time status badge and server health monitor.
π οΈ MCP Specification Details
MCP Tools (8 Tools)
Tool Name | Parameters | Returns | Description |
|
|
| Resolves Pune location names with ambiguity detection. |
|
|
| Discovers transit stops within walking distance. |
|
|
| Upcoming departures in IST with schedule metadata. |
|
|
| Direct routes serving both stops in travel order. |
|
|
| Stations, timings, and fare computation between stations. |
|
|
| Ranked multi-modal door-to-door itineraries. |
|
|
| Saves user favorite locations in SQLite database. |
| None |
| Lists user's saved places. |
MCP Resources (4 Resources)
Resource URI | MIME Type | Description |
|
| Catalog of all active public bus routes in Pune. |
|
| Stop profile containing location, wheelchair accessibility, and serving routes. |
|
| Full Pune Metro network specification, line stations, and fare rules. |
|
| Current user's saved favorite commute destinations. |
MCP Prompts (2 Prompts)
Prompt Name | Arguments | Description |
|
| Instructs the LLM to inspect saved places, calculate transit itineraries, compare with road traffic, and provide an actionable recommendation. |
|
| Instructs the LLM to analyze public transit connectivity for any Pune neighborhood. |
π REST API Endpoints
The web frontend and external apps can communicate directly via the REST API:
Method | Endpoint | Query / Body Params | Description |
|
|
| Resolve place to lat/lng coordinates |
|
|
| Find stops near coordinates |
|
|
| Get scheduled departures |
|
|
| Door-to-door itinerary planning |
|
|
| Metro stations, timings, and fares |
|
|
| Manage user saved places |
|
| None | Health check status ( |
π» Installation & Quickstart
1. Clone & Set Up Virtual Environment
git clone https://github.com/shreyashhiray16/MCP-.git
cd MCP-
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
.\venv\Scripts\activate
# On Linux/macOS:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt2. Ingest GTFS Transit Data
Populate the local SQLite transit database with Pune stops, routes, trips, and schedules:
python scripts/ingest_gtfs.py3. Run the Server
Option A: Standard Port 8000
npm start
# or: python -m src.http_serverOption B: Custom Port (e.g., 8720)
# Windows PowerShell:
$env:PORT=8720; npm start
# Linux/macOS:
PORT=8720 npm startOpen your browser to: http://localhost:8000/ (or your selected port).
π€ Connecting with Claude Desktop
Configure Claude Desktop to use Pune Transit MCP directly:
Open Claude Desktop's configuration file:
Windows:
%APPDATA%\Claude\claude_desktop_config.jsonmacOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Add the server entry:
{
"mcpServers": {
"pune-transit": {
"command": "python",
"args": [
"-m",
"src.server"
],
"cwd": "C:/Users/YOUR_USERNAME/Downloads/mcp projecty"
}
}
}Restart Claude Desktop. You will see transit tools appear with hammer icons!
Sample Questions to Ask Claude:
"Which bus stops are within walking distance of Pimpri Railway Station?"
"When is the next bus departing from Shivajinagar towards Hinjewadi?"
"What is the Pune Metro fare and travel time from Vanaz to Ramwadi?"
"Save Hinjewadi Phase 2 as my office, and plan the best route from Swargate at 8:45 AM."
π Inspecting with MCP Inspector
Debug and execute all tools in the browser using the official MCP Inspector:
npx @modelcontextprotocol/inspector python -m src.serverThis starts an interactive developer GUI where you can inspect schema definitions, execute tool calls, test resource URIs, and evaluate prompts in real-time.
π³ Production & Docker Deployment
Build and run using Docker:
# Build Docker image
docker build -t pune-transit-mcp .
# Run container
docker run -d -p 8000:8000 -e PORT=8000 --name pune-transit pune-transit-mcpπ§ͺ Testing & Quality Assurance
The codebase includes an extensive automated test suite covering unit, integration, and contract tests:
# Run full test suite
python -m pytest -v
# Or via npm shortcut
npm testTest Coverage Highlights:
β Geocoding & Disambiguation: Landmark lookups, candidate generation, OSM fallbacks.
β Nearby Stops: Spatial bounding box queries, Haversine distance accuracy.
β Departures Engine: IST calendar validation, post-midnight trips, route filters.
β Metro Adapter: Station lookup, fare calculations across Civil Court transfer.
β Multi-Modal Planner: Bus, metro, and walking itinerary generation and ranking.
β MCP Protocol Compliance: Tools, resources, and prompt invocation via MCP SDK.
β REST API Tests: HTTP status codes, JSON responses, error formats.
π Directory Structure
pune-transit-mcp/
βββ .env.example # Sample environment variables configuration
βββ .gitignore # Git exclusions (venv, databases, caches)
βββ Dockerfile # Container build recipe
βββ LICENSE # MIT License
βββ package.json # npm scripts for running and testing
βββ README.md # Comprehensive project documentation
βββ requirements.txt # Python dependencies (mcp, starlette, uvicorn, httpx, etc.)
βββ data/
β βββ metro.json # Curated Pune Metro lines, stations, and fare rules
β βββ pune_places.json # Curated landmarks and aliases for instant resolution
β βββ pune_transit.db # SQLite database with indexed transit tables
β βββ gtfs/ # Raw GTFS feed CSV files
βββ docs/
β βββ data-sources.md # Data lineage, licenses, and catalog
β βββ decisions.md # Architecture Decision Records (ADRs)
β βββ learning-log.md # Implementation notes and learnings
βββ frontend/ # Interactive Web UI
β βββ index.html # Modern dashboard layout
β βββ style.css # Premium CSS design system
β βββ app.js # Frontend logic & API client
βββ scripts/
β βββ ingest_gtfs.py # Seed GTFS generation and SQLite loader
βββ src/
β βββ __init__.py
β βββ config.py # Central environment and configuration settings
β βββ http_server.py # Unified Starlette ASGI server (Web UI + REST + /mcp)
β βββ server.py # Core MCP Server instance and stdio entrypoint
β βββ adapters/
β β βββ geocoding.py # Hybrid local + OSM Nominatim geocoding
β β βββ http_client.py # Resilient HTTP client with retry logic
β β βββ metro_adapter.py # Maha-Metro operational and fare engine
β βββ db/
β β βββ connection.py # SQLite connection manager with thread safety
β β βββ repository.py # SQL queries for stops, routes, departures, places
β βββ prompts/
β β βββ transit_prompts.py # MCP Prompts (morning_commute, explore_area)
β βββ resources/
β β βββ transit_resources.py# MCP Resources (transit://...)
β βββ services/
β β βββ departures.py # Timetable departure calculations
β β βββ places.py # Landmark resolution and user bookmarks
β β βββ planner.py # Multi-modal trip itinerary generation
β β βββ stops.py # Spatial stop discovery
β βββ tools/
β βββ transit_tools.py # MCP Tool handler registrations
βββ tests/
βββ test_api.py # REST API endpoint tests
βββ test_departures.py # Timetable departures tests
βββ test_mcp_server.py # MCP protocol contract tests
βββ test_metro.py # Metro fares and station tests
βββ test_model_behaviour.py # Model guidance and structured error tests
βββ test_places.py # Geocoding and places tests
βββ test_planner.py # Multi-modal trip planning tests
βββ test_stops.py # Nearby stops query testsπ License
This project is open-source under the terms of the MIT License.
Transit data rights remain with PMPML, Maha-Metro (Pune Metro Rail), and OpenStreetMap Contributors.
This server cannot be deployed
Maintenance
Related MCP Connectors
Mobility, geocoding and nearby urban services for AI agents.
- geoOAuthco.thinair
Geocoding, routing, isochrones, traffic, weather, and place search for AI agents. 19 MCP tools.
Routing, geocoding, places, matrix and map tools for location-aware AI workflows.
Grounded, multilingual travel data + a cited travel concierge. 12+ languages, deep India coverage.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to search for cabs, view prices, and book rides through the open Beckn Protocol by connecting to Beckn-compliant mobility providers like Namma Yatri and ONDC.-

Magic Lane MCP Serverofficial
AlicenseBqualityCmaintenanceEnables AI agents to become geospatially intelligent assistants with tools for location search, smart routing, round trip planning, reverse geocoding, isochrone analysis, route visualization, geofence management, and interactive map display.85 npm7Apache 2.0- AlicenseAqualityDmaintenanceEnables AI agents to perform geocoding, routing, nearby search, and other location-based tasks for Indian addresses using the Mappls (MapMyIndia) platform.1715 npm3MIT
- FlicenseNot gradedqualityCmaintenanceEnables AI assistants to access Bangkok transit routes, stops, schedules, live vehicle positions, and trip planning through natural language.-