get-forecast-by-lat-long
Retrieve current or historical air quality forecast data for a specific location using latitude and longitude. Access AQI values and categories in JSON, CSV, or XML formats for informed environmental decisions.
Instructions
Get current or historical forecasted AQI values and categories for a reporting area by latitude and longitude.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | Date of forecast. Format: YYYY-MM-DD. Example: 2012-02-01 | |
| distance | No | Return a forecast from a nearby reporting area within this distance (in miles). Example: 150 | |
| format | Yes | Format of the payload file returned. Example: application/json | |
| latitude | Yes | Latitude in decimal degrees. Example: 38.33 | |
| longitude | Yes | Longitude in decimal degrees. Example: -122.28 |
Implementation Reference
- src/tools/forecast-by-lat-long.ts:32-53 (handler)The MCP handler function for the get-forecast-by-lat-long tool. It calls the AirNow API helper and returns the result as text content or an error.async (params) => { const result = await airnowApi.fetchForecastByLatLong(params); if (result === null) { return { content: [ { type: "text", text: "Failed to fetch forecast data from AirNow API.", }, ], isError: true, }; } return { content: [ { type: "text", text: result, }, ], }; }
- Zod schema defining the input parameters for the tool: latitude, longitude, optional date, format, and distance.{ latitude: z .string() .describe("Latitude in decimal degrees. Example: 38.33"), longitude: z .string() .describe("Longitude in decimal degrees. Example: -122.28"), date: z .string() .optional() .describe("Date of forecast. Format: YYYY-MM-DD. Example: 2012-02-01"), format: z .enum(["text/csv", "application/json", "application/xml"]) .describe( "Format of the payload file returned. Example: application/json" ), distance: z .string() .optional() .describe( "Return a forecast from a nearby reporting area within this distance (in miles). Example: 150" ), }, async (params) => {
- src/tools/forecast-by-lat-long.ts:5-55 (registration)The registration function that calls server.tool() to register the get-forecast-by-lat-long tool with MCP server, including name, description, schema, and handler.export const registerForecastByLatLong = (server: McpServer): void => { server.tool( "get-forecast-by-lat-long", "Get current or historical forecasted AQI values and categories for a reporting area by latitude and longitude.", { latitude: z .string() .describe("Latitude in decimal degrees. Example: 38.33"), longitude: z .string() .describe("Longitude in decimal degrees. Example: -122.28"), date: z .string() .optional() .describe("Date of forecast. Format: YYYY-MM-DD. Example: 2012-02-01"), format: z .enum(["text/csv", "application/json", "application/xml"]) .describe( "Format of the payload file returned. Example: application/json" ), distance: z .string() .optional() .describe( "Return a forecast from a nearby reporting area within this distance (in miles). Example: 150" ), }, async (params) => { const result = await airnowApi.fetchForecastByLatLong(params); if (result === null) { return { content: [ { type: "text", text: "Failed to fetch forecast data from AirNow API.", }, ], isError: true, }; } return { content: [ { type: "text", text: result, }, ], }; } ); };
- src/tools/index.ts:19-19 (registration)Invocation of the tool registration function within the main registerTools function.registerForecastByLatLong(server);
- src/airnow-api.ts:30-40 (helper)Core helper function implementing the API call to AirNow for fetching forecast by latitude and longitude, constructing query params and using shared airnowGet fetcher.export async function fetchForecastByLatLong(params: Record<string, string>): Promise<string | null> { const endpoint = 'aq/forecast/latlong/'; const queryParams = new URLSearchParams(); queryParams.append('latitude', params.latitude); queryParams.append('longitude', params.longitude); queryParams.append('format', params.format); if (params.date) queryParams.append('date', params.date); if (params.distance) queryParams.append('distance', params.distance); return airnowGet(endpoint, queryParams); }