> ## Documentation Index
> Fetch the complete documentation index at: https://mtaapi.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# LIRR and Metro-North

> Get live Long Island Rail Road and Metro-North departures and service information.

The API provides static station and route information alongside live commuter rail trip updates, train locations, and service alerts.

## Prerequisites

* Install `mta-js` with `npm install mta-js`.
* Set `MTA_API_KEY` in your environment.
* Requires `mta-js` 2.4.0 or later.

**1. Explore stations and routes**

Each railroad has its own stops and routes endpoints:

```typescript theme={null}
import { MTA } from 'mta-js'

const mta = new MTA({ apiKey: process.env.MTA_API_KEY })
const lirrStops = await mta.lirr.stops()
const lirrRoutes = await mta.lirr.routes()
const metroNorthStops = await mta.metroNorth.stops()
const metroNorthRoutes = await mta.metroNorth.routes()

for (const stop of lirrStops) {
  console.log(`LIRR: ${stop.name} (${stop.id})`)
}

for (const route of lirrRoutes) {
  console.log(`LIRR: ${route.name} (${route.id})`)
}

for (const stop of metroNorthStops) {
  console.log(`Metro-North: ${stop.name} (${stop.id})`)
}

for (const route of metroNorthRoutes) {
  console.log(`Metro-North: ${route.name} (${route.id})`)
}
```

Use `/api/v1/lirr/routes/{route}/stops` or `/api/v1/metro-north/routes/{route}/stops` to list stations served by a route. The route segment accepts an ID or exact route name, such as `Babylon Branch`:

```typescript theme={null}
const lirrRouteStops = await mta.lirr.routeStops({ route: '1' })
const metroNorthRouteStops = await mta.metroNorth.routeStops({ route: 'Hudson' })

for (const stop of lirrRouteStops.stops) {
  console.log(`LIRR: ${stop.name}`)
}

for (const stop of metroNorthRouteStops.stops) {
  console.log(`Metro-North: ${stop.name}`)
}
```

**2. Get upcoming departures**

The `stop` parameter accepts a station ID, stop code, or exact station name, matched without case sensitivity. For example, use `Penn Station` for LIRR or `Grand Central` for Metro-North. You can also filter by `route` and set a `limit`.

```typescript theme={null}
const lirrDepartures = await mta.lirr.departures({
  stop: 'Penn Station',
  route: '1',
  limit: 5,
})

const metroNorthDepartures = await mta.metroNorth.departures({
  stop: 'Grand Central',
  limit: 5,
})

for (const departure of lirrDepartures) {
  console.log(`${departure.trainNumber ?? departure.route.name} — ${departure.destination ?? departure.direction} — ${departure.minutes} min`)
}

for (const departure of metroNorthDepartures) {
  console.log(`${departure.trainNumber ?? departure.route.name} — ${departure.destination ?? departure.direction} — ${departure.minutes} min`)
}
```

Each departure includes its `trainNumber`, `destination`, scheduled `time`, `minutes` until the event, and `delaySeconds` when available. The response also includes the route, station, direction, and peak/off-peak classification.

**3. Check train locations and alerts**

Vehicle locations can be filtered by route. Service alerts are available separately for both systems:

```typescript theme={null}
const lirrVehicles = await mta.lirr.vehicles({ route: '1' })
const lirrAlerts = await mta.lirr.alerts()
const metroNorthVehicles = await mta.metroNorth.vehicles()
const metroNorthAlerts = await mta.metroNorth.alerts()

for (const vehicle of lirrVehicles) {
  console.log(`LIRR ${vehicle.trainNumber ?? vehicle.route.name} — ${vehicle.lat}, ${vehicle.lon}`)
}

for (const alert of lirrAlerts) {
  console.log(`LIRR: ${alert.header ?? alert.id}`)
}

for (const vehicle of metroNorthVehicles) {
  console.log(`Metro-North ${vehicle.trainNumber ?? vehicle.route.name} — ${vehicle.lat}, ${vehicle.lon}`)
}

for (const alert of metroNorthAlerts) {
  console.log(`Metro-North: ${alert.header ?? alert.id}`)
}
```

**4. Use the MCP tools or shared stop catalog**

The read-only MCP tools are `get_lirr_departures`, `get_metro_north_departures`, and `list_commuter_rail_stops`.

LIRR and Metro-North stops and routes are also available in the shared endpoints. Add `modes=lirr,metro-north` to `/stops/near` and `/routes`; omitted modes continue to default to subway and bus.

```typescript theme={null}
const nearbyRailStops = await mta.stops.near({
  lat: 40.7506,
  lon: -73.9935,
  modes: ['lirr', 'metro-north'],
})

for (const stop of nearbyRailStops) {
  console.log(`${stop.mode}: ${stop.displayName} (${stop.distanceMeters} m)`)
}

const railRoutes = await mta.routes.list({ modes: ['lirr', 'metro-north'] })
for (const route of railRoutes) {
  console.log(`${route.mode}: ${route.longName ?? route.id}`)
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.