Skip to main content

MCP server for fetching air quality data from AQICN

Project description

AQICN MCP Server

smithery badge

This is a Model Context Protocol (MCP) server that provides air quality data tools from the World Air Quality Index (AQICN) project. It allows LLMs to fetch real-time air quality data for cities and coordinates worldwide.

Installation

Installing via Smithery

To install AQICN MCP Server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install @mattmarcin/aqicn-mcp --client claude

Installing via recommended uv (manual)

We recommend using uv to manage your Python environment:

# Install the package and dependencies
uv pip install -e .

Environment Setup

Create a .env file in the project root (you can copy from .env.example):

# .env
AQICN_API_KEY=your_api_key_here

Alternatively, you can set the environment variable directly:

# Linux/macOS
export AQICN_API_KEY=your_api_key_here

# Windows
set AQICN_API_KEY=your_api_key_here

Running the Server

Development Mode

The fastest way to test and debug your server is with the MCP Inspector:

mcp dev aqicn_server.py

Claude Desktop Integration

Once your server is ready, install it in Claude Desktop:

mcp install aqicn_server.py

Direct Execution

For testing or custom deployments:

python aqicn_server.py

Available Tools

1. city_aqi

Get air quality data for a specific city.

@mcp.tool()
def city_aqi(city: str) -> AQIData:
    """Get air quality data for a specific city."""

Input:

  • city: Name of the city to get air quality data for

Output: AQIData with:

  • aqi: Air Quality Index value
  • station: Station name
  • dominant_pollutant: Main pollutant (if available)
  • time: Timestamp of the measurement
  • coordinates: Latitude and longitude of the station

2. geo_aqi

Get air quality data for a specific location using coordinates.

@mcp.tool()
def geo_aqi(latitude: float, longitude: float) -> AQIData:
    """Get air quality data for a specific location using coordinates."""

Input:

  • latitude: Latitude of the location
  • longitude: Longitude of the location

Output: Same as city_aqi

3. search_station

Search for air quality monitoring stations by keyword.

@mcp.tool()
def search_station(keyword: str) -> list[StationInfo]:
    """Search for air quality monitoring stations by keyword."""

Input:

  • keyword: Keyword to search for stations (city name, station name, etc.)

Output: List of StationInfo with:

  • name: Station name
  • station_id: Unique station identifier
  • coordinates: Latitude and longitude of the station

Example Usage

Using the MCP Python client:

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})")

Contributing

Feel free to open issues and pull requests. Please ensure your changes include appropriate tests and documentation.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aqicn_mcp_server-0.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aqicn_mcp_server-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file aqicn_mcp_server-0.1.0.tar.gz.

File metadata

  • Download URL: aqicn_mcp_server-0.1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for aqicn_mcp_server-0.1.0.tar.gz
Algorithm Hash digest
SHA256 73ecefad794a28187864d93c85f43a5adab99f2f39f6c395fcf315c677d93662
MD5 a702459b3880ff618b5143942a286ae8
BLAKE2b-256 fbd11bc4646bce021b0766559c47ee453545da6c4792e1189e4fbab4f4cce922

See more details on using hashes here.

File details

Details for the file aqicn_mcp_server-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aqicn_mcp_server-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 697c15054d1dadb4b20860bf7a8a5f365657409dd955cf6adadd20e4c0380f67
MD5 b371c9b2f979dbf1b26344e7de13e100
BLAKE2b-256 dddae2ce25c49acda98b5aca69eac05e1e1fe135990d2641987d3f9b950cf40a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page