๐ Google Air Quality MCP Server
This Model Context Protocol (MCP) server offers access to Google's Air Quality API, allowing AI assistants to obtain real - time air quality data, forecasts, historical information, and heatmap visualizations.
๐ Quick Start
The Google Air Quality MCP Server enables seamless access to Google's Air Quality API. Follow the steps below to get started:
- Ensure you have Go 1.21 or higher installed and obtain a Google Air Quality API key.
- Clone the repository, install dependencies, and configure environment variables.
- Run the server and start exploring air quality data.
โจ Features
- ๐ Real - time Air Quality Data: Get current air quality 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: Use natural language for location queries.
- ๐ฆ MCP Resources: Access structured data via URI templates.
๐ฆ Installation
Prerequisites
- Go 1.21 or higher
- Google Air Quality API key (see API Key Setup)
Steps
- 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
๐ Documentation
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
โ ๏ธ Important Note
The Air Quality API may require billing to be enabled on your Google Cloud project. Check the pricing page for details.
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
| Property | Details |
|---|---|
| Tool Name | get_current_air_quality, get_air_quality_forecast, get_air_quality_history, get_air_quality_heatmap_tile |
| Description | Get current air quality conditions, hourly forecasts, historical data, and heatmap tiles respectively |
| Required Parameters | Vary by tool, e.g., latitude and longitude for most tools |
| Optional Parameters | Vary by tool, e.g., universalAqi, languageCode etc. |
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
| Property | Details |
|---|---|
| Prompt Name | current_air_quality_by_location_prompt, air_quality_forecast_by_location_prompt etc. |
| Description | Use natural language location names to get air quality data |
| Arguments | Vary by prompt, e.g., location for most prompts |
Resources
| Property | Details |
|---|---|
| Resource URI | example://server-info |
| Type | Static |
| Description | Basic server information and available resources |
| Content Type | text/plain |
Examples
๐ป Usage Examples
Basic Usage
{
"name": "get_current_air_quality",
"arguments": {
"latitude": 37.7749,
"longitude": -122.4194,
"universalAqi": true
}
}
This code gets the current air quality for San Francisco.
Advanced Usage
{
"name": "get_air_quality_forecast",
"arguments": {
"latitude": 40.7128,
"longitude": -74.0060,
"pageSize": 24
}
}
This code gets a 24 - hour air quality forecast for New York.
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
| Property | Details |
|---|---|
| Variable | GOOGLE_AIR_QUALITY_API_KEY, MCP_SERVER_NAME, PORT |
| Description | Google Air Quality API key, display name for MCP server, HTTP server port |
| Default | - for GOOGLE_AIR_QUALITY_API_KEY, Google Air Quality MCP Server for MCP_SERVER_NAME, 8080 for PORT |
| Required | Yes for GOOGLE_AIR_QUALITY_API_KEY, No for others |
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.
- Verify your API key is correct in
- 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
This project is licensed under the MIT license.
๐ 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.












