一个全面的航空航天研究和飞行计划服务,提供HTTP API和模型上下文协议(MCP)集成。使用FastMCP构建,以简化MCP服务器开发。功能包括智能机场解析、大圆航线计算、飞机性能估算、大气建模、坐标系转换、空气动力学分析、螺旋桨性能建模、火箭轨迹优化、轨道力学计算以及航天器轨迹规划,用于航空航天操作。
本软件仅用于教育、研究和开发目的
对于实际飞行计划,请始终使用经过认证的航空软件,并参考官方来源,包括NOTAM、气象报告和空中交通管制。
# 安装UV(快速Python包管理器)
curl -LsSf https://astral.sh/uv/install.sh | sh
# 克隆并设置
git clone https://github.com/username/aerospace-mcp.git
cd aerospace-mcp
uv venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
uv sync
# 复制环境变量并配置(可选但推荐)
cp .env.example .env
# 根据需要编辑.env(主机/端口/日志级别,可选LLM工具)
# 运行HTTP服务器(包入口点)
uv run aerospace-mcp-http
# 或者(开发者风格)
uvicorn main:app --reload --host 0.0.0.0 --port 8080
# 测试API
curl "http://localhost:8080/health"
git clone https://github.com/username/aerospace-mcp.git
cd aerospace-mcp
docker build -t aerospace-mcp .
docker run -p 8080:8080 aerospace-mcp
# 测试API
curl "http://localhost:8080/health"
添加到您的Claude桌面配置中:
{
"mcpServers": {
"aerospace-mcp": {
"command": "uv",
"args": ["run", "aerospace-mcp"],
"cwd": "/path/to/aerospace-mcp",
"env": {
"LLM_TOOLS_ENABLED": "true",
"OPENAI_API_KEY": "your-openai-api-key-here"
}
}
}
}
注意:env部分是可选的,仅在您希望启用AI驱动代理工具以增强用户体验时才需要。
# 启动MCP服务器(标准输入输出)
uv run aerospace-mcp
# 启动SSE模式(可选)
uv run aerospace-mcp sse 0.0.0.0 8001
UV是最快速的Python包管理器,并提供了出色的依赖项解析:
# 安装UV
curl -LsSf https://astral.sh/uv/install.sh | sh # Linux/macOS
# 或:powershell -c "irm https://astral.sh/uv/install.ps1 | iex" # Windows
# 克隆仓库
git clone https://github.com/username/aerospace-mcp.git
cd aerospace-mcp
# 创建虚拟环境
uv venv
source .venv/bin/activate # Linux/macOS
# .venv\Scripts\activate # Windows
# 安装依赖项
uv add fastapi uvicorn[standard] airportsdata geographiclib pydantic python-dotenv
uv add openap # 可选:用于性能估算
uv add mcp # 可选:用于MCP服务器功能
# 安装可选的航空航天分析依赖项
uv add --optional-dependencies atmosphere # Ambiance用于增强ISA
uv add --optional-dependencies space # Astropy用于坐标系
uv add --optional-dependencies all # 所有可选依赖项
# 安装开发依赖项(可选)
uv add --dev pytest httpx black isort mypy pre-commit
# 验证安装
python -c "import main; print('✅ 安装成功')"
# 克隆仓库
git clone https://github.com/username/aerospace-mcp.git
cd aerospace-mcp
# 创建虚拟环境
python -m venv .venv
source .venv/bin/activate # Linux/macOS
# .venv\Scripts\activate # Windows
# 升级pip
pip install --upgrade pip
# 安装核心依赖项
pip install fastapi uvicorn[standard] airportsdata geographiclib pydantic python-dotenv
# 安装可选依赖项
pip install openap # 用于性能估算
pip install mcp # 用于MCP服务器
pip install python-dotenv # 用于加载本地/开发中的.env
# 从pyproject.toml安装
pip install -e .
# 验证安装
python -c "import main; print('✅ 安装成功')"
# 克隆仓库
git clone https://github.com/username/aerospace-mcp.git
cd aerospace-mcp
# 构建镜像
docker build -t aerospace-mcp .
# 运行容器
docker run -d -p 8080:8080 --name aerospace-mcp aerospace-mcp
# 健康检查
curl http://localhost:8080/health
# 查看日志
docker logs aerospace-mcp
# 停止容器
docker stop aerospace-mcp
# 创建conda环境
conda create -n aerospace-mcp python=3.11
conda activate aerospace-mcp
# 克隆仓库
git clone https://github.com/username/aerospace-mcp.git
cd aerospace-mcp
# 安装依赖项
conda install fastapi uvicorn pydantic
pip install airportsdata geographiclib openap mcp
# 验证安装
python -c "import main; print('✅ 安装成功')"
OpenAP安装问题:
# 如果OpenAP无法安装,尝试以下替代方案
pip install openap --no-cache-dir
pip install openap --force-reinstall
# 或者不安装OpenAP(性能估算不可用)
GeographicLib问题:
# 安装系统依赖项(Ubuntu/Debian)
sudo apt-get install libproj-dev proj-data proj-bin
# 安装系统依赖项(macOS)
brew install proj
# 安装系统依赖项(Windows)
# 下载自:https://proj.org/download.html
导入错误:
# 验证您的Python环境
python --version # 应该是3.11+
pip list | grep -E "(fastapi|openap|airportsdata)"
# 测试单独导入
python -c "import fastapi; print('FastAPI OK')"
python -c "import airportsdata; print('AirportsData OK')"
python -c "import openap; print('OpenAP OK')" || echo "OpenAP不可用(可选)"
# 规划简单飞行
curl -X POST "http://localhost:8080/plan" \
-H "Content-Type: application/json" \
-d '{
"depart_city": "旧金山",
"arrive_city": "纽约",
"ac_type": "A320",
"cruise_alt_ft": 37000,
"backend": "openap"
}'
# 按城市查找机场
curl "http://localhost:8080/airports/by_city?city=东京"
# 按国家过滤
curl "http://localhost:8080/airports/by_city?city=伦敦&country=GB"
# 多个结果
curl "http://localhost:8080/airports/by_city?city=巴黎"
# 指定确切的机场和飞机质量
curl -X POST "http://localhost:8080/plan" \
-H "Content-Type: application/json" \
-d '{
"depart_city": "洛杉矶",
"arrive_city": "东京",
"prefer_depart_iata": "LAX",
"prefer_arrive_iata": "NRT",
"ac_type": "B777",
"cruise_alt_ft": 39000,
"mass_kg": 220000,
"route_step_km": 100.0,
"backend": "openap"
}'
import requests
import json
class AerospaceClient:
def __init__(self, base_url="http://localhost:8080"):
self.base_url = base_url
def plan_flight(self, departure, arrival, aircraft="A320", altitude=35000):
"""在两个城市之间规划航班。"""
response = requests.post(f"{self.base_url}/plan", json={
"depart_city": departure,
"arrive_city": arrival,
"ac_type": aircraft,
"cruise_alt_ft": altitude,
"backend": "openap"
})
return response.json()
def find_airports(self, city, country=None):
"""在一个城市中查找机场。"""
params = {"city": city}
if country:
params["country"] = country
response = requests.get(f"{self.base_url}/airports/by_city", params=params)
return response.json()
# 使用
client = AerospaceClient()
# 查找机场
airports = client.find_airports("悉尼", "AU")
print(f"悉尼有 {len(airports)} 个机场")
# 规划航班
plan = client.plan_flight("悉尼", "墨尔本", "B737")
print(f"飞行距离:{plan['distance_nm']:.0f} NM")
print(f"预计飞行时间:{plan['estimates']['block']['time_min']:.0f} 分钟")
import asyncio
import aiohttp
from typing import List, Dict
async def plan_multiple_flights(flights: List[Dict]) -> List[Dict]:
"""并发地规划多个航班。"""
async with aiohttp.ClientSession() as session:
tasks = []
for flight in flights:
task = plan_single_flight(session, flight)
tasks.append(task)
results = await asyncio.gather(*tasks, return_exceptions=True)
return results
async def plan_single_flight(session, flight_data):
"""规划单个航班。"""
async with session.post(
"http://localhost:8080/plan",
json=flight_data
) as response:
return await response.json()
# 示例使用
flights_to_plan = [
{"depart_city": "纽约", "arrive_city": "伦敦", "ac_type": "A330"},
{"depart_city": "伦敦", "arrive_city": "迪拜", "ac_type": "B777"},
{"depart_city": "迪拜", "arrive_city": "新加坡", "ac_type": "A350"}
]
# 运行批量规划
results = asyncio.run(plan_multiple_flights(flights_to_plan))
for i, result in enumerate(results):
if not isinstance(result, Exception):
print(f"航班{i+1}:{result['distance_nm']:.0f} NM,{result['estimates']['block']['time_min']:.0f} 分钟")
import requests
class OrbitalMechanicsClient:
def __init__(self, base_url="http://localhost:8080"):
self.base_url = base_url
def plan_hohmann_transfer(self, r1_km, r2_km):
"""在两个圆形轨道之间计算霍曼转移。"""
response = requests.post(f"{self.base_url}/hohmann_transfer", json={