Weather MCP Server

Weather MCP Server

Enables AI assistants to retrieve real-time weather data and 5-day forecasts for any city using the OpenWeather API, supporting both metric and imperial units.

Category
访问服务器

README

Weather MCP Server - Sample Implementation

Reference implementation for ASUS and OEM partners

A simple, production-ready MCP server demonstrating how to integrate external services with AI PCs using the Model Context Protocol.

License: MIT Node.js Version MCP SDK


🎯 Purpose

This sample MCP server demonstrates:

  • ✅ How to create an MCP server from scratch
  • ✅ How to expose tools (functions) to AI clients
  • ✅ How to integrate external APIs (OpenWeather API)
  • ✅ Production-ready error handling
  • ✅ Clean, well-documented code

Perfect for: OEM partners building AI PC features, developers learning MCP, proof-of-concept projects


🌟 Features

Available Tools

  1. get_current_weather - Get real-time weather for any city

    • Temperature, conditions, humidity, wind speed
    • Supports both Celsius and Fahrenheit
  2. get_weather_forecast - Get 5-day forecast

    • Daily high/low temperatures
    • Weather conditions per day

🚀 Quick Start

Prerequisites

  • Node.js >= 18.0.0
  • OpenWeather API key (free tier available)

Installation

# Clone or download this repository
cd weather-mcp-server

# Install dependencies
npm install

# Configure API key
cp .env.example .env
# Edit .env and add your OpenWeather API key

Get API Key

  1. Visit OpenWeather API
  2. Sign up for free account
  3. Generate API key
  4. Add to .env file

Run the Server

# Start the server
npm start

# Or with auto-reload during development
npm run dev

📖 Usage Examples

Configure in Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "weather": {
      "command": "node",
      "args": ["/absolute/path/to/weather-mcp-server/index.js"],
      "env": {
        "OPENWEATHER_API_KEY": "your_api_key_here"
      }
    }
  }
}

Test with AI Client

Once configured, you can ask your AI assistant:

"What's the weather like in Taipei?"
"Give me a 5-day forecast for Tokyo"
"What's the temperature in New York in Fahrenheit?"

The AI will automatically call the appropriate MCP tools!


🏗️ Architecture

┌─────────────────┐
│   AI Client     │ (Claude, ChatGPT, etc.)
│  (Claude Desktop)│
└────────┬────────┘
         │ MCP Protocol (stdio)
         ↓
┌─────────────────┐
│  Weather MCP    │ ← This server
│     Server      │
└────────┬────────┘
         │ HTTPS
         ↓
┌─────────────────┐
│ OpenWeather API │
└─────────────────┘

Key Components

  • index.js - Main server implementation
  • @modelcontextprotocol/sdk - Official MCP SDK
  • StdioServerTransport - Communicates via stdin/stdout
  • OpenWeather API - External weather data source

📁 Project Structure

weather-mcp-server/
├── package.json          # Dependencies and scripts
├── index.js              # Main MCP server code
├── .env.example          # Environment variables template
├── .env                  # Your API keys (git-ignored)
├── README.md             # This file
├── README.zh-TW.md       # 繁體中文版
├── PARTNER-GUIDE.md      # Detailed guide for OEM partners
└── examples/
    └── client-example.js # Example client code

🛠️ Development

Code Structure

The server is organized into clear sections:

  1. Configuration - API keys, URLs
  2. WeatherServer Class - Main server logic
  3. Tool Registration - Define available tools
  4. Tool Handlers - Implement tool functionality
  5. Error Handling - Robust error management

Adding New Tools

// 1. Add tool definition in setupToolHandlers()
{
  name: 'your_new_tool',
  description: 'What this tool does',
  inputSchema: {
    type: 'object',
    properties: {
      param1: { type: 'string', description: 'Parameter description' }
    },
    required: ['param1']
  }
}

// 2. Add handler in CallToolRequestSchema
case 'your_new_tool':
  return await this.yourNewTool(args.param1);

// 3. Implement the method
async yourNewTool(param1) {
  // Your logic here
  return {
    content: [{
      type: 'text',
      text: 'Result'
    }]
  };
}

🧪 Testing

Manual Testing

# Test the MCP server directly
npm test

Integration Testing

Use the included examples/client-example.js to test tool calls programmatically.


📝 API Reference

Tool: get_current_weather

Parameters:

  • city (string, required) - City name (e.g., "Taipei", "Tokyo")
  • units (string, optional) - "metric" (default) or "imperial"

Returns:

🌤️ Current Weather in Taipei, TW

Temperature: 25.3°C (feels like 26.1°C)
Condition: Clear - clear sky
Humidity: 65%
Wind Speed: 3.2 m/s
Pressure: 1013 hPa
Visibility: 10.0 km

Last updated: 11/14/2025, 10:30:00 AM

Tool: get_weather_forecast

Parameters:

  • city (string, required) - City name
  • units (string, optional) - "metric" (default) or "imperial"

Returns:

📅 5-Day Weather Forecast for Taipei, TW

11/14/2025:
  High: 26.5°C | Low: 22.1°C
  Condition: Clear

11/15/2025:
  High: 27.2°C | Low: 23.4°C
  Condition: Clouds

...

🔒 Security Best Practices

Implemented in this sample:

  • ✅ API keys stored in environment variables (not in code)
  • ✅ Input validation for all parameters
  • ✅ Proper error handling (no sensitive data leakage)
  • ✅ HTTPS for external API calls
  • ✅ Minimal dependencies (reduces attack surface)

For production deployments:

  • 🔐 Use secrets management system (AWS Secrets Manager, Azure Key Vault)
  • 🔐 Implement rate limiting
  • 🔐 Add request logging/monitoring
  • 🔐 Use TLS for MCP communication if deployed remotely

🌐 Localization

This server supports multiple languages through the OpenWeather API:

// Add language parameter to API call
const url = `${API_BASE_URL}/weather?q=${city}&units=${units}&lang=zh_tw&appid=${API_KEY}`;

Supported languages: en, zh_tw, zh_cn, ja, ko, and 50+ more


🐛 Troubleshooting

Common Issues

"City not found"

  • Check spelling of city name
  • Try including country code: "Taipei,TW"

"Weather API error: Unauthorized"

  • Verify your API key in .env
  • Check API key is active at openweathermap.org

"Module not found"

  • Run npm install
  • Check Node.js version >= 18.0.0

MCP server not detected in Claude

  • Verify claude_desktop_config.json path
  • Restart Claude Desktop
  • Check server logs for errors

📚 Learn More

MCP Resources

Weather API


🤝 For OEM Partners

See PARTNER-GUIDE.md for:

  • Detailed integration guide
  • Deployment options
  • Customization examples
  • Production checklist
  • Support information

Contact: partners@irisgo.ai


📄 License

MIT License - see LICENSE file


🙏 Credits

  • Created by: IrisGo.AI Team
  • MCP Protocol: Anthropic
  • Weather Data: OpenWeather
  • For: ASUS and AI PC OEM partners

📮 Support


Last Updated: 2025-11-14 Version: 1.0.0

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选