weather-mcp

weather-mcp

Provides current weather information by combining geocoding and weather data APIs, supporting city names with optional state and country parameters and locale-based unit preferences.

Category
访问服务器

README

Weather MCP Server

A Model Context Protocol (MCP) server that provides current weather information by integrating geocoding and weather data APIs. This project serves as an expanded example of an MCP server, building on the examples shown in the official TypeScript SDK. This project shows a server in the context of TypeScript tooling.

<img width="738" height="629" alt="image of weather mcp in use in Cursor" src="https://github.com/user-attachments/assets/d3a4be21-aff2-4314-9d63-1272fa792377" />

Features

  • Current Weather Service: Combines geocoding and weather data fetching into a single MCP tool
  • Location Flexibility: Supports city names with optional state and country parameters
  • Unit Preferences: Automatically detects locale preferences or allows manual unit specification
  • TypeScript Tooling: Includes build, linting, and type checking setup
  • MCP Compliance: Implements the Model Context Protocol for seamless integration with MCP clients

Architecture

This MCP server demonstrates several key concepts:

  1. Multi-API Integration: The currentWeather function orchestrates two external API calls:

    • OpenWeatherMap Geocoding API to convert location names to coordinates
    • OpenWeatherMap Current Weather API to fetch weather data
  2. Smart Defaults: Automatically determines preferred units based on system locale (imperial for US, metric for others)

  3. Error Handling: Graceful error handling with JSON error responses

  4. TypeScript Best Practices: Full TypeScript setup with strict linting rules and proper module resolution

Installation

Prerequisites

  • Node.js >= 22
  • npm >= 11
  • OpenWeatherMap API key

Setup

  1. Clone and install dependencies:

    git clone <repository-url>
    cd weather-mcp
    npm install
    
  2. Get an OpenWeatherMap API key:

  3. Build the project:

    npm run build
    

    Important: You must run npm run build before using the server or after making any changes to the source code.

Cursor Configuration

To use this MCP server with Cursor, add the following to your mcp.json configuration file:

{
  "mcpServers": {
    "weather-mcp": {
      "command": "node",
      "args": ["/path/to/weather-mcp/dist/esm/server.js"],
      "env": {
        "OPEN_WEATHER_API_KEY": "your_api_key_here"
      }
    }
  }
}

Replace /path/to/weather-mcp with the actual path to your weather-mcp directory and add your actual API key.

For more information, see Cursor documentation.

Usage

The server provides one tool:

currentWeather

Fetches current weather data for a given location.

Development

Available Scripts

  • npm run build: Clean and build the project (types + ESM)
  • npm run clean: Remove build artifacts
  • npm run typecheck: Run TypeScript type checking

Project Structure

src/
├── server.ts      # MCP server setup and tool registration
├── functions.ts   # Weather API integration logic
dist/
├── esm/           # Compiled JavaScript (ES modules)
└── types/         # TypeScript declaration files

Code Quality

The project includes ESLint configuration with:

  • TypeScript-specific rules
  • Import/export practices
  • Code style enforcement
  • Error prevention rules

Potential Improvements

Better Cross-Platform Locale Detection

The current locale detection using execSync('locale') is Unix-specific and may not work reliably or at all on Windows. Consider implementing a more robust cross-platform solution. Keep an eye on how Intl API functions in Node.js

Unit Testing

The project currently lacks unit tests. Consider adding:

  • Unit tests for the currentWeather function
  • Mock API responses for testing
  • Error handling scenarios
  • Edge cases (invalid cities, API failures)

Additional Features

  • Weather forecast functionality
  • Historical weather data
  • Multiple weather providers for redundancy
  • Caching to reduce API calls
  • More granular location support (coordinates, postal codes)

OpenWeatherMap APIs Used

  1. Geocoding API: http://api.openweathermap.org/geo/1.0/direct
  2. Current Weather API: https://api.openweathermap.org/data/2.5/weather

Both APIs require the OPEN_WEATHER_API_KEY environment variable.

Links

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选