code/chapter10/weather-mcp-server/README.md
真实天气查询 MCP 服务器,基于 HelloAgents 框架开发。
pip install hello-agents requests
python server.py
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) 或 %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"weather": {
"command": "python",
"args": ["/path/to/server.py"]
}
}
}
from hello_agents import SimpleAgent, HelloAgentsLLM
from hello_agents.tools import MCPTool
agent = SimpleAgent(name="天气助手", llm=HelloAgentsLLM())
weather_tool = MCPTool(server_command=["python", "server.py"])
agent.add_tool(weather_tool)
response = agent.run("北京今天天气怎么样?")
获取指定城市的当前天气。
参数:
city (string): 城市名称(支持中文和英文)示例:
{
"city": "北京"
}
返回:
{
"city": "北京",
"temperature": 10.0,
"feels_like": 9.0,
"humidity": 94,
"condition": "Light rain",
"wind_speed": 1.7,
"visibility": 10.0,
"timestamp": "2025-10-09 13:25:03"
}
列出所有支持的中文城市。
返回:
{
"cities": ["北京", "上海", "广州", "深圳", "杭州", "成都", "重庆", "武汉", "西安", "南京", "天津", "苏州"],
"count": 12
}
获取服务器信息。
返回:
{
"name": "Weather MCP Server",
"version": "1.0.0",
"tools": ["get_weather", "list_supported_cities", "get_server_info"]
}
北京、上海、广州、深圳、杭州、成都、重庆、武汉、西安、南京、天津、苏州
也支持使用英文城市名查询全球任意城市。
MIT License
HelloAgents Team