Skip to content

Commit 5f36bf9

Browse files
committed
t
1 parent bfebc17 commit 5f36bf9

File tree

6 files changed

+556
-0
lines changed

6 files changed

+556
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

hackathon/nasa-mcp-python/README.md

Whitespace-only changes.
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[project]
2+
name = "nasa-mcp-python"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
dependencies = [
8+
"httpx>=0.28.1",
9+
"mcp[cli]>=1.13.0",
10+
]

hackathon/nasa-mcp-python/uv.lock

Lines changed: 490 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hackathon/nasa-mcp-python/weather.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from typing import Any
2+
import httpx
3+
from mcp.server.fastmcp import FastMCP
4+
5+
# Initialize FastMCP server
6+
mcp = FastMCP("nasa")
7+
8+
# Constants
9+
NASA_API_BASE = "https://api.nasa.gov"
10+
NASA_API_KEY = "<YOUR_NASA_API_KEY>"
11+
12+
async def make_nasa_request(url: str) -> dict[str, Any] | None:
13+
"""Make a request to the NASA API with proper error handling."""
14+
params = {"api_key": NASA_API_KEY}
15+
async with httpx.AsyncClient() as client:
16+
try:
17+
response = await client.get(url, params=params, timeout=30.0)
18+
response.raise_for_status()
19+
return response.json()
20+
except Exception:
21+
return None
22+
23+
@mcp.tool()
24+
async def get_astronomy_picture_of_day(date: str = None) -> str:
25+
"""Get NASA's Astronomy Picture of the Day (APOD).
26+
27+
Args:
28+
date: Optional date in YYYY-MM-DD format. If not provided, returns today's image.
29+
"""
30+
url = f"{NASA_API_BASE}/planetary/apod"
31+
32+
if date:
33+
url += f"?date={date}"
34+
35+
data = await make_nasa_request(url)
36+
37+
if not data:
38+
return "Unable to fetch APOD data from NASA API."
39+
40+
# Format the response
41+
result = f"""
42+
🌌 NASA Astronomy Picture of the Day
43+
44+
📅 Date: {data.get('date', 'Unknown')}
45+
📝 Title: {data.get('title', 'Unknown')}
46+
👨‍🚀 Author: {data.get('copyright', 'NASA')}
47+
📖 Explanation: {data.get('explanation', 'No explanation available')}
48+
🔗 HD Image: {data.get('hdurl', 'Not available')}
49+
🔗 Standard Image: {data.get('url', 'Not available')}
50+
"""
51+
52+
return result
53+
54+
if __name__ == "__main__":
55+
mcp.run(transport='stdio')

0 commit comments

Comments
 (0)