jpl_cad
Query NASA's JPL database to identify asteroid and comet close approaches to planets within specified date ranges and distance parameters for planetary defense monitoring.
Instructions
Asteroid and comet close approaches to the planets in the past and future
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dist_max | No | Maximum approach distance (e.g., 0.05, 10LD). Default: 0.05 au | |
| dist_min | No | Minimum approach distance. Default: none | |
| date_min | No | Start date for search (YYYY-MM-DD). Default: now | |
| date_max | No | End date for search (YYYY-MM-DD). Default: +60 days | |
| body | No | Body to find close approaches to (e.g., Earth, Mars, ALL). Default: Earth | |
| sort | No | Sort field: date, dist, dist-min, v-inf, v-rel, h, object. Default: date | |
| des | No | Object designation (e.g., '2000 SG344' or '433') | |
| spk | No | Object SPK-ID (e.g., '2000433') | |
| neo | No | Limit to NEOs. Default: true | |
| fullname | No | Include full object name in result. Default: false |
Implementation Reference
- src/handlers/jpl/cad.ts:14-80 (handler)The main handler function cadHandler that implements the JPL Close Approach Data (CAD) API call, parameter transformation, resource creation, and error handling.
export async function cadHandler(args: Record<string, any>) { try { // Base URL for the CAD API const baseUrl = 'https://ssd-api.jpl.nasa.gov/cad.api'; // Validate parameters if needed // Parameters are fairly flexible in this API, so minimal validation is needed // Transform parameter names from underscore to hyphenated format const transformedParams = transformParamsToHyphenated(args); // Make the API request const response = await axios.get(baseUrl, { params: transformedParams }); const data = response.data; // Create a resource URI that represents this query let resourceUri: string; let resourceName: string; if (args.des) { // Query for a specific object resourceUri = `jpl://cad/object/${args.des}`; resourceName = `Close approaches for object ${args.des}`; } else if (args.spk) { // Query for a specific object by SPK-ID resourceUri = `jpl://cad/object/${args.spk}`; resourceName = `Close approaches for object ${args.spk}`; } else { // Query for close approaches with constraints const constraints = Object.entries(args) .map(([key, value]) => `${key}=${value}`) .join('&'); resourceUri = `jpl://cad/list${constraints ? '?' + constraints : ''}`; // Create a readable name based on date range and body const dateMin = args['date_min'] || 'now'; const dateMax = args['date_max'] || '+60'; const body = args.body || 'Earth'; resourceName = `Close approaches to ${body} from ${dateMin} to ${dateMax}`; } // Add response to resources addResource(resourceUri, { name: resourceName, mimeType: "application/json", text: JSON.stringify(data, null, 2) }); // Format the response return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Error accessing JPL SB Close Approach API: ${error.message}` }], isError: true }; } }