Skip to main content
Glama

get_earth_imagery

Retrieve Landsat 8 satellite imagery for specific coordinates, date, and dimensions. Use to access visual Earth data by inputting latitude, longitude, and optional parameters for detailed analysis.

Instructions

Get Earth imagery from Landsat 8 satellite.

Args: lat: Latitude. lon: Longitude. date: Image date in YYYY-MM-DD format. If not specified, the most recent image is used. dim: Width and height of the image in degrees (0.025 degrees is approximately 2.7 km). cloud_score: Calculate the percentage of the image covered by clouds (currently not available).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cloud_scoreNo
dateNo
dimNo
latYes
lonYes

Implementation Reference

  • Main handler function for the 'get_earth_imagery' tool. Fetches imagery from NASA's Earth imagery API endpoint, handles parameters like lat, lon, date, dim, and cloud_score. Uses make_nasa_request helper and processes both JSON metadata and potential binary image responses.
    async def get_earth_imagery(lat: float, lon: float, date: str = None, dim: float = 0.025, cloud_score: bool = False) -> str: """Get Earth imagery from Landsat 8 satellite. Args: lat: Latitude. lon: Longitude. date: Image date in YYYY-MM-DD format. If not specified, the most recent image is used. dim: Width and height of the image in degrees (0.025 degrees is approximately 2.7 km). cloud_score: Calculate the percentage of the image covered by clouds (currently not available). """ params = { "lat": lat, "lon": lon, "dim": dim } if date: params["date"] = date # cloud_score parameter seems deprecated or unavailable based on docs # if cloud_score: # params["cloud_score"] = "True" url = f"{NASA_API_BASE}/planetary/earth/imagery" data = await make_nasa_request(url, params) if not data: return "Could not retrieve Earth imagery due to a connection error." # Check for error response (must be a dictionary) if isinstance(data, dict) and "error" in data: # Handle specific case where API returns error message instead of image/JSON if isinstance(data.get("details"), str) and "No Landsat 8 imagery available" in data["details"]: return f"No Landsat 8 imagery available for the specified location and date (Lat: {lat}, Lon: {lon}, Date: {date or 'latest'})." return f"API Error: {data.get('error')} - Details: {data.get('details', 'N/A')}" # Handle binary content if isinstance(data, dict) and data.get("binary_content"): # The API returned the image directly return f"Received image data directly ({data.get('content_type')}). Cannot display image content, but the image is available at the requested URL: {data.get('url')}" # If it's not binary, it should be JSON containing the URL try: result = [ f"Earth image metadata for coordinates: Lat {lat}, Lon {lon}", f"Date: {data.get('date', 'Unknown')}", f"ID: {data.get('id', 'Unknown')}", f"Image URL: {data.get('url', 'Not available')}" # This URL should point to the image ] # Cloud score might be present in JSON even if binary isn't returned if 'cloud_score' in data and data['cloud_score'] is not None: # Check for None explicitly result.append(f"Cloud score: {data.get('cloud_score')}") else: result.append("Cloud score: Not available") return "n".join(result) except Exception as e: logger.error(f"Error processing Earth Imagery JSON data: {str(e)}") return f"Error processing Earth imagery data: {str(e)}"
  • Shared helper function used by get_earth_imagery (and other tools) to make HTTP requests to NASA APIs, handling JSON parsing, binary image detection, errors, and API key injection.
    async def make_nasa_request(url: str, params: dict = None) -> Union[dict[str, Any], List[Any], None]: """Make a request to the NASA API with proper error handling. Handles both JSON and binary (image) responses. """ logger.info(f"Making request to: {url} with params: {params}") if params is None: params = {} # Ensure API key is included in parameters if "api_key" not in params: params["api_key"] = API_KEY async with httpx.AsyncClient() as client: try: response = await client.get(url, params=params, timeout=30.0, follow_redirects=True) response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx) content_type = response.headers.get("Content-Type", "").lower() if "application/json" in content_type: try: return response.json() except json.JSONDecodeError as json_err: logger.error(f"JSON decode error for URL {response.url}: {json_err}") logger.error(f"Response text: {response.text[:500]}") # Log beginning of text return {"error": "Failed to decode JSON response", "details": str(json_err)} elif content_type.startswith("image/"): logger.info(f"Received binary image content ({content_type}) from {response.url}") # Return a dictionary indicating binary content was received return { "binary_content": True, "content_type": content_type, "url": str(response.url) # Return the final URL after redirects } else: # Handle other unexpected content types logger.warning(f"Unexpected content type '{content_type}' received from {response.url}") return {"error": f"Unexpected content type: {content_type}", "content": response.text[:500]} except httpx.HTTPStatusError as http_err: logger.error(f"HTTP error occurred: {http_err} - {http_err.response.status_code} for URL {http_err.request.url}") try: # Try to get more details from response body if possible error_details = http_err.response.json() except Exception: error_details = http_err.response.text[:500] return {"error": f"HTTP error: {http_err.response.status_code}", "details": error_details} except httpx.RequestError as req_err: logger.error(f"Request error occurred: {req_err} for URL {req_err.request.url}") return {"error": "Request failed", "details": str(req_err)} except Exception as e: logger.error(f"An unexpected error occurred: {str(e)}") return {"error": "An unexpected error occurred", "details": str(e)}
  • The @mcp.tool() decorator registers the get_earth_imagery function as an MCP tool in the FastMCP server.
    async def get_earth_imagery(lat: float, lon: float, date: str = None, dim: float = 0.025, cloud_score: bool = False) -> str:
  • Input schema/arguments and description defined in the function docstring, used by FastMCP for tool schema generation.
    Args: lat: Latitude. lon: Longitude. date: Image date in YYYY-MM-DD format. If not specified, the most recent image is used. dim: Width and height of the image in degrees (0.025 degrees is approximately 2.7 km). cloud_score: Calculate the percentage of the image covered by clouds (currently not available). """

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/AnCode666/nasa-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server