nasa_epic
Access high-resolution Earth images by specifying a date and collection type (natural or enhanced). Utilize NASA's data integration to visualize Earth from space.
Instructions
Earth Polychromatic Imaging Camera - views of Earth
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | No | Image collection (natural or enhanced) | |
| date | No | Date of the image (YYYY-MM-DD) |
Implementation Reference
- src/handlers/nasa/epic.ts:131-199 (handler)nasaEpicHandler: Main handler function that fetches EPIC data from NASA API, processes images, creates resources, and returns formatted MCP content.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: `` })), // Direct image URL markdown entries ...results.images.map(img => ({ type: "text", text: `` })), // 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 }; } }
- src/handlers/nasa/epic.ts:11-14 (schema)epicParamsSchema: Zod validation schema for the tool input parameters (collection and date).export const epicParamsSchema = z.object({ collection: z.enum(['natural', 'enhanced']).optional().default('natural'), date: z.string().optional(), });
- src/handlers/nasa/epic.ts:25-126 (helper)processEpicResults: Helper function to process raw EPIC API data, fetch image binaries, register resources, and prepare formatted 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 }; }
- src/index.ts:1511-1523 (registration)MCP server request handler registration for the 'nasa/epic' method, which dynamically loads and calls the 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:433-550 (registration)tools/manifest handler that lists 'nasa_epic' as an available tool API.server.setRequestHandler( z.object({ method: z.literal("tools/manifest"), params: z.object({}).optional() }), async () => { // Return all tools we support in the MCP required format return { apis: [ { name: "nasa_apod", id: "nasa/apod", description: "Fetch NASA's Astronomy Picture of the Day" }, { name: "nasa_neo", id: "nasa/neo", description: "Information about asteroids and near-Earth objects" }, { name: "nasa_epic", id: "nasa/epic", description: "Earth Polychromatic Imaging Camera views of Earth" }, { name: "nasa_gibs", id: "nasa/gibs", description: "Global Imagery Browse Services satellite imagery" }, { name: "nasa_cmr", id: "nasa/cmr", description: "Search NASA's Common Metadata Repository for satellite data" }, { name: "nasa_firms", id: "nasa/firms", description: "Fire Information for Resource Management System" }, { name: "nasa_images", id: "nasa/images", description: "Search NASA's image and video library" }, { name: "nasa_exoplanet", id: "nasa/exoplanet", description: "Access NASA's Exoplanet Archive data" }, { name: "nasa_donki", id: "nasa/donki", description: "Space Weather Database Of Notifications, Knowledge, Information" }, { name: "nasa_mars_rover", id: "nasa/mars-rover", description: "Browse photos from NASA's Mars rovers" }, { name: "nasa_eonet", id: "nasa/eonet", description: "Earth Observatory Natural Event Tracker" }, { name: "nasa_power", id: "nasa/power", description: "Prediction of Worldwide Energy Resources" }, { name: "jpl_sbdb", id: "jpl/sbdb", description: "Small-Body DataBase (SBDB) - primarily orbital data on all known asteroids and comets" }, { name: "jpl_fireball", id: "jpl/fireball", description: "Fireball atmospheric impact data reported by US Government sensors" }, { name: "jpl_jd_cal", id: "jpl/jd_cal", description: "Julian Day number to/from calendar date/time converter" }, { name: "jpl_nhats", id: "jpl/nhats", description: "Human-accessible NEOs (Near-Earth Objects) data" }, { name: "jpl_cad", id: "jpl/cad", description: "Asteroid and comet close approaches to the planets in the past and future" }, { name: "jpl_sentry", id: "jpl/sentry", description: "JPL Sentry - NEO Earth impact risk assessment data" }, { name: "jpl_horizons", id: "jpl/horizons", description: "JPL Horizons - Solar system objects ephemeris data" }, { name: "jpl_scout", id: "jpl/scout", description: "NEOCP orbits, ephemerides, and impact risk data (Scout)" }, // { // name: "nasa_earth", // id: "nasa/earth", // description: "Earth - Landsat satellite imagery and data" // } ] }; } );
- src/index.ts:750-765 (registration)tools/list entry registering 'nasa_epic' tool with input schema.name: "nasa_epic", description: "Earth Polychromatic Imaging Camera - views of Earth", inputSchema: { type: "object", properties: { collection: { type: "string", description: "Image collection (natural or enhanced)" }, date: { type: "string", description: "Date of the image (YYYY-MM-DD)" } } } },