Skip to main content
Glama

nasa_apod

Retrieve NASA's Astronomy Picture of the Day (APOD) by specifying a date, date range, or random count, including video thumbnails, using the NASA MCP Server.

Instructions

Fetch NASA's Astronomy Picture of the Day

Input Schema

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

Implementation Reference

  • Main execution logic for the 'nasa_apod' tool. Fetches data from NASA APOD API, processes results including base64 image encoding, formats response with text summary and 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 input parameters for the nasa_apod tool, including date range, count, HD, thumbs options.
    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() });
  • Supporting function that processes APOD API response: adds resources, generates summary, fetches and encodes images to base64 for direct embedding.
    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:1479-1494 (registration)
    Registers the specific MCP request handler for method 'nasa/apod', which dispatches to the generic handleToolCall.
    // APOD Handler 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 || {}); } );
  • src/index.ts:697-725 (registration)
    Registers 'nasa_apod' tool in the tools/list response, including description and input schema.
    { 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"] }

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