get_locations
Retrieve all available cities and locations in Portugal to access 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.js:301-337 (handler)The main handler function for the 'get_locations' tool. Fetches location data from the IPMA API, groups locations by district, formats them into a markdown text response, and returns it in the MCP content format.async getLocations() { try { const response = await fetch(`${this.baseUrl}/distrits-islands.json`); const data = await response.json(); let result = "**Locais Disponíveis para Previsão**\n\n"; const groupedByDistrict = {}; data.data.forEach((location) => { if (!groupedByDistrict[location.idDistrito]) { groupedByDistrict[location.idDistrito] = []; } groupedByDistrict[location.idDistrito].push(location); }); Object.values(groupedByDistrict).forEach((locations) => { result += `**Região ${locations[0].idDistrito}:**\n`; locations.forEach((loc) => { 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.js:74-81 (registration)Registers the 'get_locations' tool in the list of tools returned by ListToolsRequestSchema, including its name, description, and input schema.{ name: "get_locations", description: "Listar todas as cidades/locais disponíveis para previsão", inputSchema: { type: "object", properties: {} } },
- src/index.js:77-80 (schema)Defines the input schema for the 'get_locations' tool, which requires no parameters (empty properties).inputSchema: { type: "object", properties: {} }
- src/index.js:114-115 (handler)Part of the CallToolRequestSchema handler that dispatches calls to the 'get_locations' tool by invoking the getLocations() method.case "get_locations": return await this.getLocations();