# MAPA (Agricultura) MCP

> MAPA (Agricultura) MCP Server connects your AI agent directly to Brazil's Ministry of Agriculture open data. It lets you search, inspect, and retrieve thousands of official datasets covering agribusiness topics like agrotoxics, rural credit, and livestock records using tools like `search_packages` and `get_resource`.

## Overview
- **Category:** government-public-data
- **Price:** Free
- **Tags:** open-data, agribusiness, public-records, dataset-discovery, brazil-data

## Description

Your AI client uses the `search_packages` tool to find specific dataset packages across Brazil's Ministry of Agriculture data instantly by supplying keywords or filters like an organization name. You can run `list_packages` for a basic inventory list, or you might use `list_tags` to see every descriptive tag used throughout the entire portal, helping you narrow down your search criteria from the start.

When you need to map out exactly what data is available and where it comes from, you first run `list_groups`, which spits back a list of all high-level categories for the records. If you want to track who published the records, you'll use `list_organizations` to get names and IDs of every contributing department. You can then drill down using `get_organization` on any specific ID to pull detailed provenance information about that government source. The system also lets you check which data groups are involved by running `list_groups`, letting you categorize the scope before you even look at a package.

To understand what's inside a dataset container, you run `get_package` using a known package ID; this pulls all the metadata for an entire collection, telling you its full scope and update history. If you know which department published it, but don’t want to list every single group or organization, you can use `search_packages` with a filter that targets the source itself. You'll find data packaged under various names; if you run `list_packages`, you get the basic IDs needed for further inspection.

If you know exactly what file type you need—say, a CSV or an XLS sheet—you don't have to guess. You use `get_resource` on an individual resource ID within a package to fetch its metadata and direct download link. This tool confirms the file format and gives you the exact means to pull down the data itself. The ability to cross-reference everything is key: if you find a promising dataset through searching, you can immediately run `get_package` to validate its contents before using `get_resource` on any of the underlying files it contains.

You never have to guess what's available; running `search_packages` allows you to filter thousands of records by keyword or organization name. If your initial search is broad, you can always run `list_organizations` and then use `get_organization` on a specific result to validate the source department. Once you identify a package ID via `list_packages`, running `get_package` provides the complete metadata profile, letting you confirm things like data coverage area or last update date. To nail down the actual file download, remember that after getting the package details, you must run `get_resource` to get the specific link and format information for that file.

This server connects your agent directly to the raw structure of Brazilian governmental data. You'll use `list_groups` to map high-level categories, then potentially `list_organizations` to see all contributing entities; you can always follow up with `get_organization` if you want deep details on one source. If a search term is vague, running `search_packages` helps narrow it down using keywords or filters like 'agrofit.' Once you've found the right dataset container, use `list_packages` to get its ID, then feed that into `get_package` for the full metadata report. For every single file inside that package, you run `get_resource` to grab the download details and format confirmation. You can check what descriptive tags are applied everywhere by running `list_tags`, which provides a complete list of classification terms across all records.

## Tools

### get_organization
Retrieves detailed information about a single, specific publishing organization within MAPA.

### get_package
Pulls all metadata for an entire dataset package (the container holding the data). 

### get_resource
Gets metadata and download details for a single file or resource inside a package.

### list_groups
Returns a list of all high-level data groups (categories) used by MAPA.

### list_organizations
Outputs a comprehensive list of every organization that contributes data to the portal.

### list_packages
Lists the names and IDs of all available datasets (the packages) in the system.

### search_packages
Searches for dataset packages using keywords or filters (e.g., searching by 'agrofit' or an organization name).

### list_tags
Provides a list of all descriptive tags applied across different MAPA datasets.

## Prompt Examples

**Prompt:** 
```
Search for datasets related to 'Agrofit' in the MAPA portal.
```

**Response:** 
```
I found several datasets related to Agrofit. The main one is 'agrofit-sistema-de-agrotoxicos-fitossanitarios' (ID: 120593). Would you like to see the metadata or the available resources for this package?
```

**Prompt:** 
```
List all organizations responsible for agricultural data.
```

**Response:** 
```
I've retrieved the list of organizations. There are 12 entities, including 'Secretaria de Defesa Agropecuária (SDA)' and 'Secretaria de Política Agrícola (SPA)'. Which one would you like to explore?
```

**Prompt:** 
```
Get the metadata for the dataset 'registro-de-agrotoxicos'.
```

**Response:** 
```
Fetching metadata for 'registro-de-agrotoxicos'... This dataset is maintained by SDA and was last updated on 2023-10-15. It contains 3 resources (CSV, PDF, and XLS). Should I provide the download links?
```

## Capabilities

### Search for datasets
Run `search_packages` to find specific dataset packages by keyword or filter across all MAPA data.

### List and categorize sources
Use `list_organizations`, `get_organization`, or `list_groups` to map out which government departments published the records and how they are categorized.

### Examine dataset details
Run `get_package` on a known package ID to pull complete metadata, including data scope and update history.

### Identify specific files
Use `get_resource` to fetch the metadata for an individual file (like a CSV or XLS) within a dataset package.

## Use Cases

### Analyzing Pesticide Records
An analyst needs all data on agrotoxics. They start by running `search_packages` using 'agrotoxicos'. The result points to the main package ID, which they then pass into `get_package` to confirm the dataset's scope and resource availability.

### Mapping Data Ownership
A researcher wants to know all entities involved in livestock data. They use `list_organizations` to see every potential source, then run `get_organization` on specific names like 'SDA' to understand their publishing mandate.

### Finding a Specific File
The team knows the dataset package ID but needs only the CSV for 2023. They skip listing everything and go straight to `get_resource` with the package and file name, getting the direct download link immediately.

### Broad Sector Exploration
A new team member has no idea what data exists. They first run `list_tags`, which gives them a broad view of available concepts (like 'financing' or 'climate'), guiding their next search with `search_packages`.

## Benefits

- Pinpoint the data you need. Instead of sifting through thousands of links, run `search_packages` to find specific topics like 'Agrofit' or 'Rural Credit' immediately.
- Validate data sources. Use `get_package` to inspect metadata and confirm when a dataset was last updated—essential for any policy-making report.
- Track data origin. Need to know who published the numbers? Run `list_organizations` first, then use `get_organization` to verify the source department's mandate.
- Streamline discovery. Use `list_tags` and `list_groups`. This helps you map out related information across different agricultural domains without needing deep domain knowledge.
- Get ready for analysis. Once you find a package, use `get_resource` to get the exact download URL and file format (CSV/XLS), skipping manual link hunting.

## How It Works

The bottom line is that you query official government records using specific tool calls, and your agent gets back structured JSON data ready to analyze.

1. Subscribe to this server and provide your API key (if required).
2. Instruct your AI client to use a discovery tool, like `search_packages` or `list_tags`, specifying the desired topic.
3. The server returns structured data—either a list of packages, metadata for a dataset, or a download URL.

## Frequently Asked Questions

**How do I find datasets on 'Agrofit'? (search_packages)**
Run `search_packages` with the query 'agrofit'. This tool searches across all available packages, giving you a list of IDs and names directly relevant to agrochemicals.

**Where do I find every department that publishes data? (list_organizations)**
Use `list_organizations`. It outputs the full roster of contributing bodies. After getting the list, you can use `get_organization` on any name to see their specific role and mandate.

**I need metadata for 'registro-de-agrotoxicos'. Which tool do I run? (get_package)**
You need `get_package`. Provide the package ID, and the server returns comprehensive details: who maintains it, when it was last updated, and what resources are available.

**How can I list all available data categories? (list_groups)**
Run `list_groups`. This tool gives you a high-level overview of the entire dataset structure by grouping related topics together for easy navigation.

**I found a dataset package; how do I use `get_resource` to check its actual file types?**
The `get_resource` tool pulls metadata for individual files within the package. It tells you the format (CSV, PDF, XLS) and provides direct download URLs before you even try to pull the data.

**If I know a specific department's name, how does `get_organization` help me get deeper details?**
`get_organization` pulls more than just the name. You retrieve specific details about that entity—like its full scope of work or primary focus area—which helps you understand data provenance.

**When I run `list_packages`, how can I find related topics across different groups?**
For cross-cutting classification, use the `list_tags` tool. Tags provide a secondary layer of indexing that lets you discover data related to a specific subject, even if it belongs to a different official group.

**If I run high-volume queries like `list_packages`, what should I watch out for regarding performance?**
For stability and large result sets, consider using your MAPA/CKAN API key. This helps manage rate limits and gives you better throughput when listing or searching massive datasets.

**How can I find datasets about a specific topic like 'coffee'?**
You can use the `search_packages` tool with the query 'café'. It will return all datasets that match the term in their title or description.

**How do I get the actual download link for a data file?**
First, use `get_package` to find the resource IDs within a dataset. Then, call `get_resource` with the specific ID to retrieve the download URL and file format.

**Can I see which government departments publish the data?**
Yes! Use the `list_organizations` tool to see all publishing entities. You can then use `get_organization` to see all datasets managed by a specific department.