Skip to main content
Glama

jpl_sbdb

Search NASA's Small-Body Database to retrieve detailed asteroid and comet data, including orbital parameters and close approach information.

Instructions

Small-Body Database (SBDB) - asteroid and comet data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sstrYesSearch string (e.g., asteroid name, number, or designation)
cadNoInclude close approach data

Implementation Reference

  • Core handler function that validates parameters, constructs the JPL SBDB API request, transforms parameter names, fetches data using axios, and returns MCP-formatted content or error.
    export async function jplSbdbHandler(params: SbdbParams) {
      try {
        const { 
          sstr, 
          full_precision, 
          solution_epoch, 
          orbit_class, 
          body_type, 
          phys_par, 
          close_approach, 
          ca_time, 
          ca_dist, 
          ca_tbl, 
          format 
        } = params;
        
        // Construct the SBDB query URL
        const url = 'https://ssd-api.jpl.nasa.gov/sbdb.api';
        
        // Prepare the query parameters
        const queryParams: Record<string, any> = {
          sstr
        };
        
        // Add optional parameters
        if (full_precision) queryParams.full_precision = full_precision ? 'yes' : 'no';
        if (solution_epoch) queryParams.solution_epoch = solution_epoch;
        if (orbit_class) queryParams.orbit_class = orbit_class ? 'yes' : 'no';
        if (body_type !== 'all') queryParams.body_type = body_type;
        if (phys_par) queryParams.phys_par = phys_par ? 'yes' : 'no';
        if (close_approach) queryParams.close_approach = close_approach ? 'yes' : 'no';
        if (ca_time !== 'all') queryParams.ca_time = ca_time;
        if (ca_dist !== 'au') queryParams.ca_dist = ca_dist;
        if (ca_tbl !== 'approach') queryParams.ca_tbl = ca_tbl;
        if (format !== 'json') queryParams.format = format;
        
        // Transform parameter names from underscore to hyphenated format
        const transformedParams = transformParamsToHyphenated(queryParams);
        
        // Make the request to SBDB API
        const response = await axios.get(url, { params: transformedParams });
        
        // Return the response
        return {
          content: [
            {
              type: "text",
              text: `Retrieved data for small body "${params.sstr}".`
            },
            {
              type: "text",
              text: JSON.stringify(response.data, null, 2)
            }
          ],
          isError: false
        };
      } catch (error: any) {
        console.error('Error in JPL SBDB handler:', error);
        
        return {
          isError: true,
          content: [{
            type: "text",
            text: `Error: ${error.message || 'An unexpected error occurred'}`
          }]
        };
      }
    } 
  • Zod schema defining and validating input parameters for the jpl_sbdb tool, including required search string and various optional filters.
    export const sbdbParamsSchema = z.object({
      sstr: z.string().min(1),
      full_precision: z.boolean().optional().default(false),
      solution_epoch: z.string().optional(),
      orbit_class: z.boolean().optional().default(false),
      body_type: z.enum(['ast', 'com', 'all']).optional().default('all'),
      phys_par: z.boolean().optional().default(false),
      close_approach: z.boolean().optional().default(false),
      ca_time: z.enum(['all', 'now', 'fut', 'past']).optional().default('all'),
      ca_dist: z.enum(['au', 'ld', 'lu']).optional().default('au'),
      ca_tbl: z.enum(['elem', 'approach']).optional().default('approach'),
      format: z.enum(['json', 'xml']).optional().default('json')
    });
  • Helper utility to transform API parameter keys from underscore_case (e.g., full_precision) to hyphen-case (full-precision) as required by JPL APIs.
    export function transformParamsToHyphenated(params: Record<string, any>): Record<string, any> {
      const transformed: Record<string, any> = {};
      
      for (const [key, value] of Object.entries(params)) {
        // Replace underscores with hyphens for parameter names
        const transformedKey = key.replace(/_/g, '-');
        transformed[transformedKey] = value;
      }
      
      return transformed;
    } 
  • src/index.ts:1896-1932 (registration)
    Dynamic registration and execution logic for JPL tools (including jpl/sbdb): dynamically imports the handler module from ./handlers/jpl/sbdb.js and invokes the exported handler function with arguments.
    } else if (internalToolId.startsWith("jpl/")) {
      // Extract the JPL API endpoint name
      const endpoint = internalToolId.split("/")[1];
      serverInstance?.sendLoggingMessage({
        level: "info",
        data: `JPL Endpoint: ${endpoint}`,
      });
      
      try {
        // Dynamic import for JPL handlers using the original slash format path
        serverInstance?.sendLoggingMessage({
          level: "info",
          data: `Importing handler module: ./handlers/jpl/${endpoint}.js`,
        });
        const handlerModule = await import(`./handlers/jpl/${endpoint}.js`);
        
        // Try to find the handler function in various export formats
        const handlerFunction = handlerModule.default || 
                               handlerModule[`jpl${endpoint.charAt(0).toUpperCase() + endpoint.slice(1)}Handler`] ||
                               handlerModule[`${endpoint}Handler`];
        
        if (typeof handlerFunction === 'function') {
          return await handlerFunction(args);
        } else {
          throw new Error(`Handler for ${endpoint} not found in module`);
        }
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        return {
          content: [{
            type: "text",
            text: `Error executing JPL tool '${toolName}': ${errorMessage}`
          }],
          isError: true
        };
      }
    }
  • src/index.ts:1032-1048 (registration)
    Tool registration in MCP tools/list handler: defines the 'jpl_sbdb' tool name, description, and JSON input schema.
      name: "jpl_sbdb",
      description: "Small-Body Database (SBDB) - asteroid and comet data",
      inputSchema: {
        type: "object",
        properties: {
          sstr: {
            type: "string",
            description: "Search string (e.g., asteroid name, number, or designation)"
          },
          cad: {
            type: "boolean",
            description: "Include close approach data"
          }
        },
        required: ["sstr"]
      }
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ProgramComputer/NASA-MCP-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server