关于 DESI MCP Server
DESI MCP Server 是面向天文学研究者的模块化 MCP 服务,统一访问 DESI 和多个天文数据源,并提供数据检索、分析与文件管理工具。它还支持跨巡天查询和标准格式转换。
主要功能
- 01访问 DESI 光谱与目录数据
- 02查询 40 多种 astroquery 服务
- 03按坐标、类型和红移搜索
- 04跨巡天数据关联
- 05管理文件并转换为 FITS
适用场景
- 01搜索指定天区的星系或类星体
- 02检索天体光谱并分析红移
- 03关联 DESI 与 SDSS 数据
- 04预览结果并转换为 FITS
MCP 相关
该 MCP 服务向 MCP 客户端提供天文数据查询、光谱检索、服务发现、文件管理和格式转换工具。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
Astro MCP - 智能天文学数据访问
一个模块化的 Model Context Protocol(MCP)服务,通过简洁、可扩展的架构统一访问多个天文学数据集。
愿景
此 MCP 服务旨在将大数据天文学从软件工程问题转变为自然语言对话。研究人员无需花数月学习 astroquery API,只需提出需求,即可获得经过整理、处理完毕且可直接用于分析的数据产品。
一位专家一次性解决复杂问题,数千名科学家便能长久受益。如今,编程经验有限的学生只需使用自然语言和 AI 助手,就能完成与资深天文学家相同的多巡天分析。
这不仅关乎天文学,更是让所有科学普及化的范例。每个领域都有杰出的研究人员,他们把 80% 的时间花在数据整理上,而非发现上。移除这一瓶颈,我们就能加快科学进步本身的步伐。
最终,我们将拥有能够无缝访问数十个天文巡天数据并进行交叉匹配的 AI 科学家,从而实现几年前还需要数月准备才能尝试的发现。
Cursor 和 Claude Desktop 快速设置
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 astroquery
2. 测试服务
# 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. 配置 Cursor
将此配置添加到 Cursor 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 above
4. 配置 Claude Desktop
编辑 Claude Desktop MCP 配置文件:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %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 Desktop,加载新的 MCP 服务
- 使用类似以下查询进行测试:
- “搜索 RA=10.68、Dec=41.27 附近的星系”
- “从 SIMBAD 获取参宿四的坐标”
- “查找 z=0.5 附近的 10 个 BOSS 星系并保存为 FITS”
- “列出可用的 astroquery 服务”
6. 故障排除
服务无法启动:
# Check Python environment
conda activate mcp
python --version # Should be 3.11+
# Test server manually
python server.py
# Should start without errors
MCP 连接问题:
- 确认配置中的 Python 路径指向 conda 环境
- 确保工作目录(
cwd)指向 astro_mcp 文件夹 - 检查所有依赖是否已安装在正确的环境中
缺少天文数据:
# Install optional dependencies for full functionality
conda activate mcp
pip install sparclclient datalab astropy astroquery h5py
在 Cursor/Claude Desktop 中的使用示例
配置完成后,你可以用自然语言询问天文数据相关问题:
基本搜索
- “查找 RA=150.5、Dec=2.2 附近 0.1 度范围内的星系”
- “搜索红移在 2 到 3 之间的类星体”
- “从 SIMBAD 获取参宿四的精确坐标”
- “查找红移 0.5 附近的 10 个 BOSS 星系”
多巡天数据访问
- “查询 VizieR 中猎户座区域的恒星星表”
- “在 SDSS 中搜索星系并保存为 FITS 格式”
- “从多个天文数据库获取天体信息”
- “列出可用于星系研究的所有 astroquery 服务”
光谱数据分析
- “获取 DESI 天体的光谱,其 ID 为 1270d3c4-9d36-11ee-94ad-525400ad1336”
- “显示你能找到的最亮类星体的详细光谱信息”
- “查找一个星系光谱并分析其红移”
文件管理与转换
- “列出所有已保存的天文数据文件”
- “将我的星系星表转换为 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
功能
🔭 通用天文数据访问
- DESI:通过 SPARCL 和 Data Lab 访问暗能量光谱仪数据
- Astroquery:自动访问 40 多种天文服务(SIMBAD、VizieR、SDSS、Gaia 等)
- 自动发现:自动检测并配置可用的 Astroquery 服务
- 统一接口:所有数据源使用相同的 API
📁 智能文件管理
- 使用描述性文件名自动保存数据
- 跨数据源文件注册与整理
- 全面跟踪元数据及其来源
- 智能文件预览,附带加载示例
- 转换为 FITS 格式,以兼容天文数据
🔍 强大的搜索功能
- 在所有巡天项目中按坐标搜索(点、圆锥、矩形)
- 按天体类型和红移筛选
- 使用空间索引(Q3C)执行 SQL 查询
- 自然语言查询解读
- 跨巡天项目数据关联
📊 数据分析与转换工具
- 获取并分析光谱数据
- 自动将星表、光谱和图像转换为 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.py
2. 可用工具
此服务提供以下主要工具:
数据访问:
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"
)
数据源
DESI(暗能量光谱仪)
状态:✅ 已完整实现
- SPARCL 访问:完整获取光谱数据
- Data Lab SQL:快速查询星表(sparcl.main 表)
- 覆盖范围:DESI EDR(约 180 万条光谱)和 DR1(超过 1,800 万条光谱)
- 波长:360–980 nm,分辨率:R ~ 2000–5500
Astroquery 通用访问
状态:✅ 已完整实现
可用的主要服务:
- SIMBAD:天体识别和基本数据
- VizieR:天文星表和巡天项目
- SDSS:斯隆数字巡天数据和光谱
- Gaia:天体测量和测光数据
- MAST:哈勃、JWST 及其他空间望远镜档案
- IRSA:红外和亚毫米档案
- ESASky:多任务天文数据
- 以及 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/
贡献
- Fork 此仓库
- 创建功能分支(
git checkout -b feature/new-capability) - 按照现有模式添加数据源或工具
- 为新功能编写测试
- 更新文档和示例
- 提交拉取请求
依赖项
核心要求
mcp>=1.0.0- Model Context Protocol 框架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 Data Lab 查询
可选功能
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 和 Data Lab 访问 DESI 数据
- ✅ 通用 astroquery 集成(40 多项服务)
- ✅ 自动将所有数据类型转换为 FITS
- ✅ 借助全面的元数据实现智能文件管理
- ✅ 自然语言查询接口
计划中(v0.2.0)
- 🚧 跨巡天天体匹配与关联
- 🚧 高级天文计算(距离、星等)
- 🚧 变星的时间序列分析
- 🚧 可视化工具集成
未来(v0.3.0+)
- 🔮 集成机器学习以进行天体分类
- 🔮 巡天数据实时流传输
- 🔮 自定义分析流水线创建
- 🔮 多波段数据关联工具
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。