# EMT Madrid (Open Data) MCP

> EMT Madrid (Open Data) MCP connects your AI agent directly to real-time public transit data for Madrid. Check next bus arrivals at any stop, see which BiciMAD stations have bikes and docks available, or calculate a full trip route using the city's official bus network.

## Overview
- **Category:** government-public-data
- **Price:** Free
- **Tags:** public-transport, real-time-data, bus-arrivals, bike-sharing, urban-mobility, open-data

## Description

Need to get around Madrid? Instead of juggling multiple apps—one for buses, one for bike sharing, another for maps—your agent handles it all. This connection gives your AI client direct access to Madrid’s official mobility data. You can ask your agent simple questions like, “What bus should I take from here?” or “Are there any available bikes near Puerta del Sol?” The system pulls live information on everything: the precise arrival time of Line 19 at a specific stop, or how many docks are free at the nearest BiciMAD station. All this data is managed through Vinkius, allowing you to connect your preferred AI client and treat Madrid's entire transit network as one unified tool set.

## Tools

### list_bicimad_stations
Provides a complete listing of all BiciMAD stations and their current bike/dock availability counts.

### get_bus_arrivals
Retrieves the precise estimated arrival time for a specified bus line at an official stop.

### login
Authenticates the connection by logging into EMT MobilityLabs to generate an access token.

### plan_bus_route
Generates a step-by-step route calculation between two points using only the official bus network.

## Prompt Examples

**Prompt:** 
```
What are the bus arrival times for stop ID 72?
```

**Response:** 
```
I've checked stop 72. Line 19 is arriving in 3 minutes, and Line 51 is estimated in 8 minutes. Would you like to check another stop?
```

**Prompt:** 
```
List all BiciMAD stations and their current bike availability.
```

**Response:** 
```
Fetching BiciMAD status... I found 600+ stations. For example, Station 'Puerta del Sol' has 12 bikes available and 15 free docks. Do you have a specific area in mind?
```

**Prompt:** 
```
Plan a bus route starting from stop 1022.
```

**Response:** 
```
Calculating routes from stop 1022... You can take Line 27 towards Plaza de Castilla. The next departure is in 5 minutes. Where is your final destination?
```

## Capabilities

### Calculate a complete bus trip
Determines the best path between two points using the full EMT bus network.

### Check real-time bus arrivals
Provides exact minutes until the next scheduled bus reaches a specific stop ID.

### Map bike sharing status
Lists every BiciMAD station and reports its current count of available bikes and empty docks.

### Authenticate API access
Securely processes the necessary credentials to activate all other data tools.

## Use Cases

### A traveler needs to get from their hotel to a museum across town.
The user asks, 'How do I get to the Prado Museum?' The agent runs `plan_bus_route`, suggests taking Line 27, and tells them exactly where to board. This saves minutes of research and walking.

### A commuter is waiting at a major transfer hub.
The user asks, 'When does the next bus come?' The agent uses `get_bus_arrivals` by stop ID 1022. It reports that Line 51 arrives in 3 minutes and Line 19 is estimated for 8 minutes.

### An event organizer needs to check transport options for attendees.
The agent runs `list_bicimad_stations` across the area. It reports that while one station is full, a nearby location has 15 free docks and 12 bikes ready.

### A developer needs to build a custom dashboard for city services.
They use the MCP's structured tools to pull continuous real-time data streams from `get_bus_arrivals` and combine it with route planning outputs into one unified feed.

## Benefits

- You stop switching between different city apps. Your agent checks live arrivals using `get_bus_arrivals` without you opening multiple browser tabs.
- Get a complete picture of local movement. Use the listing tool to check all BiciMAD stations and their status in one go, knowing exactly where bikes are available.
- Stop guessing your travel time. The MCP calculates full itineraries using `plan_bus_route`, giving you the best path from start point to destination.
- It's official data. This connector uses the same live feeds that local apps rely on, guaranteeing accurate information for critical mobility workflows.
- The process is clean: You just ask your agent a question; it handles the necessary `login` and executes the right tool in sequence.

## How It Works

The bottom line is that after initial setup, querying Madrid’s transport data happens through natural conversation, not manual API calls.

1. First, subscribe to this MCP and provide your EMT MobilityLabs API key.
2. Next, your agent uses the `login` tool to secure an access token with the official system.
3. Finally, you ask your AI client a question—for example, asking for bus arrivals or planning a route—and the agent executes the appropriate tool.

## Frequently Asked Questions

**How do I check bus arrivals using get_bus_arrivals?**
You must provide a specific stop ID. Just give your agent the unique stop number and the line you want to track, and it tells you the minutes until arrival.

**What is the difference between plan_bus_route and get_bus_arrivals?**
`plan_bus_route` gives you a multi-step itinerary (Start -> Bus Line X -> End Point). `get_bus_arrivals` only tells you when the next bus arrives at one single spot.

**Can I check bike availability with list_bicimad_stations?**
Yes. This tool lists all BiciMAD stations and reports exactly how many bikes are available for use, along with empty docks.

**Do I need to run the login tool first?**
Yes. The agent needs to successfully complete the `login` process to get an access token before it can query any real-time data like bus or bike status.

**If I use `get_bus_arrivals` and the stop ID is invalid, what should my agent expect?**
The tool returns a standardized error code or an empty dataset. Your AI client can read this structured output to tell the user that the specific Stop ID wasn't found, instead of just crashing.

**When I call `list_bicimad_stations`, is there a way to filter results by neighborhood?**
The tool fetches all station data. You must apply geographical filtering yourself using the latitude and longitude coordinates provided in the output, since the MCP itself doesn't support location parameters.

**For `plan_bus_route`, do I need precise numeric stop IDs, or can I use descriptive names?**
The best results come from using the unique Stop ID. While some stops might be known by name, supplying the official number ensures accurate route calculation and avoids ambiguity.

**What should happen if my agent makes too many requests to `plan_bus_route` quickly?**
The underlying EMT API enforces rate limits. If you hit the limit, your AI client will receive a 429 error code. You'll need to build a retry loop with backoff logic into your application.

**How do I check when the next bus arrives at a specific stop?**
You can use the `get_bus_arrivals` tool by providing the unique Stop ID. The agent will return real-time estimates for all lines serving that stop.

**Can I see the availability of BiciMAD electric bikes?**
Yes! The `list_bicimad_stations` tool provides a complete list of all stations in Madrid, including the number of available bikes and free docks at each location.

**Does this server require a login to access the data?**
The server uses the `login` tool internally or via your API key to authenticate with EMT MobilityLabs, ensuring you have a valid session to fetch real-time transport data.