Weather MCP Server
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.
README
Practice MCP JS
A Model Context Protocol (MCP) server implementation in TypeScript that provides weather information tools for AI assistants.
Description
This project demonstrates how to create an MCP server that exposes weather-related tools to Large Language Models (LLMs). The server provides a fetch-weather tool that retrieves current weather data and forecasts for any city using the Open-Meteo API.
Features
- Weather Tool: Fetch current weather conditions and forecasts for any city
- Input Validation: Uses Zod for robust input/output validation
- MCP Protocol: Compatible with AI assistants that support the Model Context Protocol
- TypeScript: Fully typed implementation for better development experience
Prerequisites
- Node.js (version 14 or higher)
- npm or yarn package manager
Installation
- Clone the repository:
git clone <repository-url>
cd practice-mcp-js
- Install dependencies:
npm install
Usage
Running the Server
To start the MCP server:
npx tsx main.ts
The server will start and listen for MCP connections via stdio transport.
Available Tools
fetch-weather
Retrieves weather information for a specified city.
Parameters:
city(string): Name of the city to get weather information for
Example Response: The tool returns current weather conditions including:
- Temperature
- Precipitation
- Day/night status
- Rain information
- Hourly forecast data
Project Structure
practice-mcp-js/
├── main.ts # Main server implementation
├── package.json # Project configuration and dependencies
├── package-lock.json # Dependency lock file
└── README.md # This file
Dependencies
- @modelcontextprotocol/sdk: Core MCP SDK for server implementation
- zod: Schema validation library for input/output validation
API Integration
This project integrates with the following external APIs:
- Open-Meteo Geocoding API: For converting city names to coordinates
- Open-Meteo Weather API: For retrieving weather data and forecasts
How It Works
- The server creates an MCP server instance with the name "PRO INDUSTRIAL MCP SERVER"
- It defines a
fetch-weathertool that:- Accepts a city name as input
- Geocodes the city name to get coordinates
- Fetches weather data using the coordinates
- Returns formatted weather information
- The server connects via stdio transport for communication with AI assistants
Development
The main server logic is implemented in main.ts:7-55. Key components include:
- Server initialization (
main.ts:7-10) - Tool definition (
main.ts:13-50) - Transport setup (
main.ts:54-55)
Error Handling
The weather tool includes error handling for:
- Cities that cannot be found
- API request failures
- Invalid input parameters (via Zod validation)
License
ISC
Contributing
This is a practice project for learning MCP server development. Feel free to fork and experiment with additional tools and features.
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.