You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

yujie-weather-mcp-server

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yujie-weather-mcp-server

A simple MCP server for weather queries with AI integration

1.0.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Weather MCP Server

一个简单的 MCP (Model Context Protocol) 服务器,提供天气查询功能并集成AI模型生成友好的天气报告。

功能特性

  • 🌤️ 天气查询:支持多个城市的天气信息查询
  • 🤖 AI 增强:通过大模型生成友好的天气报告和建议
  • 🌍 多语言:支持中文和英文城市名称
  • 📊 详细信息:提供温度、天气状况、湿度等详细数据

安装和运行

1. 安装依赖

cd weather-mcp-server
npm install

2. 启动服务器

npm start

或者使用开发模式(自动重启):

npm run dev

支持的城市

目前支持以下城市(中英文均可):

  • 北京 / Beijing
  • 上海 / Shanghai
  • 广州 / Guangzhou
  • 深圳 / Shenzhen
  • 杭州 / Hangzhou

MCP 工具

get_weather

获取指定城市的天气信息并生成AI增强的天气报告。

参数:

  • city (string, 必需): 城市名称

示例调用:

{
  "name": "get_weather",
  "arguments": {
    "city": "北京"
  }
}

返回示例:

🌤️ 北京 天气报告

今天北京的天气晴天,温度15°C,湿度45%。天气有点凉,建议多穿一件衣服。

📊 详细数据:
• 温度:15°C
• 天气:晴天
• 湿度:45%

架构说明

  • MCP 服务器:使用 @modelcontextprotocol/sdk 实现标准的 MCP 协议
  • 天气数据:目前使用模拟数据,可以轻松替换为真实的天气API
  • AI 集成:模拟大模型调用,可以替换为 OpenAI、Claude 等真实API
  • 错误处理:完善的错误处理和降级机制

扩展建议

集成真实天气API

替换 WEATHER_DATA 为真实的天气API调用:

async function getWeatherData(city) {
  const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=YOUR_API_KEY`);
  return await response.json();
}

集成真实AI模型

替换 callAIModel 函数为真实的AI API调用:

async function callAIModel(weatherData, city) {
  const response = await fetch('https://api.openai.com/v1/chat/completions', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      model: 'gpt-3.5-turbo',
      messages: [
        {
          role: 'user',
          content: `请根据天气信息生成友好的天气报告:${JSON.stringify(weatherData)}`
        }
      ]
    })
  });
  
  const data = await response.json();
  return data.choices[0].message.content;
}

许可证

MIT License

Keywords

mcp

FAQs

Package last updated on 10 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts