Skip to main content
Glama

nasa_apod

Fetch NASA's Astronomy Picture of the Day for specific dates, date ranges, or random selections to access space imagery and explanations.

Instructions

Fetch NASA's Astronomy Picture of the Day

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateYesThe date of the APOD image to retrieve (YYYY-MM-DD)
countNoCount of random APODs to retrieve
start_dateNoStart date for date range search (YYYY-MM-DD)
end_dateNoEnd date for date range search (YYYY-MM-DD)
thumbsNoReturn URL of thumbnail for video content

Implementation Reference

  • The core handler function for the 'nasa_apod' tool. Fetches data from NASA's APOD API using nasaApiRequest, processes the result with base64 image encoding, adds resources, and returns formatted content including text summary and embeddable images.
    export async function nasaApodHandler(params: ApodParams) {
      try {
        // Call the NASA APOD API
        const result = await nasaApiRequest('/planetary/apod', params);
        
        // Store results as resources
        const processedResult = await processApodResultWithBase64(result);
        
        return {
          content: [
            {
              type: "text",
              text: processedResult.summary
            },
            ...processedResult.images.map(img => ({
              type: "text",
              text: `![${img.title}](${img.url})`
            })),
            ...processedResult.images.map(img => ({
              type: "image",
              data: img.base64,
              mimeType: img.mimeType || "image/jpeg"
            }))
          ],
          isError: false
        };
      } catch (error: any) {
        console.error('Error in APOD handler:', error);
        
        return {
          content: [
            {
              type: "text",
              text: `Error retrieving APOD data: ${error.message}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters for the nasa_apod tool, including optional date, hd, count, date range, and thumbs.
    export const apodParamsSchema = z.object({
      date: z.string().optional(),
      hd: z.boolean().optional(),
      count: z.number().int().positive().optional(),
      start_date: z.string().optional(),
      end_date: z.string().optional(),
      thumbs: z.boolean().optional()
    });
  • src/index.ts:697-726 (registration)
    Tool registration in the tools/list handler response. Defines the 'nasa_apod' tool name, description, and input schema for MCP tool discovery.
    {
      name: "nasa_apod",
      description: "Fetch NASA's Astronomy Picture of the Day",
      inputSchema: {
        type: "object",
        properties: {
          date: {
            type: "string",
            description: "The date of the APOD image to retrieve (YYYY-MM-DD)"
          },
          count: {
            type: "number",
            description: "Count of random APODs to retrieve"
          },
          start_date: {
            type: "string",
            description: "Start date for date range search (YYYY-MM-DD)"
          },
          end_date: {
            type: "string",
            description: "End date for date range search (YYYY-MM-DD)"
          },
          thumbs: {
            type: "boolean",
            description: "Return URL of thumbnail for video content"
          }
        },
        required: ["date"]
      }
    },
  • Supporting function that processes APOD API results: generates summary markdown, adds JSON resources, fetches images via axios, encodes to base64 for embedding, and detects MIME types.
    async function processApodResultWithBase64(result: any) {
      const results = Array.isArray(result) ? result : [result];
      let summary = '';
      const images: any[] = [];
      for (const apod of results) {
        const apodId = `nasa://apod/image?date=${apod.date}`;
        let mimeType = 'image/jpeg';
        if (apod.url) {
          if (apod.url.endsWith('.png')) mimeType = 'image/png';
          else if (apod.url.endsWith('.gif')) mimeType = 'image/gif';
          else if (apod.url.endsWith('.jpg') || apod.url.endsWith('.jpeg')) mimeType = 'image/jpeg';
        }
        addResource(apodId, {
          name: `Astronomy Picture of the Day - ${apod.title}`,
          mimeType: 'application/json',
          text: JSON.stringify(apod, null, 2)
        });
        summary += `## ${apod.title} (${apod.date})\n\n${apod.explanation}\n\n`;
        if (apod.url && (!apod.media_type || apod.media_type === 'image')) {
          summary += `Image URL: ${apod.url}\n\n`;
          let base64 = null;
          try {
            const imageResponse = await axios.get(apod.url, { responseType: 'arraybuffer', timeout: 30000 });
            base64 = Buffer.from(imageResponse.data).toString('base64');
          } catch (err) {
            console.error('Failed to fetch APOD image for base64:', apod.url, err);
          }
          images.push({
            url: apod.url,
            title: apod.title,
            resourceUri: apodId,
            mimeType,
            base64
          });
        }
      }
      return {
        summary,
        images
      };
    }
  • src/index.ts:1480-1494 (registration)
    Direct MCP request handler registration for the 'nasa/apod' method, which validates params with Zod schema matching apodParamsSchema and delegates execution to the general handleToolCall function.
    server.setRequestHandler(
      z.object({ 
        method: z.literal("nasa/apod"),
        params: z.object({
          date: z.string().optional(),
          start_date: z.string().optional(),
          end_date: z.string().optional(),
          count: z.number().optional(),
          thumbs: z.boolean().optional()
        }).optional()
      }),
      async (request) => {
        return await handleToolCall("nasa/apod", request.params || {});
      }
    );
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. It states 'fetch', implying a read operation, but does not disclose behavioral traits like rate limits, authentication needs, response format, or whether it's a safe operation. This is a significant gap for a tool with no annotation coverage.

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 with zero waste, front-loaded and appropriately sized for its purpose. Every word earns its place, making it highly concise and well-structured.

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 no annotations and no output schema, the description is incomplete. It does not explain return values, error handling, or behavioral context, which is inadequate for a tool with 5 parameters and potential complexity in fetching data. More detail is needed to compensate for the lack of structured data.

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 5 parameters. The description adds no additional meaning beyond the schema, such as explaining interactions between parameters (e.g., 'date' vs. 'start_date'/'end_date'). Baseline 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.

Purpose4/5

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

The description clearly states the verb 'fetch' and the resource 'NASA's Astronomy Picture of the Day', making the purpose specific and understandable. However, it does not differentiate from sibling tools like 'nasa_images' or 'nasa_epic', which might also fetch NASA images, so it lacks explicit sibling distinction.

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, such as sibling tools like 'nasa_images' or 'nasa_epic'. There is no mention of context, exclusions, or prerequisites, leaving usage entirely implied.

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