ibge-states-list
Retrieve comprehensive data about all Brazilian states, including names, codes, and regional information, for integration with Brazilian public data services.
Instructions
List all Brazilian states with their information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/ibge/index.ts:15-36 (handler)The main handler function for the 'ibge-states-list' tool. Fetches Brazilian states data from BrasilAPI, formats it as a newline-separated list with sigla, name, and region, and returns as text content or formatted 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)Registers the 'ibge-states-list' tool on the MCP server. Defines the tool name, description, empty input schema (no parameters), and attaches the handler 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/utils/api.ts:11-39 (helper)Shared helper function that performs API requests to BrasilAPI. Called by the handler with endpoint '/ibge/uf/v1' to retrieve the states list data.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 to format error responses consistently. Used by the handler if API call fails.export function formatErrorResponse(message: string) { return { content: [{ type: "text" as const, text: message }], isError: true }; }