Skip to main content
Glama

nasa_cmr

Search NASA's Common Metadata Repository to find data collections and granules using keywords, with options for format, pagination, and sorting.

Instructions

NASA Common Metadata Repository - search for NASA data collections

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordYesSearch keyword
search_typeYesSearch type (collections or granules)collections
formatYesResponse formatjson
limitNoMaximum number of results to return
pageNoPage number for pagination
sort_keyNoField to sort results by

Implementation Reference

  • The main handler function `nasaCmrHandler` that executes the `nasa_cmr` tool logic. It validates parameters, constructs the CMR API request, fetches data using axios, processes the response, and adds resources.
    export async function nasaCmrHandler(params: CmrParams) {
      try {
        const { 
          search_type, format, limit, page, offset, sort_key, include_facets,
          polygon, bbox, point, line, circle, temporal,
          ...otherParams 
        } = params;
        
        // Determine the correct format extension for the URL
        let formatExtension = format;
        if (format === 'json') {
          formatExtension = 'json';
        } else if (format === 'umm_json') {
          formatExtension = 'umm_json';
        }
        
        // Determine search endpoint based on search type
        const endpoint = `/${search_type}.${formatExtension}`;
        
        // Construct parameters
        const queryParams: Record<string, any> = {
          page_size: limit,
          page_num: page,
          offset,
          sort_key
        };
        
        // Add other parameters
        for (const [key, value] of Object.entries(otherParams)) {
          if (value !== undefined) {
            queryParams[key] = value;
          }
        }
        
        // Add temporal parameter if provided
        if (temporal) {
          queryParams.temporal = temporal;
        }
        
        // Add spatial parameters if provided
        if (polygon) queryParams.polygon = polygon;
        if (bbox) queryParams.bbox = bbox;
        if (point) queryParams.point = point;
        if (line) queryParams.line = line;
        if (circle) queryParams.circle = circle;
        
        // Add facet options if requested
        if (include_facets) {
          queryParams.include_facets = 'v2';
        }
        
        // Make the request to CMR directly
        const response = await axios({
          url: `${CMR_API_BASE_URL}${endpoint}`,
          params: queryParams,
          headers: {
            'Client-Id': 'NASA-MCP-Server',
            'Accept': format === 'json' || format === 'umm_json' ? 'application/json' : undefined
          },
          timeout: 30000 // 30 second timeout
        });
        
        // Parse the response based on format
        let data;
        if (format === 'json' || format === 'umm_json') {
          data = response.data;
        } else {
          // For non-JSON formats, just return the raw text
          data = {
            raw: response.data,
            format: format
          };
        }
        
        // Format the response to match MCP expectations
        let summary = '';
        let formattedData;
        
        if (search_type === 'collections') {
          const collectionsCount = 
            format === 'json' ? (data.feed?.entry?.length || 0) : 
            format === 'umm_json' ? (data.items?.length || 0) : 
            0;
          summary = `Found ${collectionsCount} NASA collections`;
          formattedData = data;
        } else {
          const granulesCount = 
            format === 'json' ? (data.feed?.entry?.length || 0) : 
            format === 'umm_json' ? (data.items?.length || 0) : 
            0;
          summary = `Found ${granulesCount} data granules`;
          formattedData = data;
        }
        
        // Create a resource ID
        const resourceParams = [];
        if (params.keyword) resourceParams.push(`keyword=${encodeURIComponent(params.keyword)}`);
        if (params.concept_id) resourceParams.push(`concept_id=${params.concept_id}`);
        if (temporal) resourceParams.push(`temporal=${encodeURIComponent(temporal)}`);
        
        const resourceId = `nasa://cmr/${search_type}${resourceParams.length > 0 ? '?' + resourceParams.join('&') : ''}`;
        
        // Register the response as a resource
        addResource(resourceId, {
          name: `NASA CMR ${search_type} search${params.keyword ? ` for "${params.keyword}"` : ''}`,
          mimeType: 'application/json',
          text: JSON.stringify(formattedData, null, 2)
        });
        
        // If the response includes specific collections or granules, register those too
        if (formattedData.feed?.entry && Array.isArray(formattedData.feed.entry)) {
          formattedData.feed.entry.forEach((entry: any, index: number) => {
            if (index < 5) { // Limit to first 5 entries to avoid too many resources
              const entryId = entry.id || entry['concept-id'] || `${search_type}-${index}`;
              const entryTitle = entry.title || `NASA ${search_type} Item ${index + 1}`;
              
              const entryResourceId = `nasa://cmr/${search_type}/item?id=${entryId}`;
              
              addResource(entryResourceId, {
                name: entryTitle,
                mimeType: 'application/json',
                text: JSON.stringify(entry, null, 2)
              });
            }
          });
        }
        
        return {
          content: [
            {
              type: "text",
              text: summary
            },
            {
              type: "text",
              text: JSON.stringify(formattedData, null, 2)
            }
          ],
          isError: false
        };
      } catch (error: any) {
        console.error('Error in CMR handler:', error);
        
        // Proper error handling with isError flag
        return {
          isError: true,
          content: [{
            type: "text",
            text: `Error searching NASA Common Metadata Repository: ${error.message || 'Unknown error'}`
          }]
        };
      }
    }
    
    // Export the handler function directly as default
    export default nasaCmrHandler; 
  • Zod schema `cmrParamsSchema` defining the input parameters for the nasa_cmr tool.
    export const cmrParamsSchema = z.object({
      // Search type - collections or granules
      search_type: z.enum(['collections', 'granules']).default('collections'),
      
      // Basic search parameters
      keyword: z.string().optional(),
      concept_id: z.string().optional(),
      entry_title: z.string().optional(),
      short_name: z.string().optional(),
      provider: z.string().optional(),
      
      // Temporal parameters
      temporal: z.string().optional().describe('Temporal range in the format: start_date,end_date'),
      
      // Spatial parameters
      polygon: polygonSchema.optional(),
      bbox: bboxSchema.optional(),
      point: pointSchema.optional(),
      line: lineSchema.optional(),
      circle: circleSchema.optional(),
      
      // Platform, instrument, and project
      platform: z.string().optional(),
      instrument: z.string().optional(),
      project: z.string().optional(),
      
      // Processing level and data format
      processing_level_id: z.string().optional(),
      granule_data_format: z.string().optional(),
      
      // Search flags
      downloadable: z.boolean().optional(),
      browsable: z.boolean().optional(),
      online_only: z.boolean().optional(),
      
      // Facet parameters
      include_facets: z.boolean().optional(),
      
      // Pagination and sorting
      limit: z.number().optional().default(10),
      page: z.number().optional().default(1),
      offset: z.number().optional(),
      sort_key: z.string().optional(),
      
      // Result format
      format: z.enum(['json', 'umm_json', 'atom', 'echo10', 'iso19115', 'iso_smap', 'kml']).optional().default('json')
    });
  • src/index.ts:1558-1574 (registration)
    MCP server request handler registration for the `nasa/cmr` method, which dispatches to the tool handler.
    // CMR Handler
    server.setRequestHandler(
      z.object({ 
        method: z.literal("nasa/cmr"),
        params: z.object({
          keyword: z.string().optional(),
          search_type: z.enum(['collections', 'granules']).optional(),
          format: z.enum(['json', 'umm_json', 'atom', 'echo10', 'iso19115', 'iso_smap', 'kml']).optional(),
          limit: z.number().optional(),
          page: z.number().optional(),
          sort_key: z.string().optional()
        }).passthrough().optional()
      }),
      async (request) => {
        return await handleToolCall("nasa/cmr", request.params || {});
      }
    );
  • src/index.ts:793-829 (registration)
    Tool definition for `nasa_cmr` in the tools/list response, including input schema.
      name: "nasa_cmr",
      description: "NASA Common Metadata Repository - search for NASA data collections",
      inputSchema: {
        type: "object",
        properties: {
          keyword: {
            type: "string",
            description: "Search keyword"
          },
          search_type: {
            type: "string",
            description: "Search type (collections or granules)",
            enum: ["collections", "granules"],
            default: "collections"
          },
          format: {
            type: "string",
            description: "Response format",
            enum: ["json", "umm_json", "atom", "echo10", "iso19115", "iso_smap", "kml"],
            default: "json"
          },
          limit: {
            type: "number",
            description: "Maximum number of results to return"
          },
          page: {
            type: "number",
            description: "Page number for pagination"
          },
          sort_key: {
            type: "string",
            description: "Field to sort results by"
          }
        },
        required: ["keyword","search_type", "format"]
      }
    },
  • src/index.ts:463-466 (registration)
    Tool listing for `nasa_cmr` in the tools/manifest response.
      name: "nasa_cmr",
      id: "nasa/cmr",
      description: "Search NASA's Common Metadata Repository for satellite data"
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure but only states it's a search tool. It doesn't mention whether this is a read-only operation, what authentication might be required, rate limits, pagination behavior beyond the page parameter, or what the response structure looks like. For a search tool with 6 parameters and no annotations, this is inadequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise - a single sentence that efficiently communicates the core purpose. There's no wasted language or unnecessary elaboration, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a search tool with 6 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what kind of results to expect, how pagination works, what the different search types mean, or provide any context about the NASA CMR system. The agent would need to guess about important behavioral aspects.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description doesn't add any parameter-specific information beyond what's already in the schema (which has 100% coverage). It doesn't explain the relationship between parameters like search_type and format, or provide examples of keyword usage. With complete schema coverage, the baseline is 3, but no additional value is added.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as searching for NASA data collections in the Common Metadata Repository, specifying both the action (search) and resource (NASA data collections). However, it doesn't explicitly differentiate this from sibling tools like nasa_images or nasa_apod, which also involve NASA data but serve different purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when this search tool is appropriate compared to other NASA data tools in the sibling list, nor does it specify any prerequisites or exclusions for its use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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