Open-Meteo MCP Server
Open-Meteo MCP Server
一个基于 MCP(Model Context Protocol)的小型服务器,通过封装免费的 Open-Meteo API,让 Claude 等 AI 助手能够查询真实的天气数据——当前实况和预报。无需 API 密钥。
这是一个学习项目,用于端到端理解 MCP 服务器的工作原理:定义工具、本地运行,并将其连接到真实的 AI 客户端。
功能
连接到兼容 MCP 的客户端(如 Claude)后,它会暴露三个工具:
工具 | 作用 |
| 将地名(“London”)转换为坐标 |
| 获取某个坐标的当前温度、风速、降水等 |
| 获取某个坐标最长 16 天的预报(按天和/或按小时) |
因此,用户可以问助手“里斯本明天天气怎么样?”,助手会自己调用这些工具来查询并回答——它并没有预先内置天气数据,而是实时获取。
Related MCP server: Weather MCP Server
构建方式
src/server.ts—— 定义这三个工具以及每个工具如何调用 Open-Meteo API。这是服务器真正的“大脑”。src/index.ts—— 通过 stdio(标准输入/输出)运行服务器。这是本地开发工具(如 MCP Inspector)以及将服务器作为子进程启动的桌面应用所使用的传输方式。src/http.ts—— 通过 Streamable HTTP 运行同一个服务器,因此可以通过网络访问——例如部署在某处,或从基于浏览器的客户端访问。这就是无需在本地安装任何东西即可演示的原因。
两个入口点共享 server.ts 中相同的工具定义,因此实际逻辑只存在于一个地方。
运行
npm install
npm run build本地/stdio 模式(适用于将服务器作为子进程启动的工具):
npm startHTTP 模式(用于连接远程客户端,例如通过转发的 Codespaces 端口或托管服务提供商):
node build/http.js这会启动一个普通 HTTP 服务器,监听端口 3000(可通过 PORT 配置),在 POST /mcp 提供单个 MCP 端点,并附带 GET /health 检查。
无需客户端进行测试
MCP Inspector 的 CLI 模式是在终端中直接尝试的最快方式,无需浏览器:
# See what tools are available
npx @modelcontextprotocol/inspector --cli node build/index.js --method tools/list
# Actually call one
npx @modelcontextprotocol/inspector --cli node build/index.js \
--method tools/call --tool-name geocode_location --tool-arg name=London连接到 AI 助手
Claude Desktop / Claude Code:在客户端配置中将
build/index.js指向为 stdio MCP 服务器。Claude.ai 自定义连接器:指向正在运行的 HTTP 实例的
/mcpURL(需要支持自定义连接器的套餐)。Anthropic API 直连:在
/v1/messages请求的mcp_servers参数中传入/mcpURL——这样任何自定义应用或页面都可以使用这些工具,而无需预先构建 MCP 客户端。
扩展说明
Open-Meteo 提供的变量和端点远多于本项目使用的(空气质量、海洋预报、历史/存档数据、集合预报)。若要添加更多,请遵循 src/server.ts 中现有工具的模式——注册一个新的 server.tool(...) 块,带上自己的输入 schema 和 Open-Meteo 请求。
数据 © Open-Meteo.com,CC BY 4.0。
Available Tools
3 toolsgeocode_locationA
Look up geographic coordinates (latitude/longitude) for a place name, e.g. 'London', 'Paris, TX', or 'Tokyo'. Use this before calling the weather tools if you only have a place name rather than coordinates.
Inputs: name (required), count, language.
get_current_weatherA
Get the current weather conditions (temperature, wind, precipitation, etc.) for a specific latitude/longitude. Use geocode_location first if you only have a place name.
Inputs: latitude (required), longitude (required), timezone, wind_speed_unit, +1 more.
get_weather_forecastA
Get a multi-day hourly and/or daily weather forecast (up to 16 days) for a specific latitude/longitude. Use geocode_location first if you only have a place name. Defaults to a useful set of daily summary variables; pass include_hourly=true for hour-by-hour detail as well.
Inputs: latitude (required), longitude (required), timezone, forecast_days, +3 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
Each tool has a clearly distinct purpose: geocoding converts place names to coordinates, while the other two retrieve weather data. The current weather and forecast tools are differentiated by time horizon and description.
All tool names follow a consistent snake_case verb_noun pattern: geocode_location, get_current_weather, get_weather_forecast. The naming style is uniform and predictable.
With 3 tools, the server is tightly scoped for its purpose: location resolution, current conditions, and forecast. Each tool earns its place and the count feels complete without redundancy.
The core weather lookup flow is fully covered: geocode a place name, get current conditions, or get a forecast. Minor gaps exist such as historical weather data or alerts, but these are not essential for the apparent primary use case.
Related MCP Connectors
Global weather via Open-Meteo: forecast, historical, marine, air quality, geocoding, elevation.
Current weather and forecast lookup as an agent tool.
Worldwide place search with coordinates (Open-Meteo) — paid per call (x402/credits), 1 tools
Get current weather for any city and create images from your prompts. Streamline planning, reports…
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to fetch current weather conditions and forecasts for any city using the Open-Meteo API. Provides temperature, precipitation, and hourly forecast data through natural language queries.ISC
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to retrieve current weather, forecasts, and summaries for any global location using the Open-Meteo API, with no API key required.Creative Commons Zero v1.0 Universal
- AlicenseNot gradedqualityDmaintenanceProvides live weather data (current conditions, forecasts) and city geocoding through Open-Meteo API, enabling AI assistants to answer weather queries without an API key.MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to retrieve real-time weather conditions and 7-10 day forecasts for any location via Open-Meteo, with no API key required.144 npmMIT