nasa_donki
Access space weather event data from NASA's DONKI database to analyze solar activity, geomagnetic storms, and other space weather phenomena by specifying event type and date range.
Instructions
Space Weather Database Of Notifications, Knowledge, Information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | Yes | Type of space weather event | |
| startDate | No | Start date (YYYY-MM-DD) | |
| endDate | No | End date (YYYY-MM-DD) |
Implementation Reference
- src/handlers/nasa/donki.ts:9-91 (handler)The core handler function `nasaDonkiHandler` that implements the logic for the 'nasa_donki' tool. It validates the event type, constructs the API endpoint, fetches data from NASA's DONKI API using `nasaApiRequest`, creates a resource, and returns formatted content.export async function nasaDonkiHandler(params: DonkiParams) { try { const { type, startDate, endDate } = params; // Map the type to the appropriate endpoint const typeEndpoints: Record<string, string> = { cme: '/DONKI/CME', cmea: '/DONKI/CMEAnalysis', gst: '/DONKI/GST', ips: '/DONKI/IPS', flr: '/DONKI/FLR', sep: '/DONKI/SEP', mpc: '/DONKI/MPC', rbe: '/DONKI/RBE', hss: '/DONKI/HSS', wsa: '/DONKI/WSAEnlilSimulations', notifications: '/DONKI/notifications' }; const endpoint = typeEndpoints[type.toLowerCase()]; // Validate that the endpoint exists for the given type if (!endpoint) { return { isError: true, content: [{ type: "text", text: `Error: Invalid DONKI type "${type}". Valid types are: ${Object.keys(typeEndpoints).join(', ')}` }] }; } const queryParams: Record<string, any> = {}; // Add date parameters if provided if (startDate) queryParams.startDate = startDate; if (endDate) queryParams.endDate = endDate; // Call the NASA DONKI API const result = await nasaApiRequest(endpoint, queryParams); // Create a resource ID and register the resource const dateParams = []; if (startDate) dateParams.push(`start=${startDate}`); if (endDate) dateParams.push(`end=${endDate}`); const resourceId = `nasa://donki/${type}${dateParams.length > 0 ? '?' + dateParams.join('&') : ''}`; addResource(resourceId, { name: `DONKI ${type.toUpperCase()} Space Weather Data${startDate ? ` from ${startDate}` : ''}${endDate ? ` to ${endDate}` : ''}`, mimeType: 'application/json', text: JSON.stringify(result, null, 2) }); // Return the confirmation message and the actual data return { content: [ { type: "text", text: `Retrieved DONKI ${type.toUpperCase()} space weather data${startDate ? ` from ${startDate}` : ''}${endDate ? ` to ${endDate}` : ''}.` }, { type: "text", text: JSON.stringify(result, null, 2) } ], isError: false }; } catch (error: any) { console.error('Error in DONKI handler:', error); return { isError: true, content: [{ type: "text", text: `Error: ${error.message || 'An unexpected error occurred'}` }] }; } } // Export the handler function directly as default export default nasaDonkiHandler;
- src/handlers/setup.ts:108-112 (schema)Zod schema definition for DonkiParams used for input validation in the nasaDonkiHandler. Exported as donkiParamsSchema and typed as DonkiParams.const DonkiSchema = z.object({ type: z.enum(['cme', 'cmea', 'gst', 'ips', 'flr', 'sep', 'mpc', 'rbe', 'hss', 'wsa', 'notifications']), startDate: z.string().optional(), endDate: z.string().optional() });
- src/index.ts:1626-1638 (registration)Registers the MCP server request handler specifically for the 'nasa/donki' tool method, which dispatches parameters to the shared handleToolCall function.server.setRequestHandler( z.object({ method: z.literal("nasa/donki"), params: z.object({ type: z.string(), startDate: z.string().optional(), endDate: z.string().optional() }).optional() }), async (request) => { return await handleToolCall("nasa/donki", request.params || {}); } );
- src/index.ts:482-486 (registration)Lists the 'nasa_donki' tool in the tools/manifest response, providing its name, ID, and description.{ name: "nasa_donki", id: "nasa/donki", description: "Space Weather Database Of Notifications, Knowledge, Information" },
- src/index.ts:913-933 (registration)Registers the 'nasa_donki' tool in the tools/list response, including its inputSchema for MCP tool discovery.name: "nasa_donki", description: "Space Weather Database Of Notifications, Knowledge, Information", inputSchema: { type: "object", properties: { type: { type: "string", description: "Type of space weather event" }, startDate: { type: "string", description: "Start date (YYYY-MM-DD)" }, endDate: { type: "string", description: "End date (YYYY-MM-DD)" } }, required: ["type"] } },