TerraLuna-MCP
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
๐ TerraLuna: Autonomous Lunar & Terrestrial Landing-Site Validation
TerraLuna is a production-grade, end-to-end Geospatial Digital Twin and Autonomous AI Agent system designed to validate planetary landing sites for ISRO Chandrayaan-class and NASA Artemis-class lunar landers.
The system connects deterministic raster geospatial math engines via a Model Context Protocol (MCP) server to an Autonomous LangGraph AI Agent powered by Google Gemini, paired with an interactive 3D Aerospace Mission Control Dashboard built in Streamlit and Plotly.
๐๏ธ System Architecture
graph TD
subgraph UI ["3D Mission Control (Streamlit + Plotly)"]
A[Preset & Coordinate Selector] --> B[Run Autonomous Agent]
B --> C[3D Elevation & Hazard Mesh]
B --> D[KPI Scorecard & Tool Trace]
end
subgraph Agent ["LangGraph Autonomous Agent"]
E[validate_bounds] -->|In Bounds| F[analyze_terrain]
E -->|Out of Bounds| J[synthesize_report]
F --> G[check_illumination]
G --> H[analyze_regolith]
H --> I[compare_earth_analog]
I --> J
J --> K{Mode Check}
K -->|GEMINI_API_KEY present| L[Gemini 2.5 Flash Executive Brief]
K -->|Zero Key / Offline| M[Deterministic Aerospace Brief]
end
subgraph MCP ["FastMCP Server (TerraLuna-MCP)"]
N[resource: twin://missions/catalog]
O[resource: twin://constraints/lander-specs]
P[tool: analyze_terrain_hazards]
Q[tool: simulate_solar_illumination]
R[tool: extract_regolith_composition]
S[tool: compare_lunar_earth_analog]
end
subgraph Engines ["Geospatial & Spectral Compute Engines"]
T[Horn's 2D Finite Gradient Slope]
U[Riley Terrain Ruggedness Index TRI]
V[Ray-Cast Horizon Shadow Mask]
W[IIRS FeO / TiO2 / 2.8um Hydration Index]
X[Deccan Basalt Lonar Terrestrial Analog]
end
UI --> Agent
Agent --> MCP
MCP --> EnginesRelated MCP server: MCP4RS Open Earth Explorer
๐ Key Capabilities
Deterministic FastMCP Server (
mcp_server/server.py):MCP Resources:
twin://missions/catalog: Dynamic JSON index of available Lunar South Pole and Earth Analog datasets, CRS, bounding boxes, and sensor metadata.twin://constraints/lander-specs: Authoritative structural tolerances (max 10.0ยฐ slope, max 0.45m TRI, min 65.0% illumination).
MCP Prompt:
landing_site_audit_prompt(site_name, lat, lon): Reusable mission-control audit template for flight controllers.
Deterministic MCP Tools:
analyze_terrain_hazards: Clips DEM window, calculates Horn's slope using 2D finite gradients, Riley TRI, % unsafe pixels, and produces a downsampled 3D mesh artifact.simulate_solar_illumination: Casts reverse rays towards the solar azimuth/elevation vector to compute topographic horizon occlusions, self-shadowing, and permanently shadowed region (PSR) cryogenic hazards.extract_regolith_composition: Extracts FeO wt%, TiO2 wt%, and 2.8ยตm OH/H2O hydration index to classify regolith (e.g., Highland Anorthosite, Mare Basalt, Hydrated Cold Trap).compare_lunar_earth_analog: Computes quantitative similarity (0โ100%) against Lonar Basalt Meteorite Crater in Maharashtra, India.
Dual-Mode Autonomous LangGraph Agent (
agent/graph.py):Gemini LLM Mode: Powered by
ChatGoogleGenerativeAI(model="gemini-2.5-flash")with yourGEMINI_API_KEYfrom Google AI Studio. Synthesizes flight director briefs.Offline Deterministic Fallback Mode: Works 100% offline with zero API keys if
GEMINI_API_KEYis omitted, executing the exact LangGraph state machine over deterministic MCP tools and formatting an aerospace engineering brief.
3D Mission Control Web Dashboard (
dashboard/app.py):Interactive 3D terrain surface mesh rendered with Plotly WebGL.
Dynamic colormaps: Elevation (m), Slope Hazard (ยฐ) (red > 10ยฐ limit), or Solar Shadow Mask (1 = lit, 0 = shadow).
4 Mission KPI Cards:
Mean Slope,Sunlit Area %,Regolith Type,Earth Analog Match %.Live expandable MCP Tool Execution Trace displaying exact millisecond latency, JSON inputs, and JSON outputs.
Synthetic-but-Physically-Realistic GeoTIFF Generator (
scripts/generate_sample_rasters.py):Automatically generates 4 georeferenced rasters (
EPSG:4326) on first launch:data/lunar/ch2_tmc2_south_pole_dem.tif: Chandrayaan-2 TMC-2 / NASA LRO LOLA composite DEM at Lunar South Pole.data/lunar/ch2_iirs_hydration.tif: Multi-band FeO, TiO2, and 2.8ยตm hydration band depth.data/earth_analog/lonar_crater_dem.tif: Lonar Basalt Crater DEM (1.8km crater with 510m rim and 450m saline lake).data/earth_analog/lonar_sentinel2_bands.tif: Sentinel-2 basaltic iron oxide and clay alteration bands.
๐ Repository Structure
terraluna-mcp/
โโโ .env.example # API key configuration template
โโโ .env # Local environment configuration
โโโ requirements.txt # Pinned dependencies
โโโ README.md # Complete project documentation
โโโ data/
โ โโโ lunar/
โ โ โโโ ch2_tmc2_south_pole_dem.tif # Lunar South Pole DEM
โ โ โโโ ch2_iirs_hydration.tif # 3-band spectral regolith raster
โ โโโ earth_analog/
โ โ โโโ lonar_crater_dem.tif # Lonar Crater basalt DEM
โ โ โโโ lonar_sentinel2_bands.tif # 3-band Sentinel-2 mineral proxy
โ โโโ artifacts/ # Generated 3D mesh & overlay JSONs
โโโ scripts/
โ โโโ generate_sample_rasters.py # Deterministic GeoTIFF generator
โโโ mcp_server/
โ โโโ __init__.py
โ โโโ terrain_engine.py # Horn's slope, TRI, and solar ray-casting
โ โโโ spectral_engine.py # FeO, TiO2, hydration & analog similarity
โ โโโ server.py # FastMCP Server (Resources, Prompts, Tools)
โโโ agent/
โ โโโ __init__.py
โ โโโ schemas.py # Pydantic v2 schemas & LandingZoneReport
โ โโโ graph.py # LangGraph state machine & Gemini client
โโโ dashboard/
โ โโโ app.py # Streamlit + Plotly 3D Mission Control
โโโ evals/
โโโ test_landing_sites.py # Automated pytest verification suiteโก Quickstart & Setup Guide
1. Prerequisites
Python 3.11 or Python 3.12
Git
2. Clone and Setup Environment
# Clone the repository
git clone https://github.com/your-username/terraluna-mcp.git
cd terraluna-mcp
# Create and activate virtual environment
python -m venv .venv
# Windows:
.venv\Scripts\activate
# Linux / macOS:
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt3. Generate Scientific Datasets
Run the sample raster generator (generates all 4 georeferenced GeoTIFFs immediately):
python scripts/generate_sample_rasters.py4. Configure Google Gemini API Key (Optional)
Copy .env.example to .env:
cp .env.example .envOpen .env and add your free Google AI Studio API key:
GEMINI_API_KEY=AIzaSy...your_actual_key_hereNote: If
GEMINI_API_KEYis left blank, the system automatically runs in 100% Offline Deterministic Fallback Mode. No external calls or credits required!
๐ฅ๏ธ Running the Application
Launch the 3D Mission Control Web Dashboard
python -m streamlit run dashboard/app.pyOpen your browser at http://localhost:8501.
Using the Dashboard:
Select a Mission Target Preset in the sidebar:
Preset 1 (Safe Ridge): Flat landing plateau adjacent to South Pole crater (
lat: -89.494ยฐ,lon: -0.680ยฐ) -> APPROVED.Preset 2 (Steep Rim): 28ยฐ crater rim wall (
lat: -89.506ยฐ,lon: +0.680ยฐ) -> REJECTED_HAZARD.Preset 3 (Earth Analog): Lonar Basalt Crater (
lat: 19.976ยฐ,lon: 76.508ยฐ).Custom Coordinates: Test any coordinate within dataset bounds or test out-of-bounds safety refusals.
Adjust Search Footprint Radius, Sun Elevation Angle, or Max Lander Slope Tolerance.
Click "Run Autonomous Agent Validation".
Inspect the interactive 3D terrain surface, change colormaps (Elevation, Slope Hazard, Solar Mask), and review the live MCP step-by-step tool trace.
๐ฌ Testing with the Official MCP Inspector
You can inspect and debug the FastMCP server directly using Anthropic/Model Context Protocol's official visual inspector:
npx @modelcontextprotocol/inspector python mcp_server/server.pyIn the MCP Inspector UI:
Resources: View and read
twin://missions/catalogandtwin://constraints/lander-specs.Prompts: Render
landing_site_audit_promptwith custom coordinates.Tools: Directly execute
analyze_terrain_hazards,simulate_solar_illumination,extract_regolith_composition, andcompare_lunar_earth_analog.
๐งช Automated Benchmark & Verification Suite
Run the full end-to-end automated test suite:
python -m pytest -v evals/test_landing_sites.pyEvaluation Matrix:
Test Case | Scenario | Expected Verdict | Verified Telemetry |
| Safe South Polar Ridge |
| Mean slope ~2.89ยฐ (<10ยฐ), 100% Sunlit, Safety Score = 100.0 |
| 28ยฐ Impact Crater Rim |
| Mean slope ~29.4ยฐ (>10ยฐ), 90.9% unsafe pixels, Safety Score = 0.0 |
| Target outside bounds |
| Automated abort engaged, Safety Score = 0.0, zero descent burn |
| Lonar Basalt Analog |
| Validates Deccan basalt slope profile & Sentinel-2 mineral bands |
| FastMCP Architecture |
| Tests all resources, prompts, and tools via direct Python API |
๐ฐ๏ธ Dropping in Real ISRO Pradan / NASA PDS Rasters
To replace the synthetic rasters with raw missions GeoTIFFs:
Download Level-2 calibrated DEM and Map-projected spectral products from:
ISRO ISSDC / Pradan: Chandrayaan-2 TMC-2 Stereo DEMs & IIRS Level-2 calibrated radiances.
NASA Planetary Data System (PDS): LRO LOLA GDR DEMs (Lunar Orbiter Laser Altimeter).
Bhuvan / USGS: Cartosat-1 / SRTM DEMs for Earth Analogs.
Ensure tiles are in
EPSG:4326or reproject using GDAL:gdalwarp -t_srs EPSG:4326 input_dem.tif data/lunar/ch2_tmc2_south_pole_dem.tifUpdate bounding boxes in
DATASET_REGISTRYinmcp_server/server.py. The rest of the pipeline executes without any code changes!
โ๏ธ Engineering Assumptions & Formula Reference
Horn's 2D Finite Gradient Slope: $$\frac{\partial z}{\partial x} = \text{np.gradient}(z, \Delta x, \text{axis}=1), \quad \frac{\partial z}{\partial y} = \text{np.gradient}(z, \Delta y, \text{axis}=0)$$ $$\theta_{\text{slope}} = \arctan\left(\sqrt{\left(\frac{\partial z}{\partial x}\right)^2 + \left(\frac{\partial z}{\partial y}\right)^2}\right) \times \frac{180}{\pi}$$
Terrain Ruggedness Index (Riley et al. 1999): $$\text{TRI} = \sqrt{\frac{1}{8}\sum_{i=-1}^{1}\sum_{j=-1}^{1} (z_{y+i, x+j} - z_{y, x})^2} \quad \text{for } (i,j) \neq (0,0)$$
Solar Vector & Horizon Ray-Casting: $$\vec{S} = (\sin\theta_{\text{az}}\cos\phi_{\text{el}}, -\cos\theta_{\text{az}}\cos\phi_{\text{el}}, \sin\phi_{\text{el}})$$ Occlusion occurs when any intermediate terrain height $z_{\text{terrain}}(s) > z_0 + s \cdot \tan(\phi_{\text{el}})$.
๐ License
MIT License. Built for autonomous planetary exploration research.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogโฆ
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP server for aerospace calculations: orbital mechanics, ephemeris, DSN operations, ...
Geospatial AI MCP server โ satellite imagery, embeddings, weather, GNS governance
Geodata for any place, inside your agent: map data, terrain, routes, satellite images, GIS files.
Remote MCP endpoint for U.S. home forecasts, public benchmark data, and permit or zoning readiness.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables advanced geospatial analysis including elevation queries, line-of-sight calculations, terrain visualization, and autonomous drone mission planning with real-time safety analysis and 3D visualization capabilities.MIT
- AlicenseNot gradedqualityDmaintenanceEnables discovery, analysis, and explanation of open satellite data through MCP, with support for STAC catalogs and NASA GIBS.1MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to perform geospatial analysis, spatial data processing, vector and raster operations, coordinate transformations, spatial statistics, mapping, and access to climate, satellite, and other geospatial data through MCP-compatible clients.MIT
- AlicenseNot gradedqualityCmaintenanceEnables MCP clients to run evidence-based geolocation investigations: managing cases, candidates, observations and evidence with optimistic revisions and hash-chained audit logs, performing WGS84 geodesic and sun/shadow math, extracting EXIF/XMP metadata from original images, and issuing controlled OSM Overpass queries within governed geographic search scopes. The server validates inputs, does the deterministic math and controls lookups while the client's own model supplies visual reasoning, keeping executed calls, metadata, and verified locations as distinct claims.MIT