Content
# China City Weather Query MCP Service
A Model Context Protocol (MCP) service for querying the weather in Chinese cities based on the Amap API. This service allows users to obtain real-time weather conditions and forecasts for the next few days in various cities across China through simple requests.
## Features
- Uses Amap Weather API to obtain accurate weather data for Chinese cities
- Supports querying real-time weather conditions
- Supports querying weather forecasts for the next 3-4 days
- Supports intelligent city name recognition, including queries at the city and district levels
- Supports city name search functionality
- Implemented as a standard MCP service, easy to integrate into AI applications
## Installation Instructions
### Prerequisites
- Amap Developer API Key (must be configured via environment variables)
### Installation Steps
1. Clone or download this repository
2. Navigate to the project directory
3. Install dependencies using uv:
```bash
uv venv
source .venv/bin/activate
uv add "mcp[cli]" httpx
```
## Usage
### Start the MCP Service
If you need to create a client to test this MCP service, please start it manually. Execute the following command in the terminal to start the MCP service:
```bash
uv run weather.py
```
### Use the Integrated MCP Service
#### Using in Claude Desktop
To use it in Claude Desktop, please add the server configuration:
Open the Claude for Desktop App configuration in a text editor, with the path as follows `~/Library/Application Support/Claude/claude_desktop_config.json`
If the file does not exist, please ensure to create it.
```python
{
"mcpServers": {
"amap-weather-mcp-server": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/PARENT/FOLDER/weather",
"run",
"weather.py"
],
"env": {
"AMAP_API_KEY": "YOUR_API_KEY_HERE"
}
}
}
}
```
#### Using in Cherry Studio
Configure as shown in the image below:

### Call the Service
The MCP service provides three main utility functions for weather queries:
1. `get_current_weather`: Get the current weather conditions for a city
2. `get_weather_forecast`: Get the weather forecast for the next few days
3. `search_city`: Search for city names
Example of calling using the MCP client:
```python
from mcp.client import Client
# Connect to the service
client = Client("amap-weather-mcp-server")
# Query real-time weather
current_weather = await client.get_current_weather("北京市")
print(current_weather)
# Query weather forecast
forecast = await client.get_weather_forecast("上海市")
print(forecast)
# Search for city names
cities = await client.search_city("广州")
print(cities)
```
## API Reference
### get_current_weather
Get real-time weather data for a specified city.
**Parameters:**
- `city`: The name of the Chinese city, which needs to include administrative division identifiers such as "北京市", "上海市", "海珠区", etc.
**Returns:**
A formatted string of real-time weather information for the city, including:
- City name
- Weather conditions
- Temperature
- Wind direction
- Wind force
- Humidity
- Release time
### get_weather_forecast
Get the weather forecast for a specified city (next 3-4 days).
**Parameters:**
- `city`: The name of the Chinese city, which needs to include administrative division identifiers such as "北京市", "上海市", "浙江省杭州市", etc.
**Returns:**
A formatted string of weather forecast information for the city, including:
- City name
- Dates for the next few days
- Daytime and nighttime weather conditions
- Daytime and nighttime temperatures
- Daytime and nighttime wind direction and force
### search_city
Search for matching city names based on keywords.
**Parameters:**
- `keyword`: The keyword for the city name, preferably including administrative division identifiers such as "广州市", "海珠区", etc.
**Returns:**
A string containing a list of matching city names.
## Data Source
This service uses the weather data API provided by the Amap Open Platform:
- Real-time weather data API: <https://restapi.amap.com/v3/weather/weatherInfo>
- City code data: AMap_adcode_citycode.csv
## Notes
- This service only supports weather queries for cities in mainland China
- The Amap API may have request frequency limits
- City name recognition supports direct input of city or district names (it is recommended to include administrative division identifiers such as "市", "县", "区", etc.)
- Environment variables must be correctly configured; otherwise, API requests will fail
## License
[MIT License](LICENSE)
Connection Info
You Might Also Like
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
markitdown
Python tool for converting files and office documents to Markdown.
firecrawl
Firecrawl MCP Server enables web scraping, crawling, and content extraction.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.
TrendRadar
TrendRadar: Your hotspot assistant for real news in just 30 seconds.
mempalace
The highest-scoring AI memory system ever benchmarked. And it's free.