Skip to main content
Glama
spraveenitpro

mcp-weather-server

MCP Weather Server Tutorial

This project demonstrates how to build a simple Model Context Protocol (MCP) server that provides weather information for any city using the Open-Meteo API.

Features

  • MCP server using @modelcontextprotocol/sdk

  • One tool: get-weather (returns weather for a given city)

  • Uses geocoding and weather APIs from Open-Meteo

  • Returns weather data in JSON format

Related MCP server: MCP Weather Server

How It Works

  1. The MCP server exposes a tool called get-weather.

  2. When a city name is provided, the server:

    • Uses Open-Meteo's geocoding API to get latitude and longitude for the city.

    • Fetches current weather data for those coordinates.

    • Returns the weather data as a JSON response.

  3. If the city is not found, a helpful error message is returned.

Prerequisites

  • Node.js (v18+ recommended)

  • MCP Inspector (or any MCP client)

Setup

  1. Clone this repository or copy the files to your workspace.

  2. Install dependencies:

    npm install
    npm install node-fetch
  3. Update your main.ts to import fetch from node-fetch if running in Node.js:

    import fetch from "node-fetch";
  4. Start the MCP server using MCP Inspector:

    npx -y @modelcontextprotocol/inspector npx tsx main.ts

Usage

  • Open MCP Inspector and connect to your server.

  • Use the get-weather tool, enter a city name (e.g., "Paris", "Bangalore", "Chennai").

  • The server will respond with the current weather data for that city.

Example Tool Response

{
  "latitude": 13,
  "longitude": 80.125,
  "current": {
    "temperature_2m": 30,
    "relative_humidity_2m": 66,
    "wind_speed_10m": 14.9,
    "cloud_cover": 94,
    "apparent_temperature": 33.2
  }
}

Troubleshooting

  • If you see fetch is not defined, make sure you have installed and imported node-fetch.

  • If the city is not found, check for typos or try a nearby major city.

License

MIT

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to fetch current weather conditions and forecasts for any city using the Open-Meteo API. Provides temperature, precipitation, and hourly forecast data through natural language queries.
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables users to get current weather information for any city worldwide using the Open-Meteo API. Provides temperature and wind speed data through natural language queries.
    10 npm
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides current weather information for any city worldwide using the free Open-Meteo API, enabling users to query temperature, wind speed, humidity, and weather conditions through natural language.
    5 npm
    MIT