get_locations
Retrieve all available cities and locations in Portugal for accessing weather forecasts and meteorological data from IPMA.
Instructions
Listar todas as cidades/locais disponíveis para previsão
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:406-444 (handler)The handler function that fetches the list of locations from the IPMA API, groups them by district, and returns a formatted text response listing all available cities/locations.private async getLocations() { try { const response = await fetch(`${this.baseUrl}/distrits-islands.json`); const data = await response.json() as ApiResponse<Location>; let result = "📍 **Locais Disponíveis para Previsão**\n\n"; // Agrupar por distrito/região const groupedByDistrict: { [key: number]: Location[] } = {}; data.data.forEach((location: Location) => { if (!groupedByDistrict[location.idDistrito]) { groupedByDistrict[location.idDistrito] = []; } groupedByDistrict[location.idDistrito].push(location); }); Object.values(groupedByDistrict).forEach((locations: Location[]) => { // Assumir que todas as localizações no grupo têm o mesmo distrito result += `**Região ${locations[0].idDistrito}:**\n`; locations.forEach((loc: Location) => { result += `• ${loc.local} (${loc.latitude}, ${loc.longitude})\n`; }); result += "\n"; }); return { content: [ { type: "text", text: result } ] }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new McpError(ErrorCode.InternalError, `Erro ao obter locais: ${errorMessage}`); } }
- src/index.ts:173-180 (schema)Defines the input schema for the get_locations tool: an empty object (no parameters required). Also includes name and description.{ name: "get_locations", description: "Listar todas as cidades/locais disponíveis para previsão", inputSchema: { type: "object", properties: {} } },
- src/index.ts:215-216 (registration)Registers the tool handler by dispatching calls to the getLocations() method in the CallToolRequest handler.case "get_locations": return await this.getLocations();
- src/index.ts:49-58 (helper)TypeScript interface defining the structure of location data used in the getLocations handler.interface Location { idRegiao: number; idAreaAviso: string; idConcelho: number; globalIdLocal: number; latitude: string; idDistrito: number; local: string; longitude: string; }