# Ayuntamiento de Barcelona MCP

> The Ayuntamiento de Barcelona MCP lets you talk to the Open Data BCN portal and pull structured data from city records. You can search for specific datasets, inspect metadata, or run complex SQL queries against resources like transportation maps or environmental statistics. Stop downloading CSVs; just ask your agent what you need.

## Overview
- **Category:** data-analytics
- **Price:** Free
- **Tags:** open-data, urban-planning, public-statistics, ckan-api, city-data, data-discovery

## Description

The Barcelona open-source data repository contains massive amounts of municipal information—everything from traffic accident reports to local market records. This MCP connects directly to that source, letting you turn natural conversation into structured data results. Instead of navigating the BCN website and figuring out which file is right, your AI client handles it all. You can ask for specific metrics or compare different datasets using simple language commands. Because this connection is hosted on Vinkius, you connect once from any compatible agent—Claude, Cursor, Windsurf, etc.—and gain immediate access to this entire catalog of Barcelona’s public data.

It's about getting answers fast. You don't need a background in SQL or API calls; you just need to know what question you're asking the city.

## Tools

### bcn_current_packages
Lists available datasets, including details on their resources and file formats.

### bcn_datastore_search_sql
Executes complex SQL queries directly against a data resource, allowing advanced data calculations.

### bcn_datastore_search
Filters existing records within a specific CSV resource using simple search criteria.

### bcn_package_list
Retrieves an exhaustive list of all dataset names in the Open Data BCN catalogue for general discovery.

### bcn_package_search
Searches the catalog to find datasets that match specific keywords or criteria you provide.

### bcn_package_show
Gets detailed metadata for a single dataset, showing its full scope and purpose.

### bcn_resource_show
Retrieves specific details about a data resource, including download links and format specifications.

## Prompt Examples

**Prompt:** 
```
List the first 10 datasets available in the Barcelona Open Data catalogue.
```

**Response:** 
```
I've retrieved the first 10 datasets. They include 'arbrat-zona' (Tree zones), 'estacions-meteorologiques' (Weather stations), and 'mercats-municipals' (Municipal markets). Would you like to see the resources for any of these?
```

**Prompt:** 
```
Search for datasets about 'wifi' in Barcelona and show their descriptions.
```

**Response:** 
```
I found 3 datasets related to 'wifi'. The main one is 'punts-wifi', which contains the locations of all public WiFi hotspots in the city. It includes resources in CSV, JSON, and KML formats.
```

**Prompt:** 
```
Run a SQL query to get the count of records in resource '2023-accidents-gu-bcn'.
```

**Response:** 
```
The SQL query `SELECT count(*) from "2023-accidents-gu-bcn"` returned a total of 8,452 records for traffic accidents in 2023. Would you like to filter these by district?
```

## Capabilities

### Search for available datasets
Find and list entire datasets by name, topic, or keyword using simple search commands.

### Get dataset details
Retrieve full metadata on a specific data package to understand its structure and update frequency.

### Filter records in CSV files
Search through the rows of existing resources using filters, like specifying 'only records from 2023'.

### Run complex SQL queries
Execute full SQL commands directly against a data resource to calculate metrics or count specific record types.

### List all associated resources
See every file type and download link connected to a dataset, including their format specifications.

## Use Cases

### Comparing historical traffic data
A researcher needs to compare accident records from 2021 versus 2023. Instead of downloading two separate CSVs, they ask their agent to run a specific `bcn_datastore_search_sql` query that selects and aggregates the count for both years simultaneously.

### Finding all local WiFi hotspots
An urban planner needs to know every public WiFi resource location. They use `bcn_package_search` with 'wifi' to locate the primary dataset, then follow up by using `bcn_resource_show` to confirm its format and download link.

### Validating a data source before coding
A developer needs to know if an existing city resource contains latitude and longitude fields. They run `bcn_package_show` first, checking the metadata structure before writing code that relies on specific columns.

### Getting a list of all available data categories
A new analyst joins the project and needs to know what's even available. They simply run `bcn_package_list` to get an immediate, comprehensive inventory of every dataset name.

## Benefits

- Stop downloading massive files just to get a count. Use `bcn_datastore_search_sql` to calculate totals or averages directly within your agent, saving hours of spreadsheet work.
- When you need to find the right data source, start with `bcn_package_search`. It narrows down thousands of city records based on keywords like 'environment' or 'transportation'.
- Need to validate if a dataset is current? Use `bcn_resource_show` to check metadata and update frequency before relying on the numbers.
- The MCP handles complex discovery. You can use `bcn_package_list` for a full inventory, then follow up with `bcn_package_show` to get deep technical specs.
- It’s faster than manual API calls. Your agent structures the query using tools like `bcn_datastore_search`, so you just focus on the question.

## How It Works

The bottom line is that you talk to the data like talking to a human analyst; your agent translates that into API calls automatically.

1. Subscribe to this MCP and provide your Open Data BCN API Token (optional for basic public queries).
2. Tell your agent exactly what data you need—for example, 'Find all datasets related to tree zones.'
3. The MCP uses the necessary tools to query Barcelona’s repository and returns a precise list of records or data points.

## Frequently Asked Questions

**How do I find datasets related to environmental records using bcn_package_search?**
You simply ask your agent to search for 'environment' or 'air quality'. `bcn_package_search` will return all relevant dataset packages, which you can then inspect further with `bcn_package_show`.

**What should I use if I need to count records from a specific CSV resource?**
You must run the `bcn_datastore_search_sql` tool. This allows you to execute SQL commands like `SELECT COUNT(*) FROM "resource_id"`, giving you an accurate tally.

**Is there a way to see all available data packages at once?**
Yes, run the `bcn_package_list` tool. It pulls a comprehensive list of every dataset name in the Open Data BCN catalog so you can start your research.

**I want to know what fields are available for a specific resource.**
Use `bcn_resource_show`. This tool provides detailed metadata, confirming the exact format and structure of any given data file before you attempt to query it.

**What is the proper process for handling rate limits when I use bcn_datastore_search?**
You need to manage your API token and be mindful of usage volume. If you hit a limit, your agent will receive an authentication error. For high-volume work, ensure you are using a dedicated API token with increased rate limits configured in the BCN portal.

**If I use bcn_package_show, how do I discover all available resources linked to that dataset?**
The `bcn_package_show` tool provides detailed metadata on the package itself. However, for a complete list of every associated file and its format specifications, you should also check the output from bcn_current_packages.

**When do I use bcn_datastore_search versus bcn_datastore_search_sql?**
Use `bcn_datastore_search` for simple, filtered searches within a resource using common criteria. Reserve `bcn_datastore_search_sql` when you need the power of full SQL syntax to join data or perform complex calculations across columns.

**How does bcn_package_show help me understand the scope and structure of a dataset before I query it?**
Running `bcn_package_show` gives you all the necessary metadata, including update frequencies and descriptions. This helps confirm if the data provided by the city matches your research needs before attempting any complex queries.

**Can I perform SQL queries on Barcelona's public datasets?**
Yes, you can use the `bcn_datastore_search_sql` tool to execute SELECT statements directly against any resource that is stored in the portal's datastore.

**How do I find datasets related to a specific topic like 'transport'?**
Use the `bcn_package_search` tool with the query parameter `q` set to your topic. You can also limit the number of results for faster browsing.

**Is it possible to see the actual rows of a CSV file without downloading it?**
Absolutely. The `bcn_datastore_search` tool allows you to query and preview the contents of a resource directly, including filtering and sorting options.