Skip to main content
Glama

get_weather_forecast

Retrieve 5-day weather forecasts with 3-hour intervals for any city using the Multi-MCPs server's integrated weather API.

Instructions

Get 5-day/3-hour forecast by city name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
locationYes
daysNoDays to include (1-5)

Implementation Reference

  • The async handler function that implements the get_weather_forecast tool. It validates the API key and location, fetches the forecast data using client.forecastByCity, and optionally slices the list based on the 'days' parameter.
    async get_weather_forecast(args: Record<string, unknown>) { if (!cfg.openWeatherApiKey) throw new Error("OPENWEATHER_API_KEY is not configured"); const location = String(args.location || ""); const days = args.days ? Number(args.days) : undefined; if (!location) throw new Error("location is required"); const data: any = await client.forecastByCity(location); if (!days) return data; const count = Math.max(1, Math.min(5, days)); const list = (data as any).list || []; return { ...(data as object), list: list.slice(0, count * 8) } as any;
  • The inputSchema for the get_weather_forecast tool, defining 'location' as required string and optional 'days' number.
    inputSchema: { type: "object", properties: { location: { type: "string" }, days: { type: "number", description: "Days to include (1-5)" }, }, required: ["location"], },
  • The call to registerOpenWeather() within the registerAllTools function, which includes the get_weather_forecast tool in the overall tool registrations for the MCP server.
    registerOpenWeather(),
  • The forecastByCity method in OpenWeatherClient that makes the API request to retrieve the raw forecast data used by the handler.
    async forecastByCity(location: string) { return this.request("/data/2.5/forecast", { query: { q: location, appid: this.apiKey, units: "metric" }, }); }
  • The registerOpenWeather function that defines and returns the ToolRegistration object containing the tool schema and handler for get_weather_forecast.
    export function registerOpenWeather(): ToolRegistration { const cfg = loadConfig(); const client = new OpenWeatherClient(cfg.openWeatherApiKey || ""); return { tools: [ { name: "get_current_weather", description: "Get current weather by city name", inputSchema: { type: "object", properties: { location: { type: "string", description: "City name, e.g., London" }, }, required: ["location"], }, }, { name: "get_weather_forecast", description: "Get 5-day/3-hour forecast by city name", inputSchema: { type: "object", properties: { location: { type: "string" }, days: { type: "number", description: "Days to include (1-5)" }, }, required: ["location"], }, }, { name: "get_weather_alerts", description: "Get weather alerts for a location (requires One Call support)", inputSchema: { type: "object", properties: { location: { type: "string" }, }, required: ["location"], }, }, ], handlers: { async get_current_weather(args: Record<string, unknown>) { if (!cfg.openWeatherApiKey) throw new Error("OPENWEATHER_API_KEY is not configured"); const location = String(args.location || ""); if (!location) throw new Error("location is required"); return client.currentWeatherByCity(location); }, async get_weather_forecast(args: Record<string, unknown>) { if (!cfg.openWeatherApiKey) throw new Error("OPENWEATHER_API_KEY is not configured"); const location = String(args.location || ""); const days = args.days ? Number(args.days) : undefined; if (!location) throw new Error("location is required"); const data: any = await client.forecastByCity(location); if (!days) return data; const count = Math.max(1, Math.min(5, days)); const list = (data as any).list || []; return { ...(data as object), list: list.slice(0, count * 8) } as any; }, async get_weather_alerts(args: Record<string, unknown>) { if (!cfg.openWeatherApiKey) throw new Error("OPENWEATHER_API_KEY is not configured"); const location = String(args.location || ""); if (!location) throw new Error("location is required"); return client.alertsByLocation(location); }, }, }; }

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/TaylorChen/muti-mcps'

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