weather-mcp
Provides current weather information by combining geocoding and weather data APIs, supporting city names with optional state and country parameters and locale-based unit preferences.
README
Weather MCP Server
A Model Context Protocol (MCP) server that provides current weather information by integrating geocoding and weather data APIs. This project serves as an expanded example of an MCP server, building on the examples shown in the official TypeScript SDK. This project shows a server in the context of TypeScript tooling.
<img width="738" height="629" alt="image of weather mcp in use in Cursor" src="https://github.com/user-attachments/assets/d3a4be21-aff2-4314-9d63-1272fa792377" />
Features
- Current Weather Service: Combines geocoding and weather data fetching into a single MCP tool
- Location Flexibility: Supports city names with optional state and country parameters
- Unit Preferences: Automatically detects locale preferences or allows manual unit specification
- TypeScript Tooling: Includes build, linting, and type checking setup
- MCP Compliance: Implements the Model Context Protocol for seamless integration with MCP clients
Architecture
This MCP server demonstrates several key concepts:
-
Multi-API Integration: The
currentWeatherfunction orchestrates two external API calls:- OpenWeatherMap Geocoding API to convert location names to coordinates
- OpenWeatherMap Current Weather API to fetch weather data
-
Smart Defaults: Automatically determines preferred units based on system locale (imperial for US, metric for others)
-
Error Handling: Graceful error handling with JSON error responses
-
TypeScript Best Practices: Full TypeScript setup with strict linting rules and proper module resolution
Installation
Prerequisites
- Node.js >= 22
- npm >= 11
- OpenWeatherMap API key
Setup
-
Clone and install dependencies:
git clone <repository-url> cd weather-mcp npm install -
Get an OpenWeatherMap API key:
- Visit OpenWeatherMap
- Sign up for a free account
- Generate an API key
-
Build the project:
npm run buildImportant: You must run
npm run buildbefore using the server or after making any changes to the source code.
Cursor Configuration
To use this MCP server with Cursor, add the following to your mcp.json configuration file:
{
"mcpServers": {
"weather-mcp": {
"command": "node",
"args": ["/path/to/weather-mcp/dist/esm/server.js"],
"env": {
"OPEN_WEATHER_API_KEY": "your_api_key_here"
}
}
}
}
Replace /path/to/weather-mcp with the actual path to your weather-mcp directory and add your
actual API key.
For more information, see Cursor documentation.
Usage
The server provides one tool:
currentWeather
Fetches current weather data for a given location.
Development
Available Scripts
npm run build: Clean and build the project (types + ESM)npm run clean: Remove build artifactsnpm run typecheck: Run TypeScript type checking
Project Structure
src/
├── server.ts # MCP server setup and tool registration
├── functions.ts # Weather API integration logic
dist/
├── esm/ # Compiled JavaScript (ES modules)
└── types/ # TypeScript declaration files
Code Quality
The project includes ESLint configuration with:
- TypeScript-specific rules
- Import/export practices
- Code style enforcement
- Error prevention rules
Potential Improvements
Better Cross-Platform Locale Detection
The current locale detection using execSync('locale') is Unix-specific and may not work reliably
or at all on Windows. Consider implementing a more robust cross-platform solution. Keep an eye on
how Intl API functions in Node.js
Unit Testing
The project currently lacks unit tests. Consider adding:
- Unit tests for the
currentWeatherfunction - Mock API responses for testing
- Error handling scenarios
- Edge cases (invalid cities, API failures)
Additional Features
- Weather forecast functionality
- Historical weather data
- Multiple weather providers for redundancy
- Caching to reduce API calls
- More granular location support (coordinates, postal codes)
OpenWeatherMap APIs Used
- Geocoding API:
http://api.openweathermap.org/geo/1.0/direct - Current Weather API:
https://api.openweathermap.org/data/2.5/weather
Both APIs require the OPEN_WEATHER_API_KEY environment variable.
Links
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.