# TCE-SP Audesp MCP

> TCE-SP (Audesp) provides direct programmatic access to public transparency data from the São Paulo State Court of Auditors. Use this server to query municipal expenses and revenues across any city in the state, filtered precisely by fiscal year and month.

## Overview
- **Category:** data-analytics
- **Price:** Free
- **Tags:** transparency, public-spending, fiscal-data, auditing, municipal-data, open-data

## Description

You're connecting your AI agent to the official São Paulo State Court of Auditors transparency portal using this MCP Server. This setup gives you programmatic access straight into municipal spending records (despesas) and revenue reports (receitas), letting you run structured queries without ever having to navigate a messy website or download a spreadsheet manually.

Your AI client handles all the heavy lifting; it's an API bridge that takes your parameters—the city, fiscal year, and month—and executes the lookup. It cuts out all the friction of manual data retrieval, letting you focus on what the numbers actually mean.

To get started, first you need to know which municipalities are even in scope. You'll use the `list_municipios` tool; this simply retrieves a full list of every single city currently tracked by TCE-SP. This call gives you the definitive roster of jurisdictions, ensuring you don't waste time querying a place that doesn't exist in their system.

Once you have your target municipality from that list, you can start pulling the actual financial data. If you need to see how much money was spent—the operational costs and spending records—you fire up `list_despesas`. You gotta specify three things for this: the city name (which you got from `list_municipios`), the exact fiscal year, and the specific month. This gives you a detailed breakdown of every expense recorded.

For tracking income, you use `list_receitas`. Like spending, you need to lock in the municipality, the fiscal year, and the month. This tool pulls all the collected funds and state transfers for that given period. You get a clear picture of how much money came into the system versus what left it.

This combination means you can compare spending and revenue directly across multiple cities without leaving your chat window. For example, you don't have to run three separate reports; you just tell your agent which months or years you want to check for expenses (`list_despesas`) and revenues (`list_receitas`), and it gets both sets of data points for the same parameters.

The server is designed for people who work with raw, public finance numbers. Researchers, journalists digging into local governance, and policy analysts rely on this because it cuts out the guesswork. You're not just looking at a number; you're getting structured records detailing *what* was spent and *where* the money came from.

When you use `list_despesas`, you get comprehensive operational cost data for one city, specific to one month and year. When you use `list_receitas`, you get total collected funds for that same city, month, and year. The whole process is about precision: finding the scope of available cities with `list_municipios` first, then drilling down into hyper-specific financial records using the other two tools. It keeps your workflow tight—no cross-referencing multiple government tabs or wrestling with CSV formats. You're querying a direct, stable stream of public data that lets you analyze spending and income across São Paulo's municipal landscape.

## Tools

### list_despesas
Lists detailed expense records (despesas) for a specified municipality, year, and month.

### list_municipios
Retrieves the unique list of all municipalities managed under TCE-SP jurisdiction.

### list_receitas
Lists total revenue records (receitas) for a specified municipality, year, and month.

## Prompt Examples

**Prompt:** 
```
List all municipalities available in the TCE-SP system.
```

**Response:** 
```
I've retrieved the list of municipalities. There are hundreds of cities available, including 'santos', 'campinas', and 'sao-bernardo-do-campo'. Which one would you like to analyze?
```

**Prompt:** 
```
Show me the expenses for the municipality of 'santos' in January 2023.
```

**Response:** 
```
Fetching expenses for Santos (01/2023)... I've found the detailed records. The data includes operational costs, personnel expenses, and investments made during that period.
```

**Prompt:** 
```
What were the revenues for 'campinas' in the year 2022, month 12?
```

**Response:** 
```
Querying revenues for Campinas (12/2022)... The report shows the total collection for the month, including tax revenues and state transfers.
```

## Capabilities

### List all available municipalities
Retrieves a full list of every municipality currently tracked by TCE-SP.

### Retrieve detailed municipal expenses
Fetches records of operational costs and spending for a specific city, fiscal year, and month.

### Track municipal revenue data
Accesses collected funds and state transfers for a given municipality, year, and month.

## Use Cases

### Investigating budget discrepancies in Campinas
A journalist needs to know if spending increased more than revenue did. They first use `list_municipios` to confirm 'campinas' slug, then call `list_receitas` and `list_despesas` for the same period (e.g., 2023/12). The agent returns both structured data sets, allowing the journalist to immediately write about the discrepancy.

### Tracking resource allocation in Santos
A policy analyst wants a year-over-year comparison of operational costs. They use `list_municipios` for 'santos', then call `list_despesas` for January 2023, and repeat the call for January 2022. The agent organizes two separate data outputs into one comparative report.

### Mapping state-wide spending patterns
A researcher needs to analyze how revenue shifted across three different cities over six months. They cycle through `list_municipios` for all targets, then loop the calls to `list_receitas`, ensuring consistent data collection without repeating setup code.

### Auditing a specific fiscal quarter
A public manager needs to check spending in 2021. They confirm the city slug, then run `list_despesas` three times—once for Q1, once for Q2, and once for Q3—to build an accurate quarterly spending picture.

## Benefits

- Access structured data immediately. Instead of downloading and cleaning raw CSV files from the official portal, you get clean JSON output directly via `list_despesas` or `list_receitas`.
- Build comprehensive comparisons quickly. Run sequential calls using `list_municipios` first, then use the resulting IDs to compare spending across 50 different cities in minutes.
- Analyze budget gaps programmatically. By running both `list_receitas` and `list_despesas` for the same city/month, you can immediately calculate variance without manual spreadsheet work.
- Audit historical records instantly. You don't need to remember which date range or portal link applies; just tell your agent the target month and year.
- Speed up research flow. The server handles all the complex API calls to TCE-SP, letting your AI client focus purely on analysis and reporting.

## How It Works

The bottom line is you use a three-step process: find the city ID, then call the data tool with that ID and date range.

1. First, call `list_municipios` to get the unique slug (ID) of the city you need data from.
2. Next, pass that city slug, along with the required fiscal year and month, to either `list_despesas` or `list_receitas`.
3. The server executes the query against the TCE-SP database and returns structured JSON containing the financial records.

## Frequently Asked Questions

**How do I get the full list of cities using TCE-SP Audesp?**
Use the `list_municipios` tool. This function returns a complete list of all available city slugs (IDs) under the São Paulo State Court of Auditors' jurisdiction.

**What data does list_despesas provide?**
`list_despesas` gives you detailed expense records for one specific municipality, year, and month. It tracks operational costs and spending breakdowns.

**Can I use TCE-SP Audesp to compare revenues across different years?**
Yes. You must call `list_municipios` first to get the slug, then run `list_receitas` multiple times for the same municipality but with different year/month parameters.

**Do I need an API key before using list_despesas?**
Yes. You must subscribe and provide your API access credentials or token to link your client (like Claude or Cursor) to the server.

**What should I do if the `list_despesas` tool returns an error code for a specific fiscal month?**
The system will return a clear HTTP status and an error message detailing the problem. This usually means the municipality slug or date range is invalid. Check your inputs—try adjacent months, or verify that the specified year/month combination actually contains recorded data.

**How does the server handle high volumes of requests when running multiple queries with `list_receitas`?**
The server enforces standard rate limits to prevent abuse. If you make too many calls in a short burst, your AI client will receive a 429 Too Many Requests error. You'll need to implement an exponential backoff strategy or batch your queries into fewer steps.

**Does `list_municipios` allow me to filter the search by specific regions within São Paulo State?**
No, the `list_municipios` tool returns a complete list of all slugs under TCE-SP jurisdiction. You must handle the filtering logic client-side—your AI agent processes the full list and selects only the slugs you want to use for subsequent calls.

**In what format does the server deliver the raw results after calling any tool, like `list_despesas`?**
All data is delivered in structured JSON format. Your AI client processes this standard JSON output directly. This makes it simple to pass the records into other tools or write them out for reporting.

**How do I find the correct name (slug) for a specific city?**
Use the `list_municipios` tool. It returns a complete list of all municipalities under TCE-SP jurisdiction with their respective slugs needed for expense and revenue queries.

**Can I query data for any year and month?**
Yes, using `list_despesas` or `list_receitas`, you can specify the `exercicio` (year) and `mes` (month, 1-12) to get precise historical data for a municipality.

**What is the difference between list_despesas and list_receitas?**
`list_despesas` focuses on how the municipality spent its budget (expenses), while `list_receitas` shows the income and collections (revenues) received by the city.