ibge-states-list
Retrieve comprehensive information about all Brazilian states, including details like names and codes, through integration with the Brasil API MCP server for access to Brazilian public data.
Instructions
List all Brazilian states with their information
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {},
"type": "object"
}
Implementation Reference
- src/tools/ibge/index.ts:15-36 (handler)Handler function that fetches Brazilian states list from BrasilAPI, formats it, and returns formatted text response or error.async () => { console.error("Listing all Brazilian states"); const result = await getBrasilApiData(`/ibge/uf/v1`); if (!result.success) { return formatErrorResponse(`Error listing states: ${result.message}`); } // Format the response data const states = result.data; const formattedStates = states.map((state: any) => `${state.sigla} - ${state.nome} (Region: ${state.regiao.nome})` ).join("\n"); return { content: [{ type: "text" as const, text: `Brazilian States:\n${formattedStates}` }] }; }
- src/tools/ibge/index.ts:11-37 (registration)Direct registration of the 'ibge-states-list' tool via server.tool call inside registerIbgeTools function.server.tool( "ibge-states-list", "List all Brazilian states with their information", {}, async () => { console.error("Listing all Brazilian states"); const result = await getBrasilApiData(`/ibge/uf/v1`); if (!result.success) { return formatErrorResponse(`Error listing states: ${result.message}`); } // Format the response data const states = result.data; const formattedStates = states.map((state: any) => `${state.sigla} - ${state.nome} (Region: ${state.regiao.nome})` ).join("\n"); return { content: [{ type: "text" as const, text: `Brazilian States:\n${formattedStates}` }] }; } );
- src/index.ts:29-29 (registration)Top-level call to registerIbgeTools which includes registration of 'ibge-states-list' tool.registerIbgeTools(server);
- src/utils/api.ts:11-40 (helper)Shared helper function used by the handler to fetch data from BrasilAPI endpoints.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 }; } }
- src/utils/api.ts:47-55 (helper)Shared helper function used by the handler to format error responses in MCP format.export function formatErrorResponse(message: string) { return { content: [{ type: "text" as const, text: message }], isError: true }; }