Skip to main content
Glama

nasa_mars_rover

Access and retrieve Mars rover photos by specifying rover name, date, and camera to explore Martian terrain through NASA's image database.

Instructions

NASA Mars Rover Photos - images from Mars rovers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
roverYesName of the rover (curiosity, opportunity, spirit, perseverance)
solNoMartian sol (day) of the photos
earth_dateNoEarth date of the photos (YYYY-MM-DD)
cameraNoCamera name
pageNoPage number for pagination

Implementation Reference

  • Main handler function that executes the nasa_mars_rover tool: validates params, calls NASA API, processes results.
    export async function nasaMarsRoverHandler(params: MarsRoverParams) {
      try {
        const { rover, ...queryParams } = params;
        
        // Call the NASA Mars Rover Photos API
        const result = await nasaApiRequest(`/mars-photos/api/v1/rovers/${rover}/photos`, queryParams);
        
        // Process the results and register resources
        return processRoverResults(result, rover);
      } catch (error: any) {
        console.error('Error in Mars Rover handler:', error);
        
        if (error.name === 'ZodError') {
          return {
            content: [{
              type: "text",
              text: `Invalid request parameters: ${JSON.stringify(error.errors)}`
            }],
            isError: true
          };
        }
        
        return {
          content: [{
            type: "text",
            text: `Error fetching Mars Rover photos: ${error.message || 'Unknown error'}`
          }],
          isError: true
        };
      }
    }
  • Helper function to process rover API results: fetches images, registers nasa://mars_rover/photo resources, formats MCP response.
    async function processRoverResults(data: any, rover: string) {
      const photos = data.photos || [];
      const resources = [];
      // Collect base64 image data for direct display
      const images: Array<{ title: string; url: string; data: string; mimeType: string }> = [];
      
      if (photos.length === 0) {
        return {
          content: [{
            type: "text",
            text: `No photos found for rover ${rover} with the specified parameters.`
          }],
          isError: false
        };
      }
      
      // Register each photo as a resource
      for (const photo of photos) {
        const photoId = photo.id.toString();
        const resourceUri = `nasa://mars_rover/photo?rover=${rover}&id=${photoId}`;
        
        try {
          // Fetch the actual image data
          const imageResponse = await axios({
            url: photo.img_src,
            responseType: 'arraybuffer',
            timeout: 30000
          });
          
          // Convert image data to Base64
          const imageBase64 = Buffer.from(imageResponse.data).toString('base64');
          
          // Register the resource with binary data in the blob field
          addResource(resourceUri, {
            name: `Mars Rover Photo ${photoId}`,
            mimeType: "image/jpeg",
            // Store metadata as text for reference
            text: JSON.stringify({
              photo_id: photoId,
              rover: rover,
              camera: photo.camera?.name || 'Unknown',
              earth_date: photo.earth_date,
              sol: photo.sol,
              img_src: photo.img_src
            }),
            // Store the actual image data as a blob
            blob: Buffer.from(imageResponse.data)
          });
          // Keep base64 data for direct response
          images.push({ title: `Mars Rover Photo ${photoId}`, url: photo.img_src, data: imageBase64, mimeType: "image/jpeg" });
        } catch (error) {
          console.error(`Error fetching image for rover photo ${photoId}:`, error);
          
          // If fetching fails, register with just the metadata and URL
          addResource(resourceUri, {
            name: `Mars Rover Photo ${photoId}`,
            mimeType: "image/jpeg",
            text: JSON.stringify({
              photo_id: photoId,
              rover: rover,
              camera: photo.camera?.name || 'Unknown',
              img_src: photo.img_src,
              earth_date: photo.earth_date,
              sol: photo.sol,
              fetch_error: (error as Error).message
            })
          });
        }
        
        resources.push({
          title: `Mars Rover Photo ${photoId}`,
          description: `Photo taken by ${rover} rover on Mars`,
          resource_uri: resourceUri
        });
      }
      
      // Format the response for MCP
      return {
        content: [
          {
            type: "text",
            text: `Found ${photos.length} photos from Mars rover ${rover}.`
          },
          {
            type: "text",
            text: JSON.stringify(resources, null, 2)
          },
          // Include direct image links and binary data
          ...images.map(img => ({ type: "text", text: `![${img.title}](${img.url})` })),
          ...images.map(img => ({ type: "image", data: img.data, mimeType: img.mimeType })),
        ],
        isError: false
      };
    }
  • Zod schema defining input parameters for Mars Rover tool (MarsRoverParams), imported and used by handler.
    const MarsRoverSchema = z.object({
      rover: z.enum(['curiosity', 'opportunity', 'perseverance', 'spirit']),
      sol: z.number().int().nonnegative().optional(),
      earth_date: z.string().optional(),
      camera: z.string().optional(),
      page: z.number().int().positive().optional()
    });
  • src/index.ts:1526-1540 (registration)
    Registers direct MCP request handler for method 'nasa/mars-rover', validates params inline, dispatches to handleToolCall.
    server.setRequestHandler(
      z.object({ 
        method: z.literal("nasa/mars-rover"),
        params: z.object({
          rover: z.enum(['curiosity', 'opportunity', 'perseverance', 'spirit']),
          sol: z.number().int().nonnegative().optional(),
          earth_date: z.string().optional(),
          camera: z.string().optional(),
          page: z.number().int().positive().optional()
        }).optional()
      }),
      async (request) => {
        return await handleToolCall("nasa/mars-rover", request.params || {});
      }
    );
  • src/index.ts:935-963 (registration)
    Registers 'nasa_mars_rover' tool in tools/list response with full input schema definition.
      name: "nasa_mars_rover",
      description: "NASA Mars Rover Photos - images from Mars rovers",
      inputSchema: {
        type: "object",
        properties: {
          rover: {
            type: "string",
            description: "Name of the rover (curiosity, opportunity, spirit, perseverance)"
          },
          sol: {
            type: "number",
            description: "Martian sol (day) of the photos"
          },
          earth_date: {
            type: "string",
            description: "Earth date of the photos (YYYY-MM-DD)"
          },
          camera: {
            type: "string",
            description: "Camera name"
          },
          page: {
            type: "number",
            description: "Page number for pagination"
          }
        },
        required: ["rover"]
      }
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions retrieving photos but doesn't cover key traits like whether it's a read-only operation, rate limits, authentication needs, pagination behavior (implied by 'page' parameter but not explained), or error handling. 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.

Conciseness4/5

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

The description is concise with a single sentence that directly states the tool's purpose. It's front-loaded and wastes no words, though it could be slightly more informative without losing efficiency.

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 complexity (5 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain return values, behavioral constraints, or usage context, making it inadequate for an agent to fully understand how to invoke and interpret results from this tool.

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 schema fully documents all parameters. The description adds no additional meaning beyond implying photo retrieval, which is already clear from the tool name and schema. Baseline score of 3 is appropriate as the schema handles the heavy lifting.

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 states the tool retrieves 'images from Mars rovers', which is a clear purpose, but it's vague about the specific action (e.g., 'fetch', 'search', 'retrieve') and doesn't differentiate from sibling tools like 'nasa_images' or 'nasa_apod', which might also handle images. It's not tautological but lacks specificity.

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, such as other NASA tools for images or data. The description doesn't mention prerequisites, exclusions, or context for selection, leaving the agent without usage direction.

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