A comprehensive Model Context Protocol (MCP) server providing access to NASA's open APIs, including astronomy imagery, Mars rover photos, asteroid tracking, Earth observations, and NASA's media library.
- Daily astronomy images with scientific explanations
- Historical APOD lookup by date or date range
- Random APOD discovery
- High-resolution image support
- Photos from all active and historical rovers (Curiosity, Perseverance, Opportunity, Spirit)
- Search by Martian sol (day) or Earth date
- Multiple camera support (FHAZ, RHAZ, MAST, CHEMCAM, etc.)
- Latest mission updates and rover manifests
- Real-time asteroid approach tracking
- Potentially hazardous asteroid identification
- Detailed orbital and physical characteristics
- Comprehensive asteroid database browsing
- Search NASA's vast image and video collection
- High-resolution space imagery
- Historical mission photography
- Educational content discovery
- Smart caching (30min for images, 10min for dynamic data)
- Rate limit awareness and management
- Comprehensive error handling
- Multi-tier caching strategy
- Python 3.8+
- NASA API key (get free at api.nasa.gov)
- pip or uv package manager
- Clone the project:
git clone https://github.com/jezweb/nasa-mcp-server.git
cd nasa-mcp-server- Install dependencies:
pip install -r requirements.txt- Configure environment:
cp .env.example .env
# Edit .env with your NASA API key- Run the server:
# STDIO transport (default)
python nasa_server.py
# HTTP transport
TRANSPORT=http PORT=8000 python nasa_server.py
# Development with FastMCP
fastmcp dev nasa_server.py
# Test the server
python nasa_server.py --testGet today's Astronomy Picture of the Day or specific date.
Parameters:
date_str(optional): Date in YYYY-MM-DD formathd(bool): Request high-definition image URL (default: true)include_concepts(bool): Include concept tags (default: false)
Example:
{
"date_str": "2024-01-15",
"hd": true,
"include_concepts": false
}Get random APOD images for discovery.
Parameters:
count(int): Number of random images (1-100, default: 5)
Get APOD images for a date range.
Parameters:
start_date(str): Start date in YYYY-MM-DD formatend_date(str): End date in YYYY-MM-DD format (max 7 days)hd(bool): Request high-definition images (default: true)
Get Mars rover photos by Martian sol (day).
Parameters:
rover(str): Rover name (curiosity, perseverance, opportunity, spirit)sol(int): Martian sol number (default: 1000)camera(optional): Camera abbreviation (fhaz, rhaz, mast, chemcam, etc.)page(int): Page number for pagination (default: 1)
Example:
{
"rover": "curiosity",
"sol": 3000,
"camera": "mast"
}Get Mars rover photos by Earth date.
Parameters:
rover(str): Rover name (default: "curiosity")earth_date(optional): Date in YYYY-MM-DD format (defaults to today)camera(optional): Camera abbreviation
Get the latest photos from a Mars rover.
Parameters:
rover(str): Rover name (default: "curiosity")camera(optional): Camera abbreviation
Get Mars rover mission information and photo availability.
Parameters:
rover(str): Rover name (default: "curiosity")
Get asteroids approaching Earth within a date range.
Parameters:
start_date(optional): Start date in YYYY-MM-DD format (defaults to today)end_date(optional): End date in YYYY-MM-DD format (max 7 days from start)detailed(bool): Include detailed orbital data (default: false)
Example:
{
"start_date": "2024-08-18",
"end_date": "2024-08-25",
"detailed": true
}Look up specific asteroid by NASA JPL ID.
Parameters:
asteroid_id(str): NASA JPL small body database ID
Browse the Near Earth Objects database.
Parameters:
page(int): Page number (0-based, default: 0)size(int): Results per page (max 20, default: 20)
Search NASA's image and video library.
Parameters:
query(str): Search termsmedia_type(str): Type of media (image, video, audio) (default: "image")page(int): Page number (default: 1)page_size(int): Results per page (max 100, default: 100)
Example:
{
"query": "apollo moon landing",
"media_type": "image",
"page": 1,
"page_size": 20
}Get API status, usage statistics, and rate limiting information.
Get cache performance statistics for both image and dynamic caches.
Get detailed information about all Mars rovers, their cameras, and capabilities.
Generate comprehensive space exploration analysis for any topic.
Parameters:
topic(str): Space exploration topic to analyze
Create detailed Mars rover mission reports.
Parameters:
rover(str): Rover name (default: "curiosity")
Generate asteroid monitoring and threat assessment reports.
Parameters:
days_ahead(int): Days to monitor (default: 30)
Generate comprehensive daily space exploration briefings.
Edit the .env file to customize server behavior:
# API Configuration
API_KEY=your_nasa_api_key_here
DEFAULT_COUNT=10
# Cache Settings
CACHE_TTL_IMAGES=1800 # 30 minutes
CACHE_TTL_DYNAMIC=600 # 10 minutes
# Rate Limiting
MAX_HOURLY_CALLS=1000 # For registered API keys
DEMO_HOURLY_LIMIT=30 # For DEMO_KEY
# Server Settings
LOG_LEVEL=INFO
TRANSPORT=stdio
PORT=8000- Free Tier (DEMO_KEY): 30 requests/hour, 50/day per IP
- Registered Key: 1,000 requests/hour (free signup at api.nasa.gov)
fastmcp install claude-desktop nasa_server.py- Create GitHub repository:
git init
git add .
git commit -m "NASA MCP Server"
gh repo create nasa-mcp-server --public
git push -u origin main-
Deploy on fastmcp.cloud:
- Sign in with GitHub
- Create new project from repository
- Set entrypoint:
nasa_server.py - Add environment variables from
.env - Deploy
-
Connect to Claude Desktop:
{
"mcpServers": {
"nasa": {
"url": "https://your-project.fastmcp.app/mcp",
"transport": "http"
}
}
}"Analyze the current status of Mars exploration missions and show me recent rover discoveries."
"What potentially hazardous asteroids are approaching Earth in the next 30 days?"
"Give me today's space exploration update including APOD, Mars photos, and Earth imagery."
"Show me APOD images from the Apollo 11 anniversary week in July 2019."
"Compare the latest photos from Curiosity and Perseverance rovers, what are they currently investigating?"
"Search NASA's media library for educational content about black holes and show me the most relevant images."
# Run test mode
python nasa_server.py --test
# Test with FastMCP client
fastmcp dev nasa_server.pyEnable debug logging in .env:
LOG_LEVEL=DEBUGThe server is modular and extensible:
- Add new tools by creating
@mcp.tooldecorated functions - Add new resources using
@mcp.resource(uri)decorators - Add new prompts using
@mcp.prompt(name)decorators - Update configuration in
Configclass - Add caching strategy for new endpoints
- DEMO_KEY: 30 requests/hour, 50/day per IP address
- Registered Key: 1,000 requests/hour
- Caching: 30 minutes for images, 10 minutes for dynamic data
- Batch Requests: Use date ranges and pagination wisely
- Error Handling: Server gracefully handles API limits and errors
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Update documentation
- Submit a pull request
MIT License - see LICENSE file for details.
Explore the universe with NASA's data! ππβ¨