Back to MCP directory
publicPublicdnsLocal runtime

weather-server-mcp-server-h72

一个基于TypeScript的天气信息MCP服务器,提供天气数据资源访问、天气信息获取与更新工具,以及天气摘要生成功能。

article

README

🚀 天气服务器 MCP 服务器

本项目是一个用于测试天气服务器的工具,是基于 TypeScript 构建的 MCP 服务器,实现了一套天气信息系统。它通过一系列方式对核心 MCP 概念进行了演示,如提供带有 URI 和元数据的天气数据资源、获取和更新天气信息的工具,以及生成天气摘要提示等。

✨ 主要特性

资源

  • 可列出天气数据,并通过 weather:// URI 进行访问。
  • 每个天气条目包含位置、温度和元数据。
  • 采用 JSON MIME 类型,便于结构化数据访问。

工具

  • fetch_weather:用于获取当前天气信息。
    • 必须传入位置作为参数。
    • 从外部 API 获取天气数据。
  • update_weather:用于更新天气信息。
    • 必须传入位置和新天气数据作为参数。
    • 更新服务器状态中的天气数据。

提示

  • summarize_weather:生成当前天气数据的摘要。
    • 将所有天气条目作为嵌入资源包含在内。
    • 返回结构化提示,供 LLM 进行摘要处理。

📦 安装指南

开发环境安装

  1. 安装依赖
npm install
  1. 重命名环境配置文件
mv .envexample .env
  1. 更新环境配置文件: 在 .env 文件中更新 OPENWEATHER_API_KEY
OPENWEATHER_API_KEY=您的自有 OpenWeather API 密钥
  1. 构建服务器
npm run build
  1. 使用自动重建进行开发
npm run watch

与 Claude Desktop 集成安装

要与 Claude Desktop 配合使用,需添加服务器配置:

  • MacOS:在 ~/Library/Application Support/Claude/claude_desktop_config.json 文件中添加。
  • Windows:在 %APPDATA%/Claude/claude_desktop_config.json 文件中添加。
{
  "mcpServers": {
    "weatherserver": {
      "command": "/path/to/weatherserver/build/index.js"
    }
  }
}

调试说明

由于 MCP 服务器通过 stdio 进行通信,调试可能具有一定挑战性。我们推荐使用 MCP Inspector,它可作为包脚本使用:

npm run inspector

Inspector 将提供一个 URL,用于访问浏览器调试工具。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client