Skip to main content
Glama

nasa_epic

Retrieve Earth imagery from NASA's EPIC camera to visualize our planet from space. Specify date and collection type to access natural or enhanced color images.

Instructions

Earth Polychromatic Imaging Camera - views of Earth

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionNoImage collection (natural or enhanced)
dateNoDate of the image (YYYY-MM-DD)

Implementation Reference

  • nasaEpicHandler: Main handler function that processes parameters, fetches EPIC data from NASA API, processes images with processEpicResults, registers resources, and returns MCP-formatted content with text summaries, markdown images, and embedded images.
    export async function nasaEpicHandler(params: EpicParams) {
      try {
        // Parse the request parameters
        const { collection, date } = params;
        
        // Determine the endpoint based on parameters
        let endpoint = `/${collection}`;
        if (date) {
          endpoint += `/date/${date}`;
        }
        
        // Try to fetch EPIC data with timeout of 30 seconds
        const response = await axios.get(`${EPIC_API_BASE_URL}${endpoint}`, { 
          timeout: 30000 
        });
        
        const epicData = response.data;
        
        // Process the results
        if (epicData && epicData.length > 0) {
          const results = await processEpicResults(epicData, collection);
          
          return {
            content: [
              { type: "text", text: results.summary },
              // Existing resource URI entries
              ...results.images.map(img => ({ type: "text", text: `![${img.caption}](${img.resourceUri})` })),
              // Direct image URL markdown entries
              ...results.images.map(img => ({ type: "text", text: `![${img.caption}](${img.imageUrl})` })),
              // Embedded binary images
              ...results.images
                .filter(img => img.base64)
                .map(img => ({ type: "image", data: img.base64!, mimeType: img.mimeType! })),
            ],
            isError: false
          };
        }
        
        // No data found for date
        return {
          content: [{
            type: "text",
            text: `No EPIC data found for date ${date || 'latest'} in collection ${collection}`
          }],
          isError: false
        };
      } catch (error: any) {
        console.error('Error in EPIC handler:', error);
        
        if (error.name === 'ZodError') {
          return {
            content: [{
              type: "text",
              text: `Invalid request parameters: ${error.message}`
            }],
            isError: true
          };
        }
        
        // Return a properly formatted error
        return {
          content: [{
            type: "text",
            text: `Error fetching EPIC data: ${error.message}`
          }],
          isError: true
        };
      }
    }
    
    // Export the handler function directly as default
    export default nasaEpicHandler; 
  • epicParamsSchema: Zod schema defining input parameters for the nasa_epic tool (collection: 'natural'|'enhanced', date: string optional).
    export const epicParamsSchema = z.object({
      collection: z.enum(['natural', 'enhanced']).optional().default('natural'),
      date: z.string().optional(),
    });
  • src/index.ts:1511-1523 (registration)
    Direct MCP request handler registration for method 'nasa/epic', which delegates to handleToolCall('nasa/epic') dispatching to the dynamic import of epic handler.
    // EPIC Handler
    server.setRequestHandler(
      z.object({ 
        method: z.literal("nasa/epic"),
        params: z.object({
          collection: z.string().optional(),
          date: z.string().optional()
        }).optional()
      }),
      async (request) => {
        return await handleToolCall("nasa/epic", request.params || {});
      }
    );
  • src/index.ts:453-456 (registration)
    Tool manifest listing 'nasa_epic' as available tool with id 'nasa/epic' and description.
      name: "nasa_epic",
      id: "nasa/epic",
      description: "Earth Polychromatic Imaging Camera views of Earth"
    },
  • processEpicResults: Helper function that processes raw EPIC API data, fetches and encodes images to base64, registers them as MCP resources, and prepares formatted image data for the response.
    async function processEpicResults(epicData: any[], collection: string) {
      if (!Array.isArray(epicData) || epicData.length === 0) {
        return {
          summary: "No EPIC data available for the specified parameters.",
          images: []
        };
      }
    
      // Extract date information from the first image
      const firstImage = epicData[0];
      const date = firstImage.date || 'unknown date';
      
      // Get image date parts for URL construction
      const dateStr = firstImage.date.split(' ')[0];
      const [year, month, day] = dateStr.split('-');
      
      // Collect image data including base64 for direct display
      const images: Array<{ identifier: string; caption: string; imageUrl: string; resourceUri: string; base64?: string; mimeType?: string; error?: string }> = [];
      
      for (const img of epicData) {
        // Construct the image URL according to NASA's format
        const imageUrl = `${EPIC_IMAGE_BASE_URL}/${collection}/${year}/${month}/${day}/png/${img.image}.png`;
        
        // Create a unique resource URI for this image
        const resourceUri = `nasa://epic/image/${collection}/${img.identifier}`;
        
        try {
          // Fetch the actual image data
          const imageResponse = await axios({
            url: imageUrl,
            responseType: 'arraybuffer',
            timeout: 30000
          });
          
          // Convert image data to Base64 for direct response
          const imageBase64 = Buffer.from(imageResponse.data).toString('base64');
          
          // Register this image as a resource with binary data
          addResource(resourceUri, {
            name: `NASA EPIC Earth Image - ${img.identifier}`,
            mimeType: "image/png",
            // Store metadata as text
            text: JSON.stringify({
              id: img.identifier,
              date: img.date,
              caption: img.caption || "Earth view from DSCOVR satellite",
              imageUrl: imageUrl,
              centroid_coordinates: img.centroid_coordinates,
              dscovr_j2000_position: img.dscovr_j2000_position,
              lunar_j2000_position: img.lunar_j2000_position,
              sun_j2000_position: img.sun_j2000_position,
              attitude_quaternions: img.attitude_quaternions
            }),
            // Store actual image data as blob
            blob: Buffer.from(imageResponse.data)
          });
          
          // Keep data for direct response
          images.push({
            identifier: img.identifier,
            caption: img.caption || "Earth view from DSCOVR satellite",
            imageUrl: imageUrl,
            resourceUri: resourceUri,
            base64: imageBase64,
            mimeType: "image/png"
          });
        } catch (error) {
          console.error(`Error fetching EPIC image ${img.identifier}:`, error);
          
          // If fetch fails, register with just the metadata
          addResource(resourceUri, {
            name: `NASA EPIC Earth Image - ${img.identifier}`,
            mimeType: "image/png",
            text: JSON.stringify({
              id: img.identifier,
              date: img.date,
              caption: img.caption || "Earth view from DSCOVR satellite",
              imageUrl: imageUrl,
              centroid_coordinates: img.centroid_coordinates,
              dscovr_j2000_position: img.dscovr_j2000_position,
              lunar_j2000_position: img.lunar_j2000_position,
              sun_j2000_position: img.sun_j2000_position,
              attitude_quaternions: img.attitude_quaternions,
              fetch_error: (error as Error).message
            })
          });
          
          images.push({
            identifier: img.identifier,
            caption: img.caption || "Earth view from DSCOVR satellite",
            imageUrl: imageUrl,
            resourceUri: resourceUri,
            error: "Failed to fetch image data"
          });
        }
      }
      
      return {
        summary: `EPIC Earth imagery from ${date} - Collection: ${collection} - ${images.length} images available`,
        images: images
      };
    }
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 'views of Earth' but does not specify whether this is a read-only operation, what the output format is (e.g., images, metadata), or any constraints like rate limits or authentication needs. The description is minimal and lacks critical behavioral details for a tool with parameters.

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

Conciseness4/5

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

The description is very concise with a single phrase, making it efficient and front-loaded. However, it is under-specified rather than optimally concise, as it lacks necessary details for clarity and usage. Every word earns its place, but the description is too brief to be fully helpful.

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 has 2 parameters, no annotations, and no output schema, the description is incomplete. It does not explain what the tool returns (e.g., image URLs, metadata), how to interpret results, or any behavioral aspects. For a data retrieval tool with parameters, this minimal description leaves significant gaps in understanding.

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?

Schema description coverage is 100%, so the input schema fully documents the two parameters ('collection' and 'date'). The description adds no additional meaning beyond what the schema provides, such as explaining valid collection types or date ranges. With high schema coverage, the baseline score is 3, as the description does not compensate but also does not detract.

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

Purpose3/5

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

The description 'Earth Polychromatic Imaging Camera - views of Earth' identifies the resource (Earth imagery from EPIC) but lacks a specific action verb. It distinguishes from siblings like 'nasa_apod' or 'nasa_images' by specifying the EPIC source, but the purpose remains vague without stating what the tool does (e.g., retrieve, list, or display images).

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?

No guidance is provided on when to use this tool versus alternatives. The description does not mention context, prerequisites, or exclusions, and it fails to differentiate from sibling tools like 'nasa_images' or 'nasa_gibs' that might also provide Earth imagery. Usage is implied only by the tool name and description, with no explicit instructions.

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