nasa_firms
Retrieve fire detection data for specific coordinates to monitor wildfire activity and support resource management decisions.
Instructions
NASA Fire Information for Resource Management System - fire data
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| latitude | Yes | Latitude coordinate | |
| longitude | Yes | Longitude coordinate | |
| days | No | Number of days of data to retrieve |
Implementation Reference
- src/handlers/nasa/firms.ts:22-124 (handler)The nasaFirmsHandler function implements the core logic for the nasa_firms tool. It validates parameters, calls the NASA FIRMS API, parses CSV response into JSON, registers a resource, and returns formatted content.export async function nasaFirmsHandler(params: FirmsParams) { try { const { latitude, longitude, radius, days, source } = params; // Validate required parameters if (!process.env.NASA_API_KEY) { return { isError: true, content: [{ type: "text", text: "Error: NASA API key is required for FIRMS requests" }] }; } // Get the NASA API key from environment variables const apiKey = process.env.NASA_API_KEY; // Construct request URL const url = FIRMS_API_BASE_URL; // Send request to FIRMS API const response = await axios.get(url, { params: { lat: latitude, lon: longitude, radius: radius, days: days, source: source, api_key: apiKey } }); // Parse the CSV response into a structured format const csvData = response.data; const rows = csvData.split('\n'); if (rows.length < 2) { return { results: [] }; } const headers = rows[0].split(','); const results = rows.slice(1) .filter((row: string) => row.trim() !== '') .map((row: string) => { const values = row.split(','); const entry: Record<string, string | number> = {}; headers.forEach((header: string, index: number) => { const value = values[index] ? values[index].trim() : ''; // Try to convert numeric values const numValue = Number(value); entry[header] = !isNaN(numValue) && value !== '' ? numValue : value; }); return entry; }); // Register the response as a resource const resourceId = `nasa://firms/data?lat=${latitude}&lon=${longitude}&days=${days}&source=${source}`; const resourceData = { metadata: { latitude, longitude, radius, days, source }, results }; addResource(resourceId, { name: `Fire Data near (${latitude}, ${longitude}) for the past ${days} day(s)`, mimeType: 'application/json', text: JSON.stringify(resourceData, null, 2) }); // Return data in MCP format return { content: [ { type: "text", text: `Found ${results.length} fire hotspots near (${latitude}, ${longitude}) in the past ${days} day(s)` }, { type: "text", text: JSON.stringify(results, null, 2) } ], isError: false }; } catch (error: any) { console.error('Error in FIRMS handler:', error); return { isError: true, content: [{ type: "text", text: `Error: ${error.message || 'An unexpected error occurred'}` }] }; } }
- src/handlers/nasa/firms.ts:8-14 (schema)Zod schema defining input parameters for the nasa_firms tool handler.export const firmsParamsSchema = z.object({ latitude: z.number(), longitude: z.number(), radius: z.number().optional().default(1.0), days: z.number().int().min(1).max(10).optional().default(1), source: z.enum(['VIIRS_SNPP_NRT', 'MODIS_NRT', 'VIIRS_NOAA20_NRT']).optional().default('VIIRS_SNPP_NRT') });
- src/index.ts:1577-1589 (registration)Registers the specific MCP request handler for the 'nasa/firms' method, which delegates execution to the general handleToolCall function.server.setRequestHandler( z.object({ method: z.literal("nasa/firms"), params: z.object({ days: z.number().optional(), latitude: z.number().optional(), longitude: z.number().optional() }).optional() }), async (request) => { return await handleToolCall("nasa/firms", request.params || {}); } );
- src/index.ts:468-471 (registration)Registers the nasa_firms tool in the tools/manifest response, listing it with name, id, and description.name: "nasa_firms", id: "nasa/firms", description: "Fire Information for Resource Management System" },
- src/index.ts:1866-1885 (helper)Dynamic import and invocation of the nasa/firms handler module within the general handleToolCall function used by all tools.const handlerModule = await import(`./handlers/nasa/${endpoint}.js`); serverInstance?.sendLoggingMessage({ level: "info", data: `Successfully imported handler module for: ./handlers/nasa/${endpoint}.js`, }); // Try different potential handler function names const handlerFunctionName = `nasa${endpoint.charAt(0).toUpperCase() + endpoint.slice(1).replace(/-/g, '_')}Handler`; // e.g. nasaMars_roverHandler const simpleHandlerName = `${endpoint.replace(/-/g, '_')}Handler`; // e.g. mars_roverHandler const handlerFunction = handlerModule.default || handlerModule[handlerFunctionName] || handlerModule[simpleHandlerName]; if (typeof handlerFunction === 'function') { serverInstance?.sendLoggingMessage({ level: "info", data: `Executing handler function for ${endpoint}`, }); return await handlerFunction(args);