Skip to main content
Glama

nasa_images

Search NASA's media archive for images, videos, and audio using queries, media types, and date ranges to access space exploration content.

Instructions

NASA Image and Video Library - search NASA's media archive

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
qYesSearch query
media_typeNoMedia type (image, video, audio)
year_startNoStart year for results
year_endNoEnd year for results
pageNoPage number for pagination

Implementation Reference

  • Main execution logic for the nasa_images tool: constructs NASA Images API request, fetches data, processes results via helper, handles errors.
    export async function nasaImagesHandler(params: ImagesParams) {
      try {
        const { q, media_type, year_start, year_end, page, page_size } = params;
    
        // Construct request to NASA Image API
        const url = 'https://images-api.nasa.gov/search';
        
        // Prepare query parameters
        const queryParams: Record<string, any> = {
          q,
          page,
          page_size
        };
        
        if (media_type) queryParams.media_type = media_type;
        if (year_start) queryParams.year_start = year_start;
        if (year_end) queryParams.year_end = year_end;
        
        // Make the request to NASA Images API
        const response = await axios.get(url, { params: queryParams, timeout: 30000 });
        
        // Process the results and register resources
        return await processImageResultsWithBase64(response.data);
      } catch (error: any) {
        console.error('Error in NASA Images handler:', error);
        
        if (error.name === 'ZodError') {
          return {
            content: [{
              type: "text",
              text: `Invalid request parameters: ${error.message}`
            }],
            isError: true
          };
        }
        
        return {
          content: [{
            type: "text",
            text: `Error fetching NASA images: ${error.message || 'Unknown error'}`
          }],
          isError: true
        };
      }
    }
  • Supporting function to process API response: extracts image metadata, fetches full-res images as base64, registers MCP resources, formats content with markdown and embedded images.
    async function processImageResultsWithBase64(data: any) {
      const items = data?.collection?.items || [];
      
      if (items.length === 0) {
        return {
          content: [{
            type: "text",
            text: "No images found matching the search criteria."
          }],
          isError: false
        };
      }
      
      const images: any[] = [];
      for (const item of items) {
        const metadata = item.data && item.data[0];
        if (!metadata || !metadata.nasa_id || metadata.media_type !== 'image') continue;
        const nasaId = metadata.nasa_id;
        const title = metadata.title || 'Untitled NASA Image';
        const resourceUri = `nasa://images/item?nasa_id=${nasaId}`;
        // Find the full-res image link (look for rel: 'orig' or the largest image)
        let fullResUrl = null;
        if (item.links && Array.isArray(item.links)) {
          // Try to find rel: 'orig' or the largest image
          const orig = item.links.find((link: any) => link.rel === 'orig');
          if (orig && orig.href) fullResUrl = orig.href;
          else {
            // Fallback: use the first image link
            const firstImg = item.links.find((link: any) => link.render === 'image');
            if (firstImg && firstImg.href) fullResUrl = firstImg.href;
          }
        }
        let mimeType = 'image/jpeg';
        if (fullResUrl) {
          if (fullResUrl.endsWith('.png')) mimeType = 'image/png';
          else if (fullResUrl.endsWith('.gif')) mimeType = 'image/gif';
          else if (fullResUrl.endsWith('.jpg') || fullResUrl.endsWith('.jpeg')) mimeType = 'image/jpeg';
        }
        // Fetch the image and encode as base64
        let base64 = null;
        if (fullResUrl) {
          try {
            const imageResponse = await axios.get(fullResUrl, { responseType: 'arraybuffer', timeout: 30000 });
            base64 = Buffer.from(imageResponse.data).toString('base64');
          } catch (err) {
            console.error('Failed to fetch NASA Images image for base64:', fullResUrl, err);
          }
        }
        addResource(resourceUri, {
          name: title,
          mimeType: "application/json",
          text: JSON.stringify({
            item_details: metadata,
            full_res_url: fullResUrl,
            title: title,
            description: metadata.description || 'No description available',
            date_created: metadata.date_created || 'Unknown date',
            nasa_id: nasaId
          })
        });
        images.push({
          title,
          base64,
          mimeType,
          url: fullResUrl
        });
      }
      return {
        content: [
          {
            type: "text",
            text: `Found ${images.length} NASA images/media items.`
          },
          ...images.map(img => ({
            type: "text",
            text: `![${img.title}](${img.url})`
          })),
          ...images.map(img => ({
            type: "image",
            data: img.base64,
            mimeType: img.mimeType
          }))
        ],
        isError: false
      };
    }
  • Zod schema defining input parameters for the nasa_images tool (search query, media type, date range, pagination).
    export const imagesParamsSchema = z.object({
      q: z.string().min(1),
      media_type: z.enum(['image', 'audio', 'video']).optional(),
      year_start: z.string().optional(),
      year_end: z.string().optional(),
      page: z.number().int().positive().optional().default(1),
      page_size: z.number().int().min(1).max(100).optional().default(10)
    });
  • src/index.ts:1592-1606 (registration)
    Registers direct MCP request handler for method 'nasa/images', validates params with inline Zod schema, delegates to central handleToolCall.
    server.setRequestHandler(
      z.object({ 
        method: z.literal("nasa/images"),
        params: z.object({
          q: z.string(),
          page: z.number().optional(),
          media_type: z.string().optional(),
          year_start: z.string().optional(),
          year_end: z.string().optional()
        }).optional()
      }),
      async (request) => {
        return await handleToolCall("nasa/images", request.params || {});
      }
    );
  • src/index.ts:852-881 (registration)
    Registers nasa_images tool in tools/list endpoint response, providing JSON schema for inputs.
    {
      name: "nasa_images",
      description: "NASA Image and Video Library - search NASA's media archive",
      inputSchema: {
        type: "object",
        properties: {
          q: {
            type: "string",
            description: "Search query"
          },
          media_type: {
            type: "string",
            description: "Media type (image, video, audio)"
          },
          year_start: {
            type: "string",
            description: "Start year for results"
          },
          year_end: {
            type: "string",
            description: "End year for results"
          },
          page: {
            type: "number",
            description: "Page number for pagination"
          }
        },
        required: ["q"]
      }
    },
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions searching an archive but doesn't cover key aspects like whether this is a read-only operation, potential rate limits, authentication needs, or what the response format looks like (e.g., paginated results). This leaves significant gaps for a tool with 5 parameters and no output schema.

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 a single, efficient sentence that front-loads the core purpose ('NASA Image and Video Library - search NASA's media archive'). There is no wasted text, making it highly concise and well-structured for quick understanding.

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?

Given the tool's complexity (5 parameters, no annotations, no output schema), the description is incomplete. It lacks behavioral details, usage context, and output information, which are crucial for an agent to effectively use this search tool. The high schema coverage helps with parameters, but overall guidance is insufficient.

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 input schema has 100% description coverage, so the schema already documents all 5 parameters (e.g., 'q' for search query, 'media_type' for filtering). The description adds no additional meaning beyond what's in the schema, such as examples or constraints, but since schema coverage is high, a baseline score of 3 is appropriate.

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 NASA's media archive, which is a specific verb ('search') and resource ('NASA's media archive'). However, it doesn't explicitly differentiate from sibling tools like 'nasa_apod' (Astronomy Picture of the Day) or 'nasa_mars_rover' (Mars rover images), which might also involve NASA media but serve different functions.

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 any context, exclusions, or comparisons to sibling tools, such as 'nasa_apod' for daily astronomy images or 'nasa_mars_rover' for Mars-specific media, leaving the agent to infer usage based on the name alone.

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