getCampgrounds
Search and filter campgrounds in U.S. National Parks by park code, name, or description. Retrieve details on amenities and availability, with pagination for easy navigation.
Instructions
Get information about available campgrounds and their amenities
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of campgrounds to return (default: 10, max: 50) | |
| parkCode | No | Filter campgrounds by park code (e.g., "yose" for Yosemite). Multiple parks can be comma-separated (e.g., "yose,grca"). | |
| q | No | Search term to filter campgrounds by name or description | |
| start | No | Start position for results (useful for pagination) |
Implementation Reference
- src/handlers/getCampgrounds.ts:6-44 (handler)The main handler function that implements the core logic for the getCampgrounds tool, including parameter processing, API call to NPS, response formatting, grouping by park, and returning structured JSON content.export async function getCampgroundsHandler(args: z.infer<typeof GetCampgroundsSchema>) { // 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.getCampgrounds(requestParams); // Format the response for better readability by the AI const formattedCampgrounds = formatCampgroundData(response.data); // Group campgrounds by park code for better organization const campgroundsByPark: { [key: string]: any[] } = {}; formattedCampgrounds.forEach(campground => { if (!campgroundsByPark[campground.parkCode]) { campgroundsByPark[campground.parkCode] = []; } campgroundsByPark[campground.parkCode].push(campground); }); const result = { total: parseInt(response.total), limit: parseInt(response.limit), start: parseInt(response.start), campgrounds: formattedCampgrounds, campgroundsByPark: campgroundsByPark }; return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }
- src/schemas.ts:34-39 (schema)Zod schema defining the input parameters and validation for the getCampgrounds tool.export const GetCampgroundsSchema = z.object({ parkCode: z.string().optional().describe('Filter campgrounds 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 campgrounds 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 campgrounds by name or description') });
- src/server.ts:64-67 (registration)Tool registration in the ListTools handler, defining the tool name, description, and input schema for getCampgrounds.name: "getCampgrounds", description: "Get information about available campgrounds and their amenities", inputSchema: zodToJsonSchema(GetCampgroundsSchema), },
- src/server.ts:105-108 (registration)Tool execution registration in the CallToolRequestSchema switch statement, parsing arguments and calling the getCampgroundsHandler.case "getCampgrounds": { const args = GetCampgroundsSchema.parse(request.params.arguments); return await getCampgroundsHandler(args); }
- src/utils/npsApiClient.ts:445-453 (helper)Helper method in NPS API client that fetches campgrounds data from the NPS API endpoint, used by the handler.async getCampgrounds(params: CampgroundQueryParams = {}): Promise<NPSResponse<CampgroundData>> { try { const response = await this.api.get('/campgrounds', { params }); return response.data; } catch (error) { console.error('Error fetching campgrounds data:', error); throw error; } }