Skip to main content
Glama
guilhermelirio

Brasil API MCP

ibge-municipalities-list

Retrieve a complete list of municipalities for any Brazilian state using its two-letter abbreviation. This tool provides structured municipal data from IBGE through the Brasil API MCP server.

Instructions

List all municipalities of a Brazilian state by its abbreviation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ufYesState abbreviation (e.g., SP, RJ)

Implementation Reference

  • Handler function that fetches municipalities list from Brasil API for given state 'uf', formats it (shows first 30 if more than 50), handles errors.
    async ({ uf }) => {
      console.error(`Listing municipalities for state: ${uf}`);
      
      const result = await getBrasilApiData(`/ibge/municipios/v1/${uf}`);
      
      if (!result.success) {
        return formatErrorResponse(`Error listing municipalities: ${result.message}`);
      }
      
      // Format the response data
      const municipalities = result.data;
      
      // If there are too many municipalities, limit the display
      let formattedText;
      if (municipalities.length > 50) {
        const first30 = municipalities.slice(0, 30).map((municipality: any) => 
          `${municipality.nome} (Code: ${municipality.codigo_ibge})`
        ).join("\n");
        
        formattedText = `Municipalities in ${uf} (showing first 30 of ${municipalities.length}):\n${first30}\n\n...and ${municipalities.length - 30} more municipalities.`;
      } else {
        const formattedMunicipalities = municipalities.map((municipality: any) => 
          `${municipality.nome} (Code: ${municipality.codigo_ibge})`
        ).join("\n");
        
        formattedText = `Municipalities in ${uf}:\n${formattedMunicipalities}`;
      }
      
      return {
        content: [{ 
          type: "text" as const, 
          text: formattedText
        }]
      };
    }
  • Zod schema defining the input parameter 'uf': state abbreviation (e.g., SP, RJ).
    {
      uf: z.string()
        .describe("State abbreviation (e.g., SP, RJ)")
    },
  • Registers the tool 'ibge-municipalities-list' on the MCP server with description, input schema, and handler function.
    server.tool(
      "ibge-municipalities-list",
      "List all municipalities of a Brazilian state by its abbreviation",
      {
        uf: z.string()
          .describe("State abbreviation (e.g., SP, RJ)")
      },
      async ({ uf }) => {
        console.error(`Listing municipalities for state: ${uf}`);
        
        const result = await getBrasilApiData(`/ibge/municipios/v1/${uf}`);
        
        if (!result.success) {
          return formatErrorResponse(`Error listing municipalities: ${result.message}`);
        }
        
        // Format the response data
        const municipalities = result.data;
        
        // If there are too many municipalities, limit the display
        let formattedText;
        if (municipalities.length > 50) {
          const first30 = municipalities.slice(0, 30).map((municipality: any) => 
            `${municipality.nome} (Code: ${municipality.codigo_ibge})`
          ).join("\n");
          
          formattedText = `Municipalities in ${uf} (showing first 30 of ${municipalities.length}):\n${first30}\n\n...and ${municipalities.length - 30} more municipalities.`;
        } else {
          const formattedMunicipalities = municipalities.map((municipality: any) => 
            `${municipality.nome} (Code: ${municipality.codigo_ibge})`
          ).join("\n");
          
          formattedText = `Municipalities in ${uf}:\n${formattedMunicipalities}`;
        }
        
        return {
          content: [{ 
            type: "text" as const, 
            text: formattedText
          }]
        };
      }
    );
  • src/index.ts:29-29 (registration)
    Top-level call to registerIbgeTools which includes the 'ibge-municipalities-list' tool.
    registerIbgeTools(server);
  • Utility to fetch data from Brasil API endpoints via axios, handles errors, used by the tool handler.
    export async function getBrasilApiData(endpoint: string, params: Record<string, any> = {}) {
      try {
        const url = `${BASE_URL}${endpoint}`;
        console.error(`Making request to: ${url}`);
        
        const response = await axios.get(url, { params });
        return { 
          data: response.data,
          success: true
        };
      } catch (error: any) {
        console.error(`Error in API request: ${error.message}`);
        
        // Handle API errors in a structured format
        if (error.response) {
          return {
            success: false,
            statusCode: error.response.status,
            message: error.response.data?.message || error.message,
            error: error.response.data
          };
        }
        
        return {
          success: false,
          message: error.message,
          error
        };
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('List') but lacks details on permissions, rate limits, pagination, or return format. This leaves significant gaps for a tool with no output schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words. It front-loads the core action and resource, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the output looks like (e.g., list format, fields included) or address potential behavioral aspects like error cases or data freshness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds minimal value beyond the input schema, which has 100% coverage. It implies the 'uf' parameter is a state abbreviation but doesn't provide additional context like valid examples beyond 'SP, RJ' or error handling. Baseline 3 is appropriate given the schema does most of the work.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('List') and resource ('municipalities of a Brazilian state'), making the purpose specific and understandable. It doesn't explicitly distinguish from sibling tools like 'ibge-state-search' or 'ibge-states-list', which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'ibge-state-search' or 'ibge-states-list', nor does it specify prerequisites such as needing the state abbreviation beforehand.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/guilhermelirio/brasil-api-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server