Skip to main content
Glama
Paritosh008

MCP Weather Server

by Paritosh008

🌀️ MCP Weather Server

A simple Model Context Protocol (MCP) Weather Server built with Node.js that exposes weather functionality as an MCP tool.

This project demonstrates how an MCP server can expose tools that an AI application or MCP client can discover and execute.

πŸš€ Built as a practical project to understand MCP Servers, MCP Tools, stdio transport, Zod validation, and external API integration.


✨ Features

  • πŸ”Œ MCP server using the official MCP SDK

  • πŸ› οΈ Custom MCP tool: getWeatherDataByCityName

  • πŸ“ Weather lookup by city name

  • πŸ” Environment-variable based API configuration

  • βœ… Input validation using Zod

  • πŸ“‘ MCP communication using StdioServerTransport

  • ⚑ Built with Node.js and JavaScript

  • πŸ§ͺ Testable with MCP Inspector

  • πŸ€– Compatible with MCP clients that support stdio transport


Related MCP server: MCP Weather Data Fetcher

πŸ—οΈ Architecture

                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚     MCP Client      β”‚
                β”‚                     β”‚
                β”‚ Cursor / Inspector  β”‚
                β”‚ Other MCP Client    β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                           β”‚ MCP / stdio
                           β–Ό
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚    MCP Weather      β”‚
                β”‚       Server        β”‚
                β”‚      index.js       β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                           β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚ getWeatherDataByCityNameβ”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                           β–Ό
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚   Weather Service   β”‚
                β”‚    External API     β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🧰 Tech Stack

Technology

Purpose

Node.js

Runtime

JavaScript

Application language

MCP SDK

Model Context Protocol server

Zod

Input validation

pnpm

Package manager

MCP Inspector

MCP server testing

Weather API

Real-time weather data


πŸ“‚ Project Structure

MyMcp/
β”‚
β”œβ”€β”€ index.js
β”œβ”€β”€ package.json
β”œβ”€β”€ pnpm-lock.yaml
β”œβ”€β”€ .env
β”œβ”€β”€ .env.example
β”œβ”€β”€ .gitignore
└── README.md

πŸ“¦ Installation

1. Clone the repository

git clone https://github.com/YOUR_USERNAME/mcp-weather-server.git
cd mcp-weather-server

2. Install dependencies

This project uses pnpm.

pnpm install

πŸ” Environment Variables

Create a .env file:

WEATHER_API_KEY=your_weather_api_key

⚠️ Never commit your .env file or API key to GitHub.

The repository should contain .env.example instead:

WEATHER_API_KEY=your_weather_api_key_here

▢️ Run the MCP Server

Start the server with:

node index.js

For an MCP stdio server, no web page or server URL is expected to appear in the terminal.

The process waits for an MCP client to communicate with it through stdin/stdout.


πŸ§ͺ Test With MCP Inspector

You can test the MCP server without Cursor Agent.

Run:

pnpm dlx @modelcontextprotocol/inspector node index.js

The MCP Inspector will provide a local URL.

Open it in your browser.

You should see the available MCP tool:

getWeatherDataByCityName

Tool Input

{
  "city": "Delhi"
}

The MCP server then calls the weather service and returns weather information.


πŸ› οΈ Available MCP Tool

getWeatherDataByCityName

Gets weather information for a specified city.

Input

{
  "city": "Delhi"
}

Example Response

{
  "temp": "30Β°C",
  "forecast": "Clear"
}

πŸ”„ How MCP Works in This Project

The request flow is:

User
 ↓
AI / MCP Client
 ↓
MCP Tool Call
 ↓
getWeatherDataByCityName
 ↓
Weather API
 ↓
Weather Data
 ↓
MCP Server
 ↓
MCP Client
 ↓
AI Response

The important concept is that the AI does not directly contain the weather functionality.

Instead, the AI can discover and call an MCP tool exposed by the server.


🧠 What I Learned

This project helped me understand:

  • What MCP is

  • Why MCP servers are useful

  • MCP server architecture

  • MCP tools

  • Tool schemas

  • Zod validation

  • StdioServerTransport

  • MCP client/server communication

  • External API integration

  • API key management

  • Environment variables

  • MCP Inspector

  • Testing MCP tools without relying on a paid AI agent


πŸ”’ Security

Never expose API keys in source code.

❌ Don't do:

const API_KEY = "my-secret-key";

βœ… Use environment variables:

const API_KEY = process.env.WEATHER_API_KEY;

And add .env to .gitignore:

.env
node_modules/

πŸ“š MCP Concepts Demonstrated

MCP
β”‚
β”œβ”€β”€ MCP Server
β”‚
β”œβ”€β”€ MCP Client
β”‚
β”œβ”€β”€ Tools
β”‚
β”œβ”€β”€ Tool Schema
β”‚
β”œβ”€β”€ Transport
β”‚   └── stdio
β”‚
└── External APIs

Maintenance

ActivityMaintained
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Paritosh008/MCP-weather-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server