Astro MCP-代理天文数据访问
一种模块化的模型上下文协议(MCP)服务器,通过干净、可扩展的架构提供对多个天文数据集的统一访问。
视觉
这个MCP服务器旨在将大数据天文学从软件工程问题转变为自然语言对话。研究人员没有花几个月的时间学习astroquery API,而是简单地询问他们需要什么,并获得干净、经过处理的分析就绪数据产品。
一位专家一次性解决了复杂性;成千上万的科学家永远受益。一个几乎没有编程经验的学生现在可以使用自然语言和人工智能助手进行与专家天文学家相同的多调查分析。
这不仅仅是天文学,它是所有科学民主化的模板。每个领域都有杰出的研究人员将80%的时间花在数据争论上,而不是发现上。通过消除这一瓶颈,我们加快了科学进步的步伐。
结果:人工智能科学家可以无缝访问和交叉匹配数十次天文调查的数据,从而实现几年前需要数月时间才能尝试的发现。
光标和克劳德桌面的快速设置
1.克隆和设置环境
# Clone the repository
git clone https://github.com/SandyYuan/astro_mcp.git
cd astro_mcp
# Create a dedicated conda environment with Python 3.11+
conda create -n mcp python=3.11
conda activate mcp
# Install dependencies
pip install -r requirements.txt
# Install astronomical libraries for full functionality
pip install sparclclient datalab astropy astroquery2.测试服务器
# Test basic functionality
python test_server.py
# Test with a simple query (optional)
python -c "
import asyncio
from server import astro_server
async def test():
result = astro_server.get_global_statistics()
print('✅ Server working:', result['total_files'], 'files in registry')
services = astro_server.list_astroquery_services()
print(f'✅ Astroquery: {len(services)} services discovered')
asyncio.run(test())
"3.配置光标
将此配置添加到光标MCP设置中:
{
"mcpServers": {
"astro-mcp": {
"command": "/path/to/conda/envs/mcp/bin/python",
"args": ["/path/to/astro_mcp/server.py"],
"cwd": "/path/to/astro_mcp",
"env": {}
}
}
}要查找您的conda Python路径:
conda activate mcp
which python
# Copy this path for the "command" field above4.配置克劳德桌面
编辑您的Claude Desktop MCP配置文件:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json 窗户: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"astro-mcp": {
"command": "/path/to/conda/envs/mcp/bin/python",
"args": ["/path/to/astro_mcp/server.py"],
"cwd": "/path/to/astro_mcp",
"env": {}
}
}
}5.重新启动和测试
- 重新启动Cursor/Claude桌面 加载新的MCP服务器
- 使用查询进行测试 比如:
- “搜索RA附近的星系=10.68,Dec=41.27” - “从SIMBAD获取参宿四的坐标” - “在z=0.5附近找到10个BOSS星系并另存为FITS” - “列出可用的天文查询服务”
6.故障排除
服务器无法启动:
# Check Python environment
conda activate mcp
python --version # Should be 3.11+
# Test server manually
python server.py
# Should start without errorsMCP连接问题:
- 验证配置中的Python路径是否指向conda环境
- 确保工作目录(
cwd)指向astro_mcp文件夹 - 检查所有依赖项是否安装在正确的环境中
缺少天文数据:
# Install optional dependencies for full functionality
conda activate mcp
pip install sparclclient datalab astropy astroquery h5pyCursor/Claude桌面使用示例
配置后,您可以询问有关天文数据的自然语言问题:
基本搜索
- *“在RA=150.5,Dec=2.2的0.1度范围内找到星系”*
- *“寻找红移在2到3之间的类星体”*
- *“从SIMBAD获取参宿四的精确坐标”*
- *“在红移0.5附近找到10个BOSS星系”*
多调查访问
- *“向VizieR查询猎户座地区的恒星目录”*
- *“在SDSS中搜索星系并保存为FITS格式”*
- *“从多个天文数据库获取天体信息”*
- *“列出用于星系研究的所有可用天文查询服务”*
光谱数据分析
- *“获取ID为1270d3c4-9d36-11ee-94ad-525400ad1336的DESI对象的光谱”*
- *“显示你能找到的最亮类星体的详细光谱信息”*
- *“找到星系光谱并分析其红移”*
文件管理和转换
- *“列出所有保存的天文数据文件”*
- *“将我的星系目录转换为FITS格式”*
- *“预览最新搜索结果的结构”*
- *“显示下载数据的存储统计信息”*
高级查询
- *“找到高红移星系(z>1.5)并保存它们的光谱”*
- *“在COSMOS领域搜索对象并分析其类型”*
- *“对同一天空区域的DESI和SDSS数据进行交叉匹配”*
服务器将自动:
- 在多个调查中执行适当的数据库查询
- 使用描述性文件名和元数据保存结果
- 处理坐标转换和天文计算
- 根据需要将数据转换为标准格式(CSV、FITS)
建筑
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特性
🔭 通用天文数据访问
- 设计:通过SPARCL和数据实验室的暗能量光谱仪
- 天文查询:自动访问40多种天文服务(SIMBAD、VizieR、SDSS、盖亚等)
- 自动发现:自动检测和配置可用的astroquery服务
- 统一接口:所有数据源使用相同的API
📁 智能文件管理
- 使用描述性文件名自动保存数据
- 跨源文件注册表和组织
- 具有来源的全面元数据跟踪
- 带有加载示例的智能文件预览
- 天文兼容性的FITS格式转换
🔍 强大的搜索功能
- 在所有测量中进行基于坐标的搜索(点、圆锥体、长方体)
- 对象类型和红移过滤
- 具有空间索引的SQL查询(Q3C)
- 自然语言查询解释
- 交叉调查数据相关性
📊 数据分析和转换工具
- 光谱数据检索和分析
- 目录、光谱和图像的自动FITS转换
- 文件结构检查和预览
- 统计和存储管理
- 用于自定义分析的可扩展工具架构
🤖 AI优化界面
- 参数预处理和验证
- 智能错误处理,提供有用的建议
- 自动格式检测和转换
- 跨所有数据源的一致元数据
安装
快速入门: 有关Cursor和Claude Desktop集成,请参阅 快速设置 上面的部分。
手动安装
# Clone the repository
git clone https://github.com/SandyYuan/astro_mcp.git
cd astro_mcp
# Create and activate environment
conda create -n mcp python=3.11
conda activate mcp
# Install core dependencies
pip install -r requirements.txt
# Install astronomical libraries
pip install sparclclient datalab astropy astroquery
# Optional: Install development dependencies
pip install pytest coverage验证安装
# Test the server components
python test_server.py
# Check available astroquery services
python -c "
import asyncio
from server import astro_server
async def show_services():
services = astro_server.list_astroquery_services()
print(f'✅ Discovered {len(services)} astroquery services')
for service in services[:5]: # Show first 5
print(f' - {service["full_name"]} ({service["service"]})')
asyncio.run(show_services())
"快速开始
1.启动MCP服务器
python server.py2.可用工具
服务器提供以下主要工具:
数据访问:
search_objects-寻找天体(DESI)astroquery_query-40多个天文服务的通用查询get_spectrum_by_id-检索详细的光谱数据(DESI)
服务发现:
list_astroquery_services-显示所有可用的天文数据库get_astroquery_service_details-详细服务信息search_astroquery_services-按条件查找服务
文件管理:
preview_data-使用结构分析检查保存的文件list_files-管理所有来源的已保存数据file_statistics-存储使用和组织信息convert_to_fits-将数据转换为FITS格式
3.示例用法
# Get object coordinates from SIMBAD
astroquery_query(
service_name="simbad",
object_name="Betelgeuse"
)
# Search SDSS for galaxies with SQL
astroquery_query(
service_name="sdss",
query_type="query_sql",
sql="SELECT TOP 10 ra, dec, z FROM SpecObj WHERE class='GALAXY' AND z BETWEEN 0.1 AND 0.3"
)
# Search VizieR catalogs
astroquery_query(
service_name="vizier",
ra=10.68,
dec=41.27,
radius=0.1
)
# Convert results to FITS
convert_to_fits(
identifier="search_results.csv",
data_type="catalog"
)数据源
暗能量光谱仪
状态: ✅ 全面实施
- SPARCL访问:全光谱数据检索
- 数据实验室SQL:快速目录查询(sparcl.main表)
- 覆盖:DESI EDR(~1.8M)和DR1(~18M+光谱)
- 波长:360-980纳米,分辨率:R~2000-5500
Astroquery通用访问
状态: ✅ 全面实施
可用的主要服务:
- 辛巴达:对象标识和基本数据
- 维齐:天文目录和测量
- 斯隆数字巡天:斯隆数字巡天数据和光谱
- 盖亚:天体测量和光度数据
- 桅杆:哈勃、JWST和其他太空望远镜档案
- 利率敏感性资产:红外和亚毫米档案
- ESASK:多任务天文数据
- 30多个服务。..
能力:
- 自动服务发现和配置
- 智能查询类型检测
- 参数预处理和验证
- 统一的错误处理和帮助生成
所需依赖关系:
pip install astroquery astropy扩展架构
添加新数据源
- 创建数据源类:
# 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- 更新主服务器:
# 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)添加新的Astroquery服务
astroquery集成会自动发现新服务。要添加自定义元数据,请执行以下操作:
# 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')"
}
]
}
}文件组织
文件按数据源自动组织,并具有全面的元数据:
~/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发展
项目结构效益
- 模块化:易于添加新的调查和分析工具
- 通用访问:40多个天文数据库的单一接口
- 关注点分离:数据访问、I/O和分析是分开的
- 可测试性:每个模块都可以独立测试
- 可扩展性:清洁架构支持无限增长
测试
# 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/贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/new-capability) - 按照现有模式添加数据源或工具
- 为新功能编写测试
- 更新文档和示例
- 提交拉取请求
依赖项
核心要求
mcp>=1.0.0-模型上下文协议框架pandas>=2.0.0-数据操纵numpy>=1.24.0-数值计算
天文图书馆
astroquery>=0.4.6-通用天文数据库访问astropy>=5.0.0-FITS文件和天文计算sparclclient>=1.0.0-DESI SPARCL访问权限datalab>=2.20.0-NOAO数据实验室查询
可选功能
h5py>=3.8.0-HDF5文件支持pytest>=7.0.0-测试框架
许可证
\[在此处指定您的许可证\]
引用
如果您在研究中使用此软件,请引用:
@software{astro_mcp,
title={Astro MCP: Universal Astronomical Data Access for AI Agents},
author={[Your Name]},
year={2024},
url={[Repository URL]}
}支持
- 问题:
- 文档: 全部文件
- 讨论:
路线图
电流(v0.1.0)
- ✅ 通过SPARCL和数据实验室访问DESI数据
- ✅ 通用天文查询集成(40+服务)
- ✅ 所有数据类型的自动FITS转换
- ✅ 具有全面元数据的智能文件管理
- ✅ 自然语言查询界面
计划(v0.2.0)
- 🚧 交叉调查对象匹配和相关性
- 🚧 高级天文计算(距离、星等)
- 🚧 可变对象的时间序列分析
- 🚧 可视化工具集成
未来(v0.3.0+)
- 🔮 用于对象分类的机器学习集成
- 🔮 来自调查的实时数据流
- 🔮 自定义分析管道创建
- 🔮 多波长数据关联工具
