# Comunidad de Madrid MCP

> The Comunidad de Madrid Open Data Portal MCP lets your agent search and query official regional public records. Need to analyze air quality data or track public transport schedules? Connect it once, then use natural language to find datasets, inspect metadata, and pull content directly from the regional datastore.

## Overview
- **Category:** knowledge-management
- **Price:** Free
- **Tags:** madrid, open-data, ckan, spain, public-records

## Description

This connector bridges your AI client to the Community of Madrid's open data portal. You gain access to a massive repository covering everything from health records and environmental reports to economic indicators and transportation logistics. Instead of clicking through complex government websites or downloading dozens of spreadsheets, you talk to your agent. It handles the search logic for you. Your agent can find specific datasets by keyword—like 'salud' or 'transporte'—then pull the full metadata to show you exactly what's available. Even better, you don't have to download files manually; the data store allows direct querying of actual content, letting your AI client analyze the numbers right where they sit. When connected through Vinkius, you get immediate access to this whole catalog, making regional analysis simple conversation.

## Tools

### get_dataset
Retrieves the complete technical details and scope for one specific dataset ID.

### get_resource
Gets metadata for a specific file or resource attached to a dataset (e.g., CSV, PDF).

### list_datasets
Lists the identifiers of every available dataset in the portal.

### search_datasets
Filters and searches for datasets based on specific keywords or criteria you provide.

### search_datastore
Runs a direct query against the actual content of a dataset to pull raw data points.

## Prompt Examples

**Prompt:** 
```
Search for datasets related to air quality in Madrid.
```

**Response:** 
```
I found several datasets. The most relevant is 'Calidad del aire: datos diarios' (ID: calidad_aire_datos_dia). Would you like to see its metadata or available resources?
```

**Prompt:** 
```
List all dataset identifiers available in the portal.
```

**Response:** 
```
Fetching the list of datasets... There are over 500 datasets available. Some examples include 'centros_salud', 'transporte_publico_lineas', and 'presupuestos_municipales'.
```

**Prompt:** 
```
Get the metadata for the dataset 'calidad_aire_datos_dia'.
```

**Response:** 
```
The dataset 'Calidad del aire: datos diarios' is managed by the Environment department. It contains 12 resources (CSV and Excel files) and is updated daily. Would you like the ID of the latest CSV resource?
```

## Capabilities

### Find available datasets
List every dataset identifier currently indexed in the entire public portal.

### Search for specific data topics
Filter and find relevant datasets using keywords related to a topic, like 'medio ambiente' or 'economía'.

### Get dataset details
Retrieve the full metadata, including owners and update schedules, for one specific dataset.

### Inspect individual files
Check the metadata for a particular resource within a dataset, such as an attached CSV or PDF file.

### Query live data content
Run direct queries against the raw numbers inside a dataset's content store without needing to download anything.

## Use Cases

### Comparing air quality over time
A researcher needs to compare historical pollution levels across different districts. Instead of visiting several municipal sites, they ask their agent to find all environment-related data sources and use `search_datasets` to narrow it down. Then they run targeted queries using `search_datastore` for the specific time ranges needed.

### Modeling public transport changes
An urban planner needs to know if new train lines correlate with demographic shifts. They first use `list_datasets` to map out available infrastructure data, then use `get_dataset` on the relevant transit dataset to confirm its scope before querying it for specific line identifiers.

### Building a local health dashboard
A developer needs real-time metrics on healthcare resource availability. They ask their agent to find all 'health' related datasets, confirming the IDs with `get_dataset`, and then use `search_datastore` repeatedly to build a structured data output for an application.

### Drafting a policy brief
A consultant needs recent economic indicators. They ask their agent to search using keywords like 'economía' or 'presupuesto', letting `search_datasets` filter the results, and then use `get_resource` on the most promising dataset to confirm if it contains the required file type (like a yearly PDF).

## Benefits

- Stop manual downloads. Instead of downloading CSVs and struggling with headers, you use `search_datastore` to query the actual data content directly, letting your agent pull clean figures into your report.
- Know exactly what's available. Use `list_datasets` first to see all dataset identifiers in the portal before committing to a search, giving you a full scope of regional information.
- Quickly find relevant sources. If you know the general topic—say, 'salud'—you use `search_datasets` to narrow down thousands of records instantly, skipping weeks of manual browsing.
- Get deep metadata without hassle. Once you identify a dataset ID using `get_dataset`, your agent pulls all the technical details (like update frequency and owner) in one step.
- Better integration means less effort. By connecting this MCP through Vinkius, you get access to Madrid's full open data catalog from every compatible client, no matter where you code.

## How It Works

The bottom line is, you tell your AI client what regional data you need, and it handles the complex search and retrieval process for you.

1. Subscribe to this MCP and optionally provide your Comunidad de Madrid API Key for better rate limits.
2. Tell your agent what you need; for example, 'Find all datasets about air quality' or 'Query the latest transport schedules.'
3. Your agent uses the appropriate tool—like `search_datasets` or `search_datastore`—to pull the information directly into the conversation window.

## Frequently Asked Questions

**How do I find all possible datasets using list_datasets?**
You simply ask your agent to run `list_datasets`. This tool fetches every single dataset identifier the portal holds, giving you a master checklist of available regional data categories.

**Can I query raw numbers without downloading anything using search_datastore?**
Yes. That's exactly what `search_datastore` does. Instead of manually grabbing and cleaning the figures from a CSV, you tell your agent which data points you need, and it pulls the numbers directly into your chat window.

**What is the difference between search_datasets and get_dataset?**
`search_datasets` finds potential datasets based on keywords. `get_dataset` requires a precise ID and returns the full, detailed metadata for that specific dataset only.

**Do I need to know the resource type before using get_resource?**
You don't. You just tell your agent which dataset you are looking at, and it uses `get_resource` to check metadata for specific file types—like confirming a PDF or CSV exists.

**What happens if I hit rate limits when using `search_datasets`?**
The system will throw a rate limit error. To increase your query capacity, you can subscribe to the MCP and optionally input your Comunidad de Madrid CKAN API Key. This key significantly raises your allowable request volume.

**When I use `get_dataset`, what specific details does the full metadata provide?**
The metadata gives you more than just a name; it lists tags, the owning organization, and how often the data updates. This helps you determine if the dataset is current or if it covers the scope you need.

**For `get_resource`, do I need the full identifier for the file?**
Yes, pinpoint accuracy matters here. You must provide the specific resource ID and its associated dataset context. This ensures your agent retrieves the exact CSV or JSON file you're looking for.

**I want to analyze data from several sources; should I use `list_datasets` first?**
No, listing every identifier is too much work. Instead, start by using `search_datasets` with keywords like 'transporte'. Once you find the right dataset ID, use `search_datastore` to query its content directly.

**How can I find datasets about a specific topic like 'transport'?**
Use the `search_datasets` tool with the query 'transporte'. The agent will return a list of matching datasets with their unique IDs and descriptions from the portal.

**Can I see the actual content of a data file without downloading it?**
Yes. If the resource is stored in the CKAN DataStore, you can use the `search_datastore` tool with the Resource ID to query the rows and columns directly.

**Is an API key mandatory to use this server?**
No, it is optional. However, providing a `CKAN_API_KEY` allows for higher rate limits and access to restricted datasets if your account has permissions.