getVisitorCenters
Find visitor center details and operating hours in U.S. National Parks using park code, search terms, or pagination filters.
Instructions
Get information about visitor centers and their operating hours
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of visitor centers to return (default: 10, max: 50) | |
| parkCode | No | Filter visitor centers by park code (e.g., "yose" for Yosemite). Multiple parks can be comma-separated (e.g., "yose,grca"). | |
| q | No | Search term to filter visitor centers by name or description | |
| start | No | Start position for results (useful for pagination) |
Implementation Reference
- src/handlers/getVisitorCenters.ts:6-44 (handler)The main handler function getVisitorCentersHandler that implements the core logic of the tool: processes input args, calls NPS API via npsApiClient, formats the response data, groups by park, and returns structured JSON.export async function getVisitorCentersHandler(args: z.infer<typeof GetVisitorCentersSchema>) { // 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.getVisitorCenters(requestParams); // Format the response for better readability by the AI const formattedCenters = formatVisitorCenterData(response.data); // Group visitor centers by park code for better organization const centersByPark: { [key: string]: any[] } = {}; formattedCenters.forEach(center => { if (!centersByPark[center.parkCode]) { centersByPark[center.parkCode] = []; } centersByPark[center.parkCode].push(center); }); const result = { total: parseInt(response.total), limit: parseInt(response.limit), start: parseInt(response.start), visitorCenters: formattedCenters, visitorCentersByPark: centersByPark }; return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }
- src/schemas.ts:26-31 (schema)Zod schema defining the input validation for the getVisitorCenters tool parameters.export const GetVisitorCentersSchema = z.object({ parkCode: z.string().optional().describe('Filter visitor centers 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 visitor centers 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 visitor centers by name or description') });
- src/server.ts:58-62 (registration)Registration of the getVisitorCenters tool in the ListToolsRequestSchema handler, including name, description, and input schema reference.{ name: "getVisitorCenters", description: "Get information about visitor centers and their operating hours", inputSchema: zodToJsonSchema(GetVisitorCentersSchema), },
- src/server.ts:100-103 (registration)Dispatch logic in the CallToolRequestSchema handler that validates arguments with the schema and invokes the getVisitorCentersHandler.case "getVisitorCenters": { const args = GetVisitorCentersSchema.parse(request.params.arguments); return await getVisitorCentersHandler(args); }