MCP Weather Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Weather ServerWhat's the current weather in Tokyo?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
π€οΈ 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: weather-mcp-server
ποΈ 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.gitcd mcp-weather-server2. Install dependencies
This project uses pnpm.
pnpm installπ Environment Variables
Create a .env file:
WEATHER_API_KEY=your_weather_api_keyβ οΈ Never commit your
.envfile 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.jsFor 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.jsThe MCP Inspector will provide a local URL.
Open it in your browser.
You should see the available MCP tool:
getWeatherDataByCityNameTool 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 ResponseThe 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
StdioServerTransportMCP 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 APIsThis server cannot be deployed
Maintenance
Related MCP Connectors
Hosted MCP server for Xweather weather data: conditions, forecasts, alerts, and more.
OpenWeather MCP β wraps the OpenWeatherMap API (openweathermap.org)
Weather, code search, currency & Solana trust scoring as MCP tools. Free, no API key needed.
Provide real-time and forecast weather information for locations in the United States using naturaβ¦
Related MCP Servers
- FlicenseNot gradedqualityCmaintenanceEnables AI agents to retrieve live weather updates for any city via OpenWeatherMap, wrapped in MCP format.1-
- AlicenseAqualityDmaintenanceProvides real-time weather and forecast data via MCP tools, enabling AI agents to query current weather and up to 3-day forecasts for any city.3MIT
- FlicenseAqualityCmaintenanceProvides current weather data for any city using the Open-Meteo API, exposed as an MCP tool for integration with MCP clients.1-
- AlicenseNot gradedqualityCmaintenanceEnables AI assistants to query current weather for specified cities via MCP.MIT