Skip to main content
Glama

get-forecast

Retrieve a 5-day weather forecast for any city using location details. Input city name and optional country code to fetch accurate weather predictions.

Instructions

Get 5-day weather forecast for a location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesCity name (e.g. Beijing, London)
countryNoCountry code (e.g. CN, GB)

Implementation Reference

  • Main implementation of the get-forecast tool logic: fetches raw forecast data from service and formats it into a readable 5-day text summary.
    async getForecast(city: string, country?: string): Promise<string> { const forecastData = await this.weatherService.getForecast(city, country); if (!forecastData) { return `Failed to retrieve forecast data for ${country ? `${city}, ${country}` : city}`; } const forecasts = forecastData.list .filter((_, index) => index % 8 === 0) // Get one forecast per day .map(forecast => [ `\nDate: ${forecast.dt_txt.split(" ")[0]}`, `Temperature: ${forecast.main.temp}°C (Feels like: ${forecast.main.feels_like}°C)`, `Conditions: ${forecast.weather[0].main} - ${forecast.weather[0].description}`, `Humidity: ${forecast.main.humidity}%`, `Wind Speed: ${forecast.wind.speed} m/s`, "---" ].join("\n")); return `5-day forecast for ${forecastData.city.name}, ${forecastData.city.country}:\n${forecasts.join("\n")}`; }
  • Registers the 'get-forecast' MCP tool with description, input schema (Zod), and handler that delegates to WeatherController.getForecast().
    server.tool( "get-forecast", "Get 5-day weather forecast for a location", { city: z.string().describe("City name (e.g. Beijing, London)"), country: z.string().optional().describe("Country code (e.g. CN, GB)") }, async ({ city, country }) => { const forecastText = await weatherController.getForecast(city, country); return { content: [ { type: "text", text: forecastText, }, ], }; } );
  • Helper method in WeatherService that constructs the API query and fetches raw forecast data from OpenWeatherMap.
    async getForecast(city: string, country?: string): Promise<ForecastData | null> { const query = country ? `${city},${country}` : city; return this.makeRequest<ForecastData>("forecast", { q: query }); }
  • TypeScript interface defining the structure of the OpenWeather forecast response data for type safety.
    export interface ForecastData { list: Array<{ dt_txt: string; main: { temp: number; feels_like: number; humidity: number; }; weather: Array<{ main: string; description: string; }>; wind: { speed: number; deg: number; }; }>; city: { name: string; country: string; }; }

Other Tools

Related 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/fist-maestro/mcp-servers'

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