getAlerts
Retrieve real-time alerts for U.S. National Parks, including closures, hazards, and updates. Filter by park code, keyword, or limit results for efficient access to critical park information.
Instructions
Get current alerts for national parks including closures, hazards, and important information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of alerts to return (default: 10, max: 50) | |
| parkCode | No | Filter alerts by park code (e.g., "yose" for Yosemite). Multiple parks can be comma-separated (e.g., "yose,grca"). | |
| q | No | Search term to filter alerts by title or description | |
| start | No | Start position for results (useful for pagination) |
Implementation Reference
- src/handlers/getAlerts.ts:6-44 (handler)The main handler function that executes the getAlerts tool logic: processes input args, calls NPS API client, formats and groups alerts by park, returns formatted JSON response.export async function getAlertsHandler(args: z.infer<typeof GetAlertsSchema>) { // Set default limit if not provided or if it exceeds maximum const limit = args.limit ? Math.min(args.limit, 50) : 10; // Format the request parameters const requestParams = { limit, ...args }; const response = await npsApiClient.getAlerts(requestParams); // Format the response for better readability by the AI const formattedAlerts = formatAlertData(response.data); // Group alerts by park code for better organization const alertsByPark: { [key: string]: any[] } = {}; formattedAlerts.forEach(alert => { if (!alertsByPark[alert.parkCode]) { alertsByPark[alert.parkCode] = []; } alertsByPark[alert.parkCode].push(alert); }); const result = { total: parseInt(response.total), limit: parseInt(response.limit), start: parseInt(response.start), alerts: formattedAlerts, alertsByPark }; return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }
- src/schemas.ts:18-23 (schema)Zod schema for input validation of getAlerts tool parameters: parkCode, limit, start, q.export const GetAlertsSchema = z.object({ parkCode: z.string().optional().describe('Filter alerts by park code (e.g., "yose" for Yosemite). Multiple parks can be comma-separated (e.g., "yose,grca").'), limit: z.number().optional().describe('Maximum number of alerts to return (default: 10, max: 50)'), start: z.number().optional().describe('Start position for results (useful for pagination)'), q: z.string().optional().describe('Search term to filter alerts by title or description') });
- src/server.ts:53-57 (registration)Tool registration in ListToolsRequestHandler: defines name, description, and inputSchema for getAlerts.{ name: "getAlerts", description: "Get current alerts for national parks including closures, hazards, and important information", inputSchema: zodToJsonSchema(GetAlertsSchema), },
- src/server.ts:95-98 (registration)Dispatch/execution handler in CallToolRequestHandler switch statement that parses args and calls getAlertsHandler.case "getAlerts": { const args = GetAlertsSchema.parse(request.params.arguments); return await getAlertsHandler(args); }
- src/utils/npsApiClient.ts:396-404 (helper)NPS API client utility method to fetch alerts from the '/alerts' endpoint.async getAlerts(params: AlertQueryParams = {}): Promise<NPSResponse<AlertData>> { try { const response = await this.api.get('/alerts', { params }); return response.data; } catch (error) { console.error('Error fetching alerts data:', error); throw error; } }