getAlerts
Retrieve current national park alerts for closures, hazards, and important safety information to plan visits safely.
Instructions
Get current alerts for national parks including closures, hazards, and important information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| parkCode | No | Filter alerts by park code (e.g., "yose" for Yosemite). Multiple parks can be comma-separated (e.g., "yose,grca"). | |
| limit | No | Maximum number of alerts to return (default: 10, max: 50) | |
| start | No | Start position for results (useful for pagination) | |
| q | No | Search term to filter alerts by title or description |
Implementation Reference
- src/handlers/getAlerts.ts:6-44 (handler)The main getAlerts tool handler: sets limit, calls NPS API for alerts, formats data, groups by park, returns structured 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 input schema for getAlerts tool defining optional 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 ListTools handler: defines name, description, and converts Zod schema to JSON schema for tool metadata.{ name: "getAlerts", description: "Get current alerts for national parks including closures, hazards, and important information", inputSchema: zodToJsonSchema(GetAlertsSchema), },
- src/server.ts:95-98 (registration)Tool dispatch in CallToolRequest handler: parses arguments using schema and invokes getAlertsHandler.case "getAlerts": { const args = GetAlertsSchema.parse(request.params.arguments); return await getAlertsHandler(args); }