Connect with MCP client and Shows weather by city name
Weather MCP Server
A Model Context Protocol (MCP) server that provides weather information for various cities.
Overview
This is a TypeScript-based MCP server that implements weather-related tools and resources. It enables AI agents and tools compatible with the MCP protocol to access weather data in a standardized way.
Features
- get_weather tool: Retrieve current weather conditions for supported cities
- weather://cities resource: List of supported cities with available weather data
Supported Cities
- London (22° C, Sunny)
- Paris (25° C, Cloudy)
Prerequisites
- Node.js 18+
- npm or yarn
Installation
# Install dependencies
npm install
Development
Build
# Compile TypeScript to JavaScript
npx tsc
Run
# Execute the server
node server.js
Or use tsx for direct execution:
npx tsx server.ts
Project Structure
.
├── server.ts # Main server implementation with tools and resources
├── package.json # Project dependencies and metadata
├── package-lock.json # Locked dependency versions
├── .gitignore # Git ignore rules
└── .github/
└── copilot-instructions.md # AI agent development guidelines
Architecture
This project follows the MCP server architecture:
- Server Setup: Uses
McpServerfrom the official MCP SDK - Tool Registration: Weather tools defined with Zod input validation
- Resource Management: Static resources listing available weather data
- Type Safety: Full TypeScript with strict mode
API Reference
Tools
get_weather
Retrieves current weather for a specified city.
Input Schema:
{
city: string // City name (e.g., "London", "Paris")
}
Response:
{
"temp": "22° C",
"conditions": "Sunny"
}
Resources
weather://cities
Returns a list of supported cities for weather queries.
Configuration
All configuration is in package.json. The server uses:
@modelcontextprotocol/sdk- MCP protocol implementationzod- Runtime schema validationtypescript- Type safety and compilation
Development Guidelines
See .github/copilot-instructions.md for detailed instructions for AI agents and developers working on this project.
Contributing
When adding new tools:
- Define the input schema with Zod
- Register the handler with proper MCP ContentBlock structure
- Update this README with new features
License
ISC