Labsco
SandyYuan logo

Astro MCP

โ˜… 4

from SandyYuan

A modular server providing unified access to multiple astronomical datasets, including astroquery services and DESI data sources.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

Astro MCP - Agentic Astronomical Data Access

A modular Model Context Protocol (MCP) server that provides unified access to multiple astronomical datasets through a clean, extensible architecture.

Vision

This MCP server aims to transform big-data astronomy from a software engineering problem into a natural language conversation. Instead of spending months learning astroquery APIs, researchers simply ask for what they need and get clean, processed analysis-ready data products.

One expert solves the complexity once; thousands of scientists benefit forever. A student with little programming experience can now perform the same multi-survey analysis as an expert astronomer using nothing but natural language and an AI assistant.

This isn't just about astronomyโ€”it's a template for democratizing all of science. Every field has brilliant researchers spending 80% of their time on data wrangling instead of discovery. By removing that bottleneck, we accelerate the pace of scientific progress itself.

The result: AI scientists that can seamlessly access and cross-match data from dozens of astronomical surveys, enabling discoveries that would have taken months of setup to attempt just a few years ago.

Architecture

astro_mcp/
โ”œโ”€โ”€ server.py                    # Main MCP server entry point
โ”œโ”€โ”€ data_sources/               # Modular data source implementations
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ base.py                # Base class for all data sources
โ”‚   โ”œโ”€โ”€ desi.py                # DESI survey data access
โ”‚   โ”œโ”€โ”€ astroquery_universal.py # Universal astroquery wrapper
โ”‚   โ””โ”€โ”€ astroquery_metadata.py  # Service metadata and capabilities
โ”œโ”€โ”€ data_io/                   # File handling and conversion
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ preview.py             # Data preview and structure analysis
โ”‚   โ””โ”€โ”€ fits_converter.py      # FITS format conversion
โ”œโ”€โ”€ tests/                     # Test suite
โ”œโ”€โ”€ examples/                  # Usage examples
โ””โ”€โ”€ requirements.txt           # Project dependencies

Features

๐Ÿ”ญ Universal Astronomical Data Access

  • DESI: Dark Energy Spectroscopic Instrument via SPARCL and Data Lab
  • Astroquery: Automatic access to 40+ astronomical services (SIMBAD, VizieR, SDSS, Gaia, etc.)
  • Auto-discovery: Automatically detects and configures available astroquery services
  • Unified interface: Same API for all data sources

๐Ÿ“ Intelligent File Management

  • Automatic data saving with descriptive filenames
  • Cross-source file registry and organization
  • Comprehensive metadata tracking with provenance
  • Smart file preview with loading examples
  • FITS format conversion for astronomical compatibility

๐Ÿ” Powerful Search Capabilities

  • Coordinate-based searches (point, cone, box) across all surveys
  • Object type and redshift filtering
  • SQL queries with spatial indexing (Q3C)
  • Natural language query interpretation
  • Cross-survey data correlation

๐Ÿ“Š Data Analysis & Conversion Tools

  • Spectral data retrieval and analysis
  • Automatic FITS conversion for catalogs, spectra, and images
  • File structure inspection and preview
  • Statistics and storage management
  • Extensible tool architecture for custom analysis

๐Ÿค– AI-Optimized Interface

  • Parameter preprocessing and validation
  • Intelligent error handling with helpful suggestions
  • Automatic format detection and conversion
  • Consistent metadata across all data sources

Data Sources

DESI (Dark Energy Spectroscopic Instrument)

Status: โœ… Fully Implemented

  • SPARCL Access: Full spectral data retrieval
  • Data Lab SQL: Fast catalog queries (sparcl.main table)
  • Coverage: DESI EDR (~1.8M) and DR1 (~18M+ spectra)
  • Wavelength: 360-980 nm, Resolution: R ~ 2000-5500

Astroquery Universal Access

Status: โœ… Fully Implemented

Major Services Available:

  • SIMBAD: Object identification and basic data
  • VizieR: Astronomical catalogs and surveys
  • SDSS: Sloan Digital Sky Survey data and spectra
  • Gaia: Astrometric and photometric data
  • MAST: Hubble, JWST, and other space telescope archives
  • IRSA: Infrared and submillimeter archives
  • ESASky: Multi-mission astronomical data
  • And 30+ more services...

Capabilities:

  • Automatic service discovery and configuration
  • Intelligent query type detection
  • Parameter preprocessing and validation
  • Unified error handling and help generation

Required Dependencies:

pip install astroquery astropy

Extending the Architecture

Adding a New Data Source

  1. Create the data source class:
# data_sources/my_survey.py
from .base import BaseDataSource

class MySurveyDataSource(BaseDataSource):
    def __init__(self, base_dir=None):
        super().__init__(base_dir=base_dir, source_name="my_survey")
        # Initialize survey-specific clients
    
    def search_objects(self, **kwargs):
        # Implement survey-specific search
        pass
  1. Update the main server:
# server.py
from data_sources import MySurveyDataSource

class AstroMCPServer:
    def __init__(self, base_dir=None):
        # ... existing code ...
        self.my_survey = MySurveyDataSource(base_dir=base_dir)

Adding New Astroquery Services

The astroquery integration automatically discovers new services. To add custom metadata:

# data_sources/astroquery_metadata.py
ASTROQUERY_SERVICE_INFO = {
    "my_service": {
        "full_name": "My Custom Service",
        "description": "Custom astronomical database",
        "data_types": ["catalogs", "images"],
        "wavelength_coverage": "optical",
        "object_types": ["stars", "galaxies"],
        "requires_auth": False,
        "example_queries": [
            {
                "description": "Search by object name",
                "query": "astroquery_query(service_name='my_service', object_name='M31')"
            }
        ]
    }
}

File Organization

Files are automatically organized by data source with comprehensive metadata:

~/astro_mcp_data/
โ”œโ”€โ”€ file_registry.json           # Global file registry with metadata
โ”œโ”€โ”€ desi/                        # DESI-specific files
โ”‚   โ”œโ”€โ”€ desi_search_*.json      # Search results
โ”‚   โ”œโ”€โ”€ spectrum_*.json         # Spectral data
โ”‚   โ””โ”€โ”€ *.fits                  # FITS conversions
โ””โ”€โ”€ astroquery/                 # Astroquery results
    โ”œโ”€โ”€ astroquery_simbad_*.csv # SIMBAD queries
    โ”œโ”€โ”€ astroquery_sdss_*.csv   # SDSS results
    โ”œโ”€โ”€ astroquery_vizier_*.csv # VizieR catalogs
    โ””โ”€โ”€ *.fits                  # FITS conversions

Development

Project Structure Benefits

  • Modularity: Easy to add new surveys and analysis tools
  • Universal Access: Single interface to 40+ astronomical databases
  • Separation of Concerns: Data access, I/O, and analysis are separate
  • Testability: Each module can be tested independently
  • Scalability: Clean architecture supports unlimited growth

Testing

# Run all tests
pytest

# Test specific modules
pytest tests/test_desi.py
pytest tests/test_astroquery.py

# Test with coverage
pytest --cov=data_sources tests/

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-capability)
  3. Add your data source or tool following the existing patterns
  4. Write tests for new functionality
  5. Update documentation and examples
  6. Submit a pull request

Dependencies

Core Requirements

  • mcp>=1.0.0 - Model Context Protocol framework
  • pandas>=2.0.0 - Data manipulation
  • numpy>=1.24.0 - Numerical computing

Astronomical Libraries

  • astroquery>=0.4.6 - Universal astronomical database access
  • astropy>=5.0.0 - FITS files and astronomical calculations
  • sparclclient>=1.0.0 - DESI SPARCL access
  • datalab>=2.20.0 - NOAO Data Lab queries

Optional Features

  • h5py>=3.8.0 - HDF5 file support
  • pytest>=7.0.0 - Testing framework

Citation

If you use this software in your research, please cite:

@software{astro_mcp,
  title={Astro MCP: Universal Astronomical Data Access for AI Agents},
  author={[Your Name]},
  year={2024},
  url={[Repository URL]}
}

Support

Roadmap

Current (v0.1.0)

  • โœ… DESI data access via SPARCL and Data Lab
  • โœ… Universal astroquery integration (40+ services)
  • โœ… Automatic FITS conversion for all data types
  • โœ… Intelligent file management with comprehensive metadata
  • โœ… Natural language query interface

Planned (v0.2.0)

  • ๐Ÿšง Cross-survey object matching and correlation
  • ๐Ÿšง Advanced astronomical calculations (distances, magnitudes)
  • ๐Ÿšง Time-series analysis for variable objects
  • ๐Ÿšง Visualization tools integration

Future (v0.3.0+)

  • ๐Ÿ”ฎ Machine learning integration for object classification
  • ๐Ÿ”ฎ Real-time data streaming from surveys
  • ๐Ÿ”ฎ Custom analysis pipeline creation
  • ๐Ÿ”ฎ Multi-wavelength data correlation tools