天气信息服务

Weather MCP Server 是一个基于Model Context Protocol (MCP)的简单天气信息服务,提供全球城市的天气信息,适用于AI助手和其他MCP兼容应用。

  • by Annihilater
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 annihilater/mcp-server-get-weather

使用说明

气象MCP服务器

中文文档 |英语

使用模型上下文协议(MCP)构建的简单天气信息服务。

概述

Weather MCP Server通过一个简单的API接口为世界各地的城市提供天气信息。它使用模型上下文协议(MCP)与客户端通信,允许与AI助手和其他MCP兼容应用程序轻松集成。

特性

  • 按城市名称获取当前天气状况
  • 返回温度、天气描述、湿度和风速
  • 如果外部API不可用,则回退到生成的数据
  • 简单轻便的实现

技术栈

  • TypeScript
  • Node.js
  • MCP SDK(@modelcontextprotocol/SDK)
  • Zod用于验证

安装

  1. 克隆存储库
git clone https://github.com/Annihilater/mcp-server-get-weather
  1. 安装依赖项:
npm install
  1. 构建项目:
npm run build

用法

启动服务器:

npx @modelcontextprotocol/inspector node dist/index.js

MCP配置

要在Cursor中使用此天气服务,需要在~/.cursor/mcp.json文件中添加以下配置:

"mcp-server-get-weather": {
  "command": "node",
  "args": [
    "<path-to-your-project>/dist/index.js"
  ]
}

将<path-to-your-project>替换为实际项目路径。配置完成后,可以通过MCP工具调用mcp_mcp_server_get_weather_get_weather函数来获取天气信息。

示例

api参考

get_weather

获取指定城市的天气信息。

参数

名称 类型 描述
cityName string 要获取天气的城市名称

响应

返回具有以下结构的JSON对象:

{
  "city": "London",
  "current_condition": {
    "temperature": "15",
    "weatherDesc": "Partly cloudy",
    "humidity": "71",
    "windSpeed": "11",
    "observation_time": "06:53 PM"
  },
  "forecast": {
    "maxTemp": "16",
    "minTemp": "9",
    "sunHour": "7.4",
    "date": "2023-04-12"
  }
}

发展

可用脚本

  • npm run build -构建项目并使入口点可执行
  • npm run watch -自动监视更改和重建
  • npx @modelcontextprotocol/inspector node dist/index.js -启动服务器

项目结构

  • src/index.ts -入口点,使用stdio传输设置MCP服务器
  • src/server.ts -服务器实现,定义天气工具

许可证

麻省理工学院