AQICN MCP 服务器

这是一个模型上下文协议 (MCP) 服务器,提供来自世界空气质量指数 (AQICN) 项目的空气质量数据工具。它允许 LLM 获取全球城市和坐标的实时空气质量数据。
安装
通过 Smithery 安装
要通过Smithery自动为 Claude Desktop 安装 AQICN MCP 服务器:
npx -y @smithery/cli install @mattmarcin/aqicn-mcp --client claude
通过推荐的 uv 安装(手动)
我们建议使用uv来管理您的 Python 环境:
# Install the package and dependencies
uv pip install -e .
Related MCP server: Weather MCP Tool
环境设置
在项目根目录中创建一个.env文件(您可以从.env.example复制):
# .env
AQICN_API_KEY=your_api_key_here
或者,您可以直接设置环境变量:
# Linux/macOS
export AQICN_API_KEY=your_api_key_here
# Windows
set AQICN_API_KEY=your_api_key_here
运行服务器
开发模式
测试和调试服务器的最快方法是使用 MCP Inspector:
Claude 桌面集成
服务器准备就绪后,请在 Claude Desktop 中安装它:
mcp install aqicn_server.py
直接执行
对于测试或自定义部署:
可用工具
1. 城市阿奇
获取特定城市的空气质量数据。
@mcp.tool()
def city_aqi(city: str) -> AQIData:
"""Get air quality data for a specific city."""
输入:
输出: AQIData包含:
2. geo_aqi
使用坐标获取特定位置的空气质量数据。
@mcp.tool()
def geo_aqi(latitude: float, longitude: float) -> AQIData:
"""Get air quality data for a specific location using coordinates."""
输入:
latitude :位置的纬度
longitude :位置的经度
**输出:**与city_aqi相同
3. 搜索站
通过关键词搜索空气质量监测站。
@mcp.tool()
def search_station(keyword: str) -> list[StationInfo]:
"""Search for air quality monitoring stations by keyword."""
输入:
输出: StationInfo列表,其中包含:
name :车站名称
station_id :唯一车站标识符
coordinates :车站的经纬度
示例用法
使用 MCP Python 客户端:
from mcp import Client
async with Client() as client:
# Get air quality data for Beijing
beijing_data = await client.city_aqi(city="beijing")
print(f"Beijing AQI: {beijing_data.aqi}")
# Get air quality data by coordinates (Tokyo)
geo_data = await client.geo_aqi(latitude=35.6762, longitude=139.6503)
print(f"Tokyo AQI: {geo_data.aqi}")
# Search for stations
stations = await client.search_station(keyword="london")
for station in stations:
print(f"Station: {station.name} ({station.coordinates})")
贡献
欢迎随时提交问题和拉取请求。请确保您的更改包含适当的测试和文档。
执照
该项目已获得 MIT 许可。