Skip to main content
Glama
hafizrahman

Weather & WordPress MCP Server

by hafizrahman

get-forecast

Fetch precise weather forecasts for any location by providing latitude and longitude coordinates. Simplify weather data integration for informed planning.

Instructions

Get weather forecast for a location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latitudeYesLatitude of the location
longitudeYesLongitude of the location

Implementation Reference

  • The handler function fetches the weather forecast from the National Weather Service API using latitude and longitude, formats the forecast periods including temperature, wind, and short forecast, and returns formatted text content.
    async ({ latitude, longitude }) => { const pointsUrl = `${NWS_API_BASE}/points/${latitude.toFixed(4)},${longitude.toFixed(4)}`; const pointsData = await fetchJson<PointsResponse>(pointsUrl, { Accept: "application/geo+json", }); if (!pointsData || !pointsData.properties?.forecast) { return { content: [ { type: "text", text: `Failed to get forecast data for coordinates: ${latitude}, ${longitude}`, }, ], }; } const forecastData = await fetchJson<ForecastResponse>(pointsData.properties.forecast); if (!forecastData) { return { content: [{ type: "text", text: "Failed to retrieve forecast data" }], }; } const periods = forecastData.properties?.periods || []; if (periods.length === 0) { return { content: [{ type: "text", text: "No forecast periods available" }], }; } const formattedForecast = periods.map((period) => [ `${period.name || "Unknown"}:`, `Temperature: ${period.temperature || "Unknown"}°${period.temperatureUnit || "F"}`, `Wind: ${period.windSpeed || "Unknown"} ${period.windDirection || ""}`, `${period.shortForecast || "No forecast available"}`, "---", ].join("\n") ); return { content: [{ type: "text", text: `Forecast for ${latitude}, ${longitude}:\n\n${formattedForecast.join("\n")}` }], }; }
  • Input schema using Zod for validating latitude and longitude parameters.
    { latitude: z.number().min(-90).max(90).describe("Latitude of the location"), longitude: z.number().min(-180).max(180).describe("Longitude of the location"), },
  • src/index.ts:112-164 (registration)
    The server.tool call that registers the 'get-forecast' tool, including its name, description, input schema, and handler function.
    server.tool( "get-forecast", "Get weather forecast for a location", { latitude: z.number().min(-90).max(90).describe("Latitude of the location"), longitude: z.number().min(-180).max(180).describe("Longitude of the location"), }, async ({ latitude, longitude }) => { const pointsUrl = `${NWS_API_BASE}/points/${latitude.toFixed(4)},${longitude.toFixed(4)}`; const pointsData = await fetchJson<PointsResponse>(pointsUrl, { Accept: "application/geo+json", }); if (!pointsData || !pointsData.properties?.forecast) { return { content: [ { type: "text", text: `Failed to get forecast data for coordinates: ${latitude}, ${longitude}`, }, ], }; } const forecastData = await fetchJson<ForecastResponse>(pointsData.properties.forecast); if (!forecastData) { return { content: [{ type: "text", text: "Failed to retrieve forecast data" }], }; } const periods = forecastData.properties?.periods || []; if (periods.length === 0) { return { content: [{ type: "text", text: "No forecast periods available" }], }; } const formattedForecast = periods.map((period) => [ `${period.name || "Unknown"}:`, `Temperature: ${period.temperature || "Unknown"}°${period.temperatureUnit || "F"}`, `Wind: ${period.windSpeed || "Unknown"} ${period.windDirection || ""}`, `${period.shortForecast || "No forecast available"}`, "---", ].join("\n") ); return { content: [{ type: "text", text: `Forecast for ${latitude}, ${longitude}:\n\n${formattedForecast.join("\n")}` }], }; } );

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/hafizrahman/wp-mcp'

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