Skip to main content
Glama
jayaraj-kannan

Weather MCP Server

Weather MCP Server (OpenWeather API)

A Model Context Protocol (MCP) server built with Python and uv that provides weather information by city name using the OpenWeather API (https://api.openweathermap.org/data/2.5/weather).


Table of Contents


Related MCP server: Weather MCP Server

Features

  • Get Weather by City Name: Fetches real-time weather metrics for any city (e.g., London, Chennai, New York,US).

  • Structured JSON Output: Returns temperature (°C), feels-like (°C), humidity (%), pressure (hPa), weather conditions, and wind speed (m/s).

  • Environment Key Integration: Loads OPENWEATHER_API_KEY automatically via .env / dotenv.

  • Package Management via uv: Uses pyproject.toml and uv for reproducible builds.


Prerequisites


Step-by-Step Setup Guide

VS Code Configuration

Step 1: Clone / Navigate to Project Directory

cd /Users/jayarajkannan/Learnings/project/mcp

Step 2: Environment Configuration

Create a .env file from .env.example and set your OpenWeather API key:

cp .env.example .env

Edit .env:

OPENWEATHER_API_KEY=your_actual_openweather_api_key_here

Step 3: Install Dependencies

Sync virtual environment and lockfile using uv:

uv sync

This installs mcp, httpx, and python-dotenv into the project environment.


Step 4: Run the MCP Server

You can run the server directly using uv:

uv run server.py

Or using the CLI script entry point defined in pyproject.toml:

uv run weather-mcp

Note: MCP servers communicate over stdio via JSON-RPC. Running the script directly will wait for input on stdin.


Step 5: Test Interactively with MCP Inspector

Use the official MCP Inspector to test and verify all tool calls in your browser UI:

npx @modelcontextprotocol/inspector uv run server.py
  1. Open the URL printed in the terminal (e.g. http://127.0.0.1:6274?...).

  2. Click Connect.

  3. Select the get_weather tool.

  4. Input a city name (e.g. London or Chennai) and click Run Tool.


Step 6: Run Automated Tests

Run the test suite using unittest and uv:

uv run python -m unittest test_server.py

MCP Tools Reference

get_weather

Gets current weather for a city using OpenWeather API.

Input Schema

Parameter

Type

Required

Description

city

string

Yes

City name (e.g. "London", "Chennai", "New York")

Example Response Output

{
  "city": "London",
  "country": "GB",
  "temperature_c": 21.57,
  "feels_like_c": 21.58,
  "humidity": 69,
  "pressure": 1006,
  "weather": "Clouds",
  "description": "broken clouds",
  "wind_speed_mps": 9.26
}

MCP Client Integration

Add the Weather MCP server to your MCP client configuration (e.g. Claude Desktop claude_desktop_config.json or Antigravity .mcp.json):

For VS code configuration

ctrl+shift+p for windows , cmd+shift+p mac

search >mcp: open user configuration

it will open a mcp.json file update the below config there

{
  "mcpServers": {
    "weather": {
      "command": "uv",
      "args": [
        "--directory",
        "/Users/jayarajkannan/Learnings/project/mcp",
        "run",
        "server.py"
      ],
      "env": {
        "OPENWEATHER_API_KEY": "YOUR_OPENWEATHER_API_KEY"
      }
    }
  }
}

Project Structure

├── pyproject.toml    # Project dependencies and script entry points
├── uv.lock           # Locked dependency tree
├── server.py         # Weather MCP server implementation
├── test_server.py    # Automated unit tests
├── .env.example      # Sample environment configuration
├── .env              # Local environment variables (API Key)
└── README.md         # Documentation

Available Tools

1 tool
get_weatherA

Get current weather for a city.

Args: city: City name (e.g. London, Chennai, New York)

Returns: Weather details including temperature, humidity, and conditions.

ParametersJSON Schema
NameRequiredDescriptionDefault
cityYes

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A4.2/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the behavioral burden. It does disclose that the result includes temperature, humidity, and conditions, but it does not mention units, city-resolution behavior, possible errors, or whether the operation is strictly read-only. This is acceptable but minimal.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is compact and well-structured: one clear purpose sentence, an Args block, and a Returns block. Every sentence earns its place and the main purpose is front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a one-parameter tool with an output schema available, this description is sufficient for an agent to select and invoke the tool correctly. It could add minor caveats like units or error behavior, but those are not necessary for basic correct use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The JSON schema provides only the parameter title 'City' with 0% description coverage, so the description's Args section adds crucial meaning by explaining that it expects a city name and giving concrete examples. It could add disambiguation guidance for duplicate city names, but for a single required parameter it compensates well.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening sentence 'Get current weather for a city' uses a specific verb and resource and immediately communicates the tool's purpose. It also clearly identifies the input (a city) and expected output, making the tool easy to distinguish even without siblings.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The phrase 'current weather' makes the intended use case clear: this tool is for real-time conditions, not forecasts or historical data. There are no sibling tools and no exclusions to document, so the usage context is sufficiently clear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 1 tool updatev0.1.0
    • First observedget_weather

TDQS

A3.9/5.0

Scored across 1 tool

Disambiguation5/5

With only one tool, there is no possibility of confusing it with others. The tool's purpose is clearly stated and unambiguous.

Naming Consistency4/5

The single tool name follows a clear verb_noun pattern. However, with only one example, consistency cannot be fully assessed.

Tool Count2/5

A single tool is too few for a weather-focused server, which would typically also cover forecasts, historical data, or location-based queries. The tool provides only current conditions.

Completeness2/5

The tool surface is severely limited to current weather only. Obvious gaps include forecasts, severe weather alerts, historical weather, and geocoding or location disambiguation.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers