MCP ExplorerExplorer

Openweathermap Mcp Server

@MikeTeddyOmondion 22 days ago
1 MIT
FreeCommunity
AI Systems
An MCP server that connects to OpenWeatherMap API for weather data caching.

Overview

What is Openweathermap Mcp Server

openweathermap-mcp-server is a Model Context Protocol (MCP) server that connects to the OpenWeatherMap API and caches weather data using Redis/Valkey. It serves as a modular solution for AI models to access external weather data.

Use cases

Use cases include developing weather monitoring applications, creating AI models that predict weather patterns, and building dashboards that display real-time weather updates for specific locations.

How to use

To use openweathermap-mcp-server, first install the necessary dependencies using ‘bun install’. Then, build the TypeScript files with ‘bun run build’. Start the SSE server with ‘bun start:sse’ or the Stdio server with ‘bun start:stdio’. Ensure to set up your environment variables in a .env file with your OpenWeatherMap API key and Redis configuration.

Key features

Key features include retrieving current weather conditions for any city, obtaining 5-day weather forecasts, querying weather by geographic coordinates, caching weather data in Redis for performance, and supporting both SSE and Stdio transport for MCP communication.

Where to use

openweathermap-mcp-server can be used in various fields such as weather applications, AI-driven weather analysis tools, and any system requiring real-time weather data integration.

Content

OpenWeatherMap MCP Server

This project provides a Model Context Protocol (MCP) server that connects to the OpenWeatherMap API and caches weather data in Redis/Valkey. It demonstrates how to build a modular MCP server that AI models can use to access external APIs.

Features

  • Retrieve current weather conditions for any city
  • Get 5-day weather forecasts
  • Query weather by geographic coordinates
  • Cache weather data in Redis for improved performance
  • SSE (Server-Sent Events) transport for MCP communication
  • Stdio (Standard Input Output) transport for MCP communication

Prerequisites

  • Node.js 18+ and npm/yarn
  • Redis server running locally or accessible via URL
  • OpenWeatherMap API key

Environment Variables

Create a .env file in the project root with:

OPENWEATHER_API_KEY=your_api_key_here
REDIS_URL=redis://localhost:6379
REDIS_HOST=localhost
REDIS_POST=6379
PORT=10203

Installation

# Install dependencies
bun install

# Build TypeScript
bun run build

# Start the SSE server
bun start:sse

# Start the Stdio server
bun start:stdio

# Start the MCP Inspector for debugging
bun start:stdio

Project Structure

  • openweather-mcp-server.ts: Core MCP server with weather tools and Redis caching
  • sse-server.ts: Express server implementing SSE transport for MCP
  • mcp-client.ts: Example client to test the MCP server

Available Tools

The MCP server provides the following tools:

  1. get-current-weather: Get current weather for a city
  • Parameters: city (string)
  1. get-weather-forecast: Get 5-day forecast for a city
  • Parameters: city (string)
  1. get-weather-by-coordinates: Get weather using latitude/longitude
  • Parameters: lat (number), lon (number)
  1. clear-weather-cache: Clear cached weather data
  • Parameters: city (string, optional) - If not provided, clears all cache

Integration with AI Models

This MCP server is designed to be used with AI models that support the Model Context Protocol. By connecting to this server, AI models can:

  1. Access real-time weather data
  2. Query forecasts
  3. Provide location-specific weather information

Example Usage (with Claude or similar model)

Once the server is running, you can instruct an AI model to use it:

“Please connect to my weather MCP server at http://localhost:10203/sse and tell me the current weather in Paris.”

The AI would then:

  1. Connect to the MCP server
  2. Call the get-current-weather tool with city: "Paris"
  3. Return the formatted weather information

Extending the Server

To add new functionality:

  1. Add new tools to weather-mcp-server.ts using the mcpServer.tool() method
  2. Update the server info in sse-server.ts to document your new tool
  3. Implement any required helper functions and caching logic

Redis Caching

The server uses Redis to cache weather data with a 30-minute TTL (Time To Live). This reduces API calls to OpenWeather and improves response times.

To clear the cache manually, use the clear-weather-cache tool.


Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers