MCPInstall
openweathermap-mcp-server logo

openweathermap-mcp-server

by MikeTeddyOmondi 1 stars MikeTeddyOmondi/openweathermap-mcp-server

An MCP server that connects to OpenWeatherMap API for weather data caching.

READMEmain

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=32200

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.


More Web Scraping & Data Collection MCP servers

Similar servers from the same category.

BuiltWith

builtwith

Integrates with BuiltWith's technology detection API to identify and analyze web technologies used on specified domains, providing marketers and developers with comprehensive website stack information.

Web Scraping & Data Collection

Provides a bridge to ElfProxy's dynamic IP proxy service for retrieving country-specific proxy IPs, enabling IP rotation, geo-targeting, and bypassing regional restrictions.

WebOptimize

UniFuncs

unifuncs

Provides a bridge to the UniFuncs API for web search and web reading capabilities through TypeScript implementation with Express and NPX commands.

search

Integrates with Bocha, a Chinese search engine, to provide web search capabilities with rich structured data from billions of documents across multiple domains and languages.

search