Google Air Quality MCP Server
A Model Context Protocol (MCP) server that provides access to Google's Air Quality API, enabling AI assistants to retrieve real-time air quality data, forecasts, historical information, and heatmap visualizations.
Features
- 🌍 Real-time Air Quality Data - Current conditions for any location worldwide
- 📊 Forecasts - Hourly air quality predictions
- 📈 Historical Data - Access past air quality measurements
- 🗺️ Heatmap Visualizations - Generate air quality heatmap tiles
- 🤖 LLM-Friendly Prompts - Natural language location queries
- 📦 MCP Resources - Structured data access via URI templates
Prerequisites
- Go 1.21 or higher
- Google Air Quality API key (see API Key Setup)
Installation
- Clone the repository
git clone git@github.com:ContexaAI/google-air-quality-mcp.git
cd google-air-quality-mcp
- Install dependencies
go mod download
- Configure environment variables
Create a .env file in the project root:
GOOGLE_AIR_QUALITY_API_KEY=your_api_key_here
MCP_SERVER_NAME=Google Air Quality MCP Server
PORT=8080
API Key Setup
Step 1: Enable the API
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Navigate to APIs & Services > Library
- Search for "Air Quality API"
- Click Enable
Step 2: Create API Credentials
- Go to APIs & Services > Credentials
- Click Create Credentials > API Key
- Copy the generated API key
- (Recommended) Click Restrict Key and:
- Under API restrictions, select "Restrict key"
- Choose "Air Quality API" from the dropdown
- Under Application restrictions, you can restrict by IP, HTTP referrer, etc.
Step 3: Configure the Server
Add your API key to the .env file:
GOOGLE_AIR_QUALITY_API_KEY=AIzaSyD...your-key-here
Note: The Air Quality API may require billing to be enabled on your Google Cloud project. Check the pricing page for details.
Docker Deployment
Using Docker
Build the image:
docker build -t google-air-quality-mcp .
Run the container:
docker run -d \
-p 8080:8080 \
-e GOOGLE_AIR_QUALITY_API_KEY=your_api_key_here \
--name air-quality-mcp \
google-air-quality-mcp
Using Docker Compose
Start the service:
docker-compose up -d
Stop the service:
docker-compose down
View logs:
docker-compose logs -f
Note: Make sure your
.envfile containsGOOGLE_AIR_QUALITY_API_KEYbefore running docker-compose.
Image Size
The Docker image uses a multi-stage build with Alpine Linux, resulting in a lightweight image (~54MB):
- Build stage: Uses
golang:1.24-alpineto compile the binary - Final stage: Uses
alpine:latestwith only the compiled binary and CA certificates - Security: Runs as non-root user for enhanced security
Usage
Running the Server
go run cmd/server/main.go
The server will start on http://localhost:8080 with the MCP endpoint at /mcp.
Connecting with MCP Inspector
- Open MCP Inspector
- Connect to
http://localhost:8080/mcp - Explore available tools, prompts, and resources
API Reference
Tools
| Tool Name | Description | Required Parameters | Optional Parameters |
|---|---|---|---|
get_current_air_quality | Get current air quality conditions for a specific location | latitude (float)longitude (float) | universalAqi (bool)languageCode (string)extraComputations (array)uaqiColorPalette (string) |
get_air_quality_forecast | Get hourly air quality forecast predictions | latitude (float)longitude (float) | pageSize (int)pageToken (string)universalAqi (bool)languageCode (string)extraComputations (array) |
get_air_quality_history | Get historical air quality data | latitude (float)longitude (float) | hours (int)pageSize (int)pageToken (string)universalAqi (bool)languageCode (string) |
get_air_quality_heatmap_tile | Get heatmap tile image for visualization | mapType (string)zoom (int)x (int)y (int) | - |
Valid Map Types for Heatmap
UAQI_RED_GREEN- Universal AQI with red-green color paletteUAQI_INDIGO_PERSIAN- Universal AQI with indigo-persian palettePM25_INDIGO_PERSIAN- PM2.5 concentration heatmapGBR_DEFRA- UK DEFRA indexDEU_UBA- German UBA indexCAN_EC- Canadian AQHIFRA_ATMO- French ATMO indexUS_AQI- US EPA AQI
Prompts
| Prompt Name | Description | Arguments |
|---|---|---|
current_air_quality_by_location_prompt | Get current air quality using a human-readable location name (LLM resolves to coordinates) | location (string) - e.g., "Paris, France" |
air_quality_forecast_by_location_prompt | Get air quality forecast for a location name | location (string)pageSize (int, optional) |
air_quality_history_by_location_prompt | Get historical air quality for a location name | location (string)hours (int, optional) |
air_quality_heatmap_by_location_prompt | Get heatmap tile for a location name | location (string)mapType (string)zoom (int) |
air_quality_heatmap_prompt | Get heatmap tile using direct coordinates | mapType (string)x (int)y (int)zoom (int) |
Resources
| Resource URI | Type | Description | Content Type |
|---|---|---|---|
example://server-info | Static | Basic server information and available resources | text/plain |
Examples
Using Tools
Get current air quality for San Francisco:
{
"name": "get_current_air_quality",
"arguments": {
"latitude": 37.7749,
"longitude": -122.4194,
"universalAqi": true
}
}
Get 24-hour forecast for New York:
{
"name": "get_air_quality_forecast",
"arguments": {
"latitude": 40.7128,
"longitude": -74.0060,
"pageSize": 24
}
}
Get historical data for London:
{
"name": "get_air_quality_history",
"arguments": {
"latitude": 51.5074,
"longitude": -0.1278,
"hours": 72
}
}
Using Prompts
Prompts allow you to use natural language location names. The LLM will automatically resolve them to coordinates.
Example prompt usage:
Use the current_air_quality_by_location_prompt with location "Tokyo, Japan"
The LLM will:
- Resolve "Tokyo, Japan" to coordinates (35.6762, 139.6503)
- Call the
get_current_air_qualitytool with those coordinates - Return the air quality data
Using Resources
Read server information:
URI: example://server-info
This returns basic information about the server and available resources.
Project Structure
.
├── cmd/
│ └── server/ # Server entry point
├── internal/
│ ├── capabilities/ # MCP capabilities
│ │ ├── prompts/ # Prompt definitions and handlers
│ │ ├── resources/ # Resource definitions and handlers
│ │ └── tools/ # Tool implementations
│ │ ├── client.go # Google Air Quality API client
│ │ ├── types.go # Shared types and structures
│ │ ├── current_conditions.go
│ │ ├── forecast.go
│ │ ├── history.go
│ │ └── heatmap.go
│ ├── config/ # Configuration management
│ └── mcp/ # MCP server setup
├── .env # Environment variables (not in git)
├── .gitignore
├── go.mod
├── go.sum
└── README.md
Development
Building
go build -o bin/server cmd/server/main.go
Running
./bin/server
Testing
go test ./...
Configuration
Environment variables (set in .env):
| Variable | Description | Default | Required |
|---|---|---|---|
GOOGLE_AIR_QUALITY_API_KEY | Your Google Air Quality API key | - | ✅ Yes |
MCP_SERVER_NAME | Display name for the MCP server | Google Air Quality MCP Server | No |
PORT | HTTP server port | 8080 | No |
Troubleshooting
API Key Issues
Error: "API key not valid"
- Verify your API key is correct in
.env - Ensure the Air Quality API is enabled in Google Cloud Console
- Check that API restrictions (if any) allow requests from your IP
Error: "This API method requires billing to be enabled"
- Enable billing on your Google Cloud project
- The Air Quality API may have usage costs
Connection Issues
Error: "address already in use"
- Another process is using port 8080
- Kill the process:
npx kill-port 8080 - Or change the
PORTin.env
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Resources
Support
For issues and questions:
- Open an issue on GitHub
- Check the Google Air Quality API documentation